:root {
  color-scheme: light;
  --ink: #252620;
  --ink-soft: #5f6058;
  --muted: #8b8b82;
  --paper: #f6f5f1;
  --surface: #fffefa;
  --line: #deddd5;
  --line-strong: #c9c7bd;
  --dark: #1b1b17;
  --dark-2: #24231e;
  --gold: #b78650;
  --gold-soft: #e9d1ae;
  --gold-pale: #f5eadb;
  --green: #4e765f;
  --red: #a65343;
  --shadow: 0 14px 40px rgba(34, 31, 24, .06);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--paper); }
body { margin: 0; min-width: 320px; color: var(--ink); background: var(--paper); }
button, input, select { font: inherit; }
button, select, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; left: 16px; top: -80px; z-index: 100; background: #fff; color: #111; padding: 12px 16px; }
.skip-link:focus { top: 16px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 226px minmax(0, 1fr); }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 226px; padding: 28px 18px 22px; background: var(--dark); color: #f5f2e9; display: flex; flex-direction: column; border-right: 1px solid rgba(255,255,255,.06); z-index: 20; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 10px 34px; }
.brand-mark { width: 39px; height: 39px; display: grid; place-items: center; border: 1px solid rgba(231, 189, 133, .4); border-radius: 9px; color: #e5bb82; font-family: Georgia, serif; font-size: 21px; box-shadow: inset 0 0 18px rgba(201, 143, 78, .16); }
.brand strong { display: block; font-size: 19px; letter-spacing: .12em; }
.brand small { display: block; margin-top: 3px; color: #aaa79d; font-size: 10px; letter-spacing: .2em; }
.side-nav { display: grid; gap: 7px; }
.nav-item { width: 100%; border: 0; background: transparent; color: #aaa99f; padding: 12px 13px; border-radius: 8px; text-align: left; cursor: pointer; display: flex; align-items: center; gap: 11px; transition: background .18s, color .18s; }
.nav-item:hover { color: #fffdf5; background: rgba(255,255,255,.05); }
.nav-item.is-active { color: #fffaf0; background: rgba(205, 161, 101, .13); box-shadow: inset 2px 0 0 #d5a66b; }
.nav-icon { width: 22px; text-align: center; color: #d1aa74; font-size: 18px; }
.side-foot { margin-top: auto; padding: 16px 10px 0; border-top: 1px solid rgba(255,255,255,.08); }
.privacy-badge { color: #ded9ca; font-size: 12px; display: flex; align-items: center; gap: 8px; }
.privacy-badge span { width: 7px; height: 7px; border-radius: 50%; background: #78a48a; box-shadow: 0 0 0 4px rgba(120,164,138,.12); }
.side-foot p { margin: 8px 0 0; color: #77766e; font-size: 11px; }

.main-content { grid-column: 2; min-width: 0; padding: 0 34px 56px; }
.topbar { min-height: 112px; display: flex; align-items: center; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--line); }
.eyebrow, .section-kicker, .panel-kicker { margin: 0 0 7px; color: var(--gold); font-size: 10px; font-weight: 700; letter-spacing: .17em; }
h1 { margin: 0; font-size: 29px; line-height: 1.15; letter-spacing: -.03em; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.date-filter { display: flex; align-items: center; gap: 8px; }
select, input[type="date"], input[type="search"] { border: 1px solid var(--line); background: rgba(255,255,255,.72); color: var(--ink); border-radius: 7px; min-height: 40px; padding: 0 12px; outline: 0; }
select:focus, input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(183,134,80,.12); }
.custom-range { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.custom-range button, .icon-button { min-height: 40px; border: 1px solid var(--line); background: var(--surface); border-radius: 7px; cursor: pointer; }
.custom-range button { padding: 0 13px; }
.icon-button { width: 40px; font-size: 21px; }
.icon-button.is-loading { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.user-chip { height: 40px; display: flex; align-items: center; gap: 9px; padding: 0 11px 0 5px; border: 1px solid var(--line); background: rgba(255,255,255,.55); border-radius: 20px; font-size: 12px; color: var(--ink-soft); max-width: 210px; }
.user-chip > span:first-child { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; color: #3e2d1c; background: var(--gold-soft); font-weight: 700; }
#user-email { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.notice { margin-top: 22px; border-left: 3px solid var(--gold); background: #f0e7d9; color: #5c4932; padding: 12px 15px; font-size: 13px; line-height: 1.6; }
.section-heading { margin: 34px 0 20px; display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.section-heading h2 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.section-heading > div > p:last-child { margin: 9px 0 0; color: var(--ink-soft); font-size: 13px; }
.updated-at { margin: 0; color: var(--muted); font-size: 12px; }
.kpi-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.kpi-card { min-height: 132px; padding: 17px 17px 15px; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; box-shadow: 0 4px 16px rgba(44,39,30,.025); position: relative; overflow: hidden; }
.kpi-card::after { content: ''; position: absolute; inset: auto 0 0; height: 3px; background: var(--gold-soft); transform: scaleX(var(--strength, .5)); transform-origin: left; }
.kpi-label { margin: 0; color: var(--ink-soft); font-size: 12px; display: flex; justify-content: space-between; gap: 8px; }
.kpi-value { margin: 17px 0 11px; font: 600 27px/1.1 Georgia, "Times New Roman", serif; letter-spacing: -.02em; }
.kpi-delta { margin: 0; color: var(--muted); font-size: 11px; }
.kpi-delta strong { color: var(--green); font-weight: 600; }
.kpi-delta strong.down { color: var(--red); }
.kpi-delta strong.neutral { color: var(--muted); }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(260px, .75fr); gap: 14px; margin-top: 14px; }
.dashboard-grid.lower-grid { grid-template-columns: minmax(0, 1.45fr) minmax(300px, .85fr); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 21px; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.panel-head h3 { margin: 0; font-size: 16px; }
.panel-kicker { margin-bottom: 5px; }
.segmented { display: inline-flex; background: #eeede7; border-radius: 7px; padding: 3px; }
.segmented button { border: 0; background: transparent; padding: 6px 10px; border-radius: 5px; color: var(--muted); font-size: 11px; cursor: pointer; }
.segmented button.is-active { color: var(--ink); background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.chart { margin-top: 16px; min-height: 255px; }
.chart svg { display: block; width: 100%; height: 255px; overflow: visible; }
.chart-grid { stroke: #e8e6df; stroke-width: 1; }
.chart-line { fill: none; stroke: #a86f38; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.chart-area { fill: #ead7bd; opacity: .45; }
.chart-dot { fill: var(--surface); stroke: #a86f38; stroke-width: 2; }
.chart-label { fill: #85847c; font-size: 10px; }
.chart-value { fill: #4f4e48; font-size: 10px; font-weight: 600; }
.chart-empty { height: 255px; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.live-pill { color: var(--green); background: #edf4ef; padding: 5px 8px; border-radius: 14px; font-size: 10px; }
.live-pill i { display: inline-block; width: 6px; height: 6px; margin-right: 4px; border-radius: 50%; background: var(--green); }
.health-list { display: grid; margin-top: 15px; }
.health-row { padding: 15px 0; border-bottom: 1px solid #ebe9e1; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.health-row:last-child { border-bottom: 0; }
.health-row span { display: block; color: var(--muted); font-size: 11px; margin-top: 4px; }
.health-row strong { font: 600 20px Georgia, serif; }

.funnel { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; margin-top: 26px; }
.funnel-step { position: relative; padding: 18px 14px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: #faf9f5; }
.funnel-step:first-child { border-left: 1px solid var(--line); border-radius: 8px 0 0 8px; }
.funnel-step:last-child { border-right: 1px solid var(--line); border-radius: 0 8px 8px 0; }
.funnel-step:not(:last-child)::after { content: ''; position: absolute; right: -7px; top: calc(50% - 7px); width: 13px; height: 13px; background: #faf9f5; border-top: 1px solid var(--line); border-right: 1px solid var(--line); transform: rotate(45deg); z-index: 2; }
.funnel-step span { color: var(--muted); font-size: 11px; }
.funnel-step strong { display: block; margin: 8px 0 4px; font: 600 24px Georgia, serif; }
.funnel-step small { color: var(--gold); font-size: 10px; }
.panel-note { margin: 16px 0 0; color: var(--muted); font-size: 11px; line-height: 1.6; }
.breakdowns { display: grid; gap: 22px; margin-top: 18px; }
.breakdown-group h4 { margin: 0 0 11px; font-size: 12px; font-weight: 600; }
.bar-row { display: grid; grid-template-columns: 72px 1fr 48px; align-items: center; gap: 10px; margin: 9px 0; font-size: 11px; color: var(--ink-soft); }
.bar-track { height: 6px; background: #eceae3; overflow: hidden; border-radius: 3px; }
.bar-fill { height: 100%; background: var(--gold); border-radius: 3px; }
.bar-row strong { text-align: right; font-weight: 600; color: var(--ink); }

.table-heading { align-items: center; }
.secondary-button { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 15px; border: 1px solid var(--line-strong); color: var(--ink); text-decoration: none; border-radius: 7px; background: var(--surface); font-size: 12px; }
.table-toolbar { display: flex; gap: 9px; margin-bottom: 12px; }
.table-toolbar input { flex: 1; max-width: 430px; }
.table-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.table-scroll { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 790px; }
th { padding: 12px 15px; background: #efeee8; color: #77766e; font-size: 10px; letter-spacing: .08em; text-align: left; font-weight: 600; }
td { padding: 15px; border-top: 1px solid #e8e6df; color: var(--ink-soft); font-size: 12px; vertical-align: middle; }
td strong { display: block; color: var(--ink); font-size: 12px; margin-bottom: 4px; }
td small { color: var(--muted); }
.status-tag { display: inline-flex; padding: 4px 7px; border-radius: 12px; background: #efeee9; font-size: 10px; }
.status-tag.good { color: var(--green); background: #eaf2ec; }
.status-tag.warn { color: #946623; background: #f6ecd9; }
.status-tag.bad { color: var(--red); background: #f6e7e3; }
.table-foot { padding: 11px 15px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.empty-cell { padding: 52px 20px; text-align: center; color: var(--muted); }

.system-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.system-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 18px; }
.system-card header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.system-card h3 { margin: 0; font-size: 13px; }
.system-card strong { display: block; margin: 20px 0 8px; font: 600 28px Georgia, serif; }
.system-card p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(78,118,95,.1); }
.status-dot.warn { background: #ba8139; box-shadow: 0 0 0 4px rgba(186,129,57,.1); }
.definition-panel { margin-top: 14px; }
.definition-list { display: grid; grid-template-columns: repeat(2, 1fr); column-gap: 38px; margin: 18px 0 0; }
.definition-list div { display: grid; grid-template-columns: 90px 1fr; gap: 12px; padding: 13px 0; border-top: 1px solid #e9e7df; }
.definition-list dt { font-size: 12px; font-weight: 600; }
.definition-list dd { margin: 0; color: var(--ink-soft); font-size: 12px; line-height: 1.65; }
.mobile-nav { display: none; }

@media (max-width: 1180px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .system-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 860px) {
  .app-shell { display: block; }
  .sidebar { display: none; }
  .main-content { padding: 0 16px 92px; }
  .topbar { min-height: 92px; align-items: flex-start; padding: 19px 0 15px; }
  .topbar h1 { font-size: 23px; }
  .eyebrow { display: none; }
  .topbar-actions { align-items: flex-start; }
  .user-chip { display: none; }
  .date-filter { display: block; }
  .custom-range { position: absolute; top: 69px; left: 16px; right: 16px; z-index: 10; background: var(--surface); padding: 10px; border: 1px solid var(--line); box-shadow: var(--shadow); }
  .custom-range input { min-width: 0; width: 100%; }
  .section-heading { margin-top: 25px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .kpi-card { min-height: 120px; }
  .dashboard-grid, .dashboard-grid.lower-grid { grid-template-columns: 1fr; }
  .health-panel { order: -1; }
  .funnel { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .funnel-step, .funnel-step:first-child, .funnel-step:last-child { border: 1px solid var(--line); border-radius: 7px; }
  .funnel-step::after { display: none; }
  .mobile-nav { position: fixed; display: grid; grid-template-columns: repeat(4, 1fr); inset: auto 0 0; height: calc(67px + env(safe-area-inset-bottom)); padding: 7px 8px env(safe-area-inset-bottom); background: rgba(27,27,23,.97); border-top: 1px solid rgba(255,255,255,.08); z-index: 30; }
  .mobile-nav button { border: 0; background: transparent; color: #89887e; font-size: 10px; display: grid; justify-items: center; gap: 2px; cursor: pointer; }
  .mobile-nav button span { font-size: 20px; line-height: 1; }
  .mobile-nav button.is-active { color: #e8c28f; }
  .definition-list { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .kpi-grid { gap: 9px; }
  .kpi-card { padding: 14px; min-height: 111px; }
  .kpi-value { font-size: 23px; margin: 14px 0 9px; }
  .section-heading h2 { font-size: 19px; }
  .updated-at { display: none; }
  .panel { padding: 17px; border-radius: 9px; }
  .segmented button { padding: 6px 8px; }
  .chart, .chart svg { min-height: 220px; height: 220px; }
  .table-heading { align-items: flex-start; }
  .table-heading .secondary-button { flex: 0 0 auto; }
  .table-toolbar { flex-wrap: wrap; }
  .table-toolbar input { max-width: none; flex-basis: 100%; }
  .system-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .system-card { padding: 14px; }
  .system-card strong { font-size: 23px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
