/* ------------------------------------------------------------------------
   Clinic Manager — local styling
   Aesthetic: refined medical / editorial. Soft neutrals, sage accent,
   serif headings paired with a humanist sans for UI.
   ------------------------------------------------------------------------ */

:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-2: #fafaf6;
  --ink: #1a1d1a;
  --ink-soft: #4a4f4a;
  --ink-mute: #8a8f87;
  --line: #e4e0d6;
  --line-soft: #efebe1;
  --accent: #2f5d50;
  --accent-soft: #d6e2dc;
  --accent-ink: #1a3a30;
  --danger: #a8392f;
  --danger-soft: #f3d9d5;
  --warn: #b07a2a;
  --warn-soft: #f4e5c8;
  --info: #3b5d8f;
  --info-soft: #d8e1ee;
  --radius: 6px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(20, 25, 20, 0.04);
  --shadow: 0 4px 16px rgba(20, 25, 20, 0.06);
  --font-display: "Fraunces", Georgia, serif;
  --font-sans: "Manrope", -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar -------------------------------------------------------- */

.sidebar {
  width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 24px 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px 24px;
  border-bottom: 1px solid var(--line-soft);
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 20px;
  font-family: var(--font-display);
}

.brand-name {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 11px;
  color: var(--ink-mute);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.nav {
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 2px;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  color: var(--ink-soft);
  text-decoration: none;
  font-weight: 500;
  font-size: 13.5px;
  transition: all 0.15s;
}

.nav-link:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.nav-icon {
  font-size: 16px;
  width: 18px;
  text-align: center;
  opacity: 0.8;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--line-soft);
}

.footer-label {
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--ink-mute);
  margin-bottom: 8px;
}

.quick-link {
  display: block;
  font-size: 12.5px;
  color: var(--ink-soft);
  text-decoration: none;
  padding: 4px 0;
  transition: color 0.15s;
}

.quick-link:hover { color: var(--accent); }

/* --- Main area ------------------------------------------------------ */

.main {
  flex: 1;
  padding: 40px 48px;
  max-width: 100%;
  overflow-x: auto;
}

/* --- Flash messages ------------------------------------------------- */

.flash-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.flash {
  padding: 12px 18px;
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 13px;
  box-shadow: var(--shadow);
  min-width: 240px;
}

.flash-success {
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-left: 3px solid var(--accent);
}

.flash-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-left: 3px solid var(--danger);
}

/* --- Page header ---------------------------------------------------- */

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 32px;
  gap: 20px;
  flex-wrap: wrap;
}

.page-title {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 500;
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.1;
}

.page-subtitle {
  color: var(--ink-mute);
  font-size: 13.5px;
  margin: 6px 0 0;
}

.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--surface);
  color: var(--ink);
}

.btn:hover { box-shadow: var(--shadow-sm); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-ink); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-soft);
}
.btn-ghost:hover { border-color: var(--ink-mute); color: var(--ink); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger-soft);
}
.btn-danger:hover { background: var(--danger-soft); }

.btn-sm { padding: 6px 10px; font-size: 12px; }

/* --- Cards & grids -------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.card-tight { padding: 18px; }

.card-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}

.card-section {
  margin-bottom: 28px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .main { padding: 24px; }
  .sidebar { width: 200px; }
}

/* --- Stat cards ---------------------------------------------------- */

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  position: relative;
  overflow: hidden;
}

.stat-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-mute);
  font-weight: 600;
  margin-bottom: 12px;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 36px;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1;
}

.stat-sub {
  font-size: 12px;
  color: var(--ink-mute);
  margin-top: 6px;
}

.stat-accent { color: var(--accent); }

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

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.data thead th {
  text-align: left;
  background: var(--surface-2);
  padding: 12px 18px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-mute);
  border-bottom: 1px solid var(--line);
}

table.data tbody td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }

table.data a { color: var(--accent-ink); text-decoration: none; font-weight: 500; }
table.data a:hover { text-decoration: underline; }

.empty {
  padding: 60px 24px;
  text-align: center;
  color: var(--ink-mute);
}

.empty-title {
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

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

.form-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(2, 1fr);
}

.form-grid .full { grid-column: 1 / -1; }

@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
}

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
}

.form-group .hint {
  font-size: 11.5px;
  color: var(--ink-mute);
  font-weight: 400;
  letter-spacing: 0;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="date"],
input[type="time"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: var(--font-sans);
  font-size: 13.5px;
  background: var(--surface);
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea { resize: vertical; min-height: 80px; font-family: var(--font-sans); }

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line-soft);
}

/* --- Badges & pills ------------------------------------------------ */

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
}

.badge-dental { background: var(--info-soft); color: var(--info); }
.badge-pediatric { background: var(--warn-soft); color: var(--warn); }
.badge-general { background: var(--line-soft); color: var(--ink-soft); }

.badge-scheduled { background: var(--info-soft); color: var(--info); }
.badge-completed { background: var(--accent-soft); color: var(--accent-ink); }
.badge-cancelled { background: var(--danger-soft); color: var(--danger); }
.badge-no-show { background: var(--line-soft); color: var(--ink-soft); }

/* Invoice / finance status badges */
.badge-paid { background: var(--accent-soft); color: var(--accent-ink); }
.badge-unpaid { background: var(--danger-soft); color: var(--danger); }
.badge-partial { background: var(--warn-soft); color: var(--warn); }
.badge-overdue {
  background: var(--danger);
  color: #fff;
  font-weight: 700;
}

/* Finance stat card variants */
.stat-finance-collected {
  background: linear-gradient(135deg, var(--accent-soft), var(--surface));
  border-color: var(--accent);
}
.stat-finance-collected .stat-value { color: var(--accent-ink); }

.stat-finance-outstanding {
  background: linear-gradient(135deg, var(--warn-soft), var(--surface));
  border-color: var(--warn);
}
.stat-finance-outstanding .stat-value { color: var(--warn); }

.stat-finance-overdue {
  background: linear-gradient(135deg, var(--danger-soft), var(--surface));
  border-color: var(--danger);
}
.stat-finance-overdue .stat-value { color: var(--danger); }

/* Outstanding balance pill on patient header */
.balance-pill {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  background: var(--warn-soft);
  border: 1px solid var(--warn);
  padding: 6px 14px;
  border-radius: var(--radius);
  margin-right: 4px;
}
.balance-label {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--warn);
  font-weight: 700;
}
.balance-amount {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--warn);
}

/* Invoice print totals */
.invoice-totals {
  margin-left: auto;
  max-width: 320px;
  margin-top: 18px;
}
.invoice-totals-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  font-size: 12.5px;
}
.invoice-totals-row.total {
  border-top: 2px solid var(--ink);
  margin-top: 6px;
  padding-top: 10px;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
}
.invoice-totals-row.paid {
  color: var(--accent-ink);
}
.invoice-totals-row.balance {
  border-top: 1px solid var(--line);
  margin-top: 4px;
  padding-top: 8px;
  font-weight: 700;
  font-size: 14px;
}

/* PAID stamp on receipts */
.paid-stamp {
  position: absolute;
  top: 280px;
  right: 80px;
  transform: rotate(-18deg);
  font-family: var(--font-display);
  font-size: 56px;
  font-weight: 700;
  color: var(--accent);
  border: 4px solid var(--accent);
  padding: 6px 24px;
  border-radius: 4px;
  letter-spacing: 0.08em;
  opacity: 0.45;
  pointer-events: none;
}

.print-page { position: relative; }

/* --- Filter bar ---------------------------------------------------- */

.filter-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.chip {
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-soft);
  text-decoration: none;
  transition: all 0.15s;
}

.chip:hover { border-color: var(--ink-mute); }
.chip.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.filter-bar form {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: auto;
}

.filter-bar input[type="search"],
.filter-bar input[type="date"] {
  padding: 7px 12px;
  font-size: 13px;
  width: auto;
}

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

.patient-header {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 28px;
  margin-bottom: 24px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 24px;
  align-items: center;
}

.avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
}

.patient-name {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 500;
  letter-spacing: -0.02em;
  margin: 0;
}

.patient-meta {
  display: flex;
  gap: 16px;
  color: var(--ink-mute);
  font-size: 13px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.patient-meta span::before {
  content: "·";
  margin-right: 12px;
  color: var(--ink-mute);
}

.patient-meta span:first-child::before { content: ""; margin: 0; }

.info-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px 32px;
}

@media (max-width: 720px) {
  .info-grid { grid-template-columns: 1fr; }
  .patient-header { grid-template-columns: 1fr; text-align: center; }
}

.info-item .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-mute);
  font-weight: 600;
  margin-bottom: 4px;
}

.info-item .value {
  font-size: 14px;
  color: var(--ink);
  word-break: break-word;
}

.empty-value { color: var(--ink-mute); font-style: italic; }

/* --- Record entries ----------------------------------------------- */

.record-list { display: flex; flex-direction: column; gap: 12px; }

.record-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}

.record-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 12px;
}

.record-date {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  color: var(--accent-ink);
}

.record-body {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 24px;
  font-size: 13px;
}

@media (max-width: 720px) {
  .record-body { grid-template-columns: 1fr; }
}

.record-field b {
  font-weight: 600;
  color: var(--ink-soft);
  margin-right: 4px;
}

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

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.section-head h2 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 500;
  margin: 0;
  letter-spacing: -0.01em;
}

.muted { color: var(--ink-mute); }
.mb-0 { margin-bottom: 0; }
.mt-3 { margin-top: 24px; }

.divider {
  height: 1px;
  background: var(--line-soft);
  margin: 24px 0;
}

.inline-form { display: inline; }

/* ------------------------------------------------------------------------
   PRINT VIEWS — dedicated print pages
   ------------------------------------------------------------------------ */

.print-body {
  display: block;
  background: #ddd;
  padding: 24px 0;
}

.print-toolbar {
  max-width: 8.5in;
  margin: 0 auto 18px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.print-page {
  max-width: 8.5in;
  margin: 0 auto;
  background: #fff;
  padding: 0.75in 0.75in 1in;
  min-height: 11in;
  box-shadow: 0 6px 32px rgba(0, 0, 0, 0.18);
  color: #1a1d1a;
  font-family: var(--font-sans);
  font-size: 12.5px;
  line-height: 1.55;
}

/* ----- Headers and patient block ----- */

.rx-header,
.print-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 16px;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--ink);
}

.rx-clinic,
.print-clinic {
  display: flex;
  align-items: center;
  gap: 12px;
}

.rx-clinic-mark {
  width: 44px; height: 44px;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 24px;
}

.rx-clinic-name {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.rx-clinic-sub {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

.rx-doctor {
  text-align: right;
}

.rx-doctor-name {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
}

.rx-doctor-meta {
  font-size: 11.5px;
  color: var(--ink-soft);
  margin-top: 1px;
}

.print-doc-title { text-align: right; }
.print-doc-title h1 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 500;
  margin: 0;
  letter-spacing: -0.01em;
}

.rx-patient-block {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px 18px;
  margin-bottom: 24px;
}

.rx-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 24px;
  font-size: 12.5px;
}

.rx-grid .span-2 { grid-column: span 2; }

.rx-label {
  color: var(--ink-mute);
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  font-weight: 600;
  margin-right: 4px;
}

/* ----- The big Rx symbol ----- */

.rx-symbol {
  font-family: var(--font-display);
  font-size: 68px;
  line-height: 1;
  color: var(--accent);
  margin: 8px 0 12px;
  font-weight: 500;
}

/* ----- Medications list ----- */

.rx-meds {
  list-style: none;
  padding: 0;
  margin: 0 0 24px;
  counter-reset: med-counter;
}

.rx-med {
  counter-increment: med-counter;
  padding: 14px 0 14px 36px;
  border-bottom: 1px solid var(--line-soft);
  position: relative;
}

.rx-med:last-child { border-bottom: none; }

.rx-med::before {
  content: counter(med-counter) ".";
  position: absolute;
  left: 0;
  top: 14px;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  color: var(--accent);
}

.rx-med-name {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}

.rx-med-dose {
  font-weight: 500;
  color: var(--ink-soft);
}

.rx-med-form {
  color: var(--ink-mute);
  font-size: 13px;
  font-weight: 400;
  font-style: italic;
}

.rx-med-sig {
  font-size: 12.5px;
  color: var(--ink-soft);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.rx-med-instructions {
  font-size: 11.5px;
  color: var(--ink-mute);
  font-style: italic;
  margin-top: 4px;
}

.rx-notes {
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  padding: 12px 16px;
  margin-bottom: 24px;
  font-size: 12px;
}

.rx-notes p { margin: 4px 0 0; }

/* ----- Footer / signature ----- */

.rx-footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 80px;
  padding-top: 14px;
}

.rx-validity { font-size: 11px; color: var(--ink-mute); }

.rx-signature { text-align: center; }

.rx-sig-line {
  width: 240px;
  height: 1px;
  background: var(--ink);
  margin-bottom: 6px;
}

.rx-sig-label {
  font-size: 11.5px;
  color: var(--ink-soft);
}

/* ----- Print tables ----- */

.print-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
  margin-bottom: 24px;
}

.print-table thead th {
  background: var(--ink);
  color: #fff;
  text-align: left;
  padding: 9px 10px;
  font-weight: 600;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.print-table tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}

.print-table tbody tr.subrow td {
  border-bottom: 1px solid var(--line);
  padding-top: 0;
  padding-bottom: 8px;
  font-size: 11px;
  color: var(--ink-soft);
}

.print-table tbody tr.total-row td {
  border-top: 2px solid var(--ink);
  border-bottom: none;
  padding-top: 10px;
  font-size: 13px;
}

/* ----- Report sections ----- */

.report-section {
  margin-bottom: 22px;
}

.report-section h2 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.report-section h3 {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 4px;
}

.report-section p { margin: 0 0 8px; }

.visit-entry {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px dotted var(--line);
}

.visit-entry:last-child { border-bottom: none; }

.visit-date {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  color: var(--accent-ink);
  margin-bottom: 4px;
}

.visit-body { font-size: 11.5px; line-height: 1.6; }
.visit-body > div { margin-bottom: 2px; }
.visit-body b { color: var(--ink-soft); }

.rx-summary {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 14px;
  margin-bottom: 12px;
}

.rx-summary-head {
  font-size: 12px;
  margin-bottom: 6px;
}

.rx-summary-meds {
  margin: 0;
  padding-left: 18px;
  font-size: 11.5px;
}

.rx-summary-meds li { margin-bottom: 4px; }

.avoid-break {
  page-break-inside: avoid;
  break-inside: avoid;
}

/* ------------------------------------------------------------------------
   @media print — actual printer output
   ------------------------------------------------------------------------ */

@media print {
  @page {
    size: letter;
    margin: 0.5in;
  }

  body, .print-body {
    background: #fff !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .no-print,
  .sidebar,
  .flash-container,
  .page-actions,
  .print-toolbar,
  .menu-toggle,
  .sidebar-backdrop {
    display: none !important;
  }

  .print-page {
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
    min-height: 0 !important;
  }

  .main { padding: 0 !important; }

  a { color: inherit !important; text-decoration: none !important; }

  /* Ensure backgrounds and borders print */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}

/* ------------------------------------------------------------------------
   AUTH PAGES (login, setup)
   ------------------------------------------------------------------------ */

.auth-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background: linear-gradient(135deg, #f7f5f0 0%, #e8ebe4 100%);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 32px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 16px 48px rgba(20, 25, 20, 0.08);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line-soft);
}

.auth-flash {
  margin-bottom: 16px;
  min-width: 0;
}

.auth-form .form-group { margin-bottom: 14px; }

.auth-submit {
  width: 100%;
  padding: 12px;
  margin-top: 8px;
  font-size: 14px;
}

.auth-foot {
  text-align: center;
  font-size: 12px;
  color: var(--ink-mute);
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--line-soft);
}

/* ------------------------------------------------------------------------
   ROLE BADGES & USER CARD
   ------------------------------------------------------------------------ */

.badge.role-admin       { background: #f3d9d5; color: #a8392f; }
.badge.role-doctor      { background: #d6e2dc; color: #1a3a30; }
.badge.role-receptionist{ background: #d8e1ee; color: #3b5d8f; }
.badge.role-billing     { background: #f4e5c8; color: #b07a2a; }

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--surface-2);
  border-radius: var(--radius);
  margin-bottom: 4px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  flex-shrink: 0;
}

.user-info { min-width: 0; flex: 1; }
.user-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role {
  font-size: 11px;
  color: var(--ink-mute);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ------------------------------------------------------------------------
   MOBILE — hamburger toggle, sliding sidebar, touch-friendly UI
   ------------------------------------------------------------------------ */

.menu-toggle {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 200;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 20px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.2s;
}

.sidebar-backdrop.open {
  display: block;
  opacity: 1;
}

@media (max-width: 768px) {
  body {
    /* Stack instead of side-by-side */
    flex-direction: column;
  }

  .menu-toggle { display: grid; place-items: center; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 280px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    padding-top: 60px; /* room for menu button area */
  }

  .sidebar.open { transform: translateX(0); }

  .main {
    padding: 70px 18px 24px;
    width: 100%;
  }

  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .page-title { font-size: 26px; }

  .page-actions {
    flex-wrap: wrap;
  }

  .btn { padding: 11px 16px; font-size: 13.5px; }
  .btn-sm { padding: 8px 12px; font-size: 12.5px; }

  .stat-card { padding: 16px 18px; }
  .stat-value { font-size: 30px; }

  /* Tables scroll horizontally on narrow screens */
  .table-wrap { overflow-x: auto; }
  table.data { min-width: 600px; }
  table.data thead th, table.data tbody td {
    padding: 10px 12px;
    font-size: 12.5px;
  }

  /* Patient header reflows */
  .patient-header {
    grid-template-columns: 1fr;
    text-align: left;
    padding: 20px;
    gap: 16px;
  }

  .info-grid { grid-template-columns: 1fr 1fr; gap: 14px 16px; }

  .form-grid { grid-template-columns: 1fr; gap: 14px; }

  .flash-container {
    top: auto;
    bottom: 16px;
    left: 16px;
    right: 16px;
  }
  .flash { min-width: 0; }

  /* Bigger tap targets */
  .nav-link { padding: 14px 16px; font-size: 14.5px; }
  input, select, textarea { font-size: 16px !important; /* prevents iOS zoom-on-focus */ }

  .record-body { grid-template-columns: 1fr; }

  /* Auth card full width */
  .auth-card { padding: 24px; border-radius: 12px; }

  /* Account page grid stacks */
  .grid-2 { grid-template-columns: 1fr; }

  /* Outstanding balance widget */
  .balance-widget {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
  }
}

@media (max-width: 480px) {
  .main { padding: 70px 14px 24px; }
  .card { padding: 18px; }
  .card-tight { padding: 14px; }
  .patient-name { font-size: 22px; }
  .stat-card { padding: 14px 16px; }
  .stat-value { font-size: 26px; }
  .info-grid { grid-template-columns: 1fr; }
}

/* When installed as a PWA, add safe-area padding for iPhone notch */
@supports (padding: env(safe-area-inset-top)) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ------------------------------------------------------------------------
   BRAND LOGO IN SIDEBAR
   ------------------------------------------------------------------------ */

.brand-logo {
  width: 38px;
  height: 38px;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
  padding: 3px;
  border: 1px solid var(--line);
}

/* ------------------------------------------------------------------------
   FILTER CHIPS (used on appointments calendar + reconciliation)
   ------------------------------------------------------------------------ */

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.chip {
  padding: 7px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  color: var(--ink);
  text-decoration: none;
  transition: all 0.15s;
  white-space: nowrap;
}

.chip:hover {
  background: var(--surface-2);
  border-color: var(--accent);
}

.chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ------------------------------------------------------------------------
   CALENDAR / APPOINTMENT VIEWS (day / week / month)
   ------------------------------------------------------------------------ */

.cal-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.cal-view-tabs {
  display: flex;
  gap: 8px;
}

.cal-nav {
  display: flex;
  gap: 6px;
}

/* Day view */
.day-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.day-slot {
  display: grid;
  grid-template-columns: 80px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
}

.day-slot:last-child { border-bottom: none; }
.day-slot:hover { background: var(--surface-2); }

.day-time {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 500;
  color: var(--accent);
}

.day-patient {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  font-size: 14px;
  margin-bottom: 2px;
}

.day-patient a { color: var(--ink); text-decoration: none; }
.day-patient a:hover { color: var(--accent); }

.day-meta {
  font-size: 12.5px;
  color: var(--ink-mute);
}

/* Week view — 7 column grid */
.cal-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
}

.cal-day {
  background: var(--surface);
  min-height: 200px;
  display: flex;
  flex-direction: column;
}

.cal-day.is-today {
  background: #f0f3ec;
}

.cal-day-head {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
}

.cal-dow {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-mute);
}

.cal-date {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 500;
}

.cal-day.is-today .cal-date {
  color: var(--accent);
  font-weight: 600;
}

.cal-day-body {
  flex: 1;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
}

.cal-evt {
  display: block;
  padding: 5px 8px;
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--ink);
  text-decoration: none;
  transition: background 0.12s;
}

.cal-evt:hover {
  background: #e2eae3;
}

.cal-evt-time {
  font-weight: 600;
  margin-right: 4px;
}

.cal-evt-patient {
  display: block;
  font-weight: 500;
}

.cal-evt-reason {
  display: block;
  color: var(--ink-mute);
  font-size: 10.5px;
}

.cal-evt-dental    { border-left-color: #b8945c; }
.cal-evt-pediatric { border-left-color: #5dabd6; }
.cal-evt-general   { border-left-color: var(--accent); }

.cal-empty {
  color: var(--ink-fade);
  font-size: 11px;
  text-align: center;
  padding-top: 16px;
}

/* Month view */
.cal-month {
  margin-bottom: 24px;
}

.cal-month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.cal-month-dow {
  background: var(--surface-2);
  padding: 10px 8px;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-mute);
}

.cal-month-cell {
  background: var(--surface);
  min-height: 110px;
  padding: 6px 7px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow: hidden;
}

.cal-month-cell.is-pad { background: var(--surface-2); opacity: 0.6; }
.cal-month-cell.is-today { background: #f0f3ec; }

.cal-month-date {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
}

.cal-month-cell.is-today .cal-month-date {
  color: var(--accent);
  font-weight: 600;
}

.cal-more {
  font-size: 11px;
  color: var(--ink-mute);
  text-decoration: none;
  padding: 2px 4px;
}

.cal-more:hover { color: var(--accent); }

/* ------------------------------------------------------------------------
   DENTAL TOOTH CHART
   ------------------------------------------------------------------------ */

.tooth-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 18px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 12.5px;
}

.leg {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.leg-sw {
  width: 14px;
  height: 14px;
  border: 1px solid #1a1d1a;
  border-radius: 3px;
}

.tooth-chart {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 18px;
}

.arch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.arch-upper { margin-bottom: 20px; }

.arch-label {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--ink-mute);
  text-transform: uppercase;
}

.teeth-row {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
  justify-content: center;
}

.tooth-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: transparent;
  border: none;
  padding: 4px 2px;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.12s, transform 0.12s;
}

.tooth-btn:hover {
  background: var(--surface-2);
  transform: translateY(-1px);
}

.tooth-btn.tooth-gap { margin-left: 14px; }

.tooth-btn svg {
  width: 30px;
  height: 42px;
  display: block;
}

.tooth-btn.tooth-lower { flex-direction: column-reverse; }

.tooth-num {
  font-size: 10px;
  font-family: var(--font-mono, monospace);
  color: var(--ink-mute);
  font-weight: 600;
}

@media (max-width: 768px) {
  .teeth-row { gap: 2px; }
  .tooth-btn svg { width: 22px; height: 32px; }
  .tooth-btn.tooth-gap { margin-left: 8px; }
  .tooth-num { font-size: 9px; }
  .tooth-chart { padding: 14px 8px; overflow-x: auto; }
}

/* ------------------------------------------------------------------------
   MODAL OVERLAY (used by tooth chart)
   ------------------------------------------------------------------------ */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 25, 20, 0.45);
  z-index: 250;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}

.modal-overlay.open { display: flex; }

.modal-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 520px;
  width: 100%;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.3);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line-soft);
}

.surface-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px 12px;
  margin-top: 6px;
}

.surface-grid label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
}

/* ------------------------------------------------------------------------
   DIVIDER + SECTION HELPERS
   ------------------------------------------------------------------------ */

.divider {
  height: 1px;
  background: var(--line-soft);
  margin: 20px 0;
}

.card-section { margin-bottom: 24px; }

.mb-0 { margin-bottom: 0 !important; }
.mt-3 { margin-top: 24px !important; }

/* ------------------------------------------------------------------------
   THEME PRESET PICKER (Settings → Appearance)
   ------------------------------------------------------------------------ */

.theme-presets {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  margin-top: 6px;
}

.theme-preset-card {
  cursor: pointer;
  display: block;
  position: relative;
}

.theme-preset-card input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.theme-preset-body {
  background: var(--p-surface);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  transition: border-color 0.15s, transform 0.12s;
}

.theme-preset-card:hover .theme-preset-body {
  transform: translateY(-1px);
}

.theme-preset-card input:checked + .theme-preset-body {
  border-color: var(--p-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--p-accent) 18%, transparent);
}

.theme-preset-swatches {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}

.theme-preset-swatches span {
  display: block;
  width: 22px;
  height: 22px;
  border-radius: 6px;
}

.theme-preset-label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink);
}

/* ------------------------------------------------------------------------
   PATIENT ATTACHMENTS GRID
   ------------------------------------------------------------------------ */

.scan-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px;
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.scan-btn {
  flex-shrink: 0;
}

.attachments-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.attachment-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.att-preview {
  aspect-ratio: 4 / 3;
  background: var(--surface-2);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.att-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.att-icon {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  color: var(--ink-mute);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.att-icon-glyph {
  font-size: 42px;
  line-height: 1;
}

.att-meta {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.att-title {
  font-weight: 500;
  font-size: 13.5px;
  line-height: 1.4;
  word-break: break-word;
}

.att-tags {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.att-notes {
  font-size: 12px;
  color: var(--ink-mute);
  line-height: 1.4;
  max-height: 3.6em;
  overflow: hidden;
}

.att-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
  font-size: 11px;
}

.att-actions {
  display: flex;
  gap: 4px;
}

/* Attachment type badges */
.badge.att-prescription { background: #d6e2dc; color: #1a3a30; }
.badge.att-lab_result   { background: #d8e1ee; color: #3b5d8f; }
.badge.att-xray         { background: #ebebed; color: #3a3f47; }
.badge.att-photo        { background: #f3d9d5; color: #a8392f; }
.badge.att-id           { background: #f4e5c8; color: #b07a2a; }
.badge.att-consent      { background: #e9efe5; color: #3e6b3a; }
.badge.att-document     { background: var(--surface-2); color: var(--ink-mute); }
.badge.att-other        { background: var(--surface-2); color: var(--ink-mute); }

/* Registration review — compact attachment thumbnails */
.reg-attachments {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.reg-att-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: transform 0.12s, border-color 0.15s;
}

.reg-att-card:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

.reg-att-preview {
  aspect-ratio: 4 / 3;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.reg-att-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reg-att-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
}
