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

:root {
  --red: #E8231A;
  --red-dark: #b81a13;
  --red-soft: rgba(232, 35, 26, 0.08);
  --dark: #F5F7FB;
  --dark2: #FFFFFF;
  --dark3: #EEF2F7;
  --border: rgba(15,23,42,0.10);
  --text: #101828;
  --muted: #667085;
  --success: #16A34A;
  --warning: #D97706;
  --card: rgba(255, 255, 255, 0.92);
  --topbar-bg: rgba(245, 247, 251, 0.86);
  --shadow-soft: 0 12px 28px rgba(15, 23, 42, 0.08);
}

body.dark-theme {
  --dark: #0D0F14;
  --dark2: #151820;
  --dark3: #1E2230;
  --border: rgba(255,255,255,0.07);
  --text: #F0F2F5;
  --muted: #6B7280;
  --card: rgba(30, 34, 48, 0.8);
  --topbar-bg: rgba(13, 15, 20, 0.85);
  --shadow-soft: none;
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--dark);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

h1, h2, h3, h4, h5 {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

/* ─── SIDEBAR ─── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: 240px;
  height: 100vh;
  background: var(--dark2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-logo {
  padding: 28px 24px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-mark {
  width: 36px; height: 36px;
  background: var(--red);
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}

.logo-text { font-family: 'Syne', sans-serif; font-weight: 700; font-size: 17px; }
.logo-text span { color: var(--red); }

.nav-section {
  padding: 20px 12px 8px;
  flex: 1;
  overflow-y: auto;
}

.nav-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--muted);
  text-transform: uppercase;
  padding: 0 12px 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 2px;
  text-decoration: none;
}

.nav-item:hover { background: var(--dark3); color: var(--text); }
.nav-item.active { background: var(--red-soft); color: var(--red); }
.nav-item.active .nav-icon { color: var(--red); }

.nav-icon {
  width: 18px; height: 18px;
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 20px;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}
.user-card:hover { background: var(--dark3); }

.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--dark3);
  border: 2px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--red);
  flex-shrink: 0;
}

.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; color: var(--muted); }

/* ─── MAIN LAYOUT ─── */
.main {
  margin-left: 240px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky; top: 0;
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 50;
}

.topbar-title { font-size: 18px; font-weight: 700; }
.topbar-sub { font-size: 13px; color: var(--muted); margin-top: 1px; }

.topbar-right { display: flex; align-items: center; gap: 12px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: rgba(255,255,255,0.15); background: var(--dark3); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.1); }
.btn-sm { padding: 6px 12px; font-size: 12px; }

.notif-btn {
  width: 38px; height: 38px;
  border-radius: 8px;
  background: var(--dark3);
  border: 1px solid var(--border);
  display: grid; place-items: center;
  cursor: pointer;
  position: relative;
  transition: background 0.2s;
}
.notif-btn:hover { background: #252836; }
body:not(.dark-theme) .notif-btn:hover { background: #E4E9F2; }

.theme-btn { color: var(--muted); }
.theme-btn svg { transition: transform .2s ease; }
.theme-btn:hover svg { transform: rotate(-12deg); }

.notif-dot {
  position: absolute;
  top: 8px; right: 8px;
  width: 8px; height: 8px;
  background: var(--red);
  border-radius: 50%;
  border: 2px solid var(--dark2);
}

/* ─── PAGE CONTENT ─── */
.page { padding: 32px; flex: 1; }

/* ─── CARDS ─── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-soft);
}

.card-body { padding: 24px; }
.card-header { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-title { font-size: 15px; font-weight: 700; }
.card-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ─── STATS GRID ─── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s;
}

.stat-card:hover { border-color: rgba(255,255,255,0.14); }

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--accent, var(--red));
}

.stat-label { font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 8px; }
.stat-value { font-family: 'Syne', sans-serif; font-size: 28px; font-weight: 800; line-height: 1; margin-bottom: 6px; }
.stat-change { font-size: 12px; color: var(--muted); }
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--red); }

.stat-icon {
  position: absolute;
  top: 20px; right: 20px;
  width: 36px; height: 36px;
  background: var(--red-soft);
  border-radius: 8px;
  display: grid; place-items: center;
  color: var(--red);
}

/* ─── STATUS BADGES ─── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-red { background: rgba(232,35,26,0.15); color: #f87171; }
.badge-green { background: rgba(22,163,74,0.15); color: #4ade80; }
.badge-yellow { background: rgba(217,119,6,0.15); color: #fbbf24; }
.badge-blue { background: rgba(59,130,246,0.15); color: #60a5fa; }
.badge-gray { background: rgba(107,114,128,0.15); color: var(--muted); }

.badge-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

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

table { width: 100%; border-collapse: collapse; }

thead tr { border-bottom: 1px solid var(--border); }

th {
  padding: 12px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

td {
  padding: 14px 16px;
  font-size: 13px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }

/* ─── GRID LAYOUTS ─── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-65-35 { display: grid; grid-template-columns: 1fr 380px; gap: 20px; }

/* ─── MAP PLACEHOLDER ─── */
.map-placeholder {
  width: 100%; height: 100%;
  min-height: 380px;
  background: var(--dark3);
  border-radius: 8px;
  position: relative;
  overflow: hidden;
}

.map-grid {
  position: absolute; inset: 0;
  background-image: 
    linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 40px 40px;
}

.map-dot {
  position: absolute;
  width: 12px; height: 12px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.map-dot.ambulance {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(232,35,26,0.2);
  animation: pulse-map 2s infinite;
}

.map-dot.patient {
  background: #60a5fa;
  box-shadow: 0 0 0 4px rgba(96,165,250,0.2);
}

@keyframes pulse-map {
  0%, 100% { box-shadow: 0 0 0 4px rgba(232,35,26,0.2); }
  50% { box-shadow: 0 0 0 12px rgba(232,35,26,0.05); }
}

/* ─── ALERT ITEM ─── */
.alert-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.alert-item:last-child { border-bottom: none; }
.alert-item:hover { background: rgba(255,255,255,0.02); }

.alert-icon {
  width: 38px; height: 38px;
  border-radius: 8px;
  display: grid; place-items: center;
  flex-shrink: 0;
}

.alert-icon.critical { background: rgba(232,35,26,0.15); color: var(--red); }
.alert-icon.moderate { background: rgba(217,119,6,0.15); color: #fbbf24; }
.alert-icon.stable { background: rgba(22,163,74,0.15); color: #4ade80; }

.alert-content { flex: 1; min-width: 0; }
.alert-name { font-size: 13px; font-weight: 600; margin-bottom: 3px; }
.alert-desc { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.alert-time { font-size: 11px; color: var(--muted); flex-shrink: 0; }

/* ALERTES PAGE */
.alertes-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  align-items: start;
}

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

.search-box {
  position: relative;
  flex: 1;
  min-width: 240px;
}

.search-box svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
}

.search-box .form-input { padding-left: 40px; }

.filter-tabs {
  display: flex;
  gap: 6px;
  background: var(--dark3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
}

.filter-tab {
  border: 0;
  border-radius: 6px;
  padding: 7px 11px;
  background: transparent;
  color: var(--muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.filter-tab:hover { color: var(--text); }
.filter-tab.active { background: var(--red); color: #fff; }

.alert-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 14px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.alert-row:last-child { border-bottom: none; }
.alert-row:hover, .alert-row.active { background: rgba(255,255,255,0.03); }
.alert-row.active { box-shadow: inset 3px 0 0 var(--red); }

.alert-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.alert-id {
  font-family: monospace;
  color: var(--muted);
  font-size: 12px;
}

.alert-actions {
  display: flex;
  align-items: flex-end;
  flex-direction: column;
  gap: 10px;
}

.detail-panel {
  position: sticky;
  top: 84px;
}

.detail-section {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.detail-section:last-child { border-bottom: none; }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.detail-field {
  background: var(--dark3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}

.detail-label {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 5px;
}

.detail-value {
  font-size: 13px;
  font-weight: 600;
}

.timeline {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.timeline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
  margin-top: 5px;
  box-shadow: 0 0 0 4px rgba(232,35,26,0.12);
}

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

.empty-state {
  padding: 34px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ─── FORM ─── */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 7px; text-transform: uppercase; letter-spacing: 0.05em; }
.form-input {
  width: 100%;
  background: var(--dark3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: 'DM Sans', sans-serif;
  color: var(--text);
  transition: border-color 0.2s;
  outline: none;
}
.form-input:focus { border-color: var(--red); }
.form-input::placeholder { color: var(--muted); }

select.form-input { cursor: pointer; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ─── HAMBURGER ─── */
.hamburger {
  display: none;
  width: 38px; height: 38px;
  background: var(--dark3);
  border: 1px solid var(--border);
  border-radius: 8px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
}

.hamburger span {
  width: 18px; height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: all 0.3s;
}

.overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
}

/* ─── RESPONSIVE ─── */
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-65-35 { grid-template-columns: 1fr; }
  .alertes-shell { grid-template-columns: 1fr; }
  .detail-panel { position: static; }
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .topbar { padding: 0 16px; }
  .page { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .hamburger { display: flex; }
  .overlay.open { display: block; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--dark); }
::-webkit-scrollbar-thumb { background: var(--dark3); border-radius: 3px; }

/* ─── ANIMATIONS ─── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn 0.4s ease forwards; }

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(232,35,26,0.1);
  border: 1px solid rgba(232,35,26,0.2);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  color: var(--red);
}

.live-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--red);
  animation: blink 1.2s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

/* ─── AMBULANCE STATUS CARDS ─── */
.amb-card {
  background: var(--dark3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: border-color 0.2s;
  cursor: pointer;
}

.amb-card:hover { border-color: rgba(255,255,255,0.12); }

.amb-num {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 15px;
  width: 40px; height: 40px;
  background: var(--dark);
  border-radius: 8px;
  display: grid; place-items: center;
  flex-shrink: 0;
}

.amb-info { flex: 1; }
.amb-id { font-size: 13px; font-weight: 600; }
.amb-loc { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ─── MOBILE APP STYLE (patient page) ─── */
.phone-wrap {
  display: flex;
  justify-content: center;
  padding: 40px 20px;
}

.phone-frame {
  width: 360px;
  background: #0a0c10;
  border-radius: 40px;
  border: 3px solid #2a2d38;
  overflow: hidden;
  box-shadow: 0 40px 80px rgba(0,0,0,0.6);
  position: relative;
}

.phone-notch {
  width: 120px; height: 28px;
  background: #0a0c10;
  border: 2px solid #2a2d38;
  border-radius: 0 0 16px 16px;
  margin: 0 auto;
  position: relative;
  z-index: 2;
}

.phone-screen {
  min-height: 700px;
  background: var(--dark);
  padding: 20px 20px 30px;
  display: flex;
  flex-direction: column;
}

.sos-btn {
  width: 160px; height: 160px;
  border-radius: 50%;
  background: var(--red);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 22px;
  color: #fff;
  box-shadow: 0 0 0 12px rgba(232,35,26,0.15), 0 0 0 24px rgba(232,35,26,0.07);
  transition: all 0.2s;
  align-self: center;
  margin: 20px auto;
  animation: sos-pulse 2.5s infinite;
}

@keyframes sos-pulse {
  0%, 100% { box-shadow: 0 0 0 12px rgba(232,35,26,0.15), 0 0 0 24px rgba(232,35,26,0.07); }
  50% { box-shadow: 0 0 0 18px rgba(232,35,26,0.08), 0 0 0 32px rgba(232,35,26,0.03); }
}

.sos-btn:hover { transform: scale(1.04); }
.sos-btn:active { transform: scale(0.97); }

/* ─── PROGRESS BAR ─── */
.progress-bar {
  height: 6px;
  background: var(--dark3);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--red);
  transition: width 0.5s ease;
}

/* ─── SECTION TITLE ─── */
.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 14px;
}

/* ─── SWEETALERT OVERRIDES ─── */
.swal2-popup {
  background: var(--dark2) !important;
  border: 1px solid var(--border) !important;
  border-radius: 14px !important;
  font-family: 'DM Sans', sans-serif !important;
  color: var(--text) !important;
}

.swal2-title { font-family: 'Syne', sans-serif !important; color: var(--text) !important; }
.swal2-html-container { color: var(--muted) !important; }
.swal2-confirm { background: var(--red) !important; border-radius: 8px !important; font-family: 'DM Sans', sans-serif !important; font-weight: 600 !important; }
.swal2-cancel { border-radius: 8px !important; font-family: 'DM Sans', sans-serif !important; font-weight: 600 !important; background: var(--dark3) !important; color: var(--text) !important; border: 1px solid var(--border) !important; }
.swal2-icon { border-color: var(--red) !important; }
.swal2-icon.swal2-warning { border-color: var(--warning) !important; color: var(--warning) !important; }
.swal2-icon.swal2-success { border-color: var(--success) !important; }
.swal2-icon.swal2-success [class^='swal2-success-line'] { background: var(--success) !important; }
.swal2-icon.swal2-success .swal2-success-ring { border-color: rgba(22,163,74,0.3) !important; }
