:root {
  --ink: #17201c;
  --muted: #65716a;
  --line: #dce3df;
  --surface: #ffffff;
  --canvas: #f4f6f5;
  --primary: #176b4d;
  --primary-dark: #0f513a;
  --success-bg: #e7f4ed;
  --warning-bg: #fff4d6;
  --danger: #a8382d;
  --danger-bg: #fbe9e7;
  --info-bg: #e9f0f8;
  --radius: 6px;
  font-family: "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  letter-spacing: 0;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--canvas); }
button, input, select { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid #79b99e; outline-offset: 2px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 26px; line-height: 1.25; }
h2 { margin-bottom: 0; font-size: 19px; line-height: 1.35; }
.muted { color: var(--muted); }
.eyebrow { margin-bottom: 5px; color: var(--muted); font-size: 12px; font-weight: 700; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 220px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 22px 14px; background: #202924; color: #f6faf7; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 24px; font-weight: 700; }
.brand-mark { width: 48px; height: 48px; display: grid; place-items: center; background: var(--primary); color: white; border-radius: var(--radius); font-size: 22px; font-weight: 800; }
.brand-mark.small { width: 30px; height: 30px; font-size: 15px; }
nav { display: grid; gap: 4px; }
.nav-item { width: 100%; min-height: 42px; border: 0; border-radius: 4px; padding: 0 12px; background: transparent; color: #bdc9c2; text-align: left; cursor: pointer; }
.nav-item:hover, .nav-item.active { background: #344139; color: white; }
.logout { margin-top: auto; }
.sidebar form { margin-top: auto; }

.workspace { min-width: 0; padding: 26px clamp(18px, 3vw, 42px) 60px; }
.topbar, .section-heading, .toolbar, .dialog-actions, .merchant-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.topbar { padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.system-pill, .status-badge { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 999px; background: white; padding: 8px 12px; font-size: 13px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #2b9369; }
.status-dot.warning { background: #c18a16; }
.status-dot.danger { background: var(--danger); }
.view { display: none; padding-top: 24px; }
.view.active { display: block; }

.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(130px, 1fr)); border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.metric { min-height: 112px; padding: 20px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric strong { display: block; margin-top: 12px; font-size: 30px; font-weight: 700; }
.metric span { color: var(--muted); font-size: 13px; }
.event-category-metrics { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
.content-band.event-evaluation { border-bottom: 0; }
.event-evaluation-metrics { grid-template-columns: repeat(6, minmax(112px, 1fr)); margin-bottom: 20px; }
.event-evaluation-metrics .metric { min-height: 98px; padding: 16px; }
.event-evaluation-metrics .metric strong { font-size: 25px; }
.content-band { margin-top: 24px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 24px 0; }
.import-history { border-bottom: 0; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; padding: 22px 0 0; margin: 0; list-style: none; }
.steps li { display: flex; gap: 13px; align-items: flex-start; }
.steps li > span { flex: 0 0 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: #dfe9e4; color: var(--primary-dark); font-weight: 800; }
.steps p { margin: 5px 0 0; color: var(--muted); font-size: 14px; }
.steps.vertical { grid-template-columns: 1fr; }

.section-heading { margin-bottom: 18px; }
.toolbar { flex-wrap: wrap; }
.compact-label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.compact-label select { min-width: 190px; }
.event-filter-bar { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; margin: 0 0 16px; }
.event-filter-fields, .event-filter-actions, .event-label-actions { display: flex; align-items: center; gap: 8px; }
.event-filter-fields { flex-wrap: wrap; }
.event-filter-fields .compact-label { display: grid; gap: 6px; white-space: normal; }
.event-filter-fields .compact-label select { min-width: 180px; }
.event-label-actions { min-width: 250px; flex-wrap: wrap; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 13px 15px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; font-size: 14px; }
th { background: #f7f9f8; color: var(--muted); font-size: 12px; font-weight: 700; }
tbody tr:last-child td { border-bottom: 0; }
.url { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event-table { min-width: 1060px; }
.event-table th:last-child, .event-table td:last-child { width: 270px; }
.event-time { min-width: 148px; white-space: nowrap; }
.event-path { max-width: 190px; }
.event-feature { min-width: 210px; max-width: 250px; overflow-wrap: anywhere; color: #435048; font-size: 13px; }
.event-score { margin-top: 6px; font-size: 12px; white-space: nowrap; }
.event-empty { height: 96px; text-align: center; }
.event-pagination { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.event-page-status { min-width: 92px; color: var(--muted); font-size: 13px; text-align: center; }
.tag { display: inline-flex; align-items: center; min-height: 25px; padding: 3px 8px; border-radius: 999px; background: #edf1ef; color: #4b5851; font-size: 12px; font-weight: 700; }
.tag.success, .status-ready { background: var(--success-bg); color: var(--primary-dark); }
.tag.warning, .status-waiting { background: var(--warning-bg); color: #755812; }
.tag.danger { background: var(--danger-bg); color: var(--danger); }

.button { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid #bac5bf; border-radius: 5px; padding: 0 14px; background: white; color: var(--ink); text-decoration: none; cursor: pointer; font-weight: 700; font-size: 14px; }
.button:hover { background: #f2f5f3; }
.button-primary { border-color: var(--primary); background: var(--primary); color: white; }
.button-primary:hover { background: var(--primary-dark); }
.button-small { min-height: 32px; padding: 0 9px; font-size: 12px; }
.button:disabled { cursor: wait; opacity: .55; }
.event-label-button.active { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); color: var(--primary-dark); background: var(--success-bg); }
.event-label-button.active[data-review-label="bot"] { border-color: var(--danger); box-shadow: inset 0 0 0 1px var(--danger); color: var(--danger); background: var(--danger-bg); }
.event-label-button.active[data-review-label="unknown"] { border-color: #9b7418; box-shadow: inset 0 0 0 1px #9b7418; color: #755812; background: var(--warning-bg); }
.button-wide { width: 100%; }
.icon-button { width: 44px; height: 44px; border: 0; background: transparent; font-size: 26px; cursor: pointer; }

dialog { width: min(540px, calc(100vw - 28px)); border: 1px solid var(--line); border-radius: var(--radius); padding: 0; box-shadow: 0 24px 70px rgba(20, 33, 27, .22); }
dialog::backdrop { background: rgba(18, 27, 23, .45); }
.wide-dialog { width: min(980px, calc(100vw - 28px)); }
.dialog-body { padding: 24px; }
.dialog-body label, .form-stack label { display: grid; gap: 7px; color: #435048; font-size: 13px; font-weight: 700; }
input, select { width: 100%; min-height: 42px; border: 1px solid #b8c3bd; border-radius: 4px; padding: 8px 10px; background: white; color: var(--ink); }
.form-stack { display: grid; gap: 16px; margin-top: 24px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.dialog-actions { margin-top: 22px; justify-content: flex-end; }
.file-drop { min-height: 110px; place-items: center; border: 1px dashed #9eaaa4; border-radius: var(--radius); background: #f7f9f8; cursor: pointer; }
.file-drop input { width: auto; min-height: auto; }
.preview-summary { margin: 0 0 14px; }
.preview-table { max-height: 390px; }

.notice { margin-top: 18px; border-left: 4px solid #547da9; padding: 12px 14px; background: var(--info-bg); font-size: 14px; }
.notice-error { border-color: var(--danger); background: var(--danger-bg); color: #74271f; }
.toast { position: fixed; z-index: 10; right: 24px; top: 22px; max-width: min(380px, calc(100vw - 48px)); padding: 12px 16px; border-radius: var(--radius); background: #202924; color: white; opacity: 0; transform: translateY(-8px); pointer-events: none; transition: .18s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

.login-shell, .merchant-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(420px, 100%); border-top: 4px solid var(--primary); padding: 34px; background: white; box-shadow: 0 18px 45px rgba(31, 49, 40, .10); }
.login-panel .brand-mark { margin-bottom: 24px; }
.merchant-shell { display: block; max-width: 900px; margin: 0 auto; }
.merchant-header { padding: 26px 0; border-bottom: 1px solid var(--line); }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 12px; }
  .brand { padding-bottom: 10px; }
  nav { grid-template-columns: repeat(5, minmax(96px, 1fr)); overflow-x: auto; }
  .sidebar form { display: none; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .event-category-metrics, .event-evaluation-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metric { border-bottom: 1px solid var(--line); }
  .steps { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  nav { grid-template-columns: repeat(3, minmax(0, 1fr)); overflow-x: visible; }
  .nav-item { min-height: 40px; padding: 0 8px; text-align: center; white-space: nowrap; }
  .workspace { padding: 18px 14px 40px; }
  .topbar, .section-heading, .merchant-header { align-items: flex-start; flex-direction: column; }
  .metric-grid { grid-template-columns: 1fr; }
  .event-category-metrics { grid-template-columns: 1fr; }
  .event-evaluation-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { min-height: 88px; border-right: 0; }
  .event-evaluation-metrics .metric { min-height: 82px; padding: 14px; border-right: 1px solid var(--line); }
  .event-evaluation-metrics .metric:nth-child(2n) { border-right: 0; }
  .event-evaluation-metrics .metric strong { font-size: 23px; }
  .event-filter-bar, .event-filter-fields, .event-filter-actions { width: 100%; }
  .event-filter-bar { align-items: stretch; flex-direction: column; }
  .event-filter-fields { display: grid; grid-template-columns: 1fr; }
  .event-filter-fields .compact-label select { min-width: 0; }
  .event-filter-actions .button { flex: 1; }
  .event-table-wrap { max-width: calc(100vw - 28px); overflow: visible; }
  .event-table { min-width: 0; }
  .event-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .event-table, .event-table tbody, .event-table tr, .event-table td { display: block; width: 100%; }
  .event-table tbody tr { padding: 7px 0; border-bottom: 1px solid var(--line); }
  .event-table tbody tr:last-child { border-bottom: 0; }
  .event-table td, .event-table th:last-child, .event-table td:last-child {
    width: 100%;
    min-width: 0;
    max-width: none;
  }
  .event-table td { display: grid; grid-template-columns: 78px minmax(0, 1fr); gap: 10px; align-items: start; padding: 9px 12px; border-bottom: 0; white-space: normal; }
  .event-table td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 700; }
  .event-table .event-feature, .event-table .event-path { min-width: 0; max-width: none; overflow-wrap: anywhere; }
  .event-table .event-empty { display: block; height: auto; padding: 28px 12px; text-align: center; }
  .event-table .event-empty::before { display: none; }
  .event-label-actions { min-width: 0; }
  .event-label-actions .button { flex: 1; min-width: 0; padding: 0 6px; }
  .event-pagination { justify-content: space-between; }
  .event-pagination .button { min-width: 88px; }
  .field-grid { grid-template-columns: 1fr; }
  .dialog-body { padding: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
