:root {
  --ink: #1B2430;
  --muted: #5B6576;
  --faint: #8A93A3;
  --line: #E4E7EC;
  --line-strong: #D0D5DD;
  --surface: #FFFFFF;
  --page: #FFFFFF;
  --sidebar: #F6F7F9;
  --hover: #F2F4F7;
  --accent: #1D4FD8;
  --accent-hover: #1A43B8;
  --accent-soft: #EEF3FE;
  --chart: #2a78d6;
  --good: #15803D;
  --warn: #B45309;
  --bad: #B91C1C;
  --none: #64748B;
  --radius: 10px;
  --radius-sm: 6px;
  --header-h: 56px;
  --sidebar-w: 232px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 14px/1.5 var(--font);
  color: var(--ink);
  background: var(--page);
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.icon { flex: none; vertical-align: -3px; }
.num { text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }

.shell {
  display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh;
  background: linear-gradient(to right, var(--sidebar) calc(var(--sidebar-w) - 1px), var(--line) calc(var(--sidebar-w) - 1px), var(--line) var(--sidebar-w), var(--page) var(--sidebar-w));
}
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 600; color: var(--ink); }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; background: var(--ink); color: #fff;
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  min-height: 36px; padding: 0 10px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 500;
}
.nav a:hover { background: var(--hover); color: var(--ink); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.nav a[aria-current="page"] .icon { color: var(--accent); }
.nav-label { font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--faint); padding: 16px 10px 6px; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--line); padding-top: 10px; }
.sidebar-foot form { margin: 0; }
.sidebar-foot button.linklike { width: 100%; }
.user-line { font-size: 12px; color: var(--faint); padding: 6px 10px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { min-width: 0; }
.content { max-width: 1240px; padding: 28px 32px 64px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; line-height: 1.3; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.crumb { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; margin-bottom: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
  touch-action: manipulation; transition: background-color .12s, border-color .12s;
}
.btn:hover { background: var(--hover); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--bad); }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
button.linklike {
  display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 0 10px;
  background: none; border: 0; border-radius: var(--radius-sm); color: var(--muted);
  font: inherit; font-weight: 500; cursor: pointer; text-align: left;
}
button.linklike:hover { background: var(--hover); color: var(--ink); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head h2 { font-size: 15px; }
.card-body { padding: 18px; }
.content > .card + .card, .content > .card + .grid-2, .section + .section { margin-top: 20px; }

.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { padding: 16px 18px; }
.kpi-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi-value { font-size: 24px; font-weight: 600; line-height: 1.25; margin-top: 6px; letter-spacing: -0.01em; }
.kpi-value.small { font-size: 18px; }
.kpi-caption { font-size: 12px; color: var(--faint); margin-top: 4px; }
.kpi a { color: inherit; }

.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; white-space: nowrap; }
.status .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.status-good { color: var(--good); }
.status-warn { color: var(--warn); }
.status-bad { color: var(--bad); }
.status-none { color: var(--none); }

.tag {
  display: inline-block; padding: 1px 7px; border-radius: 4px; font-size: 12px; font-weight: 500;
  color: var(--muted); border: 1px solid var(--line); background: var(--surface); white-space: nowrap;
}

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
.data th {
  text-align: left; font-size: 12px; font-weight: 500; color: var(--muted);
  padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface);
}
.data td { padding: 0 14px; height: 44px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data tr:last-child td { border-bottom: 0; }
.data tbody tr:hover td { background: #FAFBFC; }
.data th.num, .data td.num { text-align: right; }
.data .primary { font-weight: 500; color: var(--ink); }
.data a.primary:hover { color: var(--accent); }
.data .stack { display: flex; flex-direction: column; line-height: 1.3; padding: 6px 0; }
.data .stack small { color: var(--faint); font-size: 12px; }
.empty { padding: 40px 18px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); margin-bottom: 4px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.field-inline { position: relative; }
.field-inline .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.input, .select, .textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  min-height: 36px; padding: 6px 10px;
}
.select { padding-right: 28px; }
.input.search { padding-left: 32px; width: 260px; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.filter-clear { font-size: 13px; }
.result-line { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); margin: 0 2px 10px; flex-wrap: wrap; }

.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.pager .btns { display: flex; gap: 6px; }

.form { display: grid; gap: 18px; max-width: 640px; }
.form-row { display: grid; gap: 6px; }
.form-row label { font-weight: 500; }
.form-row .help { font-size: 12px; color: var(--faint); }
.form-row .error, .errorlist { color: var(--bad); font-size: 13px; margin: 0; padding: 0; list-style: none; }
.form-row .input, .form-row .select, .form-row .textarea { width: 100%; }
.form-row.check { grid-template-columns: auto 1fr; align-items: center; gap: 10px; }
.form-row.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.form-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-actions { display: flex; gap: 8px; }
fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 18px; }
legend { font-weight: 600; font-size: 15px; margin-bottom: 4px; }

.section { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.section:first-of-type { border-top: 0; padding-top: 0; }
.section-intro h2 { font-size: 15px; }
.section-intro p { color: var(--muted); font-size: 13px; margin: 4px 0 0; }

.facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; }
.fact { padding: 14px 18px; border-left: 1px solid var(--line); }
.fact:first-child { border-left: 0; }
.fact dt { font-size: 12px; color: var(--muted); }
.fact dd { margin: 4px 0 0; font-weight: 600; font-size: 15px; }

.kv { display: grid; grid-template-columns: 160px minmax(0, 1fr); }
.kv dt, .kv dd { margin: 0; padding: 10px 18px; border-bottom: 1px solid var(--line); }
.kv dt { color: var(--muted); }
.kv dd { min-width: 0; overflow-wrap: anywhere; }
.kv > :nth-last-child(-n+2) { border-bottom: 0; }

.keybox { display: flex; align-items: center; gap: 8px; min-width: 0; }
.keybox code { min-width: 0; }
.keybox code { background: var(--sidebar); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px 10px; overflow-x: auto; white-space: nowrap; }
pre.snippet { margin: 0; background: var(--sidebar); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; font: 12.5px/1.6 var(--mono); overflow-x: auto; }

.flash { display: flex; gap: 8px; align-items: center; padding: 10px 14px; border: 1px solid var(--line); border-left-width: 3px; border-radius: var(--radius-sm); margin-bottom: 16px; background: var(--surface); }
.flash-success { border-left-color: var(--good); }
.flash-error { border-left-color: var(--bad); }
.flash-warning { border-left-color: var(--warn); }
.notice { padding: 12px 16px; border: 1px solid var(--line); border-left: 3px solid var(--warn); border-radius: var(--radius-sm); margin-bottom: 16px; }

.chart-wrap { position: relative; padding: 8px 18px 14px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--faint); font-size: 11px; }
.chart .bar { fill: var(--chart); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart g.col:hover .bar { fill: #1f62b5; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--ink); color: #fff;
  font-size: 12px; padding: 6px 8px; border-radius: 6px; white-space: nowrap;
  transform: translate(-50%, -100%); margin-top: -8px; display: none;
}
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; }
.seg a { padding: 4px 10px; font-size: 12px; color: var(--muted); border-left: 1px solid var(--line-strong); }
.seg a:first-child { border-left: 0; }
.seg a[aria-current="true"] { background: var(--sidebar); color: var(--ink); font-weight: 600; }
.seg a:hover { text-decoration: none; color: var(--ink); }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.inline-form { display: inline; margin: 0; }
.stack-sm > * + * { margin-top: 8px; }

.auth { min-height: 100vh; display: grid; place-items: center; background: var(--sidebar); padding: 24px; }
.auth .card { width: 100%; max-width: 380px; padding: 28px; }
.auth h1 { font-size: 20px; margin: 16px 0 4px; }
.auth .form { margin-top: 20px; }
.auth .btn { width: 100%; min-height: 44px; }

@media (max-width: 1100px) {
  .section { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); background: var(--page); }
  .sidebar {
    position: sticky; top: 0; z-index: 10; height: var(--header-h);
    flex-direction: row; align-items: center; padding: 0 12px; gap: 4px;
    border-right: 0; border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0 8px 0 0; }
  .brand span:last-child { display: none; }
  .nav { flex-direction: row; overflow-x: auto; scrollbar-width: none; min-width: 0; flex: 1; }
  .sidebar { min-width: 0; }
  .nav a { white-space: nowrap; min-height: 36px; padding: 0 10px; }
  .nav a .label-long { display: none; }
  .nav-label, .user-line, .sidebar-foot { display: none; }
  .content { padding: 20px 16px 48px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fact:nth-child(3) { border-left: 0; }
  .fact:nth-child(n+3) { border-top: 1px solid var(--line); }
  .input.search { width: 100%; }
  .filters .field-inline { flex: 1 1 100%; }
  .filters .select { flex: 1 1 calc(50% - 4px); }
  .form-cols { grid-template-columns: 1fr; }
  .kv { grid-template-columns: minmax(0, 1fr); }
  .kv dt { border-bottom: 0; padding-bottom: 0; }
  .btn { min-height: 44px; }
  .hide-sm { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
