:root {
  --ink: #10233a;
  --ink-soft: #4b6074;
  --muted: #7a8b9c;
  --line: #e4ebf2;
  --line-strong: #d5dee8;
  --bg: #eef3f8;
  --card: #ffffff;
  --primary: #1478c8;
  --primary-deep: #0b4f86;
  --primary-soft: #e8f3fb;
  --up: #0f9d58;
  --up-soft: #e8f8ef;
  --down: #d93025;
  --down-soft: #fdecea;
  --warn: #d48806;
  --warn-soft: #fff7e6;
  --shadow: 0 1px 2px rgba(16, 35, 58, 0.04), 0 8px 24px rgba(16, 35, 58, 0.06);
  --radius: 12px;
  --header-h: 64px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "DIN Alternate", "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}

.app { height: 100%; display: flex; flex-direction: column; }

.topbar {
  height: var(--header-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px 0 18px;
  background: linear-gradient(180deg, #0d3a63 0%, #0b4f86 100%);
  color: #fff;
  z-index: 40;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 196px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: rgba(255,255,255,.12);
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; padding: 8px;
}
.brand-mark span { background: #7ec8ff; border-radius: 1px; }
.brand-mark span:nth-child(1) { height: 10px; align-self: end; }
.brand-mark span:nth-child(2) { height: 16px; align-self: end; background: #fff; }
.brand-mark span:nth-child(3) { height: 7px; align-self: end; background: #f7c948; }
.brand-title { font-size: 14px; font-weight: 700; letter-spacing: .02em; }
.brand-sub { font-size: 11px; opacity: .7; margin-top: 1px; }

.level-stepper {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  min-width: 0;
  gap: 2px 0;
  row-gap: 4px;
}
.step {
  display: flex; align-items: center; gap: 8px;
  color: rgba(255,255,255,.55); font-size: 12px; white-space: nowrap;
}
.step-index {
  width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.35);
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
}
.step.done .step-index { background: rgba(255,255,255,.18); color: #fff; border-color: transparent; }
.step.current { color: #fff; font-weight: 600; }
.step.current .step-index { background: #fff; color: var(--primary-deep); border-color: #fff; }
.step-line {
  width: 14px; height: 1px; background: rgba(255,255,255,.28); margin: 0 4px;
}

.topbar-right { display: flex; align-items: center; gap: 12px; }
.role-switch {
  display: flex; background: rgba(255,255,255,.1); border-radius: 8px; padding: 3px;
}
.role-btn {
  border: 0; background: transparent; color: rgba(255,255,255,.75);
  padding: 5px 12px; border-radius: 6px; font-size: 12px;
}
.role-btn.active { background: #fff; color: var(--primary-deep); font-weight: 600; }
.user-chip { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: #7ec8ff; color: var(--primary-deep);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.user-name { font-size: 13px; font-weight: 600; line-height: 1.2; }
.user-title { font-size: 11px; opacity: .65; }

.workspace {
  flex: 1; overflow: auto; padding: 0 20px 24px;
}
.sticky-stack {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  padding-top: 12px; margin: 0 -20px; padding-left: 20px; padding-right: 20px;
}

.crumb-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; min-height: 36px; margin-bottom: 10px;
}
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 13px; }
.crumb {
  border: 0; background: none; color: var(--primary); padding: 2px 4px; border-radius: 4px;
}
.crumb:hover { background: var(--primary-soft); }
.crumb.current { color: var(--ink); font-weight: 600; cursor: default; }
.crumb-sep { color: var(--muted); font-size: 12px; }
.crumb-actions { display: flex; gap: 8px; }

.filter-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px; box-shadow: var(--shadow); margin-bottom: 12px;
}
.filter-group { display: flex; align-items: center; gap: 8px; }
.filter-group.dim-switch {
  background: var(--primary-soft); padding: 4px 10px 4px 8px; border-radius: 10px;
}
.seg-dim .seg-btn { font-weight: 600; padding: 6px 10px; }
.filter-label { font-size: 12px; color: var(--ink-soft); white-space: nowrap; }
.filter-spacer { flex: 1; }
.custom-dates { background: var(--primary-soft); padding: 4px 8px; border-radius: 8px; }
.tilde { color: var(--muted); font-size: 12px; }

.seg { display: flex; background: #f3f6f9; border-radius: 8px; padding: 3px; gap: 2px; }
.seg-btn {
  border: 0; background: transparent; color: var(--ink-soft);
  padding: 5px 10px; border-radius: 6px; font-size: 12px; white-space: nowrap;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.active { background: #fff; color: var(--primary-deep); font-weight: 600; box-shadow: 0 1px 3px rgba(16,35,58,.08); }

.select, .search-field input, .custom-dates input[type=date] {
  height: 32px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: #fff; padding: 0 10px; min-width: 148px; outline: none;
}
.select:focus, .search-field input:focus, .custom-dates input:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(20,120,200,.12);
}

.dropdown { position: relative; }
.dropdown-trigger { min-width: 168px; text-align: left; cursor: pointer; }
.dropdown-panel {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 8px; min-width: 220px;
}
.drop-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; border-radius: 6px; font-size: 13px; cursor: pointer;
}
.drop-item:hover { background: #f5f8fb; }
.drop-item input { accent-color: var(--primary); }
.drop-actions {
  display: flex; justify-content: flex-end; gap: 6px;
  padding: 6px 4px 2px; border-top: 1px solid var(--line); margin-top: 4px;
}

.btn {
  height: 32px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: #fff; color: var(--ink);
  font-size: 13px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #1b86d9; color: #fff; }
.btn-sm { height: 28px; font-size: 12px; padding: 0 10px; }
.btn-ghost {
  background: transparent; border-color: transparent; color: inherit; height: auto; padding: 4px 8px;
}
.topbar .btn-ghost { color: rgba(255,255,255,.85); }
.topbar .btn-ghost:hover { background: rgba(255,255,255,.1); color: #fff; }
.icon-btn {
  width: 32px; height: 32px; border: 0; background: #f3f6f9; border-radius: 8px; font-size: 18px; color: var(--ink-soft);
}
.icon-btn:hover { background: #e8eef4; color: var(--ink); }

.guide {
  display: flex; align-items: flex-start; gap: 10px;
  background: linear-gradient(90deg, #e8f3fb, #fff);
  border: 1px solid #cfe4f5; border-radius: 10px;
  padding: 10px 14px; margin-bottom: 14px; color: var(--ink-soft); font-size: 13px;
}
.guide strong { color: var(--primary-deep); }
.guide-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--primary);
  margin-top: 6px; flex-shrink: 0; box-shadow: 0 0 0 4px rgba(20,120,200,.16);
}
.guide-close { margin-left: auto; border: 0; background: none; font-size: 18px; color: var(--muted); padding: 0 4px; }
.guide[hidden] { display: none; }

.table-panel {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); overflow: hidden;
}
.table-toolbar {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 16px 18px 10px;
}
.table-title-block h2 { font-size: 16px; }
.table-desc { font-size: 12px; color: var(--muted); margin-top: 4px; }
.table-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.search-field input { min-width: 220px; }
.row-count { font-size: 12px; color: var(--muted); }

.delta {
  font-size: 11px; font-weight: 600; display: inline-flex; align-items: center; gap: 2px;
  padding: 1px 6px; border-radius: 999px;
}
.delta.up { color: var(--up); background: var(--up-soft); }
.delta.down { color: var(--down); background: var(--down-soft); }
.delta.flat { color: var(--muted); background: #f3f6f9; }

.table-scroll { overflow: auto; max-height: calc(100vh - 260px); min-height: 320px; }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.data-table th {
  position: sticky; top: 0; z-index: 5;
  background: #f7fafc; color: var(--ink-soft); font-weight: 600;
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line);
  white-space: nowrap; user-select: none;
}
.data-table th.sortable { cursor: pointer; }
.data-table th.sortable:hover { color: var(--primary); }
.data-table th .sort { color: var(--muted); margin-left: 4px; font-size: 11px; }
.data-table th.is-sorted { color: var(--primary-deep); background: #eef6fc; }
.data-table th.num, .data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table th.hl, .data-table td.hl { background: #f3f9fd; }
.data-table td {
  padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; background: #fff;
}
.data-table tbody tr:hover td { background: #f4f9fd; }
.data-table tbody tr.clickable { cursor: pointer; }
.data-table tbody tr.clickable:hover td.name-cell .name-link { text-decoration: underline; }

.row-summary td {
  background: #f0f7fc !important;
  font-weight: 700;
  border-bottom: 1px solid #cfe4f5;
  position: sticky; top: 41px; z-index: 4;
  vertical-align: top;
  padding-top: 12px;
  padding-bottom: 12px;
}
.row-summary.row-alert td { background: #fff4f2 !important; }
.sum-val {
  font-family: var(--mono); font-size: 16px; font-weight: 700; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; line-height: 1.2;
}
.sum-val.up { color: var(--up); }
.sum-val.down { color: var(--down); }
.sum-trends { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; margin-top: 6px; }
.sum-note { font-size: 11px; font-weight: 500; color: var(--muted); margin-top: 4px; }
.sum-muted { color: var(--muted); font-size: 13px; }
.row-summary .grade-stack { justify-content: flex-start; }
.row-alert td { background: #fff8f7; }
.row-alert:hover td { background: #ffefed; }

.col-sticky { position: sticky; left: 0; z-index: 3; }
.col-sticky-2 { position: sticky; left: 52px; z-index: 3; box-shadow: 8px 0 8px -8px rgba(16,35,58,.12); }
th.col-sticky, th.col-sticky-2 { z-index: 6; }
.row-summary .col-sticky, .row-summary .col-sticky-2 { z-index: 5; }

.rank {
  width: 28px; height: 22px; border-radius: 6px; display: inline-grid; place-items: center;
  font-size: 12px; font-weight: 700; background: #f3f6f9; color: var(--ink-soft);
}
.rank.r1 { background: #fff3d6; color: #9a6b00; }
.rank.r2 { background: #eef1f5; color: #5c6b7a; }
.rank.r3 { background: #f6e6d8; color: #8a4b24; }

.name-cell { min-width: 248px; }
.name-main { display: flex; align-items: center; gap: 8px; }
.name-link { color: var(--ink); font-weight: 600; }
.sub-name { font-size: 11px; color: var(--muted); margin-top: 2px; }

.tree-name { display: flex; align-items: flex-start; gap: 8px; }
.tree-toggle {
  width: 22px; height: 22px; flex: 0 0 22px; margin-top: 1px;
  border: 0; background: #e8eef4; border-radius: 5px;
  font-size: 9px; line-height: 22px; color: var(--ink-soft); cursor: pointer;
}
.tree-toggle:hover { background: #d7e6f2; color: var(--primary-deep); }
.tree-toggle.is-open { background: #d6ebf8; color: var(--primary-deep); }
.tree-leaf { background: transparent; pointer-events: none; }
.type-pill {
  display: inline-flex; align-items: center; padding: 0 6px; height: 18px;
  border-radius: 4px; font-size: 10px; font-weight: 700; letter-spacing: .02em;
  background: #eef4f8; color: var(--ink-soft); flex: 0 0 auto;
}
.type-pill.type-region { background: #e8f3fb; color: #1d6fa3; }
.type-pill.type-sales { background: #eef2ff; color: #3f5bd9; }
.type-pill.type-org { background: #eef8f0; color: #2f7a46; }
.type-pill.type-group { background: #fff7e6; color: #b76a00; }
.type-pill.type-customer { background: #f4f0ff; color: #6b4bb3; }
.type-pill.type-other { background: #fff1f0; color: #cf1322; }
.type-pill.type-province, .type-pill.type-city { background: #e8f3fb; color: #1d6fa3; }
.type-pill.type-campus, .type-pill.type-building { background: #f3f6f9; color: #5c6b7a; }
.type-pill.type-floor, .type-pill.type-room { background: #fff7e6; color: #b76a00; }
.data-table tbody tr.depth-1 td { background: #fbfcfd; }
.data-table tbody tr.depth-2 td { background: #f7fafc; }
.data-table tbody tr.depth-3 td { background: #f3f7fa; }
.data-table tbody tr.depth-4 td { background: #eef4f8; }
.data-table tbody tr.depth-1:hover td,
.data-table tbody tr.depth-2:hover td,
.data-table tbody tr.depth-3:hover td,
.data-table tbody tr.depth-4:hover td { background: #f4f9fd; }
.share {
  display: block; height: 4px; background: #e8eef4; border-radius: 99px; margin-top: 6px; overflow: hidden; max-width: 120px; margin-left: auto;
}
.share > i { display: block; height: 100%; background: #79b7e0; }
.share-num { font-size: 11px; color: var(--muted); font-weight: 500; }

.grade-tag, .status-tag {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.grade-S { background: #fff1f0; color: #cf1322; }
.grade-A { background: #fff7e6; color: #d48806; }
.grade-B { background: #f3f6f9; color: #5c6b7a; }
.status-tag.st-new { background: #eef2ff; color: #3f5bd9; }
.status-tag.st-follow { background: #fff7e6; color: #d48806; }
.status-tag.st-won { background: var(--up-soft); color: var(--up); }
.status-tag.st-lost { background: #f5f5f5; color: #8c8c8c; }
.grade-stack { display: flex; flex-wrap: wrap; gap: 4px; }

.op-btns { display: flex; gap: 6px; justify-content: flex-end; }
.link-btn {
  border: 0; background: none; color: var(--primary); font-size: 12px; padding: 0 2px;
}
.link-btn:hover { text-decoration: underline; }
.link-btn.muted { color: var(--muted); }
.link-btn.todo-link { font-weight: 700; }

.todo-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.todo-table th, .todo-table td {
  text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: top;
}
.todo-table th { color: var(--muted); font-weight: 600; background: #f7fafc; }

.warn-dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--down); margin-right: 4px; vertical-align: middle;
}

.empty { text-align: center; padding: 64px 20px; color: var(--ink-soft); }
.empty-icon { font-size: 36px; color: #c5d2de; margin-bottom: 8px; }
.empty h3 { font-size: 15px; color: var(--ink); margin-bottom: 6px; }

.page-foot {
  text-align: center; color: var(--muted); font-size: 12px; padding: 16px 8px 8px;
}

.drawer { position: fixed; inset: 0; z-index: 80; pointer-events: none; }
.drawer.open { pointer-events: auto; }
.drawer-backdrop {
  position: absolute; inset: 0; background: rgba(16,35,58,.36); opacity: 0; transition: opacity .2s;
}
.drawer.open .drawer-backdrop { opacity: 1; }
.drawer-panel {
  position: absolute; top: 0; right: 0; height: 100%; width: min(560px, 94vw);
  background: #fff; transform: translateX(100%); transition: transform .28s cubic-bezier(.2,.8,.2,1);
  display: flex; flex-direction: column; box-shadow: -8px 0 32px rgba(16,35,58,.16);
}
.drawer.open .drawer-panel { transform: translateX(0); }
.drawer-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 18px 18px 12px; border-bottom: 1px solid var(--line);
}
.drawer-kicker { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.drawer-body { padding: 16px 18px 24px; overflow: auto; }
.dl-grid { display: grid; grid-template-columns: 88px 1fr; gap: 8px 12px; font-size: 13px; }
.dl-grid dt { color: var(--muted); }
.mini-kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0; }
.mini-kpi { background: #f7fafc; border-radius: 10px; padding: 10px 12px; }
.mini-kpi span { display: block; font-size: 12px; color: var(--muted); }
.mini-kpi b { font-size: 16px; }
.timeline { margin-top: 8px; }
.tl-item { display: flex; gap: 10px; padding: 8px 0; }
.tl-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); margin-top: 6px; flex-shrink: 0; }
.tl-item p { font-size: 13px; }
.tl-item time { font-size: 12px; color: var(--muted); }

.modal { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(16,35,58,.4); }
.modal-panel {
  position: relative; width: min(560px, 92vw); background: #fff; border-radius: 14px;
  box-shadow: var(--shadow); max-height: 80vh; overflow: auto;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 16px 18px 22px; }
.help-item { margin-bottom: 12px; }
.help-item h4 { font-size: 13px; margin-bottom: 4px; }
.help-item p { font-size: 13px; color: var(--ink-soft); }

.toast-host {
  position: fixed; top: 76px; right: 20px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 10px;
  font-size: 13px; box-shadow: var(--shadow); animation: slidein .2s ease;
}
@keyframes slidein { from { transform: translateX(12px); opacity: 0; } to { transform: none; opacity: 1; } }

.table-scroll.loading { opacity: .55; pointer-events: none; }

@media (max-width: 1400px) {
  .level-stepper { display: none; }
}
@media (max-width: 960px) {
  .brand-sub { display: none; }
  .user-chip div:last-child { display: none; }
  .table-toolbar { flex-direction: column; }
}
