/* ============================================================
   DR. SARAH'S ESSENTIALS — DASHBOARD STYLES
   ============================================================ */

:root {
  --bg: #0d0f14;
  --surface: #161a23;
  --surface2: #1e2330;
  --border: #2a3042;
  --accent: #6c8fff;
  --accent2: #a78bfa;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #f59e0b;
  --text: #e8eaf0;
  --text-muted: #7c869e;
  --text-dim: #4a5568;
  --card-radius: 12px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── LOGIN SCREEN ─────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 50% 0%, #1a1f35 0%, var(--bg) 70%);
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px;
  width: 360px;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}

.login-logo {
  max-width: 220px;
  max-height: 80px;
  object-fit: contain;
  margin-bottom: 16px;
  border-radius: 6px;
}

.header-logo {
  max-height: 36px;
  max-width: 160px;
  object-fit: contain;
  border-radius: 4px;
}

.login-box h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 32px;
}

.login-box input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  margin-bottom: 12px;
  transition: border-color 0.2s;
}

.login-box input:focus { border-color: var(--accent); }

.login-box button {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.login-box button:hover { opacity: 0.88; }

.login-error {
  color: var(--red);
  font-size: 13px;
  margin-top: 10px;
  display: none;
}

/* ── APP SHELL ────────────────────────────────────────────── */
#app { display: none; }

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left { display: flex; align-items: center; gap: 16px; }

.header-brand {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.header-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

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

.date-display {
  font-size: 12px;
  color: var(--text-muted);
}

.refresh-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s;
}

.refresh-btn:hover { border-color: var(--accent); }

nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
}

.nav-tab {
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color 0.2s, border-color 0.2s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}

.nav-tab:hover { color: var(--text); }
.nav-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

main {
  padding: 24px 28px;
  max-width: 1400px;
  margin: 0 auto;
}

.tab-section { display: none; }
.tab-section.active { display: block; }

/* ── LOADING STATES ────────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13,15,20,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
  gap: 16px;
}

.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text { color: var(--text-muted); font-size: 14px; }

/* ── GRID LAYOUTS ─────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; margin-bottom: 16px; }

@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* ── CARDS ────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 20px;
}

.card-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* ── KPI TILES ────────────────────────────────────────────── */
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 20px;
}

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  margin-bottom: 6px;
}

.kpi-delta {
  font-size: 12px;
  font-weight: 600;
}

.kpi-delta.up { color: var(--green); }
.kpi-delta.down { color: var(--red); }
.kpi-delta.neutral { color: var(--text-muted); }

.kpi-sub {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ── DIAGNOSIS SECTIONS ───────────────────────────────────── */
.diagnosis-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.diagnosis-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 20px;
}

.diagnosis-card.up { border-left: 3px solid var(--green); }
.diagnosis-card.down { border-left: 3px solid var(--red); }

.diagnosis-card h3 {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.diagnosis-card.up h3 { color: var(--green); }
.diagnosis-card.down h3 { color: var(--red); }

.diagnosis-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
}

.diagnosis-item:last-child { border-bottom: none; }

.diagnosis-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }

/* ── UNIT ECONOMICS ───────────────────────────────────────── */
.unit-econ-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.unit-tile {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}

.unit-tile .value {
  font-size: 26px;
  font-weight: 700;
  color: var(--accent);
}

.unit-tile .label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-top: 4px;
}

.unit-tile .note {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 6px;
}

.highlight-tile {
  background: linear-gradient(135deg, #1a2540, #1e2a4a);
  border-color: var(--accent);
}

.highlight-tile .value { color: var(--accent); }

.cac-meter {
  margin-top: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 20px;
}

.cac-bar-wrap {
  background: var(--bg);
  border-radius: 6px;
  height: 10px;
  margin: 12px 0;
  overflow: hidden;
}

.cac-bar-fill {
  height: 100%;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--green), var(--yellow));
  transition: width 0.5s ease;
}

/* ── ROWS & TABLES ────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface2); }

/* ── BADGES ───────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
}

.badge.green { background: rgba(34,197,94,0.15); color: var(--green); }
.badge.red { background: rgba(239,68,68,0.15); color: var(--red); }
.badge.yellow { background: rgba(245,158,11,0.15); color: var(--yellow); }
.badge.blue { background: rgba(108,143,255,0.15); color: var(--accent); }

/* ── SECTION HEADERS ─────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-header h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.section-header .sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── PRIORITY ACTIONS ─────────────────────────────────────── */
.action-list { list-style: none; }

.action-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.action-item:last-child { border-bottom: none; }

.action-priority {
  min-width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  flex-shrink: 0;
}

.priority-1 { background: rgba(239,68,68,0.2); color: var(--red); }
.priority-2 { background: rgba(245,158,11,0.2); color: var(--yellow); }
.priority-3 { background: rgba(108,143,255,0.2); color: var(--accent); }

.action-content strong { display: block; font-size: 13px; color: var(--text); }
.action-content span { font-size: 12px; color: var(--text-muted); }

/* ── BAR CHART ────────────────────────────────────────────── */
.bar-chart { display: flex; flex-direction: column; gap: 10px; }

.bar-row { display: flex; align-items: center; gap: 10px; font-size: 12px; }

.bar-label { width: 80px; color: var(--text-muted); text-align: right; white-space: nowrap; }

.bar-track {
  flex: 1;
  background: var(--bg);
  border-radius: 4px;
  height: 8px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
  transition: width 0.5s ease;
}

.bar-val { width: 60px; color: var(--text); font-weight: 600; }

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

/* ── ERROR STATES ─────────────────────────────────────────── */
.error-msg {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  color: var(--red);
  margin-bottom: 16px;
}
