/* ============================================================
   GeoVantage
   โครงหน้าจอ (layout/โครงสร้าง) : ตามภาพ REFERENCE ในข้อเสนอ
   สไตล์ (สี ตัวอักษร รัศมี เงา คอมโพเนนต์) : ตาม designsystem-fixed.html
   ============================================================ */
:root {
  /* ── รัศมี (design system) ── */
  --radius: 0.75rem;
  --radius-sm: calc(var(--radius) * 0.6);
  --radius-md: calc(var(--radius) * 0.8);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) * 1.4);
  --radius-2xl: calc(var(--radius) * 1.8);
  --radius-3xl: calc(var(--radius) * 2.2);

  /* ── พื้นผิว (design system) ── */
  --background: oklch(0.99 0 0);
  --foreground: oklch(0.145 0 0);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.145 0 0);
  --card-alt: oklch(0.97 0 0);
  --muted: oklch(0.97 0 0);
  --muted-foreground: oklch(0.45 0 0);
  --dim: oklch(0.52 0 0);
  --border: oklch(0.92 0 0);
  --border-strong: oklch(0.88 0 0);
  --input: oklch(0.92 0 0);
  --ring: oklch(0.557 0.241 28.59);

  /* ── แบรนด์ (design system) ── */
  --primary: oklch(0.557 0.241 28.59);
  --primary-hover: oklch(0.5 0.241 28.59);
  --primary-foreground: oklch(0.985 0 0);
  --primary-soft: oklch(0.97 0.02 25);
  --secondary: oklch(0.97 0 0);
  --secondary-foreground: oklch(0.205 0 0);
  --accent: oklch(0.97 0.02 25);
  --accent-foreground: oklch(0.205 0 0);
  --accent-strong: oklch(0.557 0.241 28.59);
  --destructive: oklch(0.577 0.245 27.325);
  --destructive-foreground: oklch(0.985 0 0);

  --brand-50: #fff1f2;
  --brand-100: #ffe4e6;
  --brand-500: #e60023;
  --brand-600: #b30019;
  --brand-700: #8a0014;

  /* ── สีสถานะ: พื้นอ่อน + ตัวอักษรเข้มพอให้ contrast ≥ 4.5:1 ── */
  --success: oklch(0.45 0.16 145);
  --success-soft: oklch(0.6 0.18 145 / 0.12);
  --success-border: oklch(0.6 0.18 145 / 0.35);
  --warning: oklch(0.45 0.14 60);
  --warning-soft: oklch(0.65 0.16 60 / 0.14);
  --warning-border: oklch(0.65 0.16 60 / 0.4);
  --danger: oklch(0.52 0.22 27.3);
  --danger-soft: oklch(0.577 0.245 27.325 / 0.12);
  --danger-border: oklch(0.577 0.245 27.325 / 0.35);
  --info: oklch(0.45 0.15 240);
  --info-soft: oklch(0.55 0.18 240 / 0.1);
  --info-border: oklch(0.55 0.18 240 / 0.3);

  /* ── ชาร์ต (design system) ── */
  --chart-1: oklch(0.557 0.241 28.59);
  --chart-2: oklch(0.65 0.16 60);
  --chart-3: oklch(0.55 0.18 240);
  --chart-4: oklch(0.6 0.18 145);
  --chart-5: oklch(0.55 0.2 290);

  /* ── เงา (design system) ── */
  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.06);
  --shadow: 0 2px 8px oklch(0 0 0 / 0.08);
  --shadow-md: 0 4px 16px oklch(0 0 0 / 0.1);
  --shadow-lg: 0 8px 32px oklch(0 0 0 / 0.12);

  --sidebar-w: 236px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Noto Sans Thai', system-ui, sans-serif;
  background: var(--background);
  color: var(--foreground);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select, textarea { font-family: inherit; }

/* ─── App shell ────────────────────────────────────────── */
.app { display: none; }
.app.show { display: block; }

.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 60px;
  background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 1rem; padding: 0 1.25rem;
  z-index: 300;
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.1rem; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 10px; background: var(--primary);
  display: grid; place-items: center; color: var(--primary-foreground); flex-shrink: 0;
}
.brand-text { line-height: 1.15; }
.brand-text b { color: var(--foreground); }
.brand-text b i { color: var(--primary); font-style: normal; }
.brand-text small { display: block; font-size: .6rem; font-weight: 500; color: var(--dim); letter-spacing: .02em; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: var(--primary); color: var(--primary-foreground);
  font-size: .78rem; font-weight: 700; flex-shrink: 0;
}
.who { line-height: 1.15; text-align: right; }
.who b { font-size: .82rem; }
.who span { display: block; font-size: .68rem; color: var(--dim); }

.sidebar {
  position: fixed; top: 60px; bottom: 0; left: 0; width: var(--sidebar-w);
  background: var(--card); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 1rem 0 2rem; z-index: 200;
}
.nav-group { padding: 0 .75rem .85rem; }
.nav-label {
  font-size: .65rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted-foreground); padding: .3rem .6rem; margin-bottom: .15rem;
}
.nav-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .7rem; border-radius: var(--radius-md);
  font-size: .84rem; color: var(--foreground); text-decoration: none;
  cursor: pointer; border: none; background: transparent; width: 100%; text-align: left;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--muted); }
.nav-item.active { background: var(--accent); color: var(--brand-600); font-weight: 600; }
.nav-item svg { flex-shrink: 0; opacity: .75; }
.nav-item.active svg { opacity: 1; }

/* container-type ทำให้ลูกหลานใช้ @container ได้ — วัดจากความกว้างจริงของกล่อง
   ไม่ใช่ viewport จึงไม่สลับ layout เวลาผู้ใช้ซูมเบราว์เซอร์
   หมายเหตุ: container-type: inline-size บังคับ contain:layout ด้วย ทำให้กล่องนี้
   กลายเป็น containing block ของ position:fixed ที่อยู่ข้างใน — ตรวจแล้วว่า
   topbar/sidebar/toast/modal ทั้งหมดอยู่นอก .main จึงไม่กระทบ */
.main {
  margin-left: var(--sidebar-w); padding: 5.5rem 1.75rem 4rem;
  max-width: 1800px;
  container-type: inline-size; container-name: main;
}
.page { display: none; }
.page.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; transform: none; } }

.page-header { margin-bottom: 1.25rem; }
.page-header h1 { font-size: 1.6rem; font-weight: 700; line-height: 1.25; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.page-header p { font-size: .85rem; color: var(--muted-foreground); margin-top: .2rem; }
.page-header-row { display: flex; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.page-header-row .spacer { flex: 1; }

/* ─── Buttons (design system) ──────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font-weight: 500; cursor: pointer; border: none; outline: none;
  transition: background .15s, opacity .15s; white-space: nowrap; text-decoration: none;
  height: 34px; padding: 0 .875rem; font-size: .875rem; border-radius: var(--radius-lg);
}
.btn:focus-visible { outline: 3px solid oklch(0.557 0.241 28.59 / 0.4); outline-offset: 2px; }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn-sm { height: 28px; padding: 0 .625rem; font-size: .8rem; border-radius: var(--radius-md); }
.btn-lg { height: 40px; padding: 0 1.25rem; font-size: .9rem; }
.btn-icon { width: 34px; padding: 0; }
.btn-sm.btn-icon { width: 28px; }
.btn-block { width: 100%; }
.btn-default { background: var(--primary); color: var(--primary-foreground); }
.btn-default:hover { background: var(--primary-hover); }
.btn-accent { background: var(--primary); color: var(--primary-foreground); }
.btn-accent:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--secondary); color: var(--secondary-foreground); border: 1px solid var(--border); }
.btn-secondary:hover { background: oklch(0.94 0 0); }
.btn-outline { background: transparent; color: var(--foreground); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--muted); }
.btn-ghost { background: transparent; color: var(--foreground); }
.btn-ghost:hover { background: var(--muted); }
.btn-destructive { background: var(--destructive); color: var(--destructive-foreground); }
.btn-destructive:hover { background: oklch(0.52 0.245 27.325); }
/* ปุ่มยืนยันเมื่องานสำเร็จ — ใช้กับปุ่มบันทึกผลการกวาดที่มาแทนปุ่มหยุด */
.btn-success { background: #16a34a; color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-link {
  background: transparent; border: none; cursor: pointer; color: var(--primary);
  height: auto; padding: 0; text-decoration: underline; text-underline-offset: 2px;
}

/* ─── Badges (design system) ───────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: .25rem;
  height: 20px; padding: 0 .5rem; font-size: .7rem; font-weight: 500;
  border-radius: 999px; white-space: nowrap;
}
.badge-default { background: var(--primary); color: var(--primary-foreground); }
.badge-accent { background: var(--accent); color: var(--brand-600); border: 1px solid oklch(0.557 0.241 28.59 / 0.3); }
.badge-secondary { background: var(--secondary); color: var(--secondary-foreground); border: 1px solid var(--border); }
.badge-outline { background: transparent; color: var(--foreground); border: 1px solid var(--border); }
.badge-ghost { background: var(--muted); color: var(--muted-foreground); }
.badge-destructive { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger-border); }
.badge-success { background: var(--success-soft); color: var(--success); border: 1px solid var(--success-border); }
.badge-warning { background: var(--warning-soft); color: var(--warning); border: 1px solid var(--warning-border); }
.badge-info { background: var(--info-soft); color: var(--info); border: 1px solid var(--info-border); }

/* ─── Cards (design system) ────────────────────────────── */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-sm); overflow: hidden;
}
.card-header { padding: 1.125rem 1.25rem 0; }
.card-header.with-border { padding-bottom: .875rem; border-bottom: 1px solid var(--border); }
.card-title { font-size: .975rem; font-weight: 600; display: flex; align-items: center; gap: .4rem; }
.card-desc { font-size: .775rem; color: var(--muted-foreground); margin-top: .15rem; }
.card-content { padding: 1.125rem 1.25rem; }
.card-footer {
  padding: .75rem 1.25rem; border-top: 1px solid var(--border); background: var(--muted);
  display: flex; gap: .5rem; align-items: center;
}
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid-6 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }

/* ─── Meta strip (แถบข้อมูลการประเมิน) ─────────────────── */
.meta-strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-xl);
  overflow: hidden; box-shadow: var(--shadow-sm);
}
.meta-item { display: flex; align-items: center; gap: .65rem; padding: .85rem 1rem; border-right: 1px solid var(--border); }
.meta-item:last-child { border-right: none; }
.meta-ico { width: 34px; height: 34px; border-radius: var(--radius-md); display: grid; place-items: center; flex-shrink: 0; }
.meta-label { font-size: .7rem; color: var(--dim); }
.meta-value { font-size: .87rem; font-weight: 600; }

/* ─── Factor rows ──────────────────────────────────────── */
.factor { padding: .6rem 0; border-bottom: 1px solid var(--border); }
.factor:last-child { border-bottom: none; }
.factor-top { display: flex; align-items: center; gap: .5rem; }
.factor-ico { width: 28px; height: 28px; border-radius: var(--radius-sm); display: grid; place-items: center; flex-shrink: 0; }
.factor-name { font-size: .85rem; font-weight: 600; }
.factor-val { margin-left: auto; font-size: .9rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.factor-val small { font-size: .68rem; color: var(--dim); font-weight: 500; }
.factor-detail { font-size: .72rem; color: var(--muted-foreground); margin-top: .25rem; padding-left: 2.1rem; }
.factor-bar { margin: .35rem 0 0 2.1rem; }

/* ─── Forms (design system) ────────────────────────────── */
.field { display: flex; flex-direction: column; gap: .375rem; margin-bottom: .875rem; }
.label { font-size: .8rem; font-weight: 500; }
.input, .select, .textarea {
  height: 36px; padding: 0 .75rem; font-size: .875rem;
  background: var(--card); border: 1px solid var(--input); border-radius: var(--radius-lg);
  outline: none; transition: border .15s, box-shadow .15s; width: 100%; color: var(--foreground);
}
.textarea { height: auto; padding: .5rem .75rem; resize: vertical; line-height: 1.55; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--ring); box-shadow: 0 0 0 3px oklch(0.557 0.241 28.59 / 0.2); }
.input::placeholder, .textarea::placeholder { color: var(--dim); }
.select {
  appearance: none; cursor: pointer; padding-right: 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
}
.input-sm, .select-sm { height: 30px; font-size: .8rem; border-radius: var(--radius-md); }
.helper { font-size: .72rem; color: var(--muted-foreground); }
.helper.error { color: var(--destructive); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }

.chip-group { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .3rem .65rem; font-size: .78rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--card); cursor: pointer;
  transition: all .15s; user-select: none; color: var(--foreground);
}
.chip:hover { background: var(--muted); }
.chip.on { background: var(--accent); border-color: oklch(0.557 0.241 28.59 / 0.45); color: var(--brand-600); font-weight: 600; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.switch {
  width: 36px; height: 20px; border-radius: 999px; background: var(--muted);
  border: 1px solid var(--border); position: relative; cursor: pointer;
  transition: background .2s; flex-shrink: 0;
}
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--card); transition: transform .2s; box-shadow: var(--shadow-sm);
}
.switch.on { background: var(--primary); border-color: var(--primary); }
.switch.on::after { transform: translateX(16px); }
.control-row { display: flex; align-items: center; gap: .625rem; margin-bottom: .5rem; font-size: .85rem; }

/* ─── Tabs (design system) ─────────────────────────────── */
.tab-list { display: inline-flex; background: var(--muted); border-radius: var(--radius-lg); padding: 3px; gap: 2px; }
.tab {
  padding: .375rem .875rem; border-radius: var(--radius-md); font-size: .8rem;
  font-weight: 500; cursor: pointer; border: none; background: transparent;
  color: var(--muted-foreground); transition: all .15s;
}
.tab.active { background: var(--card); color: var(--foreground); box-shadow: var(--shadow-sm); font-weight: 600; }

/* ─── Table (design system) ────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border); background: var(--card); }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead { background: var(--muted); }
th { padding: .625rem 1rem; text-align: left; font-weight: 600; font-size: .8rem; white-space: nowrap; color: var(--muted-foreground); }
td { padding: .625rem 1rem; border-top: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover td { background: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, 'Courier New', monospace; font-size: .78rem; }
.rank { width: 22px; height: 22px; border-radius: var(--radius-sm); background: var(--muted); display: inline-grid; place-items: center; font-size: .72rem; font-weight: 700; color: var(--muted-foreground); }

/* ─── Progress (design system) ─────────────────────────── */
.progress-track { height: 6px; background: var(--muted); border-radius: 999px; overflow: hidden; width: 100%; }
.progress-bar { height: 100%; background: var(--primary); border-radius: 999px; transition: width .4s ease; }
.progress-wrap { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .7rem; }
.progress-label { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted-foreground); }
.progress-label b { color: var(--foreground); font-variant-numeric: tabular-nums; }

/* ─── Alerts / callouts (design system) ────────────────── */
.alert {
  display: flex; gap: .7rem; align-items: flex-start; padding: .8rem 1rem;
  border-radius: var(--radius-lg); border: 1px solid; margin-bottom: .75rem; font-size: .85rem;
}
.alert strong { font-weight: 600; display: block; margin-bottom: .1rem; }
.alert svg { flex-shrink: 0; margin-top: 2px; }
.alert-info { background: oklch(0.55 0.18 240 / 0.08); border-color: var(--info-border); color: var(--info); }
.alert-success { background: oklch(0.6 0.18 145 / 0.08); border-color: var(--success-border); color: var(--success); }
.alert-warning { background: oklch(0.65 0.16 60 / 0.1); border-color: var(--warning-border); color: var(--warning); }
.alert-error { background: oklch(0.577 0.245 27 / 0.08); border-color: var(--danger-border); color: var(--danger); }

.callout {
  border: 1px solid var(--warning-border); background: oklch(0.65 0.16 60 / 0.1);
  border-radius: var(--radius-xl); padding: .9rem 1.1rem; margin-bottom: 1rem;
}
.callout b { display: block; color: var(--warning); font-size: .9rem; margin-bottom: .2rem; }
.callout p { font-size: .82rem; color: var(--warning); }

.note-box {
  border: 1px solid var(--danger-border); background: var(--danger-soft); color: var(--danger);
  border-radius: var(--radius-md); padding: .55rem .7rem; font-size: .74rem; text-align: center; line-height: 1.45;
}

/* ─── Map ──────────────────────────────────────────────── */
.map { height: 480px; width: 100%; z-index: 1; }
.map-sm { height: 320px; }
.map-wrap { position: relative; border-radius: var(--radius-xl); overflow: hidden; border: 1px solid var(--border); background: var(--card); }
.leaflet-container { font-family: inherit; background: oklch(0.96 0 0); }
.filter-bar {
  display: flex; gap: 0; align-items: stretch; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-xl);
  padding: .55rem .25rem; margin-bottom: .85rem; box-shadow: var(--shadow-sm);
}
.filter-item { display: flex; align-items: center; gap: .6rem; padding: .15rem 1rem; border-right: 1px solid var(--border); }
.filter-item:last-child { border-right: none; }
.filter-ico { width: 34px; height: 34px; border-radius: var(--radius-md); display: grid; place-items: center; flex-shrink: 0; }
.filter-label { font-size: .7rem; color: var(--dim); }
.filter-value { font-size: .85rem; font-weight: 600; display: flex; align-items: center; gap: .4rem; }
.map-search {
  position: absolute; top: .7rem; left: .7rem; z-index: 500; display: flex; gap: .4rem;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: .3rem; box-shadow: var(--shadow-md);
  /* กันไม่ให้แถบยาวไปทับปุ่มซูมที่มุมขวาบนของแผนที่ (ปุ่มกว้าง ~34px + ระยะขอบ) */
  max-width: calc(100% - 4.4rem);
}
/* ปุ่มและ dropdown คงขนาดไว้ ให้ช่องค้นหาเป็นตัวหดเมื่อพื้นที่ไม่พอ */
.map-search > * { flex: none; }
.map-search .input { flex: 1 1 auto; min-width: 96px; }
.tool-rail {
  position: absolute; top: 4.2rem; left: .7rem; z-index: 500;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md); padding: .3rem; display: flex; flex-direction: column; gap: .2rem;
}
.tool-btn {
  width: 46px; height: 42px; border: none; background: transparent; border-radius: var(--radius-md);
  cursor: pointer; display: grid; place-items: center; color: var(--muted-foreground);
  font-size: .58rem; line-height: 1.1; gap: 1px; transition: all .15s;
}
.tool-btn:hover { background: var(--muted); color: var(--foreground); }
.tool-btn.on { background: var(--accent); color: var(--brand-600); }
.map-legend {
  position: absolute; bottom: .7rem; left: .7rem; z-index: 500;
  background: oklch(1 0 0 / 0.94); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: .4rem .6rem; font-size: .7rem; box-shadow: var(--shadow-sm); display: flex; gap: .8rem; flex-wrap: wrap;
}
.legend-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: .25rem; }
.heat-scale {
  height: 7px; width: 110px; border-radius: 999px; display: inline-block;
  background: linear-gradient(90deg,
    oklch(0.55 0.18 240), oklch(0.6 0.18 145), oklch(0.65 0.16 60), oklch(0.557 0.241 28.59));
}

/* ─── Gauge / score ────────────────────────────────────── */
.gauge-wrap { display: flex; flex-direction: column; align-items: center; gap: .3rem; }
.score-caption { font-size: .9rem; font-weight: 700; }
.stars { color: oklch(0.65 0.16 60); font-size: .95rem; letter-spacing: .05em; }

/* ─── Evidence / list rows ─────────────────────────────── */
.ev { padding: .65rem 0; border-bottom: 1px dashed var(--border); }
.ev:last-child { border-bottom: none; }
.ev-top { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.ev-title { font-size: .86rem; font-weight: 600; }
.ev-val { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.ev-meta { font-size: .73rem; color: var(--muted-foreground); margin-top: .15rem; }
.ev-action { font-size: .73rem; color: var(--info); margin-top: .2rem; }

.src-card { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: .6rem .7rem; background: var(--muted); }
.src-card b { font-size: .78rem; display: flex; align-items: center; gap: .35rem; }
.src-card span { font-size: .7rem; color: var(--muted-foreground); }

.next-card {
  border: 1px solid var(--border); border-radius: var(--radius-lg); padding: .7rem;
  display: flex; align-items: center; gap: .6rem; cursor: pointer; background: var(--card);
  transition: all .15s; text-align: left; width: 100%;
}
.next-card:hover { border-color: oklch(0.557 0.241 28.59 / 0.45); background: var(--accent); }
.next-card b { font-size: .82rem; display: block; }
.next-card span { font-size: .7rem; color: var(--muted-foreground); }

/* ─── Misc ─────────────────────────────────────────────── */
.sep { height: 1px; background: var(--border); margin: .9rem 0; }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted-foreground); font-size: .875rem; }
.empty svg { opacity: .35; margin-bottom: .5rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .38rem 1rem; font-size: .82rem; }
.kv dt { color: var(--muted-foreground); }
.kv dd { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.scroll-y { max-height: 380px; overflow-y: auto; }
.hidden { display: none !important; }
.text-dim { color: var(--muted-foreground); }
.text-sm { font-size: .82rem; }
.text-xs { font-size: .72rem; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; }
.foot-note { font-size: .72rem; color: var(--muted-foreground); margin-top: 1rem; }

/* ─── Toast (design system) ────────────────────────────── */
#toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 900; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  background: var(--card); border: 1px solid var(--border); border-left: 3px solid var(--primary);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: .7rem .9rem;
  font-size: .82rem; max-width: 350px; animation: slidein .2s ease;
}
.toast.success { border-left-color: oklch(0.6 0.18 145); }
.toast.warn { border-left-color: oklch(0.65 0.16 60); }
.toast.error { border-left-color: var(--destructive); }
.toast b { display: block; font-size: .85rem; margin-bottom: .1rem; }
@keyframes slidein { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ─── Modal (design system) ────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; background: oklch(0 0 0 / 0.4); z-index: 800; display: grid; place-items: center; padding: 1rem; }
.modal { background: var(--card); border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); width: 100%; max-width: 620px; max-height: 85vh; overflow-y: auto; }

/* ─── Login — การ์ดลอยกลางจอ แบ่งซ้าย/ขวาในการ์ดเดียว ─── */
/* เต็มจอพอดี ไม่ให้ทั้งหน้าเลื่อน — ถ้าฟอร์มยาวเกิน ให้เลื่อนเฉพาะคอลัมน์ฟอร์ม */
.login-page { height: 100vh; overflow: hidden; position: relative; background: var(--card); }
.login-bg { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.login-bg::before, .login-bg::after {
  content: ''; position: absolute; border-radius: 50%;
}
.login-bg::before {
  width: 520px; height: 520px; top: -200px; right: -150px;
  background: radial-gradient(circle, oklch(0.557 0.241 28.59 / .08), transparent 68%);
}
.login-bg::after {
  width: 560px; height: 560px; bottom: -240px; right: -120px;
  background: radial-gradient(circle, oklch(0.557 0.241 28.59 / .06), transparent 68%);
}

.login-top {
  position: absolute; top: 1.5rem; left: 0; right: 0; z-index: 2;
  display: flex; align-items: center; gap: 1rem; padding: 0 2rem;
}

/* การ์ดหลัก */
.login-card-shell {
  position: relative; z-index: 1; height: 100vh;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

/* ซ้าย: แผงแบรนด์ */
.login-side {
  position: relative; padding: 3.5rem 3rem; overflow: hidden;
  color: oklch(0.30 0.09 28.59);
  background:
    radial-gradient(120% 90% at 78% 22%, oklch(1 0 0 / .75), transparent 62%),
    linear-gradient(155deg, oklch(0.965 0.022 25), oklch(0.915 0.055 25));
  display: flex; flex-direction: column; gap: 1.25rem;
}
/* ภาพหมุดบนผังถนน = พื้นหลังของแผงแดง ข้อความวางทับด้านบน */
.login-side-art { position: absolute; inset: 0; pointer-events: none; }
.login-scene { width: 100%; height: 100%; display: block; }
.login-side-copy { position: relative; z-index: 1; margin-top: auto; }
/* ไล่เฉดเข้มด้านล่าง ให้ตัวหนังสือขาวอ่านชัดเหนือภาพเสมอ */
.login-side::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 52%;
  background: linear-gradient(to top, oklch(0.99 0.01 25 / .82), oklch(0.99 0.01 25 / 0));
  pointer-events: none;
}
.login-side-copy h2 { font-size: 2.35rem; font-weight: 800; line-height: 1.3; letter-spacing: -.01em; color: oklch(0.42 0.19 28.59); }
.login-side-copy p { font-size: .95rem; margin-top: .7rem; line-height: 1.8; max-width: 44ch; color: oklch(0.38 0.06 28.59); }

/* ขวา: ฟอร์มแคบ จัดกลาง */
.login-form { display: grid; place-items: center; padding: 3rem 2rem; background: var(--card); position: relative; overflow-y: auto; }
.login-form-in { width: 100%; max-width: 330px; }
.login-mark {
  width: 46px; height: 46px; border-radius: var(--radius-lg); margin: 0 auto .9rem;
  background: var(--accent); color: var(--primary); display: grid; place-items: center;
  border: 1px solid oklch(0.557 0.241 28.59 / .22);
}
.login-title { font-size: 1.2rem; font-weight: 700; text-align: center; margin-bottom: 1.4rem; }
.login-label { display: block; font-size: .76rem; font-weight: 500; color: var(--muted-foreground); margin-bottom: .3rem; }
.login-form-in .input, .login-form-in .select { margin-bottom: .85rem; }
/* ระยะห่างอยู่ที่กล่องครอบ ไม่ใช่ที่ input — ไม่งั้นกล่องสูงเกินตัว input แล้วไอคอนจะเลื่อนลงล่าง */
.login-form-in .input-ico { margin-bottom: .85rem; }
.login-form-in .input-ico .input { padding-left: 2.25rem; margin-bottom: 0; }
.login-row { display: flex; align-items: center; gap: .5rem; margin: -.2rem 0 .9rem; }
.login-row .btn-link { margin-left: auto; }
.login-check { display: inline-flex; align-items: center; gap: .4rem; font-size: .76rem; color: var(--muted-foreground); cursor: pointer; }
.login-check input { width: 14px; height: 14px; accent-color: var(--primary); cursor: pointer; }
.login-divider { display: flex; align-items: center; gap: .7rem; margin: .9rem 0; color: var(--dim); font-size: .74rem; }
.login-divider::before, .login-divider::after { content: ''; height: 1px; background: var(--border); flex: 1; }
.login-foot-link { font-size: .78rem; color: var(--muted-foreground); text-align: center; margin-top: 1rem; }


.input-ico { position: relative; display: flex; align-items: center; }
.input-ico .input { flex: 1; min-width: 0; }
.input-ico svg { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); color: var(--dim); pointer-events: none; }

@media (max-width: 1100px) {
  .login-side { padding: 3rem 2rem; }
  .login-side-copy h2 { font-size: 1.9rem; }
}
@media (max-width: 860px) {
  /* จอเล็ก: กลับมาเลื่อนหน้าได้ตามปกติ 100vh บนมือถือเชื่อถือไม่ได้ */
  .login-page { height: auto; min-height: 100vh; overflow: visible; }
  .login-card-shell { grid-template-columns: minmax(0, 1fr); height: auto; min-height: 0; }
  .login-form { overflow-y: visible; }
  .login-side {
    padding: 4.5rem 1.5rem 1.6rem; flex-direction: row; align-items: center; gap: 1.1rem; min-height: 0;
  }
  .login-side-copy { margin-top: 0; }
  /* จอเล็ก: แถบบนเตี้ย — เลื่อนภาพไปขวาให้หัวข้ออ่านชัด */
  .login-scene { transform: translateX(34%); opacity: .9; }
  .login-side-copy h2 { font-size: 1.15rem; }
  .login-side-copy p { display: none; }
  .login-form { padding: 2rem 1.5rem 2.5rem; min-height: calc(100vh - 150px); }
  .login-top { padding: 0 1rem; }
}

.spin { animation: rot .9s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

/* ============================================================
   Layout utilities — โครงตาม reference, ยืดหยุ่นตามขนาดจอ
   ============================================================ */
.split        { display: grid; grid-template-columns: minmax(0, 1.95fr) minmax(320px, 1fr); gap: 1rem; align-items: start; }
.result-top   { display: grid; grid-template-columns: minmax(240px, .9fr) minmax(300px, 1.4fr) minmax(300px, 1.15fr); gap: 1rem; align-items: stretch; }
.two-col      { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); gap: 1rem; align-items: start; }
.dash-row     { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(260px, 1fr) minmax(280px, 1.1fr); gap: 1rem; align-items: start; }
.triple       { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; align-items: start; }
.pair         { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; align-items: start; }

/* ── Tablet ─────────────────────────────────────────────── */
@media (max-width: 1280px) {
  .result-top { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .result-top > :nth-child(2) { grid-column: span 2; order: 3; }
  .dash-row   { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .dash-row > :first-child { grid-column: span 2; }
  .triple     { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .triple > :last-child:nth-child(3) { grid-column: span 2; }
}
@media (max-width: 1100px) {
  .split, .two-col { grid-template-columns: minmax(0, 1fr); }
}

/* ── Mobile ─────────────────────────────────────────────── */
@media (max-width: 860px) {
  .result-top, .dash-row, .triple, .pair { grid-template-columns: minmax(0, 1fr); }
  .result-top > :nth-child(2), .dash-row > :first-child,
  .triple > :last-child:nth-child(3) { grid-column: auto; order: 0; }
  .grid-2, .grid-3, .grid-4, .grid-6 { grid-template-columns: minmax(0, 1fr); }
  .page-header h1 { font-size: 1.3rem; }
  .page-header-row { gap: .5rem; }
  .filter-bar { flex-wrap: nowrap; overflow-x: auto; }
  .filter-item { flex: 0 0 auto; }
  .meta-strip { grid-template-columns: minmax(0, 1fr); }
  .meta-item { border-right: none; border-bottom: 1px solid var(--border); }
  .meta-item:last-child { border-bottom: none; }
  .card-content, .card-header { padding-left: .9rem; padding-right: .9rem; }
  .modal { max-height: 92vh; }
  .tab-list { width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .tab { white-space: nowrap; flex: 0 0 auto; }
  .field-row { grid-template-columns: minmax(0, 1fr); }
}

/* แผนที่: สูงพอใช้งานได้ทุกจอ ไม่ล้นจอมือถือ */
.map    { height: clamp(300px, 46vh, 480px); }
.map-sm { height: clamp(260px, 36vh, 340px); }
@media (max-width: 860px) {
  .map-search {
    position: static; box-shadow: none; border: none; border-bottom: 1px solid var(--border);
    border-radius: 0; padding: .5rem; flex-wrap: wrap; max-width: none;
  }
  .map-search .input { width: 100% !important; }
  .tool-rail {
    position: static; flex-direction: row; flex-wrap: wrap; border: none;
    border-bottom: 1px solid var(--border); border-radius: 0; box-shadow: none; padding: .35rem .5rem;
  }
  .tool-btn { width: 44px; height: 40px; }
  .map-legend { font-size: .65rem; gap: .5rem; padding: .3rem .45rem; }
}

/* ── ตารางบนมือถือ: แปลงเป็นการ์ดรายแถว ─────────────────── */
@media (max-width: 760px) {
  .table-wrap.cards { border: none; background: transparent; overflow: visible; }
  .table-wrap.cards table, .table-wrap.cards tbody, .table-wrap.cards tr, .table-wrap.cards td { display: block; width: 100%; }
  .table-wrap.cards thead { display: none; }
  .table-wrap.cards tr {
    border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--card);
    margin-bottom: .6rem; padding: .35rem .6rem; box-shadow: var(--shadow-sm);
  }
  .table-wrap.cards td {
    border: none; display: flex; align-items: center; justify-content: space-between;
    gap: 1rem; padding: .35rem .1rem; text-align: right;
  }
  .table-wrap.cards td::before {
    content: attr(data-label); color: var(--muted-foreground); font-size: .74rem;
    text-align: left; flex: 0 0 auto; font-weight: 500;
  }
  .table-wrap.cards td:first-child { border-bottom: 1px dashed var(--border); padding-bottom: .5rem; margin-bottom: .2rem; }
}

/* ── Sidebar drawer ─────────────────────────────────────── */
.sb-backdrop { display: none; position: fixed; inset: 60px 0 0 0; background: oklch(0 0 0 / 0.35); z-index: 190; }
@media (max-width: 1024px) {
  .main { margin-left: 0; padding: 5.25rem 1rem 3rem; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .sb-backdrop.show { display: block; }
}
@media (max-width: 700px) {
  .topbar { padding: 0 .75rem; gap: .5rem; }
  #dbBadge, .who { display: none; }
  .brand-text small { display: none; }
  .brand { font-size: 1rem; }
}


/* ============================================================
   หน้าผลการประเมิน — Decision Support
   ใช้ token/สเกลของ design system เดิมทั้งหมด
   ============================================================ */

.reason { display: flex; gap: .7rem; padding: .65rem 0; border-bottom: 1px dashed var(--border); }
.reason:last-child { border-bottom: none; }
.reason-ico { width: 30px; height: 30px; border-radius: var(--radius-md); display: grid; place-items: center; flex-shrink: 0; }
.reason-text { font-size: .82rem; color: var(--muted-foreground); margin-top: .15rem; line-height: 1.6; }

.evidence-card { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: .75rem .85rem; background: var(--card); }
.evidence-val { font-size: 1.35rem; font-weight: 700; line-height: 1.25; font-variant-numeric: tabular-nums; margin: .1rem 0; }
.evidence-src {
  font-size: .68rem; color: var(--dim); margin-top: .45rem; padding-top: .4rem;
  border-top: 1px dashed var(--border); display: flex; align-items: center; gap: .3rem;
}



/* ============================================================
   หน้าเลือกทำเล — Workspace 2 คอลัมน์
   แผนที่กับเงื่อนไขต้องเห็นพร้อมกัน ไม่ต้องเลื่อนทั้งหน้า
   ============================================================ */
.ws-head { display: flex; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: .85rem; }
.ws-head-main h1 { font-size: 1.5rem; font-weight: 700; line-height: 1.25; }

/* ความสูง: เต็มจอพอดี ไม่ให้หน้าเว็บเลื่อน */
.main.main-ws { padding-bottom: 1rem; }
.workspace {
  display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(340px, .85fr); gap: 1rem;
  height: calc(100vh - 214px); min-height: 460px;
}
.ws-map { height: 100%; display: flex; flex-direction: column; }
.ws-mapcanvas { flex: 1; height: auto !important; min-height: 0; }

.ws-panel { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
.ws-scroll { flex: 1; overflow-y: auto; padding: 1rem 1.15rem .5rem; min-height: 0; }
.ws-block { padding-bottom: .9rem; margin-bottom: .9rem; border-bottom: 1px solid var(--border); }
.ws-block:last-of-type { border-bottom: none; }
.ws-block-head {
  display: flex; align-items: baseline; gap: .5rem; margin-bottom: .7rem;
  font-size: .85rem; font-weight: 600;
}
.ws-block-head .btn-link { margin-left: auto; }
/* ยังไม่ปักหมุด: กล่องว่าง ให้เส้นคั่นขยับขึ้นไปชิดหัวข้อ */
.ws-block-head:has(+ #pinCard:empty) { margin-bottom: 0; }
.ws-block:has(> #pinCard:empty) { padding-bottom: .55rem; margin-bottom: .55rem; }

.ws-pin { display: flex; gap: .55rem; align-items: flex-start; }
.ws-pin-ico { color: var(--primary); flex-shrink: 0; margin-top: 2px; }
.ws-pin b { font-size: .9rem; display: block; line-height: 1.4; }
.ws-pin span { font-size: .76rem; color: var(--muted-foreground); }
.ws-pin .coord { font-size: .72rem; color: var(--dim); font-variant-numeric: tabular-nums; margin-top: .2rem; }

/* สองคอนโทรลเรียงแถวเดียวกัน ครึ่ง–ครึ่ง */
.ws-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; align-items: start; }
.ws-row2 .field { margin-bottom: .6rem; min-width: 0; }
.ws-range-scale { display: flex; justify-content: space-between; font-size: .68rem; color: var(--dim); margin-top: .1rem; }

/* สรุป + ปุ่มหลัก ติดท้ายแผงเสมอ */
.ws-foot { border-top: 1px solid var(--border); background: var(--card); padding: .8rem 1.15rem 1rem; flex-shrink: 0; }

/* จอกลาง: แผงแคบลงแต่ยังอยู่ข้างแผนที่ */
@media (max-width: 1240px) {
  .workspace { grid-template-columns: minmax(0, 1.4fr) minmax(320px, 1fr); height: calc(100vh - 224px); }
}

/* จอเล็ก: วางซ้อนกัน แผนที่ก่อน แล้วปุ่มหลักติดขอบล่างจอ */
@media (max-width: 1000px) {
  .workspace { grid-template-columns: minmax(0, 1fr); height: auto; min-height: 0; }
  .ws-map { height: clamp(400px, 58vh, 540px); }
  .ws-panel { height: auto; overflow: visible; }
  .ws-scroll { overflow: visible; padding-bottom: 1rem; }
  .ws-foot {
    position: sticky; bottom: 0; z-index: 20;
    box-shadow: 0 -6px 16px oklch(0 0 0 / .06);
  }
}
@media (max-width: 700px) {
  .ws-head-main h1 { font-size: 1.25rem; }
}

/* ============================================================
   หน้าผลการประเมิน — Dashboard composition
   แผนที่เป็นภาพหลักคู่กับผลสรุป แล้วค่อยไล่ลงเป็นแถบตัวเลข/หลักฐาน/รายละเอียด
   ============================================================ */
.res-head { display: flex; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: .85rem; }
.res-head > #backToFind { flex: 0 0 auto; margin-top: .2rem; }
.res-head-main h1 { font-size: 1.45rem; font-weight: 700; line-height: 1.25; }
.res-crumbs { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-top: .2rem; font-size: .78rem; color: var(--muted-foreground); }
.res-crumbs span { display: inline-flex; align-items: center; gap: .3rem; }
.res-crumbs span + span::before { content: '·'; color: var(--border-strong); margin-right: .35rem; }
.res-crumbs b { color: var(--foreground); }
.res-actions { display: flex; gap: .5rem; margin-left: auto; flex-wrap: wrap; }

/* แถวหลัก */
.res-hero {
  display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(330px, .95fr);
  gap: 1rem; margin-bottom: 1rem; height: 480px;
}
.res-map-card { display: flex; flex-direction: column; overflow: hidden; }
.res-map-wrap { border: none; border-radius: 0; flex: 1; min-height: 0; }
.res-map { height: 100% !important; min-height: 0; }

.res-verdict { display: flex; flex-direction: column; overflow: hidden; }
.res-verdict-scroll { overflow-y: auto; padding: 1.1rem 1.15rem; min-height: 0; }
.res-why { margin-top: .9rem; padding-top: .9rem; border-top: 1px solid var(--border); }
.res-why-title { font-size: .85rem; font-weight: 600; margin-bottom: .4rem; }
.res-reason-group + .res-reason-group { margin-top: .7rem; }
.res-group-label { font-size: .72rem; font-weight: 600; margin-bottom: .3rem; }
.res-reason { display: flex; gap: .45rem; align-items: flex-start; padding: .3rem 0; font-size: .8rem; line-height: 1.55; }
.res-reason-ico { flex-shrink: 0; margin-top: 3px; }
.res-reason b { font-weight: 600; }

/* แถบตัวเลข */
/* 4 การ์ดอยู่แถวเดียวเสมอ — บีบขนาดแทนการตัดขึ้นบรรทัดใหม่ */
.res-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.res-stat {
  display: flex; gap: .6rem; align-items: flex-start; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius-xl); padding: .85rem 1rem; box-shadow: var(--shadow-sm);
}
.res-stat-ico {
  width: 30px; height: 30px; border-radius: var(--radius-md); flex-shrink: 0;
  display: grid; place-items: center; background: var(--accent); color: var(--primary);
}
.res-stat-label { font-size: .74rem; color: var(--muted-foreground); }
.res-stat-value { font-size: 1.3rem; font-weight: 700; line-height: 1.25; font-variant-numeric: tabular-nums; }
.res-stat-sub { font-size: .72rem; color: var(--dim); }
/* จอแคบ: ย่อองค์ประกอบในการ์ดแทนการตัดแถว เพื่อให้ยังอยู่ 4 ช่องเท่าเดิม */
@media (max-width: 1100px) {
  .res-stats { gap: .5rem; }
  .res-stat { padding: .65rem .7rem; gap: .45rem; }
  .res-stat-ico { width: 26px; height: 26px; }
  .res-stat-value { font-size: 1.05rem; }
  .res-stat-label, .res-stat-sub { font-size: .66rem; }
}
@media (max-width: 720px) {
  .res-stat { flex-direction: column; gap: .35rem; padding: .55rem .6rem; }
  .res-stat-value { font-size: .95rem; }
}

/* แถวคู่ */
.res-split { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 1rem; margin-bottom: 1rem; align-items: start; }
/* กล่องปัจจัยใต้แผนที่ — สองใบกว้างเท่ากัน */
.res-factors { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.res-detail-single { margin-bottom: 1rem; }


@media (max-width: 1240px) {
  .res-hero { grid-template-columns: minmax(0, 1fr); height: auto; }
  .res-map-wrap { height: 380px; flex: none; }
  .res-verdict { max-height: none; }
  .res-verdict-scroll { overflow: visible; }
}
@media (max-width: 860px) {
  .res-split, .res-factors { grid-template-columns: minmax(0, 1fr); }
  .res-head-main h1 { font-size: 1.25rem; }
  .res-actions { margin-left: 0; width: 100%; }
  .res-actions .btn { flex: 1 1 auto; }
  .res-map-wrap { height: 320px; }
}

/* ============================================================
   Design language primitives
   สกัดจาก reference: ภาพหลักครองพื้นที่ + แถบตัวเลขติดขอบ
   หัวการ์ดมีลิงก์ลงลึก · กราฟผสมแท่ง/เส้น · แถวรายละเอียดสองใบเท่ากัน
   (ใช้ token สี/ตัวอักษร/รัศมี/เงา ของ design system เดิมทั้งหมด)
   ============================================================ */

/* หัวการ์ด: ชื่อซ้าย + ลิงก์ลงลึกขวา */
.card-head-link {
  display: flex; align-items: flex-start; gap: 1rem;
  padding: 1rem 1.15rem .8rem; border-bottom: 1px solid var(--border);
}
.card-head-link > :last-child:not(:first-child) { margin-left: auto; flex-shrink: 0; white-space: nowrap; }

/* legend ของกราฟ — มุมขวาบนตามภาษาที่สกัดมา */
.chart-legend { display: flex; gap: 1rem; justify-content: flex-end; font-size: .72rem; color: var(--muted-foreground); margin-top: .2rem; }
.chart-legend span { display: inline-flex; align-items: center; gap: .35rem; }
.chart-legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* โซนหลักของแดชบอร์ด */
/* สัดส่วน 2:1 คงที่ทุกระดับซูม — ไม่ใช้ minmax() ที่มีขั้นต่ำเป็น px
   เพราะค่า px จะโตขึ้นเมื่อซูมเข้า จนคอลัมน์ขวาเบียดคอลัมน์ซ้ายแล้วตกบรรทัด */
.dash-hero {
  display: grid; grid-template-columns: 2fr 1fr;
  gap: 1rem; margin-bottom: 1rem; align-items: stretch;
}
.dash-map-card { display: flex; flex-direction: column; overflow: hidden; }
.dash-sweep-card { margin-bottom: 1rem; }

/* รายการช่องที่กวาดไม่สำเร็จ พร้อมปุ่มกวาดซ้ำรายช่อง */
/* รายชื่อธุรกิจที่กวาดได้ (แผงขวาระหว่าง/หลังกวาด) */
/* แถบความคืบหน้าตอนกำลังกวาด — ลายวิ่งบอกว่าระบบยังทำงานอยู่ แม้ % จะยังไม่ขยับ
   (ช่วงรอ Overpass ตอบกลับ เปอร์เซ็นต์จะนิ่งได้เป็นนาที) */
.progress-bar.busy {
  background-image: linear-gradient(115deg,
    oklch(1 0 0 / .28) 25%, transparent 25%, transparent 50%,
    oklch(1 0 0 / .28) 50%, oklch(1 0 0 / .28) 75%, transparent 75%);
  background-size: 22px 22px;
  animation: sweepStripe 1s linear infinite;
  transition: width .35s ease;
}
@keyframes sweepStripe { from { background-position: 0 0; } to { background-position: 22px 0; } }
@media (prefers-reduced-motion: reduce) { .progress-bar.busy { animation: none; } }

.found-count { font-size: .76rem; color: var(--muted-foreground); margin-bottom: .5rem; }
.found-list {
  max-height: 58vh; overflow-y: auto; overscroll-behavior: contain;
  border: 1px solid var(--border); border-radius: var(--radius-lg); padding: .25rem;
}
.found-row {
  display: flex; align-items: center; gap: .5rem; padding: .35rem .45rem;
  border-radius: var(--radius-md); font-size: .8rem;
}
.found-row:nth-child(odd) { background: var(--muted); }
.found-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.found-row b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.found-row i { font-style: normal; margin-left: auto; flex: none; font-size: .7rem; color: var(--muted-foreground); }

.sweep-retry { display: grid; gap: .4rem; margin-top: .55rem; }
.sweep-retry-row {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-md); padding: .45rem .6rem;
}
.sweep-retry-row span { flex: 1; min-width: 0; font-size: .78rem; }
.sweep-retry-row b { display: block; font-weight: 600; }
.sweep-retry-row i { font-style: normal; color: var(--muted-foreground); font-size: .72rem; }

/* จุดสีของชั้น “พื้นที่ที่กวาดแล้ว” ในป้ายใต้แผนที่หน้ากวาดข้อมูล */
.swept-key {
  display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: .4rem;
  vertical-align: -1px; background: #22c55e; opacity: .45; border: 1px solid #22c55e;
}
/* ความสูงผูกกับความกว้างด้วย aspect-ratio — สัดส่วนคงเดิมทุกระดับซูม
   ต่างจาก height เป็น px ที่ทำให้แผนที่สูงขึ้นเรื่อย ๆ เมื่อซูมเข้า จนดันการ์ดขวาตก */
.dash-map-body { display: flex; flex: 1; min-height: 0; }
.dash-map-wrap {
  flex: 1; border: none; border-radius: 0; min-width: 0;
  aspect-ratio: 16 / 10; max-height: 520px;
}
.dash-map { height: 100% !important; }

/* ตัวเลขสรุปเหนือแผนที่ — 4 การ์ดแถวเดียวเสมอ */
.dash-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.dash-kpi {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm); padding: .85rem 1rem;
}
.dash-kpi-label { font-size: .74rem; color: var(--muted-foreground); }
.dash-kpi-value { font-size: 1.5rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.dash-kpi-value span { font-size: .7rem; font-weight: 500; color: var(--dim); margin-left: .2rem; }
.dash-kpi-sub { font-size: .7rem; color: var(--dim); }
@media (max-width: 1100px) {
  .dash-kpis { gap: .5rem; }
  .dash-kpi { padding: .6rem .7rem; }
  .dash-kpi-value { font-size: 1.1rem; }
  .dash-kpi-label, .dash-kpi-sub { font-size: .64rem; }
}

.dash-side { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.dash-mini { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.mini-metric {
  display: flex; flex-direction: column; gap: .15rem; align-items: flex-start;
  padding: .8rem .9rem; cursor: pointer; text-align: left; font-family: inherit;
  transition: border-color .15s, background .15s;
}
.mini-metric:hover { border-color: oklch(0.557 0.241 28.59 / .4); background: var(--accent); }
.mini-metric-label { font-size: .74rem; color: var(--muted-foreground); }
.mini-metric-value { font-size: 1.45rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.mini-metric-value i { font-size: .7rem; font-weight: 500; color: var(--dim); font-style: normal; margin-left: .25rem; }

/* ตัวเลขจำนวนการประเมินบนแดชบอร์ด */
.dash-count { display: flex; align-items: baseline; gap: .7rem; padding: .2rem 0 .1rem; }
.dash-count b { font-size: 2.1rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.dash-count span { font-size: .82rem; color: var(--muted-foreground); }
.dash-count i { display: block; font-style: normal; font-size: .74rem; color: var(--dim); margin-top: .1rem; }

.dash-alerts { display: grid; gap: .6rem; margin-bottom: 1rem; }
.dash-detail { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; align-items: start; }

.dash-acts { display: flex; flex-direction: column; }
.dash-act { display: flex; gap: .6rem; align-items: flex-start; padding: .5rem 0; border-bottom: 1px dashed var(--border); }
.dash-act:last-child { border-bottom: none; }
.dash-act-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--primary); flex-shrink: 0; margin-top: .45rem; }
.dash-act b { font-size: .82rem; font-weight: 500; display: block; line-height: 1.5; }
.dash-act span:last-child { font-size: .7rem; color: var(--dim); }

/* fallback จอเล็กจริง ๆ — วัดจากความกว้างของ .main ไม่ใช่ viewport
   จึงยุบเฉพาะตอนที่พื้นที่ไม่พอจริง ไม่ใช่ตอนผู้ใช้ซูมเข้า */
@container main (max-width: 700px) {
  .dash-hero { grid-template-columns: minmax(0, 1fr); }
  .dash-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .dash-map-body { flex-direction: column; min-height: 0; }
  .dash-detail { grid-template-columns: minmax(0, 1fr); }
}

/* ============================================================
   เมนูโปรไฟล์บนแถบบน + ปุ่มเมนูที่แสดงเฉพาะตอนที่ sidebar ถูกซ่อน
   ============================================================ */
/* ปุ่มขีดสามขีดมีผลเฉพาะตอน sidebar เป็น drawer (จอ ≤1024px) จอใหญ่จึงไม่ต้องแสดง */
#btnMenu { display: none; }
@media (max-width: 1024px) { #btnMenu { display: inline-flex; } }

/* ── แผงแจ้งเตือนใต้กระดิ่ง ─────────────────────────────── */
.bell-wrap { position: relative; }
.bell-menu {
  position: absolute; top: calc(100% + .45rem); right: 0; z-index: 400; width: 330px; max-width: 88vw;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); overflow: hidden; animation: fade .12s ease;
}
.bell-head {
  display: flex; align-items: center; gap: .5rem; padding: .7rem .85rem;
  border-bottom: 1px solid var(--border); font-size: .85rem; font-weight: 600;
}
.bell-head span { margin-left: auto; font-size: .72rem; font-weight: 400; color: var(--muted-foreground); }
.bell-list { max-height: 330px; overflow-y: auto; }
.bell-item { padding: .6rem .85rem; border-bottom: 1px solid var(--border); }
.bell-item:last-child { border-bottom: none; }
.bell-item b { display: block; font-size: .82rem; font-weight: 500; line-height: 1.5; }
.bell-item i { font-style: normal; font-size: .72rem; color: var(--muted-foreground); }
.bell-empty { padding: 1.6rem .85rem; text-align: center; font-size: .8rem; color: var(--muted-foreground); }
.bell-foot { padding: .5rem .6rem; border-top: 1px solid var(--border); }

.user-wrap { position: relative; }
.user-btn {
  display: grid; place-items: center; background: transparent;
  border: 1px solid transparent; border-radius: 50%; padding: 2px;
  cursor: pointer; font-family: inherit; color: inherit; transition: background .15s, border-color .15s, box-shadow .15s;
}
.user-btn:hover { background: var(--muted); border-color: var(--border); }
.user-btn[aria-expanded="true"] { background: transparent; border-color: transparent; box-shadow: 0 0 0 3px oklch(0.557 0.241 28.59 / .25); }
.user-caret { color: var(--dim); flex-shrink: 0; transition: transform .15s; }
.user-btn[aria-expanded="true"] .user-caret { transform: rotate(180deg); }

.user-menu {
  position: absolute; top: calc(100% + .45rem); right: 0; z-index: 400; width: 250px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: .35rem; animation: fade .12s ease;
}
.user-menu-head {
  display: flex; gap: .6rem; align-items: center; padding: .6rem .55rem .7rem;
  border-bottom: 1px solid var(--border); margin-bottom: .35rem;
}
.user-menu-head b { font-size: .85rem; display: block; line-height: 1.35; }
.user-menu-head span span {
  display: block; font-size: .72rem; color: var(--muted-foreground);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-menu-item {
  display: flex; align-items: center; gap: .55rem; width: 100%; text-align: left;
  padding: .5rem .55rem; border: none; background: transparent; cursor: pointer;
  border-radius: var(--radius-md); font-family: inherit; font-size: .84rem; color: var(--foreground);
  transition: background .15s;
}
.user-menu-item:hover { background: var(--muted); }
.user-menu-item svg { color: var(--dim); flex-shrink: 0; }
.user-menu-item.danger { color: var(--danger); }
.user-menu-item.danger svg { color: var(--danger); }
.user-menu-item.danger:hover { background: var(--danger-soft); }

@media (max-width: 700px) {
  .user-btn .who { display: none; }
  .user-menu { width: 230px; }
}

/* หน้ากวาดข้อมูล: หัวหน้าสั้นกว่าหน้าเลือกทำเล จึงยืดแผนที่ได้ยาวกว่า */
.ws-page-head { margin-bottom: .85rem; }
.workspace-sweep { height: calc(100vh - 174px); }
@media (max-width: 1240px) { .workspace-sweep { height: calc(100vh - 184px); } }
@media (max-width: 1000px) { .workspace-sweep { height: auto; } }

/* กล่องผลการกวาดว่าง ไม่ควรดันให้หน้าเลื่อน */
#sweepResult:empty { display: none; }

/* หน้าต่างนำเข้าข้อมูล — กว้างกว่าปกติเพราะมีตารางตรวจสอบ */
.modal.modal-lg { max-width: 880px; }
.modal.modal-up { max-width: 520px; }
/* ── หน้าต่างนำเข้าไฟล์ CSV ─────────────────────────────── */
.up-head {
  display: flex; align-items: flex-start; gap: .8rem;
  padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.up-head-ico {
  width: 42px; height: 42px; border-radius: 12px; flex: none; display: grid; place-items: center; color: #fff;
  background: linear-gradient(145deg, oklch(0.62 0.23 28.59), oklch(0.5 0.24 28.59));
  box-shadow: 0 3px 10px oklch(0.557 0.241 28.59 / .32);
}
.up-x {
  margin-left: auto; flex: none; width: 30px; height: 30px; border-radius: 8px; border: none;
  background: transparent; color: var(--muted-foreground); cursor: pointer; display: grid; place-items: center;
  transition: background .15s, color .15s;
}
.up-x:hover { background: var(--accent); color: var(--foreground); }

/* กรอบรับไฟล์เป็นสี่เหลี่ยมจัตุรัส จัดกลางหน้าต่าง */
.up-drop {
  border: 1.5px dashed var(--border); border-radius: var(--radius-xl);
  width: 320px; max-width: 100%; aspect-ratio: 1 / 1; margin: .25rem auto 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 1.25rem; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.up-drop:hover, .up-drop.over { border-color: var(--primary); background: oklch(0.557 0.241 28.59 / .04); }
.up-drop-t { font-size: .92rem; font-weight: 600; margin-top: .9rem; }
.up-drop-s { font-size: .8rem; color: var(--muted-foreground); margin-top: .2rem; }

.up-file {
  display: flex; align-items: center; gap: .75rem; margin-top: 1rem;
  border: 1px solid var(--border); border-radius: var(--radius-xl); padding: .85rem .95rem;
}
.up-file.bad { border-color: oklch(0.577 0.245 27.3 / .45); }
.up-file-ico {
  width: 38px; height: 38px; border-radius: 10px; flex: none; display: grid; place-items: center;
  color: var(--primary); background: oklch(0.557 0.241 28.59 / .09);
}
.up-file-body { flex: 1; min-width: 0; }
.up-file-name { font-size: .9rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-file-meta { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; font-size: .78rem; color: var(--muted-foreground); margin-top: .1rem; }
.up-file-meta svg { vertical-align: -2px; }
.up-dot { color: var(--dim); }
.up-ok { color: var(--success); display: inline-flex; align-items: center; gap: .25rem; }
.up-bad { color: var(--danger); display: inline-flex; align-items: center; gap: .25rem; }
.up-run { color: var(--muted-foreground); }
.up-bar { height: 6px; border-radius: 999px; background: var(--muted); overflow: hidden; margin-top: .5rem; }
.up-bar i { display: block; height: 100%; border-radius: 999px; background: var(--primary); transition: width .2s; }
.up-pct { font-size: .78rem; font-weight: 600; color: var(--muted-foreground); font-variant-numeric: tabular-nums; flex: none; }
.up-del {
  flex: none; width: 32px; height: 32px; border-radius: 8px; border: none; background: transparent;
  color: var(--muted-foreground); cursor: pointer; display: grid; place-items: center; transition: background .15s, color .15s;
}
.up-del:hover { background: oklch(0.577 0.245 27.3 / .1); color: var(--danger); }


/* ป้ายชื่อหน่วยปกครองบนชั้นข้อมูลประชากร */
.pop-tag {
  white-space: nowrap; font-size: .68rem; font-weight: 600; color: #fff;
  background: oklch(0.35 0.12 295 / .88); padding: .1rem .38rem; border-radius: var(--radius-sm);
  transform: translate(-50%, -34px); width: max-content;
}

/* ─── Dropdown ที่จำกัดความสูงเอง (รายการยาวเกินจอ) ─────── */
.dd { position: relative; }
.dd-native { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.dd-btn {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  text-align: left; cursor: pointer;
}
.dd-btn:focus-visible { outline: 3px solid oklch(0.557 0.241 28.59 / 0.4); outline-offset: 1px; }
.dd-placeholder { color: var(--dim); }
.dd-menu {
  position: absolute; z-index: 40; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--card); border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: .25rem;
  /* แสดง 6 รายการพอดี ที่เหลือเลื่อนดู */
  max-height: calc(6 * 33px + .5rem); overflow-y: auto; overscroll-behavior: contain;
}
.dd-opt {
  display: block; width: 100%; text-align: left; border: none; background: transparent;
  padding: .45rem .6rem; border-radius: var(--radius-md); cursor: pointer;
  font-size: .84rem; color: var(--foreground); line-height: 1.35;
}
.dd-opt:hover { background: var(--muted); }
.dd-opt.on { background: var(--accent); color: var(--brand-600); font-weight: 600; }

/* ─── แถบน้ำหนัก ควรทำ / ไม่ควรทำ (หน้าผลการประเมิน) ──── */
.rec-wrap { margin: .5rem 0 .7rem; }
.rec-head { display: flex; align-items: baseline; justify-content: space-between; gap: .6rem; margin-bottom: .4rem; }
.rec-head b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.rec-do { color: var(--success); }
.rec-dont { color: var(--danger); }
.rec-dim { font-size: .95rem !important; color: var(--muted-foreground); font-weight: 600; }
.rec-none { font-size: 1rem !important; color: var(--muted-foreground); }
.rec-bar {
  display: flex; height: 12px; border-radius: 999px; overflow: hidden;
  background: var(--muted); border: 1px solid var(--border);
}
.rec-bar-do { background: var(--success); }
.rec-bar-dont { background: var(--danger); }
.rec-bar-none { width: 100%; background: repeating-linear-gradient(90deg, var(--border) 0 8px, transparent 8px 16px); }
.rec-note { font-size: .7rem; color: var(--dim); line-height: 1.6; margin-top: .4rem; }

/* ป้ายลำดับ cell บนตาราง Adaptive Grid */
.cell-tag {
  font-size: .62rem; font-weight: 700; color: var(--primary);
  background: oklch(1 0 0 / .82); border: 1px solid oklch(0.557 0.241 28.59 / .35);
  border-radius: 999px; padding: 0 .3rem; width: max-content;
  transform: translate(-50%, -50%); pointer-events: none;
}

/* ตารางเทียบคู่ข้อมูลซ้ำ */
.dup-table td, .dup-table th { vertical-align: top; }
.dup-table td.dup-diff { background: var(--warning-soft); font-weight: 600; }

/* ─── Master Data ───────────────────────────────────────── */
.master-toolbar {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .9rem;
}
.master-toolbar .spacer { flex: 1; }
.master-toolbar .input-ico { max-width: 300px; flex: 1 1 220px; }
.master-toolbar .input-ico .input { padding-left: 2.2rem; }
.master-table th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.master-table th.sortable:hover { color: var(--primary); }
.master-table td { vertical-align: middle; }
.master-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap; margin-top: .8rem;
}
.row-menu { min-width: 160px; }
.area-row {
  display: flex; align-items: center; gap: .5rem; padding: .38rem .3rem;
  border-bottom: 1px solid var(--border); font-size: .86rem;
}
.area-row:last-child { border-bottom: none; }
.area-toggle {
  width: 22px; height: 22px; flex-shrink: 0; border: none; background: transparent;
  cursor: pointer; color: var(--muted-foreground); font-size: .8rem; border-radius: var(--radius-sm);
}
.area-toggle:hover:not(:disabled) { background: var(--muted); color: var(--foreground); }
.area-toggle:disabled { cursor: default; opacity: .45; }
.area-name { font-weight: 600; }
.area-count { margin-left: auto; font-size: .72rem; color: var(--dim); white-space: nowrap; }
@media (max-width: 860px) {
  .master-toolbar .input-ico { max-width: none; }
  .master-toolbar #mdAdd, .master-toolbar #areaSync, .master-toolbar #areaImport { flex: 1 1 auto; }
}

/* ─── ความครอบคลุมการกวาด (ช่อง x หมวด) ─────────────────────────── */
.cov-bar {
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem .75rem; margin-bottom: .5rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  font-size: .82rem; color: var(--txt);
}
.cov-sum { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.cov-sum b { font-size: 1rem; }
.cov-chip { display: inline-flex; align-items: center; gap: .3rem; color: var(--muted); }
.cov-chip i {
  width: .7rem; height: .7rem; border-radius: 2px; display: inline-block;
  border: 1px solid oklch(0 0 0 / .18);
}
.cov-legend-wrap {
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem; flex-wrap: wrap; margin-top: .5rem;
}
.cov-legend { display: flex; align-items: center; gap: .85rem; flex-wrap: wrap; }
.cov-key {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .76rem; color: var(--muted);
}
.cov-key i {
  width: .85rem; height: .85rem; border-radius: 2px;
  display: inline-block; border: 1.5px solid;
}
