:root {
  --bg: #f6f7fb; --card: #ffffff; --text: #1b1f2a; --muted: #5d667a; --line: #e3e6ee;
  --brand: #1f6feb; --brand-ink: #ffffff; --ok: #1a7f4b; --ok-bg: #e8f6ee;
  --warn: #9a4a07; --warn-bg: #fff4e5;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10131a; --card: #181c26; --text: #e8ebf2; --muted: #9aa4b8; --line: #272d3a;
    --brand: #4c8dff; --brand-ink: #0b1020; --ok: #4cc38a; --ok-bg: #12261d;
    --warn: #ffb067; --warn-bg: #2a1f12;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.65 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.wrap { max-width: 780px; margin: 0 auto; padding: 0 16px; }
a { color: var(--brand); }

.site-header { background: var(--card); border-bottom: 1px solid var(--line); }
.site-header .wrap { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 20px; padding-top: 12px; padding-bottom: 12px; }
.logo { font-weight: 800; font-size: 1.15rem; text-decoration: none; color: var(--text); }
.logo span { color: var(--brand); }
nav { display: flex; flex-wrap: wrap; gap: 4px 16px; }
nav a { text-decoration: none; color: var(--muted); font-size: .95rem; padding: 4px 0; border-bottom: 2px solid transparent; }
nav a:hover, nav a[aria-current="page"] { color: var(--text); border-bottom-color: var(--brand); }

main { padding-top: 24px; padding-bottom: 40px; }
h1 { font-size: 1.7rem; line-height: 1.25; margin: 0 0 8px; }
h2 { font-size: 1.25rem; margin: 32px 0 8px; }
h3 { font-size: 1.05rem; margin: 20px 0 6px; }
.lead { color: var(--muted); margin: 0 0 20px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin: 16px 0; }
.grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 620px) { .grid.two { grid-template-columns: 1fr 1fr; } }
label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 4px; }
input, select {
  width: 100%; padding: 12px; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px;
}
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 1px; }

table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .85rem; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr.total td { font-weight: 800; border-bottom: 0; font-size: 1.05rem; }
.table-scroll { overflow-x: auto; }
.table-scroll table { min-width: 560px; }
tr.best td { background: var(--ok-bg); }

.notice { border-radius: 10px; padding: 10px 12px; margin: 12px 0 0; font-size: .92rem; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.small { font-size: .88rem; color: var(--muted); }
.badge { display: inline-block; font-size: .75rem; padding: 1px 8px; border-radius: 99px; background: var(--warn-bg); color: var(--warn); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }

.deadlines { list-style: none; margin: 0; padding: 0; }
.deadlines li { display: flex; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.deadlines li:last-child { border-bottom: 0; }
.deadlines .when { min-width: 118px; font-weight: 700; }
.deadlines .left { display: block; font-weight: 400; font-size: .8rem; color: var(--muted); }

.ad-slot:empty { display: none; }
.ad-slot { margin: 20px 0; text-align: center; }

.site-footer { border-top: 1px solid var(--line); padding: 20px 0 32px; color: var(--muted); font-size: .88rem; }
.site-footer p { margin: 4px 0; }

/* --- Плитки калькуляторів на головній --- */
.tiles { display: grid; gap: 14px; grid-template-columns: 1fr; margin: 16px 0; }
@media (min-width: 620px) { .tiles { grid-template-columns: 1fr 1fr; } }
.tile { display: block; text-decoration: none; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.tile:hover, .tile:focus-visible { border-color: var(--brand); }
.tile strong { display: block; font-size: 1.05rem; margin-bottom: 4px; }
.tile span { color: var(--muted); font-size: .92rem; }

/* --- Картки з підсумками --- */
.stats { display: grid; gap: 12px; grid-template-columns: 1fr; margin-top: 14px; }
@media (min-width: 520px) { .stats { grid-template-columns: 1fr 1fr; } }
.stat { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.stat.main { border-color: var(--brand); }
.stat small { display: block; color: var(--muted); font-size: .82rem; }
.stat b { display: block; font-size: 1.2rem; line-height: 1.35; }

/* --- Поля по місяцях --- */
.months { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; margin-top: 10px; }
@media (min-width: 620px) { .months { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 760px) { .months { grid-template-columns: repeat(4, 1fr); } }
.months label { font-weight: 500; font-size: .85rem; color: var(--muted); }

.btn { font: inherit; font-size: .92rem; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; cursor: pointer; }
.btn:hover { border-color: var(--brand); }
.hidden { display: none; }
ul.links { padding-left: 20px; }

/* На вузьких екранах ховаємо річну колонку, щоб таблиця не виходила за межі екрана */
@media (max-width: 519px) { .col-year, .col-extra { display: none; } }
.table-scroll table.fit { min-width: 0; }
.table-scroll table.fit { font-size: .85rem; }
.table-scroll table.fit th, .table-scroll table.fit td { padding: 8px 4px; }
/* У компактних таблицях дозволяємо переносити «грн» і довгі заголовки на новий рядок */
.table-scroll table.fit td.num, .table-scroll table.fit th.num { white-space: normal; }
