:root {
  color-scheme: light dark;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-soft: #f0f1f3;
  --text: #1d1d1f;
  --text-secondary: #5b5b62;
  --border: #d7d7dc;
  --blue: #0066cc;
  --blue-hover: #0057b8;
  --positive: #16753a;
  --positive-soft: #e8f7ed;
  --warning: #8a4b00;
  --warning-soft: #fff3db;
  --critical: #b42318;
  --critical-soft: #ffebe9;
  --info: #075f9e;
  --info-soft: #e7f3ff;
  --focus: #0077ed;
  --shadow: 0 8px 30px rgb(0 0 0 / 0.06);
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --motion: 180ms cubic-bezier(.2, .8, .2, 1);
}

:root[data-theme="dark"] {
  --bg: #09090b;
  --surface: #171719;
  --surface-raised: #202023;
  --surface-soft: #2a2a2e;
  --text: #f5f5f7;
  --text-secondary: #b7b7bf;
  --border: #3a3a40;
  --blue: #409cff;
  --blue-hover: #68b1ff;
  --positive: #5dd683;
  --positive-soft: #123c22;
  --warning: #ffbd5c;
  --warning-soft: #46300e;
  --critical: #ff8178;
  --critical-soft: #461b18;
  --info: #72b9ed;
  --info-soft: #11344e;
  --focus: #66b2ff;
  --shadow: 0 14px 40px rgb(0 0 0 / 0.28);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #09090b; --surface: #171719; --surface-raised: #202023; --surface-soft: #2a2a2e;
    --text: #f5f5f7; --text-secondary: #b7b7bf; --border: #3a3a40; --blue: #409cff;
    --positive: #5dd683; --positive-soft: #123c22; --warning: #ffbd5c; --warning-soft: #46300e;
    --critical: #ff8178; --critical-soft: #461b18; --info: #72b9ed; --info-soft: #11344e;
    --focus: #66b2ff; --shadow: 0 14px 40px rgb(0 0 0 / 0.28);
  }
}

* { box-sizing: border-box; }
html { font-family: var(--font-sans); background: var(--bg); color: var(--text); }
body { margin: 0; min-width: 320px; background: var(--bg); }
button, input, select, textarea { font: inherit; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.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; padding: 10px 14px; border-radius: 10px; background: var(--text); color: var(--bg); transition: top var(--motion); }
.skip-link:focus { top: 16px; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 24px 16px; border-right: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(18px); display: flex; flex-direction: column; }
.brand-lockup { display: flex; align-items: center; gap: 12px; padding: 0 10px 24px; }
.brand-lockup span:last-child, .topbar > div:first-child { display: grid; gap: 2px; }
.brand-lockup small, .topbar small { color: var(--text-secondary); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--text); color: var(--bg); display: grid; place-items: center; font-weight: 750; }
.sidebar nav { display: grid; gap: 4px; }
.sidebar nav a { padding: 10px 12px; border-radius: 10px; text-decoration: none; color: var(--text-secondary); transition: background var(--motion), color var(--motion); }
.sidebar nav a:hover { background: var(--surface-soft); color: var(--text); }
.sidebar nav a[aria-current="page"] { background: var(--text); color: var(--bg); font-weight: 650; transition: none; }
.sidebar-foot { margin-top: auto; padding: 12px 10px; color: var(--text-secondary); font-size: 12px; }
.demo-dot { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--warning); }
.page-column { min-width: 0; }
.topbar { min-height: 64px; padding: 12px clamp(20px, 4vw, 48px); border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(18px); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 20; }
.topbar > div:first-child { display: none; }
.topbar-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
main { width: min(1440px, 100%); margin: 0 auto; padding: 38px clamp(20px, 4vw, 52px) 72px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 22px; }
.card-header { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 20px; }
.card-header h2 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.card-header p { margin: 6px 0 0; color: var(--text-secondary); font-size: 14px; }
.status-badge { display: inline-flex; align-items: center; gap: 7px; min-height: 26px; padding: 4px 9px; border-radius: 999px; font-size: 12px; font-weight: 650; white-space: nowrap; }
.status-badge > span { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-positive { color: var(--positive); background: var(--positive-soft); }
.status-warning { color: var(--warning); background: var(--warning-soft); }
.status-critical { color: var(--critical); background: var(--critical-soft); }
.status-info { color: var(--info); background: var(--info-soft); }
.status-neutral { color: var(--text-secondary); background: var(--surface-soft); }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.money-emphasize { font-weight: 720; letter-spacing: -.015em; }
.table-scroll { max-width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-md); }
table { width: 100%; border-collapse: collapse; min-width: 680px; }
th, td { padding: 13px 16px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--text-secondary); background: var(--surface-soft); font-size: 12px; font-weight: 650; }
tbody tr:last-child td { border-bottom: 0; }
.empty-cell { padding: 42px; text-align: center; color: var(--text-secondary); }
.field { display: grid; gap: 7px; color: var(--text); font-size: 14px; font-weight: 600; }
.field input { width: 100%; min-height: 44px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--surface-raised); color: var(--text); }
.field small { color: var(--text-secondary); font-weight: 400; }
.field-error { color: var(--critical) !important; }
.button { min-height: 42px; border: 0; border-radius: var(--radius-sm); padding: 9px 16px; font-weight: 650; cursor: pointer; transition: transform var(--motion), background var(--motion); }
.button:active { transform: scale(.98); }
.button-primary { background: var(--blue); color: white; }
.button-secondary { background: var(--surface-soft); color: var(--text); }
.button-danger { background: var(--critical); color: #fff; }
.button-quiet { background: transparent; color: var(--text-secondary); }
.button:disabled { opacity: .5; cursor: not-allowed; }
.confirm-dialog { width: min(520px, calc(100% - 32px)); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 0; color: var(--text); background: var(--surface-raised); box-shadow: 0 24px 80px rgb(0 0 0 / .25); }
.confirm-dialog::backdrop { background: rgb(0 0 0 / .46); backdrop-filter: blur(5px); }
.confirm-dialog form { display: grid; gap: 16px; padding: 26px; }
.confirm-dialog h2, .confirm-dialog p { margin: 0; }
.confirm-dialog p { color: var(--text-secondary); line-height: 1.55; }
.dialog-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; background: var(--critical-soft); color: var(--critical); font-weight: 800; }
.demo-notice { padding: 10px 12px; border-radius: 10px; background: var(--warning-soft); color: var(--warning); font-size: 13px; font-weight: 650; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }

@media (max-width: 820px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: auto 0 0; z-index: 30; width: 100%; height: auto; padding: 8px; border: 1px solid var(--border); border-width: 1px 0 0; }
  .sidebar .brand-lockup, .sidebar-foot { display: none; }
  .sidebar nav { display: flex; overflow-x: auto; gap: 5px; scrollbar-width: none; }
  .sidebar nav a { flex: 0 0 auto; font-size: 13px; padding: 9px 12px; }
  .topbar > div:first-child { display: grid; }
  main { padding-top: 24px; padding-bottom: 98px; }
}

@media (max-width: 560px) {
  .card { padding: 18px; border-radius: var(--radius-md); }
  .card-header { align-items: stretch; flex-direction: column; }
  .table-scroll { border: 0; overflow: visible; }
  table, thead, tbody, tr, th, td { display: block; min-width: 0; }
  thead { display: none; }
  tbody { display: grid; gap: 12px; }
  tr { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 14px; background: var(--surface-raised); }
  td { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; }
  td::before { content: attr(data-label); color: var(--text-secondary); font-size: 12px; }
}

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