/* Vision 2033 — one job: collect and show one number per province.
   Built for phones on patchy connections: high contrast, big tap targets,
   no heavy effects that stutter on older Android hardware. */

:root {
  --cream: #FBFAF8;
  --card: #FFFFFF;
  --ink: #241C18;
  --muted: #7A6E67;
  --line: #EAE3DC;
  --brand: #A9502F;
  --brand-soft: #F6EAE3;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--cream);
  color: var(--ink);
}

body {
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.km {
  font-family: "Noto Sans Khmer", "Khmer OS", system-ui, sans-serif;
  line-height: 1.9;
}

/* Figures line up in columns */
.num { font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--brand);
  min-width: 0;
}

.brand-mark { display: flex; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-title { font-weight: 700; font-size: 16px; color: var(--ink); line-height: 1.2; }
.brand-sub { font-size: 12px; color: var(--muted); line-height: 1.3; }

.lang-toggle {
  border: 1px solid var(--line);
  background: var(--cream);
  border-radius: 999px;
  padding: 7px 12px;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.lang-toggle .sep { opacity: 0.4; margin: 0 4px; }
.lang-toggle [data-lang-opt].on { color: var(--brand); font-weight: 700; }

/* Tabs on their own full-width row — nothing can scroll out of reach.
   2033 is deliberately narrower: it's context, not a thing to fill in. */
.tabs {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px 10px;
  display: grid;
  /* 2x2 on a phone so no tab can scroll out of reach; one row once there's space */
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tab {
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  padding: 11px 8px;
  border: 1px solid var(--line);
  background: var(--cream);
  color: var(--muted);
  border-radius: 10px;
  cursor: pointer;
}
.tab.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

/* ---------- layout ---------- */
.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 18px 16px 40px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 18px;
  margin-bottom: 14px;
}

/* ---------- headline ---------- */
.headline { text-align: center; padding: 26px 18px; }

.headline-num {
  font-size: 52px;
  font-weight: 700;
  color: var(--brand);
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.headline-label {
  font-size: 17px;
  font-weight: 600;
  margin-top: 4px;
}

.headline-sub {
  font-size: 14px;
  color: var(--muted);
  margin-top: 8px;
}

/* ---------- table ---------- */
.rows { display: flex; flex-direction: column; }

.row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }

.row-head {
  font-size: 11px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  padding-bottom: 8px;
}

.row-name { font-weight: 600; min-width: 0; }
.row-by { font-size: 12px; color: var(--muted); font-weight: 400; }
.row-num { font-weight: 700; text-align: right; }
.row-pct { font-size: 13px; color: var(--muted); font-weight: 400; }

/* confidence pip bar */
.conf { display: flex; gap: 2px; align-items: center; justify-content: flex-end; }
.conf-pip { width: 5px; height: 14px; border-radius: 1px; background: var(--line); }
.conf-pip.on { background: var(--brand); }
.conf-val { font-size: 12px; color: var(--muted); margin-left: 6px; min-width: 30px; }

.waiting { font-size: 13px; color: var(--muted); }
.waiting strong { color: var(--ink); font-weight: 600; display: block; margin-bottom: 6px; }

/* ---------- empty state ---------- */
.empty { text-align: center; padding: 30px 18px; }
.empty h2 { margin: 0 0 6px; font-size: 19px; }
.empty p { margin: 0 0 18px; color: var(--muted); }

/* ---------- village registry ---------- */
.prov-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.prov-card {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px 14px;
  cursor: pointer;
  color: var(--ink);
}
.prov-card-name { font-weight: 600; }
.prov-card-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.mini-bar {
  height: 4px;
  background: var(--line);
  border-radius: 999px;
  margin-top: 8px;
  overflow: hidden;
}
.mini-bar span { display: block; height: 100%; background: var(--brand); }

.reg-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.reg-title { font-weight: 700; font-size: 18px; }
.reg-count { font-size: 13px; color: var(--muted); white-space: nowrap; }

/* collapsible district / commune */
.node { border-bottom: 1px solid var(--line); }
.node:last-child { border-bottom: 0; }

.node-head {
  width: 100%;
  text-align: left;
  font: inherit;
  background: none;
  border: 0;
  padding: 13px 0;
  cursor: pointer;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
}
.node-head:hover { color: var(--brand); }
.node-caret { color: var(--muted); font-size: 11px; width: 10px; flex-shrink: 0; }
.node-name { font-weight: 600; flex: 1; min-width: 0; }
.node-sub { font-size: 12px; color: var(--muted); font-weight: 400; }
.node-body { padding-left: 20px; }
.node-commune > .node-head { padding: 10px 0; }
.node-commune > .node-head .node-name { font-weight: 500; }

/* a village row is the tap target */
.vil {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 0;
  cursor: pointer;
  border-top: 1px solid var(--line);
}
.vil:first-child { border-top: 0; }

.vil-box {
  width: 24px;
  height: 24px;
  border: 2px solid var(--line);
  border-radius: 6px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
}
.vil.on .vil-box { background: var(--brand); border-color: var(--brand); color: #fff; }
.vil.busy { opacity: 0.5; }
.vil-name { min-width: 0; }
.vil-where { font-size: 12px; color: var(--muted); }

.reg-search { margin-bottom: 4px; }

/* ---------- 2033 ---------- */
.goal-heads {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  text-align: center;
  margin-bottom: 16px;
}

.goal-num {
  font-size: 30px;
  font-weight: 700;
  color: var(--brand);
  line-height: 1.1;
}
.goal-num-muted { color: var(--ink); opacity: 0.42; }

.goal-cap {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}

.goal-bar {
  height: 10px;
  background: var(--brand-soft);
  border-radius: 999px;
  overflow: hidden;
}
.goal-bar span {
  display: block;
  height: 100%;
  background: var(--brand);
  border-radius: 999px;
}

.goal-scope {
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.stat {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.stat:last-child { border-bottom: 0; padding-bottom: 0; }
.stat:first-child { padding-top: 0; }
.stat-num { font-size: 26px; font-weight: 700; line-height: 1.15; }
.stat-cap { font-size: 13px; color: var(--muted); }

/* ---------- form ---------- */
.field { margin-bottom: 20px; }

.field-note {
  font-size: 13px;
  color: var(--muted);
  margin: -3px 0 8px;
}
.field-note strong { color: var(--ink); font-weight: 700; }

.label {
  display: block;
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 8px;
}
.label-hint { font-weight: 400; color: var(--muted); font-size: 13px; }

input[type="text"],
input[type="number"],
input[type="password"],
select {
  width: 100%;
  font: inherit;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--cream);
  color: var(--ink);
}
body.km input, body.km select { font-family: "Noto Sans Khmer", "Khmer OS", system-ui, sans-serif; }

input:focus, select:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
  background: #fff;
}

input.big {
  font-size: 26px;
  font-weight: 700;
  text-align: center;
  padding: 16px 14px;
  font-variant-numeric: tabular-nums;
}

/* confidence 1–10 */
.conf-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
}

.conf-btn {
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  padding: 13px 0;
  border: 1px solid var(--line);
  background: var(--cream);
  color: var(--muted);
  border-radius: 10px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.conf-btn.on {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.conf-caption {
  margin-top: 10px;
  font-size: 14px;
  color: var(--brand);
  font-weight: 600;
  min-height: 21px;
  text-align: center;
}

.btn {
  width: 100%;
  font: inherit;
  font-weight: 700;
  font-size: 17px;
  padding: 16px;
  border: 0;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
}
.btn:disabled { opacity: 0.55; cursor: default; }

.btn-link {
  display: inline-block;
  background: none;
  border: 0;
  color: var(--brand);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 10px;
  text-decoration: underline;
}

.error {
  background: var(--brand-soft);
  color: #7C2D12;
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 14px;
  margin-bottom: 14px;
}

.success { text-align: center; padding: 34px 18px; }
.success-mark { font-size: 40px; line-height: 1; }
.success h2 { margin: 12px 0 4px; font-size: 20px; }
.success p { margin: 0; color: var(--muted); }

.loading { text-align: center; color: var(--muted); padding: 40px 0; }

/* ---------- footer ---------- */
.footer {
  max-width: 760px;
  margin: 0 auto;
  padding: 20px 16px 34px;
  text-align: center;
}
.footer p { margin: 0; font-size: 12px; color: var(--muted); }

@media (min-width: 620px) {
  .conf-grid { grid-template-columns: repeat(10, 1fr); }
  .headline-num { font-size: 64px; }
  .tabs { grid-template-columns: 1fr 1fr 1fr 0.6fr; }
  .prov-grid { grid-template-columns: 1fr 1fr; }
}

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