/* Inter Variable (OFL), bundled so the panel looks the same offline and never swaps fonts mid-load. */
@font-face { font-family: "Inter"; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url("fonts/inter-latin-wght-normal.woff2") format("woff2-variations");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: "Inter"; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url("fonts/inter-latin-ext-wght-normal.woff2") format("woff2-variations");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: "Inter"; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url("fonts/inter-cyrillic-wght-normal.woff2") format("woff2-variations");
  unicode-range: U+0301,U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116; }
@font-face { font-family: "Inter"; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url("fonts/inter-cyrillic-ext-wght-normal.woff2") format("woff2-variations");
  unicode-range: U+0460-052F,U+1C80-1C8A,U+20B4,U+2DE0-2DFF,U+A640-A69F,U+FE2E-FE2F; }

:root {
  --bg: #0b0c0e; --sidebar: #101113; --surface: #111215; --surface-2: #17191c; --raised: #222427;
  --border: #1f2124; --border-strong: #2e3033; --text: #f4f5f6; --text-2: #a1a4a9; --text-3: #6e737a;
  --primary: #f7f7f8; --on-primary: #0e1012; --danger: #f2706b; --danger-soft: #f2706b1f; --ok: #57c78b; --warn: #e8b45c;
  --track: #26292d;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f5f7; --sidebar: #eceef1; --surface: #fff; --surface-2: #f6f7f9; --raised: #e2e5e9; --border: #e1e3e7;
    --border-strong: #cfd3d9; --text: #121418; --text-2: #5a6069; --text-3: #868c95; --primary: #121418; --on-primary: #fff;
    --danger: #c8322c; --danger-soft: #c8322c14; --ok: #1f8a52; --warn: #a8700f; --track: #e3e5e9; color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text); font: 15px/1.5 "Inter", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased; font-feature-settings: "cv11", "ss01";
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: 13px; }

.layout { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--sidebar); border-right: 1px solid var(--border); padding: 28px 14px 18px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 12px; align-items: center; padding: 0 12px 26px; }
.brand svg { width: 34px; height: 34px; color: var(--text); flex: none; }
.brand b { font-size: 22px; letter-spacing: -.01em; display: block; line-height: 1.1; }
.brand span { font-size: 13px; color: var(--text-2); }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 14px; height: 46px; padding: 0 14px; border-radius: 10px; text-decoration: none; color: color-mix(in srgb, var(--text) 82%, transparent); font-size: 16px; }
.nav a:hover { background: color-mix(in srgb, var(--raised) 60%, transparent); color: var(--text); }
.nav a[aria-current="page"] { background: var(--raised); color: var(--text); font-weight: 600; }
.nav svg { width: 20px; height: 20px; flex: none; }
.side-foot { margin-top: auto; border: 1px solid var(--border); background: var(--surface); border-radius: 14px; padding: 14px 16px; }
.side-foot .who { font-weight: 600; }
.side-foot form { margin-top: 10px; }

main { padding: 36px 40px 60px; min-width: 0; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
h1 { font-size: 30px; line-height: 1.15; letter-spacing: -.02em; margin: 0; }
.head p { margin: 6px 0 0; color: var(--text-2); font-size: 16px; }
h2 { font-size: 19px; margin: 0 0 14px; letter-spacing: -.005em; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 22px 24px; }
.card + .card, .grid + .card, .card + .grid, .grid + .grid { margin-top: 18px; }
.grid { display: grid; gap: 18px; }
.grid > .card { margin-top: 0; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; }
.kpi .v { font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--text-2); font-size: 14px; }
.kpi .sub { color: var(--text-3); font-size: 13px; margin-top: 2px; }

.chart { display: grid; grid-template-columns: repeat(14, minmax(0, 1fr)); gap: 8px; align-items: end; height: 170px; padding-top: 8px; }
.bar { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; height: 100%; }
.bar i { display: block; width: 100%; max-width: 30px; background: var(--primary); border-radius: 6px 6px 2px 2px; min-height: 2px; }
.bar i.u { background: var(--text-3); }
.bar span { font-size: 11px; color: var(--text-3); }
.legend { display: flex; gap: 18px; font-size: 13px; color: var(--text-2); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--primary); margin-right: 6px; vertical-align: -1px; }
.legend i.u { background: var(--text-3); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; color: var(--text-2); font-size: 13px; padding: 0 12px 10px 0; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px 12px 12px 0; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; padding-right: 0; }
td.actions form { display: inline; }
.table-wrap { overflow-x: auto; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border-strong); background: transparent; color: var(--text); font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--raised); }
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn.primary:hover { filter: brightness(.94); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { height: 32px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.lg { height: 52px; font-size: 16px; padding: 0 22px; }
.btn.block { width: 100%; }

label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px; }
.hint { font-size: 13px; color: var(--text-3); margin-top: 4px; font-weight: 400; }
input[type=text], input[type=number], input[type=url], input[type=password], input[type=date], input[type=search], select, textarea {
  width: 100%; height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface-2);
  color: var(--text); font: inherit;
}
textarea { height: auto; min-height: 110px; padding: 10px 12px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--text-2); }
.field { margin-bottom: 16px; }
.row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 400; margin: 0 0 10px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.chips { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 6px; }

.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--raised); color: var(--text-2); white-space: nowrap; }
.pill.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.pill.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.pill.bad { color: var(--danger); background: var(--danger-soft); }
.progress { height: 8px; border-radius: 99px; background: var(--track); overflow: hidden; min-width: 120px; }
.progress i { display: block; height: 100%; background: var(--primary); border-radius: 99px; }

.flash { border-radius: 12px; padding: 12px 16px; margin-bottom: 18px; border: 1px solid; font-weight: 500; }
.flash.ok { border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.flash.err { border-color: color-mix(in srgb, var(--danger) 45%, transparent); background: var(--danger-soft); }
.empty { text-align: center; padding: 30px 10px; color: var(--text-2); }
.list { margin: 0; padding: 0; list-style: none; }
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.trunc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 420px; }
.preview { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; font-size: 14px; max-height: 120px; overflow: hidden; }
details summary { cursor: pointer; color: var(--text-2); font-size: 14px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .card { width: 100%; max-width: 420px; padding: 32px; }
.login .brand { padding: 0 0 22px; }
.login h1 { font-size: 24px; margin-bottom: 6px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--text-3); font-size: 13px; margin: 20px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

@media (max-width: 1100px) { .g3 { grid-template-columns: 1fr 1fr; } }
.brand { text-decoration: none; }
.side-menu { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.menu-toggle, .menu-btn, .menu-scrim { display: none; }
.layout > main { min-width: 0; }

/* ============================ Phones & small tablets ============================
   Sticky top bar with the brand and a menu button; the menu drops down as a sheet. */
@media (max-width: 860px) {
  .layout { display: block; }
  .side { position: sticky; top: 0; z-index: 40; height: auto; padding: 0; border-right: 0; border-bottom: 1px solid var(--border);
          background: color-mix(in srgb, var(--sidebar) 88%, transparent); backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
          padding-top: env(safe-area-inset-top); }
  .side-top { display: flex; align-items: center; justify-content: space-between; height: 60px; padding: 0 8px 0 16px; }
  .brand { padding: 0; gap: 10px; min-width: 0; }
  .brand svg { width: 28px; height: 28px; }
  .brand b { font-size: 18px; }
  .brand span { font-size: 12px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .menu-btn { display: grid; place-content: center; gap: 5px; width: 48px; height: 48px; border-radius: 12px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
  .menu-btn:active { background: var(--raised); }
  .menu-btn span { display: block; width: 20px; height: 2px; border-radius: 2px; background: var(--text); transition: transform var(--med) var(--ease), opacity var(--fast) var(--ease); }
  .menu-toggle:checked ~ .side-top .menu-btn span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .menu-toggle:checked ~ .side-top .menu-btn span:nth-child(2) { opacity: 0; }
  .menu-toggle:checked ~ .side-top .menu-btn span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  .side-menu { position: absolute; left: 0; right: 0; top: 100%; display: block; flex: none;
               max-height: calc(100dvh - 60px - env(safe-area-inset-top)); overflow-y: auto; overscroll-behavior: contain;
               background: var(--sidebar); border-bottom: 1px solid var(--border); padding: 8px 12px calc(16px + env(safe-area-inset-bottom));
               box-shadow: 0 24px 48px -24px rgba(0,0,0,.5);
               opacity: 0; transform: translateY(-8px); visibility: hidden; pointer-events: none;
               transition: opacity var(--med) var(--ease), transform var(--med) var(--ease), visibility 0s linear var(--med); }
  .menu-toggle:checked ~ .side-menu { opacity: 1; transform: none; visibility: visible; pointer-events: auto; transition-delay: 0s; }
  .menu-scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity var(--med) var(--ease); }
  .layout:has(.menu-toggle:checked) .menu-scrim { opacity: 1; pointer-events: auto; }
  body:has(.menu-toggle:checked) { overflow: hidden; }
  .nav { gap: 2px; }
  .nav a { height: 50px; font-size: 16px; }
  .side-foot { display: block; margin-top: 12px; }

  main { padding: 20px 16px calc(48px + env(safe-area-inset-bottom)); }
  h1 { font-size: 24px; }
  .head { margin-bottom: 18px; align-items: flex-start; }
  .head p { font-size: 15px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .card { padding: 18px 16px; border-radius: 14px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 14px; }
  .kpi .v { font-size: 22px; }
  .kpi .l, .kpi .sub { font-size: 13px; }

  /* Chart: thinner bars, every other date label. */
  .chart { gap: 4px; height: 150px; }
  .chart .bar > div { gap: 2px !important; height: 112px !important; }
  .bar span { font-size: 10px; }
  .bar:nth-child(even) span { visibility: hidden; }
  .legend { flex-wrap: wrap; gap: 6px 14px; }

  /* Touch: bigger targets, 16px inputs so iOS does not zoom in. */
  input[type=text], input[type=number], input[type=url], input[type=password], input[type=date], input[type=search], select, textarea { font-size: 16px; height: 46px; }
  textarea { height: auto; }
  .btn { height: 44px; }
  .btn.sm { height: 38px; padding: 0 12px; }
  .check { min-height: 40px; margin-bottom: 4px; }
  .check input { width: 22px; height: 22px; flex: none; }
  .form-actions { flex-wrap: wrap; }
  .form-actions > .btn.primary, .form-actions > button.primary { flex: 1 1 auto; }
  .row { grid-template-columns: 1fr; gap: 0; }
  .list li { flex-wrap: wrap; }
  .trunc { max-width: 100%; }

  /* Tables become stacked cards (labels are added by admin.js). */
  .table-wrap.stack thead { display: none; }
  .table-wrap.stack table, .table-wrap.stack tbody, .table-wrap.stack tr, .table-wrap.stack td { display: block; width: 100%; }
  .table-wrap.stack tr { border: 1px solid var(--border); border-radius: 12px; padding: 6px 14px; margin-bottom: 10px; background: var(--surface-2); }
  .table-wrap.stack td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); text-align: right; min-height: 40px; }
  .table-wrap.stack td:last-child { border-bottom: 0; }
  .table-wrap.stack td[data-label]::before { content: attr(data-label); color: var(--text-3); font-size: 13px; text-align: left; flex: none; max-width: 45%; }
  .table-wrap.stack td.lead { display: block; text-align: left; font-weight: 600; padding-top: 10px; }
  .table-wrap.stack td.lead::before { content: none; }
  .table-wrap.stack td.actions { justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
  .table-wrap.stack td.actions::before { content: none; }
  .table-wrap.stack td:empty { display: none; }
  .table-wrap.stack td:has(.preview), .table-wrap.stack td:has(details) { display: block; text-align: left; }
  .table-wrap.stack td:has(.preview)::before, .table-wrap.stack td:has(details)::before { display: block; max-width: none; margin-bottom: 6px; }
  .table-wrap.stack td.actions:has(details) { display: flex; }
  .table-wrap.stack .progress { min-width: 0; flex: 1; max-width: 160px; }

  .login { padding: 16px; align-items: start; padding-top: max(10vh, 24px); }
  .login .card { padding: 24px 20px; }
}
@media (max-width: 380px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi .v { font-size: 20px; }
}

/* ============================ Motion ============================
   One easing everywhere; page changes cross-fade (View Transitions), the sidebar stays put. */
:root { --ease: cubic-bezier(.2, .8, .2, 1); --fast: 140ms; --med: 240ms; }
html { scroll-behavior: smooth; }
@view-transition { navigation: auto; }
.side { view-transition-name: sidebar; }
::view-transition-group(sidebar) { animation: none; }
::view-transition-old(root) { animation: vt-out 140ms var(--ease) both; }
::view-transition-new(root) { animation: vt-in 240ms var(--ease) both; }
@keyframes vt-out { to { opacity: 0; transform: translateY(-4px); } }
@keyframes vt-in { from { opacity: 0; transform: translateY(6px); } }

.nav a { transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease), transform var(--fast) var(--ease); }
.nav a:active { transform: scale(.985); }
.btn { transition: background-color var(--fast) var(--ease), border-color var(--fast) var(--ease), color var(--fast) var(--ease),
       transform 90ms var(--ease), box-shadow var(--fast) var(--ease), filter var(--fast) var(--ease); }
.btn:active { transform: translateY(1px) scale(.985); }
.btn.primary:hover { filter: none; box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 14%, transparent); }
input, select, textarea { transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease), background-color var(--fast) var(--ease); }
input:focus, select:focus, textarea:focus { box-shadow: 0 0 0 4px color-mix(in srgb, var(--text-2) 16%, transparent); }
tbody tr { transition: background-color var(--fast) var(--ease); }
tbody tr:hover { background: color-mix(in srgb, var(--raised) 35%, transparent); }
.check input, .pill, .kpi, .card { transition: border-color var(--med) var(--ease), background-color var(--med) var(--ease); }
.kpi:hover { border-color: var(--border-strong); }
.progress i { transition: width 600ms var(--ease); }

/* Busy button while a form is being sent (set by admin.js) — blocks double submits. */
.btn.is-loading { pointer-events: none; color: transparent !important; position: relative; }
.btn.is-loading::after { content: ""; position: absolute; inset: 0; margin: auto; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-color: var(--text) transparent var(--text) var(--text); animation: spin .7s linear infinite; }
.btn.primary.is-loading::after { border-color: var(--on-primary) transparent var(--on-primary) var(--on-primary); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Notices slide in and the green one fades away on its own. */
.flash { animation: flash-in var(--med) var(--ease) both; transition: opacity 320ms var(--ease), transform 320ms var(--ease), margin 320ms var(--ease), max-height 320ms var(--ease); max-height: 200px; overflow: hidden; }
.flash.is-hiding { opacity: 0; transform: translateY(-6px); max-height: 0; margin: 0; padding-top: 0; padding-bottom: 0; border-width: 0; }
@keyframes flash-in { from { opacity: 0; transform: translateY(-8px); } }

/* First paint of a page: cards rise in once, staggered. Disabled on auto-refresh swaps. */
.page-enter > .kpis > .kpi, .page-enter > .card, .page-enter > .grid > .card { animation: rise 420ms var(--ease) both; }
.page-enter > .kpis > .kpi:nth-child(2) { animation-delay: 30ms; } .page-enter > .kpis > .kpi:nth-child(3) { animation-delay: 60ms; }
.page-enter > .kpis > .kpi:nth-child(4) { animation-delay: 90ms; } .page-enter > .kpis > .kpi:nth-child(5) { animation-delay: 120ms; }
.page-enter > .kpis > .kpi:nth-child(6) { animation-delay: 150ms; }
.page-enter > .card:nth-of-type(2), .page-enter > .grid:nth-of-type(2) > .card { animation-delay: 80ms; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.bar i { transform-origin: bottom; animation: grow 640ms var(--ease) both; animation-delay: calc(var(--i, 0) * 28ms + 120ms); }
@keyframes grow { from { transform: scaleY(0); } }
details > *:not(summary) { animation: rise 200ms var(--ease) both; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after, ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) {
    animation-duration: .001ms !important; animation-delay: 0ms !important; transition-duration: .001ms !important;
  }
}
