:root {
  --bg: #f7f9fc;
  --panel: #ffffff;
  --line: #e3e9f2;
  --line-soft: #eef2f8;
  --text: #0f172a;
  --muted: #64748b;
  --weak: #94a3b8;
  --primary: #1e40af;
  --primary-soft: #eaf0ff;
  --blue: #2563eb;
  --green: #15803d;
  --green-soft: #e7f6ec;
  --amber: #b45309;
  --amber-soft: #fff4e2;
  --red: #dc2626;
  --red-soft: #fdecec;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .03);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* ---------------------------------------------------------------- layout */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 228px; flex: 0 0 228px; background: var(--panel);
  border-right: 1px solid var(--line); padding: 18px 12px 14px;
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
}
.brand { padding: 0 8px 12px; border-bottom: 1px solid var(--line-soft); }
.brand h1 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: .2px; }
.brand .sub { margin-top: 3px; font-size: 11px; color: var(--weak); }

.nav { flex: 1; overflow-y: auto; min-height: 0; display: flex; flex-direction: column; padding-top: 10px; }
.nav::-webkit-scrollbar { width: 6px; }
.nav::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 3px; }

.nav-overview {
  padding: 8px 10px; border-radius: 8px; font-size: 13.5px; font-weight: 600; color: #334155;
}
.nav-overview:hover { background: #f4f7fb; }
.nav-overview.active { background: var(--primary-soft); color: var(--primary); }

.nav-label {
  margin: 14px 10px 5px; font-size: 11px; font-weight: 700;
  color: var(--weak); letter-spacing: .06em;
}
.nav-item, .nav-dir {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px 6px 18px; border-radius: 7px; font-size: 13px; color: #475569;
}
.nav-dir { padding-left: 10px; font-weight: 600; color: #334155; margin-top: 8px; }
.nav-item:hover, .nav-dir:hover { background: #f4f7fb; }
.nav-item.active, .nav-dir.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-item .count, .nav-dir .count { font-size: 11px; color: var(--weak); font-variant-numeric: tabular-nums; }

.sidebar-foot { border-top: 1px solid var(--line-soft); padding-top: 10px; }
.foot-link { display: block; font-size: 13px; color: #475569; padding: 5px 0; }
.foot-link:hover, .foot-link.active { color: var(--primary); }
.who { margin-top: 6px; }
.who .name { font-size: 13px; font-weight: 600; }
.who .role { font-size: 11px; color: var(--weak); margin-top: 1px; }
.link-btn { background: none; border: none; color: var(--muted); padding: 5px 0; font-size: 12.5px; }
.link-btn:hover { color: var(--primary); }

.main { flex: 1; min-width: 0; padding: 24px 30px 56px; }
.main-inner { max-width: 1460px; margin: 0 auto; }

/* ---------------------------------------------------------------- header */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.2px; }
.page-head .desc { margin-top: 5px; color: var(--muted); font-size: 12.5px; }
.head-tools { display: flex; gap: 10px; align-items: center; }

.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.back-btn {
  display: inline-flex; align-items: center; height: 30px; padding: 0 11px;
  border-radius: 8px; border: 1px solid var(--line); background: #fff;
  font-size: 12.5px; color: #475569;
}
.back-btn:hover { border-color: #bfd3f8; color: var(--primary); }
.crumb-sep { color: #cbd5e1; }
.crumb-now { font-size: 12.5px; color: var(--muted); }

.meta-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip { padding: 3px 10px; border-radius: 999px; background: #f1f5f9; color: #475569; font-size: 12px; }
.chip-warn { background: var(--amber-soft); color: var(--amber); }

/* ---------------------------------------------------------------- KPI */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 18px 0 24px; }
.kpi {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .value { font-size: 27px; font-weight: 700; margin-top: 4px; letter-spacing: -.6px; font-variant-numeric: tabular-nums; }
.kpi .hint { color: var(--weak); font-size: 11.5px; margin-top: 2px; }
.kpi.primary { border-color: #c9d8fb; background: linear-gradient(180deg, #f6f9ff, #fff); }
.kpi.warn .value { color: var(--amber); }

/* ---------------------------------------------------------------- groups & cards */
.group-block { margin-bottom: 26px; }
.group-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.group-head h3 { margin: 0; font-size: 14px; font-weight: 700; color: #1e293b; }
.group-head span { font-size: 12px; color: var(--weak); }

.track-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(252px, 1fr)); gap: 12px; }

.track-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 15px 12px; box-shadow: var(--shadow); cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .15s;
  display: flex; flex-direction: column; gap: 10px;
}
.track-card:hover { border-color: #bfd3f8; box-shadow: 0 4px 14px rgba(30, 64, 175, .07); transform: translateY(-1px); }

.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.card-head h3 { margin: 0; font-size: 13.5px; font-weight: 600; }
.card-head .muted { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.card-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.card-stats div { display: flex; flex-direction: column; gap: 1px; }
.card-stats b { font-size: 19px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.card-stats b.warn { color: var(--amber); }
.card-stats span { font-size: 11px; color: var(--weak); }

.bar { height: 5px; border-radius: 3px; background: #eef2f8; overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; }
.bar .ok { background: #16a34a; }
.bar .near { background: #f59e0b; }
.card-foot { font-size: 11px; color: var(--weak); }

.track-card.brand { grid-column: 1 / -1; gap: 8px; }
.brand-value { font-size: 30px; font-weight: 700; letter-spacing: -.8px; font-variant-numeric: tabular-nums; }
.progress { height: 8px; border-radius: 5px; background: #eaf0fb; overflow: hidden; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, #3b82f6, #1e40af); border-radius: 5px; }

.note-line {
  margin-top: 8px; padding: 10px 12px; border: 1px dashed var(--line);
  border-radius: 9px; background: #fbfcfe; color: var(--muted); font-size: 12px;
}

/* ---------------------------------------------------------------- panel & table */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; margin-top: 16px;
}
.panel-head { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); display: flex; justify-content: space-between; align-items: center; }
.panel-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.panel-head .hint { color: var(--weak); font-size: 11.5px; }

.table-note {
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  padding: 8px 12px; border-bottom: 1px solid var(--line-soft);
  font-size: 11.5px; color: var(--muted); background: #fcfdff;
}
.table-note .dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }
.table-note .dot.ok { background: #bbf7d0; }
.table-note .dot.pending { background: #fde68a; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 9px; text-align: left; border-bottom: 1px solid var(--line-soft); white-space: nowrap; vertical-align: middle; }
th { background: #f8fafc; color: var(--muted); font-size: 11.5px; font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover td { background: #f8fbff; }
tbody tr.clickable { cursor: pointer; }
tbody tr.row-ok td { background: #f4fbf6; }
tbody tr.row-pending td { background: #fffaf1; }
tbody tr.row-ok:hover td { background: #ecf8f0; }
tbody tr.row-pending:hover td { background: #fff5e4; }
td.key { font-weight: 700; color: #0f172a; }
td.num.gap { color: var(--amber); font-weight: 600; }
td.name { max-width: 240px; }
td.note { white-space: normal; min-width: 190px; max-width: 320px; }
td.note .notetext { color: var(--muted); line-height: 1.45; font-size: 12px; }
.empty { padding: 30px; text-align: center; color: var(--weak); }

span.obj, span.nm {
  display: inline-block; max-width: 200px; white-space: normal;
  word-break: break-all; font-size: 12px; line-height: 1.4;
}

.panel.scrollable .table-wrap { max-height: calc(100vh - 320px); overflow: auto; }
.panel.scrollable thead th { position: sticky; top: 0; z-index: 3; box-shadow: inset 0 -1px 0 var(--line); }

/* ---------------------------------------------------------------- tags */
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; line-height: 1.7; background: #f1f5f9; color: #475569; }
.tier-T0 { background: #f1f5f9; color: #64748b; }
.tier-T1 { background: #e8efff; color: #1e40af; }
.tier-T2 { background: #e6f6ec; color: #15803d; }
.tier-T3 { background: #dcf3e4; color: #0f6b38; }
.tier-T4, .tier-T5 { background: #c9edd8; color: #0b5c30; }
.tier-pending { background: var(--amber-soft); color: var(--amber); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------------------------------------------------------------- rules & filters */
.rules-panel { margin-top: 14px; padding: 10px 14px; border: 1px solid var(--line); background: #fbfcfe; border-radius: 10px; }
.rules-panel summary { cursor: pointer; font-size: 13px; font-weight: 600; list-style: none; display: flex; align-items: baseline; gap: 10px; }
.rules-panel summary::-webkit-details-marker { display: none; }
.rules-panel summary::before { content: "▸"; color: var(--weak); font-size: 11px; }
.rules-panel[open] summary::before { content: "▾"; }
.rules-panel summary .hint { font-weight: 400; color: var(--weak); font-size: 11.5px; }
.rules-panel ul { margin: 8px 0 2px; padding-left: 18px; columns: 2; column-gap: 32px; font-size: 12.5px; line-height: 1.75; color: #475569; }
@media (max-width: 1180px) { .rules-panel ul { columns: 1; } }

.filters {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  margin-top: 14px; padding: 9px 11px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 6;
}
.inline-input, .inline-select {
  height: 34px; width: auto; min-width: 150px; border-radius: 8px;
  border: 1px solid var(--line); background: #fff; padding: 0 10px; font: inherit; font-size: 13px;
}
.inline-select { min-width: 128px; }

select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' fill='none' stroke='%2364748b' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 12px 12px;
  padding-right: 30px;
}

/* ---------------------------------------------------------------- search */
.search-box { position: relative; display: inline-block; }
.search-results {
  position: absolute; right: 0; top: 40px; width: 320px; z-index: 20;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, .12); overflow: hidden;
}
.sr-item { display: flex; justify-content: space-between; gap: 12px; padding: 9px 12px; font-size: 13px; cursor: pointer; }
.sr-item:hover { background: var(--primary-soft); }
.sr-item b { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.sr-empty { padding: 12px; font-size: 13px; color: var(--muted); }

/* ---------------------------------------------------------------- login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: 0 8px 24px rgba(15, 23, 42, .08); }
.login-card h1 { margin: 0 0 6px; font-size: 20px; }
.login-card p { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.login-dev { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
input, select { font: inherit; color: var(--text); }
.field input, .login-dev select { width: 100%; height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.btn { display: inline-flex; align-items: center; justify-content: center; height: 38px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--text); font-weight: 600; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; width: 100%; }
.btn.small { height: 30px; padding: 0 10px; font-size: 12px; font-weight: 500; }
.btn:hover { filter: brightness(.98); }
.error { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---------------------------------------------------------------- customer tabs */
.scope-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 2px; }
.scope-tab { height: 32px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: #475569; font-size: 13px; }
.scope-tab:hover { border-color: #bfd3f8; color: var(--primary); }
.scope-tab.active { background: var(--primary-soft); border-color: #c9d8fb; color: var(--primary); font-weight: 600; }

@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sidebar { width: 200px; flex-basis: 200px; }
  .main { padding: 18px; }
}

.card-stats.two { grid-template-columns: repeat(2, 1fr); }

.track-summary {
  display: flex; align-items: center; gap: 26px; flex-wrap: wrap;
  margin-top: 14px; padding: 12px 16px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.ts-item { display: flex; flex-direction: column; gap: 1px; }
.ts-item span { font-size: 11px; color: var(--weak); }
.ts-item b { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ts-item.ok b { color: var(--green); }
.ts-tiers { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.tier-chip { padding: 2px 9px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: 12px; font-weight: 600; }
.brand-summary { display: grid; grid-template-columns: 1fr auto; gap: 6px 18px; align-items: end; }
.brand-summary .progress { grid-column: 1 / -1; }
.ts-main .ts-label { font-size: 12px; color: var(--muted); }
.ts-main .ts-value { font-size: 30px; font-weight: 700; letter-spacing: -.8px; font-variant-numeric: tabular-nums; }
.ts-side { text-align: right; font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
