:root {
  color-scheme: light;
  --bg: #f2f4f5;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-muted: #e9edef;
  --sidebar: #171919;
  --sidebar-muted: #a5adad;
  --text: #171b1b;
  --text-muted: #657070;
  --line: #d9dede;
  --line-strong: #c5cccc;
  --accent: #087f87;
  --accent-soft: #d9f1f1;
  --green: #16855b;
  --green-soft: #dff3e9;
  --amber: #b66b0d;
  --amber-soft: #fff0d3;
  --red: #c13d48;
  --red-soft: #fbe4e6;
  --blue: #356fbd;
  --blue-soft: #e3edfa;
  --shadow: 0 10px 30px rgba(22, 30, 30, .08);
  --sidebar-width: 236px;
  --topbar-height: 72px;
  --radius: 6px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101212;
  --surface: #181b1b;
  --surface-raised: #1e2222;
  --surface-muted: #242929;
  --sidebar: #0b0d0d;
  --sidebar-muted: #899292;
  --text: #edf1f0;
  --text-muted: #9aa4a3;
  --line: #303636;
  --line-strong: #424949;
  --accent: #37b9bc;
  --accent-soft: #173a3b;
  --green: #48bf88;
  --green-soft: #19372a;
  --amber: #e4a449;
  --amber-soft: #3c2d17;
  --red: #ef7178;
  --red-soft: #442126;
  --blue: #6da3e8;
  --blue-soft: #1d3049;
  --shadow: 0 16px 36px rgba(0, 0, 0, .24);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: 0;
}
button, input, select, textarea { color: inherit; font: inherit; letter-spacing: 0; }
button, select { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
a { color: inherit; }
[hidden] { display: none !important; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  background: var(--sidebar);
  color: #f2f5f4;
  border-right: 1px solid rgba(255,255,255,.08);
}
.brand {
  display: flex;
  height: var(--topbar-height);
  align-items: center;
  gap: 12px;
  padding: 0 22px;
  text-decoration: none;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand > span:last-child { display: grid; line-height: 1; }
.brand strong { font-size: 14px; font-weight: 800; }
.brand small { margin-top: 5px; color: #899494; font-size: 9px; font-weight: 700; }
.brand-mark { position: relative; display: grid; width: 30px; height: 30px; place-items: end; }
.brand-mark i { position: absolute; bottom: 4px; width: 5px; background: #46c3c5; border-radius: 1px; }
.brand-mark i:nth-child(1) { left: 4px; height: 10px; }
.brand-mark i:nth-child(2) { left: 13px; height: 18px; background: #f3a83b; }
.brand-mark i:nth-child(3) { left: 22px; height: 24px; background: #e85d68; }
.main-nav { display: grid; gap: 4px; padding: 18px 12px; }
.nav-item {
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  color: var(--sidebar-muted);
  background: transparent;
  border: 0;
  border-radius: 5px;
  text-align: left;
  font-weight: 620;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-item.is-active { color: #fff; background: #263031; box-shadow: inset 3px 0 #45bec0; }
.nav-glyph { display: inline-grid; width: 24px; height: 24px; place-items: center; font-size: 17px; }
.sidebar-status {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: auto 14px 12px;
  padding: 13px;
  background: rgba(255,255,255,.045);
  border: 1px solid rgba(255,255,255,.07);
  border-radius: var(--radius);
}
.sidebar-status div { display: grid; min-width: 0; }
.sidebar-status strong { font-size: 12px; }
.sidebar-status small { color: #899494; font-size: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pulse-dot { width: 8px; height: 8px; flex: 0 0 auto; background: var(--green); border-radius: 50%; box-shadow: 0 0 0 4px rgba(72,191,136,.12); }
.pulse-dot.is-error { background: var(--red); box-shadow: 0 0 0 4px rgba(239,113,120,.12); }
.sidebar-foot { padding: 0 26px 22px; color: #626b6a; font-size: 10px; }

.workspace { min-width: 0; margin-left: var(--sidebar-width); }
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  height: var(--topbar-height);
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 28px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.topbar-start, .topbar-actions { display: flex; align-items: center; gap: 10px; }
.topbar h1 { margin: 1px 0 0; font-size: 19px; line-height: 1.2; font-weight: 720; }
.eyebrow { margin: 0; color: var(--text-muted); font-size: 9px; font-weight: 800; }
.sync-state { display: inline-flex; align-items: center; gap: 7px; margin-right: 4px; color: var(--text-muted); font-size: 12px; }
.sync-state i { width: 7px; height: 7px; background: var(--green); border-radius: 50%; }
.mobile-menu { display: none !important; }
.content { min-width: 0; padding: 24px 28px 40px; outline: none; }
.content-inner { width: 100%; max-width: 1680px; margin: 0 auto; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.view-head h2 { margin: 0; font-size: 16px; }
.view-head p { margin: 4px 0 0; color: var(--text-muted); font-size: 12px; }
.section-title { margin: 0; font-size: 14px; font-weight: 700; }
.section-meta { color: var(--text-muted); font-size: 11px; }
.grid { display: grid; gap: 14px; }
.grid.metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.two { grid-template-columns: minmax(0, 1.45fr) minmax(320px, .75fr); }
.grid.equal { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.scrim { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.48); }
#nav-scrim { z-index: 35; }
.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: 80;
  width: min(560px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: translateX(100%);
  transition: transform .22s ease;
}
.drawer.is-open { transform: translateX(0); }
.drawer-header { display: flex; height: 76px; align-items: center; justify-content: space-between; padding: 0 20px; border-bottom: 1px solid var(--line); }
.drawer-header h2 { margin: 2px 0 0; font-size: 17px; }
.drawer-body { height: calc(100vh - 76px); overflow: auto; padding: 18px; }
.toast-stack { position: fixed; z-index: 120; right: 18px; bottom: 18px; display: grid; width: min(360px, calc(100vw - 36px)); gap: 8px; }

@media (max-width: 1100px) {
  .grid.metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  :root { --topbar-height: 64px; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.is-open { transform: translateX(0); }
  .workspace { margin-left: 0; }
  .mobile-menu { display: inline-grid !important; }
  .topbar { padding: 0 14px; }
  .topbar-actions .sync-state { display: none; }
  .topbar-actions .button { width: 38px; padding: 0; font-size: 0; }
  .topbar-actions .button span { font-size: 17px; }
  .content { padding: 16px 12px 28px; }
  .grid.metrics, .grid.equal { grid-template-columns: 1fr; }
  .view-head { align-items: stretch; flex-direction: column; }
}
