/* PracticeEHR -- design system
   Clean, dense tables; color-coded status pills; one-click actions with
   confirmation only for destructive/mass changes; notes popovers that
   tint blue when filled. Single light theme (desktop app). */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1f2937;
  --text-muted: #6b7280;
  --text-faint: #9aa3b0;

  --sidebar-bg: #1b2431;
  --sidebar-bg-hover: #242f3f;
  --sidebar-text: #aab4c2;
  --sidebar-text-active: #ffffff;
  --sidebar-width: 220px;
  --sidebar-width-collapsed: 60px;

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eaf0fe;
  --teal: #0d9488;

  --green: #16a34a;   --green-soft: #dcfce7;
  --amber: #b45309;   --amber-soft: #fef3c7;
  --gray: #6b7280;    --gray-soft: #f0f1f3;
  --red: #dc2626;     --red-soft: #fee2e2;
  --blue: #2563eb;    --blue-soft: #dbeafe;

  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, 0.18);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- App shell ---------- */

#app-shell {
  display: none;
  height: 100vh;
}
#app-shell.visible { display: flex; }

#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  transition: width 0.15s ease, min-width 0.15s ease;
  overflow: hidden;
}
#sidebar.collapsed { width: var(--sidebar-width-collapsed); min-width: var(--sidebar-width-collapsed); }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand svg { flex: none; }

.sidebar-nav { flex: 1; padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px;
  border-radius: 6px;
  color: var(--sidebar-text);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.nav-item svg { flex: none; width: 18px; height: 18px; }
.nav-item:hover { background: var(--sidebar-bg-hover); color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; }
#sidebar.collapsed .nav-label { display: none; }
#sidebar.collapsed .nav-item { justify-content: center; }

.sidebar-footer {
  padding: 10px 8px 14px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#topbar {
  height: 52px;
  min-height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 14px;
}
#topbar .section-title { font-weight: 700; font-size: 16px; }
#topbar .spacer { flex: 1; }
#topbar .user-chip { color: var(--text-muted); font-size: 13px; }

#main-content { flex: 1; overflow: auto; padding: 22px; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn:hover { background: var(--gray-soft); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { color: var(--red); border-color: #f3c7c7; }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-icon { padding: 6px; border-radius: 6px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ---------- Cards / placeholders ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 18px 20px; }

.placeholder-card {
  max-width: 560px;
  margin: 60px auto;
  text-align: center;
  padding: 40px 30px;
}
.placeholder-card svg { width: 56px; height: 56px; color: var(--text-faint); margin-bottom: 14px; }
.placeholder-card h2 { margin: 0 0 8px; font-size: 17px; }
.placeholder-card p { margin: 0; color: var(--text-muted); line-height: 1.5; }

/* ---------- Tables ---------- */

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.search-input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  min-width: 240px;
  background: var(--surface);
}
.toolbar select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}
.search-input:focus, select:focus, textarea:focus, input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

table.data-table { width: 100%; border-collapse: collapse; background: var(--surface); }
table.data-table th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
}
table.data-table th:hover { color: var(--text); }
table.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data-table tbody tr:hover { background: #fafbfc; cursor: pointer; }
table.data-table tbody tr:last-child td { border-bottom: none; }
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.empty-row td { text-align: center; color: var(--text-faint); padding: 30px; cursor: default; }
.empty-row:hover { background: transparent !important; }

/* ---------- Status pills ---------- */

.pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 100px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: capitalize;
  white-space: nowrap;
}
.pill-green { background: var(--green-soft); color: var(--green); }
.pill-amber { background: var(--amber-soft); color: var(--amber); }
.pill-gray  { background: var(--gray-soft); color: var(--gray); }
.pill-red   { background: var(--red-soft); color: var(--red); }
.pill-blue  { background: var(--blue-soft); color: var(--blue); }

/* ---------- Notes popover (blue when filled) ---------- */

.notes-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-faint);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.notes-btn.filled { background: var(--blue-soft); border-color: #bcd3fb; color: var(--accent); }
.notes-btn:hover { border-color: var(--accent); }

.notes-popover {
  position: absolute;
  z-index: 60;
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 10px;
}
.notes-popover textarea {
  width: 100%;
  min-height: 90px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  resize: vertical;
}
.notes-popover .notes-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* ---------- Forms ---------- */

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 16px; }
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-field.span-2 { grid-column: span 2; }
.form-field label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.form-field input, .form-field select, .form-field textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.field-error { color: var(--red); font-size: 12.5px; min-height: 16px; }

/* ---------- Modal ---------- */

#modal-root { position: fixed; inset: 0; z-index: 100; pointer-events: none; }
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(17, 24, 39, 0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 20px;
  overflow: auto;
  pointer-events: auto;
}
.modal-box {
  background: var(--surface);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 640px;
}
.modal-box.modal-wide { max-width: 860px; }
.modal-header {
  display: flex; align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-header .spacer { flex: 1; }
.modal-close { cursor: pointer; color: var(--text-muted); background: none; border: none; font-size: 20px; line-height: 1; }
.modal-body { padding: 18px 20px; max-height: 68vh; overflow: auto; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Patient detail ---------- */

.detail-header {
  display: flex; align-items: center; gap: 14px; margin-bottom: 18px;
}
.detail-header h1 { margin: 0; font-size: 20px; }
.detail-header .sub { color: var(--text-muted); font-size: 13px; }
.detail-header .spacer { flex: 1; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tab-btn {
  padding: 9px 14px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.balance-hero { display: flex; align-items: baseline; gap: 8px; margin-bottom: 16px; }
.balance-hero .amount { font-size: 26px; font-weight: 700; }

.section-heading {
  display: flex; align-items: center; margin: 22px 0 10px;
}
.section-heading:first-child { margin-top: 0; }
.section-heading h4 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.section-heading .spacer { flex: 1; }

.kv-list { display: grid; grid-template-columns: 140px 1fr; row-gap: 8px; font-size: 13.5px; }
.kv-list dt { color: var(--text-muted); }
.kv-list dd { margin: 0; }

/* ---------- Schedule / weekly calendar ---------- */

.cal-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.cal-toolbar .cal-range { font-weight: 700; min-width: 200px; }

.calendar {
  display: grid;
  grid-template-columns: 64px repeat(7, 1fr);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.cal-corner, .cal-daycol-header {
  background: #fafbfc;
  border-bottom: 1px solid var(--border);
  border-left: 1px solid var(--border);
  padding: 8px 6px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  position: sticky; top: 0; z-index: 2;
}
.cal-corner { border-left: none; }
.cal-daycol-header .dow { color: var(--text-muted); font-weight: 600; display: block; font-size: 10.5px; text-transform: uppercase; }
.cal-daycol-header.today { color: var(--accent); }

.cal-timecol { border-left: none; }
.cal-timeslot {
  height: 44px;
  font-size: 10.5px;
  color: var(--text-faint);
  text-align: right;
  padding: 2px 8px 0 0;
  border-bottom: 1px solid #f0f1f3;
}
.cal-daycol { border-left: 1px solid var(--border); position: relative; }
.cal-slot { height: 44px; border-bottom: 1px solid #f0f1f3; cursor: pointer; }
.cal-slot:hover { background: var(--accent-soft); }

.cal-appt {
  position: absolute;
  left: 3px; right: 3px;
  background: var(--accent);
  color: #fff;
  border-radius: 5px;
  padding: 3px 6px;
  font-size: 11px;
  line-height: 1.3;
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.cal-appt.status-completed { background: var(--gray); }
.cal-appt.status-checked-in { background: var(--teal); }
.cal-appt.status-no-show { background: var(--red); }
.cal-appt .appt-time { opacity: 0.85; font-size: 10px; }

/* ---------- Login screen ---------- */

#login-screen, #must-change-screen {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #10192b 0%, #1b2431 100%);
}
#login-screen.visible, #must-change-screen.visible { display: flex; }
.login-box {
  width: 360px;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 30px 28px;
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; font-weight: 700; font-size: 17px; }
.login-box h2 { font-size: 15px; margin: 0 0 16px; color: var(--text-muted); font-weight: 600; }
.login-box .form-field { margin-bottom: 14px; }
.login-box .btn-primary { width: 100%; justify-content: center; padding: 10px; }
.login-error { color: var(--red); font-size: 13px; margin-bottom: 10px; min-height: 0; }
.login-hint { color: var(--text-faint); font-size: 12px; margin-top: 14px; text-align: center; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); margin-bottom: 14px; }
.checkbox-row input { width: auto; }

/* ---------- Exam form ---------- */

.exam-actionbar {
  position: sticky;
  top: -22px;            /* cancel #main-content's padding so it pins flush */
  z-index: 5;
  background: var(--bg);
  padding: 10px 0 12px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.exam-actionbar .spacer { flex: 1; }
.exam-dirty-dot {
  display: none;
  color: var(--amber);
  font-size: 12.5px;
  font-weight: 600;
}
.exam-dirty-dot.on { display: inline; }

.exam-section { margin-bottom: 14px; }
.exam-sec-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.exam-sec-head h3 {
  margin: 0;
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.exam-sec-head .spacer { flex: 1; }

.exam-input, .exam-section textarea {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
.exam-section textarea { min-height: 64px; resize: vertical; }
.exam-input[disabled], .exam-section textarea[disabled],
.exam-section input[disabled], .exam-section select[disabled] {
  background: var(--gray-soft);
  color: var(--text-muted);
}

.eye-grid { display: grid; gap: 8px 10px; align-items: center; }
.eye-grid .eg-h {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 700;
}
.eye-grid .eg-row-label { font-weight: 700; font-size: 12.5px; color: var(--text-muted); }

.w-code { max-width: 110px; }

.dx-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.dx-row .dx-num { width: 20px; text-align: right; color: var(--text-muted); font-weight: 700; flex: none; }
.dx-row .btn-icon { flex: none; }

.locked-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--blue-soft);
  border: 1px solid #bcd3fb;
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 13px;
}
.locked-banner svg { flex: none; color: var(--accent); }
.locked-banner .spacer { flex: 1; }

.amendment-card {
  border-left: 3px solid var(--amber);
  background: var(--surface);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.amendment-card .amend-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.amendment-card .amend-reason { font-weight: 600; margin-bottom: 4px; }
.amendment-card .amend-note { white-space: pre-wrap; }

/* ---------- Misc ---------- */

.text-muted { color: var(--text-muted); }
.mono { font-variant-numeric: tabular-nums; }
.qr-wrap { text-align: center; margin: 14px 0; }
.qr-wrap img { border: 1px solid var(--border); border-radius: 8px; }
.secret-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--gray-soft); padding: 6px 10px; border-radius: 6px; display: inline-block; letter-spacing: 0.05em; }
.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 200;
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px;
  box-shadow: var(--shadow-lg); font-size: 13px;
}
