:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface-1: #ffffff;
  --surface-2: #f1f2f5;
  --surface-3: #e8eaef;
  --border: #e3e5ea;
  --text-primary: #111318;
  --text-secondary: #4a4f5a;
  --text-muted: #737885;
  --accent: #2a78d6;
  --accent-soft: #e6f0fc;
  --on-accent: #ffffff;     /* текст на кнопці кольору accent */
  --series-1: #2a78d6;      /* виручка, нейтральні величини */
  --pos: #2a78d6;           /* прибуток: синій полюс */
  --neg: #e34948;           /* збиток: червоний полюс */
  --up: #12784a;  --up-bg: #e5f5ec;
  --down: #c2362f; --down-bg: #fdecea;
  --grid: #eceef2;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 4px 16px rgba(16,24,40,.05);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1013; --surface-1: #17191d; --surface-2: #1f2227; --surface-3: #2a2e35; --border: #2b2f36;
    --text-primary: #f1f2f4; --text-secondary: #c2c6ce; --text-muted: #8d929c;
    --accent: #4b93ea; --accent-soft: #1b2a3d; --on-accent: #0b1525; --series-1: #3987e5; --pos: #3987e5; --neg: #e66767;
    --up: #4cc387; --up-bg: #15291f; --down: #ff8a80; --down-bg: #33191a;
    --grid: #24272d; --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1013; --surface-1: #17191d; --surface-2: #1f2227; --surface-3: #2a2e35; --border: #2b2f36;
  --text-primary: #f1f2f4; --text-secondary: #c2c6ce; --text-muted: #8d929c;
  --accent: #4b93ea; --accent-soft: #1b2a3d; --on-accent: #0b1525; --series-1: #3987e5; --pos: #3987e5; --neg: #e66767;
  --up: #4cc387; --up-bg: #15291f; --down: #ff8a80; --down-bg: #33191a;
  --grid: #24272d; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--text-primary);
  font: 15px/1.55 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--text-muted); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- шапка ---------- */
.top { background: color-mix(in srgb, var(--surface-1) 92%, transparent); backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.top-row { display: flex; align-items: center; gap: 18px; min-height: 60px; }
.logo { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: var(--text-primary); letter-spacing: -.01em; white-space: nowrap; }
.logo:hover { text-decoration: none; }
.logo-mark { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: #fff; font-size: 15px; }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { color: var(--text-secondary); padding: 7px 12px; border-radius: 9px; font-size: 14px; font-weight: 500; white-space: nowrap; }
.tabs a:hover { background: var(--surface-2); text-decoration: none; color: var(--text-primary); }
.tabs a.on { color: var(--accent); background: var(--accent-soft); }
.search { position: relative; margin-left: auto; flex: 0 1 280px; }
.search input {
  width: 100%; padding: 9px 12px 9px 36px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 12px center;
  color: var(--text-primary); font: inherit; font-size: 14px;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; background-color: var(--surface-1); }
.suggest {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; margin: 0; padding: 6px; z-index: 30;
  list-style: none; background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0,0,0,.14); max-height: 60vh; overflow: auto; min-width: 280px;
}
.suggest li a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--text-primary); font-size: 14px; }
.suggest li a:hover, .suggest li a.hl { background: var(--surface-2); text-decoration: none; }
.suggest small { color: var(--text-muted); display: block; font-size: 12px; }
@media (max-width: 760px) {
  .top-row { flex-wrap: wrap; gap: 8px 12px; padding: 10px 16px 8px; min-height: 0; }
  .tabs { order: 3; width: 100%; margin: 0 -4px; }
  .search { order: 2; flex: 1 1 160px; }
}
.home .top .search { visibility: hidden; }   /* на головній — великий пошук у героїчному блоці */
@media (max-width: 760px) { .home .top .search { display: none; } }

/* ---------- макет ---------- */
main { padding-top: 24px; padding-bottom: 40px; min-height: 60vh; }
h1 { font-size: 30px; line-height: 1.15; margin: 0 0 6px; letter-spacing: -.02em; font-weight: 700; }
h2 { font-size: 19px; margin: 0; letter-spacing: -.01em; font-weight: 650; }
h3 { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin: 2px 0 8px; }
.sub { color: var(--text-secondary); margin: 0 0 18px; font-size: 15px; }
.lead { font-size: 18px; line-height: 1.5; color: var(--text-secondary); margin: 0 0 18px; max-width: 760px; }
.lead b { color: var(--text-primary); font-weight: 650; }
.crumbs { font-size: 13px; margin-bottom: 10px; color: var(--text-muted); }
.crumbs a { color: var(--text-secondary); }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px 16px; flex-wrap: wrap; margin-bottom: 16px; }
.card-head p { margin: 4px 0 0; color: var(--text-muted); font-size: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid2 > * { min-width: 0; }  /* інакше елемент сітки розтягується під ширину графіка */
@media (max-width: 820px) { .grid2 { grid-template-columns: 1fr; } h1 { font-size: 25px; } .lead { font-size: 16px; } }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px 20px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .sub { margin: 0; }

/* ---------- героїчний блок головної ---------- */
.hero { background: linear-gradient(135deg, var(--accent-soft), var(--surface-1) 70%); border: 1px solid var(--border);
  border-radius: 22px; padding: 32px; margin-bottom: 20px; }
.hero h1 { font-size: 34px; max-width: 760px; }
.hero .search { margin: 18px 0 10px; max-width: 560px; }
.hero .search input { padding: 14px 16px 14px 44px; font-size: 16px; border-radius: 14px; background-color: var(--surface-1); background-position: 16px center; box-shadow: var(--shadow); }
.quick { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; color: var(--text-muted); }
.chip-link { display: inline-block; padding: 4px 10px; border-radius: 999px; background: var(--surface-1); border: 1px solid var(--border); color: var(--text-secondary); font-size: 13px; }
.chip-link:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
@media (max-width: 600px) { .hero { padding: 22px 18px; border-radius: 18px; } .hero h1 { font-size: 26px; } }

/* ---------- показники ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
@media (max-width: 900px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) {
  .kpis { gap: 10px; }
  .kpi { padding: 12px 13px; border-radius: 14px; }
  .kpi .v { font-size: clamp(16px, 4.6vw, 19px); white-space: normal; }
  .kpi .d { font-size: 12px; }
  .card { padding: 16px; }
}
.kpi { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.kpi .l { font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.kpi .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin: 4px 0 6px; line-height: 1.15; }
.kpi .d { font-size: 13px; color: var(--text-muted); }
.chip { display: inline-flex; align-items: center; gap: 3px; padding: 1px 8px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.chip.up { color: var(--up); background: var(--up-bg); }
.chip.down { color: var(--down); background: var(--down-bg); }
.chip.flat { color: var(--text-muted); background: var(--surface-2); }
.neg-text { color: var(--down); }

/* ---------- плитки галузей ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.tile { display: block; padding: 14px 16px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-1); color: var(--text-primary); transition: border-color .15s, transform .15s; }
.tile:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.tile .t { font-weight: 600; font-size: 14px; line-height: 1.3; min-height: 2.6em; }
.tile .code { color: var(--text-muted); font-weight: 500; font-size: 12px; }
.tile .v { font-size: 20px; font-weight: 700; margin: 6px 0 2px; letter-spacing: -.01em; }
.tile .bar { height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: 8px 0 6px; }
.tile .bar i { display: block; height: 100%; background: var(--series-1); border-radius: 4px; }
.tile .meta { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; color: var(--text-muted); align-items: center; }

/* ---------- таблиці ---------- */
.tbl-wrap { overflow-x: auto; margin: 0 -6px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--text-muted); white-space: nowrap; text-transform: uppercase; letter-spacing: .03em; }
td.r, th.r { text-align: right; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
table.cmp td:first-child { white-space: nowrap; color: var(--text-secondary); }
table.cmp th.r, table.cmp td.r { min-width: 96px; }
table.cmp tr.key td { font-weight: 600; color: var(--text-primary); }
.rank { color: var(--text-muted); width: 36px; font-variant-numeric: tabular-nums; }
.co-name { font-weight: 600; color: var(--text-primary); }
.co-meta { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.tag { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-secondary); white-space: nowrap; font-weight: 500; }
.tag.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- фільтри й перемикачі ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.field { display: inline-flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.filters select, .field select {
  font: inherit; font-size: 14px; padding: 8px 32px 8px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-1) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23888' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
  color: var(--text-primary); appearance: none; max-width: 100%; min-width: 0; text-overflow: ellipsis; cursor: pointer;
}
.seg { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; border-radius: 11px; background: var(--surface-2); max-width: 100%; }
.seg button { font: inherit; font-size: 13.5px; padding: 6px 12px; border-radius: 8px; border: 0; cursor: pointer; background: transparent; color: var(--text-secondary); font-weight: 500; }
.seg button:hover { color: var(--text-primary); }
.seg button.on { background: var(--surface-1); color: var(--text-primary); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.filter-card { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
@media (max-width: 600px) { .field, .field select, .filters select { width: 100%; } }

/* ---------- графіки ---------- */
.chart-scroll { overflow-x: auto; }
.chart-scroll .chart { min-width: 340px; }
.chart { width: 100%; display: block; overflow: visible; }
.chart text { fill: var(--text-muted); font-size: 12px; font-family: inherit; }
.chart .axis { stroke: var(--border); }
.chart .grid { stroke: var(--grid); }
.chart .hit { fill: transparent; cursor: default; }
.chart .bar { transition: opacity .1s; }
.chart g.col:hover .bar { opacity: .8; }
.hbar { display: flex; flex-direction: column; gap: 2px; }
.hrow { display: grid; grid-template-columns: minmax(120px, 240px) 1fr auto; gap: 12px; align-items: center;
  padding: 5px 6px; border-radius: 8px; color: var(--text-secondary); font-size: 13.5px; }
a.hrow:hover { text-decoration: none; background: var(--surface-2); color: var(--text-primary); }
.hl { text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ht { position: relative; height: 18px; }
.hb { position: absolute; top: 0; bottom: 0; border-radius: 0 4px 4px 0; }
.hb.neg { border-radius: 4px 0 0 4px; }
.hz { position: absolute; top: -3px; bottom: -3px; width: 1px; background: var(--border); }
.hv { color: var(--text-primary); min-width: 96px; text-align: right; font-weight: 500; }
@media (max-width: 600px) {
  .hrow { grid-template-columns: 1fr auto; row-gap: 3px; }
  .hl { grid-column: 1 / -1; text-align: left; white-space: normal; }
  .ht { grid-column: 1; }
}
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-secondary); margin-top: 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- підказки й примітки ---------- */
.tip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--text-primary); color: var(--surface-1);
  border-radius: 10px; padding: 8px 11px; font-size: 13px; line-height: 1.45;
  box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 300px;
}
.tip b { display: block; font-weight: 600; margin-bottom: 2px; }
.term { border-bottom: 1px dotted currentColor; cursor: help; }
.info { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; background: var(--surface-3); color: var(--text-secondary); font-size: 11px; font-weight: 700; cursor: help; vertical-align: 1px; margin-left: 4px; font-style: normal; }
details.how { margin-top: 14px; font-size: 13.5px; color: var(--text-secondary); }
details.how > summary { cursor: pointer; color: var(--text-muted); list-style: none; display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
details.how > summary::-webkit-details-marker { display: none; }
details.how > summary::before { content: "i"; display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--surface-2); font-size: 11px; font-weight: 700; font-style: italic; }
details.how[open] > summary { margin-bottom: 8px; }
details.how p { margin: 6px 0; }
details.more > summary { cursor: pointer; color: var(--accent); font-size: 14px; font-weight: 500; margin-top: 12px; list-style: none; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::after { content: " ↓"; }
details.more[open] > summary::after { content: " ↑"; }
.note { font-size: 13px; color: var(--text-muted); margin: 10px 0 0; }
.callout { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--accent-soft); color: var(--text-secondary); font-size: 14px; margin-bottom: 18px; }
.foot { padding-bottom: 32px; font-size: 13px; border-top: 1px solid var(--border); padding-top: 18px; }

/* ---------- сторінка компанії ---------- */
.co-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badges .tag { white-space: normal; max-width: 100%; }
.verdict { font-size: 16px; color: var(--text-secondary); margin: 14px 0 0; max-width: 760px; }
.verdict b { color: var(--text-primary); }

/* ---------- про дані ---------- */
.prose { max-width: 780px; }
.prose h2 { margin: 26px 0 8px; }
.prose p, .prose li { color: var(--text-secondary); }
.prose dl { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; gap: 8px 18px; }
.prose dt { font-weight: 600; }
.prose dd { margin: 0; color: var(--text-secondary); }
@media (max-width: 600px) { .prose dl { grid-template-columns: 1fr; } .prose dd { margin-bottom: 8px; } }

/* ---------- завантаження ---------- */
.skeleton { height: 220px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite linear; }
@keyframes sk { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } html { scroll-behavior: auto; } }

/* ---------- підсумок кварталу / місце серед конкурентів ---------- */
.qsum { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin: 0 0 16px; }
.qsum > div { display: flex; flex-direction: column; gap: 3px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); min-width: 0; }
.qsum > div > b { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.qsum > div > b .chip { font-size: 15px; padding: 2px 10px; }
.qsum .muted { font-size: 12.5px; }

/* ---------- таблиці компаній: сортування, «показати ще», CSV ---------- */
th button.sort { all: unset; cursor: pointer; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; white-space: nowrap; border-bottom: 1px dashed transparent; }
th button.sort:hover { color: var(--text-primary); border-bottom-color: currentColor; }
th button.sort.on { color: var(--accent); }
th button.sort:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.dt-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-top: 12px; font-size: 13px; }
.dt-foot .muted { margin-right: auto; }
.btn { font: inherit; font-size: 13.5px; font-weight: 600; padding: 7px 14px; border-radius: 10px; border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent); cursor: pointer; }
.btn:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; color: var(--accent); border-color: var(--border); }
.btn.ghost:hover { border-color: var(--accent); }
tr.me td { background: var(--accent-soft); }

/* ---------- лідери кварталу ---------- */
.leaders { list-style: none; margin: 0; padding: 0; counter-reset: l; }
.leaders li { counter-increment: l; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.leaders li:last-child { border-bottom: 0; }
.leaders li > span:first-child { display: flex; flex-direction: column; min-width: 0; }
.leaders li > span:first-child::before { content: counter(l) "."; color: var(--text-muted); font-size: 12px; }
.leaders .co-name { overflow: hidden; text-overflow: ellipsis; }

/* ---------- сторінка компанії: посилання ---------- */
.co-links { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; margin-top: 14px; font-size: 13.5px; }
.co-links .ext { display: inline-flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.co-links .ext a { font-weight: 600; }
a.tag.link { color: var(--accent); }
a.tag.link:hover { text-decoration: none; background: var(--accent-soft); }
.card-head .field select { min-width: 220px; }
@media (max-width: 600px) { .card-head .field, .card-head .field select { width: 100%; min-width: 0; } }

/* ---------- футер і статичні сторінки (про проєкт, умови, політика) ---------- */
.foot-links { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-bottom: 10px; font-size: 13.5px; }
.foot-links a { color: var(--text-secondary); }
.foot-links a:hover { color: var(--accent); }
.foot p { margin: 6px 0; }
.foot .owner { font-size: 12.5px; }
body.static main { padding-top: 22px; }
.legal { max-width: 860px; }
.legal h1 { margin-top: 4px; }
.legal h2 { font-size: 18px; }
.legal .small { font-size: 13px; }
.legal ul { padding-left: 20px; }
.legal li { margin: 6px 0; }
.legal code { font-size: 12.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
