/* ============================================================
   Обмінники GBP/UAH — дизайн-система v2
   Дві шкіри на CSS-змінних (data-theme на <html>):
     dark  — «Термінал» (Bloomberg-style): IBM Plex Mono для цифр,
             зелений акцент, бурштинові підсвітки.
     light — «Швейцарський»: Golos Text 700/800 для цифр,
             червоний бренд-акцент, товсті чорні лінійки.
   Палітри графіків (--viz-*) валідовані dataviz-скриптом
   для обох тем (CVD, lightness band, contrast).
   ============================================================ */

/* ---------------- шрифти (локальні woff2) ---------------- */

/* IBM Plex Mono 400 */
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal; font-weight: 400; font-display: swap;
  src: url("/static/fonts/ibm-plex-mono-400-cyr-ext.woff2") format("woff2");
  unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal; font-weight: 400; font-display: swap;
  src: url("/static/fonts/ibm-plex-mono-400-cyr.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal; font-weight: 400; font-display: swap;
  src: url("/static/fonts/ibm-plex-mono-400-latin-ext.woff2") format("woff2");
  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: "IBM Plex Mono";
  font-style: normal; font-weight: 400; font-display: swap;
  src: url("/static/fonts/ibm-plex-mono-400-latin.woff2") format("woff2");
  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;
}
/* IBM Plex Mono 600 */
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal; font-weight: 600; font-display: swap;
  src: url("/static/fonts/ibm-plex-mono-600-cyr-ext.woff2") format("woff2");
  unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal; font-weight: 600; font-display: swap;
  src: url("/static/fonts/ibm-plex-mono-600-cyr.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal; font-weight: 600; font-display: swap;
  src: url("/static/fonts/ibm-plex-mono-600-latin-ext.woff2") format("woff2");
  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: "IBM Plex Mono";
  font-style: normal; font-weight: 600; font-display: swap;
  src: url("/static/fonts/ibm-plex-mono-600-latin.woff2") format("woff2");
  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;
}
/* Golos Text — варіативний (wght 400–900), один файл на сабсет */
@font-face {
  font-family: "Golos Text";
  font-style: normal; font-weight: 400 900; font-display: swap;
  src: url("/static/fonts/golos-text-cyr-ext.woff2") format("woff2");
  unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}
@font-face {
  font-family: "Golos Text";
  font-style: normal; font-weight: 400 900; font-display: swap;
  src: url("/static/fonts/golos-text-cyr.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Golos Text";
  font-style: normal; font-weight: 400 900; font-display: swap;
  src: url("/static/fonts/golos-text-latin-ext.woff2") format("woff2");
  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: "Golos Text";
  font-style: normal; font-weight: 400 900; font-display: swap;
  src: url("/static/fonts/golos-text-latin.woff2") format("woff2");
  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;
}

/* ---------------- токени: dark = «Термінал» (за замовчуванням) ---------------- */

:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:           #0a0f0d;
  --surface:        #0d1411;
  --surface-2:      #121b16;
  --text-primary:   #e8fff2;
  --text-secondary: #c8e6d4;
  --text-muted:     #5d7a6a;
  --gridline:       #16221b;
  --baseline:       #24362c;
  --border:         #1d2b24;

  --accent:         #5eea9c;
  --accent-ink:     #06130c;
  --accent-soft:    rgba(94, 234, 156, 0.10);

  --amber:          #ffb52e;
  --amber-soft:     rgba(255, 181, 46, 0.10);
  --up:             #5eea9c;
  --down:           #ff7a6e;

  --font-ui:  "Golos Text", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-num: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace;
  --num-weight:     600;
  --num-weight-big: 600;
  --h-weight:       600;

  --head-rule: 1px solid #1d2b24;
  --nav-marker: #5eea9c;

  /* тікер (у dark збігається зі шкірою) */
  --tk-bg:     #0d1411;
  --tk-border: #1d2b24;
  --tk-text:   #c8e6d4;
  --tk-muted:  #5d7a6a;
  --tk-up:     #5eea9c;
  --tk-down:   #ff7a6e;

  /* НБУ-чип — бурштиновий */
  --nbu-fg:     #ffb52e;
  --nbu-bg:     rgba(255, 181, 46, 0.08);
  --nbu-border: rgba(255, 181, 46, 0.35);

  /* валютне табло */
  --fx-digit:     #5eea9c;
  --fx-glow:      0 0 12px rgba(94, 234, 156, 0.40);
  --fx-digit-gbp: #ffb52e;
  --fx-glow-gbp:  0 0 12px rgba(255, 181, 46, 0.40);

  /* графіки — валідована категоріальна палітра (dark, surface #0d1411) */
  --viz-1: #21a566;   /* зелений  — продаж мін (акцент) */
  --viz-2: #bd7d0e;   /* бурштин  — продаж сер */
  --viz-3: #2296ad;   /* аква     — продаж макс */
  --viz-5: #d24a3e;   /* червоний — купівля сер */
  --viz-7: #7f6fd6;   /* фіолет   — НБУ */

  --status-good:      #34c47c;
  --status-good-text: #7df0b4;
  --status-warn:      #ffb52e;
  --status-warn-text: #ffb52e;
  --status-crit:      #ff7a6e;
  --status-crit-text: #ff958a;
  --good-soft: rgba(52, 196, 124, 0.14);
  --warn-soft: rgba(255, 181, 46, 0.12);
  --crit-soft: rgba(255, 122, 110, 0.14);

  --shadow: none;
}

/* ---------------- токени: light = «Швейцарський» ---------------- */

:root[data-theme="light"] {
  color-scheme: light;
  --page:           #f7f6f2;
  --surface:        #ffffff;
  --surface-2:      #f1efe9;
  --text-primary:   #16151a;
  --text-secondary: #45434c;
  --text-muted:     #77747e;
  --gridline:       #e7e4dc;
  --baseline:       #d8d5cd;
  --border:         #d8d5cd;

  --accent:         #e0332c;
  --accent-ink:     #ffffff;
  --accent-soft:    rgba(224, 51, 44, 0.08);

  --amber:          #16151a;
  --amber-soft:     rgba(22, 21, 26, 0.06);
  --up:             #0a7d4f;
  --down:           #c62b25;

  --font-ui:  "Golos Text", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-num: "Golos Text", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --num-weight:     700;
  --num-weight-big: 800;
  --h-weight:       800;

  --head-rule: 2px solid #16151a;
  --nav-marker: #e0332c;

  /* тікер — свідомо темний «швейцарський» масthead */
  --tk-bg:     #16151a;
  --tk-border: #16151a;
  --tk-text:   #f3f1ea;
  --tk-muted:  #9a97a0;
  --tk-up:     #4ad18f;
  --tk-down:   #ff8177;

  --nbu-fg:     #16151a;
  --nbu-bg:     #ffffff;
  --nbu-border: #16151a;

  --fx-digit:     #16151a;
  --fx-glow:      none;
  --fx-digit-gbp: #16151a;
  --fx-glow-gbp:  none;

  /* графіки — валідована категоріальна палітра (light, surface #ffffff) */
  --viz-1: #e0332c;   /* червоний — продаж мін (акцент) */
  --viz-2: #3563a8;   /* синій    — продаж сер */
  --viz-3: #b5851f;   /* охра     — продаж макс */
  --viz-5: #116e46;   /* зелений  — купівля сер */
  --viz-7: #8a5fb0;   /* фіолет   — НБУ */

  --status-good:      #0a7d4f;
  --status-good-text: #06603c;
  --status-warn:      #b5851f;
  --status-warn-text: #7a5a10;
  --status-crit:      #c62b25;
  --status-crit-text: #a31f19;
  --good-soft: rgba(10, 125, 79, 0.10);
  --warn-soft: rgba(181, 133, 31, 0.14);
  --crit-soft: rgba(198, 43, 37, 0.10);

  --shadow: none;
}

/* ---------------- base ---------------- */

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

:root {
  --ticker-h: 34px;
  --sidebar-w: 220px;
  --topbar-h: 52px;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text-primary);
  background: var(--page);
  transition: background-color 0.25s ease, color 0.25s ease;
}

h1 { font-size: 1.35rem; font-weight: var(--h-weight); margin: 0; }
h2 { font-size: 1rem; margin: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--text-muted); font-size: 0.86em; }
.accent { color: var(--accent); }

/* усі числові значення — шрифт цифр теми */
.stat-value, .chip-value, .num-inline, .source-chip,
.table td.num, .table th.num, .nbu-chip strong, .pw-once,
.fx-val, .fx-delta {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}

/* ---------------- тікер ---------------- */

.ticker-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--ticker-h);
  z-index: 90;
  display: flex;
  align-items: center;
  overflow: hidden;
  background: var(--tk-bg);
  border-bottom: 1px solid var(--tk-border);
  font-family: var(--font-num);
  font-size: 0.8rem;
}

.ticker-track {
  display: flex;
  width: max-content;
  will-change: transform;
}
.ticker-track.tk-animate {
  animation: tk-scroll var(--tk-dur, 30s) linear infinite;
}
.ticker-bar:hover .ticker-track.tk-animate { animation-play-state: paused; }
@keyframes tk-scroll { to { transform: translateX(-50%); } }

.tk-strip { display: flex; }

.tk-item {
  display: inline-flex;
  align-items: baseline;
  gap: 0.5em;
  padding: 0 1.15em;
  white-space: nowrap;
  color: var(--tk-text);
  border-left: 1px solid var(--tk-border);
}
.tk-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--tk-muted);
}
.tk-item.tk-up,   .tk-item.tk-up   .tk-label { color: var(--tk-up); }
.tk-item.tk-down, .tk-item.tk-down .tk-label { color: var(--tk-down); }

@media (prefers-reduced-motion: reduce) {
  .ticker-track.tk-animate { animation: none; }
  .ticker-bar { overflow-x: auto; }
}

/* ---------------- каркас: сайдбар + контент ---------------- */

body.with-shell { padding-top: var(--ticker-h); }

.sidebar {
  position: fixed;
  top: var(--ticker-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  z-index: 80;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  transition: background-color 0.25s ease;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.85rem 1rem 0.7rem;
}

.brand {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }

.nav-burger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 40px;
  height: 36px;
  padding: 8px 9px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.nav-burger span {
  display: block;
  height: 2px;
  background: var(--text-primary);
  border-radius: 1px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
body.nav-open .nav-burger span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
body.nav-open .nav-burger span:nth-child(2) { opacity: 0; }
body.nav-open .nav-burger span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.sidebar-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0.35rem 0.6rem;
}

.side-nav a {
  display: block;
  padding: 0.42rem 0.7rem;
  border-left: 3px solid transparent;
  border-radius: 0 7px 7px 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
}
.side-nav a:hover {
  color: var(--text-primary);
  background: var(--accent-soft);
  text-decoration: none;
}
.side-nav a.active {
  border-left-color: var(--nav-marker);
  color: var(--text-primary);
  background: var(--surface-2);
  font-weight: 600;
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--border);
}

.sidebar-foot-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.nbu-chip {
  font-size: 0.78rem;
  color: var(--nbu-fg);
  background: var(--nbu-bg);
  border: 1px solid var(--nbu-border);
  border-radius: 999px;
  padding: 0.22rem 0.7rem;
  white-space: nowrap;
  text-align: center;
}
.nbu-chip strong { font-weight: var(--num-weight); }

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.28rem 0.55rem;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.theme-toggle:hover { background: var(--surface-2); }
.theme-icon::before { content: "☀️"; }
:root[data-theme="light"] .theme-icon::before { content: "🌙"; }

.logout { color: var(--text-muted); font-size: 0.88rem; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  top: calc(var(--ticker-h) + var(--topbar-h));
  left: 0; right: 0; bottom: 0;
  z-index: 78;
  background: rgba(0, 0, 0, 0.55);
}

body.with-shell .content { margin-left: var(--sidebar-w); }

/* ---------------- layout ---------------- */

.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 1.1rem 1.25rem 2.5rem;
}

.page-head {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.page-head .btn { margin-left: auto; }

.grid { display: grid; gap: 1rem; margin-bottom: 1rem; }
.grid > * { min-width: 0; }
.grid-cities { grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); }
.grid-widgets { grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); }

/* ---------------- cards ---------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
  transition: background-color 0.25s ease;
}
.grid .card { margin-bottom: 0; }

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.7rem;
  padding-bottom: 0.45rem;
  border-bottom: var(--head-rule);
}
.card-head h2 {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-secondary);
}

.empty {
  color: var(--text-muted);
  text-align: center;
  padding: 1rem 0;
  margin: 0;
}

/* ---------------- валютне табло (dashboard) ---------------- */

.fx-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.fx-board[hidden] { display: none; }

.fx-cell {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.85rem;
}

.fx-flag { flex: 0 0 auto; display: inline-flex; }
.fx-flag svg {
  width: 27px;
  height: 18px;
  display: block;
  border-radius: 3px;
  outline: 1px solid var(--border);
}

.fx-body { min-width: 0; display: flex; flex-direction: column; }

.fx-code {
  font-size: 0.66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.fx-line { display: flex; align-items: baseline; gap: 0.45rem; }

.fx-val {
  font-size: 1.2rem;
  font-weight: var(--num-weight-big);
  color: var(--fx-digit);
  text-shadow: var(--fx-glow);
  white-space: nowrap;
}
.fx-cell[data-cur="GBP"] .fx-val {
  color: var(--fx-digit-gbp);
  text-shadow: var(--fx-glow-gbp);
}

.fx-delta { font-size: 0.76rem; white-space: nowrap; }
.fx-delta.up { color: var(--up); }
.fx-delta.down { color: var(--down); }
.fx-delta.flat { color: var(--text-muted); }

/* ---------------- stats ---------------- */

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100px, 100%), 1fr));
  gap: 0.55rem;
  margin-bottom: 0.7rem;
}

.stat {
  min-width: 0;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 0.45rem 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
}

.stat-label {
  font-size: 0.66rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-value {
  font-size: clamp(1rem, 3.2vw, 1.2rem);
  font-weight: var(--num-weight);
}
.stat-value.big {
  font-size: clamp(1.25rem, 4.5vw, 1.6rem);
  font-weight: var(--num-weight-big);
}

.best-line { margin-bottom: 0.7rem; font-size: 0.92rem; }

.signal-list { margin: 0; padding-left: 1.2rem; }
.signal-list li { margin-bottom: 0.35rem; }

.health { display: flex; flex-direction: column; gap: 0.5rem; }
.health-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

/* ---------------- badges ---------------- */

.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  white-space: nowrap;
  vertical-align: middle;
}
.badge-ok      { background: var(--good-soft); color: var(--status-good-text); }
.badge-warn    { background: var(--warn-soft); color: var(--status-warn-text); }
.badge-crit    { background: var(--crit-soft); color: var(--status-crit-text); }
.badge-neutral { background: var(--surface-2); color: var(--text-secondary); }

/* ---------------- buttons ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 1rem;
  cursor: pointer;
  background: var(--surface);
  color: var(--text-primary);
  transition: background-color 0.15s ease, opacity 0.15s ease;
}
.btn:hover { background: var(--surface-2); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn[disabled] { opacity: 0.6; cursor: wait; }

.btn-block { width: 100%; justify-content: center; }

/* спінер під час оновлення */
.btn .spin {
  display: inline-block;
  width: 0.9em; height: 0.9em;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- form controls (глобально) ---------------- */

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="email"],
input[type="search"],
input[type="tel"],
input[type="url"],
select,
textarea {
  font: inherit;
  height: 38px;
  padding: 0 0.7rem;
  border: 1px solid var(--baseline);
  border-radius: 8px;
  background: var(--page);
  color: var(--text-primary);
  min-width: 0;
  max-width: 100%;
}

input[type="number"] { font-family: var(--font-num); }

select { background: var(--surface); }

textarea {
  height: auto;
  min-height: 88px;
  padding: 0.55rem 0.75rem;
  resize: vertical;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="email"]:focus,
input[type="search"]:focus,
input[type="tel"]:focus,
input[type="url"]:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

/* лейбл над полем */
.control {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
}

/* ---------------- tables ---------------- */

.table-scroll { overflow-x: auto; margin: 0 -0.25rem; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table th {
  text-align: left;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0.4rem 0.5rem;
  border-bottom: var(--head-rule);
  white-space: nowrap;
}

.table td {
  padding: 0.42rem 0.5rem;
  border-bottom: 1px solid var(--gridline);
  vertical-align: middle;
}

/* зебра: звичайні таблиці */
.table:not(.has-sources) tbody tr:nth-of-type(even) { background: var(--surface-2); }
/* зебра: таблиці з прихованими рядками джерел (парний видимий рядок = tr 4n+3) */
.table.has-sources tbody tr:nth-of-type(4n+3) { background: var(--surface-2); }

.table .num,
.table td.num {
  text-align: right;
  white-space: nowrap;
}
.table th.num { text-align: right; }

.table-compact { font-size: 13px; }
.table-compact td, .table-compact th { padding: 0.28rem 0.42rem; }

/* обрізання довгих назв (щільні таблиці дашборда) */
.table td.td-name {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-stale td { color: var(--text-muted); }
.row-stale .best-rate { color: inherit; }

.best-rate {
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 5px;
  padding: 0.05rem 0.3rem;
}
:root[data-theme="light"] .best-rate { color: #b3211b; }

.spread-warn { cursor: help; margin-left: 0.2rem; }

.tel { white-space: nowrap; }
.addr { font-size: 0.8em; }

/* розгортувані джерела */
.src-toggle {
  font: inherit;
  font-size: 0.82rem;
  font-family: var(--font-num);
  color: var(--accent);
  background: none;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.12rem 0.5rem;
  cursor: pointer;
}
:root[data-theme="light"] .src-toggle { color: #b3211b; }
.src-toggle:hover { background: var(--accent-soft); }

.sources-row td {
  background: var(--surface-2);
  padding: 0.55rem 0.75rem;
}

.sources-detail {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.source-chip {
  font-size: 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.18rem 0.65rem;
}
.source-chip.source-best { border-color: var(--accent); }

/* ---------------- alerts / banners ---------------- */

.alert {
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  margin-bottom: 1rem;
  font-size: 0.92rem;
}
.alert-error {
  background: var(--crit-soft);
  color: var(--status-crit-text);
  border: 1px solid var(--status-crit);
}

.nbu-banner {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 0.6rem 0.9rem;
  margin-bottom: 1rem;
}
.nbu-banner strong {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-weight: var(--num-weight);
}

/* ---------------- news ---------------- */

.news-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.92rem;
  color: var(--text-secondary);
}
.news-card .news-when {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.9rem;
}

/* розібраний дайджест: секції з іконками та кольоровою межею */
.news-text.news-parsed { white-space: normal; }
.digest { display: flex; flex-direction: column; gap: 0.6rem; }
.digest-section {
  border-left: 3px solid var(--sec-color, var(--baseline));
  background: var(--surface-2);
  border-radius: 0 8px 8px 0;
  padding: 0.55rem 0.8rem 0.6rem;
  min-width: 0;
}
.digest-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
}
.digest-icon {
  display: inline-flex;
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  align-items: center;
  justify-content: center;
}
.digest-icon svg {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 4px;
  overflow: hidden;
}
.digest-icon { color: var(--sec-color, var(--text-secondary)); }
.digest-title {
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--sec-color, var(--text-secondary));
}
.digest-list {
  margin: 0;
  padding-left: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  font-size: 0.92rem;
  color: var(--text-secondary);
}
.digest-list li { overflow-wrap: anywhere; }
.digest-list li::marker { color: var(--sec-color, var(--text-muted)); }
.digest-para {
  margin: 0 0 0.3rem;
  font-size: 0.92rem;
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}
.digest-para:last-child { margin-bottom: 0; }

/* кольори секцій — узгоджені з палітрою теми */
.digest-sec-gbp  { --sec-color: var(--viz-1); }
.digest-sec-uah  { --sec-color: var(--viz-3); }
.digest-sec-mkt  { --sec-color: var(--viz-7); }
.digest-sec-warn { --sec-color: var(--status-warn-text); }
.digest-sec-sum  { --sec-color: var(--viz-2); }

/* ---------------- login ---------------- */

.login-wrap {
  min-height: calc(100vh - 6rem);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 2rem;
}

.login-title {
  font-size: 1.3rem;
  font-weight: var(--h-weight);
  margin: 0 0 0.25rem;
  text-align: center;
}
.login-sub {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
  margin: 0 0 1.25rem;
}

.login-form { display: flex; flex-direction: column; gap: 0.4rem; }
.login-form label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-top: 0.5rem;
}
.login-form .btn { margin-top: 1rem; }

/* ---------------- charts page ---------------- */

.chart-card { padding-bottom: 1.25rem; }

.chart-controls {
  display: flex;
  align-items: end;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.control-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.range-group {
  display: inline-flex;
  border: 1px solid var(--baseline);
  border-radius: 8px;
  overflow: hidden;
}
.range-group button {
  font: inherit;
  font-size: 0.86rem;
  padding: 0.35rem 0.8rem;
  border: none;
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  border-right: 1px solid var(--gridline);
}
.range-group button:last-child { border-right: none; }
.range-group button:hover { background: var(--surface-2); }
.range-group button.active {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.chart-wrap { position: relative; height: 420px; }
.chart-wrap canvas { max-width: 100%; }

.chart-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  text-align: center;
  padding: 1rem;
}
.chart-state[hidden] { display: none; }

/* ---------------- market (TradingView) ---------------- */

.tv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.tv-cell { margin-bottom: 0; display: flex; flex-direction: column; }
.tv-title {
  margin-bottom: 0.55rem;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-secondary);
  padding-bottom: 0.45rem;
  border-bottom: var(--head-rule);
}
.tv-container { height: 480px; }
.tv-container .tradingview-widget-container,
.tv-container .tradingview-widget-container__widget { height: 100%; }

@media (max-width: 900px) {
  .tv-grid { grid-template-columns: 1fr; }
  .tv-container { height: 420px; }
}

/* ---------------- history chips ---------------- */

.chips-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.chip-card {
  flex: 1 1 140px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 0.65rem 1rem;
  display: flex;
  flex-direction: column;
}

.chip-value {
  font-size: 1.4rem;
  font-weight: var(--num-weight-big);
}
.chip-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

/* ---------------- посилання на обмінник + обрані ---------------- */

.exch-link {
  color: var(--text-primary);
  border-bottom: 1px dashed var(--baseline);
  overflow-wrap: anywhere;
}
.exch-link:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
  text-decoration: none;
}

.fav-star { margin-right: 0.2rem; font-size: 0.85em; }

body.favs-only tr[data-fav="0"] { display: none; }

.btn-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
:root[data-theme="light"] .btn-active { color: #b3211b; }

.btn-small {
  font-size: 0.8rem;
  padding: 0.22rem 0.55rem;
  border-radius: 7px;
}

.btn-danger {
  color: var(--status-crit-text);
  border-color: var(--status-crit);
}
.btn-danger:hover { background: var(--crit-soft); }

/* ---------------- сторінка обмінника ---------------- */

.grid-detail { grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); gap: 1rem; }
.grid-detail .card { padding: 0.85rem 1rem; }
.grid-detail + .card, .grid-detail ~ .card { margin-bottom: 1rem; }

.blacklist-banner {
  background: var(--crit-soft);
  border: 1px solid var(--status-crit);
  color: var(--status-crit-text);
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

/* компактна сітка «лейбл: значення» — два стовпці, на мобільному один */
.info-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.4rem 1.1rem;
  margin: 0 0 0.75rem;
}
.info-item {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
  min-width: 0;
  padding: 0.15rem 0;
  border-bottom: 1px dashed var(--gridline);
}
.info-item.info-wide { grid-column: 1 / -1; }
.info-item dt {
  font-size: 0.66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  white-space: nowrap;
  flex: 0 0 auto;
}
.info-item dd {
  margin: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
  min-width: 0;
}
.info-item dd .muted { font-weight: 400; }

@media (max-width: 640px) {
  .info-list { grid-template-columns: 1fr; }
}

.map-card { display: flex; flex-direction: column; }
.map-embed {
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 100%;
  height: 300px;
  flex: 1;
}

.rep-line {
  border-top: 1px solid var(--gridline);
  padding-top: 0.6rem;
  margin-bottom: 0.75rem;
}
.rep-summary {
  margin: 0.4rem 0 0;
  color: var(--text-secondary);
  font-size: 0.92rem;
}

.detail-actions {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  border-top: 1px solid var(--gridline);
  padding-top: 0.75rem;
}
.detail-actions form { margin: 0; }
.inline-form { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.inline-form input { flex: 1 1 160px; }
.inline-form .btn { flex: 0 0 auto; }

@media (max-width: 520px) {
  .inline-form { flex-direction: column; align-items: stretch; }
  .inline-form .btn { justify-content: center; }
}

/* ---------------- сигнали ---------------- */

.signal-form {
  display: flex;
  align-items: flex-end;
  gap: 0.8rem 1rem;
  flex-wrap: wrap;
}
.signal-form .control { flex: 0 1 230px; }
.signal-form .control input,
.signal-form .control select { width: 100%; }
.signal-form > .btn { flex: 0 0 auto; }

@media (max-width: 640px) {
  .signal-form { flex-direction: column; align-items: stretch; }
  .signal-form .control { flex: 1 1 auto; }
  .signal-form > .btn { justify-content: center; }
}

.check-col { width: 2rem; }
.check-col input { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }

.edit-row td { background: var(--surface-2); }
.form-actions { margin-top: 0.8rem; }
.form-hint { margin: 0.6rem 0 0; }

/* ---------------- адмін ---------------- */

.alert-success {
  background: var(--good-soft);
  color: var(--status-good-text);
  border: 1px solid var(--status-good);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  margin-bottom: 1rem;
}
.pw-once {
  font-size: 1rem;
  font-weight: var(--num-weight);
  overflow-wrap: anywhere;
  background: var(--surface);
  border: 1px dashed var(--status-good);
  border-radius: 7px;
  padding: 0.1rem 0.5rem;
  user-select: all;
}

.actions-cell { white-space: nowrap; }
.inline-action { display: inline-block; margin: 0 0.15rem 0 0; }

/* ---------------- форма додавання обміну ---------------- */

.add-form-card { max-width: 620px; }
.add-form { display: flex; flex-direction: column; gap: 0.85rem; }
.add-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr));
  gap: 0.85rem;
}
.add-form input,
.add-form select { width: 100%; }

.search-control { position: relative; }
.suggest-box {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 30;
  margin-top: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--baseline);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  max-height: 280px;
  overflow-y: auto;
}
.suggest-item {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 0.92rem;
  background: none;
  border: none;
  border-bottom: 1px solid var(--gridline);
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  color: var(--text-primary);
}
.suggest-item:last-child { border-bottom: none; }
.suggest-item:hover, .suggest-item:focus { background: var(--accent-soft); }
.suggest-other { color: var(--accent); font-weight: 600; }
:root[data-theme="light"] .suggest-other { color: #b3211b; }

/* ---------------- бульбашковий графік історії ---------------- */

.bubble-wrap { position: relative; }
.bubble-chip {
  position: absolute;
  top: 0.4rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  background: var(--surface-2);
  border: 1px solid var(--accent);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 0.3rem 0.85rem;
  font-size: 0.86rem;
  white-space: nowrap;
  max-width: 95%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bubble-chip[hidden] { display: none; }

/* ---------------- responsive: топбар + шухляда < 1024px ---------------- */

@media (max-width: 1023px) {
  body.with-shell { padding-top: calc(var(--ticker-h) + var(--topbar-h)); }
  body.with-shell .content { margin-left: 0; }

  .sidebar {
    right: 0;
    bottom: auto;
    width: auto;
    height: var(--topbar-h);
    flex-direction: row;
    align-items: center;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-top {
    flex: 1;
    height: 100%;
    padding: 0 0.9rem;
  }
  .nav-burger { display: inline-flex; }

  .sidebar-body {
    position: fixed;
    top: calc(var(--ticker-h) + var(--topbar-h));
    left: 0;
    bottom: 0;
    width: min(300px, 85vw);
    background: var(--surface);
    border-right: 1px solid var(--border);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    z-index: 82;
  }
  body.nav-open .sidebar-body { transform: none; }
  body.nav-open .sidebar-backdrop { display: block; }
  body.nav-open { overflow: hidden; }

  .side-nav { padding: 0.6rem 0.6rem; }
  .side-nav a { padding: 0.6rem 0.8rem; font-size: 0.95rem; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar-body { transition: none; }
}

@media (max-width: 720px) {
  .container { padding: 0.9rem 0.75rem 2.25rem; }
  h1 { font-size: 1.2rem; }
  .chart-wrap { height: 320px; }
  .page-head { gap: 0.6rem; }
  .page-head .btn { margin-left: 0; }
  .card { padding: 0.75rem 0.8rem; }
  .form-actions .btn { width: 100%; justify-content: center; }
}

@media (max-width: 420px) {
  .brand { font-size: 0.95rem; }
  .nbu-chip { font-size: 0.74rem; padding: 0.15rem 0.55rem; }
  .chips-row { gap: 0.6rem; }
  .chip-card { padding: 0.6rem 0.8rem; }
  .chip-value { font-size: 1.2rem; }
  .fx-val { font-size: 1.05rem; }
  .table td.td-name { max-width: 130px; }
}
