:root {
  --brand: #0f766e;
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #17212b;
  --muted: #64748b;
  --line: #e2e8f0;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 12px;
  --nav-w: 250px;
  --top-h: 56px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 2px 8px rgba(15, 23, 42, .04);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Telugu", "Noto Sans Devanagari", sans-serif; background: var(--bg); color: var(--ink); -webkit-tap-highlight-color: transparent; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
small, .muted { color: var(--muted); }
img { max-width: 100%; }
code { background: #eef2f7; padding: 1px 5px; border-radius: 4px; font-size: .9em; }

/* ---------- layout */
.topbar { position: fixed; inset: 0 0 auto 0; height: var(--top-h); background: var(--brand); color: #fff; display: flex; align-items: center; gap: 10px; padding: 0 14px; z-index: 40; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 600; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand-mark { background: rgba(255,255,255,.2); border-radius: 8px; width: 34px; height: 34px; display: grid; place-items: center; font-weight: 800; letter-spacing: -.5px; flex: none; }
.brand-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { margin-left: auto; }
.user-chip { background: rgba(255,255,255,.15); padding: 4px 10px; border-radius: 99px; font-size: .85rem; white-space: nowrap; }
.user-chip small { color: rgba(255,255,255,.75); margin-left: 4px; }
.icon-btn { background: none; border: 0; color: inherit; font-size: 1.4rem; padding: 6px; cursor: pointer; }

.sidebar { position: fixed; top: var(--top-h); bottom: 0; left: 0; width: var(--nav-w); background: var(--card); border-right: 1px solid var(--line); overflow-y: auto; padding: 10px 8px 30px; z-index: 30; }
.sidebar a, .nav-link-btn { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--ink); font-size: .93rem; }
.sidebar a i, .nav-link-btn i, .bottom-nav i { font-style: normal; width: 22px; text-align: center; }
.sidebar a:hover, .nav-link-btn:hover { background: #f1f5f9; text-decoration: none; }
.sidebar a.active { background: color-mix(in srgb, var(--brand) 12%, white); color: var(--brand); font-weight: 600; }
.nav-link-btn { width: 100%; background: none; border: 0; font: inherit; cursor: pointer; text-align: left; }
.nav-group { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 12px 4px; }
.nav-backdrop { display: none; }

main { padding: calc(var(--top-h) + 18px) 22px 40px; max-width: 1400px; }
main.with-nav { margin-left: var(--nav-w); }
main.no-nav { margin: 0; padding: 0; max-width: none; }
main.no-nav > .empty-state { padding-top: 80px; }

.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; background: var(--card); border-top: 1px solid var(--line); display: flex; z-index: 35; padding-bottom: env(safe-area-inset-bottom); }
.bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 7px 2px; color: var(--muted); font-size: .7rem; }
.bottom-nav a i { font-size: 1.25rem; }
.bottom-nav a.active { color: var(--brand); font-weight: 600; }
.only-mobile { display: none !important; }

@media (max-width: 900px) {
  .only-mobile { display: flex !important; }
  .hide-mobile { display: none !important; }
  .sidebar { transform: translateX(-105%); transition: transform .2s ease; box-shadow: 4px 0 20px rgba(0,0,0,.12); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 25; }
  main.with-nav { margin-left: 0; padding: calc(var(--top-h) + 12px) 12px 90px; }
  .user-chip small { display: none; }
}

/* ---------- components */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head p { margin: 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.tight { padding: 0; overflow: hidden; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 700px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } .grid-4 { gap: 10px; } }

.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { font-size: .8rem; color: var(--muted); }
.stat .value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: .78rem; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--brand); color: #fff; border: 1px solid var(--brand); padding: 9px 16px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; min-height: 40px; }
.btn:hover { text-decoration: none; filter: brightness(.95); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--brand); border-color: var(--line); }
.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn-danger.btn-ghost { background: transparent; color: var(--danger); }
.btn-sm { padding: 5px 10px; min-height: 32px; font-size: .85rem; }
.btn-block { width: 100%; }
.link-btn { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; padding: 0; }
.link-btn.danger { color: var(--danger); }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; min-width: 0; }
.field > span { font-size: .82rem; font-weight: 600; color: #334155; }
.field small { font-weight: 400; }
input[type=text], input[type=password], input[type=number], input[type=tel], input[type=search], input[type=email], input[type=date], input[type=color], input[type=file], select, textarea {
  width: 100%; font: inherit; padding: 9px 11px; border: 1px solid #cbd5e1; border-radius: 9px; background: #fff; color: var(--ink); min-height: 42px;
}
input[type=color] { padding: 3px; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, white); border-color: var(--brand); }
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 12px; }
.geo-selects { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px 14px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin: 0 0 12px; }
legend { font-weight: 600; font-size: .85rem; padding: 0 6px; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th { background: #f8fafc; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.row-link { cursor: pointer; }
.table tr.row-link:hover td { background: #f8fafc; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .74rem; font-weight: 600; background: #e2e8f0; color: #334155; white-space: nowrap; }
.badge.ok, .aff-strong, .st-active, .st-done, .st-sent, .st-delivered, .st-read { background: #dcfce7; color: #166534; }
.aff-leaning { background: #d1fae5; color: #065f46; }
.aff-neutral, .st-draft, .st-queued { background: #fef3c7; color: #92400e; }
.aff-opposition, .st-failed, .badge.off { background: #fee2e2; color: #991b1b; }
.st-sending, .st-processing { background: #dbeafe; color: #1e40af; }
.st-closed { background: #e2e8f0; color: #475569; }

.progress { height: 8px; background: #e2e8f0; border-radius: 99px; overflow: hidden; min-width: 70px; display: inline-block; width: 100px; vertical-align: middle; margin-right: 6px; }
.progress > div { height: 100%; background: var(--brand); }

.flashes { display: grid; gap: 8px; margin-bottom: 14px; }
.flash { padding: 10px 40px 10px 14px; border-radius: 10px; position: relative; border: 1px solid; }
.flash-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.flash-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.flash-x { position: absolute; right: 8px; top: 6px; background: none; border: 0; font-size: 1.2rem; cursor: pointer; color: inherit; }

.empty-state { text-align: center; padding: 50px 20px; }
.empty-state .big { font-size: 3rem; font-weight: 800; color: var(--brand); }
.pager { display: flex; gap: 10px; align-items: center; justify-content: center; margin: 14px 0; }
.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.list-plain li:last-child { border: 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 1fr) 2fr 60px; gap: 10px; align-items: center; margin: 6px 0; font-size: .9rem; }
.bar-row .bar { height: 14px; background: #eef2f7; border-radius: 4px; overflow: hidden; }
.bar-row .bar > div { height: 100%; background: var(--brand); border-radius: 4px; }
.bar-row .n { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.divider { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs a { padding: 8px 14px; border-bottom: 2px solid transparent; color: var(--muted); white-space: nowrap; }
.tabs a.active { color: var(--brand); border-color: var(--brand); font-weight: 600; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 14px 0 4px; display: flex; gap: 8px; }
@media (max-width: 900px) { .sticky-actions { bottom: 58px; } }

/* ---------- voter cards (mobile) */
.voter-list { display: grid; gap: 10px; }
.voter-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; color: var(--ink); }
.voter-card:hover { text-decoration: none; border-color: var(--brand); }
.voter-card .name { font-weight: 600; }
.voter-card .meta { font-size: .82rem; color: var(--muted); }

/* ---------- hierarchy columns */
.cols-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: start; }
@media (max-width: 1000px) { .cols-3 { grid-template-columns: 1fr; } }
.pick-list { list-style: none; margin: 0; padding: 0; max-height: 460px; overflow-y: auto; }
.pick-list li { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 8px 10px; border-radius: 8px; }
.pick-list li.active { background: color-mix(in srgb, var(--brand) 10%, white); }
.pick-list li a.pick { color: var(--ink); flex: 1; min-width: 0; }
.pick-list li .cnt { font-size: .75rem; color: var(--muted); }

/* ---------- login */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--brand), #134e4a); }
.auth-card { width: 100%; max-width: 400px; background: #fff; border-radius: 16px; padding: 28px 24px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.auth-card .brand-mark { background: var(--brand); color: #fff; width: 48px; height: 48px; font-size: 1.2rem; margin-bottom: 10px; }

/* ---------- survey */
.q-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.q-card .q-text { font-weight: 600; margin-bottom: 8px; }
.q-card .req { color: var(--danger); }
.opt { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; margin: 6px 0; cursor: pointer; }
.opt:has(input:checked) { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, white); }
.opt input { width: 20px; height: 20px; accent-color: var(--brand); }
.rating { display: flex; gap: 6px; }
.rating label { flex: 1; }
.rating input { display: none; }
.rating span { display: block; text-align: center; padding: 10px 0; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-weight: 600; }
.rating input:checked + span { background: var(--brand); color: #fff; border-color: var(--brand); }
.gps-box { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: #fff; margin-bottom: 12px; }
.gps-box .dot { width: 14px; height: 14px; border-radius: 50%; background: #cbd5e1; flex: none; }
.gps-box.ok { border-color: #86efac; background: #f0fdf4; } .gps-box.ok .dot { background: var(--ok); }
.gps-box.bad { border-color: #fecaca; background: #fef2f2; } .gps-box.bad .dot { background: var(--danger); }
.gps-box.wait .dot { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.qb-item { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; background: #fcfdfe; }
.qb-item .qb-top { display: grid; grid-template-columns: 1fr 170px auto; gap: 8px; }
@media (max-width: 700px) { .qb-item .qb-top { grid-template-columns: 1fr; } }

/* ---------- poster editor */
.poster-layout { display: grid; grid-template-columns: 320px 1fr; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .poster-layout { grid-template-columns: 1fr; } .poster-stage { order: -1; } }
.poster-stage { background: repeating-conic-gradient(#e2e8f0 0 25%, #f8fafc 0 50%) 0 0/20px 20px; border-radius: 12px; padding: 12px; display: flex; justify-content: center; position: sticky; top: calc(var(--top-h) + 12px); }
@media (max-width: 1000px) { .poster-stage { position: static; } }
.poster-stage canvas { max-width: 100%; max-height: 78vh; height: auto; box-shadow: 0 6px 30px rgba(0,0,0,.2); touch-action: none; background: #fff; }
.layer-list { list-style: none; padding: 0; margin: 0; }
.layer-list li { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 8px; cursor: pointer; font-size: .88rem; }
.layer-list li.sel { background: color-mix(in srgb, var(--brand) 12%, white); }
.layer-list li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asset-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.asset-grid button { border: 1px solid var(--line); border-radius: 8px; padding: 0; background: #fff; aspect-ratio: 1; overflow: hidden; cursor: pointer; }
.asset-grid img { width: 100%; height: 100%; object-fit: cover; }
.template-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.template-grid button { border: 1px solid var(--line); border-radius: 8px; padding: 8px 4px; background: #fff; cursor: pointer; font-size: .78rem; }
.poster-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.poster-tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.poster-tile img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: #f1f5f9; }
.poster-tile .pt-body { padding: 10px; }
