/* ===== Design Tokens ===== */
:root {
  --accent: #0F766E;        /* medical teal */
  --accent-dark: #0B5C56;
  --accent-light: #E6F5F3;
  --bg: #F7F9F9;
  --surface: #FFFFFF;
  --border: #E5E7EB;
  --text: #1F2937;
  --text-muted: #6B7280;
  --danger: #DC2626;
  --danger-light: #FEE2E2;
  --warning: #D97706;
  --warning-light: #FEF3C7;
  --success: #16A34A;
  --success-light: #DCFCE7;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --sidebar-width: 240px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
a { text-decoration: none; color: inherit; }
.muted { color: var(--text-muted); }

/* ===== App Shell ===== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  overflow-y: auto;
  z-index: 100;
  transform: translateX(-100%);
  transition: transform 0.25s cubic-bezier(.22,.9,.3,1);
}
body.pe-sidebar-visible .sidebar { transform: translateX(0); box-shadow: 10px 0 30px rgba(0,0,0,0.16); }
.sidebar-brand {
  font-size: 18px; font-weight: 700;
  padding: 8px 20px 20px;
  display: flex; align-items: center; gap: 8px;
}
.logo-badge {
  background: var(--accent); color: #fff;
  width: 30px; height: 30px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 800;
}
.sidebar-nav { display: flex; flex-direction: column; }
.sidebar-nav a {
  padding: 9px 20px;
  color: var(--text);
  font-size: 13.5px;
  border-left: 3px solid transparent;
}
.sidebar-nav a:hover { background: var(--accent-light); }
.sidebar-nav a.active {
  background: var(--accent-light);
  border-left-color: var(--accent);
  color: var(--accent-dark);
  font-weight: 600;
}
.nav-group-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); padding: 16px 20px 4px;
  font-weight: 700;
}

.main-area { margin-left: 0; flex: 1; min-width: 0; }

/* Dimmed backdrop behind the sidebar flyout (mobile-style "app drawer" feel) */
.sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,0.4);
  z-index: 90; opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease;
}
body.pe-sidebar-visible .sidebar-backdrop { opacity: 1; pointer-events: auto; }

/* Invisible hover strip along the screen's left edge — desktop only — that reveals
   the sidebar the moment the cursor reaches the edge, not just the tiny ☰ icon. */
.sidebar-hotzone { position: fixed; top: 0; bottom: 0; left: 0; width: 14px; z-index: 95; }
body.pe-sidebar-visible .sidebar-hotzone { display: none; } /* don't block the open sidebar's own edge */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 60px;
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  position: sticky; top: 0; z-index: 50;
}
.hamburger {
  position: relative; z-index: 101;
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; flex: 0 0 auto;
  background: var(--bg); border: 1px solid var(--border); border-radius: 9px;
  font-size: 16px; cursor: pointer; color: var(--text);
  transition: background 0.15s ease, transform 0.1s ease;
}
.hamburger:hover { background: var(--accent-light); }
.hamburger:active { transform: scale(0.94); }
.global-search { flex: 1; max-width: 420px; }
.global-search input {
  width: 100%; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); font-size: 13.5px;
}
.topbar-right { display: flex; align-items: center; gap: 18px; margin-left: auto; }
.notif-bell { font-size: 18px; cursor: pointer; }
.user-menu { display: flex; align-items: center; gap: 8px; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.logout-link { color: var(--text-muted); font-size: 13px; margin-left: 6px; }
.logout-link:hover { color: var(--danger); }

.page-content { padding: 24px; }

/* ===== Page header pattern ===== */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-header h1 { font-size: 20px; margin: 0 0 4px; }
.page-header p { margin: 0; color: var(--text-muted); font-size: 13px; }

/* ===== Cards / Stats ===== */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stat-card .label { font-size: 12.5px; color: var(--text-muted); margin-bottom: 6px; }
.stat-card .value { font-size: 24px; font-weight: 700; }
.stat-card .value.warn { color: var(--warning); }
.stat-card .value.danger { color: var(--danger); }
.stat-card .value.success { color: var(--success); }

/* ===== Alerts / Attention required ===== */
.alert { padding: 10px 14px; border-radius: 8px; font-size: 13.5px; margin-bottom: 14px; }
.alert-error { background: var(--danger-light); color: #7F1D1D; }
.alert-warning { background: var(--warning-light); color: #78350F; }
.alert-success { background: var(--success-light); color: #14532D; }

.attention-list { display: flex; flex-direction: column; gap: 8px; }
.attention-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-radius: 8px; background: var(--warning-light);
  font-size: 13.5px; cursor: pointer;
}
.attention-item.danger { background: var(--danger-light); }
.attention-item:hover { filter: brightness(0.97); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
  font-size: 13.5px; font-weight: 600; cursor: pointer; background: var(--surface);
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--bg); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }

/* ===== Forms ===== */
label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 5px; }
input, select, textarea {
  width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border);
  font-size: 13.5px; font-family: inherit; background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-light); border-color: var(--accent); }

/* ===== Status badges ===== */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-good { background: var(--success-light); color: #14532D; }
.badge-warning { background: var(--warning-light); color: #78350F; }
.badge-danger { background: var(--danger-light); color: #7F1D1D; }

/* ===== Tables ===== */
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { padding: 10px 12px; text-align: left; font-size: 13.5px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: var(--bg); }

/* ===== Empty state ===== */
.empty-state { text-align: center; padding: 50px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 40px; margin-bottom: 10px; }
.empty-state h3 { color: var(--text); margin: 6px 0; }

/* ===== Login page ===== */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(160deg, var(--accent-light), var(--bg)); }
.login-card { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 36px 34px; width: 100%; max-width: 380px; }
.login-brand { text-align: center; margin-bottom: 20px; }
.login-logo { width: 46px; height: 46px; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 800; font-size: 18px; display: inline-flex; align-items: center; justify-content: center; margin-bottom: 10px; }
.login-brand h1 { font-size: 19px; margin: 4px 0; }
.login-brand p { font-size: 13px; margin: 0; }
.login-hint { text-align: center; font-size: 12px; margin-top: 16px; }

/* ===== Mobile bottom nav (hidden on desktop; "app" tab bar on phones) ===== */
.mobile-bottom-nav { display: none; }

/* ===== Responsive ===== */
@media (min-width: 901px) {
  /* Desktop: reveal the sidebar on hover near the left edge / ☰ button too,
     handled in app.js — this just makes the flyout feel instant & light (no dimming
     needed on desktop since the mouse naturally leaves to close it). */
  .sidebar-backdrop { display: none; }
}
@media (max-width: 900px) {
  .sidebar-hotzone { display: none; } /* mobile uses tap, not hover */
  .page-content { padding: 16px 16px 80px; }
  .global-search { max-width: none; }
  .user-name { display: none; } /* keep topbar compact on phones */
  .mobile-bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--surface); border-top: 1px solid var(--border);
    box-shadow: 0 -4px 16px rgba(0,0,0,0.06);
    z-index: 80;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .mobile-bottom-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    gap: 2px; padding: 9px 0 7px; font-size: 19px; color: var(--text-muted);
    border-top: 2px solid transparent; transition: color 0.15s ease;
  }
  .mobile-bottom-nav a.active { color: var(--accent); border-top-color: var(--accent); }
  .mobile-bottom-nav a span { font-size: 10px; font-weight: 600; }
  .mobile-bottom-nav a:active { background: var(--accent-light); }
}
