:root {
  --ink: #102a43;
  --ink-soft: #486581;
  --muted: #829ab1;
  --line: #d9e2ec;
  --canvas: #f4f7fa;
  --paper: #ffffff;
  --teal: #0f766e;
  --teal-soft: #e6fffa;
  --amber: #c27803;
  --amber-soft: #fff6db;
  --blue-soft: #eaf2fb;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(16, 42, 67, .08);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--canvas); }
button, input, select { font: inherit; }
button { cursor: pointer; }
.app-shell { min-height: 100vh; }
.loading-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; gap: 14px; color: var(--ink-soft); }
.loading-screen span { display: block; margin-top: 4px; font-size: 13px; color: var(--muted); }
.loading-mark, .brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; background: var(--ink); color: #fff; font-weight: 800; letter-spacing: -.04em; box-shadow: 0 8px 18px rgba(16,42,67,.18); }

.topbar { background: var(--ink); color: #fff; }
.topbar-inner { max-width: 1240px; margin: 0 auto; padding: 23px 28px 21px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark { background: #1d4d6f; border: 1px solid rgba(255,255,255,.16); }
.brand-copy strong { display: block; font-size: 16px; letter-spacing: -.01em; }
.brand-copy span { display: block; margin-top: 3px; color: #9fb3c8; font-size: 12px; }
.topbar-note { font-size: 12px; color: #bcccdc; display: flex; align-items: center; gap: 8px; }
.topbar-note i { display: block; width: 7px; height: 7px; background: #43d9a3; border-radius: 99px; box-shadow: 0 0 0 4px rgba(67,217,163,.14); }

.page { max-width: 1240px; margin: 0 auto; padding: 34px 28px 60px; }
.hero { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.eyebrow { color: var(--teal); text-transform: uppercase; letter-spacing: .12em; font-size: 11px; font-weight: 800; margin: 0 0 8px; }
h1 { font-size: clamp(27px, 4vw, 40px); line-height: 1.08; letter-spacing: -.045em; margin: 0; }
.hero p { margin: 10px 0 0; color: var(--ink-soft); max-width: 610px; font-size: 15px; line-height: 1.55; }
.data-note { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 11px 14px; font-size: 12px; color: var(--ink-soft); white-space: nowrap; }
.data-note strong { display: block; font-size: 16px; color: var(--ink); margin-bottom: 2px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 22px; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 17px 18px; position: relative; overflow: hidden; }
.stat::after { content: ""; position: absolute; right: -16px; bottom: -24px; width: 70px; height: 70px; border-radius: 99px; background: var(--blue-soft); }
.stat:nth-child(2)::after { background: var(--teal-soft); }
.stat:nth-child(3)::after { background: var(--amber-soft); }
.stat:nth-child(4)::after { background: #f2eafa; }
.stat-label { color: var(--ink-soft); font-size: 12px; position: relative; z-index: 1; }
.stat-value { font-size: 28px; font-weight: 750; letter-spacing: -.04em; margin-top: 8px; position: relative; z-index: 1; }
.stat-hint { color: var(--muted); font-size: 11px; margin-top: 4px; position: relative; z-index: 1; }

.workspace { display: grid; grid-template-columns: 246px minmax(0, 1fr); gap: 18px; align-items: start; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.sidebar { padding: 13px; position: sticky; top: 18px; }
.nav-label { padding: 7px 11px 9px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.nav-btn { width: 100%; border: 0; background: transparent; text-align: left; padding: 12px 11px; color: var(--ink-soft); border-radius: 12px; display: flex; gap: 10px; align-items: center; font-weight: 650; font-size: 13px; }
.nav-btn:hover { background: #f6f9fb; color: var(--ink); }
.nav-btn.active { background: var(--ink); color: #fff; box-shadow: 0 7px 16px rgba(16,42,67,.14); }
.nav-icon { width: 20px; text-align: center; font-size: 16px; }
.sidebar-divider { height: 1px; background: var(--line); margin: 15px 7px; }
.sidebar-tip { background: #f7fafc; border-radius: 12px; padding: 12px; color: var(--ink-soft); font-size: 11px; line-height: 1.5; }
.sidebar-tip strong { color: var(--ink); display: block; margin-bottom: 3px; }

.content { min-width: 0; }
.search-panel { padding: 18px; margin-bottom: 16px; }
.search-row { display: flex; gap: 10px; }
.search-wrap { position: relative; flex: 1; }
.search-wrap svg { position: absolute; width: 19px; height: 19px; left: 14px; top: 13px; stroke: var(--muted); }
.search-input { width: 100%; height: 46px; border: 1px solid #bcccdc; border-radius: 12px; padding: 0 14px 0 44px; outline: none; color: var(--ink); background: #fbfdff; }
.search-input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(15,118,110,.11); }
.search-input::placeholder { color: #9fb3c8; }
.clear-btn { height: 46px; border: 1px solid var(--line); background: var(--paper); color: var(--ink-soft); border-radius: 12px; padding: 0 15px; font-weight: 650; }
.clear-btn:hover { border-color: #9fb3c8; background: #f7fafc; }
.filter-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 13px; }
.field label { display: block; font-size: 11px; font-weight: 700; color: var(--ink-soft); margin: 0 0 6px; }
.field select, .field input { width: 100%; height: 38px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: #fff; padding: 0 10px; outline: none; font-size: 13px; }
.field select:focus, .field input:focus { border-color: var(--teal); }
.multi-select { position: relative; }
.multi-select summary { list-style: none; height: 38px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: #fff; padding: 0 10px; outline: none; font-size: 13px; display: flex; align-items: center; justify-content: space-between; cursor: pointer; }
.multi-select summary::-webkit-details-marker { display: none; }
.multi-select[open] summary { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(15,118,110,.11); }
.multi-select summary span { color: var(--muted); font-size: 16px; line-height: 1; }
.multi-menu { position: absolute; z-index: 8; top: 43px; left: 0; right: 0; max-height: 260px; overflow-y: auto; padding: 7px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 14px 30px rgba(16,42,67,.16); }
.multi-option { display: flex; align-items: center; gap: 8px; padding: 8px 7px; border-radius: 8px; color: var(--ink-soft); font-size: 12px; cursor: pointer; }
.multi-option:hover { background: #f5f9fb; color: var(--ink); }
.multi-option input { width: 15px; height: 15px; accent-color: var(--teal); }
.multi-clear { display: block; border: 0; background: transparent; color: var(--teal); font-size: 11px; font-weight: 800; padding: 5px 7px 8px; }
.multi-clear:hover { text-decoration: underline; }
.toggle-field { display: flex; align-items: end; padding-bottom: 2px; }
.check-label { height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--ink-soft); width: 100%; }
.check-label input { accent-color: var(--teal); width: 15px; height: 15px; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 2px 10px; }
.section-head h2 { font-size: 16px; letter-spacing: -.02em; margin: 0; }
.result-count { font-size: 12px; color: var(--ink-soft); }
.result-count strong { color: var(--ink); }
.table-panel { overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 790px; }
th { padding: 13px 15px; text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); background: #f8fafc; border-bottom: 1px solid var(--line); white-space: nowrap; }
.sort-head { border: 0; background: transparent; padding: 0; color: inherit; text-transform: inherit; letter-spacing: inherit; font-size: inherit; font-weight: 800; display: inline-flex; align-items: center; gap: 6px; }
.sort-head span { font-size: 13px; color: #bcccdc; line-height: 1; }
.sort-head.active { color: var(--teal); }
.sort-head.active span { color: var(--teal); }
td { padding: 14px 15px; border-bottom: 1px solid #edf2f7; font-size: 13px; color: var(--ink-soft); vertical-align: middle; }
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: #f8fbfc; }
tbody tr:last-child td { border-bottom: 0; }
.person-name, .linkish { color: var(--ink); font-weight: 700; }
.person-name { cursor: pointer; }
.person-name:hover, .linkish:hover { color: var(--teal); }
.subtle { font-size: 11px; color: var(--muted); display: block; margin-top: 3px; }
.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 99px; padding: 5px 8px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.green { color: var(--teal); background: var(--teal-soft); }
.badge.amber { color: var(--amber); background: var(--amber-soft); }
.badge.blue { color: #2f6f9f; background: var(--blue-soft); }
.empty { padding: 60px 20px; text-align: center; color: var(--ink-soft); }
.empty-icon { margin: 0 auto 12px; width: 42px; height: 42px; display: grid; place-items: center; border-radius: 14px; color: var(--muted); background: #f1f5f8; font-size: 20px; }
.empty strong { display: block; color: var(--ink); margin-bottom: 4px; }
.empty span { font-size: 13px; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 15px; border-top: 1px solid var(--line); color: var(--ink-soft); font-size: 12px; }
.page-actions { display: flex; gap: 7px; }
.page-btn { width: 32px; height: 30px; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 8px; font-weight: 700; }
.page-btn:disabled { color: #bcccdc; cursor: default; background: #f8fafc; }

.stats-view { padding: 20px; }
.stats-intro { color: var(--ink-soft); font-size: 13px; line-height: 1.5; margin: 0 0 18px; }
.village-list { display: grid; gap: 9px; }
.village-row { display: grid; grid-template-columns: 150px minmax(100px, 1fr) 80px 80px; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid #edf2f7; font-size: 12px; }
.village-row:last-child { border-bottom: 0; }
.village-name { color: var(--ink); font-weight: 700; }
.bar-track { height: 8px; background: #edf2f7; border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: var(--teal); }
.village-num { text-align: right; color: var(--ink-soft); }
.village-num strong { display: block; color: var(--ink); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(16,42,67,.38); z-index: 20; display: flex; justify-content: flex-end; }
.drawer { height: 100%; width: min(600px, 100%); background: var(--paper); box-shadow: -18px 0 60px rgba(16,42,67,.18); overflow-y: auto; animation: slide-in .22s ease-out; }
@keyframes slide-in { from { transform: translateX(30px); opacity: .6; } to { transform: translateX(0); opacity: 1; } }
.drawer-head { padding: 22px 24px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; }
.drawer-kicker { color: var(--teal); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; }
.drawer-title { font-size: 25px; letter-spacing: -.04em; margin: 5px 0 5px; color: var(--ink); }
.drawer-subtitle { color: var(--ink-soft); font-size: 12px; }
.close-btn { flex: 0 0 auto; width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink-soft); font-size: 21px; line-height: 1; }
.close-btn:hover { color: var(--ink); background: #f7fafc; }
.drawer-body { padding: 20px 24px 35px; }
.detail-section { margin-bottom: 25px; }
.detail-section h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 0 0 12px; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 13px 20px; }
.detail-item dt { color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.detail-item dd { margin: 0; font-size: 13px; color: var(--ink); font-weight: 650; line-height: 1.35; word-break: break-word; }
.household-card { border: 1px solid var(--line); border-radius: 13px; padding: 12px; margin-bottom: 8px; display: flex; justify-content: space-between; gap: 14px; align-items: center; }
.household-card strong { font-size: 13px; color: var(--ink); }
.household-card span { color: var(--ink-soft); font-size: 11px; display: block; margin-top: 3px; }
.household-card .head-tag { color: var(--amber); background: var(--amber-soft); border-radius: 99px; padding: 4px 7px; font-size: 10px; font-weight: 800; white-space: nowrap; }
.footer-note { text-align: center; color: var(--muted); font-size: 11px; margin-top: 24px; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar { position: static; display: flex; gap: 7px; padding: 8px; overflow-x: auto; }
  .nav-label, .sidebar-divider, .sidebar-tip { display: none; }
  .nav-btn { width: auto; white-space: nowrap; }
}
@media (max-width: 680px) {
  .topbar-inner, .page { padding-left: 16px; padding-right: 16px; }
  .topbar-inner { padding-top: 16px; padding-bottom: 16px; }
  .topbar-note { display: none; }
  .hero { display: block; }
  .data-note { margin-top: 15px; display: inline-block; }
  .stats { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .stat { padding: 14px; }
  .stat-value { font-size: 24px; }
  .search-panel { padding: 13px; }
  .search-row { display: block; }
  .clear-btn { width: 100%; margin-top: 8px; }
  .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-head { align-items: flex-start; flex-direction: column; gap: 5px; }
  .pagination { align-items: flex-start; flex-direction: column; }
  .stats-view { padding: 15px; }
  .village-row { grid-template-columns: 1fr 64px 64px; gap: 8px; }
  .village-row .bar-track { grid-column: 1 / -1; grid-row: 2; }
  .drawer-head, .drawer-body { padding-left: 18px; padding-right: 18px; }
}
