:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e5e9;
  --text: #1d2b36;
  --muted: #6b7c8a;
  --accent: #2d6a4f;
  --accent-light: #d8f3dc;
  --good: #2d6a4f;
  --warn: #d4a017;
  --crit: #c0392b;
  --crit-bg: #fdecea;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

body.dark {
  --bg: #1a1d23;
  --surface: #252830;
  --border: #383d48;
  --text: #e4e6eb;
  --muted: #8b8f97;
  --accent: #4ade80;
  --accent-light: #1a3a26;
  --good: #4ade80;
  --warn: #f59e0b;
  --crit: #ef4444;
  --crit-bg: #3b1515;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

* { box-sizing:border-box; margin:0; padding:0; }

html, body { height:100%; font-family:var(--font); font-size:14px; color:var(--text); background:var(--bg); }

#shell { display:flex; height:100%; }
#sidebar {
  width:220px; background:var(--surface); border-right:1px solid var(--border);
  padding:12px 0; display:flex; flex-direction:column; flex-shrink:0;
}
.sidebar-header { padding:8px 16px 16px; font-size:16px; border-bottom:1px solid var(--border); margin-bottom:8px; }
.sidebar-header .dim { font-size:12px; display:block; margin-top:2px; }
.sidebar-section { padding:0 8px; margin-bottom:12px; }
.sidebar-label { font-size:10px; text-transform:uppercase; letter-spacing:0.5px; color:var(--muted); padding:4px 8px 6px; }
.sidebar-link {
  display:flex; align-items:center; gap:8px; padding:7px 8px; color:var(--text); text-decoration:none;
  border-radius:6px; font-size:13.5px; margin-bottom:1px;
}
.sidebar-link:hover { background:var(--bg); }
.sidebar-link.active { background:var(--accent-light); color:var(--accent); font-weight:600; }
.sidebar-footer {
  margin-top:auto; padding:12px 16px; border-top:1px solid var(--border);
  display:flex; align-items:center; gap:8px; font-size:13px;
}

main { flex:1; overflow-y:auto; padding:24px; }

#topbar { height:48px; }

.card {
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius);
  box-shadow:var(--shadow); margin-bottom:16px;
}
.card-head { padding:14px 18px; display:flex; align-items:center; gap:8px; border-bottom:1px solid var(--border); }
.card-head h3 { font-size:14px; font-weight:600; }
.card-body { padding:16px 18px; }
.card-body.flush { padding:0; }

.page-head { display:flex; align-items:flex-start; justify-content:space-between; margin-bottom:20px; }
.page-head h1 { font-size:22px; font-weight:700; }
.lede { color:var(--muted); font-size:13px; margin-top:4px; }
.actions { display:flex; gap:8px; flex-shrink:0; }

.btn {
  display:inline-flex; align-items:center; gap:4px; padding:6px 14px; background:var(--surface);
  border:1px solid var(--border); border-radius:6px; font-size:13px; cursor:pointer;
  color:var(--text); font-family:inherit;
}
.btn:hover { background:var(--bg); }
.btn.primary { background:var(--accent); color:#fff; border-color:var(--accent); }
.btn.primary:hover { opacity:0.9; }
.btn.danger { color:var(--crit); border-color:var(--crit); }
.btn.sm { padding:3px 10px; font-size:12px; }
.btn.ghost { border-color:transparent; background:transparent; }

.chip {
  display:inline-flex; align-items:center; gap:3px; padding:2px 8px; border-radius:12px;
  font-size:11.5px; font-weight:600; background:var(--bg); color:var(--muted);
}
.chip.good { background:#d8f3dc; color:var(--good); }
.chip.warn { background:#fef3cd; color:#856404; }
.chip.crit { background:var(--crit-bg); color:var(--crit); }
.chip.accent { background:var(--accent-light); color:var(--accent); }

.sub { color:var(--muted); font-size:12px; }
.dim { color:var(--muted); }
.muted { color:var(--muted); }
.micro { font-size:11px; font-weight:600; text-transform:uppercase; letter-spacing:0.3px; color:var(--muted); }
.num { font-variant-numeric:tabular-nums; }

.empty { text-align:center; padding:32px 16px; }
.empty .big { font-size:36px; margin-bottom:8px; }
.empty .t { font-size:14px; font-weight:600; }
.empty .d { font-size:12.5px; color:var(--muted); margin-top:4px; }

.input, .select, .textarea {
  width:100%; padding:7px 10px; border:1px solid var(--border); border-radius:6px;
  font-family:inherit; font-size:13.5px; background:var(--surface); color:var(--text);
}
.input:focus, .select:focus, .textarea:focus { outline:none; border-color:var(--accent); box-shadow:0 0 0 2px var(--accent-light); }

.row { display:flex; align-items:center; gap:10px; }
.stack { display:flex; flex-direction:column; gap:16px; }
.grid { display:grid; gap:16px; }

.avatar {
  display:inline-flex; align-items:center; justify-content:center;
  width:32px; height:32px; border-radius:50%; background:var(--accent-light);
  color:var(--accent); font-size:13px; font-weight:700;
}

#toast {
  position:fixed; bottom:24px; left:50%; transform:translateX(-50%);
  background:var(--text); color:#fff; padding:10px 20px; border-radius:8px; font-size:13px;
  opacity:0; transition:opacity 0.2s; z-index:1000;
}
#toast.show { opacity:1; }

.form-group { margin-bottom:10px; }
.form-group label { display:block; font-size:12px; font-weight:600; margin-bottom:4px; color:var(--text); }

.roster-table { width:100%; border-collapse:collapse; font-size:13.5px; }
.roster-table th { text-align:left; padding:10px 12px; font-size:11px; text-transform:uppercase; letter-spacing:0.3px; color:var(--muted); font-weight:600; background:var(--bg); border-bottom:1px solid var(--border); }
.roster-table td { padding:10px 12px; border-bottom:1px solid var(--border); vertical-align:middle; }
.roster-row:hover { background:#fafbfc; }
.roster-row.discharged { opacity:0.6; }
.roster-photo { width:36px; height:36px; border-radius:50%; object-fit:cover; display:block; }
.roster-avatar { width:36px; height:36px; font-size:12px; }
.roster-row .sub { font-size:12px; line-height:1.4; }

.intake-form { max-height:60vh; overflow-y:auto; padding:0; }
.intake-photo { width:80px; height:80px; border-radius:50%; background:var(--bg); display:flex; align-items:center; justify-content:center; font-size:28px; overflow:hidden; }

.hidden { display:none !important; }

#mobile-bar { display:none; }

/* Premium UI Extensions */
.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1b4332 0%, #081c15 100%);
  padding: 20px;
}
.auth-card {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
  width: 100%;
  max-width: 420px;
  padding: 32px;
  border: 1px solid rgba(255,255,255,0.1);
  animation: fadeIn 0.4s ease-out;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.auth-header {
  text-align: center;
  margin-bottom: 24px;
}
.auth-header h2 {
  font-size: 24px;
  color: var(--text);
  font-weight: 700;
  margin-bottom: 6px;
}
.auth-header p {
  color: var(--muted);
  font-size: 13px;
}
.auth-error {
  background: var(--crit-bg);
  color: var(--crit);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 12.5px;
  margin-bottom: 16px;
  border-left: 3px solid var(--crit);
}
.auth-success {
  background: var(--accent-light);
  color: var(--good);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 12.5px;
  margin-bottom: 16px;
  border-left: 3px solid var(--good);
}
.auth-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 12.5px;
  color: var(--muted);
}
.auth-footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
}
.auth-footer a:hover {
  text-decoration: underline;
}

/* Dashboard & Cards Grid */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}
.kpi-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.2s, box-shadow 0.2s;
}
.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}
.kpi-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  margin: 8px 0 4px;
}

/* Feed & List Layouts */
.feed-item {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  transition: background-color 0.15s;
}
.feed-item:last-child {
  border-bottom: none;
}
.feed-item:hover {
  background-color: var(--bg);
}
.feed-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 11.5px;
  color: var(--muted);
}

/* Roster / Tables */
.roster-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}
.roster-table th {
  background: var(--bg);
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.roster-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 13px;
}
.roster-table tr:hover td {
  background: var(--bg);
}

/* Calendar Scheduler */
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.cal-day-header {
  background: var(--bg);
  padding: 10px;
  text-align: center;
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
}
.cal-cell {
  background: var(--surface);
  min-height: 120px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cal-cell.today {
  background: #f1f8f5;
}
.cal-shift {
  background: var(--accent-light);
  color: var(--accent);
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border-left: 3px solid var(--accent);
}
.cal-shift:hover {
  opacity: 0.85;
}

/* Modal and Drawers */
/* Visibility is driven solely by the .show class — never the global .hidden
   helper, whose display:none !important can't be overridden by the modal
   open/close code. */
#modal-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  animation: fadeIn 0.2s ease-out;
}
#modal-backdrop.show { display: flex; }
#modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 500px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.15);
  animation: slideUp 0.25s ease-out;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-body {
  padding: 20px;
  max-height: 70vh;
  overflow-y: auto;
}
.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width:768px) {
  #shell { flex-direction:column; }

  /* Sidebar: hidden by default, slide-out drawer on tap */
  #sidebar {
    position:fixed; top:0; left:0; bottom:0; width:280px; z-index:1600;
    transform:translateX(-100%); transition:transform 0.25s ease;
    overflow-y:auto; padding:12px 0; display:flex !important; flex-direction:column;
  }
  #sidebar.hidden { display:flex !important; }
  #sidebar.mobile-open { transform:translateX(0); box-shadow:4px 0 16px rgba(0,0,0,0.2); }
  #sidebar .sidebar-header { display:block; }
  #sidebar .sidebar-section { display:flex; flex-direction:column; }
  #sidebar .sidebar-link { font-size:14px; padding:8px 12px; }
  #sidebar .sidebar-link span { display:inline; }
  #sidebar .sidebar-footer { display:flex; }

  /* Backdrop overlay when drawer is open */
  #sidebar.mobile-open::after {
    content:''; position:fixed; top:0; left:280px; right:0; bottom:0;
    background:rgba(0,0,0,0.3); z-index:-1;
  }

  main { padding:12px 8px 60px 8px; overflow-x:hidden; }

  #mobile-bar {
    display:flex; position:fixed; bottom:0; left:0; right:0; height:48px;
    background:var(--surface); border-top:1px solid var(--border); z-index:1500;
    align-items:center; justify-content:space-around; padding:0 12px;
  }
  #mobile-bar button {
    background:none; border:none; font-size:20px; padding:8px 16px;
    cursor:pointer; color:var(--text); min-width:44px; min-height:44px;
  }

  .page-head { flex-direction:column; gap:8px; }
  .page-head h1 { font-size:18px; }
  .actions { flex-wrap:wrap; gap:4px; }
  .actions .btn { padding:4px 10px; font-size:12px; }

  .dash-grid, .kpi-container { grid-template-columns: 1fr !important; }
  .kpi-card { padding:12px 14px; }
  .kpi-value { font-size:22px; }

  .card { border-radius:6px; margin-bottom:10px; }
  .card-head { padding:10px 12px; }
  .card-body { padding:10px 12px; }
  .card-body.flush { padding:0; }

  .roster-table { font-size:12px; display:block; overflow-x:auto; }
  .roster-table th, .roster-table td { padding:6px 8px; white-space:nowrap; }
  .roster-table th { font-size:10px; }

  #modal { max-width:calc(100vw - 24px); max-height:90vh; }
  .modal-body { max-height:60vh; padding:14px; }
  .modal-head { padding:10px 14px; }

  .cal-grid { grid-template-columns: 1fr; }

  .sched-scroll, .roster-table { -webkit-overflow-scrolling:touch; }

  #toast { bottom:60px; }

  /* Messages: stack sidebar + main vertically */
  .card[style*="display:flex"] { flex-direction:column !important; }
  .card[style*="display:flex"] > div:first-child { width:100% !important; max-height:120px; border-right:none !important; border-bottom:1px solid var(--border); }
  .card[style*="display:flex"] > div:last-child { flex:auto !important; min-height:350px; }

  .input, .select, .textarea { font-size:16px; } /* prevent iOS zoom */
}

@media (max-width:480px) {
  main { padding:8px 4px; }
  .kpi-value { font-size:18px; }
  #sidebar .sidebar-link { padding:4px 6px; }
}

