/* =============================================
   SMPK-EMS — Design System
   Samutprakan Emergency Medical Services
   ระบบบริการการแพทย์ฉุกเฉิน จังหวัดสมุทรปราการ
   ============================================= */

@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap');

:root {
  /* Brand colors */
  --blue:        #185FA5;
  --blue-dark:   #0C447C;
  --blue-light:  #E6F1FB;
  --blue-mid:    #378ADD;

  /* Status colors */
  --green:       #1D9E75;
  --green-light: #E1F5EE;
  --red:         #E24B4A;
  --red-light:   #FCEBEB;
  --amber:       #EF9F27;
  --amber-light: #FAEEDA;

  /* Neutrals */
  --bg:          #F5F7FB;
  --card:        #FFFFFF;
  --border:      #DDE3EE;
  --text:        #1A1A1A;
  --muted:       #6B7280;
  --hint:        #9CA3AF;

  /* Layout */
  --sidebar-w:   220px;
  --radius:      10px;
  --radius-lg:   14px;
}

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

html, body {
  font-family: 'Sarabun', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  height: 100%;
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; }

/* =============================================
   LOGIN SCREEN
   ============================================= */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #F5F7FB 0%, #E6F1FB 100%);
  padding: 20px;
}

.login-card {
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;   /* เท่ากับการ์ด login ของ DATA-ALS */
  box-shadow: 0 8px 32px rgba(24, 95, 165, 0.08);
  text-align: center;
}

.login-logo-wrap {
  position: relative;
  height: 90px;        /* กล่องโลโก้ (โลโก้ลอยคร่อมขอบการ์ด จึงใช้พื้นที่ในการ์ดแค่ครึ่งล่าง) */
  margin-bottom: 0;
}

.login-logo-img {
  position: absolute;  /* โลโก้ลอยคร่อมขอบบนการ์ด กึ่งกลาง */
  left: 50%;
  top: -120px;
  transform: translateX(-50%);
  width: 200px;
  height: 200px;
  box-sizing: border-box;
  padding: 6px;
  border-radius: 50%;
  background: var(--card);
  object-fit: contain;
  -webkit-user-drag: none;   /* ล็อกโลโก้: ห้ามลาก/เลือก/กดค้างบันทึกภาพ */
  user-select: none;
  -webkit-touch-callout: none;
  box-shadow: 0 6px 24px rgba(24, 95, 165, 0.22);
}

.login-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.login-sub {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
  line-height: 1.5;
}

.login-form {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-top: 12px;
  margin-bottom: 4px;
}

.field-input {
  width: 100%;
  padding: 11px 14px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: 'Sarabun', sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: border-color .15s, background .15s;
}

.field-input:focus {
  outline: none;
  border-color: var(--blue);
  background: #fff;
}

.login-error {
  background: var(--red-light);
  color: #A32D2D;
  font-size: 13px;
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-top: 14px;
}

.login-foot {
  text-align: center;
  font-size: 11px;
  color: var(--hint);
  margin-top: 20px;
}

.login-credit {
  text-align: center;
  font-size: 10px;
  color: var(--hint);
  margin-top: 6px;
  opacity: 0.7;
}

/* =============================================
   BUTTONS
   ============================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  font-family: 'Sarabun', sans-serif;
  border: none;
  border-radius: var(--radius);
  padding: 11px 20px;
  cursor: pointer;
  transition: background .15s, transform .05s;
}
.btn:active { transform: scale(0.98); }
.btn-block { width: 100%; margin-top: 20px; }

.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.btn-secondary { background: var(--bg); color: var(--text); border: 0.5px solid var(--border); }
.btn-secondary:hover { background: #ECEFF5; }

.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #C23B3A; }

.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { background: #157A5C; }

.btn-sm { padding: 6px 14px; font-size: 13px; }

/* Spinner */
.spin {
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =============================================
   APP SHELL / LAYOUT
   ============================================= */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: #F8FAFF;
  border-right: 0.5px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sb-top { padding: 16px 16px 0; }

.sb-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 16px;
  border-bottom: 0.5px solid var(--border);
  margin-bottom: 0;
}

.sb-brand-img {
  width: 42px;
  height: 42px;
  object-fit: contain;
  border-radius: 8px;
  flex-shrink: 0;
}

.sb-brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sb-logo {
  font-size: 15px;
  font-weight: 700;
  color: var(--blue);
  line-height: 1.2;
  white-space: nowrap;
}

.sb-sub {
  font-size: 10px;
  color: var(--hint);
  margin-top: 2px;
  line-height: 1.4;
}

.sb-shift {
  margin: 14px 0;
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
}

.sb-shift-label {
  font-size: 10px;
  color: var(--hint);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.sb-shift-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.sb-shift-val {
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 500;
}

.sb-nav { padding: 8px 0; flex: 1; overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 18px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all .15s;
}

.nav-item:hover { background: var(--blue-light); color: var(--blue); }

.nav-item.active {
  background: var(--blue-light);
  color: var(--blue);
  border-left-color: var(--blue);
  font-weight: 500;
}

.nav-item i { font-size: 18px; flex-shrink: 0; width: 20px; text-align: center; }

/* เลือกเวลาที่แจ้ง ว.12: ปุ่มสี่เหลี่ยม 2 ช่อง กว้างเต็มกรอบการ์ด (เวลานี้ | ลงเวลา→ช่องใส่เวลา) */
.w12-when-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.w12-when-btn { padding: 11px 8px; font-size: 14px; font-weight: 600; font-family: inherit; border: 1.5px solid var(--border); background: var(--card); color: var(--text); border-radius: 6px; cursor: pointer; }
.w12-when-btn:hover { border-color: var(--blue-mid); }
.w12-when-btn.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.w12-when-input .field-input { height: 100%; min-height: 42px; text-align: center; font-size: 15px; font-weight: 600; border: 1.5px solid var(--blue); border-radius: 6px; }

/* ประวัติ ว.12/ว.14 — เส้นคั่นเมื่อเปลี่ยนเวร (เช้า/บ่าย/ดึก) */
.data-table tr.w12-shift-break > td { border-top: 2px solid var(--blue); }

/* เส้นขีดแบ่งก่อนลิงก์ออกไประบบภายนอก (DATA-ALS) ท้ายเมนู */
.nav-divider { height: 1px; background: var(--border); margin: 8px 18px; }

.sb-user {
  padding: 14px 16px;
  border-top: 0.5px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;  /* กึ่งกลาง */
}

.sb-user-role-row {
  display: flex;
  align-items: center;
  justify-content: center;  /* กึ่งกลาง */
  gap: 8px;
  width: 100%;
}

.sb-user-role {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  background: var(--blue-light);
  color: var(--blue);
  padding: 2px 9px;
  border-radius: 99px;
}

.sb-user-role-row .theme-toggle-btn {
  width: 26px;
  height: 26px;
  font-size: 13px;
  border-radius: 7px;
}

.sb-user-name {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
  margin-top: 6px;
  text-align: center;
}

.toast.warning { border-left: 3px solid var(--amber); }

.sb-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  margin-top: 10px;
  padding: 10px 14px;
  white-space: nowrap;
  cursor: pointer;
  transition: all .15s;
}
.sb-logout:hover { color: var(--red); border-color: var(--red); background: var(--red-light); }

/* Main content */
.main {
  flex: 1;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  background: #fff;
  border-bottom: 0.5px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
}
.topbar-title { font-size: 16px; font-weight: 600; color: var(--text); line-height: 1.2; }
.topbar-province { font-size: 11px; color: var(--hint); margin-top: 1px; }

.topbar-shift {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 0.5px solid var(--border);
  border-radius: 10px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--blue);
}
.topbar-shift .ti { font-size: 16px; }

.topbar-clock {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--blue-light);
  border: 0.5px solid #C7DCF2;
  border-radius: 10px;
  padding: 7px 16px 7px 12px;
}

.topbar-clock-icon {
  font-size: 18px;
  color: var(--blue);
  display: flex;
  align-items: center;
}

.topbar-clock-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.25;
}

.topbar-clock-time {
  font-size: 16px;
  font-weight: 700;
  color: var(--blue);
  font-family: 'Sarabun', monospace;
  letter-spacing: .03em;
  font-variant-numeric: tabular-nums;
}

.topbar-clock-date {
  font-size: 10.5px;
  color: var(--muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
/* เครดิตผู้พัฒนา — ข้อความตกแต่งจางๆ หน้าปุ่มธีม (ซ่อนเมื่อจอแคบ ไม่ให้ชนชื่อหน้า/นาฬิกา) */
.topbar-credit { font-size: 11px; color: var(--hint); opacity: .8; white-space: nowrap; user-select: none; margin-right: 4px; }
@media (max-width: 720px) { .topbar-credit { display: none; } }

/* ย่อเมนูข้าง sidebar-hidden mode (desktop only) */
.sidebar { transition: width .2s ease, border .2s ease; }

@media (min-width: 721px) {
  body.fs-sidebar-hidden .sidebar {
    width: 0 !important;
    overflow: hidden;
    border-right: none;
    padding: 0;
  }
  /* ปุ่มสามขีดย่อ/ขยายเมนูข้าง แสดงตลอดบน desktop (ไม่ต้องเข้า fullscreen) */
  /* specificity สูงกว่า #fs-menu-btn {display:none} ที่ประกาศถัดลงไป */
  .topbar #fs-menu-btn { display: flex; }
}

/* Hamburger ใน topbar — ซ่อนบนมือถือ (มีแถบเมนูล่างอยู่แล้ว) ; desktop แสดงตลอด */
#fs-menu-btn {
  display: none;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 0.5px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 17px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s;
  margin-right: 8px;
}
#fs-menu-btn:hover { background: var(--bg); }

/* ปุ่ม icon ใน topbar (theme) — desktop เท่านั้น */
.topbar-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 0.5px solid var(--border);
  background: var(--card);
  color: var(--hint);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all .15s;
  flex-shrink: 0;
}
.topbar-icon-btn:hover { color: var(--blue); border-color: var(--blue-mid); }
.topbar-icon-btn.mode-dark { color: var(--amber); }

/* ซ่อน theme button ใน sidebar บน desktop — มีใน topbar แล้ว */
.desktop-hidden { display: none !important; }

.theme-toggle-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 0.5px solid var(--border);
  background: var(--card);
  color: var(--hint);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all .15s;
  flex-shrink: 0;
}
.theme-toggle-btn:hover { color: var(--blue); border-color: var(--blue-mid); }
.theme-toggle-btn.mode-dark { color: var(--amber); }
.theme-toggle-btn.mode-auto { color: var(--blue); }

.content {
  padding: 24px;
  flex: 1;
  overflow-y: auto;
}

.page-section {
  animation: fadeIn .2s ease;
}

/* ระบบ Dispatcher EMD (mockup) */
.emd-mock-banner { display:flex; align-items:center; gap:8px; padding:8px 12px; margin-bottom:12px; border-radius:var(--radius); background:var(--amber-light); color:#854F0B; font-size:12.5px; font-weight:600; }
body.theme-dark .emd-mock-banner { color:#F3C980; }
.emd-dayhead { display:flex; flex-wrap:wrap; align-items:center; gap:10px; padding:10px 12px; margin-bottom:6px; background:var(--card); border:0.5px solid var(--border); border-radius:var(--radius); }
.emd-dayhead-main { flex:1 1 220px; min-width:0; text-align:center; }
.emd-dayhead-title { font-size:17px; font-weight:700; color:var(--text); }
.emd-dayhead-sub { font-size:14px; font-weight:600; color:var(--blue); margin-top:3px; }
.emd-daynav { border:0.5px solid var(--border); background:var(--bg); color:var(--text); width:38px; height:38px; border-radius:var(--radius); cursor:pointer; font-size:18px; display:inline-flex; align-items:center; justify-content:center; flex-shrink:0; }
.emd-daynav:hover { background:var(--blue-light); color:var(--blue); border-color:var(--blue-mid); }
.emd-daypick, .emd-monthsel { width:auto; min-width:140px; }
.emd-daynav:disabled { opacity:.35; cursor:not-allowed; }
.emd-daynav:disabled:hover { background:var(--bg); color:var(--text); border-color:var(--border); }
/* ป้ายเวร — เหมือน .topbar-shift ของ top nav (พื้นขาว ขอบบาง ตัวอักษรสีน้ำเงิน + ไอคอน) */
.emd-shift-badge { display:inline-flex; align-items:center; gap:5px; background:#fff; border:0.5px solid var(--border); border-radius:10px; padding:3px 10px; font-size:12.5px; font-weight:600; color:var(--blue); white-space:nowrap; line-height:1.5; }
.emd-shift-badge .ti { font-size:15px; }
.emd-report .emd-shift-badge { border:1px solid #DDE3EE; color:#185FA5; }
.emd-chip { display:inline-block; padding:2px 10px; border-radius:999px; font-size:12px; font-weight:600; line-height:1.5; white-space:nowrap; }
.emd-table td, .emd-table th { white-space:nowrap; vertical-align:middle; }
.emd-table td.emd-wrap { white-space:normal; min-width:180px; max-width:340px; }
.emd-table tr.emd-shift-first td { border-top:2px solid var(--muted); }
.emd-table tbody tr.emd-shift-first:first-child td { border-top:none; }
.emd-table tr.emd-row-flag td { background:rgba(250,204,21,.22); }
.emd-iconbtn { border:none; background:none; cursor:pointer; padding:4px 6px; border-radius:6px; color:var(--muted); font-size:16px; }
.emd-set-body { max-height:60vh; overflow-y:auto; padding-right:4px; }
.emd-set-sec + .emd-set-sec { margin-top:16px; padding-top:14px; border-top:1px solid var(--border); }
.emd-set-title { font-size:14px; font-weight:700; color:var(--text); }
.emd-set-hint { font-size:12px; color:var(--muted); margin:2px 0 8px; }
.emd-set-row { display:flex; align-items:center; justify-content:space-between; gap:10px; padding:6px 0; flex-wrap:wrap; }
.emd-set-name { min-width:130px; }
.emd-set-swatches { display:flex; gap:6px; flex-wrap:wrap; }
.emd-swatch { width:26px; height:26px; border-radius:50%; border:1px solid rgba(0,0,0,.15); cursor:pointer; display:inline-flex; align-items:center; justify-content:center; font-size:14px; padding:0; }
.emd-emoji { margin-left:4px; font-size:15px; line-height:1; vertical-align:middle; }
.emd-emoji-btn { margin-left:6px; min-width:30px; height:30px; padding:0 6px; border:1px dashed var(--border,rgba(0,0,0,.25)); border-radius:15px; background:transparent; color:var(--hint); cursor:pointer; font-size:16px; line-height:1; vertical-align:middle; display:inline-flex; align-items:center; justify-content:center; }
.emd-emoji-btn:hover { border-color:var(--blue); color:var(--blue); }
.emd-emoji-btn.has { border-style:solid; background:var(--card); }
.emd-emoji-pop { position:fixed; z-index:2100; width:300px; background:#fff; border:1px solid var(--border); border-radius:12px; box-shadow:0 8px 28px rgba(0,0,0,.22); padding:8px; }
.emd-emoji-scroll { max-height:240px; overflow-y:auto; overscroll-behavior:contain; }
.emd-emoji-cat { font-size:11.5px; font-weight:700; color:var(--hint); margin:6px 2px 4px; }
.emd-emoji-grid { display:grid; grid-template-columns:repeat(8,1fr); gap:2px; }
.emd-emoji-opt { aspect-ratio:1; border:0; border-radius:8px; background:transparent; cursor:pointer; font-size:19px; padding:0; }
.emd-emoji-opt:hover { background:var(--blue-light,#E6F1FB); }
.emd-emoji-opt.active { outline:2px solid var(--blue); }
.emd-emoji-clear { width:100%; margin-top:8px; }
.emd-swatch.active { outline:2px solid var(--blue); outline-offset:2px; }
.emd-iconbtn:hover { background:var(--blue-light); color:var(--blue); }
.emd-iconbtn.danger:hover { background:var(--red-light); color:var(--red); }
.emd-foot { display:flex; flex-wrap:wrap; align-items:center; justify-content:space-between; gap:10px; margin-top:10px; }
.emd-stats { display:flex; flex-wrap:wrap; gap:8px; }
.emd-stat { padding:6px 12px; border-radius:var(--radius); background:var(--blue-light); color:var(--blue); font-size:13px; font-weight:600; white-space:nowrap; }
.emd-stat b { font-size:15px; }
.emd-count-foot { margin-left:auto; text-align:right; font-size:14px; font-weight:600; color:var(--text); display:flex; align-items:center; gap:12px; }
.emd-reportbtn { font-weight:700; padding:8px 16px; }
.emd-spacer { flex:1 1 auto; }

/* สรุปยอด (popup Dashboard) — สีตายตัว ไม่ตามธีม เพื่อให้ภาพ/PDF ที่ส่งออกอ่านง่ายเหมือนกันทุกเครื่อง */
.emd-report-bar { display:flex; flex-wrap:wrap; align-items:center; gap:8px; margin-bottom:12px; }
.emd-report-scroll { overflow-x:auto; }
.emd-report { background:#fff; color:#1A1A1A; padding:20px; border-radius:12px; border:1px solid #DDE3EE; min-width:720px; -webkit-print-color-adjust:exact; print-color-adjust:exact; }
.emd-report * { box-sizing:border-box; }
.emd-r-head { display:flex; justify-content:space-between; align-items:flex-start; gap:12px; padding-bottom:12px; border-bottom:2px solid #185FA5; margin-bottom:14px; }
.emd-r-title { font-size:20px; font-weight:800; color:#0C447C; }
.emd-r-date { font-size:15px; font-weight:600; color:#185FA5; margin-top:3px; }
.emd-r-viewtag { background:#E6F1FB; color:#185FA5; font-size:12.5px; font-weight:700; padding:5px 12px; border-radius:999px; white-space:nowrap; }
.emd-r-duty-tr { text-align:right; font-size:13px; line-height:1.7; color:#374151; }
.emd-r-duty-tr b { color:#0C447C; }
.emd-r-kpis { display:grid; grid-template-columns:repeat(3, 1fr); gap:10px; margin-bottom:14px; }
.emd-r-kpi { border:1px solid #DDE3EE; border-top:4px solid #185FA5; border-radius:10px; padding:10px 8px; text-align:center; background:#F9FBFE; }
.emd-r-kpi-val { font-size:40px; font-weight:800; line-height:1.1; }
.emd-r-kpi.is-sub { border-top:1px solid #DDE3EE; background:#fff; padding:6px 8px; }
.emd-r-kpi.is-sub .emd-r-kpi-val { font-size:22px; font-weight:700; color:#374151; }
.emd-r-kpi-label { font-size:11.5px; color:#6B7280; margin-top:4px; }
.emd-r-card { border:1px solid #DDE3EE; border-radius:10px; padding:12px 14px; background:#fff; }
.emd-r-h { font-size:13.5px; font-weight:700; color:#0C447C; margin-bottom:10px; }
.emd-r-unitrow { display:flex; justify-content:space-between; align-items:center; padding:5px 0; border-bottom:1px dashed #E5E9F0; font-size:13px; }
.emd-r-unitrow:last-child { border-bottom:none; }
.emd-r-table { width:100%; border-collapse:collapse; font-size:13px; }
.emd-r-table th { background:#E6F1FB; color:#185FA5; text-align:left; padding:7px 10px; font-size:12px; }
.emd-r-table td { padding:7px 10px; border-bottom:1px solid #E5E9F0; }
.emd-r-grid3 { display:grid; grid-template-columns:repeat(3, 1fr); gap:12px; margin-bottom:12px; }
.emd-r-cols { display:flex; align-items:stretch; gap:10px; height:170px; }
.emd-r-col { flex:1; min-width:0; display:flex; flex-direction:column; align-items:center; }
.emd-r-colval { font-size:16px; font-weight:800; line-height:1.1; text-align:center; height:34px; display:flex; flex-direction:column; justify-content:flex-end; }
.emd-r-colval small { font-size:10.5px; font-weight:600; color:#6B7280; }
.emd-r-colarea { flex:1; width:100%; display:flex; align-items:flex-end; justify-content:center; border-bottom:2px solid #DDE3EE; }
.emd-r-colbar { width:100%; max-width:44px; border-radius:6px 6px 0 0; min-height:3px; }
.emd-r-collabel { font-size:11.5px; font-weight:600; text-align:center; margin-top:5px; line-height:1.25; }
.emd-r-collabel small { display:block; font-weight:400; color:#6B7280; font-size:10px; }
.emd-r-pie { display:flex; flex-direction:column; align-items:center; gap:10px; }
.emd-r-legend { width:100%; }
.emd-r-legendrow { display:flex; align-items:center; gap:7px; font-size:12.5px; padding:3px 0; }
.emd-r-legendrow b { margin-left:auto; white-space:nowrap; }
.emd-r-dot { width:11px; height:11px; border-radius:50%; flex-shrink:0; }
.emd-r-monthtable th, .emd-r-monthtable td { text-align:center; vertical-align:middle; padding:5px 8px; }
.emd-r-monthtable td .emd-chip { margin:1px 2px; }
.emd-r-monthtable tr.emd-r-dayfirst td { border-top:2px solid #9AA6B8; }
.emd-r-monthtable td.emd-r-daycell { font-weight:700; background:#F4F6FA; }
.emd-r-monthtable td.emd-r-daytotal { font-weight:800; font-size:16px; background:#FFF6D6; color:#7A5B00; }
.emd-r-monthtable tr.emd-r-totalrow td { font-weight:800; background:#E6F1FB; border-top:2px solid #185FA5; }
.emd-r-shifts { display:grid; grid-template-columns:repeat(3, 1fr); gap:12px; }
.emd-r-shifthead { display:flex; align-items:center; gap:8px; font-size:14px; margin-bottom:6px; }
.emd-r-shifthead small { color:#6B7280; }
.emd-r-shifttotal { font-size:38px; font-weight:800; color:#185FA5; line-height:1.1; margin-bottom:8px; }
.emd-r-shifttotal small { font-size:14px; font-weight:600; color:#6B7280; }
.emd-r-line { display:flex; justify-content:space-between; padding:5px 0; border-bottom:1px dashed #E5E9F0; font-size:13px; }
.emd-r-duty { margin-top:10px; font-size:12.5px; line-height:1.7; color:#374151; }
.emd-r-empty { text-align:center; padding:40px 0; color:#6B7280; font-size:15px; }
.emd-r-foot { margin-top:14px; padding-top:10px; border-top:1px solid #DDE3EE; font-size:11px; color:#6B7280; text-align:center; }
@media (max-width: 700px) {
  .emd-r-kpis { grid-template-columns:repeat(3, 1fr); }
  .emd-report { min-width:0; }
  .emd-r-grid3, .emd-r-shifts { grid-template-columns:1fr; }
}
#emd-print-root { display:none; }
@media print {
  @page { size:A4; margin:12mm; }
  body.emd-printing > *:not(#emd-print-root) { display:none !important; }
  body.emd-printing #emd-print-root { display:block !important; }
  body.emd-printing #emd-print-root .emd-report { border:none; padding:0; min-width:0; }
}
.emd-count-foot b { font-size:17px; }
.emd-addbtn { flex:0 0 auto; width:auto; margin-left:auto; padding:10px 22px; font-size:15px; font-weight:700; justify-content:center; gap:6px; border-radius:var(--radius); white-space:nowrap; }
.emd-addbtn i { font-size:18px; }
.emd-pick { display:flex; flex-wrap:wrap; gap:6px; }
.emd-pickchip { border:1px solid var(--border); background:var(--card); color:var(--text); border-radius:999px; padding:5px 12px; font-size:13px; cursor:pointer; font-family:inherit; }
.emd-pickchip:hover { border-color:var(--blue-mid); }
.emd-pickchip.active { background:var(--blue); border-color:var(--blue); color:#fff; font-weight:600; }
/* แก้ไขเร็วในตาราง: กดที่ค่าของช่อง → tooltip ช่องแก้ไข ✓ / ✗ */
.emd-table td.emd-editable { cursor:pointer; }
.emd-btn-on:disabled { background:var(--blue-light); color:var(--blue); border-color:var(--blue-mid); opacity:1; font-weight:700; }
.emd-table tr.emd-dayrow td { background:var(--blue-light); color:var(--blue); font-weight:700; font-size:13.5px; padding:8px 14px; border-top:2px solid var(--blue-mid); }
.emd-pager { display:flex; flex-wrap:wrap; justify-content:center; align-items:center; gap:6px; margin-top:12px; }
.emd-pagebtn { border:0.5px solid var(--border); background:var(--card); color:var(--text); min-width:36px; height:34px; padding:0 12px; border-radius:8px; cursor:pointer; font-size:13px; font-family:inherit; display:inline-flex; align-items:center; justify-content:center; gap:4px; }
.emd-pagebtn:hover:not(:disabled) { background:var(--blue-light); color:var(--blue); }
.emd-pagebtn.active { background:var(--blue); color:#fff; border-color:var(--blue); font-weight:700; }
.emd-pagebtn:disabled { opacity:.4; cursor:not-allowed; }
.emd-blank { color:var(--hint); display:inline-block; min-width:36px; }
.emd-cellpop { position:fixed; z-index:1400; background:#fff; color:#1A1A1A; border:1px solid #C9D2E0; border-radius:10px; box-shadow:0 8px 28px rgba(0,0,0,.25); padding:10px 12px; }
.emd-ce-label { font-size:12px; font-weight:700; color:#185FA5; margin-bottom:6px; }
.emd-ce-unitsel { min-height:22px; font-size:13px; margin-bottom:6px; font-weight:600; }
.emd-ce-actions { display:flex; justify-content:flex-end; gap:8px; margin-top:10px; }
.emd-ce-ok, .emd-ce-cancel { border:none; border-radius:8px; width:38px; height:34px; font-size:19px; cursor:pointer; display:inline-flex; align-items:center; justify-content:center; }
.emd-ce-ok { background:#1D9E75; color:#fff; }
.emd-ce-ok:hover { background:#157A5C; }
.emd-ce-cancel { background:#EEF1F6; color:#4B5563; }
.emd-ce-cancel:hover { background:#FCEBEB; color:#C0392B; }
.emd-trashbtn { flex:0 0 46px; padding:0; color:var(--red); font-size:18px; justify-content:center; }
.emd-trashbtn:hover { background:var(--red-light); }
.emd-unitbtn { display:flex; align-items:center; justify-content:space-between; gap:8px; width:100%; min-height:40px; text-align:left; cursor:pointer; font-family:inherit; }
.emd-unit-ph { color:var(--hint); }
.emd-unitpop { position:fixed; z-index:2000; background:#fff; border:1px solid var(--border); border-radius:10px; box-shadow:0 8px 28px rgba(0,0,0,.22); padding:8px; }
.emd-unitpop .field-input { margin-bottom:6px; }
.emd-unitlist { overflow-y:auto; }
/* แท็บ "ประสาน รพ.อื่นๆ" (js/emd_ref.js) */
.emd-ref-link { cursor:pointer; }
.emd-ref-link:hover { text-decoration:underline; }
.emd-ref-chain { display:inline-block; margin-left:4px; padding:1px 7px; border-radius:99px; background:var(--blue-light); color:var(--blue); font-size:11px; font-weight:600; }
.emd-ref-dir { display:grid; grid-template-columns:repeat(3, 1fr); gap:8px; margin-bottom:12px; }
.emd-ref-dirbtn { display:flex; flex-direction:column; align-items:center; gap:2px; padding:10px 8px; border:1.5px solid var(--border); border-radius:10px; background:var(--card); color:var(--muted); cursor:pointer; font-family:inherit; text-align:center; }
.emd-ref-dirbtn b { font-size:14px; color:var(--text); }
.emd-ref-dirbtn span { font-size:11px; }
.emd-ref-dirbtn.active { border-color:var(--blue); background:var(--blue-light); }
.emd-ref-dirbtn.active b { color:var(--blue); }
.emd-ref-sec-title { margin:14px 0 8px; font-size:14px; font-weight:700; color:var(--text); display:flex; align-items:center; gap:6px; }
.emd-ref-att { border:1px solid var(--border); border-radius:10px; padding:10px 12px 2px; margin-bottom:10px; background:var(--card); }
.emd-ref-att.declined { border-color:#E24B4A; background:rgba(226,75,74,.04); }
.emd-ref-att-head { display:flex; align-items:center; justify-content:space-between; margin-bottom:6px; font-size:13px; }
.emd-ref-addnext { width:100%; justify-content:center; border-style:dashed; }
.emd-pickchip:disabled { opacity:.4; cursor:not-allowed; }
.emd-pickchip.emd-chip-bad.active { background:#C0392B; border-color:#C0392B; }
.emd-pickchip.emd-chip-confirm.active { background:#6B3FA0; border-color:#6B3FA0; color:#fff; }
.emd-ref-att.confirmed { border-color:#6B3FA0; background:rgba(107,63,160,.06); }
.emd-ref-tl-head { font-size:13.5px; margin-bottom:12px; }
.emd-ref-tl { display:flex; flex-direction:column; gap:0; }
.emd-ref-tl-item { position:relative; display:flex; gap:10px; padding:0 0 14px 0; }
.emd-ref-tl-item:not(:last-child)::before { content:""; position:absolute; left:6px; top:16px; bottom:0; width:2px; background:var(--border); }
.emd-ref-tl-dot { flex-shrink:0; width:14px; height:14px; border-radius:50%; margin-top:3px; background:#EF9F27; border:2px solid var(--card); box-shadow:0 0 0 1px var(--border); }
.emd-ref-tl-item.declined .emd-ref-tl-dot { background:#C0392B; }
.emd-ref-tl-item.accepted .emd-ref-tl-dot { background:#1D9E75; }
.emd-ref-tl-item.confirmed .emd-ref-tl-dot { background:#6B3FA0; }
.emd-ref-tl-confirm { margin-top:6px; padding:8px 10px; border-radius:8px; background:#EDE7F6; color:#3F1D6E; font-size:12.5px; line-height:1.6; }
.emd-ref-tl-extra { margin-top:6px; padding:8px 10px; border-radius:8px; background:var(--bg); font-size:12.5px; line-height:1.6; white-space:pre-wrap; }
.emd-ref-tl-body { min-width:0; font-size:13.5px; }
.emd-ref-tl-meta { color:var(--muted); font-size:12.5px; margin-top:2px; }
.emd-ref-tl-why { margin-top:6px; padding:8px 10px; border-radius:8px; background:var(--red-light); color:#A32D2D; font-size:12.5px; line-height:1.6; }
.emd-unit-grouphead { position:sticky; top:0; z-index:1; padding:5px 10px; font-size:11.5px; font-weight:700; color:var(--blue); background:var(--blue-light); letter-spacing:.02em; }
.emd-form-2col { display:grid; grid-template-columns:1fr 1fr; gap:0 12px; }
.emd-form-2col .span-2 { grid-column:1 / -1; }
/* รพ.ที่ "รับ": เวลาที่ประสาน · ผล · เวลาที่รับ อยู่แถวเดียวกัน */
.emd-ref-trio { display:flex; flex-wrap:wrap; align-items:flex-start; gap:0 10px; }   /* ป้ายทุกช่องอยู่ระดับเดียวกัน */
.emd-ref-trio .field-group { flex:0 0 auto; }
.emd-ref-trio input.field-input { width:112px; }
.emd-ref-notelink { display:inline-flex; align-items:center; min-height:41px; font-size:13px; font-weight:600; color:var(--blue); text-decoration:underline; cursor:pointer; white-space:nowrap; }   /* ลิงก์ข้อความต่อจากช่องเวลาที่รับ */
.emd-ref-notelink:hover { color:var(--blue-dark, var(--blue)); text-decoration:none; }
/* ป้ายชื่อช่องอยู่เหนือช่องเสมอ (ทุกช่องในการ์ด รพ. ใช้สไตล์เดียวกัน) — .field-label เป็น inline จึงต้องบังคับ block กันช่องแคบ (เวลา) ไปอยู่ข้างป้าย */
.emd-ref-trio .field-label, .emd-form-2col .field-label { display:block; }
.emd-ref-trio .emd-pick { min-height:41px; align-items:center; }   /* สูงเท่าช่องกรอกข้างๆ */
@media (max-width: 520px) { .emd-form-2col { grid-template-columns:1fr; } }

/* ระบบโทรศัพท์ 1669 — iframe เต็มพื้นที่ content */
.call1669-wrap { height: calc(100vh - 130px); min-height: 480px; }
.call1669-frame {
  width: 100%; height: 100%;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
}
@media (max-width: 768px) {
  .call1669-wrap { height: calc(100vh - 190px); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =============================================
   SHARED COMPONENTS
   ============================================= */

/* Stat cards */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.stat-label { font-size: 12px; color: var(--text); font-weight: 500; margin-bottom: 6px; }
.stat-val { font-size: 26px; font-weight: 600; color: var(--text); line-height: 1; }
.stat-val.green { color: var(--green); }
.stat-val.red { color: var(--red); }
.stat-val.amber { color: var(--amber); }
.stat-sub { display: none; }

/* stat-card hover tooltip */
.stat-card.has-tooltip { position: relative; cursor: default; }
.stat-tooltip {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 280px;
  max-width: 360px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.13);
  z-index: 999;
  text-align: left;
}
.stat-card.has-tooltip:hover .stat-tooltip { display: block; }
.stat-tooltip-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text);
  padding: 3px 0;
  flex-wrap: nowrap;
}
.stat-tooltip-row + .stat-tooltip-row {
  border-top: 0.5px solid var(--border);
  padding-top: 5px;
  margin-top: 2px;
}
.stat-tooltip-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stat-tooltip-status {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  white-space: nowrap;
}

/* Section label */
.section-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 12px;
}

.units-section-title {
  font-size: 19px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
}
.units-section-title i { color: var(--blue); font-size: 20px; }

/* Unit cards grid */
.units-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.units-grid.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.units-grid.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
.units-grid.grid-cols-6 { grid-template-columns: repeat(6, 1fr); }

@media (max-width: 1240px) {
  .units-grid.grid-cols-4, .units-grid.grid-cols-6 { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 1024px) {
  .units-grid.grid-cols-3 { grid-template-columns: repeat(2, 1fr); }
  .units-grid.grid-cols-4, .units-grid.grid-cols-6 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 920px) {
  .units-grid.grid-cols-3, .units-grid.grid-cols-4, .units-grid.grid-cols-6 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .units-grid, .units-grid.grid-cols-3, .units-grid.grid-cols-4, .units-grid.grid-cols-6 {
    grid-template-columns: 1fr;
  }
}

/* Dashboard Hospital — หน่วยของคุณ (อัตราส่วนเดิม) + หน่วยงานอื่นเรียงข้าง scroll ได้ */
.dashboard-own-row {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 16px;
  align-items: start;
}
.dashboard-own-col,
.dashboard-other-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.dashboard-col-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 8px;
}
/* หน่วยตัวเองยืดเต็มความสูงคอลัมน์ซ้าย */
.dashboard-own-col .unit-card { flex: 1; }

/* หน่วยอื่น — grid 2 คอลัมน์ในคอลัมน์ขวา, scroll ถ้าเกิน */
.dashboard-other-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-content: start;
}

@media (max-width: 900px) {
  .dashboard-own-row { grid-template-columns: 1fr; }
  .dashboard-other-list { grid-template-columns: 1fr 1fr; }
}

/* Unit Card ที่กำลัง ว.12/ว.14 — ทั้งกล่องเป็นสีแดง */
.unit-card.is-w12 {
  background: var(--red-light);
  border-color: var(--red);
}
.unit-card.is-w12 .unit-card-body {
  border-top-color: rgba(226, 75, 74, 0.25);
}
.unit-card.is-w12 .unit-card-head .unit-name { color: #7A1F1F; }
.unit-card.is-w12 .contact-box.plate {
  background: rgba(226, 75, 74, 0.12);
  color: #A32D2D;
}
.unit-card.is-w12 .contact-box.phone {
  background: rgba(226, 75, 74, 0.08);
  border-color: rgba(226, 75, 74, 0.2);
}

/* Dark mode — กล่อง ว.12 */
body.theme-dark .unit-card.is-w12 {
  background: rgba(226, 75, 74, 0.15);
  border-color: rgba(226, 75, 74, 0.5);
}
body.theme-dark .unit-card.is-w12 .unit-card-head .unit-name { color: #FF9B9B; }
body.theme-dark .unit-card.is-w12 .unit-card-body {
  border-top-color: rgba(226, 75, 74, 0.2);
}

/* Unit Card ที่ "รอรายงานตัว" — ทั้งกล่องเป็นสีเทา */
.unit-card.is-pending {
  background: #F3F4F6;
  border-color: #D1D5DB;
}
.unit-card.is-pending .unit-card-body {
  border-top-color: #D1D5DB;
}
.unit-card.is-pending .unit-card-head .unit-name { color: #6B7280; }
.unit-card.is-pending .contact-box.plate,
.unit-card.is-pending .contact-box.phone {
  background: #E5E7EB;
  color: #6B7280;
  border-color: #D1D5DB;
}

body.theme-dark .unit-card.is-pending {
  background: rgba(255,255,255,0.04);
  border-color: rgba(255,255,255,0.12);
}
body.theme-dark .unit-card.is-pending .unit-card-head .unit-name { color: #9CA3AF; }
body.theme-dark .unit-card.is-pending .unit-card-body { border-top-color: rgba(255,255,255,0.1); }

/* Unit Card "นอกเวลาทำการ" (คำนวณอัตโนมัติ ไม่ใช่รายงานจริง) — เทาเหมือน is-pending
   แต่แยก class ต่างหากเพราะคนละความหมาย (28 ก.ย. 2569) */
.unit-card.is-outside-hours {
  background: #F3F4F6;
  border-color: #D1D5DB;
}
.unit-card.is-outside-hours .unit-card-body {
  border-top-color: #D1D5DB;
}
.unit-card.is-outside-hours .unit-card-head .unit-name { color: #6B7280; }
.unit-card.is-outside-hours .contact-box.plate,
.unit-card.is-outside-hours .contact-box.phone {
  background: #E5E7EB;
  color: #6B7280;
  border-color: #D1D5DB;
}

body.theme-dark .unit-card.is-outside-hours {
  background: rgba(255,255,255,0.04);
  border-color: rgba(255,255,255,0.12);
}
body.theme-dark .unit-card.is-outside-hours .unit-card-head .unit-name { color: #9CA3AF; }
body.theme-dark .unit-card.is-outside-hours .unit-card-body { border-top-color: rgba(255,255,255,0.1); }

/* Unit Card "ว.14" (หยุดปฏิบัติหน้าที่ทั้งหมด ไม่ใช่หยุดชั่วคราวแบบ ว.12) — เทาเหมือน is-pending/is-outside-hours
   แยกจาก is-w12 (แดง) ให้ชัดว่าคนละความรุนแรงกัน (29 ก.ย. 2569) */
.unit-card.is-w14 {
  background: #F3F4F6;
  border-color: #D1D5DB;
}
.unit-card.is-w14 .unit-card-body {
  border-top-color: #D1D5DB;
}
.unit-card.is-w14 .unit-card-head .unit-name { color: #6B7280; }
.unit-card.is-w14 .contact-box.plate,
.unit-card.is-w14 .contact-box.phone {
  background: #E5E7EB;
  color: #6B7280;
  border-color: #D1D5DB;
}

body.theme-dark .unit-card.is-w14 {
  background: rgba(255,255,255,0.04);
  border-color: rgba(255,255,255,0.12);
}
body.theme-dark .unit-card.is-w14 .unit-card-head .unit-name { color: #9CA3AF; }
body.theme-dark .unit-card.is-w14 .unit-card-body { border-top-color: rgba(255,255,255,0.1); }

.dot-grey { background: #9CA3AF; }

/* Grid size toggle */
.section-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.grid-toggle {
  display: inline-flex;
  gap: 2px;
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 3px;
}
.grid-toggle-btn {
  border: none;
  background: none;
  font-size: 12px;
  font-weight: 500;
  color: var(--hint);
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all .15s;
  display: flex;
  align-items: center;
  gap: 4px;
}
.grid-toggle-btn:hover { color: var(--blue); }
.grid-toggle-btn.active { background: var(--blue); color: #fff; }

/* ช่องค้นหาเล็ก ขวาบน (เช่น ค้นหาหน่วยงานหน้า ว.12) */
.search-input-sm {
  max-width: 220px;
  padding: 7px 12px;
  font-size: 13px;
}

/* =============================================
   ว.12 LIST VIEW (MD/EMD/Admin) — กดแจ้ง/ยกเลิกได้เร็ว
   ============================================= */
.w12-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.w12-list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  transition: border-color .15s;
}
.w12-list-row:hover { border-color: var(--blue-mid); }
.w12-list-row.is-w12 { border-left: 3px solid var(--red); }
.w12-list-row.is-pending { border-left: 3px solid #9CA3AF; background: #F9FAFB; }
body.theme-dark .w12-list-row.is-pending { background: rgba(255,255,255,0.03); }
.w12-list-row.is-outside-hours { border-left: 3px solid #9CA3AF; background: #F9FAFB; }
body.theme-dark .w12-list-row.is-outside-hours { background: rgba(255,255,255,0.03); }
.w12-list-row.is-w14 { border-left: 3px solid #9CA3AF; background: #F9FAFB; }
body.theme-dark .w12-list-row.is-w14 { background: rgba(255,255,255,0.03); }
.w12-list-row .unit-dot { margin-top: 0; }

.w12-list-info { flex: 1; min-width: 0; }
.w12-list-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
/* ประเภท (ALS/BLS) และสถานะในแถวรายชื่อ ขยายให้สมดุลกับชื่อที่ใหญ่ขึ้น */
.w12-list-detail {
  margin-top: 4px;
  font-size: 11.5px;
  color: #A32D2D;
  display: flex;
  align-items: center;
  gap: 5px;
  overflow: hidden;
  white-space: nowrap;
}
.w12-list-detail i { font-size: 13px; flex-shrink: 0; }
.w12-list-detail span:first-of-type { overflow: hidden; text-overflow: ellipsis; }
.w12-list-action { flex-shrink: 0; }

/* History pagination (แบ่งหน้าตามวัน) */
.history-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 14px;
}
.history-pagination-label {
  font-size: 13px;
  color: var(--text);
  text-align: center;
}

/* Feature toggle switch (Admin permissions tab) */
.feature-toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}
.feature-toggle input { opacity: 0; width: 0; height: 0; }
.feature-toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  border-radius: 99px;
  transition: .2s;
}
.feature-toggle-slider::before {
  position: absolute;
  content: "";
  height: 16px; width: 16px;
  left: 3px; bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: .2s;
}
.feature-toggle input:checked + .feature-toggle-slider { background: var(--green); }
.feature-toggle input:checked + .feature-toggle-slider::before { transform: translateX(18px); }

.unit-card {
  background: var(--card);
  border: 0.5px solid var(--green);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color .15s;
  min-width: 0;      /* กัน card ล้นออกนอก grid column */
  word-break: break-word; /* กัน text ยาวดัน card */
}
.unit-card:hover { border-color: var(--green); box-shadow: 0 2px 8px rgba(29,158,117,0.15); }

.unit-card.limited .unit-card-body { padding: 8px 14px 12px; }
.unit-card.limited .unit-card-head { padding-bottom: 8px; }

.unit-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
}

.unit-name { font-size: 13px; font-weight: 600; color: var(--text); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

/* badge สถานะ (ซ้าย) */
.unit-status-badge {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 6px;
  font-weight: 600;
  flex-shrink: 0;
  white-space: nowrap;
}

/* badge ระดับรถ (ขวา) */
.unit-type-badge {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 6px;
  font-weight: 700;
  flex-shrink: 0;
  letter-spacing: .03em;
}
.badge-type-als { background: #e66359; color: #fff; }
.badge-type-bls { background: var(--blue-light); color: #185FA5; }

/* label บนแผนที่ dashboard — badge ประเภท (สีตามสถานะ) + ชื่อหน่วยเป็นตัวอักษรล้วน ไม่มีกรอบ/พื้นขาว */
.dashboard-map-label {
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.dashboard-map-label .dm-badge {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .03em;
  color: #fff;
  padding: 1px 5px;
  border-radius: 4px;
  line-height: 1.5;
  box-shadow: 0 1px 3px rgba(0,0,0,.35);
}
.dashboard-map-label .dm-name {
  font-size: 11px;
  font-weight: 600;
  color: #1F2937;
  text-shadow:
    0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff,
    0 1px 2px rgba(255,255,255,.9);
}

/* badge สถานะ (พร้อม / ว.12 / ว.14) */
.badge-ready { background: var(--green-light); color: #0F6E56; }
.badge-w12   { background: #C0392B; color: #fff; }       /* สีเข้มเด่น + font ขาว */
.badge-pending-report { background: #E5E7EB; color: #4B5563; }  /* เทา — รอรายงานตัว */
.badge-outside-hours  { background: #E5E7EB; color: #4B5563; }  /* เทา — นอกเวลาทำการ (อัตโนมัติ) */
.badge-w14            { background: #E5E7EB; color: #4B5563; }  /* เทา — ว.14 หยุดปฏิบัติหน้าที่ทั้งหมด */

.unit-badge {
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 99px;
  font-weight: 500;
  flex-shrink: 0;
  white-space: nowrap;
}
.badge-busy    { background: var(--amber-light); color: #854F0B; }
.badge-pending { background: var(--amber-light); color: #854F0B; }

.unit-card-body {
  border-top: 0.5px solid #EEF0F5;
  padding: 10px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.detail-row { display: flex; align-items: flex-start; gap: 8px; font-size: 12px; }
.detail-row i { font-size: 14px; color: var(--hint); flex-shrink: 0; margin-top: 1px; }
.detail-label { font-size: 11px; color: var(--hint); margin-bottom: 1px; }
.detail-val { font-size: 12px; color: var(--text); font-weight: 500; }

/* แถวทะเบียนรถ + เบอร์โทร — กล่องสีคู่กันบรรทัดเดียว */
.contact-row {
  display: flex;
  gap: 8px;
}
.contact-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  min-width: 0;
}
.contact-box span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-box.plate {
  background: rgba(55, 138, 221, 0.07);
  border: 0.5px solid rgba(55, 138, 221, 0.25);
  color: var(--text);
}
.contact-box.plate i { font-size: 14px; color: var(--blue); }
.contact-box.phone {
  background: var(--bg);
  border: 0.5px solid var(--border);
  color: var(--text);
}
.contact-box.phone i {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px; height: 18px;
  border-radius: 5px;
  background: var(--green);
  color: #fff;
  font-size: 11px;
  flex-shrink: 0;
}

.member-row { display: flex; align-items: center; gap: 6px; }
.member-dot { width: 5px; height: 5px; border-radius: 50%; background: #B5D4F4; flex-shrink: 0; }
.member-name { font-size: 13px; color: #333; }
.member-pos { font-size: 11px; color: var(--hint); margin-left: 2px; }

/* เหตุผล ว.12/ว.14 — บรรทัดเดียว กระชับ */
.w12-reason {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--red-light);
  color: #A32D2D;
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 12px;
  margin-top: 1px;
  overflow: hidden;
  white-space: nowrap;
}
.w12-reason i { font-size: 13px; flex-shrink: 0; }
.w12-reason span { overflow: hidden; text-overflow: ellipsis; }
/* ว.14 / นอกเวลาทำการ — ไม่ใช้สีแดง (ไม่ใช่การแจ้งฉุกเฉินแบบ ว.12) แค่บอกสถานะเฉยๆ เทาจางๆ พอ */
.w12-reason.plain { background: #F3F4F6; color: #6B7280; }
body.theme-dark .w12-reason.plain { background: rgba(255,255,255,0.06); color: #9CA3AF; }
.w12-reason-time {
  flex-shrink: 0;
  opacity: .75;
  font-weight: 400;
}

/* Unit card action footer */
.unit-card-actions {
  border-top: 0.5px solid #EEF0F5;
  padding: 10px 14px;
  display: flex;
  gap: 8px;
}
.unit-card-actions .btn { flex: 1; }

/* =============================================
   FORM ELEMENTS (modals)
   ============================================= */
.field-group { margin-bottom: 14px; }

.field-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: 'Sarabun', sans-serif;
  background: var(--bg);
  resize: vertical;
  min-height: 80px;
  color: var(--text);
}
.field-textarea:focus { outline: none; border-color: var(--blue); background: #fff; }

.field-select {
  width: 100%;
  padding: 10px 14px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: 'Sarabun', sans-serif;
  background: var(--bg);
  color: var(--text);
}
.field-select:focus { outline: none; border-color: var(--blue); background: #fff; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 0.5px solid var(--border);
}
.checkbox-row:last-child { border-bottom: none; }
.checkbox-row input[type="checkbox"] {
  width: 18px; height: 18px;
  accent-color: var(--blue);
  flex-shrink: 0;
}
.checkbox-row label { font-size: 14px; flex: 1; cursor: pointer; }

/* Radio group */
.radio-group {
  display: flex;
  gap: 10px;
}
.radio-option {
  flex: 1;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: all .15s;
  text-align: center;
}
.radio-option:hover { border-color: var(--blue-mid); }
.radio-option.selected {
  border-color: var(--blue);
  background: var(--blue-light);
}
.radio-option.selected.danger {
  border-color: var(--red);
  background: var(--red-light);
}
.radio-option.selected.grey {
  border-color: #9CA3AF;
  background: #F3F4F6;
}
.radio-option-icon { font-size: 22px; margin-bottom: 4px; }
.radio-option-label { font-size: 13px; font-weight: 500; }
.radio-option-sub { font-size: 11px; color: var(--hint); margin-top: 2px; }

/* W12 type pills */
.w12type-pill {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 99px;
  margin-left: 6px;
}
.w12type-12 { background: var(--red-light); color: #A32D2D; }
.w12type-14 { background: #E5E7EB; color: #4B5563; }

/* Sidebar affiliation — สังกัดหน่วยงานของ user แสดงใต้ชื่อ */
.sb-affiliation {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

/* Readiness page */
.readiness-status-banner {
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.readiness-status-banner.ready { background: var(--green-light); border: 0.5px solid #9FE1CB; }
.readiness-status-banner.w12   { background: var(--red-light); border: 0.5px solid #F5C2C2; }
.readiness-status-banner.w14   { background: #F3F4F6; border: 0.5px solid #D1D5DB; }
.readiness-status-banner.pending { background: var(--amber-light); border: 0.5px solid #F5D9A8; }
.readiness-status-icon { font-size: 26px; }
.readiness-status-banner.ready .readiness-status-icon { color: var(--green); }
.readiness-status-banner.w12 .readiness-status-icon { color: var(--red); }
.readiness-status-banner.w14 .readiness-status-icon { color: #6B7280; }
.readiness-status-banner.pending .readiness-status-icon { color: var(--amber); }
.readiness-status-title { font-size: 14px; font-weight: 600; }
.readiness-status-detail { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.form-card {
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 560px;
  margin: 0 auto;
}
.form-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--blue);
  margin: 20px 0 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.form-section-title:first-child { margin-top: 0; }

.member-pick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
}
.member-pick {
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: pointer;
  transition: all .15s;
  display: flex;
  align-items: center;
  gap: 8px;
}
.member-pick:hover { border-color: var(--blue-mid); }
.member-pick.selected { border-color: var(--blue); background: var(--blue-light); }
.member-pick.leader.selected { border-color: var(--amber); background: var(--amber-light); }
.member-pick-name { font-size: 13px; font-weight: 500; }
.member-pick-pos { font-size: 10px; color: var(--hint); }

/* cert-level grouping for personnel selection */
.cert-group { margin-bottom: 16px; }
.cert-group-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.cert-group-empty {
  font-size: 12.5px;
  color: var(--hint);
  padding: 8px 0;
}
.member-pick-check {
  width: 18px; height: 18px;
  border-radius: 5px;
  border: 1.5px solid var(--border);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  color: transparent;
  transition: all .15s;
}
.member-pick.selected .member-pick-check {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
.member-pick-badge { font-size: 10px; color: var(--hint); margin-top: 1px; }
.selection-counter {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
}
.selection-counter.warn { color: var(--red); font-weight: 600; }

/* vehicle picker — button cards with ambulance icon */
.vehicle-pick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.vehicle-pick {
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px;
  cursor: pointer;
  transition: all .15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}
.vehicle-pick:hover { border-color: var(--blue-mid); }
.vehicle-pick.selected { border-color: var(--blue); background: var(--blue-light); }
.vehicle-pick-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  color: var(--blue);
}
.vehicle-pick.selected .vehicle-pick-icon { background: var(--blue); color: #fff; }
.vehicle-pick-plate { font-size: 12.5px; font-weight: 600; color: var(--text); }

/* History table */
.history-filters {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.duration-badge {
  font-family: monospace;
  font-size: 12px;
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
}
.duration-badge.ongoing { background: var(--red-light); color: #A32D2D; border-color: transparent; }
.duration-badge.no-cancel { font-family: inherit; background: var(--amber-light); color: #7A5200; border-color: transparent; white-space: nowrap; }
body.theme-dark .duration-badge.no-cancel { background: rgba(239,159,39,.18); color: #F2C57A; }

/* =============================================
   AMBULANCE — vehicle rows
   ============================================= */
.vehicle-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.vehicle-icon {
  font-size: 24px;
  color: var(--blue);
  flex-shrink: 0;
  width: 40px; height: 40px;
  background: var(--blue-light);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.vehicle-info { flex: 1; min-width: 180px; }
.vehicle-plate { font-family: monospace; font-size: 14px; color: var(--blue); font-weight: 600; letter-spacing: .03em; }
.vehicle-name { font-size: 13px; color: var(--text); margin-top: 2px; }
.vehicle-check-status { font-size: 12px; margin-top: 5px; display: flex; align-items: center; gap: 5px; }
.check-ok   { color: var(--green); }
.check-bad  { color: var(--red); }
.check-none { color: var(--hint); }

/* =============================================
   RESOURCES — person rows
   ============================================= */
.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
}
.search-bar i { color: var(--hint); font-size: 18px; }
.search-bar input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 14px;
  font-family: 'Sarabun', sans-serif;
  background: transparent;
  color: var(--text);
}

.unit-group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 20px 0 10px;
}
.unit-group-header:first-child { margin-top: 0; }
.unit-group-title { font-size: 14px; font-weight: 600; color: var(--text); }
.unit-group-count {
  font-size: 11px;
  background: var(--blue-light);
  color: var(--blue);
  padding: 2px 9px;
  border-radius: 99px;
  font-weight: 500;
}

.person-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 8px;
}
.person-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--blue-light);
  color: var(--blue);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600;
  flex-shrink: 0;
}
.person-info { flex: 1; }
.person-name { font-size: 13px; font-weight: 500; color: var(--text); }
.person-meta { font-size: 11px; color: var(--hint); margin-top: 2px; }
.person-phone { font-size: 12px; color: var(--muted); font-family: monospace; }

/* Tables */
/* ตาราง scroll แนวนอนบน mobile โดยไม่เลื่อนทั้งหน้า */
.table-scroll-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
}
.table-scroll-wrap .data-table { border-radius: 0; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--card); border-radius: var(--radius); overflow: hidden; }
.data-table th { background: var(--blue-light); color: var(--blue); text-align: left; padding: 10px 14px; font-weight: 600; font-size: 12px; }
.data-table td { padding: 10px 14px; border-bottom: 0.5px solid var(--border); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #FAFBFF; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  /* ต้องสูงกว่า Leaflet (.leaflet-container ไม่ได้ตั้ง z-index ของตัวเอง
     ทำให้ pane ภายในเช่น .leaflet-top/.leaflet-bottom ที่ z-index:1000 หลุดมาชนกับ modal ได้) */
  z-index: 1600;
  padding: 20px;
}
.modal-box {
  background: #fff;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  /* overflow:hidden (ไม่ใช่ auto) ให้มุมมนถูก clip สะอาดทุกด้าน —
     เนื้อหาที่ยาวเกินให้ .modal-box-inner ด้านในเป็นตัวสกอลล์แทน */
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}
.modal-box-inner {
  padding: 24px;
  overflow-y: auto;
  min-height: 0;
}
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }

/* Modal กว้างพิเศษ — สำหรับเนื้อหาที่ต้องการพื้นที่มาก เช่น จัดการโซน */
.modal-box.modal-box-wide {
  max-width: 980px;
}

/* Modal กว้างขึ้นเล็กน้อยจากค่าเริ่มต้น — สำหรับข้อความสั้นๆ ที่ตกบรรทัดง่ายเกินไปในกรอบ 420px เช่น popup ข้อมูลระบบ */
.modal-box.modal-box-medium {
  max-width: 560px;
}

/* Modal สำหรับฟอร์มยาวๆ ที่อยากจัดฟิลด์เป็น 2 คอลัมน์ (กว้างกว่า medium แต่ไม่ต้องถึง wide) */
.modal-box.modal-box-form {
  max-width: 680px;
}

/* Popup แจ้ง ว.12/ว.14 — ลดช่องว่างแนวตั้งให้พอดีจอเดียว ไม่ต้อง scroll
   (สโคปแยกจาก .form-section-title/.radio-option/.checkbox-row ทั่วระบบ ไม่กระทบฟอร์มอื่น) */
.w12-modal-compact .form-section-title { margin: 12px 0 8px; }
.w12-modal-compact .form-section-title:first-child { margin-top: 0; }
.w12-modal-compact .radio-option { padding: 9px 10px; }
.w12-modal-compact .checkbox-row { padding: 7px 0; }
.w12-modal-compact .note { margin-bottom: 10px; }
.w12-modal-compact .modal-actions { margin-top: 10px; }

/* Popup เพิ่ม/แก้ไขหน่วยงาน — ฟอร์มยาว (ชื่อ/ประเภท/เวลาทำการ/แผนที่/พิกัด) ลดช่องว่างให้พอดีจอเดียว
   (สโคปแยกจาก field-group/modal-title/modal-actions ทั่วระบบ ไม่กระทบฟอร์มอื่น) */
.unit-modal-compact .modal-title { margin-bottom: 4px; }
.unit-modal-compact .field-group { margin-bottom: 3px; }
.unit-modal-compact .modal-actions { margin-top: 6px; }
.unit-modal-compact .field-label { margin-top: 0; margin-bottom: 2px; }

/* popup บันทึกปฏิเสธออกเคส — 2 คอลัมน์ (ซ้าย: หน่วย/เหตุผล/ผู้บันทึก · ขวา: สถานที่/อาการ/หน่วยออกแทน) */
.cr-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 22px; align-items: start; }
.cr-col { min-width: 0; }
.cr-actions .btn { white-space: nowrap; }
/* ปุ่ม ว.12 ทรงสี่เหลี่ยม (กดสลับเลือก/ไม่เลือก) — หน้าตาเหมือนป้ายสถานะ ว.12 : พื้นชมพูจาง ขอบแดง ไอคอน ⊗ ตัวหนา ข้อความรองสีเทา */
.cr-w12-tile {
  display: flex; flex-direction: row; align-items: center; justify-content: center; gap: 8px;
  width: 100%; margin-top: 10px; padding: 9px 12px;
  font-family: inherit; cursor: pointer; text-align: center;
  background: var(--card); border: 1.5px solid var(--border); border-radius: 10px;
  transition: background .15s, border-color .15s;
}
.cr-w12-tile:hover { border-color: #E24B4A; }
.cr-w12-tile .cr-w12-icon { font-size: 20px; color: var(--hint); line-height: 1; }
.cr-w12-tile .cr-w12-title { font-size: 15px; font-weight: 700; color: var(--muted); line-height: 1.2; }
.cr-w12-tile.on { background: #FBEAE8; border-color: #E24B4A; }
.cr-w12-tile.on .cr-w12-icon, .cr-w12-tile.on .cr-w12-title { color: #1A1A1A; }
body.theme-dark .cr-w12-tile.on { background: rgba(226,75,74,0.16); }
body.theme-dark .cr-w12-tile.on .cr-w12-icon, body.theme-dark .cr-w12-tile.on .cr-w12-title { color: #F3F4F6; }
.cr-w12-note { margin-top: 6px; font-size: 11.5px; color: var(--hint); text-align: center; }
@media (max-width: 640px) { .cr-cols { grid-template-columns: 1fr; } }

/* จัดฟิลด์เป็น 2 คอลัมน์ต่อแถว — ใช้คู่กับ modal-box-form */
.field-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}
.field-grid-2 .field-group.span-2 { grid-column: 1 / -1; }
@media (max-width: 640px) {
  .field-grid-2 { grid-template-columns: 1fr; }
}

/* ปุ่มปิดมุมบนขวาของ modal */
.modal-close-x {
  position: absolute;
  top: 16px; right: 16px;
  width: 32px; height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--bg);
  color: var(--hint);
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all .15s;
  z-index: 10;
}
.modal-close-x:hover { background: var(--border); color: var(--text); }

/* =============================================
   ADMIN PANEL
   ============================================= */
.admin-tabs {
  display: flex;
  gap: 4px;
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 16px;
  width: fit-content;
}
.admin-tab {
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  transition: all .15s;
}
/* แถบแท็บหน้า Dispatcher EMD — พื้นขาวทึบ + เงาบาง ให้แยกจากพื้นหลังหน้าชัดเจน */
#emd-tabbar { background:var(--card); border:1px solid var(--border); box-shadow:0 1px 3px rgba(16,24,40,.10); max-width:100%; flex-wrap:wrap; }
.admin-tab:hover { color: var(--blue); }
.admin-tab.active { background: var(--blue); color: #fff; }

.admin-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

/* Admin group accordion */
.admin-group {
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}
.admin-group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg);
  cursor: pointer;
  user-select: none;
  transition: background .1s;
}
.admin-group-header:hover { background: var(--blue-light); }
.admin-group-name { flex: 1; font-size: 13px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 7px; }
.admin-group-count { font-size: 11px; color: var(--hint); background: var(--card); border: 0.5px solid var(--border); border-radius: 99px; padding: 1px 8px; }
.admin-group-chevron { font-size: 16px; color: var(--hint); transition: transform .2s; }
.admin-group-body { border-top: 0.5px solid var(--border); }
.admin-group-body .data-table { margin: 0; border-radius: 0; border: none; }

.admin-group.collapsed .admin-group-body { display: none; }
.admin-group.collapsed .admin-group-chevron { transform: rotate(-90deg); }

body.theme-dark .admin-group-header { background: var(--bg); }
body.theme-dark .admin-group-header:hover { background: rgba(55,138,221,0.1); }

.admin-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.role-tag {
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 99px;
  font-weight: 500;
}
.role-admin { background: var(--red-light); color: #A32D2D; }
.role-emd   { background: var(--blue-light); color: var(--blue); }
.role-md    { background: var(--green-light); color: #0F6E56; }

.status-pill {
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 99px;
  font-weight: 500;
}
.status-active   { background: var(--green-light); color: var(--green); }
.status-inactive { background: var(--bg); color: var(--hint); }

.icon-btn {
  background: none;
  border: 0.5px solid var(--border);
  border-radius: 6px;
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  transition: all .15s;
}
.icon-btn:hover { background: var(--blue-light); color: var(--blue); border-color: var(--blue); }

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 80px 20px;
  color: var(--hint);
}
.empty-icon { font-size: 48px; margin-bottom: 16px; color: var(--border); }
.empty-title { font-size: 16px; font-weight: 500; color: var(--muted); margin-bottom: 6px; }
.empty-text { font-size: 13px; color: var(--hint); }

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
}
.toast {
  background: #fff;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  animation: slideIn .2s ease;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--blue); }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

@media (max-width: 720px) {
  .toast-container {
    bottom: auto;
    top: 70px;
    left: 12px;
    right: 12px;
  }
  .toast {
    min-width: 0;
    width: 100%;
    animation: slideInTop .2s ease;
  }
  @keyframes slideInTop {
    from { opacity: 0; transform: translateY(-12px); }
    to   { opacity: 1; transform: translateY(0); }
  }
}

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 720px) {
  /* ซ่อน sidebar desktop ในมือถือ */
  .app-shell { flex-direction: column; height: auto; min-height: 100dvh; }
  .sidebar { display: none; }
  .content { padding: 14px 12px 80px; } /* 80px = เว้นให้ bottom nav */
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .dashboard-list-cols { grid-template-columns: 1fr; }
  .topbar { padding: 0 14px; }

  /* บน mobile ให้ปุ่ม theme ใน sidebar กลับมาแสดง (topbar ไม่มีปุ่มบน mobile) */
  .desktop-hidden { display: flex !important; }

  /* ซ่อนปุ่ม theme ใน topbar บน mobile */
  #topbar-theme-btn { display: none; }
  .form-card { padding: 16px; max-width: 100%; }

  /* =============================================
     หน้ารายงานตัว — Mobile
     ============================================= */

  /* shift-status-card เต็มความกว้าง */
  .shift-status-card { padding: 10px 14px; margin-bottom: 12px; }
  .shift-status-icon { font-size: 22px; }
  .shift-status-name { font-size: 14px; }
  .shift-status-date { font-size: 11px; }

  /* vehicle dropdown เต็มกว้าง */
  .vehicle-pick-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .vehicle-pick { padding: 10px 8px; }
  .vehicle-pick-plate { font-size: 11.5px; }

  /* cert-group titles เล็กลง */
  .cert-group-title { font-size: 12px; padding: 6px 10px; }

  /* selected person tags ขนาดพอดี */
  .selected-person-tag { font-size: 12px; padding: 5px 10px; }
  .selected-person-tags { gap: 5px; }

  /* radio-group ว.12/รายงานตัว ซ้อนกันแนวตั้ง */
  .radio-group { flex-direction: column; gap: 8px; }
  .radio-option { padding: 12px; }
  .radio-option-label { font-size: 14px; }
  .radio-option-sub { font-size: 11px; }

  /* checkbox เหตุผล ว.12 */
  .checkbox-row { padding: 9px 0; }
  .checkbox-row label { font-size: 13px; }

  /* ปุ่มบันทึก/ยกเลิก */
  .modal-actions { flex-direction: column; gap: 8px; }
  .modal-actions .btn { width: 100%; justify-content: center; }

  /* readiness status banner */
  .readiness-status-banner { padding: 12px 14px; }
  .readiness-status-icon { font-size: 22px; }
  .readiness-status-title { font-size: 13px; }
  .readiness-status-detail { font-size: 11px; }

  /* member-pick summary in reported card */
  .member-pick-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
  .member-pick { padding: 8px; }
  .member-pick-name { font-size: 12px; }
  .member-pick-pos { font-size: 10px; }

  /* contact-row plate + phone */
  .contact-box { font-size: 12px; padding: 6px 8px; }

  /* history accordion */
  .history-accordion-btn { font-size: 13px; padding: 11px 14px; }
  .history-accordion-body { padding: 10px; }
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 7px 8px; white-space: nowrap; }

  /* ตารางทุกอันใน mobile — scroll แนวนอนเฉพาะกล่องตาราง ไม่เลื่อนทั้งหน้า */
  .data-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
    border: 0.5px solid var(--border);
  }
  .data-table-wrap .data-table {
    border-radius: 0;
    border: none;
    min-width: 560px;
  }
  /* Admin table scroll — CSS only approach */
  .admin-tab-content .data-table,
  .admin-group-body .data-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    width: 100%;
  }

  /* =============================================
     หน้า ว.12 — Mobile
     ============================================= */

  /* section-label-row ซ้อนแนวตั้ง */
  .section-label-row { flex-direction: column; align-items: flex-start; gap: 8px; }
  .search-input-sm { max-width: 100%; width: 100%; }

  /* w12-list-row ซ้อนบนมือถือ */
  .w12-list-row {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }
  /* unit-card-head mobile — ALS > ชื่อ > สถานะ */
  .unit-card-head { flex-wrap: nowrap; }
  .unit-type-badge { order: 1; flex-shrink: 0; }
  .unit-card-head .unit-name { order: 2; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .unit-card-head .unit-card-badges,
  .unit-card-head .unit-status-badge { order: 3; flex-shrink: 0; }

  .w12-list-row {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }
  .w12-list-info { flex: 1 1 100%; order: 2; }
  .w12-list-action { order: 3; width: 100%; }
  .w12-list-action .btn { width: 100%; justify-content: center; }
  .w12-list-name { font-size: 13px; flex-wrap: wrap; gap: 6px; }
  .w12-list-detail { font-size: 11px; white-space: normal; }

  /* pagination */
  .history-pagination { flex-direction: column; gap: 8px; text-align: center; }
  .history-pagination .btn { width: 100%; justify-content: center; }
  .history-pagination-label { font-size: 12px; }

  /* w12 inline form (Hospital) */
  .form-card .radio-group { flex-direction: column; }

  /* ซ่อน mobile-nav เมื่ออยู่หน้า Login */
  body.is-login .mobile-nav { display: none !important; }

  /* Login screen — ขยับ card ขึ้นเล็กน้อยบน mobile */
  .login-screen { align-items: flex-start; padding-top: max(10vh, 110px); }

  /* ซ่อน grid toggle บน mobile — ยังไงก็แสดงตาม mobile อยู่แล้ว */
  .grid-toggle { display: none; }

  /* touch: tooltip กดเพื่อเปิด/ปิด แทน hover */
  .stat-card.has-tooltip .stat-tooltip { display: none !important; }
  .stat-card.has-tooltip.tooltip-open .stat-tooltip {
    display: block !important;
    /* fixed กึ่งกลางจอแนวตั้ง เว้นขอบซ้ายขวา 16px — ไม่มีทางล้นขอบจอ ไม่ว่ากล่องอยู่ตำแหน่งไหน */
    position: fixed;
    left: 16px;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: auto;
    min-width: 0;
    max-width: none;
    max-height: 70vh;
    overflow-y: auto;
    z-index: 1500;
  }
  /* พื้นหลังจางๆ ตัดสมาธิตอนเปิด tooltip บนมือถือ */
  .stat-card.has-tooltip.tooltip-open::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 1499;
  }
}

/* =============================================
   HOSPITAL/EMS ROLE
   เนื้อหาเต็มความกว้างเท่า role อื่น (ฟอร์มต่างๆ self-center ด้วย .form-card)
   ============================================= */

/* =============================================
   DARK MODE (Night mode)
   เปิดผ่านปุ่มข้างนาฬิกา — แบบ manual หรือ auto ตามเวลา
   Auto: Day 07:00-19:00 / Night 19:01-06:59
   ============================================= */
body.theme-dark {
  --bg:          #0E1420;
  --card:        #19253A;
  --border:      #2C3D57;
  --text:        #F7FAFF;      /* ขาวสว่างมาก */
  --muted:       #D0DCF0;      /* เทาสว่างมาก */
  --hint:        #B0C0DC;      /* เทาสว่างขึ้น */

  --blue-light:  rgba(55, 138, 221, 0.18);
  --green-light: rgba(29, 158, 117, 0.20);
  --red-light:   rgba(226, 75, 74, 0.20);
  --amber-light: rgba(239, 159, 39, 0.20);
}

/* พื้นผิวหลัก */
body.theme-dark .sidebar      { background: #141B2B; }
body.theme-dark .topbar       { background: var(--card); }

/* Nav bar — sidebar (desktop) */
body.theme-dark .nav-item { color: var(--text); }
body.theme-dark .nav-item:hover { color: #fff; background: rgba(55,138,221,0.18); }
body.theme-dark .nav-item.active { color: #fff; }

/* Mobile bottom nav */
body.theme-dark .mobile-nav-item { color: var(--text); }
body.theme-dark .mobile-nav-item.active { color: #fff; }

/* ฟอนต์สีฟ้า/น้ำเงิน (var(--blue)) ที่ใช้เป็น "ตัวอักษร" — เปลี่ยนเป็นสว่างขึ้นให้อ่านง่ายใน dark mode
   (ไม่กระทบพื้นหลัง/border ที่ยังใช้ --blue ปกติ เพราะ override เฉพาะ color ของ text) */
body.theme-dark .sb-logo,
body.theme-dark .sb-affiliation,
body.theme-dark .login-logo-wrap + .login-title,
body.theme-dark .form-section-title,
body.theme-dark .contact-box.plate i,
body.theme-dark .vehicle-plate,
body.theme-dark .data-table th,
body.theme-dark .admin-tab.active,
body.theme-dark .theme-toggle-btn.mode-auto,
body.theme-dark .mobile-user-card-role {
  color: #fff !important;
}

/* นาฬิกา — เดิมตัวอักษรสีน้ำเงินบนพื้นฟ้าจางมองไม่ชัดในธีมมืด */
body.theme-dark .topbar-clock {
  background: rgba(55, 138, 221, 0.14);
  border-color: var(--border);
}
body.theme-dark .topbar-clock-time,
body.theme-dark .topbar-clock-icon {
  color: #fff;
}
body.theme-dark .modal-box    { background: var(--card); }
body.theme-dark .toast        { background: var(--card); color: var(--text); }

/* keyframes coordFadeIn/coordSlideUp ใช้ร่วมกับ .broadcast-overlay/.broadcast-box ด้านล่าง — อย่าลบ */
@keyframes coordFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes coordSlideUp {
  from { transform: translateY(24px) scale(.96); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

/* input / select / textarea */
body.theme-dark .field-input,
body.theme-dark .field-select,
body.theme-dark .field-textarea {
  background: #0E1420;
  color: var(--text);
  border-color: var(--border);
}
body.theme-dark .field-input:focus,
body.theme-dark .field-select:focus,
body.theme-dark .field-textarea:focus {
  background: #1F2B40;
}

/* unit card / detail borders ที่เคย hardcode สีอ่อน */
body.theme-dark .unit-card-body,
body.theme-dark .unit-card-actions {
  border-top-color: var(--border);
}

/* ตาราง */
body.theme-dark .data-table tr:hover td { background: #1F2B40; }

/* ชื่อบุคลากร */
body.theme-dark .member-name { color: var(--text); }
body.theme-dark .member-dot  { background: #3A5A85; }

/* ปรับสีตัวอักษรของ badge/สถานะให้อ่านง่ายบนพื้นทึบมืด */
body.theme-dark .badge-ready,
body.theme-dark .role-md {
  color: #5EE6BD;
  background: rgba(29, 158, 117, 0.25);
}
body.theme-dark .role-emd {
  color: #90C4F5;
  background: rgba(55, 138, 221, 0.25);
}
body.theme-dark .badge-w12,
body.theme-dark .unit-status-badge.badge-w12 {
  background: #C0392B;    /* แดงเข้มเหมือน day mode */
  color: #fff;            /* font ขาว มองเห็นชัด */
}
body.theme-dark .w12type-12,
body.theme-dark .w12-reason,
body.theme-dark .w12-list-detail,
body.theme-dark .duration-badge.ongoing,
body.theme-dark .role-admin {
  color: #FF9B9B;
}
body.theme-dark .badge-busy,
body.theme-dark .badge-pending {
  color: #FFC773;
}
body.theme-dark .badge-type-als { background: rgba(230, 99, 89, 0.3); color: #F5A8A3; }
body.theme-dark .badge-type-bls { background: rgba(55, 138, 221, 0.2); color: #90C4F5; }

/* login error */
body.theme-dark .login-error { color: #FF9B9B; }

/* แถบ Hospital มุมล่างมือถือ */
@media (max-width: 720px) {
  body.theme-dark.role-hospital .sb-user { background: var(--card); }
}

/* =============================================
   เพิ่มเติม: List view, shift card, countdown modal,
   dark plate color, config tab
   ============================================= */

/* Shift status card (หน้ารายงานตัว) */
.shift-status-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--blue-light);
  border: 0.5px solid var(--blue-mid);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
}
.shift-status-icon { font-size: 28px; color: var(--blue); flex-shrink: 0; }
.shift-status-name { font-size: 15px; font-weight: 600; color: var(--blue); }
.shift-status-date { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* List view — 2 column ALS | BLS */
.dashboard-list-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 8px;
}
.dashboard-list-col {
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.dashboard-list-col .dashboard-col-label {
  padding: 10px 14px;
  border-bottom: 0.5px solid var(--border);
  background: var(--bg);
}
.list-unit-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 0.5px solid var(--border);
  cursor: pointer;
  transition: background .12s;
}
.list-unit-row:hover { background: var(--blue-light); }
.list-unit-row.is-w12 {
  background: var(--red-light);
  border-left: 3px solid var(--red);
}
.list-unit-row.is-w12:hover { background: rgba(226,75,74,0.15); }
.list-unit-row.is-w12 .list-unit-name { color: #A32D2D; }
body.theme-dark .list-unit-row.is-w12 { background: rgba(226,75,74,0.15); }
body.theme-dark .list-unit-row.is-w12 .list-unit-name { color: #FF9B9B; }
.list-unit-row.is-w14 {
  background: #F3F4F6;
  border-left: 3px solid #9CA3AF;
}
.list-unit-row.is-w14 .list-unit-name { color: #6B7280; }
body.theme-dark .list-unit-row.is-w14 { background: rgba(255,255,255,0.04); }
body.theme-dark .list-unit-row.is-w14 .list-unit-name { color: #9CA3AF; }
.list-unit-name { flex: 1; font-size: 13px; font-weight: 600; color: var(--text); }
.list-unit-chevron { font-size: 14px; color: var(--hint); transition: transform .2s; flex-shrink: 0; }
.list-unit-detail { border-bottom: 0.5px solid var(--border); }
.list-unit-detail .unit-card { border-radius: 0; border: none; border-bottom: none; }
.unit-card.no-head .unit-card-body { border-top: none; padding-top: 12px; }

@media (max-width: 720px) {
  .dashboard-list-cols { grid-template-columns: 1fr; }
}

/* Dark mode — ทะเบียนรถสีขาว */
body.theme-dark .contact-box.plate { color: #fff; background: rgba(55,138,221,0.2); }
body.theme-dark .unit-card.is-w12 .contact-box.plate { color: #FF9B9B; background: rgba(226,75,74,0.18); }

/* Admin Config tab */
.config-table { width: 100%; border-collapse: collapse; }
.config-table td { padding: 10px 12px; border-bottom: 0.5px solid var(--border); font-size: 13px; }
.config-table tr:last-child td { border-bottom: none; }
.config-table td:first-child { color: var(--muted); width: 50%; }

/* Selected person tags (readiness dropdown) */
.selected-person-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
  min-height: 0;
}
.selected-person-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--blue-light);
  color: var(--blue);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12.5px;
  font-weight: 500;
}

/* =============================================
   MOBILE BOTTOM NAV BAR
   แสดงเฉพาะ mobile, ทุก role เหมือนกัน
   ============================================= */
.mobile-nav {
  display: none; /* ซ่อนบน desktop */
}

@media (max-width: 720px) {
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 64px;
    background: var(--card);
    border-top: 0.5px solid var(--border);
    z-index: 500;
    align-items: stretch;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
  }

  .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    flex: 1;
    min-width: 56px;
    padding: 8px 4px;
    background: none;
    border: none;
    font-family: inherit;
    font-size: 10px;
    color: var(--hint);
    cursor: pointer;
    text-decoration: none;
    transition: color .15s;
    white-space: nowrap;
  }
  .mobile-nav-item i { font-size: 22px; line-height: 1; }
  .mobile-nav-item span { font-size: 10px; line-height: 1; margin-top: 2px; }

  .mobile-nav-item.active {
    color: var(--blue);
  }
  .mobile-nav-item.active i {
    /* dot indicator */
    position: relative;
  }

  .mobile-nav-logout {
    color: var(--hint);
    border-left: 0.5px solid var(--border);
    flex-shrink: 0;
  }
  .mobile-nav-logout:hover, .mobile-nav-logout:active { color: var(--red); }

  /* dark mode */
  body.theme-dark .mobile-nav {
    background: var(--card);
    border-top-color: var(--border);
    box-shadow: 0 -2px 12px rgba(0,0,0,0.3);
  }
  body.theme-dark .mobile-nav-item.active { color: #90C4F5; }
}

/* topbar logo — ซ่อนบน desktop (มี sidebar logo อยู่แล้ว), แสดงเฉพาะ mobile */
.topbar-logo-img {
  width: 26px; height: 26px;
  object-fit: contain;
  border-radius: 5px;
  flex-shrink: 0;
  display: none;
}
@media (max-width: 720px) {
  .topbar-logo-img { display: block; }
}

/* ประวัติการแจ้ง ว.12 / ว.14 — แสดงเต็มเสมอ (ไม่พับ) */
.w12-history-section { background: var(--card); border: 0.5px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.w12-history-title { display: flex; align-items: center; gap: 8px; padding: 12px 16px; background: var(--bg); font-size: 14px; font-weight: 600; color: var(--text); border-bottom: 0.5px solid var(--border); }
.w12-history-body { padding: 14px; overflow-x: auto; }

/* history accordion (readiness / w12) */
.history-accordion {
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 20px;
}
.history-accordion-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg);
  border: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  gap: 10px;
  transition: background .12s;
}
.history-accordion-btn:hover,
.history-accordion-btn:active { background: var(--blue-light); }
.history-accordion-btn span { display: flex; align-items: center; gap: 8px; }
.history-accordion-chevron { transition: transform .2s; flex-shrink: 0; }
.history-accordion-body {
  padding: 14px;
  border-top: 0.5px solid var(--border);
  background: var(--card);
  overflow-x: auto;
}

/* แถวหัว accordion ที่มี filter อยู่มุมขวา — ใช้เมื่อ header ต้องมีปุ่ม filter เพิ่ม */
.history-accordion-header-row {
  display: flex;
  align-items: center;
  background: var(--bg);
  gap: 8px;
}
.history-accordion-header-row .history-accordion-btn {
  flex: 1;
  min-width: 0;
}
.w12-monthly-filter-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  padding-right: 14px;
}

/* =============================================
   Mobile User Card Popup
   ============================================= */
.mobile-user-card {
  display: none;
  position: fixed;
  inset: 0;
  bottom: 64px;    /* เว้นความสูง mobile nav */
  background: rgba(0,0,0,0.35);
  z-index: 490;
  align-items: flex-end;
  justify-content: center;
}

.mobile-user-card-inner {
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 20px 20px 24px;
  width: 100%;
  box-shadow: 0 -8px 32px rgba(0,0,0,0.18);
  animation: slideUpCard .22s cubic-bezier(.34,1.26,.64,1);
}
@keyframes slideUpCard {
  from { transform: translateY(24px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.mobile-user-card-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.mobile-user-card-avatar {
  width: 46px; height: 46px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.mobile-user-card-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.mobile-user-card-role {
  font-size: 12px;
  color: var(--blue);
  font-weight: 500;
  margin-top: 2px;
}
.mobile-user-card-unit {
  font-size: 11px;
  color: var(--hint);
  margin-top: 3px;
}

.mobile-user-card-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mobile-user-card-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  border-radius: 12px;
  border: 0.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s;
  text-align: left;
  width: 100%;
}
.mobile-user-card-btn i { font-size: 18px; color: var(--blue); }
.mobile-user-card-btn:hover,
.mobile-user-card-btn:active { background: var(--blue-light); }
.mobile-user-card-btn.danger { color: var(--red); }
.mobile-user-card-btn.danger i { color: var(--red); }
.mobile-user-card-btn.danger:hover,
.mobile-user-card-btn.danger:active { background: var(--red-light); }

/* ปุ่มฟันเฟือง (gear) ใน mobile nav */
.mobile-nav-gear {
  color: var(--hint);
  border-left: 0.5px solid var(--border);
  flex-shrink: 0;
  background: none;
  border-top: none;
  border-bottom: none;
  border-right: none;
  font-family: inherit;
  cursor: pointer;
}
.mobile-nav-gear:hover,
.mobile-nav-gear:active { color: var(--blue); }

body.theme-dark .mobile-user-card-inner { background: var(--card); }

/* Accordion: เปิดโดย default บน desktop, ปิดบน mobile */
.history-accordion-desktop-open { display: block; }
@media (max-width: 720px) {
  .history-accordion-desktop-open { display: none; }
  .history-accordion-desktop-open + .history-accordion-chevron,
  .history-accordion .history-accordion-chevron { transform: rotate(0deg); }
}

/* Person search list */
.person-search-list {
  max-height: 200px;
  overflow-y: auto;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
}
.person-search-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 0.5px solid var(--border);
  transition: background .12s;
}
.person-search-item:last-child { border-bottom: none; }
.person-search-item:hover { background: var(--blue-light); }
.person-search-name { font-size: 13px; font-weight: 600; color: var(--text); }
.person-search-pos  { font-size: 11px; color: var(--hint); margin-top: 2px; }

/* ---- Info Button + System Info ---- */
.sb-bottom-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.sb-info-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius);
  border: 0.5px solid var(--border);
  background: var(--card);
  color: var(--blue);
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: all .15s;
}
.sb-info-btn:hover { background: var(--blue-light); }
.sb-bottom-actions .sb-logout { flex: 1; margin-top: 0; }

.sys-info-content {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}
.sys-info-content ul, .sys-info-content ol { padding-left: 20px; margin: 8px 0; }
.sys-info-content li { margin-bottom: 4px; }
.sys-info-content b, .sys-info-content strong { font-weight: 600; }
.sys-info-content img { max-width: 100%; border-radius: 8px; margin: 8px 0; }
.sys-info-content table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.sys-info-content table td, .sys-info-content table th { border: 0.5px solid var(--border); padding: 6px 10px; font-size: 13px; }

/* =============================================
   Popup เต็มจอ (ใช้ร่วมกัน: Session Expired, ฯลฯ)
   ============================================= */
.broadcast-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 9997;
  animation: coordFadeIn .2s ease;
  padding: 16px;
}
.broadcast-box {
  background: var(--card);
  border-radius: 18px;
  padding: 24px 24px 20px;
  max-width: 420px;
  width: 100%;
  position: relative;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
  animation: coordSlideUp .22s cubic-bezier(.34,1.56,.64,1);
}
.broadcast-header {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600;
  color: var(--blue);
  margin-bottom: 14px;
  padding-right: 30px;
}
.broadcast-header i { font-size: 18px; }
.broadcast-content {
  font-size: 14px;
  color: var(--text);
  line-height: 1.7;
  max-height: 320px;
  overflow-y: auto;
}
body.theme-dark .broadcast-box { background: #1A2333; }

.icon-btn.danger:hover { background: var(--red-light); color: var(--red); border-color: var(--red); }

/* =============================================
   Coordinator Quick Action (Dashboard)
   ============================================= */
.coord-quick-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}
.coord-quick-actions .btn {
  flex: 1;
}

.quick-unit-list {
  max-height: 360px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.quick-unit-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.quick-unit-item:hover {
  background: var(--blue-light);
  border-color: var(--blue-mid);
}
.quick-unit-name {
  flex: 1;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 720px) {
  .coord-quick-actions {
    flex-direction: column;
  }
}

/* =============================================
   Coordinator Quick Action Buttons (Sidebar เท่านั้น)
   แจ้ง/ยกเลิก ว.12 — ปุ่มใหญ่ กดง่าย เปิด Popup ทันที ไม่เปลี่ยนหน้า
   ไม่ใช้ class .nav-item เพื่อไม่ให้ event listener ของเมนู navigate มาจับ
   ============================================= */
.sb-quick-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 16px 16px;
  margin-top: -6px; /* ลดช่องว่างจากกล่องเวรด้านบนที่มี margin-bottom 14px อยู่แล้ว */
}
.sb-quick-actions::after {
  content: "";
  display: block;
  margin: 6px -16px -16px; /* ดึงเส้นให้กว้างเท่าตัว sidebar ไม่ใช่แค่ความกว้างปุ่ม */
  border-top: 0.5px solid var(--border);
  padding-bottom: 8px;
}
.sb-quick-btn {
  font-size: 13.5px;
  padding: 10px 12px;
  justify-content: center;
}
/* .btn-block ปกติมี margin-top:20px สำหรับปุ่ม submit ท้ายฟอร์ม — ไม่เกี่ยวกับปุ่ม quick action
   ใน sidebar เลย ต้องตัดออกไม่งั้นช่องว่างด้านบน/ล่างของกลุ่มปุ่มจะไม่เท่ากัน */
.sb-quick-btn.btn-block { margin-top: 0; }

/* ปุ่ม Quick Action แจ้ง ว.12 (ทั้งศูนย์สั่งการและ Hospital) — ใช้สีเดียวกับ badge-w12 ในการ์ด (เข้มกว่า --red ปกติของปุ่ม danger ทั่วไป) ให้สีตรงกันทั้งสอง role */
.sb-w12-quick-btn.btn-danger { background: #C0392B; }
.sb-w12-quick-btn.btn-danger:hover { background: #A93226; }

/* ปุ่ม Quick Action บันทึกปฏิเสธเคส — กรอบแดง (outline) พื้นโปร่ง ต่างจากปุ่มแจ้ง ว.12 ที่เป็นแดงทึบ */
.sb-reject-quick-btn.btn-secondary {
  background: transparent;
  color: #C0392B;
  border: 1.5px solid #C0392B;
}
.sb-reject-quick-btn.btn-secondary:hover { background: rgba(192,57,43,0.08); color: #A93226; border-color: #A93226; }
body.theme-dark .sb-reject-quick-btn.btn-secondary { color: #FF8A80; border-color: #FF8A80; }
body.theme-dark .sb-reject-quick-btn.btn-secondary:hover { background: rgba(255,138,128,0.12); color: #FFB3AC; border-color: #FFB3AC; }

/* =============================================
   Coordinator Dashboard Card (compact mode)
   หัว Card ใหญ่ขึ้น, ตัด contact-row/member ออก (ดูผ่าน tooltip แทน)
   ============================================= */
.unit-card.coord-view { cursor: default; }
.unit-card.coord-view.has-coord-tooltip { cursor: help; /* บอกผู้ใช้ว่าชี้เมาส์ดูเหตุผลได้ */ }
.unit-card.coord-view .coord-head {
  padding: 16px 16px;
}
.unit-card.coord-view .coord-head .unit-name {
  font-size: 17px;
  font-weight: 700;
}
.unit-card.coord-view .coord-head .unit-type-badge {
  font-size: 12.5px;
  padding: 4px 11px;
}
.unit-card.coord-view .coord-head .unit-status-badge {
  font-size: 12.5px;
  padding: 4px 11px;
}
.unit-card.coord-view .coord-body {
  padding: 0 16px 14px;
}
.unit-card.coord-view .unit-card-actions {
  padding: 0 16px 14px;
}

/* Tooltip ลอย — แสดง contact-row (ทะเบียน/เบอร์) + รายชื่อทีม แบบเดียวกับการ์ดปกติ
   ใช้ markup เดิม (.contact-row, .detail-row, .members) ไม่ใช่ plain text */
.has-coord-tooltip {
  position: relative;
  overflow: visible !important; /* ต้อง override overflow:hidden ของ .unit-card ไม่งั้น tooltip ที่ลอยออกมาจะถูกตัดทิ้ง */
}
.coord-tooltip {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  width: 280px;
  box-shadow: 0 10px 28px rgba(0,0,0,0.16);
  z-index: 999;
  text-align: left;
}
.has-coord-tooltip:hover .coord-tooltip {
  display: block;
}
/* เหตุผล ว.12/ว.14 ใน tooltip — ขึ้นบรรทัดใหม่ได้ ไม่ตัดด้วย ... */
.coord-tooltip { padding: 10px 12px; width: 300px; }
.coord-tooltip .w12-reason { margin: 0; white-space: normal; align-items: flex-start; font-size: 13px; }
.coord-tooltip .w12-reason i { margin-top: 2px; }
.coord-tooltip .w12-reason span { overflow: visible; text-overflow: clip; }
.coord-tooltip .w12-reason-time { flex-shrink: 1; }
/* ว.12: บรรทัดแรก = เหตุผล (ชิดซ้าย) · บรรทัดสอง = เวลา (ชิดขวา) */
.coord-tooltip .w12-reason.tip { flex-direction: column; align-items: stretch; gap: 3px; }
.coord-tooltip .w12-reason.tip .tip-reason { display: flex; align-items: flex-start; gap: 5px; text-align: left; }
.coord-tooltip .w12-reason.tip .tip-time { text-align: right; font-size: 12px; opacity: .8; margin-top: 3px; padding-top: 5px; border-top: 0.5px solid rgba(163,45,45,.3); }
body.theme-dark .coord-tooltip .w12-reason.tip .tip-time { border-top-color: rgba(255,155,155,.3); }
.coord-tooltip .contact-row {
  margin-bottom: 10px;
}
.coord-tooltip .detail-row {
  margin-top: 0;
}

@media (max-width: 720px) {
  /* บนมือถือไม่มี hover จริง — ซ่อน tooltip ไปเลย กดดูรายละเอียดผ่านปุ่ม action แทน */
  .coord-tooltip { display: none !important; }
}

/* Admin: หัวข้อจัดกลุ่มในตาราง (เช่น จัดกลุ่มผู้ใช้งานตามหน่วย/Role) */
.admin-section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  padding-bottom: 8px;
  border-bottom: 1.5px solid var(--border);
}

.admin-group-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--blue);
  margin: 18px 0 8px;
  padding-bottom: 6px;
  border-bottom: 0.5px solid var(--border);
}
.admin-group-label:first-child { margin-top: 4px; }

/* =============================================
   Admin: Toggle ระบบบังคับรายงานตัว
   ============================================= */
.readiness-toggle-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  border: 0.5px solid var(--border);
}
.readiness-toggle-card.on { background: var(--green-light); border-color: #9FE1CB; }
.readiness-toggle-card.off { background: var(--amber-light); border-color: #F5D9A8; }
.readiness-toggle-info { flex: 1; min-width: 0; }
.readiness-toggle-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 600; color: var(--text);
  margin-bottom: 4px;
}
.readiness-toggle-desc { font-size: 12.5px; color: var(--muted); line-height: 1.5; }

/* Toggle switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #C7CCD4;
  border-radius: 26px;
  transition: .2s;
}
.toggle-slider::before {
  position: absolute;
  content: "";
  height: 20px; width: 20px;
  left: 3px; bottom: 3px;
  background-color: #fff;
  border-radius: 50%;
  transition: .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-switch input:checked + .toggle-slider { background-color: var(--green); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(22px); }

/* =============================================
   Admin: จัดการโซน (Zone Management)
   ============================================= */
.zones-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 4px;
}
@media (max-width: 900px) {
  .zones-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .zones-grid { grid-template-columns: 1fr; }
}

.zone-card {
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 280px; /* ความสูงเท่ากันทุกโซน */
}
.zone-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg);
  flex-shrink: 0;
}
.zone-card-name { font-size: 14px; font-weight: 600; color: var(--text); }
.zone-card-district { font-size: 11.5px; color: var(--hint); margin-top: 2px; }
.zone-card-body {
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  overflow-y: auto; /* ถ้า Zone Member เยอะ scroll ภายในกล่องนี้แทน ไม่ดันความสูงกล่อง */
}
.zone-unit-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  flex-shrink: 0;
}

/* =============================================
   Dashboard Zone Section Styles
   ============================================= */

/* dropdown filter ติดกับ grid toggle */
.dash-zone-select {
  font-size: 12px;
  padding: 5px 10px;
  min-width: 160px;
  height: 32px;
  border-radius: 8px;
  border: 0.5px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}

/* ---- Zone Section ---- */
.zone-section {
  margin-bottom: 24px;
}

.zone-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 0 10px;
  border-bottom: 1.5px solid var(--border);
  margin-bottom: 12px;
  gap: 12px;
}

.zone-section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.zone-district-label {
  font-size: 11px;
  font-weight: 400;
  color: var(--hint);
  background: var(--bg);
  padding: 2px 7px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.zone-section-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  flex-shrink: 0;
}

.zone-meta-ready {
  display: flex;
  align-items: center;
  gap: 3px;
  color: var(--green);
}

.zone-meta-w12 {
  display: flex;
  align-items: center;
  gap: 3px;
  color: var(--red);
  font-weight: 600;
}

/* โซน "ยังไม่กำหนดโซน" */
.zone-section-unzoned .zone-section-head {
  border-bottom-style: dashed;
}
.zone-section-unzoned .zone-section-title {
  color: var(--hint);
  font-weight: 400;
}

/* ---- Responsive ---- */
@media (max-width: 720px) {
  .dash-zone-select {
    min-width: 130px;
    font-size: 11px;
  }
  .zone-section-head {
    flex-wrap: wrap;
    gap: 6px;
  }
  .zone-section-meta {
    gap: 8px;
    font-size: 11px;
  }
}

/* =============================================
   ว.12 — CC Layout (Admin/EMD/Coordinator)
   ============================================= */

/* container สำหรับ CC layout — ไม่จำกัด max-width แบบ .form-card */
.cc-panel {
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}

/* กล่องแจ้ง/ยกเลิก ว.12 แยก ALS กับ BLS คนละการ์ด อยู่แถวเดียวกัน (28 ก.ย. 2569) */
.cc-w12-row {
  display: flex;
  gap: 14px;
  align-items: stretch;
}

.cc-w12-row .cc-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

@media (max-width: 640px) {
  .cc-w12-row { flex-direction: column; }
}

/* รายการหน่วยใน CC form — scroll เต็มพื้นที่ที่เหลือของกล่อง */
.cc-unit-list {
  flex: 1;
  min-height: 200px;
  /* ไม่จำกัดความสูง/ไม่ scroll ซ้อน — ให้ลงไปสุดหน่วยสุดท้ายตามหน้า (1 ต.ค. 2569) */
}

.cc-unit-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-bottom: 0.5px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
  font-size: 14px;
}
/* รายชื่อหน่วยในหน้าระบบแจ้ง ว.12 — ตัวใหญ่ชัดเจน (ปรับขนาดได้ที่นี่) */
.cc-unit-item .cc-unit-type { font-size: 11.5px; padding: 3px 10px; flex-shrink: 0; }
.cc-unit-item .cc-unit-status { display: flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 600; flex-shrink: 0; }

.cc-unit-item:last-child { border-bottom: none; }
.cc-unit-item:hover { background: var(--bg); }

.cc-unit-item.selected {
  background: var(--blue-light);
  border-left: 3px solid var(--blue);
}

.cc-unit-item.is-w12 { background: #FEF2F2; }
.cc-unit-item.is-w12:hover { background: #FEE2E2; }
.cc-unit-item.is-w12.selected { background: #FEE2E2; border-left-color: var(--red); }
.cc-unit-item.is-outside-hours { background: #F3F4F6; cursor: default; }
.cc-unit-item.is-outside-hours:hover { background: #F3F4F6; }
.cc-unit-item.is-w14 { background: #F3F4F6; }
.cc-unit-item.is-w14:hover { background: #E5E7EB; }
.cc-unit-item.is-w14.selected { background: #E5E7EB; border-left-color: #9CA3AF; }

.cc-unit-name {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* charts grid — 2 คอลัมน์เคียงกัน */
.cc-charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

/* แต่ละ chart column — จัดกึ่งกลาง */
.cc-chart-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  position: relative;
}

/* ตารางอันดับหน่วยที่แจ้ง — กว้างกว่าคอลัมน์ donut, จัดชิดซ้าย */
.cc-charts-row:has(.cc-chart-col-wide) { grid-template-columns: 1.5fr 1fr; }
.cc-chart-col-wide { align-items: stretch; }
.cc-bars-sum { font-size: 12px; color: var(--muted); }
.cc-bars-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
/* ปุ่มมุมมอง ทั้งหมด/ALS/BLS — ใช้สไตล์ .grid-toggle เดิม แต่ไม่ซ่อนบนมือถือ */
.cc-seg { display: inline-flex !important; }
.cc-seg .grid-toggle-btn { padding: 3px 10px; font-size: 11.5px; }
.cc-bars-sum b { color: var(--text); font-weight: 600; }
/* สีแท่งโทนเดียวกับป้ายระบบ: ALS = #e66359 · BLS = ฟ้าอ่อน (โทนเดียวกับพื้น/ตัวอักษรของ .badge-type-bls แต่เข้มพอให้เห็นบนพื้นขาว) */
.cc-bars { --cc-als: #e66359; --cc-bls: #8CBCEB; --cc-na: #9AA3B2; width: 100%; }
body.theme-dark .cc-bars { --cc-als: #e66359; --cc-bls: #90C4F5; --cc-na: #7C879A; }
.cc-bar-als { background: var(--cc-als); }
.cc-bar-bls { background: var(--cc-bls); }
.cc-bar-na  { background: var(--cc-na); }
.cc-rk-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.cc-rk-table th { font-weight: 600; font-size: 11px; color: var(--muted); text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--border); }
.cc-rk-table td { padding: 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.cc-rk-table tbody tr:hover { background: var(--bg); }
.cc-rk-rank { width: 26px; color: var(--hint); }
/* คอลัมน์ชื่อกว้างเท่าชื่อที่ยาวสุด (ไม่ขยายเต็มตาราง) → "ครั้ง" ชิดชื่อ ส่วนแท่งรับพื้นที่ที่เหลือ */
.cc-rk-name { color: var(--text); width: 1%; white-space: nowrap; }
.cc-rk-table .cc-rk-num, .cc-rk-table .cc-rk-pct { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cc-rk-pct { width: 40px; color: var(--hint); }
.cc-rk-bar { width: auto; min-width: 70px; }
.cc-rk-bar .cc-bar-fill { height: 8px; border-radius: 0 3px 3px 0; }
.cc-rk-name .unit-type-badge { font-size: 10.5px; padding: 1px 7px; margin-right: 6px; }
/* popup รายการเต็ม — เลื่อนเฉพาะตาราง หัวตารางค้างด้านบน */
.cc-bars-modal { max-height: 60vh; overflow-y: auto; }
.cc-bars-modal .cc-rk-table th { position: sticky; top: 0; background: var(--card); z-index: 1; }
.cc-other-body { max-height: 60vh; overflow-y: auto; }
.cc-other-sec { font-size: 12px; font-weight: 600; color: var(--muted); margin: 10px 0 4px; }
.cc-other-folded { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.cc-other-folded li { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.cc-other-list { margin: 0; padding-left: 22px; font-size: 13px; line-height: 1.6; }
.cc-other-list li { padding: 3px 0; border-bottom: 1px solid var(--border); word-break: break-word; }
/* ปุ่ม "ดูทั้งหมด/ดูรายละเอียด" ของสองการ์ดชิดล่างสุดของแถว → อยู่ระนาบเดียวกัน */
.cc-chart-col-wide .cc-bars { flex: 1; display: flex; flex-direction: column; }
.cc-bars-toggle { align-self: flex-start; margin-top: auto; background: none; border: none; padding: 0; font: inherit; font-size: 12px; color: var(--blue); cursor: pointer; }
.cc-bars-toggle:hover { text-decoration: underline; }
/* ชิดบรรทัดบน: ตัดช่องว่างท้าย legend และลดระยะห่างของปุ่ม */
.cc-legend > div:last-child { margin-bottom: 0 !important; }
.cc-chart-col .cc-bars-toggle { margin-top: auto; position: relative; top: -4px; }
body.theme-dark .cc-bars-toggle { color: #90C4F5; }

.cc-chart-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  align-self: flex-start;
  width: 100%;
}

/* วงกลมตรงกลาง donut */
.cc-donut-hole {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 112px; height: 112px;
  border-radius: 50%;
  background: var(--card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.cc-donut-num {
  font-size: 30px;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
}

.cc-donut-sub {
  font-size: 11px;
  color: var(--hint);
}

/* legend ใต้ chart */
.cc-legend {
  width: 100%;
  max-height: none;   /* เหตุผลมีไม่เกิน 7 แถว — ไม่ตัด/ไม่เลื่อน */
}

/* tooltip */
.cc-tooltip {
  display: none;
  position: absolute;
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 7px 11px;
  font-size: 12px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 20;
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}

.cc-tooltip.show { display: block; }

@media (max-width: 640px) {
  .cc-rk-name { white-space: normal; width: auto; }
  .cc-charts-row, .cc-charts-row:has(.cc-chart-col-wide) { grid-template-columns: 1fr; }

  .history-accordion-header-row {
    flex-wrap: wrap;
  }
  .w12-monthly-filter-bar {
    width: 100%;
    padding: 0 14px 10px;
    flex-wrap: wrap;
  }
}

/* =============================================
   FORCE PASSWORD CHANGE MODAL
   ============================================= */
.force-pw-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.force-pw-card {
  background: var(--card, #fff);
  border-radius: 20px;
  padding: 32px 28px 28px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  gap: 0;
}
.force-pw-icon {
  width: 56px; height: 56px;
  border-radius: 16px;
  background: #EF444415;
  color: #EF4444;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  margin-bottom: 16px;
}
.force-pw-title {
  font-size: 20px; font-weight: 800;
  color: var(--text, #111);
  margin-bottom: 6px;
}
.force-pw-desc {
  font-size: 13px; color: var(--muted, #6B7280);
  line-height: 1.6; margin-bottom: 12px;
}
.force-pw-name {
  font-size: 13px; font-weight: 600;
  color: var(--blue, #0EA5E9);
  background: #0EA5E910;
  border-radius: 8px;
  padding: 6px 12px;
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 20px;
}
.force-pw-fields { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.force-pw-field { display: flex; flex-direction: column; gap: 5px; }
.force-pw-field label { font-size: 12px; font-weight: 600; color: var(--muted, #6B7280); }
.force-pw-input-wrap { position: relative; }
.force-pw-input-wrap input {
  width: 100%; box-sizing: border-box;
  padding: 10px 40px 10px 12px;
  border: 1.5px solid var(--border, #E5E7EB);
  border-radius: 10px;
  font-size: 14px;
  background: var(--surface, #F9FAFB);
  color: var(--text, #111);
  outline: none;
  transition: border-color .15s;
}
.force-pw-input-wrap input:focus { border-color: var(--blue, #0EA5E9); }
.force-pw-eye {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer;
  color: var(--muted, #9CA3AF); font-size: 16px; padding: 2px;
}
.force-pw-error {
  font-size: 12px; color: #EF4444;
  background: #EF444412; border-radius: 8px;
  padding: 8px 12px; margin-bottom: 12px;
}
.force-pw-btn {
  width: 100%; padding: 12px;
  background: var(--blue, #0EA5E9); color: #fff;
  border: none; border-radius: 12px;
  font-size: 15px; font-weight: 700;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: opacity .15s;
}
.force-pw-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* =============================================
   DASHBOARD — top row: แผนที่ (เด่นสุด) + stat cards เรียงข้างแผนที่
   ============================================= */
.dashboard-top-row {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.dashboard-top-row > #dashboard-map-wrap,
.dashboard-top-row > #dashboard-side-col {
  min-width: 0;
}
.dashboard-top-row > #dashboard-map-wrap { flex: 2 1 480px; margin-bottom: 0; }
.dashboard-top-row > #dashboard-side-col { flex: 1 1 260px; max-width: 300px; }

/* แถบพับ/ขยายแผนที่ — Admin/Radio/Assistant */
.dashboard-collapse-bar {
  display:flex; align-items:center; justify-content:space-between; gap:10px; width:100%;
  margin-bottom:10px; padding:8px 14px; font:inherit; font-size:13px; font-weight:600; color:var(--muted);
  background:var(--card); border:0.5px solid var(--border); border-radius:var(--radius); cursor:pointer;
}
.dashboard-collapse-bar:hover { color:var(--blue); border-color:var(--blue); }
.dashboard-collapse-hint { display:inline-flex; align-items:center; gap:4px; font-weight:500; font-size:12.5px; }
.dashboard-top-row.is-collapsed { display:none !important; }

.dashboard-side-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dashboard-stats-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-content: start;
}
.dashboard-stats-col .stat-card { margin: 0; }

/* การ์ด "ศูนย์สั่งการ" — แพทย์อำนวยการ / EMD ประจำเวร / เบอร์โทรด่วน (mockup ข้อมูล) */
.dispatch-card {
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
}
.dispatch-card-title {
  font-size: 11.5px; font-weight: 600; color: var(--muted);
  letter-spacing: 0.03em; text-transform: uppercase; margin-bottom: 10px;
}
.dispatch-card-rows { display: flex; flex-direction: column; }
.dispatch-card-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
.dispatch-card-row + .dispatch-card-row { border-top: 0.5px solid var(--border); }
.dispatch-card-row-icon {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  background: var(--blue-light); display: flex; align-items: center; justify-content: center;
}
.dispatch-card-row-icon.is-emd { background: var(--green-light); }
.dispatch-card-row-text { min-width: 0; }
.dispatch-card-row-label { font-size: 11px; line-height: 1.3; color: var(--muted); font-weight: 500; }
.dispatch-card-row-name { font-size: 14px; line-height: 1.35; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dispatch-card-phone {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--green-light);
  border-radius: 99px;
  padding: 7px 14px;
}
.dispatch-card-phone-num {
  font-size: 13.5px; font-weight: 600; color: #0F6E56;
  letter-spacing: 0.01em; font-variant-numeric: tabular-nums;
}

@media (max-width: 860px) {
  .dashboard-top-row > #dashboard-map-wrap,
  .dashboard-top-row > #dashboard-side-col { flex: 1 1 100%; max-width: none; }
}
.force-pw-btn:hover:not(:disabled) { opacity: 0.9; }

/* แถบแท็บของ Admin / หน้า ว.12 มีหลายแท็บแล้ว — ให้ขึ้นบรรทัดใหม่แทนการล้นจอ (3 ต.ค. 2569) */
.admin-tabs { flex-wrap: wrap; max-width: 100%; }

/* =============================================
   Admin → แท็บ "แนะนำระบบ" (js/system_guide.js) — หน้าตาเดียวกับแท็บแนะนำระบบของ DATA-ALS (3 ต.ค. 2569)
   ใช้ตัวแปรสีกลางทั้งหมด (รองรับ dark mode อัตโนมัติ)
   ============================================= */
.guide-head { display: flex; gap: 16px; align-items: center; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px 24px; margin-bottom: 22px; }
.guide-head-icon { flex: 0 0 auto; width: 64px; height: 64px; border-radius: 14px; background: var(--blue-light); color: var(--blue); display: flex; align-items: center; justify-content: center; font-size: 32px; }
.guide-head-main { flex: 1; min-width: 0; }
.guide-head-title { font-size: 22px; font-weight: 700; color: var(--text); line-height: 1.2; }
.guide-head-desc { font-size: 14px; color: var(--muted); margin-top: 3px; }
.guide-head-org { font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 3px; }
.guide-head-ver { text-align: right; flex: 0 0 auto; }
.guide-head-ver-k { font-size: 12px; color: var(--hint); }
.guide-head-ver-v { font-size: 22px; font-weight: 700; color: var(--blue); line-height: 1.3; }
.guide-title { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 700; color: var(--text); margin: 24px 0 12px; }
.guide-title i { color: var(--blue); }
.guide-versions { display: flex; flex-direction: column; gap: 10px; }
.guide-ver { display: flex; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.guide-ver-badge { flex: 0 0 110px; display: flex; align-items: flex-start; justify-content: center; padding: 18px 8px; font-weight: 700; font-size: 14px; color: var(--blue); background: var(--blue-light); }
.guide-ver-badge.current { background: var(--blue); color: #fff; }
.guide-ver-list { flex: 1; min-width: 0; }
.guide-ver-item { padding: 12px 18px; border-bottom: 1px solid var(--border); }
.guide-ver-item:last-child { border-bottom: none; }
.guide-ver-title { font-size: 14px; font-weight: 700; color: var(--text); }
.guide-ver-desc { font-size: 13px; color: var(--muted); line-height: 1.65; margin-top: 3px; }
.guide-group-label { display: flex; align-items: center; gap: 7px; font-size: 14px; font-weight: 700; margin: 16px 0 10px; }
.guide-group-label .guide-dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.guide-group-label.ok { color: #1D9E75; }
.guide-group-label.paused { color: #D97706; }
.guide-group-label.soon { color: #5B5BD6; }
.guide-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.guide-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.guide-card.paused { background: var(--bg); opacity: .85; }
.guide-card.soon { background: var(--bg); border-style: dashed; }
.guide-card-title { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.guide-card-title i { color: var(--blue); font-size: 18px; }
.guide-card.paused .guide-card-title i, .guide-card.paused .guide-card-title { color: var(--muted); }
.guide-card.soon .guide-card-title i, .guide-card.soon .guide-card-title { color: var(--muted); }
.guide-card-title.red, .guide-card-title.red i { color: var(--blue); }
.guide-tag { margin-left: auto; font-size: 11px; font-weight: 600; color: #B45309; background: rgba(239,159,39,.18); border-radius: 999px; padding: 1px 9px; }
.guide-card-desc { font-size: 13px; color: var(--muted); line-height: 1.65; }
.guide-bullets { list-style: none; margin: 0; padding: 0; }
.guide-bullets li { position: relative; font-size: 13px; color: var(--muted); line-height: 1.65; padding-left: 16px; margin-bottom: 5px; }
.guide-bullets li::before { content: "•"; position: absolute; left: 3px; color: var(--hint); }
.guide-bullets li.warn { padding-left: 0; color: var(--text); }
.guide-bullets li.warn::before { content: none; }
.guide-bullets li.warn i { color: #D97706; }
.guide-bullets b, .guide-card-desc b, .guide-ver-desc b { color: var(--text); }
.guide-caution { display: flex; gap: 10px; align-items: flex-start; background: rgba(250,204,21,.18); border-radius: 10px; padding: 12px 16px; margin-bottom: 10px; font-size: 13.5px; line-height: 1.65; color: var(--text); }
.guide-caution i { margin-top: 3px; color: #92400E; }
.guide-foot { text-align: center; font-size: 13px; color: var(--hint); border-top: 1px solid var(--border); margin-top: 26px; padding: 18px 0 8px; line-height: 1.9; }
@media (max-width: 640px) {
  .guide-head { flex-wrap: wrap; padding: 16px; }
  .guide-head-ver { text-align: left; }
  .guide-ver { flex-direction: column; }
  .guide-ver-badge { flex-basis: auto; justify-content: flex-start; padding: 8px 14px; }
}
/* ตาราง "ยอดประสานงานนำส่ง รพ.อื่นๆ" — กระชับให้พอดีหน้าจอ ไม่ต้องเลื่อนซ้าย-ขวา (4 ต.ค. 2569) */
.emd-reftable { width: 100%; font-size: 12.5px; }
.emd-reftable th, .emd-reftable td { padding: 8px 7px; }
.emd-reftable td.emd-wrap { white-space: normal; min-width: 100px; max-width: 220px; }
.emd-reftable .emd-ref-time { margin-top: 3px; color: var(--muted); font-size: 12px; }
.emd-reftable td.emd-ref-people .emd-chip { display: block; width: fit-content; margin: 2px 0; }
/* Dispatcher EMD: ช่อง "นำส่งแทน ALS สมุทรปราการ" + หมายเหตุใต้ค่าในตาราง (7 ต.ค. 2569) */
.emd-subcheck { display:flex; align-items:center; gap:8px; min-height:40px; font-size:13.5px; cursor:pointer; }
.emd-subcheck input { width:18px; height:18px; }
.emd-sub-note { margin-top:3px; font-size:11.5px; color:var(--muted); white-space:normal; }
.emd-subline { display:flex; align-items:center; gap:8px; }
.emd-subline .emd-subcheck { flex:0 0 auto; white-space:nowrap; }
.emd-subline .emd-subreason { flex:1 1 0; min-width:0; }
/* ช่องติ๊ก "นำส่งแทน ALS" : กึ่งกลางระนาบเดียวกับช่องกรอกฝั่งซ้าย (สูงเท่าช่องกรอก) */
.emd-subbox { display:flex; align-items:center; gap:8px; min-height:41px; padding:0 4px; font-size:14px; font-weight:500; color:var(--text); cursor:pointer; }
.emd-subbox input { width:18px; height:18px; margin:0; }
/* ช่องกรอก + ปุ่ม X ต่อท้ายในขอบเดียวกัน */
.emd-inputgroup { display:flex; align-items:stretch; }
.emd-inputgroup .field-input { flex:1 1 auto; min-width:0; border-top-right-radius:0; border-bottom-right-radius:0; }
.emd-inputgroup-x { flex:0 0 44px; display:flex; align-items:center; justify-content:center; border:0.5px solid var(--border); border-left:0; border-radius:0 var(--radius) var(--radius) 0; background:var(--bg); color:var(--muted); font-size:17px; cursor:pointer; }
.emd-inputgroup-x:hover { background:var(--red-light); color:var(--red); border-color:var(--red); }
/* ปุ่มเลือก RC code / ER Triage เป็น badge สีจริงเหมือนในตาราง : ทุกตัวสีเต็ม ตัวที่เลือก = กรอบเข้ม + วงแหวนรอบ (7 ต.ค. 2569) */
.emd-pickchip.emd-colorchip { border:2px solid transparent; font-weight:600; transition:box-shadow .12s, transform .12s; }
.emd-pickchip.emd-colorchip:hover { border-color:rgba(0,0,0,.25); }
.emd-pickchip.emd-colorchip.active { border-color:var(--text); box-shadow:0 0 0 2px var(--card), 0 0 0 4px rgba(0,0,0,.15); transform:scale(1.04); }
/* ปุ่มต่อท้ายช่องกรอก (เช่น "+ รายละเอียดอาการ") ในขอบเดียวกับช่อง */
.emd-inputgroup-btn { flex:0 0 auto; display:flex; align-items:center; gap:6px; padding:0 16px; border:0.5px solid var(--border); border-left:0; border-radius:0 var(--radius) var(--radius) 0; background:var(--blue-light); color:var(--blue); font-family:inherit; font-size:13.5px; font-weight:600; white-space:nowrap; cursor:pointer; }
.emd-inputgroup-btn:hover { background:var(--blue); color:#fff; border-color:var(--blue); }
/* popup เพิ่มโรงพยาบาล (EMD ประสาน รพ.อื่น) */
/* แท็บ Admin "จัดการ Dropdown" */
.dd-subtabs { display:flex; flex-wrap:wrap; gap:8px; margin-bottom:14px; }
.dd-subtab { display:flex; align-items:center; gap:6px; padding:8px 14px; border:1px solid var(--border); border-radius:999px; background:var(--card); color:var(--muted); font:inherit; font-size:13px; font-weight:600; cursor:pointer; }
.dd-subtab:hover { color:var(--blue); border-color:var(--blue); }
.dd-subtab.active { background:var(--blue); border-color:var(--blue); color:#fff; }
.dd-region { display:inline-block; padding:1px 9px; border-radius:999px; font-size:11.5px; font-weight:600; }
.dd-region.in { background:var(--blue-light); color:#0C447C; }
.dd-region.out { background:var(--amber-light); color:#7A5200; }
tr.dd-off td { opacity:.55; }
.emdhosp-note > i { flex:0 0 auto; margin-top:3px; }
.emdhosp-note { display:flex; gap:8px; padding:10px 12px; margin-bottom:12px; border-radius:8px; background:var(--blue-light); color:#0C447C; font-size:12.5px; line-height:1.6; }
.emdhosp-hint { margin:4px 0 10px; padding:10px 12px; border-radius:8px; font-size:12.5px; line-height:1.6; }
.emdhosp-hint.bad { background:var(--red-light); color:#A32D2D; }
.emdhosp-hint.warn { background:var(--amber-light); color:#7A5200; }
.emdhosp-sugg { display:flex; flex-wrap:wrap; gap:6px; margin-top:6px; }
.emdhosp-sub { margin-top:6px; font-size:12px; opacity:.85; }
.emd-sub-reason { color:#8A5A00; font-weight:600; }
body.theme-dark .emd-sub-reason { color:#F3C980; }
/* สถานที่เกิดเหตุในตาราง: แสดงบรรทัดเดียว ยาวเกินตัดด้วย … (ชี้เมาส์ดูข้อความเต็ม) */
.emd-oneline.dx { max-width:150px; }
.quick-unit-item.is-w12 { background:var(--red-light); }
.quick-unit-item.is-w12 .quick-unit-name { color:#A32D2D; }
.quick-unit-item.is-w14 { background:var(--bg); opacity:.75; }
.quick-unit-tag { flex:0 0 auto; font-size:10.5px; font-weight:700; padding:0 7px; border-radius:999px; line-height:18px; background:#E24B4A; color:#fff; }
.quick-unit-item.is-w14 .quick-unit-tag { background:#9CA3AF; }
body.theme-dark .quick-unit-item.is-w12 { background:rgba(226,75,74,.16); }
body.theme-dark .quick-unit-item.is-w12 .quick-unit-name { color:#F5A8A3; }
.w12-cont-pill { display:inline-block; padding:0 7px; border-radius:999px; font-size:11px; font-weight:600; line-height:18px; background:var(--blue-light); color:#0C447C; white-space:nowrap; }
.emd-reftable td.emd-unitcell { white-space:nowrap; }   /* หน่วยปฏิบัติการห้ามตกบรรทัด */   /* Diagnosis: บรรทัดเดียว ยาวเกินตัดด้วย … (ชี้เมาส์/กดแถวดูเต็ม) */
.emd-oneline { display:inline-block; max-width:180px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; vertical-align:bottom; }
/* ตารางยอดประสาน รพ.อื่น: กดแถวเพื่อดูรายละเอียด (อ่านอย่างเดียว) + popup รายละเอียดเคส */
.emd-ref-row { cursor:pointer; }
.emd-ref-row:hover td { background:var(--blue-light); }
.emd-ref-dt { display:flex; flex-direction:column; gap:6px; font-size:13.5px; }
.emd-ref-dt-row { display:flex; gap:10px; align-items:baseline; }
.emd-ref-dt-row > span { flex:0 0 130px; color:var(--muted); font-size:12.5px; }
.emd-ref-dt-row > b { font-weight:600; min-width:0; word-break:break-word; }

/* แถว "ระบุเวลายกเลิก ว.14": .field-input มี width:100% → ช่องเวลาแย่งพื้นที่จนช่องวันที่ถูกบีบเหลือแต่ขอบ */
.w14-until-wrap > input[type="date"] { flex: 1 1 auto; width: auto; min-width: 140px; }
.w14-until-wrap > input[type="text"] { flex: 0 0 130px; width: 130px; }

/* ===== ล็อกหน้าจอ / ยืนยันตัวตนขึ้นเวร (js/session_lock.js) ===== */
.session-lock-overlay {
  position: fixed; inset: 0; z-index: 3000;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(15, 23, 42, 0.72);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.session-lock-card {
  width: 100%; max-width: 440px; text-align: center;
  background: var(--card, #fff); color: var(--text, #1a1a1a);
  border-radius: var(--radius-lg, 14px); padding: 32px 28px 26px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.session-lock-icon { font-size: 40px; line-height: 1; color: var(--primary, #378ADD); margin-bottom: 10px; }
.session-lock-title { font-size: 18px; font-weight: 600; }
.session-lock-sub { font-size: 13px; color: var(--hint, #888); margin: 4px 0 18px; }
.session-lock-name { font-size: 28px; font-weight: 700; line-height: 1.25; word-break: break-word; }
.session-lock-meta { font-size: 14px; color: var(--hint, #888); margin-top: 6px; }
.session-lock-hint { font-size: 13px; color: var(--hint, #888); margin: 18px 0 22px; line-height: 1.6; }
.session-lock-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.session-lock-actions .btn { min-width: 150px; justify-content: center; }
.session-lock-continue { font-weight: 600; }
body.session-locked { overflow: hidden; }

/* ===== popup รายการแจ้ง ว.12 ของหน่วยหนึ่ง (25 ต.ค. 2569) ===== */
.w12-cell-link { color:var(--red); font-weight:600; text-decoration:none; padding:2px 8px; border-radius:6px; display:inline-block; cursor:pointer; }
.w12-cell-link:hover { background:#FEE4E2; text-decoration:underline; }
.w12-unit-link { color:var(--blue); text-decoration:none; cursor:pointer; }
.w12-unit-link:hover { text-decoration:underline; }
.w12pop-chips { margin:2px 0 12px; }
#w12pop { position:relative; }
.w12pop-title { font-size:14px; font-weight:700; margin:0 0 10px; padding-right:40px; display:flex; align-items:center; gap:6px; flex-wrap:wrap; }
.w12pop-printbtn { position:absolute; top:-4px; right:-4px; height:32px; border:1px solid var(--border); border-radius:8px; background:var(--card); color:var(--muted); cursor:pointer; display:inline-flex; align-items:center; justify-content:center; gap:5px; font-size:13px; font-weight:600; padding:0 12px; }
.w12pop-printbtn i { font-size:17px; }
/* ปุ่มปิดค้างไว้ล่างสุดของ popup เสมอ (เลื่อนรายการได้โดยปุ่มไม่จม) */
.w12pop-actions { position:sticky; bottom:0; z-index:3; margin-top:12px; padding:12px 0 0; background:var(--card); border-top:1px solid var(--border); }
.w12pop-actions .btn { flex:none; min-width:160px; margin-left:auto; }
.w12pop-printbtn:hover { color:var(--blue); border-color:var(--blue-mid); }
.w12pop-cards { display:grid; grid-template-columns:repeat(auto-fit, minmax(150px, 1fr)); gap:8px; margin-bottom:12px; }
.w12pop-card { display:flex; gap:9px; align-items:flex-start; background:var(--card); border:0.5px solid var(--border); border-radius:var(--radius); padding:10px 12px; }
.w12pop-card > i { font-size:20px; margin-top:1px; }
.w12pop-card-label { font-size:11px; color:var(--muted); }
.w12pop-card-value { font-size:22px; font-weight:700; line-height:1.25; }
.w12pop-card-value small { font-size:12px; font-weight:400; color:var(--muted); }
.w12pop-sm { font-size:17px; }
.w12pop-card-sub { font-size:11px; color:var(--hint); }
.w12pop-card.c-red > i { color:#E24B4A; } .w12pop-card.c-amber > i { color:#EF9F27; } .w12pop-card.c-teal > i { color:#1D9E75; } .w12pop-card.c-purple > i { color:#534AB7; }
.w12pop-sec { font-size:12px; font-weight:700; color:var(--muted); margin:10px 0 6px; }
.w12pop-reasons { display:flex; flex-direction:column; gap:5px; margin-bottom:6px; }
.w12pop-rrow { display:flex; align-items:center; gap:8px; font-size:12.5px; }
.w12pop-rname { flex:0 0 38%; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.w12pop-rbar { flex:1; height:8px; background:var(--bg); border-radius:4px; overflow:hidden; }
.w12pop-rbar i { display:block; height:100%; background:#185FA5; border-radius:4px; }
.w12pop-rpct { color:var(--hint); font-size:11.5px; width:36px; text-align:right; }
/* ตารางใน popup: ไม่มี scrollbar แนวนอน (popup กว้างพอ) · รายการเยอะ = เลื่อนลงในกรอบตาราง */
.w12pop-tablewrap { max-height:46vh; overflow-y:auto; overflow-x:hidden; }
.w12pop-table { font-size:12.5px; width:100%; }
.w12pop-table td, .w12pop-table th { vertical-align:top; white-space:nowrap; }
.w12pop-table td.w12pop-reasoncell { white-space:normal; min-width:150px; }
.w12pop-table .duration-badge { white-space:nowrap; }
/* หัวตารางค้างไว้ด้านบน เลื่อนเฉพาะรายการ */
.w12pop-table thead th { position:sticky; top:0; z-index:2; box-shadow:0 1px 0 var(--border); }
@media (max-width: 700px) { .w12pop-tablewrap { overflow-x:auto; } }
#w12-print-root { display:none; }
@media print {
  @page { size:A4 portrait; margin:12mm; }
  body.w12-printing > *:not(#w12-print-root) { display:none !important; }
  body.w12-printing #w12-print-root { display:block !important; color:#111; font-size:12px; -webkit-print-color-adjust:exact; print-color-adjust:exact; }
  body.w12-printing #w12-print-root .w12pop-printhead { font-size:12px; color:#555; margin-bottom:4px; }
  body.w12-printing #w12-print-root .w12pop-printfoot { font-size:10px; color:#777; margin-top:10px; }
  body.w12-printing #w12-print-root .w12pop-actions, body.w12-printing #w12-print-root .w12pop-printbtn { display:none !important; }
  body.w12-printing #w12-print-root .w12pop-card { break-inside:avoid; }
  body.w12-printing #w12-print-root .w12pop-tablewrap { max-height:none; overflow:visible; }
  body.w12-printing #w12-print-root .w12pop-table { font-size:11px; }
  body.w12-printing #w12-print-root .w12pop-table tr { break-inside:avoid; }
  body.w12-printing #w12-print-root .w12pop-table thead { display:table-header-group; }
}

/* ===== popup เพิ่ม/แก้ไขผู้ใช้ 2 คอลัมน์ (25 ต.ค. 2569 — หน้าตาเหมือน DATA ALS) · ใช้เฉพาะ popup นี้ (class modal-box-user) ===== */
.modal-box.modal-box-user { max-width:780px; }
.modal-box.modal-box-user .modal-box-inner { padding:0; }
.user-form { padding:24px 26px 20px; position:relative; }
.user-form-close { position:absolute; top:12px; right:14px; width:30px; height:30px; border:none; background:transparent; color:var(--muted); font-size:20px; cursor:pointer; border-radius:8px; display:inline-flex; align-items:center; justify-content:center; padding:0; }
.user-form-close:hover { background:var(--bg); color:var(--text); }
.user-form-title { margin:0 0 16px; font-size:17px; font-weight:600; padding-right:36px; }
.user-form-cols { display:grid; grid-template-columns:1fr 1fr; gap:0 28px; align-items:start; }
.user-form-col + .user-form-col { border-left:1px solid var(--border); padding-left:28px; }
.user-form-sec { font-size:12.5px; font-weight:600; color:var(--muted); margin-bottom:12px; display:flex; align-items:center; gap:6px; }
.user-form-hint { color:var(--hint); font-size:12px; font-weight:400; }
.user-form-actions { display:flex; gap:8px; justify-content:flex-end; align-items:center; margin-top:18px; padding-top:14px; border-top:1px solid var(--border); }
.user-switch { display:flex; align-items:center; gap:10px; cursor:pointer; font-size:13px; }
.user-switch input { position:absolute; opacity:0; width:0; height:0; }
.user-switch-slider { position:relative; flex:0 0 38px; width:38px; height:22px; border-radius:11px; background:#CBD2DC; transition:background .15s; }
.user-switch-slider::after { content:""; position:absolute; top:3px; left:3px; width:16px; height:16px; border-radius:50%; background:#fff; transition:transform .15s; box-shadow:0 1px 2px rgba(0,0,0,.25); }
.user-switch input:checked + .user-switch-slider { background:var(--blue); }
.user-switch input:checked + .user-switch-slider::after { transform:translateX(16px); }
.user-switch input:focus-visible + .user-switch-slider { outline:2px solid var(--blue-mid); outline-offset:2px; }
@media (max-width:680px) {
  .user-form { padding:20px 16px 16px; }
  .user-form-cols { grid-template-columns:1fr; }
  .user-form-col + .user-form-col { border-left:none; padding-left:0; border-top:1px solid var(--border); margin-top:6px; padding-top:14px; }
}
.user-form-req { color:#D92D20; font-weight:700; }
.user-form-reqnote { margin-top:10px; font-size:12px; color:var(--hint); }

/* ===== PIN ผู้ดูแลก่อนเข้าหน้า Admin (25 ต.ค. 2569) ===== */
.pin-boxes { display:flex; gap:8px; justify-content:center; margin:6px 0; }
.pin-box { width:44px; height:52px; text-align:center; font-size:22px; font-weight:600; border:1.5px solid var(--border); border-radius:10px; background:var(--card,#fff); color:var(--text); padding:0; outline:none; caret-color:transparent; }
.pin-box:focus { border-color:var(--blue); box-shadow:0 0 0 3px rgba(24,95,165,.18); }
.pin-box:disabled { opacity:.55; }
@media (max-width:380px) { .pin-boxes { gap:5px; } .pin-box { width:38px; height:48px; font-size:20px; } }
.admin-pin-overlay { position:fixed; inset:0; z-index:2900; background:rgba(15,23,42,.72); backdrop-filter:blur(10px); display:flex; align-items:center; justify-content:center; padding:20px; }
.admin-pin-card { background:var(--card,#fff); color:var(--text); border-radius:20px; width:100%; max-width:400px; padding:30px 26px 22px; text-align:center; box-shadow:0 20px 60px rgba(0,0,0,.35); }
.admin-pin-icon { font-size:38px; line-height:1; color:var(--blue); margin-bottom:8px; }
.admin-pin-icon.bad { color:#D92D20; }
.admin-pin-title { font-size:18px; font-weight:700; }
.admin-pin-sub { font-size:13px; color:var(--muted); margin:6px 0 16px; line-height:1.6; }
.admin-pin-lbl { font-size:12px; color:var(--muted); margin:10px 0 2px; }
.admin-pin-msg { min-height:20px; font-size:13px; color:var(--muted); margin-top:10px; }
.admin-pin-msg.bad { color:#D92D20; }
.admin-pin-cancel { margin-top:14px; background:none; border:none; font-size:12.5px; color:var(--hint); text-decoration:underline; cursor:pointer; }
.user-form-pinstatus { font-size:12.5px; margin-bottom:6px; }
.user-form-pin-ok { color:#067647; font-weight:600; }
.user-form-pin-no { color:#B54708; font-weight:600; }
.user-form-pinbtns { display:flex; gap:8px; flex-wrap:wrap; justify-content:center; margin-top:8px; }

/* ===== แท็บยอดพิเศษในหน้า EMD + ตัวสร้างแท็บใน Admin (26 ต.ค. 2569) ===== */
.emd-sheet-head { display:flex; align-items:center; gap:10px; flex-wrap:wrap; margin-bottom:12px; }
.emd-sheet-title { flex:1 1 280px; min-width:0; }
.emd-sheet-name { font-size:16px; font-weight:700; display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.emd-sheet-sub { font-size:12.5px; color:var(--muted); margin-top:2px; }
.emd-sheet-monthlbl { font-size:13px; font-weight:600; color:var(--muted); }
.emd-sheet-month { width:auto; min-width:150px; }
.emd-sheet-st { font-size:11.5px; font-weight:600; border-radius:999px; padding:2px 10px; }
.emd-sheet-st.st-on { background:#DCFAE6; color:#067647; } .emd-sheet-st.st-off { background:#EEF1F6; color:#4B5565; }
.emd-sheet-st.st-wait { background:#FEF0C7; color:#93370D; } .emd-sheet-st.st-info { background:#E6F1FB; color:#0F4C84; }
.emd-sheet-table td { vertical-align:top; }
.emd-sheet-chip { display:inline-block; background:#E6F1FB; color:#0F4C84; font-size:12.5px; font-weight:600; border-radius:999px; padding:1px 10px; white-space:nowrap; }
.emd-sheet-long { display:inline-block; max-width:260px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; vertical-align:bottom; }
#sheet-print-root { display:none; }
@media print {
  body.sheet-printing > *:not(#sheet-print-root) { display:none !important; }
  body.sheet-printing #sheet-print-root { display:block !important; -webkit-print-color-adjust:exact; print-color-adjust:exact; }
  body.sheet-printing #sheet-print-root .emd-report { border:none; padding:0; min-width:0; }
}
.modal-box.modal-box-sheet { max-width:980px; }
.sb-modes { display:flex; flex-direction:column; gap:8px; }
.sb-mode { display:flex; gap:10px; align-items:flex-start; border:1px solid var(--border); border-radius:10px; padding:9px 12px; font-size:13.5px; cursor:pointer; }
.sb-mode.on { border:1.5px solid var(--blue); background:var(--blue-light); }
.sb-fields { display:flex; flex-direction:column; gap:8px; margin-bottom:10px; max-height:58vh; overflow-y:auto; padding-right:4px; }
.sb-field { border:1px solid var(--border); border-radius:12px; padding:9px 10px; background:var(--card); }
.sb-field.is-hidden { opacity:.65; background:var(--bg); }
.sb-field-top { display:flex; gap:6px; align-items:center; }
.sb-field-top .field-input { flex:1 1 140px; min-width:0; }
.sb-field-top .field-select { flex:0 0 150px; width:150px; }
.sb-field-no { flex:0 0 22px; font-size:12px; font-weight:700; color:var(--hint); text-align:center; }
.sb-opts { margin-top:6px; font-size:13px; resize:vertical; }
.sb-flags { display:flex; gap:6px; flex-wrap:wrap; margin-top:7px; }
.sb-flag { display:inline-flex; align-items:center; gap:5px; font-size:12.5px; border:1px solid var(--border); border-radius:999px; padding:3px 11px; cursor:pointer; }
.sb-flag.on { background:var(--blue-light); border-color:var(--blue-mid); }
.sb-flag input { margin:0; }
@media (max-width:680px) { .sb-field-top { flex-wrap:wrap; } .sb-field-top .field-select { flex:1 1 140px; width:auto; } }
.sb-filter { display:flex; gap:6px; align-items:center; flex-wrap:wrap; margin-top:7px; }
.sb-filter-lbl { font-size:12.5px; font-weight:600; color:var(--muted); margin-left:2px; }
