/* ═══════════════════════════════════════════════════════════
   Emergency Response Staff — UI Theme
   Palette: Deep Red / Crisp White / Dark Slate
═══════════════════════════════════════════════════════════ */

:root {
  --red-700:   #B91C1C;
  --red-600:   #DC2626;
  --red-500:   #EF4444;
  --red-400:   #F87171;
  --red-100:   #FEE2E2;
  --red-50:    #FFF5F5;
  --dark-900:  #0F172A;
  --dark-800:  #1E293B;
  --dark-700:  #334155;
  --dark-600:  #475569;
  --slate-400: #94A3B8;
  --slate-200: #E2E8F0;
  --slate-100: #F1F5F9;
  --white:     #FFFFFF;
  --text-main: #0F172A;
  --text-muted:#64748B;
  --text-light:#94A3B8;
  --success:   #16A34A;
  --warning:   #D97706;
  --accent:    #DC2626;
  --card-bg:   #FFFFFF;
  --card-border:#E2E8F0;
  --card-shadow:rgba(15,23,42,0.08);
  --body-bg:   #F8FAFC;
  --sidebar-bg:#0F172A;
  --sidebar-w: 240px;
}

[data-theme="dark"] {
  --body-bg:    #0A0F1E;
  --card-bg:    #111827;
  --card-border:#1F2937;
  --card-shadow:rgba(0,0,0,0.4);
  --text-main:  #F1F5F9;
  --text-muted: #94A3B8;
  --text-light: #64748B;
  --slate-200:  #1F2937;
  --slate-100:  #1E293B;
  --sidebar-bg: #060B14;
}

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

body {
  font-family: 'Sarabun', 'Segoe UI', system-ui, sans-serif;
  background: var(--body-bg);
  color: var(--text-main);
  font-size: 0.9rem;
  min-height: 100vh;
}

a { text-decoration: none; color: inherit; }

/* ── SIDEBAR ─────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0;
  width: var(--sidebar-w); height: 100vh;
  background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  z-index: 100;
  border-right: 1px solid rgba(220,38,38,0.15);
}

.sidebar-brand {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 1.25rem 1.2rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-brand-icon {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, #B91C1C, #EF4444);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; color: #fff;
  box-shadow: 0 4px 12px rgba(185,28,28,0.5);
  flex-shrink: 0;
}

.sidebar-brand-text { line-height: 1.2; }
.sidebar-brand-text strong { display: block; font-size: 0.85rem; color: #fff; font-weight: 700; }
.sidebar-brand-text span   { font-size: 0.68rem; color: rgba(255,255,255,0.4); text-transform: uppercase; letter-spacing: 1px; }

.sidebar-nav { flex: 1; padding: 0.75rem 0; overflow-y: auto; }

.nav-section-label {
  font-size: 0.62rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1.5px; color: rgba(255,255,255,0.25);
  padding: 0.6rem 1.2rem 0.3rem;
}

.nav-item {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.6rem 1.2rem; margin: 1px 0.6rem;
  border-radius: 8px; cursor: pointer;
  color: rgba(255,255,255,0.55);
  font-size: 0.83rem; font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.9); }

.nav-item.active {
  background: linear-gradient(135deg, rgba(185,28,28,0.35), rgba(239,68,68,0.2));
  color: #FCA5A5;
  border-left: 3px solid #EF4444;
  margin-left: 0.3rem;
  padding-left: calc(1.2rem - 3px);
}

.nav-item i { width: 16px; text-align: center; font-size: 0.82rem; }

.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.sidebar-user {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.5rem 0.75rem; border-radius: 8px;
  background: rgba(255,255,255,0.04);
}

.sidebar-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg,#B91C1C,#EF4444);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem; color: #fff; font-weight: 700; flex-shrink: 0;
}

.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-info strong { display: block; font-size: 0.78rem; color: #E2E8F0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-info span { font-size: 0.67rem; color: rgba(255,255,255,0.3); }

.btn-logout {
  background: none; border: none; cursor: pointer;
  color: rgba(255,255,255,0.35); font-size: 0.85rem;
  padding: 4px; border-radius: 5px; transition: color 0.15s;
}
.btn-logout:hover { color: #EF4444; }

/* ── MAIN LAYOUT ─────────────────────────────────────────── */
.main-wrap { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  height: 56px; background: var(--card-bg);
  border-bottom: 1px solid var(--card-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky; top: 0; z-index: 50;
}

.topbar-left { display: flex; align-items: center; gap: 0.75rem; }
.topbar-title { font-size: 1rem; font-weight: 700; color: var(--text-main); }
.topbar-subtitle { font-size: 0.75rem; color: var(--text-muted); margin-top: 1px; }

.page-content { padding: 1.5rem; flex: 1; }

/* ── CARDS ───────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 1.25rem;
  box-shadow: 0 2px 12px var(--card-shadow);
}

.card-header-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.1rem;
}

.card-title {
  font-size: 0.78rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1.2px; color: var(--text-muted);
  display: flex; align-items: center; gap: 0.5rem;
}

.card-title::before {
  content: ''; display: inline-block;
  width: 3px; height: 14px;
  background: var(--red-600); border-radius: 2px;
}

/* ── STAT CARDS ──────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 1rem; margin-bottom: 1.5rem; }

.stat-card {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: 14px; padding: 1.1rem 1.25rem;
  box-shadow: 0 2px 10px var(--card-shadow);
  display: flex; align-items: center; gap: 1rem;
  transition: transform 0.15s;
}
.stat-card:hover { transform: translateY(-2px); }

.stat-icon {
  width: 44px; height: 44px; border-radius: 11px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}
.stat-icon.red   { background: rgba(220,38,38,0.12);  color: var(--red-600); }
.stat-icon.blue  { background: rgba(37,99,235,0.12);  color: #2563EB; }
.stat-icon.green { background: rgba(22,163,74,0.12);  color: var(--success); }
.stat-icon.amber { background: rgba(217,119,6,0.12);  color: var(--warning); }

.stat-body { min-width: 0; }
.stat-value { font-size: 1.6rem; font-weight: 800; color: var(--text-main); line-height: 1; }
.stat-label { font-size: 0.72rem; color: var(--text-muted); margin-top: 3px; font-weight: 500; }

/* ── BUTTONS ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.45rem 1rem; border: none; border-radius: 8px;
  font-size: 0.82rem; font-weight: 600; cursor: pointer;
  transition: opacity 0.15s, transform 0.12s; white-space: nowrap;
}
.btn:hover   { opacity: 0.88; transform: translateY(-1px); }
.btn:active  { transform: translateY(0); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary { background: linear-gradient(135deg, #B91C1C, #EF4444); color: #fff; box-shadow: 0 3px 10px rgba(185,28,28,0.35); }
.btn-danger  { background: rgba(220,38,38,0.12); color: var(--red-600); border: 1px solid rgba(220,38,38,0.2); }
.btn-danger:hover { background: rgba(220,38,38,0.22); opacity: 1; }
.btn-outline { background: transparent; color: var(--text-muted); border: 1px solid var(--card-border); }
.btn-outline:hover { background: var(--slate-100); opacity: 1; }
.btn-success { background: linear-gradient(135deg, #15803D, #22C55E); color: #fff; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.77rem; }
.btn-xs { padding: 0.2rem 0.55rem; font-size: 0.72rem; border-radius: 6px; }

/* ── BADGE ───────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.3px;
}
.badge-emt   { background: rgba(220,38,38,0.12); color: var(--red-600); }
.badge-emr   { background: rgba(37,99,235,0.12); color: #2563EB; }
.badge-active   { background: rgba(22,163,74,0.15);  color: #16A34A; }
.badge-inactive { background: rgba(100,116,139,0.12); color: #64748B; }

/* ── FORM CONTROLS ───────────────────────────────────────── */
.form-label {
  display: block; font-size: 0.77rem; font-weight: 600;
  color: var(--text-muted); margin-bottom: 0.3rem;
}
.form-label .req { color: var(--red-500); }

.form-control, .form-select {
  width: 100%;
  background-color: var(--card-bg);
  background-repeat: no-repeat;
  color: var(--text-main);
  border: 1px solid var(--card-border);
  border-radius: 8px; padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.form-control:focus, .form-select:focus {
  border-color: var(--red-500);
  box-shadow: 0 0 0 3px rgba(239,68,68,0.15);
}
textarea.form-control { resize: vertical; min-height: 72px; }

.form-row { display: grid; gap: 0.85rem; }
.form-row.col-2 { grid-template-columns: 1fr 1fr; }
.form-row.col-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-group { margin-bottom: 0.85rem; }

.invalid-feedback { font-size: 0.72rem; color: var(--red-500); margin-top: 3px; display: none; }
.was-validated .form-control:invalid ~ .invalid-feedback,
.was-validated .form-select:invalid  ~ .invalid-feedback { display: block; }

/* ── TABLE ───────────────────────────────────────────────── */
.tbl-wrap { overflow-x: auto; }

.tbl {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-size: 0.83rem;
}
.tbl thead th {
  background: var(--slate-100); color: var(--text-muted);
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
  padding: 0.6rem 0.85rem; white-space: nowrap;
  border-bottom: 2px solid var(--red-600);
  cursor: pointer; user-select: none;
}
.tbl thead th:first-child { border-radius: 8px 0 0 0; }
.tbl thead th:last-child  { border-radius: 0 8px 0 0; }
.tbl thead th .sort-icon  { margin-left: 4px; opacity: 0.4; font-size: 0.65rem; }
.tbl thead th.sort-asc .sort-icon,
.tbl thead th.sort-desc .sort-icon { opacity: 1; color: var(--red-500); }

.tbl tbody tr { transition: background 0.12s; }
.tbl tbody tr:hover { background: rgba(220,38,38,0.04); }
.tbl tbody td {
  padding: 0.65rem 0.85rem; border-bottom: 1px solid var(--card-border);
  vertical-align: middle; color: var(--text-main);
}
.tbl tbody tr:last-child td { border-bottom: none; }

/* ── TOOLBAR ─────────────────────────────────────────────── */
.toolbar {
  display: flex; align-items: center; gap: 0.65rem;
  flex-wrap: wrap; margin-bottom: 1rem;
}
.toolbar-search {
  position: relative; flex: 1; min-width: 180px; max-width: 300px;
}
.toolbar-search input {
  width: 100%; padding: 0.4rem 0.75rem 0.4rem 2rem;
  background-color: var(--card-bg); color: var(--text-main);
  border: 1px solid var(--card-border); border-radius: 8px;
  font-size: 0.82rem; outline: none; transition: border-color 0.15s;
}
.toolbar-search input:focus { border-color: var(--red-500); }
.toolbar-search .search-icon {
  position: absolute; left: 0.6rem; top: 50%; transform: translateY(-50%);
  color: var(--text-light); font-size: 0.75rem;
}
.toolbar select {
  padding: 0.4rem 0.7rem; background-color: var(--card-bg); color: var(--text-main);
  border: 1px solid var(--card-border); border-radius: 8px;
  font-size: 0.82rem; outline: none; cursor: pointer;
}
.toolbar-right { margin-left: auto; display: flex; gap: 0.5rem; }

/* ── PAGINATION ──────────────────────────────────────────── */
.pag-wrap { display: flex; align-items: center; gap: 0.3rem; margin-top: 0.85rem; justify-content: flex-end; flex-wrap: wrap; }
.pag-info { font-size: 0.75rem; color: var(--text-muted); margin-right: auto; }
.pag-btn {
  min-width: 30px; height: 30px; border-radius: 7px; border: 1px solid var(--card-border);
  background: var(--card-bg); color: var(--text-muted);
  font-size: 0.78rem; cursor: pointer; display: inline-flex;
  align-items: center; justify-content: center; transition: all 0.12s;
}
.pag-btn:hover  { border-color: var(--red-500); color: var(--red-600); }
.pag-btn.active { background: linear-gradient(135deg,#B91C1C,#EF4444); border-color: transparent; color: #fff; font-weight: 700; }
.pag-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── MODAL ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 1rem;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.modal-overlay.show { opacity: 1; pointer-events: all; }
.modal-overlay.show .modal-box { transform: scale(1) translateY(0); }
#modal-lightbox { z-index: 1100; }

.modal-box {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: 16px; width: 100%; max-width: 700px; max-height: 92vh;
  overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  transform: scale(0.96) translateY(12px); transition: transform 0.2s;
}
.modal-box.modal-sm  { max-width: 440px; }
.modal-box.modal-lg  { max-width: 900px; }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.3rem; border-bottom: 1px solid var(--card-border);
  position: sticky; top: 0; background: var(--card-bg); z-index: 5;
}
.modal-title { font-size: 0.95rem; font-weight: 700; color: var(--text-main); display: flex; align-items: center; gap: 0.5rem; }
.modal-title i { color: var(--red-500); }
.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-light); font-size: 1rem; padding: 4px;
  border-radius: 6px; transition: color 0.12s, background 0.12s;
}
.modal-close:hover { color: var(--red-500); background: var(--red-50); }
.modal-body   { padding: 1.3rem; }
.modal-footer { padding: 0.9rem 1.3rem; border-top: 1px solid var(--card-border); display: flex; justify-content: flex-end; gap: 0.5rem; }

/* ── SECTION INSIDE MODAL ────────────────────────────────── */
.form-section { margin-bottom: 1.25rem; }
.form-section-title {
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1.2px; color: var(--red-600);
  border-bottom: 1px solid var(--red-100); padding-bottom: 0.35rem;
  margin-bottom: 0.85rem; display: flex; align-items: center; gap: 0.4rem;
}

/* ── REPEATER (patients / vehicles) ─────────────────────── */
.repeater-row {
  background: var(--slate-100); border-radius: 10px;
  padding: 0.85rem; margin-bottom: 0.6rem; position: relative;
}
.repeater-row .btn-remove-row {
  position: absolute; top: 0.5rem; right: 0.5rem;
  background: none; border: none; color: var(--text-light);
  cursor: pointer; font-size: 0.85rem; padding: 3px 5px;
  border-radius: 5px; transition: color 0.12s;
}
.repeater-row .btn-remove-row:hover { color: var(--red-500); }

/* ── ALERT / TOAST ───────────────────────────────────────── */
.toast-stack { position: fixed; bottom: 1.5rem; right: 1.5rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 9999; }
.toast {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-left: 4px solid var(--red-500); border-radius: 10px;
  padding: 0.75rem 1rem; min-width: 240px; max-width: 320px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  display: flex; align-items: center; gap: 0.65rem;
  font-size: 0.82rem; color: var(--text-main);
  animation: slideInRight 0.25s ease;
}
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--red-500); }
.toast i { font-size: 1rem; }
.toast.success i { color: var(--success); }
.toast.error   i { color: var(--red-500); }
@keyframes slideInRight {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0);   opacity: 1; }
}

/* ── DETAIL VIEW ─────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem 1.5rem; }
.detail-item { }
.detail-label { font-size: 0.7rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; }
.detail-value { font-size: 0.87rem; color: var(--text-main); margin-top: 1px; font-weight: 500; }

/* ── LOGIN PAGE ──────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--dark-900); padding: 1rem;
  background-image: radial-gradient(circle at 20% 50%, rgba(185,28,28,0.15) 0%, transparent 50%),
                    radial-gradient(circle at 80% 20%, rgba(220,38,38,0.1) 0%, transparent 40%);
}

.login-card {
  background: var(--dark-800); border: 1px solid rgba(220,38,38,0.15);
  border-radius: 20px; padding: 2.5rem;
  width: 100%; max-width: 400px;
  box-shadow: 0 25px 60px rgba(0,0,0,0.6);
}

.login-logo {
  text-align: center; margin-bottom: 2rem;
}
.login-logo-icon {
  width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 0.85rem;
  background: linear-gradient(135deg,#B91C1C,#EF4444);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; color: #fff;
  box-shadow: 0 8px 24px rgba(185,28,28,0.5);
}
.login-logo h1 { font-size: 1.2rem; font-weight: 800; color: #fff; }
.login-logo p  { font-size: 0.75rem; color: rgba(255,255,255,0.4); margin-top: 2px; }

.login-card .form-label   { color: rgba(255,255,255,0.6); }
.login-card .form-control {
  background-color: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.1);
  color: #fff;
}
.login-card .form-control:focus { border-color: var(--red-500); box-shadow: 0 0 0 3px rgba(239,68,68,0.2); }
.login-card .form-control::placeholder { color: rgba(255,255,255,0.25); }

.btn-login {
  width: 100%; padding: 0.7rem;
  background: linear-gradient(135deg,#B91C1C,#EF4444);
  color: #fff; border: none; border-radius: 10px;
  font-size: 0.95rem; font-weight: 700; cursor: pointer;
  box-shadow: 0 6px 20px rgba(185,28,28,0.45);
  transition: opacity 0.15s, transform 0.12s; margin-top: 0.5rem;
}
.btn-login:hover { opacity: 0.9; transform: translateY(-1px); }

.login-error {
  background: rgba(220,38,38,0.12); border: 1px solid rgba(220,38,38,0.3);
  color: #FCA5A5; border-radius: 8px; padding: 0.55rem 0.85rem;
  font-size: 0.8rem; margin-bottom: 1rem; display: none;
}

/* ── CHIP / TAG ──────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 2px 10px; border-radius: 20px; font-size: 0.72rem; font-weight: 600;
  background: rgba(220,38,38,0.1); color: var(--red-600);
  border: 1px solid rgba(220,38,38,0.18);
}
.chip-multi { display: flex; flex-wrap: wrap; gap: 0.3rem; }

/* ── EMPTY STATE ─────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 3rem 1rem; color: var(--text-muted);
}
.empty-state i { font-size: 2.5rem; opacity: 0.3; margin-bottom: 0.75rem; display: block; }
.empty-state p { font-size: 0.85rem; }

/* ── RESPONSIVE ──────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar { transform: translateX(-240px); width: 240px; transition: transform 0.25s; }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }
  .form-row.col-2, .form-row.col-3 { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
}

/* ── SCROLLBAR ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(220,38,38,0.25); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(220,38,38,0.45); }
