/* Сферум · активность — dashboard + admin styles */

:root {
  --bg: #f4f6fb;
  --bg-glow-1: #dbe6ff;
  --bg-glow-2: #e8e2ff;
  --surface: #ffffff;
  --surface-2: #f5f7fc;
  --surface-3: #eaeff8;
  --border: #e4e9f2;
  --border-strong: #cfd8e8;
  --text: #0d1526;
  --muted: #61708a;
  --muted-2: #8b98ad;
  --accent: #2f6bf3;
  --accent-ink: #ffffff;
  --accent-soft: #ecf2ff;
  --accent-2: #7c5cff;
  --up: #14804a;
  --down: #c02b2b;
  --warn: #b45309;
  --shadow-xs: 0 1px 2px rgba(13, 21, 38, .05);
  --shadow-sm: 0 1px 2px rgba(13, 21, 38, .05), 0 2px 6px rgba(13, 21, 38, .04);
  --shadow-md: 0 6px 20px rgba(13, 21, 38, .09), 0 2px 6px rgba(13, 21, 38, .04);
  --shadow-lg: 0 30px 70px rgba(10, 18, 36, .25);
  --radius: 14px;
  --radius-sm: 10px;
  --topbar-h: 60px;
  --tabs-h: 50px;
  --stick-top: 110px;
  --head-1: 36px;
  --head-dates: 40px;
  --name-w: 300px;
  --font: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #070c17;
  --bg-glow-1: #12203c;
  --bg-glow-2: #1b1740;
  --surface: #0f172a;
  --surface-2: #141e33;
  --surface-3: #1d2942;
  --border: #1f2c47;
  --border-strong: #2c3c5c;
  --text: #e9eff9;
  --muted: #94a4c0;
  --muted-2: #6d7d99;
  --accent: #5a8dff;
  --accent-ink: #05101f;
  --accent-soft: #15233d;
  --accent-2: #a78bfa;
  --up: #4ade80;
  --down: #fb7185;
  --warn: #fbbf24;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, .55);
  --shadow-lg: 0 30px 70px rgba(0, 0, 0, .7);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

/* `height: 100%` would cap the body's box at one viewport and stop the sticky
   top bar / tabs from sticking once the page is scrolled further. */
html { height: 100%; }
body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto 0;
  height: 420px;
  background:
    radial-gradient(60% 100% at 12% 0%, var(--bg-glow-1) 0%, transparent 70%),
    radial-gradient(50% 100% at 88% 0%, var(--bg-glow-2) 0%, transparent 70%);
  opacity: .7;
  pointer-events: none;
  z-index: 0;
}

body.modal-open { overflow: hidden; }

h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; }
a { color: inherit; }

/* ------------------------------------------------------------- top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; text-decoration: none; }

.logo {
  width: 36px; height: 36px;
  border-radius: 11px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 40%, transparent);
  flex: none;
}

.brand-text { min-width: 0; }
.brand-text h1 {
  font-size: 15.5px; font-weight: 680; letter-spacing: -.25px;
  white-space: nowrap;
}
.brand-text .sub {
  font-size: 12px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

/* --------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13px; font-weight: 550;
  text-decoration: none;
  cursor: pointer;
  transition: background .14s, border-color .14s, transform .06s, color .14s, box-shadow .14s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: color-mix(in srgb, var(--accent) 35%, var(--border-strong)); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn[disabled] { opacity: .55; pointer-events: none; }

.btn-primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 92%, #fff), var(--accent));
  border-color: transparent;
  color: var(--accent-ink);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 35%, transparent);
}
.btn-primary:hover { filter: brightness(1.06); background: var(--accent); }

.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }

.btn-danger { color: var(--down); }
.btn-danger:hover { background: color-mix(in srgb, var(--down) 12%, transparent); border-color: color-mix(in srgb, var(--down) 40%, transparent); }

.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background .14s, color .14s;
  flex: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.icon-btn .icon-moon { display: none; }
.icon-btn.is-dark .icon-sun { display: none; }
.icon-btn.is-dark .icon-moon { display: block; }

/* ---------------------------------------------------------------- tabs */
.tabs {
  position: sticky;
  top: var(--topbar-h);
  z-index: 49;
  height: var(--tabs-h);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 24px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(1.3) blur(10px);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  display: inline-flex; align-items: center; gap: 8px;
  height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 580;
  cursor: pointer;
  white-space: nowrap;
  transition: background .16s, color .16s, border-color .16s;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.is-active {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-xs);
}
.tab.is-active .tab-count {
  background: var(--accent-soft);
  color: var(--accent);
}
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.tab-count {
  font-size: 11px;
  font-weight: 650;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.tabs-note {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted-2);
  white-space: nowrap;
  padding-left: 14px;
}

/* ----------------------------------------------------------------- page */
.page {
  position: relative;
  z-index: 1;
  padding: 18px 24px 44px;
  max-width: 1840px;
  margin: 0 auto;
}
.page-narrow { max-width: 1080px; }

/* -------------------------------------------------------------- toolbar */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 13px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.toolbar-main {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar-periods {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.toolbar-periods .field-label { flex: none; }
.toolbar-periods .chips { flex: 1 1 auto; }

.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field-label {
  font-size: 10.5px; font-weight: 680;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted-2);
}

.field-search { position: relative; flex: 1 1 260px; max-width: 380px; flex-direction: row; align-items: center; }
.field-search svg { position: absolute; left: 11px; color: var(--muted-2); pointer-events: none; }
.field-search input {
  width: 100%; height: 34px;
  padding: 0 12px 0 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit; font-size: 13px;
  transition: border-color .14s, box-shadow .14s;
}
.field-search input::placeholder { color: var(--muted-2); }
.field-search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.field-periods { flex: 1 1 320px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 11px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--muted);
  font-size: 12.5px; font-weight: 550;
  cursor: pointer;
  transition: all .13s;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip.is-on {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  color: var(--accent);
  font-weight: 650;
}
.chip .chip-kind { font-size: 10px; opacity: .7; font-weight: 500; }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

select.control {
  height: 34px; padding: 0 30px 0 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit; font-size: 13px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2361708a' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
select.control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent); }

.btn-toggle .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted-2);
  transition: background .14s;
}
.btn-toggle.is-on {
  border-color: color-mix(in srgb, var(--accent) 50%, transparent);
  color: var(--accent);
  background: var(--accent-soft);
}
.btn-toggle.is-on .dot { background: var(--accent); }

/* ----------------------------------------------------------- hero cards */
.hero-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.hero-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 15px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow .15s, border-color .15s, transform .1s;
}
.hero-card:hover {
  box-shadow: var(--shadow-md);
  border-color: color-mix(in srgb, var(--accent) 32%, var(--border));
  transform: translateY(-1px);
}
.hero-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hero-card::after {
  content: "";
  position: absolute;
  inset: -40% -30% auto auto;
  width: 160px; height: 160px;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--accent) 18%, transparent), transparent 70%);
  pointer-events: none;
}

.hero-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hero-label {
  font-size: 10.5px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hero-target {
  margin-left: auto;
  font-size: 10.5px; font-weight: 650;
  padding: 1px 7px; border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
  flex: none;
  white-space: nowrap;
}

.hero-main { display: flex; align-items: baseline; gap: 10px; }
.hero-value {
  font-size: 28px; font-weight: 700;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.hero-delta { font-size: 12.5px; font-weight: 650; display: inline-flex; align-items: center; gap: 3px; }

.hero-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}
.hero-bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
  transition: width .35s ease;
}

.hero-foot { font-size: 11.5px; color: var(--muted); }

/* --------------------------------------------------------------- table */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  /* clip (not hidden) — hidden would make this a scroll container and break
     the page-level sticky table header */
  overflow: clip;
}

/* per-kind name column width */
.table-card.kind-ou { --name-w: 300px; }
.table-card.kind-dou { --name-w: 360px; }

.table-caption {  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
}
.caption-title { font-size: 14.5px; font-weight: 680; letter-spacing: -.2px; }
.caption-meta { font-size: 12px; color: var(--muted); }
.caption-sort {
  margin-left: 14px;
  padding-left: 14px;
  border-left: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--muted);
}
.caption-sort b { color: var(--text); font-weight: 600; }
.caption-sort .reset {
  border: 0; background: none; padding: 0;
  color: var(--accent); cursor: pointer;
  font-size: 12px; font-weight: 550;
}
.caption-sort .reset:hover { text-decoration: underline; }

/* rating summary + dots */
.caption-rating {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.rating-summary-label {
  font-size: 10px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted-2);
}
.rating-item { display: inline-flex; align-items: center; gap: 5px; }

.rating-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 14%, transparent);
}
.rating-dot.r3 { background: var(--up); color: var(--up); }
.rating-dot.r2 { background: var(--warn); color: var(--warn); }
.rating-dot.r1 { background: var(--down); color: var(--down); }
.rating-dot.r0 { background: var(--muted-2); color: var(--muted-2); }

/* duplicate horizontal scrollbar along the top edge of the table, so it is
   reachable without scrolling to the bottom of a 40-row list */
.table-scroll-top {
  position: sticky;
  top: var(--stick-top);
  z-index: 7;
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  line-height: 0;
}
.table-scroll-top > div { height: 1px; }
.table-scroll-top::-webkit-scrollbar { height: 11px; }
.table-scroll-top::-webkit-scrollbar-track { background: var(--surface-2); }
.table-scroll-top::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 8px;
  border: 2px solid var(--surface-2);
}
.table-scroll-top::-webkit-scrollbar-thumb:hover { background: var(--muted-2); }

.table-wrap { overflow-x: auto; overflow-y: hidden; }

/* when everything fits, drop the scroll container so the sticky header can
   stick to the page (a scroll container would trap it) */
.table-wrap.is-fit { overflow: visible; }

/* …and when it does not fit, the wrapper is a scroll container, so the
   vertical sticky offsets must be switched off (they would push the header
   into the body).  The name column stays pinned horizontally. */
.table-wrap:not(.is-fit) table.grid thead tr.h-group th,
.table-wrap:not(.is-fit) table.grid thead tr.h-dates th,
.table-wrap:not(.is-fit) table.grid th.col-name { top: auto; }

/* horizontal scrollbar that is actually usable */
.table-wrap::-webkit-scrollbar { height: 12px; }
.table-wrap::-webkit-scrollbar-track { background: var(--surface-2); border-radius: 8px; }
.table-wrap::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 8px;
  border: 2px solid var(--surface);
}
.table-wrap::-webkit-scrollbar-thumb:hover { background: var(--muted-2); }

.caption-summary { margin-left: 4px; }
.caption-summary svg { color: var(--accent); }

/* district summary */
.dist-chart { color: var(--accent); margin: 2px 0 2px; }
.dist-chart svg { display: block; width: 100%; height: auto; }
.dist-chart .grid-line { stroke: var(--border); stroke-width: 1; }
.dist-chart .axis-label { fill: var(--muted-2); font-size: 7px; }
.dist-chart .target-line { stroke: var(--muted-2); stroke-width: 1; stroke-dasharray: 4 3; }
.dist-chart .target-label { fill: var(--muted-2); font-size: 7px; }
.dist-chart .series-line { fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.dist-chart .series-area { fill: currentColor; fill-opacity: .10; }
.dist-chart .series-dot { fill: currentColor; }
.dist-chart .series-dot.is-last { stroke: var(--surface); stroke-width: 1.5; }

.summary-legend {
  display: flex; gap: 12px; flex-wrap: wrap;
  font-size: 11px; color: var(--muted);
}
.summary-legend .lg { display: inline-flex; align-items: center; gap: 5px; }
.summary-legend .ln { width: 14px; height: 2px; border-radius: 2px; background: var(--accent); }
.summary-legend .ln.dashed {
  height: 0; border-top: 2px dashed var(--muted-2); background: none;
}

table.grid {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

table.grid th, table.grid td {
  padding: 0 8px;
  height: 36px;
  text-align: center;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

table.grid thead th {
  position: sticky;
  z-index: 6;
  transition: background .12s, color .12s;
}
table.grid thead tr.h-group th { top: var(--stick-top); height: var(--head-1); }
table.grid thead tr.h-dates th { top: calc(var(--stick-top) + var(--head-1)); height: var(--head-dates); }

table.grid thead th.h-group {
  background: var(--surface-2);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border-strong);
}
table.grid thead th.h-group.m-ped { color: var(--accent); }
table.grid thead th.h-group.m-ob { color: #0e7490; }
table.grid thead th.h-group.m-ro { color: #7c3aed; }
[data-theme="dark"] table.grid thead th.h-group.m-ob { color: #33d6c0; }
[data-theme="dark"] table.grid thead th.h-group.m-ro { color: #c4b5fd; }

table.grid thead th.h-date {
  font-size: 11.5px; font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-strong);
  cursor: pointer;
  user-select: none;
}
table.grid thead th.h-date:hover { background: var(--surface-3); color: var(--text); }
table.grid thead th.h-date.is-last { color: var(--text); font-weight: 680; }

table.grid thead th.h-delta {
  font-size: 11px; font-weight: 600;
  color: var(--muted-2);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-strong);
  border-left: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
table.grid thead th.h-delta:hover { background: var(--surface-3); color: var(--text); }

table.grid thead th.is-sorted {
  color: var(--accent) !important;
  background: var(--accent-soft) !important;
  box-shadow: inset 0 -2px 0 var(--accent);
}

.sort-arrow {
  display: inline-block;
  margin-left: 3px;
  font-size: 8.5px;
  opacity: 0;
  transform: translateY(-1px);
}
table.grid thead th.h-date:hover .sort-arrow,
table.grid thead th.h-delta:hover .sort-arrow { opacity: .45; }
table.grid thead th.is-sorted .sort-arrow { opacity: 1; }

/* first column */
table.grid th.col-name, table.grid td.col-name {
  position: sticky;
  left: 0;
  z-index: 4;
  text-align: left;
  width: var(--name-w);
  min-width: var(--name-w);
  max-width: var(--name-w);
  padding-left: 16px;
  padding-right: 12px;
  border-right: 1px solid var(--border);
}
table.grid th.col-name {
  z-index: 8;
  top: var(--stick-top);
  vertical-align: middle;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-strong);
  font-size: 10px; font-weight: 750;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
table.grid th.col-name:hover { background: var(--surface-3); color: var(--text); }
table.grid th.col-name.is-sorted { color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }

table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:hover td { background: var(--surface-2); }
table.grid tbody tr:hover td.col-name { background: var(--surface-2); }
table.grid tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

table.grid td.col-name { font-weight: 500; }
table.grid td.col-name .name-line {
  display: flex;
  align-items: center;
  gap: 7px;
  width: calc(var(--name-w) - 30px);
}
table.grid td.col-name .nm {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
table.grid td.col-name .inn {
  display: block;
  width: calc(var(--name-w) - 30px);
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 10.5px;
  color: var(--muted-2);
  font-variant-numeric: tabular-nums;
  font-weight: 450;
}

/* cells */
td.cell { position: relative; }
td.cell .val { font-weight: 550; }
td.cell.is-empty .val { color: var(--muted-2); font-weight: 400; }
td.cell.is-over .val { color: var(--warn); }
td.cell.is-over::after {
  content: "";
  position: absolute; top: 5px; right: 5px;
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--warn);
  opacity: .85;
}

td.cell-delta { border-left: 1px solid var(--border); font-weight: 650; }
.delta-up { color: var(--up); }
.delta-down { color: var(--down); }
.delta-flat { color: var(--muted-2); font-weight: 500; }
.delta-empty { color: var(--muted-2); font-weight: 400; }

table.grid tbody tr.row-avg td {
  font-weight: 700;
  background: var(--surface-2);
  border-top: 2px solid var(--border-strong);
  border-bottom: 0;
}
table.grid tbody tr.row-avg td.col-name { background: var(--surface-2); font-weight: 700; }

.table-empty { padding: 30px 16px; text-align: center; color: var(--muted); font-size: 13px; }

/* --------------------------------------------------------------- legend */
.legend {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin-top: 12px;
  padding: 0 4px;
  font-size: 11.5px; color: var(--muted);
}
.legend .lg { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 11px; height: 11px; border-radius: 3px; border: 1px solid var(--border-strong); }
.legend .lg-hint { margin-left: auto; color: var(--muted-2); }

/* --------------------------------------------------------------- footer */
.foot {
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  margin-top: 20px;
  font-size: 11.5px; color: var(--muted-2);
}

/* ------------------------------------------------------------ detail modal */
.detail {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center;
  padding: 24px;
  background: rgba(6, 12, 24, .55);
  backdrop-filter: blur(3px);
  animation: fade .16s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.detail-card {
  width: min(1180px, 100%);
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: pop .18s cubic-bezier(.2, .8, .3, 1);
}
@keyframes pop { from { transform: scale(.975); opacity: .5; } to { transform: none; opacity: 1; } }

.detail-head {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.detail-head h2 { font-size: 17px; font-weight: 680; letter-spacing: -.3px; line-height: 1.3; }
.detail-meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.detail-head .icon-btn { margin-left: auto; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr));
  gap: 14px;
  padding: 16px 20px 20px;
}

.metric-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 13px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.metric-card .mc-head { display: flex; align-items: center; gap: 8px; }
.metric-card .mc-title {
  font-size: 10.5px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted);
}
.metric-card .mc-target {
  margin-left: auto;
  font-size: 10px; font-weight: 650;
  padding: 1px 7px; border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
}
.metric-card .mc-value {
  font-size: 30px; font-weight: 720;
  letter-spacing: -1.2px;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
  display: flex; align-items: baseline; gap: 8px;
}
.metric-card .mc-hit { font-size: 13px; color: var(--up); }
.metric-card .mc-ratio { font-size: 11.5px; color: var(--muted); }
.metric-card .mc-spark { color: var(--accent); }
.metric-card .mc-delta { font-size: 12.5px; font-weight: 650; }

.mc-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.mc-table th, .mc-table td { padding: 3px 4px; text-align: right; border-bottom: 1px solid var(--border); }
.mc-table th:first-child, .mc-table td:first-child { text-align: left; }
.mc-table thead th {
  font-size: 9.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted-2); font-weight: 700;
}
.mc-table tbody tr:last-child td { border-bottom: 0; }
.mc-table tbody tr.is-current td { font-weight: 700; }
.mc-table tbody tr.is-current td:first-child { color: var(--accent); }

/* ---------------------------------------------------------------- admin */
.login-wrap { display: grid; place-items: center; padding: 40px 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-pad { padding: 20px; }
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
}
.card-head h2 { font-size: 14px; font-weight: 660; letter-spacing: -.15px; }
.card-head .hint { margin-left: auto; font-size: 11.5px; color: var(--muted-2); }

.login-card { width: min(420px, 100%); }
.login-card .card-pad { display: flex; flex-direction: column; gap: 14px; }
.login-lede { font-size: 13px; color: var(--muted); line-height: 1.5; }

.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.form-field input, .form-field select {
  height: 38px; padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit; font-size: 13.5px;
}
.form-field input:focus, .form-field select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}
.form-actions { display: flex; gap: 8px; justify-content: flex-end; }

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 16px;
  margin-bottom: 16px;
  align-items: start;
}

.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: 13px;
  padding: 34px 20px;
  text-align: center;
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .dz-icon { color: var(--accent); margin-bottom: 10px; }
.dropzone .dz-title { font-weight: 620; font-size: 14px; margin-bottom: 5px; }
.dropzone .dz-hint { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.dropzone.is-busy { pointer-events: none; opacity: .6; }

.report { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.report-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.report-cell {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
}
.report-cell .rk { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-2); font-weight: 700; }
.report-cell .rv { font-size: 16px; font-weight: 660; font-variant-numeric: tabular-nums; }

.notice {
  display: flex; gap: 9px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  line-height: 1.5;
  border: 1px solid;
}
.notice-warn { background: color-mix(in srgb, var(--warn) 10%, transparent); border-color: color-mix(in srgb, var(--warn) 32%, transparent); color: var(--warn); }
.notice-ok { background: color-mix(in srgb, var(--up) 10%, transparent); border-color: color-mix(in srgb, var(--up) 30%, transparent); color: var(--up); }
.notice-info { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 26%, transparent); color: var(--accent); }
.notice ul { margin: 5px 0 0; padding-left: 18px; }
.notice li { margin: 1px 0; }

.periods-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.periods-table th, .periods-table td {
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.periods-table thead th {
  font-size: 10px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted-2); font-weight: 720;
  background: var(--surface-2);
}
.periods-table tbody tr:last-child td { border-bottom: 0; }
.periods-table tbody tr:hover td { background: var(--surface-2); }
.periods-table .num { font-variant-numeric: tabular-nums; }
.periods-table .src { color: var(--muted); font-size: 12px; max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.periods-table td.right { text-align: right; }

.badge {
  display: inline-block;
  font-size: 10px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase;
  padding: 2px 8px; border-radius: 999px;
  background: var(--surface-3); color: var(--muted);
}
.badge.is-workbook { background: var(--accent-soft); color: var(--accent); }

/* ---------------------------------------------------------------- toasts */
.toast-stack {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  z-index: 90;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--text);
  color: var(--surface);
  padding: 10px 17px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toast-in .2s ease-out;
}
.toast.is-error { background: var(--down); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.skeleton {
  height: 220px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 37%, var(--surface) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
  border: 1px solid var(--border);
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* ------------------------------------------------------------ responsive */
@media (max-width: 1240px) {
  .admin-grid { grid-template-columns: minmax(0, 1fr); }
  .detail-grid { --cols: 3; }
}

@media (max-width: 1080px) {
  .table-wrap { overflow-x: auto; }
  table.grid thead tr.h-group th,
  table.grid thead tr.h-dates th,
  table.grid th.col-name { top: auto; }
  table.grid thead tr.h-group th { height: auto; padding-top: 9px; padding-bottom: 9px; }
  table.grid thead tr.h-dates th { height: auto; padding-top: 8px; padding-bottom: 8px; }
}

@media (max-width: 900px) {
  .table-card.kind-ou, .table-card.kind-dou { --name-w: min(240px, 62vw); }
  .topbar { padding: 0 14px; gap: 10px; }
  .tabs { padding: 0 14px; }
  .tabs-note { display: none; }
  .page { padding: 14px 12px 36px; }
  .brand-text h1 { font-size: 14.5px; }
  .brand-text .sub { font-size: 11px; }
  .hero-cards { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
  .hero-value { font-size: 24px; }
  .toolbar { gap: 12px; padding: 12px; }
  .field-search { flex: 1 1 100%; }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .detail { padding: 10px; }
  .detail-card { max-height: calc(100vh - 20px); overflow-y: auto; }
  .caption-sort { margin-left: 0; }
  .topbar-actions .btn span { display: none; }
}

@media (max-width: 640px) {
  .brand-text .sub { display: none; }
  .hero-cards { grid-template-columns: minmax(0, 1fr); }
  .hero-card { padding: 12px 14px; }
  .hero-value { font-size: 22px; }
  .legend .lg-hint { display: none; }
  .periods-table .src { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
