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

:root {
  /* Brand */
  --primary: #0F6B5C;
  --primary-dark: #0A4F44;
  --primary-light: #14876F;
  --primary-50: #E7F3F0;
  --secondary: #3B5B8C;
  --accent: #E9A23B;
  --accent-light: #F5C98A;

  /* Surfaces */
  --background: #F4F6F8;
  --surface: #FFFFFF;
  --surface-raised: #FFFFFF;
  --sidebar-bg: #0D2B26;
  --sidebar-bg-2: #0A211D;
  --sidebar-text: #C9DCD7;
  --sidebar-text-active: #FFFFFF;
  --sidebar-hover: rgba(255,255,255,0.06);
  --sidebar-active: rgba(255,255,255,0.10);

  /* Text */
  --text: #16211E;
  --muted: #6B7A77;
  --muted-2: #98A6A3;
  --border: #E6EAE9;
  --border-strong: #D3DAD8;

  /* Status */
  --success: #1E9E5A;
  --success-bg: #E7F6EE;
  --warning: #D9822B;
  --warning-bg: #FDF1E3;
  --danger: #D64545;
  --danger-bg: #FBEAEA;
  --info: #2E7DD1;
  --info-bg: #E9F1FC;

  --font-arabic: 'Tajawal', 'Segoe UI', Tahoma, sans-serif;

  --space-1: 4px; --space-2: 8px; --space-3: 12px;
  --space-4: 16px; --space-5: 24px; --space-6: 32px; --space-7: 48px;

  --radius-sm: 8px; --radius-md: 14px; --radius-lg: 20px; --radius-full: 999px;

  --shadow-1: 0 1px 2px rgba(16,40,34,0.06), 0 1px 3px rgba(16,40,34,0.08);
  --shadow-2: 0 4px 12px rgba(16,40,34,0.08), 0 2px 4px rgba(16,40,34,0.06);
  --shadow-3: 0 12px 32px rgba(16,40,34,0.14), 0 4px 8px rgba(16,40,34,0.06);
  --shadow-glow: 0 0 0 3px rgba(15,107,92,0.14);

  --duration-fast: 150ms; --duration-base: 220ms; --duration-slow: 380ms;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  --bp-mobile: 430px; --bp-tablet: 768px; --bp-desktop: 1024px;
}

/* ---------- Dark mode ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --background: #0F1715; --surface: #172420; --surface-raised: #1D2B26;
    --text: #EAF2EF; --muted: #93A6A1; --muted-2: #6B7C78;
    --border: #26362F; --border-strong: #33463D;
    --primary-50: rgba(15,107,92,0.16);
    --success-bg: rgba(30,158,90,0.16); --warning-bg: rgba(217,130,43,0.16);
    --danger-bg: rgba(214,69,69,0.16); --info-bg: rgba(46,125,209,0.16);
    --sidebar-bg: #08130F; --sidebar-bg-2: #050D0B;
  }
}
:root[data-theme="dark"] {
  --background: #0F1715; --surface: #172420; --surface-raised: #1D2B26;
  --text: #EAF2EF; --muted: #93A6A1; --muted-2: #6B7C78;
  --border: #26362F; --border-strong: #33463D;
  --primary-50: rgba(15,107,92,0.16);
  --success-bg: rgba(30,158,90,0.16); --warning-bg: rgba(217,130,43,0.16);
  --danger-bg: rgba(214,69,69,0.16); --info-bg: rgba(46,125,209,0.16);
  --sidebar-bg: #08130F; --sidebar-bg-2: #050D0B;
}

* { box-sizing: border-box; }
::selection { background: var(--primary); color: #fff; }

html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-arabic);
  background: var(--background);
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  transition: background var(--duration-base) var(--ease), color var(--duration-base) var(--ease);
}

/* Custom scrollbar — subtle, premium */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--radius-full); border: 2px solid var(--background); }
::-webkit-scrollbar-thumb:hover { background: var(--muted-2); }

a { color: var(--primary); text-decoration: none; transition: color var(--duration-fast) var(--ease); }

h1, h2, h3 { font-weight: 800; letter-spacing: -0.01em; margin: 0; }

.app-shell { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 272px;
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
  padding: var(--space-5) var(--space-3);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}
.sidebar::after {
  content: ''; position: absolute; inset-inline-end: 0; top: 0; bottom: 0; width: 1px;
  background: linear-gradient(180deg, transparent, rgba(255,255,255,0.08), transparent);
}
.sidebar .logo {
  font-weight: 800; font-size: 18px; color: #fff;
  padding: 0 var(--space-3) var(--space-5);
  display: flex; align-items: center; gap: 10px;
}
.sidebar .logo::before {
  content: '🎓'; font-size: 22px;
  width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary-light), var(--primary)); border-radius: var(--radius-sm);
  box-shadow: 0 4px 12px rgba(15,107,92,0.4);
}
.nav-toggle {
  display: none; margin-inline-start: auto;
  width: 38px; height: 38px; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.08); border: none; border-radius: var(--radius-sm);
  color: #fff; font-size: 18px; cursor: pointer;
  transition: background var(--duration-fast) var(--ease);
}
.nav-toggle:hover { background: rgba(255,255,255,0.14); }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 11px var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: 14px;
  position: relative;
  transition: background var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease), transform var(--duration-fast) var(--ease);
}
.sidebar nav a:hover { background: var(--sidebar-hover); color: var(--sidebar-text-active); transform: translateX(-2px); }
[dir="ltr"] .sidebar nav a:hover { transform: translateX(2px); }
.sidebar nav a.active {
  background: var(--sidebar-active); color: var(--sidebar-text-active); font-weight: 700;
}
.sidebar nav a.active::before {
  content: ''; position: absolute; inset-inline-end: -12px; top: 8px; bottom: 8px; width: 3px;
  background: var(--accent); border-radius: var(--radius-full);
}
.sidebar nav a[href="/emergency/new"] {
  background: rgba(214,69,69,0.18); color: #FFB4B4; font-weight: 700; margin: var(--space-2) 0;
}
.sidebar nav a[href="/emergency/new"]:hover { background: rgba(214,69,69,0.28); }

.main { flex: 1; padding: var(--space-5); max-width: 100%; overflow-x: hidden; animation: fadeIn var(--duration-slow) var(--ease); }

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

.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-5); flex-wrap: wrap; gap: var(--space-3); }
.topbar h1 { font-size: 22px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-1);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
  transition: box-shadow var(--duration-base) var(--ease), transform var(--duration-base) var(--ease);
}
.card:has(table):hover, .card:has(form):hover { box-shadow: var(--shadow-2); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--space-4); margin-bottom: var(--space-4); }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-1); padding: var(--space-4) var(--space-5);
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: var(--space-4);
  transition: transform var(--duration-base) var(--ease), box-shadow var(--duration-base) var(--ease);
}
.stat-card::before {
  content: ''; position: absolute; top: 0; inset-inline-start: 0; width: 4px; height: 100%;
  background: linear-gradient(180deg, var(--primary-light), var(--primary));
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-3); }
.stat-card .stat-body { flex: 1; min-width: 0; }
.stat-card .value { font-size: 30px; font-weight: 900; color: var(--primary); letter-spacing: -0.02em; line-height: 1.1; }
.stat-card .label { color: var(--muted); font-size: 13px; margin-top: 4px; font-weight: 500; }
.stat-card.urgent::before { background: linear-gradient(180deg, #E86B6B, var(--danger)); }
.stat-card.urgent .value { color: var(--danger); }

/* Icon bubbles — glossy gradient badges with real depth (highlight + layered shadow), used in stat
   cards, quick-action tiles, and the mobile bottom nav. This is the app's one deliberate "3D" touch —
   kept to icon badges only, not applied everywhere, so it reads as a considered accent, not a gimmick. */
.icon-bubble {
  --bubble-color: var(--primary);
  width: 52px; height: 52px; border-radius: var(--radius-md); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 24px;
  background: var(--bubble-color); /* fallback for browsers without color-mix() */
  background: linear-gradient(155deg, color-mix(in srgb, var(--bubble-color) 82%, white 18%), var(--bubble-color));
  box-shadow: 0 6px 14px rgba(15,107,92,0.32); /* fallback */
  box-shadow:
    inset 0 1px 1px rgba(255,255,255,0.45),
    inset 0 -6px 10px rgba(0,0,0,0.12),
    0 6px 14px color-mix(in srgb, var(--bubble-color) 38%, transparent);
  position: relative;
}
.icon-bubble::after {
  content: ''; position: absolute; top: 4px; inset-inline-start: 6px; width: 60%; height: 40%;
  border-radius: 50%; background: linear-gradient(rgba(255,255,255,0.55), rgba(255,255,255,0));
  filter: blur(1px);
}
.stat-card.urgent .icon-bubble { --bubble-color: var(--danger); }
.icon-bubble.sm { width: 40px; height: 40px; font-size: 18px; border-radius: var(--radius-sm); }

/* ---------- Mobile bottom navigation ---------- */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; inset-inline: 0; z-index: 90;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 20px rgba(16,40,34,0.10);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  align-items: center; justify-content: space-around;
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--muted); font-size: 10.5px; font-weight: 700; flex: 1; padding: 4px 2px;
  border-radius: var(--radius-sm); transition: color var(--duration-fast) var(--ease);
}
.bottom-nav a .bn-icon {
  width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
  font-size: 16px; border-radius: var(--radius-full); transition: background var(--duration-fast) var(--ease), transform var(--duration-fast) var(--ease);
}
.bottom-nav a.active { color: var(--primary); }
.bottom-nav a.active .bn-icon { background: var(--primary-50); transform: translateY(-1px); }
.bottom-nav a:active .bn-icon { transform: scale(0.9); }

/* The center "quick action" button floats slightly above the bar with real elevation */
.bottom-nav .bn-fab {
  width: 52px; height: 52px; border-radius: var(--radius-full); margin-top: -26px;
  background: linear-gradient(155deg, var(--primary-light), var(--primary));
  box-shadow:
    inset 0 1px 1px rgba(255,255,255,0.5),
    inset 0 -6px 10px rgba(0,0,0,0.15),
    0 8px 20px rgba(15,107,92,0.45);
  color: #fff; font-size: 24px;
  border: 3px solid var(--surface);
}
.bottom-nav .bn-fab.active { color: #fff; }
.bottom-nav .bn-fab.active .bn-icon { background: transparent; }
.bottom-nav a[href="/emergency/new"] .bn-icon { color: var(--danger); }
.bottom-nav a[href="/emergency/new"].active { color: var(--danger); }


/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: var(--radius-full); font-size: 12px; font-weight: 700;
  white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.badge-ok { background: var(--success-bg); color: var(--success); }
.badge-warn { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: right; padding: 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--muted); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr { transition: background var(--duration-fast) var(--ease); }
tbody tr:hover { background: var(--primary-50); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border-radius: var(--radius-sm);
  border: none; cursor: pointer; font-family: var(--font-arabic); font-weight: 700; font-size: 14px;
  transition: transform var(--duration-fast) var(--ease), box-shadow var(--duration-base) var(--ease), opacity var(--duration-fast) var(--ease), filter var(--duration-fast) var(--ease);
}
.btn-primary { background: linear-gradient(135deg, var(--primary-light), var(--primary)); color: #fff; box-shadow: 0 2px 8px rgba(15,107,92,0.28); }
.btn-primary:hover { filter: brightness(1.08); box-shadow: 0 4px 14px rgba(15,107,92,0.38); }
.btn-danger { background: linear-gradient(135deg, #E86B6B, var(--danger)); color: #fff; box-shadow: 0 2px 8px rgba(214,69,69,0.28); }
.btn-outline { background: var(--surface); border: 1.5px solid var(--border-strong); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-50); }
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ---------- Forms ---------- */
input, select, textarea {
  width: 100%; padding: 11px 14px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); font-family: var(--font-arabic); font-size: 14px;
  background: var(--surface); color: var(--text);
  transition: border-color var(--duration-fast) var(--ease), box-shadow var(--duration-fast) var(--ease);
}
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--shadow-glow); }
label { color: var(--text); }

/* ---------- Flash → toast ---------- */
.flash {
  padding: 14px 18px; border-radius: var(--radius-sm); margin-bottom: var(--space-4);
  font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 10px;
  border: 1px solid transparent;
}
.flash-success { background: var(--success-bg); color: var(--success); border-color: rgba(30,158,90,0.2); }
.flash-error { background: var(--danger-bg); color: var(--danger); border-color: rgba(214,69,69,0.2); }
.flash-warn { background: var(--warning-bg); color: var(--warning); border-color: rgba(217,130,43,0.2); }

.toast-container {
  position: fixed; top: env(safe-area-inset-top, 16px); left: 16px; z-index: 9999;
  display: flex; flex-direction: column; gap: 10px; max-width: 380px; width: calc(100% - 32px);
}
[dir="rtl"] .toast-container { left: auto; right: 16px; }
.toast-item {
  box-shadow: var(--shadow-3) !important; margin: 0 !important;
  animation: toastIn var(--duration-base) var(--ease);
}
.toast-item.toast-leaving { animation: toastOut var(--duration-base) var(--ease) forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-12px) scale(0.96); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-12px) scale(0.96); } }
@media (prefers-reduced-motion: reduce) { .toast-item, .toast-item.toast-leaving { animation: none !important; } }

/* ---------- Health grid ---------- */
.health-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-3); }
.health-item { display: flex; justify-content: space-between; align-items: center; padding: var(--space-3) var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--background); }

/* ---------- Theme toggle ---------- */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px;
  border-radius: var(--radius-full); background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-1); cursor: pointer; font-size: 15px;
  transition: transform var(--duration-fast) var(--ease), background var(--duration-fast) var(--ease);
}
.theme-toggle:hover { transform: scale(1.08); background: var(--primary-50); }

/* ---------- Skeleton loaders ---------- */
.skeleton { background: linear-gradient(90deg, var(--border) 25%, var(--border-strong) 37%, var(--border) 63%); background-size: 400% 100%; animation: skeletonShimmer 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes skeletonShimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

@media (max-width: 768px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%; border-inline-start: none; padding: var(--space-3) var(--space-3);
    position: sticky; top: 0; z-index: 100;
  }
  .sidebar::after { display: none; }
  .sidebar .logo { padding: 0; margin-bottom: 0; }
  .nav-toggle { display: flex; }
  .sidebar nav {
    max-height: 0; overflow: hidden; opacity: 0;
    margin-top: 0;
    transition: max-height var(--duration-slow) var(--ease), opacity var(--duration-base) var(--ease), margin-top var(--duration-slow) var(--ease);
  }
  .sidebar nav.open {
    max-height: 80vh; overflow-y: auto; opacity: 1; margin-top: var(--space-3);
  }
  .main {
    padding: var(--space-4);
    /* Reserve room for the fixed bottom nav (52px bar + FAB overhang + safe area) so content never hides behind it */
    padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  }
  .toast-container { left: 8px; right: 8px; width: auto; max-width: none; top: 8px; }

  .bottom-nav { display: flex; }

  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: var(--space-3); }
  .stat-card { padding: var(--space-3) var(--space-4); gap: var(--space-3); }
  .stat-card .value { font-size: 24px; }
  .stat-card .label { font-size: 11.5px; }
  .icon-bubble { width: 42px; height: 42px; font-size: 19px; border-radius: var(--radius-sm); }

  .card { padding: var(--space-4); border-radius: var(--radius-sm); }
  .topbar h1 { font-size: 19px; }
  .btn { font-size: 13.5px; padding: 10px 16px; }

  /* Touch targets: never smaller than 44px, the accessibility-minimum tap size */
  table .btn, td .btn { min-height: 40px; }
  input, select, textarea { font-size: 16px; } /* prevents iOS Safari auto-zoom on focus */
}


