:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --line: #d9e1ea;
  --ink: #17202a;
  --muted: #5f6e7c;
  --brand: #126b58;
  --support: #16804f;
  --leaning: #b7791f;
  --opposition: #b33a3a;
  --away: #56616d;
  --shadow: 0 16px 38px rgba(31, 47, 70, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans Devanagari", "Nirmala UI", "Segoe UI", Arial, sans-serif;
  padding-bottom: 0;
}

button,
input,
select,
a {
  font: inherit;
}

button,
.header-actions a {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  min-height: 38px;
  padding: 0 14px;
  text-decoration: none;
}

button:hover,
.header-actions a:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.topbar {
  align-items: center;
  background: linear-gradient(135deg, #fbfcfd 0%, #e5f0ed 100%);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 24px;
  justify-content: space-between;
  padding: 28px clamp(16px, 4vw, 44px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.eyebrow {
  color: #8b5d14;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 6px;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1.05;
  margin-bottom: 8px;
}

h2 {
  font-size: 1.35rem;
  margin-bottom: 0;
}

.subhead,
.muted {
  color: var(--muted);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.layout {
  display: grid;
  gap: 18px;
  margin: 0 auto;
  max-width: 680px;
  padding: 22px clamp(12px, 3vw, 32px) 40px;
}

.ward-cards {
  display: grid;
  gap: 10px;
  padding: 0 16px 16px;
}

.summary-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
}

.summary-grid article,
.controls,
.ward-panel,
.voter-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.summary-grid article {
  min-height: 96px;
  padding: 16px;
}

.summary-grid span {
  color: var(--muted);
  display: block;
  font-size: 0.86rem;
  margin-bottom: 8px;
}

.summary-grid strong {
  font-size: 1.7rem;
  line-height: 1;
}

.controls {
  display: grid;
  gap: 14px;
  padding: 16px;
}

label span {
  color: var(--muted);
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 6px;
}

input,
select {
  background: #fbfdff;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 42px;
  padding: 0 12px;
  width: 100%;
}

input:focus,
select:focus {
  border-color: var(--brand);
  outline: 3px solid rgba(18, 107, 88, 0.15);
}

.control-row {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.panel-head {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
}

#saveStatus {
  color: var(--muted);
  font-size: 0.9rem;
}

.ward-table-wrap {
  display: none;
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  min-width: 900px;
  width: 100%;
}

th,
td {
  border-top: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
}

th {
  background: #f0f5f8;
  color: #344250;
  font-size: 0.78rem;
}

.voter-cards {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
  padding: 0 16px 16px;
}

.pager {
  align-items: center;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 16px;
}

.voter-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  padding: 12px;
}

.family-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.family-head {
  align-items: center;
  background: linear-gradient(135deg, #f8fcfa 0%, #edf7f4 100%);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 14px;
}

.head-main {
  min-width: 0;
}

.ward-badge {
  background: #dff1ec;
  border-radius: 999px;
  color: var(--brand);
  display: inline-block;
  font-size: 0.76rem;
  font-weight: 800;
  margin-bottom: 8px;
  padding: 4px 9px;
}

.family-head h3 {
  font-size: 1.15rem;
  margin: 0 0 5px;
}

.family-head p {
  margin: 0 0 4px;
}

.family-score {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 86px;
  padding: 10px;
  text-align: center;
}

.family-score strong {
  display: block;
  font-size: 1.45rem;
  line-height: 1;
}

.family-score span {
  color: var(--muted);
  font-size: 0.76rem;
}

.family-stats {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 12px 14px;
}

.family-stats span {
  background: #f4f7fa;
  border-radius: 6px;
  color: var(--muted);
  display: grid;
  font-size: 0.78rem;
  min-height: 48px;
  padding: 7px;
}

.family-stats strong {
  color: var(--ink);
  font-size: 1.05rem;
}

.member-list {
  display: grid;
}

.member-row {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(220px, 1fr) minmax(460px, 1.6fr);
  padding: 12px 14px;
}

.member-info {
  min-width: 0;
}

.member-info h4 {
  font-size: 1rem;
  margin: 0 0 3px;
}

.member-info p,
.member-info span {
  color: var(--muted);
  display: block;
  font-size: 0.84rem;
  margin: 0;
}

.voter-card header {
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.voter-card h3 {
  font-size: 1rem;
  margin: 0 0 4px;
}

.voter-meta {
  color: var(--muted);
  font-size: 0.86rem;
}

.status-buttons {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.status-buttons button {
  font-size: 0.74rem;
  justify-content: center;
  min-height: 30px;
  padding: 0 5px;
  white-space: nowrap;
}

.status-buttons button.active[data-status="support"] {
  background: var(--support);
  border-color: var(--support);
  color: #fff;
}

.status-buttons button.active[data-status="leaning"] {
  background: var(--leaning);
  border-color: var(--leaning);
  color: #fff;
}

.status-buttons button.active[data-status="opposition"] {
  background: var(--opposition);
  border-color: var(--opposition);
  color: #fff;
}

.status-buttons button.active[data-status="away"] {
  background: var(--away);
  border-color: var(--away);
  color: #fff;
}

.status-buttons button.active[data-status="undecided"] {
  background: #eef3f8;
  border-color: #b9c6d3;
}

.bar {
  background: #edf2f7;
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}

.bar span {
  background: var(--brand);
  display: block;
  height: 100%;
}

.mobile-actionbar {
  align-items: center;
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  bottom: 0;
  box-shadow: 0 -10px 28px rgba(31, 47, 70, 0.12);
  display: none;
  gap: 10px;
  justify-content: space-between;
  left: 0;
  padding: 10px 12px;
  position: fixed;
  right: 0;
  z-index: 8;
}

.mobile-actionbar span {
  color: var(--muted);
  font-size: 0.82rem;
}

.mobile-actionbar strong {
  color: var(--ink);
  display: block;
  font-size: 1.05rem;
}

.ward-mini-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  display: grid;
  gap: 10px;
  padding: 12px;
}

.ward-mini-card header {
  align-items: baseline;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.ward-mini-card header span {
  color: var(--muted);
  font-size: 0.82rem;
}

.ward-mini-score {
  align-items: end;
  display: flex;
  justify-content: space-between;
}

.ward-mini-score strong {
  font-size: 1.55rem;
  line-height: 1;
}

.ward-mini-score span {
  color: var(--muted);
  font-size: 0.82rem;
}

.mini-grid {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(4, 1fr);
}

.mini-grid span {
  background: #f4f7fa;
  border-radius: 8px;
  color: var(--muted);
  display: grid;
  font-size: 0.7rem;
  padding: 6px;
}

.mini-grid b {
  color: var(--ink);
  font-size: 0.95rem;
}

.auth-screen {
  align-items: center;
  background: rgba(14, 23, 35, 0.68);
  bottom: 0;
  display: flex;
  justify-content: center;
  left: 0;
  padding: 18px;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 20;
}

.auth-screen.hidden {
  display: none;
}

.auth-card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
  display: grid;
  gap: 14px;
  max-width: 420px;
  padding: 22px;
  width: 100%;
}

.profile-list {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.profile-chip,
.profile-new {
  align-items: center;
  background: #f5f8fa !important;
  border: 1px solid var(--line) !important;
  border-radius: 10px;
  color: var(--ink) !important;
  display: flex;
  gap: 8px;
  justify-content: flex-start !important;
  min-height: 48px;
  padding: 8px 10px !important;
}

.profile-chip {
  flex-direction: column;
  align-items: flex-start;
}

.profile-chip span {
  font-weight: 800;
}

.profile-chip small {
  color: var(--muted);
}

.profile-new strong {
  align-items: center;
  background: var(--brand);
  border-radius: 999px;
  color: #fff;
  display: inline-flex;
  font-size: 1.1rem;
  height: 24px;
  justify-content: center;
  width: 24px;
}

.auth-card h2 {
  margin-bottom: 0;
}

.auth-card p {
  color: var(--muted);
  margin-bottom: 0;
}

.auth-card button {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  justify-content: center;
  min-height: 44px;
}

.auth-message {
  color: var(--opposition) !important;
  min-height: 20px;
}

@media (max-width: 980px) {
  .topbar,
  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .summary-grid,
  .control-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .voter-cards,
  .member-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 650px) {
  body {
    background: #eef3f2;
    padding-bottom: 76px;
  }

  .topbar {
    background: #126b58;
    border-bottom: 0;
    color: #fff;
    gap: 12px;
    padding: 14px 12px 12px;
    position: sticky;
    top: 0;
    z-index: 9;
  }

  h1 {
    font-size: 1.25rem;
    line-height: 1.1;
    margin-bottom: 2px;
  }

  .topbar .eyebrow,
  .topbar .subhead {
    color: rgba(255, 255, 255, 0.78);
  }

  .topbar .subhead {
    display: none;
  }

  .layout {
    gap: 10px;
    max-width: 520px;
    padding: 10px 10px 18px;
  }

  .summary-grid,
  .control-row,
  .voter-cards {
    grid-template-columns: 1fr;
  }

  .status-buttons {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .status-buttons button {
    border-radius: 999px;
    font-size: 0.64rem;
    min-height: 28px;
    padding: 0 2px;
  }

  .header-actions {
    display: grid;
    gap: 6px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .header-actions a,
  .header-actions button {
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(255, 255, 255, 0.24);
    color: #fff;
    font-size: 0.74rem;
    justify-content: center;
    min-height: 32px;
    padding: 0 6px;
  }

  .summary-grid {
    gap: 8px;
    grid-template-columns: repeat(5, minmax(92px, 1fr));
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .summary-grid article {
    border-radius: 14px;
    box-shadow: none;
    min-height: 70px;
    padding: 10px;
  }

  .summary-grid strong {
    font-size: 1.2rem;
  }

  .summary-grid span {
    font-size: 0.72rem;
  }

  .controls,
  .ward-panel,
  .voter-panel {
    border-radius: 16px;
    box-shadow: none;
  }

  .controls {
    gap: 10px;
    padding: 12px;
    position: sticky;
    top: 118px;
    z-index: 7;
  }

  .search-field input {
    min-height: 40px;
  }

  .control-row {
    grid-template-columns: 1fr 1fr;
  }

  .control-row label:last-child {
    grid-column: 1 / -1;
  }

  .panel-head {
    padding: 12px;
  }

  .panel-head h2 {
    font-size: 1.05rem;
  }

  .ward-table-wrap {
    display: none;
  }

  .ward-cards {
    display: grid;
    gap: 8px;
    padding: 0 10px 10px;
  }

  .voter-cards {
    gap: 10px;
    padding: 0 10px 10px;
  }

  .family-card {
    border-radius: 16px;
    box-shadow: 0 8px 22px rgba(31, 47, 70, 0.08);
  }

  .family-head {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
  }

  .family-score {
    align-items: center;
    display: flex;
    justify-content: space-between;
    width: 100%;
  }

  .family-score strong {
    font-size: 1.25rem;
  }

  .family-head h3 {
    font-size: 1.08rem;
  }

  .family-head p {
    font-size: 0.8rem;
  }

  .family-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 10px 12px;
  }

  .family-stats span {
    min-height: 40px;
  }

  .member-row {
    gap: 8px;
    padding: 12px;
  }

  .member-info h4 {
    font-size: 0.98rem;
  }

  .member-info p,
  .member-info span {
    font-size: 0.78rem;
  }

  .pager {
    position: sticky;
    bottom: 58px;
    background: var(--surface);
    border-radius: 14px 14px 0 0;
    padding: 10px;
  }

  .pager button {
    min-height: 34px;
    padding: 0 10px;
  }

  .mobile-actionbar {
    display: flex;
  }

  .auth-card {
    border-radius: 18px;
    min-height: auto;
    padding: 18px;
  }
}

/* App-shell overrides: keep the estimator usable even when mobile browsers request desktop site. */
body {
  background: #eef3f2;
  padding-bottom: 76px;
}

.topbar {
  background: #126b58;
  border-bottom: 0;
  color: #fff;
  gap: 12px;
  padding: 14px clamp(10px, 3vw, 18px) 12px;
  position: static;
}

.topbar .eyebrow,
.topbar .subhead {
  color: rgba(255, 255, 255, 0.78);
}

.topbar .subhead {
  display: none;
}

h1 {
  font-size: clamp(1.2rem, 3vw, 1.65rem);
  line-height: 1.1;
  margin-bottom: 3px;
}

.header-actions {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  min-width: min(420px, 100%);
}

.header-actions a,
.header-actions button {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.24);
  color: #fff;
  font-size: 0.74rem;
  justify-content: center;
  min-height: 32px;
  padding: 0 6px;
}

.layout {
  gap: 10px;
  max-width: 680px;
  padding: 10px clamp(8px, 2vw, 14px) 86px;
}

.summary-grid {
  gap: 8px;
  grid-template-columns: repeat(5, minmax(92px, 1fr));
  overflow-x: auto;
  padding-bottom: 2px;
}

.summary-grid article {
  border-radius: 14px;
  box-shadow: none;
  min-height: 68px;
  padding: 10px;
}

.summary-grid span {
  font-size: 0.72rem;
  margin-bottom: 6px;
}

.summary-grid strong {
  font-size: 1.18rem;
}

.controls,
.ward-panel,
.voter-panel {
  border-radius: 16px;
  box-shadow: none;
}

.controls {
  gap: 10px;
  padding: 12px;
  position: static;
}

input,
select {
  min-height: 38px;
}

.control-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.control-row label:last-child {
  grid-column: 1 / -1;
}

.panel-head {
  padding: 12px;
}

.panel-head h2 {
  font-size: 1.05rem;
}

.ward-table-wrap {
  display: none;
}

.ward-cards {
  display: grid;
  gap: 8px;
  padding: 0 10px 10px;
}

.voter-cards {
  gap: 10px;
  padding: 0 10px 10px;
}

.family-card {
  border-radius: 16px;
  box-shadow: 0 8px 22px rgba(31, 47, 70, 0.08);
}

.family-head {
  align-items: stretch;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
}

.ward-badge {
  margin-bottom: 6px;
  padding: 3px 8px;
}

.family-head h3 {
  font-size: 1.06rem;
  margin-bottom: 4px;
}

.family-head p {
  font-size: 0.8rem;
}

.family-score {
  align-items: center;
  display: flex;
  justify-content: space-between;
  padding: 8px 10px;
  width: 100%;
}

.family-score strong {
  font-size: 1.25rem;
}

.family-stats {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 10px 12px;
}

.family-stats span {
  min-height: 38px;
  padding: 6px;
}

.member-row {
  gap: 8px;
  grid-template-columns: 1fr;
  padding: 10px 12px;
}

.member-info h4 {
  font-size: 0.96rem;
}

.member-info p,
.member-info span {
  font-size: 0.76rem;
}

.status-buttons button {
  border-radius: 999px;
  font-size: 0.64rem;
  min-height: 28px;
  padding: 0 2px;
}

.pager {
  background: var(--surface);
  border-radius: 14px 14px 0 0;
  bottom: auto;
  padding: 10px;
  position: static;
}

.pager button {
  min-height: 34px;
  padding: 0 10px;
}

.mobile-actionbar {
  display: flex;
}
