/* Дизайн: спокійний інструмент для щоденних розрахунків. Синій для дій, жовтий лише у знаку логотипа. */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #0f1b2d;
  --muted: #52607a;
  --line: #dbe1ea;
  --accent: #0b57d0;
  --accent-ink: #ffffff;
  --accent-soft: #e4edfc;
  --mark: #ffd500;
  --warn: #9a5b00;
  --warn-bg: #fff4dc;
  --bad: #b3261e;
  --font: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1522; --surface: #162033; --ink: #e8edf6; --muted: #9aa8c2; --line: #27344d;
    --accent: #7aa7ff; --accent-ink: #0a1730; --accent-soft: #1b2b4b; --warn: #f2b45a; --warn-bg: #2b2210; --bad: #ff8a80;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1522; --surface: #162033; --ink: #e8edf6; --muted: #9aa8c2; --line: #27344d;
  --accent: #7aa7ff; --accent-ink: #0a1730; --accent-soft: #1b2b4b; --warn: #f2b45a; --warn-bg: #2b2210; --bad: #ff8a80;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.55 var(--font);
}
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
img { max-width: 100%; }

.wrap {
  max-width: 1120px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* ---------- Шапка ---------- */
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.site-header .wrap { display: flex; align-items: center; gap: 16px 24px; padding-block: 12px; flex-wrap: wrap; }
.logo { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.25rem; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.logo-mark { width: 28px; height: 28px; border-radius: 7px; background: linear-gradient(180deg, var(--accent) 0 50%, var(--mark) 50% 100%); position: relative; flex: none; }
.logo-mark::after { content: "="; position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; font-size: 18px; color: #fff; mix-blend-mode: normal; text-shadow: 0 0 2px rgba(0,0,0,.35); }
.main-nav { display: flex; gap: 4px 18px; flex-wrap: nowrap; flex: 1 0 100%; order: 3; min-width: 0; overflow-x: auto; scrollbar-width: thin; }
.main-nav a { color: var(--ink); text-decoration: none; font-size: 0.875rem; white-space: nowrap; padding: 6px 2px; }
.main-nav a:hover { color: var(--accent); }
.search { position: relative; flex: 0 1 280px; min-width: 180px; }
.search input { width: 100%; font: inherit; font-size: 0.9375rem; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); }
.search-results { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(15,27,45,.14); max-height: 60vh; overflow: auto; }
.search-results a { display: block; padding: 9px 12px; color: var(--ink); text-decoration: none; font-size: 0.9375rem; border-top: 1px solid var(--line); }
.search-results a:first-child { border-top: 0; }
.search-results a:hover, .search-results a:focus { background: var(--accent-soft); }
.search-results small { display: block; color: var(--muted); }

/* ---------- Каркас сторінки ---------- */
main { padding-block: 24px 56px; }
.crumbs { font-size: 0.875rem; color: var(--muted); margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 4px 8px; }
.crumbs a { color: var(--muted); }
h1 { font-size: clamp(1.6rem, 4.2vw, 2.25rem); line-height: 1.2; margin: 0 0 8px; letter-spacing: -0.015em; text-wrap: balance; }
h2 { font-size: 1.375rem; line-height: 1.3; margin: 32px 0 10px; text-wrap: balance; }
h3 { font-size: 1.0625rem; margin: 20px 0 6px; }
.lead { color: var(--muted); max-width: 70ch; margin: 0 0 20px; font-size: 1.0625rem; }
.asof { display: inline-block; font-size: 0.8125rem; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 3px 10px; margin-bottom: 12px; }

/* ---------- Калькулятор ---------- */
.calc-grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 16px; align-items: start; }
@media (max-width: 820px) { .calc-grid { grid-template-columns: minmax(0, 1fr); } }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; min-width: 0; }
.calc-form { display: grid; gap: 16px; }
.field label, .field legend { display: block; font-size: 0.8125rem; font-weight: 500; letter-spacing: 0.01em; color: var(--muted); margin: 0 0 6px; padding: 0; }
.field fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.field-heading { margin: 8px 0 0; font-size: 0.875rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); border-top: 1px solid var(--line); padding-top: 14px; }
.field input[type="text"], .field input[type="date"], .field select, .field textarea {
  width: 100%; font: inherit; font-size: 1rem; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
}
.field textarea { resize: vertical; line-height: 1.45; }
.input-wrap { position: relative; }
.input-wrap input { font-variant-numeric: tabular-nums; }
.input-wrap.has-unit input { padding-right: 56px; }
.unit { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 0.875rem; pointer-events: none; max-width: 50px; overflow: hidden; white-space: nowrap; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); outline: 2px solid var(--accent-soft); }
.hint { margin: 6px 0 0; font-size: 0.8125rem; color: var(--muted); }
.check { display: flex !important; gap: 10px; align-items: flex-start; font-size: 0.9375rem !important; color: var(--ink) !important; cursor: pointer; margin: 0 !important; }
.check input { margin-top: 4px; accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.seg { display: flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--bg); }
.seg label { flex: 1 1 auto; margin: 0 !important; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg span { display: block; text-align: center; padding: 9px 10px; font-size: 0.9375rem; color: var(--ink); cursor: pointer; border-left: 1px solid var(--line); white-space: nowrap; }
.seg label:first-child span { border-left: 0; }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); font-weight: 500; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn { font: inherit; font-size: 0.9375rem; border-radius: 8px; padding: 9px 16px; cursor: pointer; border: 1px solid var(--line); background: transparent; color: var(--ink); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 500; }
.btn.ghost { color: var(--muted); }
.btn.ghost:hover { color: var(--ink); border-color: var(--muted); }
.btn.small { padding: 6px 12px; font-size: 0.8125rem; }

.result { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; min-width: 0; }
.result > *, .table-block { min-width: 0; }
.calc-form { grid-template-columns: minmax(0, 1fr); }
.kicker { margin: 0 0 2px; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 500; }
.main-result .big { margin: 0; font-size: clamp(2rem, 6vw, 2.75rem); line-height: 1.1; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.main-result .sub { margin: 6px 0 0; color: var(--muted); font-size: 0.9375rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.card { background: var(--bg); border-radius: 8px; padding: 10px 12px; min-width: 0; }
.card .val { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.rows { margin: 0; display: grid; }
.rows > div { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-top: 1px solid var(--line); }
.rows dt { color: var(--muted); font-size: 0.9375rem; }
.rows dd { margin: 0; font-weight: 500; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.rows .total { font-weight: 600; }
.rows .total dt { color: var(--ink); }
.notes { margin: 0; padding: 12px 14px 12px 32px; background: var(--warn-bg); color: var(--ink); border-radius: 8px; font-size: 0.875rem; }
.notes li + li { margin-top: 4px; }
.result-error { color: var(--bad); margin: 0; }
.result-hint { color: var(--muted); margin: 0; }
.result-actions { display: flex; align-items: center; gap: 12px; }
.copied { font-size: 0.8125rem; color: var(--accent); }
.table-block h3 { margin: 4px 0 8px; }
.table-scroll { overflow: auto; max-height: 440px; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 0.875rem; }
th, td { padding: 7px 10px; text-align: left; white-space: nowrap; border-top: 1px solid var(--line); }
thead th { position: sticky; top: 0; background: var(--surface); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); border-top: 0; box-shadow: 0 1px 0 var(--line); }
th.n, td.n { text-align: right; font-variant-numeric: tabular-nums; }
.list-out { white-space: pre-wrap; font: 0.9375rem/1.5 var(--font); background: var(--bg); border-radius: 8px; padding: 12px; margin: 0; overflow-wrap: anywhere; max-height: 360px; overflow: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--accent-soft); color: var(--ink); border-radius: 6px; padding: 4px 10px; font-variant-numeric: tabular-nums; }
noscript p { background: var(--warn-bg); padding: 12px; border-radius: 8px; }

/* ---------- Статті, FAQ, пов'язані ---------- */
.article { max-width: 74ch; }
.article p, .article li { color: var(--ink); }
.article ul, .article ol { padding-left: 22px; }
.article code { background: var(--accent-soft); padding: 1px 6px; border-radius: 4px; font-size: 0.9em; }
.article table { margin: 8px 0; }
.faq details { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; margin: 8px 0; padding: 0 14px; max-width: 74ch; }
.faq summary { cursor: pointer; padding: 12px 0; font-weight: 500; }
.faq details[open] summary { border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.faq details p { margin: 0 0 12px; }
.related { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; padding: 0; list-style: none; }
.related a { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; text-decoration: none; color: var(--ink); height: 100%; }
.related a:hover { border-color: var(--accent); }
.related small { color: var(--muted); display: block; margin-top: 2px; }

/* ---------- Головна та розділи ---------- */
.hero { padding-block: 8px 12px; }
.hero h1 { font-size: clamp(1.9rem, 5vw, 2.75rem); max-width: 18ch; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; margin-top: 8px; }
.cat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; min-width: 0; }
.cat h2 { margin: 0 0 4px; font-size: 1.125rem; }
.cat h2 a { color: var(--ink); text-decoration: none; }
.cat h2 a:hover { color: var(--accent); }
.cat .desc { color: var(--muted); font-size: 0.875rem; margin: 0 0 10px; }
.cat ul { list-style: none; padding: 0; margin: 0; }
.cat li a { display: block; padding: 5px 0; text-decoration: none; font-size: 0.9375rem; border-top: 1px solid var(--line); }
.cat li:first-child a { border-top: 0; }
.popular { display: flex; flex-wrap: wrap; gap: 8px; padding: 0; list-style: none; margin: 12px 0 0; }
.popular a { display: inline-block; padding: 7px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: var(--ink); font-size: 0.9375rem; }
.popular a:hover { border-color: var(--accent); color: var(--accent); }
.big-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.big-list a { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; text-decoration: none; color: var(--ink); height: 100%; }
.big-list a:hover { border-color: var(--accent); }
.big-list strong { display: block; }
.big-list span { color: var(--muted); font-size: 0.875rem; }
.data-table { max-width: 720px; }
.data-table td, .data-table th { white-space: normal; }

/* ---------- Підвал ---------- */
.site-footer { border-top: 1px solid var(--line); background: var(--surface); padding-block: 28px; font-size: 0.875rem; color: var(--muted); }
.site-footer .wrap { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px 32px; }
.site-footer a { color: var(--muted); }
.site-footer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.site-footer h2 { font-size: 0.875rem; margin: 0 0 8px; color: var(--ink); }
.site-footer p { margin: 0 0 8px; }

@media (max-width: 720px) {
  .site-header .wrap { gap: 10px 14px; }
  .search { order: 2; flex: 1 1 160px; }
  .main-nav { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; white-space: nowrap; gap: 18px; padding-bottom: 2px; scrollbar-width: thin; }
}
@media (max-width: 560px) {
  .panel { padding: 16px; }
}
@media (prefers-reduced-motion: no-preference) {
  .btn, .related a, .big-list a, .popular a { transition: border-color .15s, color .15s; }
}

/* Готові розрахунки та повний перелік */
.related.scen { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.related.scen a { padding: 9px 12px; font-size: 0.9375rem; }
.cat-grid.all ul.sub { margin: 4px 0 8px; padding-left: 16px; font-size: 0.875rem; columns: 2; column-gap: 20px; }
.cat-grid.all ul.sub li { break-inside: avoid; }
@media (max-width: 720px) { .cat-grid.all ul.sub { columns: 1; } }
.article table.data-table td, .article table.data-table th { overflow-wrap: anywhere; }
.article .tbl-wrap { overflow-x: auto; }
