:root {
  --bg: #f4f6f5; --surface: #ffffff; --surface-2: #f8faf9; --border: #dde3e0; --border-strong: #c4ceca;
  --text: #17211e; --muted: #5d6b66; --primary: #0e6b57; --primary-ink: #ffffff; --primary-soft: #e3f1ec;
  --accent: #c7781d; --danger: #b42318; --danger-soft: #fdecea; --ok: #1d7a46; --warn-soft: #fff4e0;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,20,.06), 0 2px 8px rgba(16,24,20,.05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
a { color: var(--primary); }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .hidden { display: none !important; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  padding: .6rem 1rem; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 42px; }
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: #f0b8b2; } .btn.danger:hover { background: var(--danger-soft); }
.btn.small { min-height: 32px; padding: .3rem .7rem; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=tel], input[type=search], select, textarea {
  width: 100%; padding: .6rem .7rem; border: 1px solid var(--border-strong); border-radius: 8px; font: inherit; background: var(--surface); color: var(--text); min-height: 42px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
textarea { min-height: 90px; resize: vertical; }
label.field { display: block; margin-bottom: .9rem; } label.field > span { display: block; font-weight: 600; margin-bottom: .3rem; font-size: .9rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem; }
.alert { padding: .7rem .9rem; border-radius: 8px; background: var(--danger-soft); color: var(--danger); margin-bottom: .8rem; font-size: .9rem; }
.alert.ok { background: var(--primary-soft); color: var(--primary); } .alert.warn { background: var(--warn-soft); color: #8a4b05; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 99px; font-size: .75rem; font-weight: 600; background: var(--primary-soft); color: var(--primary); }
.badge.red { background: var(--danger-soft); color: var(--danger); } .badge.amber { background: var(--warn-soft); color: #8a4b05; } .badge.grey { background: #eceff0; color: var(--muted); }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 400px; }
.login-card .brand { display: flex; align-items: center; gap: .7rem; margin-bottom: 1.2rem; }
.logo { width: 42px; height: 42px; border-radius: 10px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 800; flex: none; }
.portal-tag { font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
.login-switch { margin-top: 1rem; text-align: center; font-size: .9rem; }

/* App bar */
.appbar { position: sticky; top: 0; z-index: 20; background: var(--primary); color: #fff; display: flex; align-items: center; gap: .8rem; padding: .6rem 1rem; }
.appbar .title { font-weight: 700; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar .btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); min-height: 34px; padding: .3rem .7rem; font-size: .85rem; }
.net { font-size: .75rem; padding: .1rem .5rem; border-radius: 99px; background: rgba(255,255,255,.18); }
.net.off { background: #f5c26b; color: #3d2600; }

/* Enumerator */
.container { max-width: 760px; margin: 0 auto; padding: 16px; }
.home-actions { display: grid; gap: .8rem; grid-template-columns: 1fr 1fr; margin: 1rem 0; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem; }
.stat b { display: block; font-size: 1.5rem; }
.list-item { display: flex; justify-content: space-between; align-items: center; gap: .6rem; padding: .7rem 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.progress { height: 6px; background: #d8e3df; border-radius: 99px; overflow: hidden; margin: .4rem 0 1rem; }
.progress > div { height: 100%; background: var(--primary); transition: width .2s; }
.section-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); font-weight: 700; }
.sub-head { margin: 1.4rem 0 .6rem; padding-bottom: .3rem; border-bottom: 2px solid var(--primary-soft); color: var(--primary); font-size: .95rem; }
.q { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: .8rem; }
.q.err { border-color: var(--danger); background: #fffafa; }
.q .qlabel { font-weight: 600; margin-bottom: .6rem; }
.q .qnum { color: var(--primary); margin-right: .3rem; }
.q .req { color: var(--danger); } .q .opt { color: var(--muted); font-weight: 400; font-size: .8rem; }
.q .hint { color: var(--muted); font-size: .85rem; margin: -.3rem 0 .6rem; font-style: italic; }
.q .errmsg { color: var(--danger); font-size: .85rem; margin-top: .5rem; }
.choices { display: grid; gap: .45rem; }
.choice { display: flex; align-items: flex-start; gap: .6rem; padding: .6rem .7rem; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; background: var(--surface-2); }
.choice:hover { border-color: var(--primary); }
.choice input { margin-top: .2rem; width: 18px; height: 18px; accent-color: var(--primary); flex: none; }
.choice.on { border-color: var(--primary); background: var(--primary-soft); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.pair label span { font-size: .85rem; color: var(--muted); }
.grid-q { width: 100%; border-collapse: collapse; }
.grid-q td, .grid-q th { padding: .45rem .3rem; border-bottom: 1px solid var(--border); text-align: center; font-size: .9rem; }
.grid-q td:first-child, .grid-q th:first-child { text-align: left; }
.grid-q input { width: 20px; height: 20px; accent-color: var(--primary); }
.grid-scroll { overflow-x: auto; }
.wizard-nav { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 1rem 0 .4rem; display: flex; gap: .6rem; }
.wizard-nav .btn { flex: 1; }
.review-mod { margin-bottom: .8rem; }
.review-row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; padding: .35rem 0; border-bottom: 1px dashed var(--border); font-size: .88rem; }
.review-row div:first-child { color: var(--muted); }

/* Admin */
.admin { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar { background: #0c2d26; color: #cfe1db; padding: 1rem .7rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { display: flex; gap: .6rem; align-items: center; padding: .3rem .4rem 1.2rem; color: #fff; }
.sidebar .brand .logo { background: #1f8f74; }
.sidebar nav a { display: block; padding: .6rem .8rem; border-radius: 8px; color: #cfe1db; text-decoration: none; font-weight: 500; margin-bottom: 2px; }
.sidebar nav a:hover { background: rgba(255,255,255,.07); }
.sidebar nav a.active { background: #1f8f74; color: #fff; }
.sidebar .foot { margin-top: 2rem; padding: .6rem .8rem; font-size: .85rem; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar .foot button { background: none; border: 0; color: #9fd6c5; cursor: pointer; padding: 0; font: inherit; }
.main { padding: 1.2rem 1.5rem 3rem; min-width: 0; }
.topline { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; background: var(--surface); border: 1px solid var(--border); padding: .7rem; border-radius: var(--radius); margin-bottom: 1rem; }
.filters label { font-size: .75rem; color: var(--muted); font-weight: 600; display: grid; gap: .2rem; }
.filters select, .filters input { min-height: 36px; padding: .35rem .5rem; width: auto; min-width: 140px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem .9rem; }
.kpi .v { font-size: 1.55rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: .8rem; }
.kpi.hl { border-left: 4px solid var(--primary); }
.charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: .9rem; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem; min-width: 0; }
.chart-card.wide { grid-column: 1 / -1; }
.chart-card h4 { font-size: .92rem; margin-bottom: .2rem; }
.kpi .v small { font-size: .9rem; font-weight: 600; color: var(--muted); }
.kpi .s { color: var(--muted); font-size: .75rem; margin-top: .15rem; }
.dash-h { font-size: 1.02rem; margin: 1.6rem 0 .7rem; padding-bottom: .35rem; border-bottom: 2px solid var(--primary-soft); color: var(--text); }
/* Block comparison heatmap */
.chart-card > .table-wrap { border: 0; }
table.heat { border-collapse: separate; border-spacing: 2px; width: 100%; font-variant-numeric: tabular-nums; font-size: .82rem; }
table.heat th { font-weight: 600; color: var(--muted); text-align: left; padding: .25rem .4rem; white-space: nowrap; }
table.heat th.grp { text-align: center; border-bottom: 2px solid var(--border); font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; }
table.heat th.ind { vertical-align: bottom; text-align: center; white-space: normal; min-width: 64px; max-width: 86px; font-size: .74rem; line-height: 1.2; }
table.heat tbody th { color: var(--text); font-weight: 500; }
table.heat td { text-align: center; padding: .38rem .2rem; border-radius: 4px; min-width: 52px; font-weight: 600; }
table.heat td.n { color: var(--muted); font-weight: 500; background: none; min-width: 48px; }
table.heat th.n { text-align: center; }
table.heat td.na { color: #9aa5a1; background: #f5f6f6; font-weight: 400; }
table.heat tr.low td:not(.n) { opacity: .35; }
table.heat tr.total th, table.heat tr.total td { border-top: 2px solid var(--text); font-weight: 700; }
table.heat tr.total th { padding-top: .5rem; }
.heat-legend { display: flex; align-items: center; gap: .5rem; font-size: .75rem; color: var(--muted); margin-top: .6rem; }
.heat-legend i { width: 160px; height: 10px; border-radius: 3px; background: linear-gradient(90deg, rgb(242,246,252), rgb(183,211,246), rgb(109,167,236), rgb(37,106,191), rgb(16,66,129)); }
.chart-card .meta { font-size: .78rem; color: var(--muted); margin-bottom: .5rem; }
.chart-box { position: relative; height: 260px; }
.mod-block { margin-top: 1.4rem; }
.mod-block > summary { cursor: pointer; font-weight: 700; font-size: 1.02rem; padding: .7rem .9rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); list-style: none; display: flex; justify-content: space-between; }
.mod-block > summary::after { content: '▾'; color: var(--muted); }
.mod-block[open] > summary { margin-bottom: .9rem; border-color: var(--primary); }
.mod-block[open] > summary::after { content: '▴'; }
.tabs { display: flex; gap: .3rem; margin-bottom: 1rem; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--border); background: var(--surface); padding: .45rem .9rem; border-radius: 99px; cursor: pointer; font: inherit; font-weight: 600; }
.tabs button.on { background: var(--primary); color: #fff; border-color: var(--primary); }
table.data { width: 100%; border-collapse: collapse; background: var(--surface); }
table.data th, table.data td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); font-size: .88rem; vertical-align: top; }
table.data th { background: var(--surface-2); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); position: sticky; top: 0; }
table.data tr:hover td { background: #fafcfb; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.pager { display: flex; gap: .5rem; align-items: center; justify-content: flex-end; margin-top: .7rem; }
.texts { max-height: 260px; overflow-y: auto; font-size: .87rem; }
.texts div { padding: .45rem 0; border-bottom: 1px solid var(--border); }
.texts small { color: var(--muted); display: block; }
.num-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; margin-bottom: .6rem; text-align: center; }
.num-stats div { background: var(--surface-2); border-radius: 6px; padding: .4rem; } .num-stats b { display: block; font-size: 1.1rem; }
.modal { position: fixed; inset: 0; background: rgba(10,20,16,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal .card { width: 100%; max-width: 720px; max-height: 90vh; overflow-y: auto; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #17211e; color: #fff; padding: .7rem 1.1rem; border-radius: 8px; z-index: 99; font-size: .9rem; box-shadow: var(--shadow); }
.menu-btn { display: none; }
@media (max-width: 900px) {
  .admin { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -260px; width: 240px; z-index: 40; transition: left .2s; }
  .sidebar.open { left: 0; }
  .menu-btn { display: inline-flex; }
  .main { padding: 1rem; }
  .charts { grid-template-columns: 1fr; }
  .row2 { grid-template-columns: 1fr; }
}
@media (max-width: 520px) { .home-actions { grid-template-columns: 1fr; } .review-row { grid-template-columns: 1fr; gap: 0; } }
@media print { .sidebar, .filters, .topline .btn, .menu-btn { display: none !important; } .admin { display: block; } .chart-card { break-inside: avoid; } table.heat td { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }
/* Keep block names visible when the heatmap scrolls sideways on small screens */
table.heat tbody th, table.heat thead tr:last-child th:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; }

/* ── Village tools, photos and attendance (enumerator) ── */
.linkbtn { background: none; border: 0; padding: .35rem 0 0; color: var(--primary); font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; display: inline-block; }
.q .unit { color: var(--muted); font-weight: 500; }
.q input.remark { margin-top: .5rem; background: var(--surface-2); }
.choices.inline { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
textarea.long { min-height: 170px; }
.probe-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: .5rem .7rem; margin-bottom: .6rem; font-size: .88rem; }
.probe-box summary { cursor: pointer; font-weight: 600; color: var(--accent); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
ul.probes { margin: .4rem 0 0; padding-left: 1.1rem; } ul.probes li { margin-bottom: .25rem; }
.tool-list { display: grid; gap: .6rem; margin: .5rem 0 1rem; }
.tool-btn { display: flex; align-items: center; gap: .8rem; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); padding: .8rem .9rem; font: inherit; color: var(--text); cursor: pointer; box-shadow: var(--shadow); min-height: 64px; }
.tool-btn:hover, .tool-btn:active { border-color: var(--primary); background: var(--primary-soft); }
.tool-btn .ic { font-size: 1.6rem; flex: none; } .tool-btn > span:nth-child(2) { flex: 1; min-width: 0; }
.tool-btn b { display: block; } .tool-btn small { color: var(--muted); display: block; line-height: 1.3; }
.tool-btn .go { flex: none; width: 34px; height: 34px; border-radius: 99px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; }
.att-card.todo { border-left: 4px solid var(--accent); }
.att-clock { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.gps { padding: .6rem .7rem; border-radius: 8px; font-size: .9rem; } .gps.wait { background: var(--warn-soft); color: #8a4b05; } .gps.ok { background: var(--primary-soft); color: var(--primary); font-weight: 600; } .gps.ok .muted { font-weight: 400; } .gps.bad { background: var(--danger-soft); color: var(--danger); }
img.selfie { display: block; width: 100%; max-width: 260px; border-radius: 8px; margin-bottom: .6rem; border: 1px solid var(--border); }
.roster-row { border: 1px solid var(--border); border-radius: 8px; padding: .7rem; margin-bottom: .6rem; background: var(--surface-2); }
.roster-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.roster-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; } .roster-grid label.wide { grid-column: 1 / -1; }
.roster-grid label span { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .15rem; } .roster-grid label span i { font-style: normal; opacity: .8; }
.photo-list { display: grid; gap: .7rem; margin-bottom: .8rem; }
.photo-item { display: grid; grid-template-columns: 120px 1fr; gap: .7rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem; }
.photo-item img { width: 120px; height: 120px; object-fit: cover; border-radius: 6px; } .photo-meta { display: grid; gap: .35rem; align-content: start; min-width: 0; }
.thumbs { display: flex; gap: .4rem; flex-wrap: wrap; } .thumbs img { width: 84px; height: 84px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
@media (max-width: 520px) { .home-actions[style*="repeat(4"] { grid-template-columns: 1fr 1fr !important; } .photo-item { grid-template-columns: 92px 1fr; } .photo-item img { width: 92px; height: 92px; } }

/* ── Admin: village tools, photos, attendance ── */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .8rem; }
.gallery figure { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.gallery img { width: 100%; height: 150px; object-fit: cover; display: block; cursor: zoom-in; background: #e8ecea; }
.gallery figcaption { padding: .5rem .6rem; font-size: .8rem; display: grid; gap: .15rem; }
.modal .card.wide { max-width: 980px; } .modal img.full { max-width: 100%; max-height: 72vh; display: block; margin: 0 auto; border-radius: 6px; }
.att-thumb { width: 38px; height: 38px; border-radius: 6px; object-fit: cover; vertical-align: middle; cursor: zoom-in; margin-right: .4rem; background: #e8ecea; }
.detail-photos { display: flex; gap: .5rem; flex-wrap: wrap; margin: .5rem 0; } .detail-photos figure { margin: 0; width: 150px; font-size: .75rem; } .detail-photos img { width: 150px; height: 110px; object-fit: cover; border-radius: 6px; cursor: zoom-in; background: #e8ecea; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
/* Attendance: live camera */
.cam-box { margin-bottom: .6rem; }
video.live { display: block; width: 100%; max-width: 340px; border-radius: 8px; background: #000; border: 1px solid var(--border); }
video.live.mirror { transform: scaleX(-1); }
.cam-box img.selfie { max-width: 340px; margin-bottom: 0; }
