:root {
  color-scheme: light;
  --bg: #f5f5f1;
  --surface: #ffffff;
  --surface-soft: #fafaf7;
  --text: #171916;
  --muted: #6c716b;
  --faint: #969c95;
  --line: #dedfd9;
  --line-strong: #c9ccc4;
  --accent: #267451;
  --accent-strong: #185d3f;
  --accent-soft: #e9f3ed;
  --danger: #a33d35;
  --danger-soft: #f8ece9;
  --warning: #936716;
  --warning-soft: #f8f0dc;
  --shadow: 0 16px 48px rgba(28, 35, 29, 0.08);
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 15px; line-height: 1.55; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(38, 116, 81, 0.24); outline-offset: 2px; }
[hidden] { display: none !important; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 268px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 24px 20px; background: #eeeee9; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 16px; overflow-y: auto; }
.brand-block { display: flex; align-items: center; gap: 12px; padding: 2px 4px 18px; }
.brand-mark { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; background: #172219; color: white; font: 700 13px/1 var(--mono); letter-spacing: .04em; }
.brand-block strong, .brand-block span { display: block; }
.brand-block strong { font-size: 17px; letter-spacing: -.02em; }
.brand-block span { color: var(--muted); font-size: 13px; }

.status-panel { padding: 17px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255, 255, 255, .58); }
.section-label { display: block; margin-bottom: 13px; color: var(--faint); font: 600 11px/1.2 var(--mono); letter-spacing: .09em; text-transform: uppercase; }
.status-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 13px; }
.status-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 24px; padding: 3px 9px; border-radius: 999px; background: var(--warning-soft); color: var(--warning); font-size: 12px; font-weight: 650; white-space: nowrap; }
.status-chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-chip[data-state="connected"] { background: var(--accent-soft); color: var(--accent-strong); }
.status-chip[data-state="error"] { background: var(--danger-soft); color: var(--danger); }
.status-value { display: block; margin-top: 14px; font-size: 18px; letter-spacing: -.02em; }
.status-panel p, .sidebar-note p { margin: 6px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.sidebar-note { padding: 12px 6px; }
.sidebar-foot { margin-top: auto; display: flex; align-items: center; gap: 9px; padding: 13px 5px 2px; color: var(--muted); font-size: 12px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(38, 116, 81, .12); }

.main-content { min-width: 0; width: 100%; max-width: 1580px; margin: 0 auto; padding: 38px clamp(24px, 4vw, 64px) 64px; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 32px; margin-bottom: 30px; }
.kicker { margin: 0 0 9px; color: var(--accent); font: 650 11px/1.2 var(--mono); letter-spacing: .1em; text-transform: uppercase; }
.page-header h1 { margin: 0; font-size: clamp(32px, 4vw, 54px); line-height: 1.02; letter-spacing: -.055em; font-weight: 660; }
.page-header > div > p:last-child { margin: 12px 0 0; color: var(--muted); font-size: 15px; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.updated-at { min-width: 112px; margin-right: 8px; text-align: right; }
.updated-at span, .updated-at strong { display: block; }
.updated-at span { color: var(--faint); font-size: 11px; }
.updated-at strong { margin-top: 3px; font: 600 12px/1.2 var(--mono); }
.primary-button, .quiet-button { min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent; font-weight: 650; transition: background-color .18s ease, border-color .18s ease, color .18s ease; }
.primary-button { background: var(--accent); color: #fff; }
.primary-button:hover { background: var(--accent-strong); }
.quiet-button { background: var(--surface); color: var(--text); border-color: var(--line); }
.quiet-button:hover { border-color: var(--line-strong); background: var(--surface-soft); }
.quiet-button:disabled { opacity: .45; cursor: not-allowed; }

.metric-ledger { display: grid; grid-template-columns: 1.35fr repeat(4, 1fr); border: 1px solid var(--line); border-radius: 16px; background: var(--surface); overflow: hidden; box-shadow: var(--shadow); }
.metric-card { position: relative; min-width: 0; min-height: 132px; padding: 22px; border-left: 1px solid var(--line); display: flex; flex-direction: column; justify-content: space-between; }
.metric-card:first-child { border-left: 0; }
.metric-card span { color: var(--muted); font-size: 12px; font-weight: 600; }
.metric-card strong { margin: 10px 0 4px; font: 600 clamp(25px, 2.8vw, 39px)/1 var(--mono); letter-spacing: -.055em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metric-card small { color: var(--faint); font: 500 11px/1.4 var(--mono); }
.metric-primary::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--accent); }
.metric-primary strong { color: var(--accent-strong); }

.analytics-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(270px, .7fr); gap: 18px; margin-top: 18px; }
.panel { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 8px 28px rgba(28, 35, 29, .045); }
.chart-panel, .model-panel { min-height: 344px; padding: 22px; }
.panel-heading, .records-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.panel h2, .records-panel h2 { margin: 0; font-size: 16px; letter-spacing: -.018em; }
.panel-heading p, .records-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.panel-meta { color: var(--muted); font: 500 11px/1.3 var(--mono); }
.token-chart { min-height: 225px; margin-top: 18px; display: grid; place-items: center; }
.chart-svg { width: 100%; height: 225px; overflow: visible; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-area { fill: rgba(38, 116, 81, .09); }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart-point { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.chart-bar { fill: rgba(38, 116, 81, .18); }
.chart-label { fill: var(--faint); font: 10px var(--mono); }
.chart-empty { color: var(--muted); font-size: 13px; text-align: center; }
.chart-legend { display: flex; gap: 18px; color: var(--muted); font-size: 11px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend-line { width: 18px; height: 2px; background: var(--accent); }
.legend-bar { width: 9px; height: 9px; background: rgba(38, 116, 81, .2); }

.model-usage-list { display: grid; gap: 17px; margin-top: 24px; }
.model-item { display: grid; gap: 8px; }
.model-copy { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.model-copy span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 600 12px/1.3 var(--mono); }
.model-copy strong { color: var(--muted); font: 600 11px/1.3 var(--mono); white-space: nowrap; }
.model-bar { height: 5px; border-radius: 999px; background: var(--surface-soft); overflow: hidden; }
.model-bar i { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.model-empty { padding: 72px 10px; text-align: center; color: var(--muted); font-size: 13px; }

.records-panel { margin-top: 18px; padding: 22px; }
.records-heading { align-items: flex-end; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.filters { display: flex; align-items: flex-end; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.filters label { display: grid; gap: 5px; }
.filters label > span { color: var(--faint); font-size: 10px; font-weight: 650; letter-spacing: .04em; }
.filters select, .filters input { height: 40px; min-width: 132px; padding: 0 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--text); font-size: 13px; }
.filters input { min-width: 190px; }
.records-table-wrap { overflow-x: auto; }
.records-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.records-table th { padding: 13px 12px; color: var(--faint); text-align: left; font-size: 10px; font-weight: 650; letter-spacing: .05em; text-transform: uppercase; }
.records-table th:first-child { width: 21%; }
.records-table th:nth-child(2) { width: 22%; }
.records-table th:nth-child(3) { width: 18%; }
.records-table th:nth-child(4), .records-table th:nth-child(5), .records-table th:nth-child(6) { width: 13%; }
.records-table td { padding: 15px 12px; border-top: 1px solid var(--line); vertical-align: middle; font-size: 12px; }
.records-table tbody tr { cursor: pointer; transition: background-color .16s ease; }
.records-table tbody tr:hover { background: var(--surface-soft); }
.records-table tbody tr:focus-visible { outline: 3px solid rgba(38, 116, 81, .22); outline-offset: -3px; }
.record-identity { display: flex; align-items: center; gap: 10px; }
.type-mark { flex: 0 0 auto; width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-strong); font: 700 10px/1 var(--mono); }
.type-mark.image { background: #edf0f8; color: #505e8b; }
.record-identity strong, .record-identity span { display: block; }
.record-identity strong { font-size: 12px; }
.record-identity span { color: var(--faint); font: 10px/1.4 var(--mono); }
.model-name, .numeric { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.model-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.endpoint { display: block; margin-top: 3px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
.token-cell strong, .token-cell span { display: block; }
.token-cell strong { font: 650 14px/1.2 var(--mono); }
.token-cell span { margin-top: 3px; color: var(--faint); font: 10px/1.3 var(--mono); }
.record-status { display: inline-flex; min-height: 24px; align-items: center; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); font-size: 11px; font-weight: 650; }
.record-status.failed { background: var(--danger-soft); color: var(--danger); }
.empty-state { min-height: 300px; display: grid; place-items: center; align-content: center; text-align: center; color: var(--muted); }
.empty-mark { width: 60px; height: 60px; margin-bottom: 15px; border: 1px solid var(--line); border-radius: 18px; display: grid; place-items: center; color: var(--accent); background: var(--surface-soft); }
.empty-state strong { color: var(--text); font-size: 15px; }
.empty-state p { max-width: 410px; margin: 7px 0 0; font-size: 12px; }

.record-dialog { width: min(620px, calc(100vw - 32px)); max-height: min(760px, calc(100vh - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--text); box-shadow: 0 30px 90px rgba(15, 22, 17, .22); }
.record-dialog::backdrop { background: rgba(18, 22, 19, .46); backdrop-filter: blur(3px); }
.dialog-header { position: sticky; top: 0; z-index: 1; padding: 20px 22px; border-bottom: 1px solid var(--line); background: var(--surface); display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.dialog-header span { color: var(--accent); font: 650 10px/1.2 var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.dialog-header h2 { margin: 5px 0 0; font-size: 18px; }
.icon-button { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-soft); color: var(--text); font-size: 22px; }
.dialog-content { padding: 22px; overflow-wrap: anywhere; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.detail-item { min-height: 86px; padding: 13px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-soft); }
.detail-item span, .detail-item strong, .detail-item small { display: block; }
.detail-item span { color: var(--faint); font-size: 10px; }
.detail-item strong { margin-top: 8px; font: 650 15px/1.3 var(--mono); }
.detail-item small { margin-top: 4px; color: var(--muted); font-size: 10px; }
.detail-note { margin: 16px 0 0; padding: 13px; border-left: 3px solid var(--accent); background: var(--accent-soft); color: var(--muted); font-size: 12px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 20; max-width: min(360px, calc(100vw - 44px)); padding: 11px 14px; border-radius: 10px; background: #172219; color: white; box-shadow: var(--shadow); font-size: 12px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .18s ease, transform .18s ease; }
.toast.visible { opacity: 1; transform: translateY(0); }

@media (max-width: 1120px) {
  .metric-ledger { grid-template-columns: repeat(6, 1fr); }
  .metric-card { grid-column: span 2; border-top: 1px solid var(--line); }
  .metric-card:nth-child(-n+3) { border-top: 0; }
  .metric-card:nth-child(4) { grid-column: 2 / span 2; }
  .metric-card:nth-child(5) { grid-column: 4 / span 2; }
  .analytics-grid { grid-template-columns: 1fr; }
  .model-usage-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .model-panel { min-height: auto; }
}

@media (max-width: 820px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: auto; height: auto; padding: 16px 20px; border-right: 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; }
  .brand-block { grid-column: 1 / -1; padding-bottom: 3px; }
  .sidebar-note { display: none; }
  .sidebar-foot { grid-column: 1 / -1; margin: 0; }
  .main-content { padding: 28px 20px 48px; }
  .page-header { align-items: flex-start; }
  .header-actions { flex-wrap: wrap; justify-content: flex-end; }
  .updated-at { width: 100%; margin: 0; }
  .records-heading { align-items: flex-start; flex-direction: column; }
  .filters { justify-content: flex-start; width: 100%; }
  .filters label { flex: 1 1 150px; }
  .filters select, .filters input { width: 100%; min-width: 0; }
}

@media (max-width: 620px) {
  .sidebar { grid-template-columns: 1fr; }
  .brand-block, .sidebar-foot { grid-column: auto; }
  .page-header { display: block; }
  .page-header h1 { font-size: 38px; }
  .header-actions { margin-top: 22px; justify-content: flex-start; }
  .updated-at { text-align: left; }
  .header-actions button { flex: 1; }
  .metric-ledger { grid-template-columns: repeat(2, 1fr); }
  .metric-card, .metric-card:nth-child(4), .metric-card:nth-child(5) { grid-column: span 1; min-height: 114px; padding: 17px; }
  .metric-card:first-child { grid-column: 1 / -1; }
  .metric-card:nth-child(2) { border-top: 1px solid var(--line); }
  .metric-card strong { font-size: 26px; }
  .chart-panel, .model-panel, .records-panel { padding: 17px; }
  .model-usage-list { grid-template-columns: 1fr; }
  .records-table, .records-table tbody, .records-table tr, .records-table td { display: block; }
  .records-table thead { display: none; }
  .records-table tr { padding: 15px 0; border-top: 1px solid var(--line); }
  .records-table td { padding: 6px 2px; border: 0; }
  .records-table td::before { content: attr(data-label); display: inline-block; width: 88px; color: var(--faint); font-size: 10px; vertical-align: top; }
  .records-table td:first-child::before { display: none; }
  .records-table td > * { display: inline-flex; max-width: calc(100% - 96px); }
  .records-table td:first-child > * { display: flex; max-width: 100%; }
  .token-cell strong, .token-cell span { display: inline; margin-right: 7px; }
  .detail-grid { grid-template-columns: 1fr; }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #151815;
    --surface: #1d211e;
    --surface-soft: #202521;
    --text: #eef1ec;
    --muted: #a9afa8;
    --faint: #7f877f;
    --line: #343a35;
    --line-strong: #4a514b;
    --accent: #6db891;
    --accent-strong: #9bd2b4;
    --accent-soft: #20372a;
    --danger: #e28b82;
    --danger-soft: #412724;
    --warning: #d5aa55;
    --warning-soft: #3b321f;
    --shadow: 0 20px 60px rgba(0, 0, 0, .28);
  }
  .sidebar { background: #191c19; }
  .brand-mark { background: #edf1eb; color: #172219; }
  .status-panel { background: rgba(31, 36, 32, .75); }
  .type-mark.image { background: #2a3040; color: #acb9e4; }
  .toast { background: #edf1eb; color: #172219; }
}

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