/* Chiluvuru Voters: phone-first layout. On a desktop browser it shows as a phone-width column. */

:root {
  --green: #1f5c45;
  --green-dark: #163f30;
  --saffron: #d9661f;
  --bg: #f2f5f1;
  --card: #ffffff;
  --ink: #1b2622;
  --muted: #5d6b64;
  --line: #dde4df;
  --outside-bg: #fde9d8;
  --outside-ink: #974010;
  --inside-bg: #dcf1e4;
  --inside-ink: #16623a;
  --unknown-bg: #eceff0;
  --unknown-ink: #4d5a55;
  --covered-bg: #dbe9fb;
  --covered-ink: #1d4c9c;
  --notcovered-bg: #f1f1f1;
  --notcovered-ink: #5b5b5b;
  --error: #b42318;
  --radius: 14px;
  --touch: 48px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; background: #dfe6e1; }
body {
  font-family: "Noto Sans Telugu", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 0 0 1px var(--line);
}
#shell { display: flex; flex-direction: column; flex: 1; min-height: 100dvh; }
main { flex: 1; padding: 12px 14px 96px; }

h1, h2, h3 { margin: 0; font-weight: 700; }
h2 { font-size: 18px; margin-bottom: 6px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.error { color: var(--error); min-height: 1.2em; font-size: 15px; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* Buttons and inputs: large touch targets */
.btn {
  min-height: var(--touch);
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  color: var(--ink);
  background: var(--card);
  border-color: var(--line);
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }
.btn.primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn.primary:active { background: var(--green-dark); }
.btn.ghost { background: transparent; }
.btn.ghost-light { background: transparent; color: #fff; border-color: rgba(255,255,255,0.5); }
.btn.block { width: 100%; margin-top: 10px; }
.btn.small { min-height: 40px; padding: 6px 12px; font-size: 15px; }
.btn.call { background: var(--saffron); border-color: var(--saffron); color: #fff; }

input, select, textarea {
  font: inherit;
  font-size: 16px; /* 16px stops iOS zooming in */
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  min-height: var(--touch);
  width: 100%;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green); outline-offset: 1px; }

label { display: block; font-size: 15px; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 6px; color: var(--ink); }

/* Login */
.login {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px;
  gap: 24px;
}
.brand { text-align: center; }
.brand-mark {
  width: 64px; height: 64px; margin: 0 auto 12px;
  border-radius: 18px; background: var(--green); color: #fff;
  display: grid; place-items: center; font-size: 32px; font-weight: 700;
}
.brand h1 { font-size: 24px; }
.login-form { display: grid; gap: 14px; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--green); color: #fff;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 14px 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.topbar-title { font-size: 18px; font-weight: 700; }
.topbar-sub { font-size: 13px; opacity: 0.85; }

/* Bottom tabs */
.tabbar {
  position: sticky; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabbar button {
  background: none; border: 0; min-height: 60px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font: inherit; font-size: 13px; cursor: pointer;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button[aria-current="page"] { color: var(--green); font-weight: 700; }

/* Search */
.searchbar { margin-bottom: 10px; }
.searchbar input { font-size: 17px; }
.filters {
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px;
  scrollbar-width: none; align-items: flex-end;
}
.filters::-webkit-scrollbar { display: none; }
.pill-select { flex: 0 0 auto; min-width: 118px; font-size: 13px; }
.pill-select select { min-height: 44px; font-size: 15px; padding: 6px 10px; }
.toggle-chip {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 8px 14px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line); color: var(--ink); font-size: 15px;
  white-space: nowrap;
}
.toggle-chip input { width: 20px; height: 20px; min-height: 0; margin: 0; }
.count { color: var(--muted); font-size: 14px; margin: 4px 2px 8px; }

.list { display: grid; gap: 10px; }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; }

/* Voter card */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; cursor: pointer; display: flex; gap: 12px; align-items: flex-start;
}
.card:active { background: #f7faf8; }
.card-top { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.card .name { font-size: 18px; font-weight: 700; }
.card .rel, .card .meta { font-size: 15px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  background: var(--unknown-bg); color: var(--unknown-ink);
}
.chip.outside { background: var(--outside-bg); color: var(--outside-ink); }
.chip.in_village { background: var(--inside-bg); color: var(--inside-ink); }
.chip.unknown { background: var(--unknown-bg); color: var(--unknown-ink); }
.chip.covered { background: var(--covered-bg); color: var(--covered-ink); }
.chip.notcovered { background: var(--notcovered-bg); color: var(--notcovered-ink); }
.card-phone { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; }
.card-phone .number { font-size: 17px; font-weight: 700; letter-spacing: 0.02em; }
.card-phone .missing { color: var(--outside-ink); font-weight: 600; font-size: 15px; }
.card a.btn.call { min-height: 44px; padding: 6px 14px; }

/* Summary */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 10px; }
.tiles-3 { grid-template-columns: repeat(3, 1fr); }
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; display: grid; gap: 2px;
}
.tile span { font-size: 26px; font-weight: 700; color: var(--green); }
.tile small { font-size: 13px; color: var(--muted); }
.tile.warn span { color: var(--outside-ink); }
.tile.good span { color: var(--covered-ink); }
.section-title { margin: 16px 0 6px; }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.quick .btn { font-size: 15px; padding: 8px 10px; }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.ward-table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 330px; }
.ward-table th, .ward-table td { padding: 10px 6px; text-align: right; border-bottom: 1px solid var(--line); }
.ward-table th:first-child, .ward-table td:first-child { text-align: left; padding-left: 12px; }
.ward-table th { font-size: 12px; color: var(--muted); font-weight: 600; }
.ward-table tbody tr { cursor: pointer; }
.ward-table tbody tr:active { background: #eef5f0; }
.ward-table tbody tr:last-child td { border-bottom: 0; }

/* Ask AI */
.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; display: grid; gap: 10px;
}
.samples { display: flex; flex-wrap: wrap; gap: 8px; }
.samples button {
  font: inherit; font-size: 14px; border: 1px solid var(--line); background: #fff; color: var(--green);
  border-radius: 999px; padding: 8px 12px; min-height: 40px; cursor: pointer;
}
.answer {
  margin-top: 12px; background: #eaf4ee; border-radius: var(--radius); padding: 12px 14px;
  border-left: 4px solid var(--green); font-size: 15px;
}
.answer-meta { margin: 10px 2px 8px; font-size: 14px; color: var(--muted); }

/* Voter detail sheet */
.sheet {
  position: fixed; inset: 0; z-index: 30;
  width: 100%; max-width: 480px; margin: 0 auto;
  background: var(--bg); display: flex; flex-direction: column;
}
.sheet-head {
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
  background: var(--green); color: #fff; font-weight: 700;
}
.sheet-body { flex: 1; overflow-y: auto; padding: 14px 14px calc(env(safe-area-inset-bottom, 0px) + 24px); display: grid; gap: 14px; align-content: start; }
.sheet-body .panel h3 { font-size: 16px; margin-bottom: 4px; }
.sheet-body .panel h3:not(:first-child) { margin-top: 6px; }

/* Slip: mirrors the printed voter slip layout */
.slip {
  background: #fffdf6; border: 2px solid #8b6b3e; border-radius: 10px; padding: 12px 14px;
  display: grid; gap: 8px;
}
.slip-head { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; color: #5e4727; font-weight: 600; border-bottom: 1px dashed #c8b28c; padding-bottom: 6px; flex-wrap: wrap; }
.slip-row { display: grid; gap: 1px; }
.slip-row > span, .slip-grid span { font-size: 13px; color: #6a5636; }
.slip-row > strong, .slip-grid strong { font-size: 17px; }
.slip-name { font-size: 20px !important; }
.slip-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.slip-grid > div { display: grid; gap: 1px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.04em; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg button {
  min-height: var(--touch); font: inherit; font-size: 15px; font-weight: 600;
  border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 12px; cursor: pointer; padding: 6px;
}
.seg button[aria-checked="true"] { background: var(--green); color: #fff; border-color: var(--green); }
.phone-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.phone-row a.btn { min-width: 96px; }
.switch { display: flex; align-items: center; gap: 12px; min-height: var(--touch); font-size: 16px; color: var(--ink); }
.switch input { width: 24px; height: 24px; min-height: 0; margin: 0; flex: 0 0 auto; accent-color: var(--green); }
.sheet-body .btn.primary.block { margin-top: 4px; min-height: 52px; font-size: 17px; }
.sheet-body textarea { min-height: 70px; }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 84px); z-index: 40;
  background: rgba(27, 38, 34, 0.94); color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 15px; max-width: calc(100% - 32px); text-align: center;
}

@media (min-width: 481px) {
  body { padding: 16px 0; }
  #app { min-height: calc(100vh - 32px); border-radius: 22px; overflow: hidden; }
}

/* Voter photos */
.card-body { display: grid; gap: 4px; min-width: 0; flex: 1; }
.thumb {
  flex: 0 0 60px; height: 78px; border-radius: 10px; background: #e6ece8; color: #6f7d76;
  position: relative; overflow: hidden; display: grid; place-items: center; border: 1px solid var(--line);
}
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.thumb .initial { font-size: 24px; font-weight: 700; }
.thumb.has-photo .initial { display: none; }
.thumb.big { flex: none; width: 150px; height: 200px; }
.thumb.big .initial { font-size: 48px; }
.detail-photo { display: flex; flex-direction: column; align-items: center; gap: 6px; }

/* Families, roll status, team and access */
.view-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 0 0 10px; background: #e3e9e5; border-radius: 12px; padding: 4px; }
.view-switch button { min-height: 42px; border: 0; border-radius: 9px; background: transparent; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.view-switch button[aria-pressed="true"] { background: #fff; color: var(--green); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }
.families-mode .only-voters { display: none; }
.chip.expired { background: #e9e9e9; color: #333; text-decoration: line-through; }
.chip.abroad { background: #dfe9ff; color: #1c3f8a; }
.saved { color: var(--inside-ink); font-weight: 600; font-size: 15px; }
.saved-badge { color: var(--inside-ink); font-weight: 600; white-space: nowrap; }
.house { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: grid; gap: 6px; }
.house-head { font-size: 14px; font-weight: 700; color: var(--muted); padding: 2px 4px 6px; border-bottom: 1px solid var(--line); }
.member { display: grid; gap: 2px; text-align: left; width: 100%; background: #fafcfb; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font: inherit; color: var(--ink); cursor: pointer; min-height: 48px; }
.member:active { background: #eef5f0; }
.member-name { font-weight: 700; font-size: 16px; }
.member-meta { font-size: 14px; color: var(--muted); }
.member-list { display: grid; gap: 6px; }
.detail-photo .member { width: auto; }
.form-grid { display: grid; gap: 10px; }
.form-grid label { display: grid; gap: 4px; }
.wards { border: 1px solid var(--line); border-radius: 12px; padding: 8px; display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 0; }
.wards legend { font-size: 14px; color: var(--muted); padding: 0 4px; }
.ward-check { display: flex; align-items: center; gap: 4px; font-size: 15px; color: var(--ink); }
.ward-check input { width: 18px; height: 18px; min-height: 0; margin: 0; }
.user-row { display: grid; gap: 8px; }
.user-head { display: grid; gap: 2px; }
details { background: #fafcfb; border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
details summary { cursor: pointer; font-weight: 600; min-height: 40px; display: flex; align-items: center; color: var(--green); }
details[open] summary { margin-bottom: 8px; }
.audit { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.audit li { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 15px; }

/* Visits, history, progress */
.visit-line { font-size: 14px; color: var(--ink); margin: 0 0 4px; }
.visit-btn { margin-top: 4px; }
.seg-wide { grid-template-columns: 1fr 1fr; }
.agent-line { margin: 0 0 6px; }
.audit small { color: var(--muted); }
