:root {
  --surface-1: #ffffff;
  --page-plane: #f4f6f8;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --border: rgba(11,11,11,0.10);

  --brand: #2a78d6;
  --brand-dark: #184f95;
  --brand-tint: #eaf2fc;

  --good: #0ca30c;
  --good-tint: #e7f7e7;
  --warning: #fab219;
  --warning-tint: #fff6e2;
  --serious: #ec835a;
  --serious-tint: #fdece4;
  --critical: #d03b3b;
  --critical-tint: #fbe9e9;
}

* { box-sizing: border-box; }

/* The .login-screen/.app rules below set display:flex unconditionally, which otherwise
   overrides the browser's default [hidden]{display:none} behavior and keeps both
   screens visibly stacked even after JS sets the hidden attribute. Force it back. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--page-plane);
  color: var(--text-primary);
}

button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ---------- Login ---------- */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(160deg, var(--brand-dark), var(--brand));
}
.login-card {
  background: var(--surface-1);
  border-radius: 16px;
  padding: 40px;
  width: 380px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  text-align: center;
}
.login-logo { display: flex; justify-content: center; margin-bottom: 10px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-sub { color: var(--text-secondary); margin: 0 0 24px; font-size: 14px; }
.login-card form { text-align: right; }
.login-card label { display: block; font-size: 13px; color: var(--text-secondary); margin: 14px 0 6px; }
.login-card input { width: 100%; padding: 11px 12px; border: 1px solid var(--gridline); border-radius: 8px; }
.login-card input:focus { outline: none; border-color: var(--brand); }
.password-field-wrap { position: relative; }
.password-field-wrap input { padding-left: 40px; }
.password-toggle-btn {
  position: absolute;
  left: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 4px 6px;
  opacity: 0.6;
}
.password-toggle-btn:hover { opacity: 1; }

.btn-primary {
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 11px 18px;
  cursor: pointer;
  font-weight: 600;
}
.btn-primary:hover { background: var(--brand-dark); }
.btn-block { width: 100%; margin-top: 20px; }
.btn-secondary {
  background: var(--surface-1);
  color: var(--text-primary);
  border: 1px solid var(--gridline);
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
}
.btn-danger {
  background: var(--critical-tint);
  color: var(--critical);
  border: 1px solid var(--critical);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
.error-msg {
  background: var(--critical-tint);
  color: var(--critical);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-top: 14px;
}

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

.sidebar {
  width: 230px;
  background: #12233d;
  color: #dce6f4;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 20px 14px;
}
.sidebar-header { display: flex; align-items: center; gap: 10px; padding: 0 8px 20px; }
.sidebar-logo { display: flex; align-items: center; }
.sidebar-clinic-name { font-weight: 700; font-size: 15px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 8px;
  color: #c3d3e8;
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
  border: none;
  background: none;
  text-align: right;
  width: 100%;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: var(--brand); color: #fff; }
.nav-icon { font-size: 17px; width: 20px; text-align: center; }
.logout-btn { margin-top: auto; }

.main-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 64px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--gridline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}
.search-box { position: relative; width: 360px; max-width: 50vw; }
.search-box input {
  width: 100%;
  padding: 9px 36px 9px 12px;
  border: 1px solid var(--gridline);
  border-radius: 8px;
  background: var(--page-plane);
}
.search-icon { position: absolute; right: 12px; top: 9px; color: var(--text-muted); }
.search-results {
  position: absolute;
  top: 42px;
  right: 0;
  width: 100%;
  background: var(--surface-1);
  border: 1px solid var(--gridline);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  max-height: 320px;
  overflow-y: auto;
  z-index: 20;
}
.search-result-item { padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--gridline); font-size: 14px; }
.search-result-item:hover { background: var(--brand-tint); }
.search-result-item:last-child { border-bottom: none; }
.topbar-doctor { font-size: 14px; color: var(--text-secondary); font-weight: 600; }

.page-content { flex: 1; padding: 24px 28px; overflow-y: auto; }

/* ---------- Shared components ---------- */
.page-title { font-size: 20px; font-weight: 700; margin: 0 0 4px; }
.page-subtitle { color: var(--text-secondary); font-size: 13px; margin: 0 0 20px; }
.page-header-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface-1); border-radius: 12px; padding: 18px 20px; border: 1px solid var(--gridline); }
.stat-card .stat-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; }
.stat-card .stat-icon { font-size: 20px; margin-bottom: 8px; }

.card { background: var(--surface-1); border-radius: 12px; border: 1px solid var(--gridline); padding: 20px; margin-bottom: 20px; }
.card-title { font-size: 15px; font-weight: 700; margin: 0 0 14px; display: flex; align-items: center; gap: 8px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: right; color: var(--text-secondary); font-weight: 600; font-size: 12px; padding: 8px 10px; border-bottom: 2px solid var(--gridline); }
td { padding: 10px; border-bottom: 1px solid var(--gridline); }
tr:hover td { background: var(--page-plane); }
.table-link { cursor: pointer; color: var(--brand); }
.table-link:hover { text-decoration: underline; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 100px; font-size: 12px; font-weight: 600; }
.badge-good { background: var(--good-tint); color: var(--good); }
.badge-warning { background: var(--warning-tint); color: #8a5a00; }
.badge-serious { background: var(--serious-tint); color: #a34322; }
.badge-critical { background: var(--critical-tint); color: var(--critical); }
.badge-neutral { background: var(--page-plane); color: var(--text-secondary); }

.alert-critical {
  background: var(--critical-tint);
  border: 1px solid var(--critical);
  color: var(--critical);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field label { font-size: 13px; color: var(--text-secondary); font-weight: 600; }
.form-field input, .form-field select, .form-field textarea {
  padding: 9px 12px; border: 1px solid var(--gridline); border-radius: 8px; background: #fff;
}
.form-field textarea { resize: vertical; min-height: 70px; }
.form-field.full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; justify-content: flex-start; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--gridline); margin-bottom: 20px; }
.tab-btn {
  padding: 10px 16px; background: none; border: none; cursor: pointer;
  font-size: 14px; color: var(--text-secondary); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-btn.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }

.chart-bars { display: flex; align-items: flex-end; gap: 3px; height: 140px; }
.chart-bar { flex: 1; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(11,11,11,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-box { background: #fff; border-radius: 14px; padding: 24px; width: 480px; max-width: 100%; max-height: 90vh; overflow-y: auto; }
.modal-box h3 { margin-top: 0; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #12233d; color: #fff; padding: 12px 20px; border-radius: 10px;
  font-size: 14px; z-index: 200; box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

.prescription-item-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 2fr auto; gap: 8px; margin-bottom: 8px; align-items: center; }

.ai-analysis-box {
  background: var(--brand-tint);
  border: 1px solid var(--brand);
  border-radius: 10px;
  padding: 14px 16px;
  margin: 14px 0;
  font-size: 13.5px;
  line-height: 1.9;
}
.ai-analysis-header {
  font-weight: 700;
  color: var(--brand-dark);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.ai-analysis-date { font-weight: 400; font-size: 12px; color: var(--text-secondary); }
.ai-analysis-text { color: var(--text-primary); }
.ai-analysis-disclaimer { margin-top: 10px; font-size: 12px; color: var(--text-muted); }

.dropzone {
  border: 2px dashed var(--gridline);
  border-radius: 10px;
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  background: var(--page-plane);
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover { border-color: var(--brand); }
.dropzone.dragover { border-color: var(--brand); background: var(--brand-tint); }
.dropzone-icon { font-size: 26px; margin-bottom: 6px; }
.dropzone-text { font-size: 13px; color: var(--text-secondary); line-height: 1.6; }
.dropzone-filename { margin-top: 10px; font-size: 13px; font-weight: 600; color: var(--brand-dark); }

.report-content {
  font-size: 14px;
  line-height: 1.9;
  background: var(--page-plane);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 4px;
}
.report-content h4, .report-content h5, .report-content h6 {
  margin: 12px 0 6px;
  color: var(--brand-dark);
}
.report-content h4 { font-size: 16px; }
.report-content h5 { font-size: 14.5px; }
.report-content h6 { font-size: 14px; }
.report-content ul { margin: 4px 0 10px; padding-inline-start: 20px; }
.report-content li { margin-bottom: 4px; }
.report-content table { width: 100%; border-collapse: collapse; margin: 8px 0 14px; font-size: 12.5px; }
.report-content th, .report-content td { border: 1px solid var(--gridline); padding: 6px 8px; text-align: right; }
.report-content th { background: var(--brand-tint); color: var(--brand-dark); font-weight: 700; }
.report-content td { background: var(--surface-1); }

.report-summary-card {
  border-inline-start: 4px solid var(--brand-dark);
  background: var(--brand-tint);
}
.report-summary-text {
  font-size: 14.5px;
  line-height: 1.8;
  color: var(--text-primary);
  background: var(--surface-1);
  border-radius: 8px;
  padding: 10px 14px;
}

@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 50; height: 100vh; transform: translateX(100%); transition: transform 0.2s; }
  .sidebar.open { transform: translateX(0); }
  .search-box { width: 200px; }
}
