/* ===========================================================
   Design tokens
   =========================================================== */
:root {
  --navy-900: #061226;
  --navy-800: #0a1f3d;
  --navy-700: #0b2545;
  --navy-600: #13315c;
  --navy-500: #1d4079;
  --navy-400: #2e5588;
  --navy-300: #5474a3;
  --navy-200: #b6cce6;
  --navy-100: #d8e3f1;
  --navy-50:  #eef3fb;

  --gold-700: #9a6e1f;
  --gold-600: #b8862c;
  --gold-500: #d4a464;
  --gold-400: #e8c389;
  --gold-300: #f0d4a7;
  --gold-100: #fbf0db;

  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-alt: #fafbfd;
  --surface-strong: #f0f3f9;
  --border: #e3e8f0;
  --border-strong: #cbd5e1;
  --text: #0b1426;
  --text-2: #1f2937;
  --text-muted: #5a6478;
  --text-light: #94a0b6;
  --text-on-navy: #f5ebd7;

  --danger: #c53030;
  --success: #2f855a;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(11, 37, 69, 0.06);
  --shadow: 0 4px 14px -4px rgba(11, 37, 69, 0.12), 0 2px 4px -2px rgba(11, 37, 69, 0.04);
  --shadow-lg: 0 18px 38px -12px rgba(11, 37, 69, 0.22), 0 6px 12px -6px rgba(11, 37, 69, 0.08);
  --shadow-pop: 0 10px 25px -5px rgba(11, 37, 69, 0.18);

  --font-sans: 'Sarabun', 'Noto Sans Thai', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-display: 'IBM Plex Sans Thai', 'Sarabun', sans-serif;
  --font-num: 'IBM Plex Sans', system-ui, sans-serif;

  --header-h: 60px;
  --crumb-h: 48px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}
body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
#root { height: 100%; display: flex; flex-direction: column; }
a { color: var(--navy-500); text-decoration: none; }
a:hover { color: var(--navy-700); }
button { font-family: inherit; }
img { display: block; max-width: 100%; }

.boot {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100vh; gap: 14px; color: var(--text-muted);
}
.boot img { opacity: 0.85; filter: drop-shadow(0 4px 12px rgba(11,37,69,0.15)); }

/* ===========================================================
   App shell
   =========================================================== */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 18px;
  height: var(--header-h);
  padding: 0 20px;
  background: linear-gradient(180deg, var(--navy-700) 0%, var(--navy-800) 100%);
  color: #fff;
  z-index: 1400;   /* above Leaflet controls (1000) so the mobile menu overlays the map */
  position: relative;
  box-shadow: 0 2px 12px rgba(6, 18, 38, 0.20);
}
.brand {
  display: flex; align-items: center; gap: 12px;
  color: #fff;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.1px;
}
.brand:hover { color: #fff; }
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 50%;
  background-image: url('/static/assets/logo-128.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.25));
}
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text strong { font-size: 17px; font-weight: 600; }
.brand-text span { font-size: 11px; opacity: 0.72; letter-spacing: 1.5px; text-transform: uppercase; font-weight: 500; }

.header-divider {
  width: 1px; height: 30px;
  background: rgba(255,255,255,0.18);
}

.breadcrumb {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.88);
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}
.breadcrumb a {
  color: rgba(255, 255, 255, 0.78);
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 6px;
  transition: background 0.15s;
}
.breadcrumb a:hover { background: rgba(255,255,255,0.10); color: #fff; }
.breadcrumb .sep { color: rgba(255,255,255,0.35); font-size: 12px; }
.breadcrumb .current { color: var(--gold-300); font-weight: 600; padding: 4px 0; }

.header-spacer { flex: 1; }

.header-actions { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--gold-500);
  color: var(--navy-800);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 14px;
  text-transform: uppercase;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-ghost-light {
  border-color: rgba(255,255,255,0.20);
  color: rgba(255,255,255,0.92);
}
.btn-ghost-light:hover { background: rgba(255,255,255,0.10); border-color: rgba(255,255,255,0.35); }
.btn-ghost {
  border-color: var(--border);
  color: var(--text-2);
  background: var(--surface);
}
.btn-ghost:hover { border-color: var(--navy-300); color: var(--navy-700); }
.btn-primary {
  background: var(--navy-700);
  color: #fff;
  border-color: var(--navy-700);
}
.btn-primary:hover { background: var(--navy-600); border-color: var(--navy-600); }
.btn-sm { height: 30px; font-size: 13px; padding: 0 10px; }

/* ===========================================================
   Layout: full map + bottom dock (home)
   =========================================================== */
.app-main { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
.map-wrap { flex: 1; min-height: 0; position: relative; }
.leaflet-container {
  width: 100%; height: 100%;
  background: #eef2f7;
  font-family: var(--font-sans);
}

/* Floating stats card on national map */
.stats-card {
  position: absolute;
  top: 16px; right: 16px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 18px 22px;
  z-index: 500;
  min-width: 240px;
  border: 1px solid var(--border);
}
.stats-card h2 {
  margin: 0 0 12px;
  font-size: 13px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
}
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.stat {
  display: flex; flex-direction: column; gap: 2px;
}
.stat-value {
  font-family: var(--font-num);
  font-size: 24px;
  font-weight: 700;
  color: var(--navy-700);
  letter-spacing: -0.5px;
}
.stat-label {
  font-size: 12px;
  color: var(--text-muted);
}
.stat-large .stat-value { font-size: 32px; }

/* Bottom legend dock */
.legend-dock {
  background: linear-gradient(180deg, rgba(255,255,255,0.97), #fff);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(11,37,69,0.06);
  padding: 12px 20px;
  z-index: 600;
}
.legend-row {
  display: flex; align-items: center; gap: 18px;
  flex-wrap: wrap;
}
.legend-total {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  font-weight: 500;
}
.legend-total b {
  font-family: var(--font-num);
  font-size: 22px;
  font-weight: 700;
  color: var(--navy-700);
}
.legend-divider {
  width: 1px; height: 28px; background: var(--border);
}
.legend-items {
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  flex: 1;
}
.legend-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px;
  color: var(--text-2);
  padding: 2px 0;
  white-space: nowrap;
  cursor: default;
}
.legend-chip .dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.08);
}

/* ===========================================================
   Layout: split (province / district detail)
   =========================================================== */
.split {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(440px, 620px);
}
.split-map {
  position: relative;
  border-right: 1px solid var(--border);
  background: #eef2f7;
}
.split-panel {
  background: var(--surface);
  display: flex; flex-direction: column;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.panel-head {
  padding: 18px 22px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
}
.panel-head h1 {
  font-family: var(--font-display);
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 600;
  color: var(--navy-800);
  letter-spacing: -0.2px;
}
.panel-head .subtitle {
  display: flex; align-items: center; gap: 10px;
  color: var(--text-muted);
  font-size: 13px;
}
.panel-head .pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--navy-50);
  color: var(--navy-700);
  font-weight: 600;
  font-size: 12px;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
}
.metric {
  background: var(--surface);
  padding: 14px 18px;
  display: flex; flex-direction: column; gap: 2px;
}
.metric .v {
  font-family: var(--font-num);
  font-size: 22px;
  font-weight: 700;
  color: var(--navy-700);
  letter-spacing: -0.3px;
}
.metric .l {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  font-weight: 600;
}

/* Mass group breakdown inside panel — fills remaining space, scrolls internally */
.mg-summary {
  padding: 14px 22px 14px;
  border-bottom: 1px solid var(--border);
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.mg-summary::-webkit-scrollbar { width: 8px; }
.mg-summary::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.mg-summary-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
  gap: 10px;
  flex-shrink: 0;
}
.mg-summary h3 {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 700;
  color: var(--text-muted);
}
.mg-bars { display: flex; flex-direction: column; gap: 7px; }
.mg-bar {
  display: grid; grid-template-columns: 170px 1fr 40px; gap: 12px;
  align-items: center;
  font-size: 12.5px;
}
.mg-bar .name {
  color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-weight: 500;
}
.mg-bar .track {
  display: block;
  background: var(--surface-strong);
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}
.mg-bar .fill {
  display: block;
  height: 100%;
  min-width: 4px;
  border-radius: 999px;
  transition: width 0.4s ease;
}
.mg-bar .num {
  font-family: var(--font-num);
  text-align: right;
  font-weight: 600;
  color: var(--navy-700);
}

/* ===========================================================
   Filters
   =========================================================== */
.filters {
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 10px;
}
.filter-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.filter-grid.with-search { grid-template-columns: 1fr 1fr 1fr 1.3fr; }
.field {
  display: flex; flex-direction: column; gap: 4px;
}
.field label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.input, .select {
  height: 36px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 0 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}
.input:focus, .select:focus {
  border-color: var(--navy-400);
  box-shadow: 0 0 0 3px rgba(46, 85, 136, 0.15);
}
.search {
  position: relative;
}
.search .input {
  padding-left: 36px;
  font-size: 14px;
  font-weight: 500;
  height: 40px;
}
.search .input::placeholder { font-weight: 400; color: var(--text-light); }
.search .icon {
  position: absolute;
  left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  font-size: 16px;
  font-weight: 600;
}

.filter-actions {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.col-toggles {
  display: flex; align-items: center; gap: 14px;
  font-size: 13px;
  color: var(--text-muted);
}
.col-toggles label {
  display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer;
  user-select: none;
}
.col-toggles input { accent-color: var(--navy-500); }

/* ===========================================================
   Table
   =========================================================== */
.table-wrap {
  flex: 1; min-height: 0;
  overflow: auto;
  background: var(--surface);
}
.table-meta {
  padding: 10px 22px;
  font-size: 13px;
  color: var(--text-muted);
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
table.people {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  background: var(--surface);
}
table.people thead {
  position: sticky; top: 40px; z-index: 4;
  background: var(--surface);
}
table.people th {
  text-align: left;
  font-weight: 700;
  font-size: 11.5px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 9px 10px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.people td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  color: var(--text-2);
  font-size: 13px;
}
table.people td:nth-child(3) { font-weight: 600; color: var(--text); white-space: nowrap; }
table.people tbody tr { transition: background 0.10s; }
table.people tbody tr:hover { background: var(--surface-strong); }
table.people td.num {
  font-family: var(--font-num);
  font-weight: 500;
  color: var(--text-muted);
  text-align: right;
}
table.people td.code {
  font-family: var(--font-num);
  font-weight: 600;
  color: var(--navy-700);
}
.mg-tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px;
  white-space: nowrap;
}
.mg-tag .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.06);
}
.agency {
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
}

.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
}
.empty svg { opacity: 0.4; margin-bottom: 12px; }

/* ===========================================================
   Loaders & states
   =========================================================== */
.spinner {
  width: 18px; height: 18px;
  border: 2.5px solid var(--navy-100);
  border-top-color: var(--navy-500);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: absolute; inset: 0;
  background: rgba(244, 246, 250, 0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 800;
  pointer-events: none;
}

/* ===========================================================
   Map tooltip + interactions
   =========================================================== */
.map-tip {
  background: var(--navy-800);
  color: #fff;
  border: none;
  box-shadow: var(--shadow-pop);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-family: var(--font-sans);
  font-weight: 500;
}
.map-tip strong { font-weight: 700; color: var(--gold-300); }
.map-tip .v {
  font-family: var(--font-num);
  font-size: 16px;
  font-weight: 700;
  display: block;
  margin-top: 2px;
}
.map-tip::before { border-top-color: var(--navy-800) !important; }
.leaflet-tooltip-top.map-tip::before { border-top-color: var(--navy-800); }

.leaflet-control-zoom a {
  background: var(--surface);
  color: var(--navy-700);
  border-color: var(--border-strong) !important;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
.leaflet-control-zoom a:hover { background: var(--navy-50); color: var(--navy-800); }
.leaflet-control-attribution {
  background: rgba(255,255,255,0.85) !important;
  font-size: 11px !important;
  color: var(--text-muted) !important;
}
.leaflet-control-attribution a { color: var(--navy-500) !important; }

/* Map scale legend (choropleth) */
.scale-legend {
  position: absolute;
  bottom: 24px; left: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 500;
  border: 1px solid var(--border);
  font-size: 12px;
  overflow: hidden;
}
.scale-legend .lg-title {
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}
.scale-legend .lg-body { padding: 0 14px 10px; }
.scale-bar {
  display: flex;
  height: 10px;
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.scale-bar span { flex: 1; }
.scale-labels {
  display: flex; justify-content: space-between;
  margin-top: 4px;
  font-family: var(--font-num);
  font-size: 11px;
  color: var(--text-muted);
}

/* Back link */
.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  color: rgba(255,255,255,0.86);
  font-weight: 500;
  padding: 4px 10px 4px 8px;
  border-radius: 6px;
  font-size: 14px;
}
.back-link:hover { color: #fff; background: rgba(255,255,255,0.10); }
.back-link::before { content: "←"; font-size: 16px; }

/* ===========================================================
   Home: dashboard sidebar + map layout
   =========================================================== */
.home-layout {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
}

.home-dashboard {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex; flex-direction: column;
  scrollbar-width: thin;
}
.home-dashboard::-webkit-scrollbar { width: 8px; }
.home-dashboard::-webkit-scrollbar-track { background: transparent; }
.home-dashboard::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.home-layout .map-wrap { position: relative; }
.home-layout + .legend-dock { display: none; }

/* Panel sections (reused inside dashboard) */
.panel-section {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0; /* prevent flex column from collapsing rich sections */
}
.panel-section:last-of-type { border-bottom: none; }

.sec-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
  gap: 10px;
}
.sec-head h3 {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.sec-meta {
  font-size: 11.5px;
  color: var(--text-light);
  font-family: var(--font-num);
  white-space: nowrap;
}

/* Hero stat block */
.hero {
  background:
    radial-gradient(circle at 88% 18%, rgba(212, 164, 100, 0.20), transparent 55%),
    linear-gradient(165deg, var(--navy-700) 0%, var(--navy-600) 100%);
  color: #fff;
  padding: 22px 22px 18px;
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid rgba(0,0,0,0.20);
}
.hero-eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--gold-300);
  font-weight: 600;
  margin-bottom: 4px;
}
.hero-num {
  font-family: var(--font-num);
  font-size: 44px;
  font-weight: 700;
  letter-spacing: -1.5px;
  line-height: 1;
  color: #fff;
}
.hero-cap {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.78);
  margin-top: 6px;
}
.hero-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1px;
  margin-top: 16px;
  background: rgba(255, 255, 255, 0.10);
  border-radius: 10px;
  overflow: hidden;
}
.mini {
  background: rgba(255, 255, 255, 0.06);
  padding: 10px 6px 8px;
  display: flex; flex-direction: column; align-items: center;
  gap: 2px;
  transition: background 0.15s;
}
.mini:hover { background: rgba(255, 255, 255, 0.12); }
.mini .v {
  font-family: var(--font-num);
  font-size: 18px;
  font-weight: 700;
  color: var(--gold-300);
  letter-spacing: -0.4px;
}
.mini .l {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.72);
}

/* Search */
.search-wrap {
  position: relative;
}
.search-wrap .icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  font-size: 18px;
  font-weight: 600;
}
.search-wrap .input {
  height: 46px;
  padding-left: 40px;
  padding-right: 14px;
  font-size: 15px;
  font-weight: 500;
  background: var(--surface-alt);
  border-color: var(--border-strong);
}
.search-wrap .input::placeholder {
  font-size: 14px;
  font-weight: 400;
  color: var(--text-light);
}
.search-wrap .input:focus {
  background: var(--surface);
  border-color: var(--navy-500);
  box-shadow: 0 0 0 3px rgba(46, 85, 136, 0.18);
}

/* Region pills */
.pill-row {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.pill {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  height: 28px;
  padding: 0 13px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
  font-family: inherit;
  white-space: nowrap;
}
.pill:hover {
  border-color: var(--navy-400);
  color: var(--navy-700);
  background: var(--navy-50);
}
.pill.active {
  background: var(--navy-700);
  color: #fff;
  border-color: var(--navy-700);
}

/* Top provinces list */
.top-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex; flex-direction: column; gap: 2px;
}
.top-item {
  display: grid;
  grid-template-columns: 22px 1fr 70px 50px;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s;
}
.top-item:hover {
  background: var(--surface-strong);
}
.top-item .rank {
  font-family: var(--font-num);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-light);
  text-align: center;
}
.top-item:hover .rank { color: var(--gold-600); }
.top-item .name {
  font-size: 13.5px;
  color: var(--text-2);
  font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.top-item .bar {
  height: 6px;
  background: var(--navy-50);
  border-radius: 999px;
  overflow: hidden;
}
.top-item .bar .fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--navy-400), var(--navy-700));
  border-radius: 999px;
}
.top-item .count {
  font-family: var(--font-num);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--navy-700);
  text-align: right;
}

/* Mass groups panel (dashboard) — renders .mg-bars, styled with the detail panels */
.mg-section { padding-bottom: 30px; }

/* ===========================================================
   Panel footer (sticky CTA button at bottom of detail panel)
   =========================================================== */
.panel-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 -4px 14px -8px rgba(11, 37, 69, 0.10);
  flex-shrink: 0;
}
.btn-cta {
  width: 100%;
  height: 52px;
  padding: 0 20px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--navy-600) 0%, var(--navy-700) 100%);
  border: 1px solid var(--navy-700);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 4px 12px -2px rgba(11, 37, 69, 0.25);
  transition: all 0.15s;
  cursor: pointer;
}
.btn-cta:hover {
  background: linear-gradient(180deg, var(--navy-500) 0%, var(--navy-600) 100%);
  box-shadow: 0 6px 18px -2px rgba(11, 37, 69, 0.35);
  transform: translateY(-1px);
}
.btn-cta:active { transform: translateY(0); }
.btn-cta .cta-meta {
  margin-left: auto;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-num);
  color: var(--gold-300);
  background: rgba(255, 255, 255, 0.10);
  padding: 3px 10px;
  border-radius: 999px;
}
.btn-cta .cta-arrow {
  font-size: 18px;
  font-weight: 700;
  color: var(--gold-300);
  transition: transform 0.15s;
}
.btn-cta:hover .cta-arrow { transform: translateX(3px); }

/* Name cell two-line layout (composed name + AAA code beneath) */
td.name-cell { white-space: nowrap; }
.name-main {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text);
}
.name-sub {
  font-family: var(--font-num);
  font-size: 11px;
  color: var(--text-light);
  letter-spacing: 0.3px;
  margin-top: 1px;
}

/* ===========================================================
   Full-screen table modal
   =========================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 18, 38, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  animation: modalIn 0.18s ease-out;
}
.modal-backdrop.closing { animation: modalOut 0.15s ease-in forwards; }

@keyframes modalIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes modalOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 96vw;
  max-width: 1600px;
  height: 94vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalSlide 0.22s ease-out;
}
@keyframes modalSlide {
  from { transform: translateY(12px); opacity: 0.7; }
  to   { transform: translateY(0);     opacity: 1; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 26px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
  flex-shrink: 0;
}
.modal-title-wrap { min-width: 0; }
.modal-head h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  font-family: var(--font-display);
  color: var(--navy-800);
  letter-spacing: -0.2px;
}
.modal-meta {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 3px;
}
.modal-close {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text-muted);
  font-family: inherit;
  font-weight: 600;
  transition: all 0.12s;
  flex-shrink: 0;
}
.modal-close:hover {
  background: var(--surface-strong);
  color: var(--text);
  border-color: var(--text-light);
}

/* Modal-internal table styling overrides for full-width comfort */
.modal .filters {
  padding: 18px 26px;
}
.modal .filter-grid,
.modal .filter-grid.with-search {
  grid-template-columns: 1fr 1fr 1fr 1.6fr;
  gap: 14px;
}
.modal .filter-grid .input,
.modal .filter-grid .select,
.modal .filter-grid .search .input {
  height: 44px;
  font-size: 15px;
}
.modal .filter-grid .field label { font-size: 12px; }

.modal .table-meta {
  padding: 12px 26px;
  font-size: 14px;
}
.modal .table-wrap { flex: 1; min-height: 0; }
.modal table.people { font-size: 14.5px; }
.modal table.people th {
  font-size: 12px;
  padding: 12px 14px;
}
.modal table.people td {
  padding: 12px 14px;
  font-size: 14px;
}
.modal table.people .name-main { font-size: 15px; }
.modal table.people .name-sub  { font-size: 12px; }
.modal table.people thead { top: 0; }

/* ===========================================================
   Responsive
   =========================================================== */
@media (max-width: 1180px) {
  .home-layout { grid-template-columns: 320px minmax(0, 1fr); }
}
@media (max-width: 1080px) {
  .split { grid-template-columns: 1fr 1fr; }
  .filter-grid.with-search { grid-template-columns: 1fr 1fr; }
  .metric-row { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .home-layout { grid-template-columns: 1fr; grid-template-rows: auto 50vh; }
  .home-dashboard { border-right: none; border-bottom: 1px solid var(--border); max-height: 50vh; }
  .split { grid-template-columns: 1fr; grid-template-rows: 40vh 1fr; }
  .split-map { border-right: none; border-bottom: 1px solid var(--border); }
  .brand-text span { display: none; }
  .brand-text strong { font-size: 14px; }
  .stats-card { left: 16px; right: 16px; min-width: auto; }
  .legend-items { font-size: 11px; }
  .filter-grid, .filter-grid.with-search { grid-template-columns: 1fr 1fr; }
}

/* ===========================================================
   Auth + admin console (added for user management & editing)
   =========================================================== */

/* --- login screen --- */
.login-screen {
  position: relative; min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; overflow: hidden;
  background: linear-gradient(150deg, #0a1f3d 0%, #0b2545 45%, #13315c 100%);
}
/* animated network of nodes drawn by app.js */
.login-bg { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; display: block; }
/* soft drifting glow orbs (navy + gold) */
.login-screen::before, .login-screen::after {
  content: ''; position: absolute; border-radius: 50%; filter: blur(80px);
  pointer-events: none; z-index: 0;
}
.login-screen::before {
  width: 520px; height: 520px; top: -170px; left: -120px; opacity: .5;
  background: radial-gradient(circle, rgba(212,164,100,.5), transparent 70%);
  animation: orbA 17s ease-in-out infinite;
}
.login-screen::after {
  width: 580px; height: 580px; bottom: -200px; right: -150px; opacity: .55;
  background: radial-gradient(circle, rgba(46,85,136,.7), transparent 70%);
  animation: orbB 21s ease-in-out infinite;
}
@keyframes orbA { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(70px, 50px); } }
@keyframes orbB { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(-60px, -40px); } }

.login-card {
  position: relative; z-index: 2;
  width: 100%; max-width: 384px; background: var(--surface);
  border: 1px solid rgba(255,255,255,0.5); border-radius: var(--radius-lg);
  box-shadow: 0 30px 70px -20px rgba(3, 12, 28, 0.6), 0 8px 24px -12px rgba(3, 12, 28, 0.5);
  padding: 34px 30px; display: flex; flex-direction: column; gap: 14px; text-align: center;
  animation: cardIn 0.55s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
@keyframes cardIn { from { opacity: 0; transform: translateY(18px) scale(0.98); } to { opacity: 1; transform: none; } }
.login-logo { align-self: center; animation: logoFloat 4.5s ease-in-out infinite; }
@keyframes logoFloat { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.login-card h1 { font-family: var(--font-display); font-size: 19px; margin: 4px 0 0; color: var(--navy-700); }
.login-sub { margin: 0 0 8px; color: var(--text-muted); font-size: 13px; letter-spacing: .03em; }
.login-card .fld { text-align: left; }
.login-card .btn-primary { margin-top: 6px; height: 42px; font-size: 15px; }
.login-err { color: var(--danger); font-size: 13px; min-height: 18px; }

/* password field show/hide eye toggle */
.pw-wrap { position: relative; display: flex; align-items: center; }
.pw-wrap .input { flex: 1; padding-right: 38px; }
.pw-eye {
  position: absolute; right: 5px; top: 50%; transform: translateY(-50%);
  display: flex; align-items: center; justify-content: center;
  border: none; background: transparent; cursor: pointer;
  color: var(--text-light); padding: 6px; border-radius: 6px;
}
.pw-eye:hover { color: var(--navy-500); background: var(--surface-strong); }
.pw-eye svg { display: block; }

/* --- header nav + user chip --- */
.header-nav { display: flex; gap: 4px; align-items: center; margin-right: 6px; }
.hnav {
  color: var(--text-on-navy); opacity: .82; text-decoration: none;
  font-size: 13.5px; padding: 6px 10px; border-radius: 7px; white-space: nowrap;
}
/* keep the cream text on every interactive state — otherwise the global
   `a:hover{color:navy}` (more specific than .hnav) turns it dark-on-navy = invisible */
.hnav:hover,
.hnav:focus-visible { opacity: 1; background: rgba(255,255,255,.16); color: var(--text-on-navy); }
.hnav:focus-visible { outline: 2px solid rgba(245,235,215,.55); outline-offset: 1px; }
.hnav:active { opacity: 1; background: rgba(255,255,255,.24); color: var(--text-on-navy); }
.user-meta { display: flex; flex-direction: column; line-height: 1.15; margin: 0 4px 0 2px; }
.user-meta strong { color: var(--text-on-navy); font-size: 13px; font-weight: 600; }
.role-badge {
  font-size: 10.5px; color: var(--text-muted); background: var(--surface-strong);
  border: 1px solid var(--border); border-radius: 20px; padding: 1px 8px; width: fit-content;
}
.role-badge.admin { color: var(--gold-700); background: var(--gold-100); border-color: var(--gold-300); }

/* --- toast --- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 16px);
  background: var(--navy-800); color: #fff; padding: 11px 18px; border-radius: 10px;
  box-shadow: var(--shadow-lg); z-index: 9999; opacity: 0; transition: all .25s ease;
  font-size: 14px; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-err { background: var(--danger); }
.toast-ok { background: var(--success); }

/* --- form modal variants (override the full-screen base) --- */
.modal.modal-form { width: min(620px, 94vw); height: auto; max-height: 92vh; }
.modal.modal-wide { width: min(900px, 96vw); height: auto; max-height: 92vh; }
.modal-body { padding: 20px 22px; overflow: auto; }
.modal-foot {
  display: flex; gap: 10px; align-items: center; justify-content: flex-end;
  padding: 14px 22px; border-top: 1px solid var(--border); background: var(--surface-alt);
}
.modal-foot .spacer { flex: 1; }

/* --- forms --- */
.fld { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.fld > label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.fld.grow { flex: 1; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid.one { grid-template-columns: 1fr; }
.form-grid textarea.input, .person-edit > .fld textarea.input { resize: vertical; font-family: inherit; }
.color-input { width: 56px; height: 36px; padding: 2px; border: 1px solid var(--border-strong); border-radius: 8px; background: #fff; }
.acct-info { display: flex; align-items: center; gap: 10px; padding-bottom: 6px; }

/* --- danger button --- */
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #a52323; }
.btn-ghost.btn-danger, .btn-danger.btn-sm { }

/* --- photo thumbnails --- */
.pthumb {
  width: 34px; height: 34px; border-radius: 8px; object-fit: cover; flex: 0 0 auto;
  background: var(--surface-strong); border: 1px solid var(--border);
}
.pthumb-ph {
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--navy-300); font-weight: 700; font-size: 14px; text-transform: uppercase;
}
.name-flex { display: flex; align-items: center; gap: 10px; }
.name-text { min-width: 0; }

/* --- person view modal --- */
.person-view { display: flex; gap: 20px; }
.person-photo { flex: 0 0 160px; }
.person-photo img, .person-photo .photo-ph {
  width: 160px; height: 200px; object-fit: cover; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-strong);
}
.photo-ph { display: flex; align-items: center; justify-content: center; font-size: 56px; font-weight: 700; color: var(--navy-200); }
.person-info { flex: 1; min-width: 0; }
.person-info h3 { margin: 0 0 12px; font-family: var(--font-display); font-size: 18px; color: var(--navy-700); }
.dl { display: grid; grid-template-columns: minmax(110px, auto) 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.dl dt { color: var(--text-muted); font-weight: 600; }
.dl dd { margin: 0; color: var(--text-2); word-break: break-word; }

/* --- person edit modal --- */
.person-edit { display: flex; flex-direction: column; gap: 14px; }
.edit-photo { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.edit-photo img, .edit-photo .photo-ph { width: 110px; height: 138px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-strong); }
.edit-photo .photo-ph { font-size: 40px; }
.photo-actions { display: flex; gap: 8px; }
.hint { font-size: 12px; color: var(--text-light); }

/* --- admin pages --- */
.admin-page { max-width: 1280px; margin: 0 auto; padding: 18px 26px 16px; width: 100%; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.admin-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.admin-head h1 { font-family: var(--font-display); font-size: 24px; color: var(--navy-700); margin: 0; }
.admin-filters { display: flex; gap: 12px; align-items: flex-end; margin-bottom: 14px; flex-wrap: wrap; }
.admin-filters .fld { min-width: 170px; }
.admin-filters .fld.grow { flex: 1; min-width: 220px; }
.admin-filters .search { display: flex; align-items: center; gap: 6px; }
.admin-filters .search .input { flex: 1; }
.admin-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: auto; flex: 1; min-height: 0; }
.admin-table { width: 100%; }
.admin-table td { vertical-align: middle; }
.admin-table .row-actions { display: flex; gap: 6px; justify-content: flex-end; white-space: nowrap; }
.prow { cursor: pointer; }
.prow:hover { background: var(--navy-50); }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 14px; color: var(--text-muted); font-size: 13px; }
.swatch { display: inline-block; width: 13px; height: 13px; border-radius: 4px; margin-right: 8px; vertical-align: middle; border: 1px solid rgba(0,0,0,.1); }
.ok-tag { color: var(--success); font-weight: 600; font-size: 13px; }
.off-tag { color: var(--text-light); font-size: 13px; }
.table-meta { display: flex; justify-content: space-between; padding: 10px 14px; color: var(--text-muted); font-size: 13px; border-bottom: 1px solid var(--border); }

@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  .person-view { flex-direction: column; }
  .person-photo { flex: none; }
  .header-nav { display: none; }
  .user-meta { display: none; }
}

/* --- grouping dimension toggle (ภาค / กองทัพภาค) on the national view --- */
.dim-toggle { display: inline-flex; gap: 2px; padding: 3px; margin-bottom: 10px;
  background: var(--surface-strong); border: 1px solid var(--border); border-radius: 9px; }
.dim-toggle .seg { border: none; background: transparent; cursor: pointer;
  font-family: var(--font-sans); font-size: 13px; color: var(--text-muted);
  padding: 5px 14px; border-radius: 7px; }
.dim-toggle .seg:hover { color: var(--text); }
.dim-toggle .seg.active { background: var(--surface); color: var(--navy-700);
  font-weight: 600; box-shadow: var(--shadow-sm); }

/* --- admin list: fill height, scroll body, pinned pager + meta --- */
.admin-head .head-actions { display: flex; gap: 10px; }
.admin-meta-bar { display: flex; justify-content: space-between; align-items: baseline; padding: 2px 2px 10px; color: var(--text-muted); font-size: 13px; }
.admin-list table.people thead { top: 0; }     /* beat base 'table.people thead { top:40px }' on specificity */
.admin-pager {
  display: flex; align-items: center; justify-content: center; gap: 16px;
  padding: 10px; margin-top: 10px; color: var(--text-muted); font-size: 13px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm);
}

/* --- Excel import modal --- */
.import-modal { display: flex; flex-direction: column; gap: 14px; }
.import-intro { margin: 0; color: var(--text-muted); font-size: 13.5px; line-height: 1.6; }
.import-cols summary { cursor: pointer; color: var(--navy-500); font-size: 13px; font-weight: 600; padding: 4px 0; }
.import-help { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 13px; }
.import-help td { padding: 5px 10px; border-bottom: 1px solid var(--border); }
.import-help td.req { color: var(--danger); font-weight: 600; white-space: nowrap; }
.import-help td.opt { color: var(--text-light); white-space: nowrap; }
.import-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px; background: var(--surface-strong); border-radius: var(--radius); }
.import-file { color: var(--text-muted); font-size: 13px; }
.import-report:empty { display: none; }
.import-report { display: flex; flex-direction: column; gap: 10px; }
.import-ok { color: var(--success); font-weight: 600; }
.import-bad { color: var(--danger); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chips-label { font-size: 12px; color: var(--text-muted); margin-right: 4px; }
.chip { font-size: 12px; padding: 2px 9px; border-radius: 20px; border: 1px solid var(--border); }
.chip-ok { background: #eaf6ee; color: var(--success); border-color: #cce9d6; }
.chip-warn { background: #fdf3e7; color: var(--gold-700); border-color: #f0dcc0; }
.import-preview { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.prev-title { padding: 8px 12px; background: var(--surface-alt); font-size: 12px; font-weight: 600; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.import-preview table.people { font-size: 13px; }
.import-preview thead { position: static; }
.import-preview td { padding: 7px 12px; }

/* sticky table headers must not intercept clicks on the row beneath them */
table.people thead { pointer-events: none; }

/* ---- Group-density dots on the province (district) map ---- */
.gd-cluster { background: none; border: 0; }
.gd-cluster-inner {
  display: flex; align-items: center; gap: 2px;
  transform: translate(-50%, -50%);   /* centre the cluster on the district point */
  white-space: nowrap;
}
.gd-dot {
  display: inline-block; border-radius: 50%;
  border: 1.5px solid #fff; flex: 0 0 auto;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}
.gd-legend {
  position: absolute; top: 16px; right: 16px; z-index: 500;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  font-size: 12px; max-width: 230px; overflow: hidden;
}
.gd-legend .lg-body { max-height: 38vh; overflow-y: auto; padding: 0 11px 9px; }

/* collapsible map panel header (tap the title to fold the panel away) */
.lg-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; border: 0; background: transparent; cursor: pointer;
  font: 700 11px var(--font-sans); color: var(--text);
  padding: 8px 11px; text-align: left;
}
.lg-head:hover { background: var(--surface-strong); }
.lg-chev { color: var(--text-light); font-size: 10px; flex: 0 0 auto; }
.gd-legend-item {
  display: flex; align-items: center; gap: 7px; width: 100%;
  background: none; border: 0; padding: 3px 2px; cursor: pointer;
  text-align: left; color: var(--text); border-radius: 6px; font: inherit;
}
.gd-legend-item:hover { background: rgba(11, 37, 69, 0.06); }
.gd-legend-item.off { opacity: 0.4; text-decoration: line-through; }
.gd-legend-dot { width: 11px; height: 11px; border-radius: 50%; flex: 0 0 auto; border: 1px solid rgba(0, 0, 0, 0.1); }
.gd-legend-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gd-legend-num { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.gd-legend-note { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 11px; }

/* ---- home_data.pptx slide viewer (lightbox) ---- */
/* Near-fullscreen fixed box; the body flexes to fill and the image is CONTAIN-fit
   so the whole slide always shows (no crop) and as large as the viewport allows. */
.modal.modal-wide:has(.slide-viewer) { width: min(1600px, 97vw); height: 94vh; max-height: 94vh; }
.modal-body:has(.slide-viewer) { flex: 1 1 auto; min-height: 0; display: flex; padding: 12px 14px; overflow: hidden; }
.slide-viewer {
  position: relative; flex: 1 1 auto; min-height: 0; width: 100%;
  display: flex; align-items: center; justify-content: center;
  background: #0b1220; border-radius: 8px;
}
.slide-img { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; display: block; border-radius: 6px; }
.slide-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: rgba(255, 255, 255, 0.92); color: #0b2545;
  font-size: 28px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}
.slide-nav:hover { background: #fff; }
.slide-nav.prev { left: 12px; }
.slide-nav.next { right: 12px; }
.slide-counter { color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 13px; }

/* ===========================================================
   สรุปมวลชน — full-page editable summary matrix (#/summary)
   =========================================================== */
/* .app is overflow:hidden — this page provides its own vertical scroll */
.summary-page { padding: 18px 22px 28px; width: 100%; flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; }
.summary-page .admin-head { margin-bottom: 4px; }
.summary-hint { color: var(--text-muted); font-size: 13px; margin: 0 0 14px; }
.summary-legend { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.summary-section { margin-bottom: 30px; }
.summary-title {
  font-family: var(--font-display); font-size: 15.5px; font-weight: 700;
  color: #fff; background: #2f8547; margin: 0;
  padding: 9px 14px; border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.summary-scroll {
  overflow-x: auto; background: var(--surface);
  border: 1px solid var(--border-strong); border-top: 0;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

table.sumtbl { border-collapse: separate; border-spacing: 0; font-size: 12.5px; width: max-content; min-width: 100%; }
.sumtbl th, .sumtbl td {
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  padding: 5px 8px; vertical-align: middle;
}
.sumtbl thead th {
  font-weight: 600; text-align: center; font-size: 12px; line-height: 1.35;
  background: var(--surface-strong); color: var(--text-2);
  max-width: 130px; min-width: 62px;
}
.sumtbl thead .sc-hdr { font-weight: 700; }
.sumtbl thead .sc-leaf { font-weight: 500; font-size: 11.5px; }
.sumtbl tbody td { background: var(--surface); white-space: nowrap; }
.sumtbl td.num { text-align: right; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.sumtbl .col-idx { text-align: center; min-width: 42px; position: sticky; left: 0; z-index: 2; }
.sumtbl .col-unit { min-width: 150px; font-weight: 600; white-space: nowrap; position: sticky; left: 42px; z-index: 2; }
.sumtbl thead .col-idx, .sumtbl thead .col-unit { z-index: 3; }
.sumtbl tbody .col-idx, .sumtbl tbody .col-unit { background: var(--surface-alt); }
.sumtbl .col-idx, .sumtbl .col-unit { box-shadow: 1px 0 0 var(--border); }
.sumtbl .col-status { min-width: 128px; text-align: center; }
.status-pill {
  display: inline-block; font-size: 11.5px; font-weight: 600;
  padding: 2px 9px; border-radius: 999px; border: 1px solid transparent; white-space: nowrap;
}
.sumtbl td.sc-total { background: #fbeee2; font-weight: 700; }
.sumtbl th.sc-total-h { background: #e98b6f; color: #fff; }
.sumtbl th.sc-note-h { background: var(--surface-strong); min-width: 170px; }
.sumtbl td.sc-note { max-width: 230px; white-space: normal; font-size: 12px; color: var(--text-2); }
.sumtbl tfoot td {
  background: #f3ddc3; font-weight: 700; border-top: 2px solid var(--border-strong);
  text-align: right; font-family: var(--font-num); font-variant-numeric: tabular-nums;
}
.sumtbl tfoot .sc-foot-label { text-align: center; position: sticky; left: 0; z-index: 2; }
.sumtbl tfoot .sc-total { background: #eec9a3; }

.sumtbl td.sc-edit { cursor: pointer; }
.sumtbl td.sc-edit:hover { outline: 2px dashed var(--gold-500); outline-offset: -2px; }
.sumtbl td.sc-saved { animation: sc-flash 0.9s ease-out; }
@keyframes sc-flash { 0% { background: #d9f2e2; } 100% { background: var(--surface); } }
.sc-input {
  width: 100%; min-width: 56px; border: 1px solid var(--gold-600); border-radius: 4px;
  font: inherit; padding: 2px 5px; text-align: right; outline: none; background: #fffdf5;
}
td.sc-note .sc-input { text-align: left; min-width: 160px; }

@media (max-width: 720px) {
  .summary-page { padding: 12px 10px 20px; }
  .summary-page .admin-head { flex-direction: column; align-items: flex-start; gap: 8px; }
}

/* ===========================================================
   บ้าน (house projects) — map markers + detail modal
   =========================================================== */
.house-pin {
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none;
  cursor: pointer;
}
.house-pin:hover { transform: scale(1.25); z-index: 1000 !important; }

/* status symbol: colour = แดง(สร้าง)/เหลือง(ซ่อม) per the source doc,
   shape = target group (● พลฯบาดเจ็บ, ■ พลฯยากไร้, ▲ ประชาชนยากไร้) */
.hmark {
  display: inline-block; vertical-align: -2px;
  width: var(--hms, 14px); height: var(--hms, 14px);
  background: var(--hm, #94a0b6);
  filter: drop-shadow(0 1px 2px rgba(11, 37, 69, 0.45));
}
.hm-circle { border-radius: 50%; box-shadow: inset 0 0 0 2px #fff; }
.hm-square { border-radius: 2px; box-shadow: inset 0 0 0 2px #fff; }
.hm-triangle { clip-path: polygon(50% 4%, 100% 96%, 0% 96%); }

.house-ctl { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.house-legend {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px 10px;
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 4px;
  max-width: 230px;
}
.hl-row { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-2); }
.hl-label { flex: 1; white-space: nowrap; }
.hl-count { font-family: var(--font-num); font-weight: 700; color: var(--navy-700); }

.house-status-chip {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1.5px solid; border-radius: 999px;
  padding: 2px 12px 2px 9px;
  font-weight: 700; font-size: 13px;
  background: #fff;
}

.house-toggle {
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.85);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 6px 11px;
  font: 600 12.5px var(--font-sans);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.house-toggle.active { background: #fff; color: #c2410c; border-color: #c2410c; }
.house-toggle:hover { box-shadow: var(--shadow); }

.house-detail { display: flex; flex-direction: column; gap: 16px; }
.house-info {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px 26px;
  background: var(--surface-alt);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px;
}
.house-kv { display: flex; gap: 10px; font-size: 13.5px; padding: 3px 0; min-width: 0; }
.house-kv .k { flex: 0 0 108px; color: var(--text-muted); }
.house-kv .v { color: var(--text); font-weight: 500; overflow-wrap: anywhere; }
.house-kv-note .v { color: var(--text-light); font-weight: 400; font-size: 12.5px; }

.hg-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13.5px; font-weight: 700; color: var(--navy-700);
  margin: 4px 0 8px; padding-bottom: 5px;
  border-bottom: 1px solid var(--border);
}
.hg-head + .hg-grid { margin-bottom: 14px; }
.hg-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 8px;
}
.hg-img {
  width: 100%; aspect-ratio: 4 / 3; object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: zoom-in;
  background: var(--surface-strong);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.hg-img:hover { transform: scale(1.03); box-shadow: var(--shadow); }

@media (max-width: 720px) {
  .house-info { grid-template-columns: 1fr; }
}

/* house overlay scope switch (national map): ทภ.1 ↔ ทั้งหมด */
.house-scope {
  display: flex;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.hscope {
  border: none; background: transparent;
  padding: 5px 10px;
  font: 600 12px var(--font-sans);
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}
.hscope + .hscope { border-left: 1px solid var(--border); }
.hscope.active { background: var(--navy-700); color: #fff; }

/* admin: house edit — status picker chips (the six allowed symbols) */
.hchip-row { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.hchip {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  border-radius: 999px;
  padding: 5px 13px 5px 10px;
  font: 500 12.5px var(--font-sans);
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.12s;
}
.hchip:hover { border-color: var(--navy-300); }
.hchip.active {
  border-color: var(--navy-700);
  background: var(--navy-700);
  color: #fff;
  font-weight: 600;
}
.hchip-hint { font-size: 12px; color: var(--text-light); }
.house-status-cell .mg-tag { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }

/* admin: house edit — photo manager */
.hp-manager { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 10px; }
.hp-title { font-weight: 700; font-size: 14px; color: var(--navy-700); margin-bottom: 4px; }
.hp-row { padding: 7px 0; border-bottom: 1px dashed var(--border); }
.hp-row:last-child { border-bottom: none; }
.hp-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; font-weight: 600; color: var(--text-2);
  margin-bottom: 6px;
}
.hp-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.hp-item { position: relative; }
.hp-img {
  width: 92px; height: 70px; object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: zoom-in;
  background: var(--surface-strong);
}
.hp-del {
  position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--danger);
  font-size: 11px; line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  display: flex; align-items: center; justify-content: center;
}
.hp-del:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

/* long menu labels (โครงการ สร้างและซ่อมแซมบ้าน ทภ.1): keep brand/user chip on
   one line and let the breadcrumb be the part that truncates when space is short */
.brand { flex-shrink: 0; }
.brand-text strong { white-space: nowrap; }
.header-actions { flex-shrink: 0; }
.user-meta strong, .role-badge { white-space: nowrap; }
.header-nav { flex-shrink: 0; }
.hnav { padding: 6px 8px; font-size: 13px; }
@media (max-width: 1680px) {
  .hnav { font-size: 12.5px; padding: 5px 6px; }
  .brand-text span { display: none; }   /* drop the EN subtitle when tight */
}

/* admin people table: เพศ / รูปภาพ / E-Mail / ID Line columns */
.gender-tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 9px;
  border-radius: 999px; border: 1px solid transparent; white-space: nowrap; }
.gender-tag.m { background: #e8f0fb; color: #1d4079; border-color: #b6cce6; }
.gender-tag.f { background: #fbe8ef; color: #9a2a52; border-color: #f0b8cb; }
.photo-flag { font-size: 12px; font-weight: 600; white-space: nowrap; }
.photo-flag.yes { color: var(--success); }
.photo-flag.no { color: var(--text-light); }
td.col-gender, td.col-photo { text-align: center; white-space: nowrap; }
td.col-contact { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12.5px; }

/* ===========================================================
   Responsive: mobile + tablet (hamburger nav, stacked layouts,
   full-screen modals, scrollable tables)
   =========================================================== */
/* hamburger + slide-down menu (hidden on desktop) */
.nav-burger {
  display: none;
  width: 40px; height: 40px;
  align-items: center; justify-content: center;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 9px; cursor: pointer; color: #fff;
  flex-shrink: 0;
}
.nav-burger-bars, .nav-burger-bars::before, .nav-burger-bars::after {
  content: ''; display: block; width: 17px; height: 2px;
  background: var(--text-on-navy); border-radius: 2px; position: relative;
}
.nav-burger-bars::before { position: absolute; transform: translateY(-5px); }
.nav-burger-bars::after { position: absolute; transform: translateY(5px); }
.mobile-menu {
  position: absolute; top: var(--header-h); left: 0; right: 0;
  background: var(--navy-800);
  border-top: 1px solid rgba(255,255,255,0.12);
  box-shadow: 0 18px 30px -12px rgba(3,12,28,0.55);
  z-index: 1300;
  display: flex; flex-direction: column;
  max-height: calc(100dvh - var(--header-h)); overflow-y: auto;
}
.mobile-menu[hidden] { display: none; }
.mobile-menu .mnav {
  display: block; width: 100%; text-align: left;
  padding: 13px 20px; font-size: 14.5px; font-weight: 500;
  color: var(--text-on-navy); text-decoration: none;
  background: none; border: none; cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  font-family: var(--font-sans);
}
.mobile-menu .mnav:active, .mobile-menu .mnav:hover { background: rgba(255,255,255,0.10); color: #fff; }
.mobile-menu .mnav-sep { height: 1px; background: rgba(255,255,255,0.18); margin: 4px 0; }

/* tablet: keep inline nav but tighter */
@media (max-width: 1180px) {
  .hnav { font-size: 12px; padding: 5px 5px; }
  .brand-text span { display: none; }
}
/* ≤900px: inline nav + header buttons fold into the hamburger */
@media (max-width: 900px) {
  .app-header { gap: 10px; padding: 0 12px; }
  .header-nav { display: none; }
  .header-actions .btn { display: none; }
  .user-meta { display: none; }
  .header-divider { display: none; }
  .breadcrumb { font-size: 13px; }
  .nav-burger { display: flex; }
}
/* ≤760px: (stacking rules above already switch home/split to columns) */
@media (max-width: 760px) {
  .breadcrumb a:not(:last-child) { display: none; }   /* keep only the current crumb */
  .breadcrumb .sep { display: none; }
  .admin-page, .summary-page { padding: 12px 12px 20px; }
  .admin-head { flex-wrap: wrap; gap: 10px; }
  .admin-head h1 { font-size: 19px; }
  .admin-head .head-actions { flex-wrap: wrap; gap: 8px; }
  .admin-head .head-actions .btn { height: 34px; font-size: 13px; padding: 0 10px; }
  .admin-filters .fld { min-width: 130px; flex: 1; }
  /* tables scroll sideways inside their card instead of crushing columns */
  .admin-list { -webkit-overflow-scrolling: touch; }
  .admin-list table.admin-table { min-width: 760px; }
  .summary-title { font-size: 13.5px; padding: 8px 12px; }
  .summary-page .admin-head { flex-direction: row; }
  .hero-num { font-size: 34px; }
  .hero-row .mini .v { font-size: 18px; }
  .panel-section { padding: 14px 16px; }
  .dim-toggle { flex-wrap: wrap; }
  .house-legend { max-width: 190px; font-size: 11px; }
  .hl-row { font-size: 11px; gap: 5px; }
  .house-toggle { font-size: 11.5px; padding: 5px 8px; }
  .house-scope .hscope { font-size: 11px; padding: 4px 7px; }
  /* full-screen modals on phones */
  .modal, .modal.modal-form, .modal.modal-wide {
    width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0;
  }
  .modal-body { padding: 14px 14px; }
  .modal-head { padding: 12px 14px; }
  .modal-foot { padding: 10px 14px; flex-wrap: wrap; gap: 8px; }
  .person-edit { flex-direction: column; }
  .hp-img { width: 78px; height: 60px; }
  .hg-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
  .house-info { grid-template-columns: 1fr; }
  .house-kv .k { flex-basis: 96px; }
  .hchip { font-size: 11.5px; padding: 4px 10px 4px 8px; }
  .login-card { max-width: 92vw; padding-left: 18px; padding-right: 18px; }
}
/* small phones */
@media (max-width: 480px) {
  .brand-text strong { font-size: 13px; }
  .brand-mark { width: 30px; height: 30px; }
  .hero-num { font-size: 30px; }
  .stats-card { padding: 12px 14px; }
  .avatar { width: 28px; height: 28px; font-size: 12px; }
  .app-header { padding: 0 8px; }
  .breadcrumb { display: none; }
}

@media (max-width: 760px) {
  .modal-backdrop { padding: 0; }
}

/* legend header (tap to expand/collapse — collapsed by default on phones) */
.house-legend { padding: 0; overflow: hidden; }
.hl-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; border: none; background: transparent; cursor: pointer;
  font: 600 12px var(--font-sans); color: var(--text-2);
  padding: 7px 10px;
}
.hl-head:hover { background: var(--surface-strong); }
.hl-chev { color: var(--text-light); font-size: 11px; }
.hl-body { display: flex; flex-direction: column; gap: 4px; padding: 0 10px 8px; }

/* mobile home: the MAP comes first and the whole page scrolls as one column —
   the dashboard used to sit on top inside its own tiny scrollbox */
@media (max-width: 760px) {
  .home-layout { display: flex; flex-direction: column; overflow-y: auto;
    -webkit-overflow-scrolling: touch; }
  .home-layout .map-wrap { order: -1; flex: 0 0 58vh; min-height: 58vh; }
  .home-dashboard { max-height: none; overflow: visible; flex: none;
    border-bottom: none; border-top: 1px solid var(--border); }
}

/* กลุ่มมวลชน: network-only categories (counts from the สรุปมวลชน matrix) */
.mg-net { margin-top: 14px; padding-top: 10px; border-top: 1px dashed var(--border); }
.mg-net-head {
  display: flex; align-items: baseline; justify-content: space-between;
  font-size: 11.5px; font-weight: 700; color: var(--text-muted);
  letter-spacing: 0.2px; margin-bottom: 6px;
}
.mg-net-link { font-size: 11px; font-weight: 600; color: var(--navy-500); }
.mg-net-row {
  display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: 8px;
  padding: 4px 0; font-size: 12.5px; color: var(--text-2); text-decoration: none;
}
.mg-net-row:hover { color: var(--navy-700); }
.mg-net-row .dot {
  width: 9px; height: 9px; border-radius: 50%; margin-left: 2px;
  border: 1px solid rgba(0,0,0,0.08); opacity: 0.55;
}
.mg-net-row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mg-net-row .num {
  font-family: var(--font-num); font-weight: 700; font-size: 12.5px; color: var(--navy-600);
}
.mg-net-foot {
  display: flex; justify-content: space-between; margin-top: 6px; padding-top: 6px;
  border-top: 1px solid var(--border); font-size: 12px; color: var(--text-muted);
}
.mg-net-foot b { font-family: var(--font-num); color: var(--navy-700); }
.mg-empty-note {
  margin-top: 10px; font-size: 11.5px; line-height: 1.5; color: var(--text-light);
}
.mg-net-note { font-size: 11px; line-height: 1.45; color: var(--text-light); margin: -2px 0 6px; }
.mg-net-row .srcs { display: block; font-size: 10.5px; color: var(--text-light); font-weight: 400;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mg-net-row { align-items: start; }
.mg-net-row .num { align-self: center; }
.mg-net-tot { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.mg-net-tot-head { font-size: 11px; font-weight: 700; color: var(--text-muted);
  letter-spacing: .2px; margin-bottom: 3px; }
.mg-net-tot-row { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0;
  font-size: 12.5px; color: var(--text-2); text-decoration: none; }
.mg-net-tot-row:hover { color: var(--navy-700); }
.mg-net-tot-row b { font-family: var(--font-num); font-variant-numeric: tabular-nums;
  color: var(--navy-700); }
.import-help td.skip { color: var(--text-light); white-space: nowrap; opacity: .7; }
.import-help td.note { color: var(--text-muted); font-size: 12.5px; }
.import-help td:first-child { font-weight: 600; white-space: nowrap; }
.chip-mute { background: var(--surface-strong); color: var(--text-light); border-color: var(--border); }
.chips-more summary { cursor: pointer; font-size: 12.5px; color: var(--text-muted); padding: 4px 0; }
.import-note { color: var(--text-muted); font-size: 13px; padding: 6px 0; }
.house-toggle:not(.active) { opacity: .78; }
