/* =============================================
   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;
  box-shadow: 0 8px 32px rgba(24, 95, 165, 0.08);
  text-align: center;
}

.login-logo-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.login-logo-img {
  width: 96px;
  height: 96px;
  object-fit: contain;
}

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

.login-sub {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 28px;
  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: 24px;
}

.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: 12px;
  border-bottom: 0.5px solid var(--border);
  margin-bottom: 4px;
}

.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; }

.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;
}

.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; }

/* Fullscreen sidebar-hidden */
.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; }
  body.fs-active #fs-menu-btn { display: flex; }
}
#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); }

.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;
}

/* ปุ่ม icon ใน topbar (theme + fullscreen) — 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: 10px 24px 24px;
  flex: 1;
  overflow-y: auto;
}

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

@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;
}

/* 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); }

.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 .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;
}
.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; }
.badge-type-fr  { background: var(--blue-light); color: #185FA5; }

/* 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; }  /* เทา — รอรายงานตัว */

.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; }
.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-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: var(--amber-light); color: #854F0B; }

/* Notification banner (W12 popup) */
.w12-notify-banner {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  background: #fff;
  border: 0.5px solid var(--border);
  border-left: 4px solid var(--red);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  padding: 14px 20px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  max-width: 480px;
  width: calc(100% - 32px);
  animation: slideDown .25s ease;
}
.w12-notify-banner.cancel { border-left-color: var(--green); }
.w12-notify-icon { font-size: 22px; color: var(--red); flex-shrink: 0; margin-top: 1px; }
.w12-notify-banner.cancel .w12-notify-icon { color: var(--green); }
.w12-notify-body { flex: 1; }
.w12-notify-title { font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.w12-notify-detail { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.w12-notify-close {
  background: none; border: none; color: var(--hint);
  cursor: pointer; font-size: 18px; flex-shrink: 0; line-height: 1;
}
.w12-notify-close:hover { color: var(--text); }

@keyframes slideDown {
  from { opacity: 0; transform: translate(-50%, -12px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* Sidebar affiliation */
.sb-affiliation {
  font-size: 11px;
  color: var(--blue);
  background: var(--blue-light);
  border-radius: 6px;
  padding: 4px 8px;
  margin-top: 6px;
  display: inline-block;
  text-align: center;
}

/* 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.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.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; }

/* =============================================
   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;
  z-index: 100;
  padding: 20px;
}
.modal-box {
  background: #fff;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 420px;
  /* overflow:hidden (ไม่ใช่ auto) เพื่อให้มุมโค้งครอบเนื้อหา/scrollbar ทุกด้านจริงๆ —
     ตัว scroll จริงอยู่ใน .modal-box-inner ข้างใน กันปัญหา scrollbar เหลี่ยมตัดมุมโค้ง */
  overflow: hidden;
  position: relative;
}
.modal-box-inner {
  padding: 24px;
  max-height: 90vh;
  overflow-y: auto;
}
.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; }

/* wrap หุ้ม modal-box เพื่อให้ปุ่มปิดเกาะขอบ */
#modal-wrap { width: 100%; max-width: 420px; }
#modal-wrap.modal-box-wide { max-width: 980px; }
#modal-wrap.modal-box-medium { max-width: 560px; }

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

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

/* ปุ่มปิดมุมบนขวาของ modal — เกาะขอบ modal-wrap */
.modal-close-x {
  position: absolute;
  top: -14px; right: -14px;
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all .15s;
  z-index: 10;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.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;
}
.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 calc(80px + env(safe-area-inset-bottom)); }
  .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 + fullscreen ใน topbar บน mobile */
  #topbar-theme-btn,
  #topbar-fullscreen-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; }

  /* ซ่อน 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 — เมนูเฉพาะ: Dashboard / รายงานความพร้อม / ว.12
   เนื้อหาเต็มความกว้างเท่า role อื่น (ฟอร์มต่างๆ self-center ด้วย .form-card)
   ============================================= */

/* เรียงเมนูใหม่: Dashboard > รายงานความพร้อม > ว.12 ก่อนเมนูอื่น */
body.role-hospital .sb-nav { display: flex; flex-direction: column; }
body.role-hospital .nav-item[data-page="dashboard"]  { order: 1; }
body.role-hospital .nav-item[data-page="readiness"]  { order: 2; }
body.role-hospital .nav-item[data-page="w12"]        { order: 3; }
body.role-hospital .nav-item[data-page="ambulance"]  { order: 4; }
body.role-hospital .nav-item[data-page="resources"]  { order: 5; }

/* =============================================
   DARK MODE (Night mode)
   เปิดผ่านปุ่มข้างนาฬิกา — แบบ manual หรือ auto ตามเวลา
   Auto: Day 07:00-19:00 / Night 19:01-06:59
   ============================================= */
body.theme-dark {
  --bg:          #0d1526;
  --card:        #1e2c47;
  --border:      #3a4f78;
  --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);
}

/* พื้นผิวหลัก — sidebar อ่อนกว่า --bg เล็กน้อยแบบเดียวกับโหมดกลางวัน (สว่างกว่า bg แต่ยัง
   เข้มกว่า --card) รักษาลำดับชั้นภาพ (sidebar ถอยหลัง, การ์ดเด่นขึ้นมาข้างหน้า) แทนที่สีเทาเข้ม
   #141B2B เดิมที่ตัดกับโทน --bg/--card ใหม่ (2026-07-10 ปรับให้สว่างขึ้น) จนดูคนละชุดสี */
body.theme-dark .sidebar      { background: #111c33; border-right-color: var(--border); }
body.theme-dark .topbar       { background: var(--card); }

/* Nav bar — sidebar (desktop)
   หมายเหตุ: hover/active ของแท็บนี้ถูก .als-sidebar .nav-item:hover/.active ใน
   als-style.css (specificity สูงกว่า) override อยู่แล้วเสมอ (ใช้ --als-red/--als-red-light
   ที่ปรับสีสำหรับ dark mode ไว้แล้ว) จึงแก้แค่สถานะปกติ (ไม่ hover) ให้สว่างขึ้นตรงนี้ */
body.theme-dark .nav-item { color: var(--muted); }
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); }
body.theme-dark .w12-notify-banner { background: var(--card); }

/* =============================================
   COORDINATOR — Modal แจ้งเตือน ว.12 กลางจอ
   พื้นหลังเฟดลง, ไม่ปิดเองจนกว่าจะกด
   ============================================= */
.coord-alert-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  animation: coordFadeIn .2s ease;
}
@keyframes coordFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.coord-alert-box {
  background: var(--card);
  border-radius: 20px;
  padding: 36px 32px;
  max-width: 380px;
  width: 90%;
  text-align: center;
  border: 2px solid transparent;
  box-shadow: 0 24px 60px rgba(0,0,0,0.28);
  animation: coordSlideUp .25s cubic-bezier(.34,1.56,.64,1);
}
@keyframes coordSlideUp {
  from { transform: translateY(24px) scale(.96); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

.coord-alert-box.alert-on  { border-color: var(--red); }
.coord-alert-box.alert-off { border-color: var(--green); }

.coord-alert-icon {
  font-size: 52px;
  line-height: 1;
  margin-bottom: 12px;
}
.alert-on  .coord-alert-icon { color: var(--red); }
.alert-off .coord-alert-icon { color: var(--green); }

.coord-alert-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  padding: 4px 14px;
  border-radius: 99px;
  margin-bottom: 14px;
}
.alert-on  .coord-alert-badge { background: var(--red-light); color: #A32D2D; }
.alert-off .coord-alert-badge { background: var(--green-light); color: #0F6E56; }

.coord-alert-unit {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  line-height: 1.3;
}
.coord-alert-reason {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 4px;
}
.coord-alert-time {
  font-size: 12px;
  color: var(--hint);
  margin-bottom: 24px;
}
.coord-alert-close {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 20px;
  padding: 11px 28px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity .15s;
}
.alert-on  .coord-alert-close { background: var(--red); color: #fff; }
.alert-off .coord-alert-close { background: var(--green); color: #fff; }
.coord-alert-close:hover { opacity: .85; }

body.theme-dark .coord-alert-box { background: #1A2333; }

/* 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,
body.theme-dark .w12type-14 {
  color: #FFC773;
}
body.theme-dark .badge-type-als { background: rgba(230, 99, 89, 0.3); color: #F5A8A3; }
body.theme-dark .badge-type-bls,
body.theme-dark .badge-type-fr  { 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 | FR/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-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; }
}

/* MD/EMD countdown alert */
.countdown-alert-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 9998;
  animation: coordFadeIn .2s ease;
}
.countdown-alert-box {
  background: var(--card);
  border-radius: 16px;
  padding: 28px 28px 24px;
  max-width: 340px; width: 90%;
  text-align: center;
  border: 2px solid transparent;
  animation: coordSlideUp .22s cubic-bezier(.34,1.56,.64,1);
}
.countdown-alert-box.alert-on  { border-color: var(--red); }
.countdown-alert-box.alert-off { border-color: var(--green); }
.countdown-alert-icon { font-size: 40px; line-height: 1; margin-bottom: 10px; }
.alert-on  .countdown-alert-icon { color: var(--red); }
.alert-off .countdown-alert-icon { color: var(--green); }
.countdown-alert-unit  { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.countdown-alert-badge { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.countdown-alert-reason{ font-size: 13px; color: var(--hint); margin-bottom: 16px; }
.countdown-alert-close {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 20px; border-radius: 8px; border: 0.5px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 13px; font-weight: 500;
  font-family: inherit; cursor: pointer; transition: opacity .15s;
}
.countdown-alert-close:hover { opacity: .75; }
body.theme-dark .countdown-alert-box { background: #1A2333; }

/* 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; }
}

/* 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;
}

/* =============================================
   Coordinator Dashboard Card (compact mode)
   หัว Card ใหญ่ขึ้น, ตัด contact-row/member ออก (ดูผ่าน tooltip แทน)
   ============================================= */
.unit-card.coord-view {
  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;
}
.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-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;
}

.cc-w12-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 14px;
  align-items: stretch;
}

.cc-w12-left {
  display: flex;
  flex-direction: column;
}

.cc-w12-left .cc-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.cc-w12-right {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.cc-w12-right .cc-panel {
  flex: 1;
}

/* รายการหน่วยใน CC form — scroll เต็มพื้นที่ที่เหลือของกล่อง */
.cc-unit-list {
  flex: 1;
  min-height: 200px;
  max-height: 480px;
  overflow-y: auto;
}

.cc-unit-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 0.5px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
  font-size: 12.5px;
}

.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-name {
  flex: 1;
  font-weight: 500;
  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;
}

.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: 72px; height: 72px;
  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: 20px;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
}

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

/* legend ใต้ chart */
.cc-legend {
  width: 100%;
  max-height: 130px;
  overflow-y: auto;
}

/* 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: 960px) {
  .cc-w12-layout { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .cc-charts-row { grid-template-columns: 1fr; }

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