/* ---------- Rang aur font (light / dark) ---------- */
:root {
  color-scheme: light;
  --paper: #f5f7f6;
  --panel: #ffffff;
  --ink: #18242e;
  --muted: #5b6a74;
  --line: #dbe1df;
  --c-line: #1d4e89;
  --c-won: #12804a;
  --c-second: #e0832a;
  --c-third: #4c6fa3;
  --c-fourth: #c8cfd2;
  --won-bg: #d5eedf;
  --second-bg: #fbe3c9;
  --focus: #1d4e89;
  --radius: 10px;
  --font: "Mukta", "Noto Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #0f161b;
    --panel: #162028;
    --ink: #e6ebee;
    --muted: #9aa8b1;
    --line: #2a3742;
    --c-line: #7aa7e8;
    --c-won: #36b571;
    --c-second: #f0a14c;
    --c-third: #7f9fd2;
    --c-fourth: #3b4955;
    --won-bg: #17432c;
    --second-bg: #4a3115;
    --focus: #7aa7e8;
  }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
}
.page { max-width: 1180px; margin-inline: auto; padding: 32px clamp(16px, 4vw, 40px) 64px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- Header ---------- */
.masthead { margin-bottom: 28px; max-width: 64rem; }
.masthead h1 {
  font-weight: 800;
  font-size: clamp(1.9rem, 4.2vw, 3rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin: 0 0 12px;
}
.masthead h1 span { display: block; color: var(--muted); font-weight: 500; }
.takeaway { margin: 0 0 18px; font-size: 1.1rem; max-width: 46rem; }
.status { font-size: 0.875rem; color: var(--muted); margin: 0; }
.status.is-error { color: #c0392b; font-weight: 600; }

/* ---------- Buttons and inputs ---------- */
.btn, .input, .fgroup select, .fgroup input {
  font: inherit;
  font-size: 0.875rem;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  min-height: 36px;
}
.btn { cursor: pointer; display: inline-flex; align-items: center; font-weight: 600; }
.btn:hover { border-color: var(--muted); }
.btn-quiet { font-weight: 500; color: var(--muted); }
.btn[aria-expanded="true"] { border-color: var(--ink); }
.input.grow { flex: 1 1 14rem; max-width: 24rem; min-width: 0; }

/* ---------- Message (loading / error) ---------- */
.msgbox { border: 1px solid var(--line); border-radius: var(--radius); padding: 40px 24px; text-align: center; background: var(--panel); }
.msg-title { font-size: 1.3rem; font-weight: 800; margin: 0 0 8px; }
.msg-text { color: var(--muted); max-width: 40rem; margin: 0 auto; font-size: 0.95rem; }
.msg-text:empty { display: none; }

/* ---------- Timeline (har chunav) ---------- */
.timeline {
  list-style: none;
  margin: 0 0 32px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr));
  gap: 0;
  border-top: 3px solid var(--ink);
}
.tl-item { position: relative; padding: 22px 20px 6px 0; }
.tl-item + .tl-item { padding-left: 20px; border-left: 1px solid var(--line); }
.tl-item::before {
  content: "";
  position: absolute;
  top: -9px;
  left: 0;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--ink);
  border: 3px solid var(--paper);
}
.tl-item + .tl-item::before { left: 13px; }
.tl-ls::before { background: var(--paper); box-shadow: inset 0 0 0 3px var(--ink); }
.tl-year { font-size: 2.6rem; font-weight: 800; line-height: 1; letter-spacing: -0.03em; }
.tl-kind { font-weight: 600; color: var(--muted); margin-bottom: 12px; }
.tl-big { font-size: 1.9rem; font-weight: 800; color: var(--c-won); line-height: 1; }
.tl-of { color: var(--muted); font-size: 0.95rem; }
.tl-stats { margin: 12px 0 8px; display: grid; gap: 2px; font-size: 0.9rem; }
.tl-stats div { display: flex; justify-content: space-between; gap: 12px; max-width: 15rem; }
.tl-stats dt { color: var(--muted); }
.tl-stats dd { margin: 0; font-weight: 600; }
.tl-stats .v-forf { color: #c0392b; }
@media (prefers-color-scheme: dark) { .tl-stats .v-forf { color: #ff8a7a; } }
.tl-note { margin: 0; font-size: 0.85rem; color: var(--muted); }
@media (max-width: 520px) {
  .tl-item + .tl-item { padding-left: 0; border-left: 0; border-top: 1px solid var(--line); }
  .tl-item + .tl-item::before { left: 0; top: -8px; }
}

/* ---------- Cards and charts ---------- */
.charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
  gap: 20px;
  margin-bottom: 20px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  min-width: 0;
}
section.card { margin-bottom: 20px; }
.card h2 { font-size: 1.15rem; font-weight: 700; margin: 0 0 2px; line-height: 1.3; }
.note { margin: 0 0 14px; font-size: 0.875rem; color: var(--muted); max-width: 60rem; }
.chart { position: relative; min-height: 220px; }
.chart svg { display: block; overflow: visible; }
.chart text { font-family: var(--font); font-size: 13px; }
.axis text { fill: var(--muted); }
.axis-label { fill: var(--muted); }
.grid { stroke: var(--line); stroke-width: 1; }
.share-line { fill: none; stroke: var(--c-line); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.share-dot { fill: var(--c-line); stroke: var(--panel); stroke-width: 2; }
.share-val { fill: var(--ink); font-weight: 600; }
.bar-label { fill: var(--ink); }
.bar-num { fill: #fff; font-weight: 600; pointer-events: none; }
.bar-num.on-light { fill: var(--ink); }
@media (prefers-color-scheme: dark) { .bar-num { fill: #0f161b; } .bar-num.on-light { fill: var(--ink); } }

.tip {
  position: absolute;
  display: none;
  pointer-events: none;
  z-index: 5;
  white-space: nowrap;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
  padding: 6px 10px;
  font-size: 0.8rem;
}
.tip-t { color: var(--muted); margin-bottom: 2px; }
.sw { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 10px; flex-wrap: wrap; }
.seg button { font: inherit; font-size: 0.85rem; padding: 5px 12px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); font-weight: 600; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.85rem; color: var(--muted); margin-bottom: 10px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend i.p1 { background: var(--won-bg); box-shadow: inset 0 0 0 1px var(--c-won); }
.legend i.p2 { background: var(--second-bg); box-shadow: inset 0 0 0 1px var(--c-second); }
.legend i.p3 { box-shadow: inset 0 0 0 1px var(--line); }

/* ---------- Table tools and filters ---------- */
.tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.count { font-size: 0.85rem; color: var(--muted); margin-left: auto; }
.filters {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  background: var(--paper);
}
.fgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); gap: 14px; margin-bottom: 14px; }
.fgroup { border: 0; margin: 0; padding: 0; min-width: 0; display: grid; gap: 6px; }
.fgroup legend { font-weight: 600; font-size: 0.9rem; padding: 0; margin-bottom: 6px; }
.fgroup select { width: 100%; }
.frow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 0.85rem; color: var(--muted); }
.frow input { width: 5.2rem; padding: 6px 8px; }
.fwide { display: grid; gap: 6px; max-width: 22rem; font-weight: 600; font-size: 0.9rem; }

/* ---------- Table ---------- */
.tbox { max-height: 560px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th { position: sticky; top: 0; z-index: 1; background: var(--panel); border-bottom: 2px solid var(--ink); text-align: left; padding: 0; }
th button { font: inherit; font-weight: 700; color: var(--ink); background: none; border: 0; padding: 9px 12px; width: 100%; text-align: inherit; cursor: pointer; white-space: nowrap; }
th[aria-sort="ascending"] button::after { content: " ▲"; font-size: 0.7em; }
th[aria-sort="descending"] button::after { content: " ▼"; font-size: 0.7em; }
th.num, td.num { text-align: right; }
th:not(:has(button)) { padding: 9px 12px; font-weight: 700; white-space: nowrap; }
td.sr { color: var(--muted); }
td { padding: 7px 12px; border-bottom: 1px solid var(--line); }
tbody tr:hover td { background: color-mix(in srgb, var(--line) 35%, transparent); }
td.p1, tbody tr:hover td.p1 { background: var(--won-bg); color: var(--c-won); font-weight: 700; }
td.p2, tbody tr:hover td.p2 { background: var(--second-bg); font-weight: 600; }
@media (prefers-color-scheme: dark) { td.p1, tbody tr:hover td.p1 { color: #7fe0a8; } }
.no-rows { margin: 0; padding: 24px; text-align: center; color: var(--muted); }
@media (max-width: 640px) { .hide-narrow { display: none; } .count { margin-left: 0; width: 100%; } }

/* ---------- Notes ---------- */
.notes ul { margin: 8px 0 0; padding-left: 1.2em; color: var(--muted); font-size: 0.9rem; }
.notes li { margin-bottom: 4px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- Elector Growth popup ---------- */
.btn-sm { min-height: 28px; padding: 3px 10px; font-size: 0.8rem; white-space: nowrap; }
td.act { padding: 4px 12px; }
.dlg {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
}
.dlg::backdrop { background: rgb(0 0 0 / 0.55); }
.dlg-in { padding: 20px clamp(16px, 3vw, 24px) 24px; }
.dlg-head { display: flex; align-items: start; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.dlg h2 { margin: 0; font-size: 1.2rem; line-height: 1.25; }
.dtab-box { overflow-x: auto; margin-bottom: 14px; }
.dtab { font-size: 0.85rem; margin-bottom: 8px; }
.dtab th { position: static; padding: 6px 10px; border-bottom: 1px solid var(--ink); font-weight: 700; }
.dtab td { padding: 6px 10px; }

/* ---------- Mahila / purush ---------- */
.fwide + .fwide { margin-top: 12px; }
.note:empty { display: none; }
