/* Cliniqo application design system: clinic workspace (/app) and platform console (/admin).
   Breakpoints: mobile < 768px · tablet 768–1023px · desktop 1024–1439px · large ≥ 1440px.
   Components read the tokens below; colours are not assigned per component. */

/* ---------- Tokens ---------- */
:root {
  --primary: #0f6657;
  --primary-hover: #0b5145;
  --primary-soft: #e5f1ee;
  --primary-ring: #4f9d8e;
  --bg: #f6f8f7;
  --surface: #ffffff;
  --surface-2: #f1f5f3;
  --border: #dce4e0;
  --border-strong: #c3cfca;
  --text: #14302a;
  --muted: #566a64;
  --success: #1d7348;
  --success-bg: #e7f4ec;
  --warning: #8a5300;
  --warning-bg: #fdf3e1;
  --warning-border: #efd6a8;
  --error: #b42318;
  --error-bg: #fdeceb;
  --error-border: #f4cdc9;
  --info: #2c5aa0;
  --info-bg: #e8effa;

  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgb(16 40 34 / 6%);
  --shadow-lg: 0 16px 48px rgb(16 40 34 / 18%);
  --control-h: 40px;
  /* Navigation widths: expanded sidebar, icon rail, and the mobile drawer. */
  --sidebar-expanded: 256px;
  --sidebar-collapsed: 72px;
  --sidebar-drawer: min(304px, 86vw);
  --nav-speed: .2s;
  --topbar-h: 60px;
  --content-max: 1280px;
  --gutter: 32px;

  /* Earlier names, kept so every screen reads the same palette. */
  --ink: var(--text);
  --green: var(--primary);
  --line: var(--border);
  --danger: var(--error);

  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
@media (max-width: 767.98px), (pointer: coarse) {
  :root { --control-h: 44px; }
}
@media (max-width: 1023.98px) {
  :root { --gutter: 24px; }
}
@media (max-width: 767.98px) {
  :root { --gutter: 16px; --topbar-h: 56px; }
}
@media (min-width: 1440px) {
  :root { --gutter: 40px; }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font-size: 15px; line-height: 1.5; background: var(--bg); }
html.nav-locked { overflow: hidden; }
a { color: var(--primary); text-underline-offset: 2px; }
a:hover { color: var(--primary-hover); }
button, input, select, textarea { font: inherit; color: inherit; }
button, a, input, select, textarea, summary { touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
h1 { font-size: clamp(1.5rem, 1.25rem + 1vw, 1.875rem); line-height: 1.2; letter-spacing: -0.02em; font-weight: 650; margin: 6px 0 8px; }
h2 { font-size: 1.125rem; line-height: 1.3; letter-spacing: -0.01em; font-weight: 650; margin: 0 0 10px; }
h3 { font-size: 1rem; line-height: 1.35; font-weight: 650; margin: 0 0 8px; }
p { line-height: 1.6; margin: 8px 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 650; }
.eyebrow { text-transform: uppercase; font-size: 11px; letter-spacing: 0.08em; font-weight: 700; color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 16px; top: -60px; background: var(--surface); z-index: 100; padding: 12px; border-radius: var(--radius); }
.skip-link:focus { top: 12px; }

/* ---------- Button ---------- */
button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--control-h); padding: 0 16px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-size: 14px; font-weight: 600; line-height: 1.2; text-align: center;
  cursor: pointer; transition: background-color .15s, border-color .15s;
}
button:hover:not(:disabled) { background: var(--surface-2); }
button:disabled { cursor: not-allowed; opacity: .55; }
button .icon { flex-shrink: 0; }
.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.danger { color: var(--error); }
.danger:hover:not(:disabled) { background: var(--error-bg); border-color: var(--error-border); }
.danger-solid { background: var(--error); border-color: var(--error); color: #fff; }
.danger-solid:hover:not(:disabled) { background: #912018; }
.icon-button { width: var(--control-h); padding: 0; border-color: transparent; background: transparent; }
.icon-button:hover:not(:disabled) { background: var(--surface-2); }
.icon-button .icon { width: 20px; height: 20px; }
[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary-ring); color: var(--primary-hover); }
.button-link { display: inline-flex; align-items: center; justify-content: center; min-height: var(--control-h); padding: 0 16px; border-radius: var(--radius); font-weight: 600; text-decoration: none; }

/* ---------- Form controls ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; font-size: 13px; font-weight: 600; min-width: 0; }
.field input, .field select, .field textarea, .search-controls input {
  width: 100%; min-height: var(--control-h); padding: 8px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-size: 14px; font-weight: 400;
}
.field textarea { resize: vertical; min-height: 88px; line-height: 1.5; }
/* Safari ignores min-height on native select menus; drawing the arrow ourselves makes
   selects size like every other control. */
.field select { -webkit-appearance: none; appearance: none; height: var(--control-h); padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23566a64' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 18px; }
.field input:hover, .field select:hover, .field textarea:hover { border-color: #a9b8b2; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible, .search-controls input:focus-visible { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
.field input:disabled, .field select:disabled, .field textarea:disabled { background: var(--surface-2); color: #6f807a; }
.field input:user-invalid, .field select:user-invalid, .field textarea:user-invalid { border-color: var(--error); }
.field small { color: var(--muted); font-weight: 400; line-height: 1.5; }
/* iOS Safari zooms into inputs under 16px; phones get 16px text instead. */
@media (max-width: 767.98px), (pointer: coarse) {
  .field input, .field select, .field textarea, .search-controls input { font-size: 16px; }
}
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.span-two { grid-column: 1 / -1; }
.checks { border: 1px solid var(--border); border-radius: var(--radius); margin: 0 0 18px; padding: 10px 14px; max-height: 200px; overflow: auto; }
.checks legend { font-size: 13px; font-weight: 600; padding: 0 4px; }
.check { display: flex; gap: 10px; font-size: 14px; align-items: center; min-height: 36px; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); flex-shrink: 0; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* ---------- Alert / notice ---------- */
.notice, .error, .success { border: 1px solid; border-radius: var(--radius); padding: 12px 14px; font-size: 13.5px; line-height: 1.5; overflow-wrap: anywhere; }
.notice { background: var(--primary-soft); border-color: #cfe3dd; color: #22483f; margin: 0 0 20px; }
.notice-warn { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning); }
.error { background: var(--error-bg); border-color: var(--error-border); color: var(--error); margin: 12px 0; }
.error:empty { display: none; }
.success { background: var(--success-bg); border-color: #c9e6d3; color: var(--success); margin-bottom: 16px; }
.success:empty { display: none; }

/* ---------- Badge ---------- */
.badge { display: inline-flex; align-items: center; font-size: 12px; line-height: 1; border-radius: 999px; padding: 5px 9px; font-weight: 600; white-space: nowrap; background: var(--success-bg); color: var(--success); }
.badge.inactive, .badge.tone-muted { background: var(--surface-2); color: var(--muted); }
.badge.tone-good { background: var(--success-bg); color: var(--success); }
.badge.tone-info { background: var(--info-bg); color: var(--info); }
.badge.tone-warn { background: var(--warning-bg); color: var(--warning); }
.badge.tone-bad { background: var(--error-bg); color: var(--error); }

/* ---------- Brand ---------- */
.logo { display: inline-flex; align-items: center; gap: 10px; font-size: 19px; font-weight: 650; letter-spacing: -0.02em; color: var(--text); }
.logo-mark { width: 30px; height: 30px; flex-shrink: 0; }
.logo-mark-bg { fill: var(--primary); }
.logo-mark-fg { stroke: #fff; }
.brand { display: inline-flex; align-items: center; }
.brand-link { text-decoration: none; color: inherit; display: inline-flex; }
.brand-tag { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 2px 6px; }

/* ---------- Shell: sidebar, rail, drawer, header ---------- */
/* Grid column = the sidebar's footprint; the page always gets the rest (min-width 0). */
.shell { --nav-w: var(--sidebar-expanded); display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); min-height: 100dvh; transition: grid-template-columns var(--nav-speed) ease; }
.shell.nav-rail, .shell[data-nav=rail] { --nav-w: var(--sidebar-collapsed); }
.sidebar { grid-column: 1; grid-row: 1; position: sticky; top: 0; height: 100dvh; width: var(--nav-w); overflow-x: hidden; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 12px 16px; background: var(--surface); border-right: 1px solid var(--border); transition: width var(--nav-speed) ease; }
.workspace { grid-column: 2; grid-row: 1; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: var(--topbar-h); padding: 0 4px 0 8px; }
.brand { display: inline-flex; min-width: 0; color: inherit; text-decoration: none; border-radius: var(--radius-sm); }
.sidebar-toggle { flex-shrink: 0; color: var(--muted); background: transparent; border-color: transparent; }
.sidebar-toggle:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.drawer-close { display: none; }
.drawer-backdrop { display: none; }
.nav-group { display: grid; gap: 2px; margin-bottom: 16px; }
.nav-heading { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 0 4px 12px; white-space: nowrap; }
.nav-link { position: relative; display: flex; gap: 12px; align-items: center; min-height: 40px; padding: 8px 12px; border-radius: var(--radius-sm); color: var(--text); text-decoration: none; font-size: 14px; font-weight: 550; white-space: nowrap; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link .icon { flex-shrink: 0; color: var(--muted); }
.nav-label { overflow: hidden; text-overflow: ellipsis; }
/* Active page: a bar as well as colour, so it reads without colour too. */
.nav-link[aria-current=page] { background: var(--primary-soft); color: var(--primary-hover); font-weight: 650; }
.nav-link[aria-current=page]::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--primary); }
.nav-link[aria-current=page] .icon { color: var(--primary); }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding: 14px 4px 0; display: flex; align-items: center; gap: 10px; min-width: 0; }
.sidebar-user-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.sidebar-user-text > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Icon rail: icons only; names stay in the links for screen readers and show as tooltips. */
.nav-rail .sidebar { padding: 0 12px 16px; }
.nav-rail .sidebar-head { flex-direction: column; justify-content: center; gap: 4px; padding: 10px 0 6px; min-height: var(--topbar-h); }
.nav-rail .logo-word, .nav-rail .brand-tag, .nav-rail .nav-heading { display: none; }
.nav-rail .nav-group { margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.nav-rail .nav-group:last-child { border-bottom: 0; }
.nav-rail .nav-link { justify-content: center; padding: 8px 0; gap: 0; }
.nav-rail .nav-label, .nav-rail .sidebar-user-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.nav-rail .sidebar-foot { justify-content: center; padding: 14px 0 0; }
.nav-tooltip { position: fixed; z-index: 70; transform: translateY(-50%); pointer-events: none; padding: 5px 9px; border-radius: var(--radius-sm); background: var(--text); color: #fff; font-size: 12.5px; font-weight: 550; white-space: nowrap; box-shadow: var(--shadow-sm); }

.workspace { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; min-height: var(--topbar-h); padding: 0 var(--gutter); background: var(--surface); border-bottom: 1px solid var(--border); }
.menu-button { display: none; margin-left: -8px; }
.topbar-title { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 14px; }
.topbar-clinic { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 32ch; }
.topbar-clinic::after { content: "/"; margin-left: 8px; color: var(--border-strong); }
.topbar-page { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.identity { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 13px; }
.trial-note { font-size: 12px; color: var(--info); background: var(--info-bg); border-radius: 4px; padding: 4px 8px; white-space: nowrap; }
.profile { position: relative; }
.profile-button { gap: 8px; padding: 0 8px 0 4px; border-color: transparent; background: transparent; font-weight: 550; }
.profile-button .icon { width: 16px; height: 16px; color: var(--muted); }
.profile-button[aria-expanded=true] { background: var(--surface-2); }
.avatar { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-hover); font-size: 13px; font-weight: 700; flex-shrink: 0; }
.identity-text { white-space: nowrap; }
.profile-menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; width: max-content; min-width: 240px; max-width: min(320px, calc(100vw - 32px)); padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.profile-summary { display: flex; flex-direction: column; gap: 2px; padding: 10px 10px 12px; margin-bottom: 6px; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.menu-item { width: 100%; justify-content: flex-start; border-color: transparent; background: transparent; font-weight: 550; }
.app-banner { padding: 11px var(--gutter); font-size: 13.5px; line-height: 1.5; border-bottom: 1px solid var(--border); }
.app-banner.warn { background: var(--warning-bg); color: var(--warning); border-bottom-color: var(--warning-border); }
.app-banner a { font-weight: 650; color: inherit; }
.content { width: 100%; max-width: var(--content-max); margin: 0 auto; padding: 32px var(--gutter) 48px; }
.content:focus { outline: none; }

/* Tablet: the rail stays in place; "expand" lays the full sidebar over the page. */
@media (min-width: 768px) and (max-width: 1279.98px) {
  .nav-peek .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 50; width: var(--sidebar-expanded); box-shadow: var(--shadow-lg); }
  .drawer-backdrop { display: block; position: fixed; inset: 0; z-index: 40; background: rgb(12 32 28 / 30%); opacity: 0; visibility: hidden; transition: opacity var(--nav-speed), visibility 0s linear var(--nav-speed); }
  .nav-peek .drawer-backdrop { opacity: 1; visibility: visible; transition: opacity var(--nav-speed); }
}
/* Mobile: no permanent sidebar; an off-canvas drawer opened from the header. */
@media (max-width: 767.98px) {
  .shell { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 50; width: var(--sidebar-drawer); height: 100dvh; transform: translateX(-100%); visibility: hidden; transition: transform var(--nav-speed) ease, visibility 0s linear var(--nav-speed); border-right: 0; }
  .nav-open .sidebar { transform: none; visibility: visible; transition: transform var(--nav-speed) ease; box-shadow: var(--shadow-lg); }
  .drawer-backdrop { display: block; position: fixed; inset: 0; z-index: 40; background: rgb(12 32 28 / 45%); opacity: 0; visibility: hidden; transition: opacity var(--nav-speed), visibility 0s linear var(--nav-speed); }
  .nav-open .drawer-backdrop { opacity: 1; visibility: visible; transition: opacity var(--nav-speed); }
  .drawer-close, .menu-button { display: inline-flex; }
  .sidebar-toggle { display: none; }
  .topbar { gap: 8px; }
  .topbar-clinic, .identity-text, .trial-note, .profile-button > .icon { display: none; }
  .content { padding-top: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  .shell, .sidebar, .drawer-backdrop, .nav-open .sidebar, .nav-open .drawer-backdrop, .nav-peek .drawer-backdrop { transition: none; }
}

/* ---------- Page header ---------- */
.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px 24px; flex-wrap: wrap; margin-bottom: 24px; }
.page-header > div:first-child { min-width: 0; flex: 1 1 320px; }
.page-header h1 { margin-bottom: 4px; }
.page-header p { margin: 0; color: var(--muted); font-size: 14px; max-width: 70ch; }
.back-link { display: inline-flex; align-items: center; min-height: 32px; margin-bottom: 8px; font-size: 13.5px; color: var(--muted); text-decoration: none; }
.back-link:hover { color: var(--text); }
@media (max-width: 767.98px) {
  .page-header { align-items: stretch; }
  .page-header > button { width: 100%; }
}

/* ---------- Card / panel ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.panel-heading h2 { font-size: 15px; margin: 0; }
.panel-body { padding: 20px; }
.panel-note { padding: 0 20px; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 16px 20px; border-top: 1px solid var(--border); }
section.panel + section.panel, .detail-columns + section.panel { margin-top: 20px; }
.profile-card { padding: 24px; }
.profile-card + .profile-card { margin-top: 20px; }
.patient-overview .profile-card, .consultation-layout .profile-card + .profile-card { margin-top: 0; }
@media (max-width: 767.98px) {
  .profile-card { padding: 18px 16px; }
  .panel-heading, .panel-body, .panel-actions { padding-left: 16px; padding-right: 16px; }
  .panel-note { padding: 0 16px; }
}

/* ---------- Table ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 14px; }
th { font-size: 12px; font-weight: 600; letter-spacing: .02em; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
th, td { padding: 14px 20px; border-bottom: 1px solid var(--border); vertical-align: top; }
td { line-height: 1.45; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafcfb; }
td p { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); }
td .wrap { min-width: 130px; max-width: 260px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.row-actions button, .row-actions .consultation-link { min-height: 34px; padding: 0 12px; font-size: 13px; }
@media (max-width: 767.98px) { .row-actions button, .row-actions .consultation-link { min-height: var(--control-h); } }
/* Stacked tables: each row becomes a labelled card (stackTable() in ui.js). */
@media (max-width: 767.98px) {
  .table-stack.stack-md thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .table-stack.stack-md, .table-stack.stack-md tbody, .table-stack.stack-md tr { display: block; }
  .table-stack.stack-md tr { padding: 14px 16px; border-bottom: 1px solid var(--border); }
  .table-stack.stack-md tbody tr:last-child { border-bottom: 0; }
  .table-stack.stack-md td { display: grid; grid-template-columns: minmax(88px, 36%) minmax(0, 1fr); gap: 12px; padding: 4px 0; border: 0; overflow-wrap: anywhere; background: none; }
  .table-stack.stack-md td::before { content: attr(data-label); color: var(--muted); font-size: 13px; }
  .table-stack.stack-md td > * { grid-column: 2; justify-self: start; }
  .table-stack.stack-md td > p { margin-top: 0; }
  .table-stack.stack-md td:first-child { display: block; padding-bottom: 8px; font-size: 15px; }
  .table-stack.stack-md td:first-child::before, .table-stack.stack-md td.cell-actions::before { content: none; }
  .table-stack.stack-md td.cell-actions { display: block; padding-top: 10px; }
  .table-stack.stack-md .row-actions > * { flex: 1 1 auto; min-height: var(--control-h); }
}
@media (max-width: 1023.98px) {
  .table-stack.stack-lg thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .table-stack.stack-lg, .table-stack.stack-lg tbody, .table-stack.stack-lg tr { display: block; }
  .table-stack.stack-lg tr { padding: 14px 16px; border-bottom: 1px solid var(--border); }
  .table-stack.stack-lg tbody tr:last-child { border-bottom: 0; }
  .table-stack.stack-lg td { display: grid; grid-template-columns: minmax(88px, 30%) minmax(0, 1fr); gap: 12px; padding: 4px 0; border: 0; overflow-wrap: anywhere; background: none; }
  .table-stack.stack-lg td::before { content: attr(data-label); color: var(--muted); font-size: 13px; }
  .table-stack.stack-lg td > * { grid-column: 2; justify-self: start; }
  .table-stack.stack-lg td > p { margin-top: 0; }
  .table-stack.stack-lg td:first-child { display: block; padding-bottom: 8px; font-size: 15px; }
  .table-stack.stack-lg td:first-child::before, .table-stack.stack-lg td.cell-actions::before { content: none; }
  .table-stack.stack-lg td.cell-actions { display: block; padding-top: 10px; }
}
.pagination { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 2px 0; color: var(--muted); font-size: 13px; }
.panel > .pagination, .profile-card > .pagination { padding: 12px 20px; border-top: 1px solid var(--border); }
.profile-card > .pagination { padding: 12px 0 0; }
.pagination button { min-height: 34px; font-size: 13px; }
.pagination div { display: flex; gap: 8px; }
@media (max-width: 767.98px) {
  .panel > .pagination { padding: 12px 16px; }
  .pagination button { min-height: var(--control-h); }
}

/* ---------- Empty, loading, skeleton ---------- */
.empty { text-align: center; padding: 48px 24px; }
.empty h2 { font-size: 16px; margin-bottom: 6px; }
.empty p { color: var(--muted); font-size: 14px; max-width: 48ch; margin: 0 auto 18px; }
.empty-icon { display: grid; place-items: center; width: 44px; height: 44px; margin: 0 auto 14px; border-radius: var(--radius-lg); background: var(--primary-soft); color: var(--primary); }
.empty-icon .icon { width: 22px; height: 22px; }
.panel .empty { padding: 36px 20px; }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 48px 24px; text-align: center; color: var(--muted); }
.loading::before { content: ""; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--primary); animation: spin .8s linear infinite; }
.skeleton-block { padding: 4px 0; }
.skeleton { border-radius: var(--radius); background: linear-gradient(90deg, var(--surface-2) 25%, #e6ecea 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }
.skeleton-title { height: 30px; width: min(320px, 60%); margin-bottom: 24px; }
.skeleton-row { height: 52px; margin-bottom: 10px; }
@keyframes shimmer { from { background-position: 100% 50%; } to { background-position: 0 50%; } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .skeleton, .loading::before { animation: none; } }

/* ---------- Modal / bottom sheet ---------- */
dialog { padding: 0; border: 0; border-radius: var(--radius-lg); width: min(640px, calc(100% - 32px)); max-width: none; max-height: min(88dvh, 920px); color: var(--text); background: var(--surface); box-shadow: var(--shadow-lg); overflow: hidden; }
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgb(12 32 28 / 45%); }
.dialog-header { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px 16px 24px; border-bottom: 1px solid var(--border); }
.dialog-header h2 { margin: 0; font-size: 17px; }
dialog > :not(.dialog-header) { overflow-y: auto; min-height: 0; overscroll-behavior: contain; }
.dialog-body { padding: 20px 24px 24px; }
/* Save and cancel stay reachable while long forms scroll. */
.dialog-body .form-actions { position: sticky; bottom: 0; margin: 20px -24px -24px; padding: 12px 24px; background: var(--surface); border-top: 1px solid var(--border); z-index: 1; }
.patient-dialog, .wide-dialog { width: min(800px, calc(100% - 32px)); }
@media (max-width: 767.98px) {
  dialog, .patient-dialog, .wide-dialog { width: 100%; max-height: 94dvh; margin: auto 0 0; border-radius: 16px 16px 0 0; }
  .dialog-header { padding: 12px 12px 12px 16px; }
  .dialog-body { padding: 16px 16px 20px; }
  .dialog-body .form-actions { margin: 16px -16px -20px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .dialog-body .form-actions > * { flex: 1 1 0; }
}

/* ---------- Tabs / segmented ---------- */
.profile-tabs { display: flex; gap: 4px; overflow-x: auto; margin-bottom: 24px; border-bottom: 1px solid var(--border); scrollbar-width: thin; }
.profile-tabs a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; white-space: nowrap; font-size: 14px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.profile-tabs a:hover { color: var(--text); }
.profile-tabs a[aria-current=page] { color: var(--primary); border-bottom-color: var(--primary); font-weight: 650; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); padding: 3px; background: var(--surface); }
.segmented button { min-height: 32px; border: 0; background: transparent; padding: 0 14px; font-size: 13px; color: var(--muted); border-radius: var(--radius-sm); }
.segmented button[aria-pressed="true"] { background: var(--text); color: #fff; }
@media (max-width: 767.98px), (pointer: coarse) { .segmented button { min-height: var(--control-h); } }

/* ---------- Sign-in ---------- */
.login-shell { display: grid; grid-template-columns: minmax(360px, 5fr) 7fr; min-height: 100dvh; }
.login-story { display: flex; flex-direction: column; justify-content: space-between; gap: 32px; padding: 40px 48px; background: #0f3d35; color: #d5e6e1; }
.login-story .logo { color: #fff; }
.login-story .logo-mark-bg { fill: #5ec4ad; }
.login-story .logo-mark-fg { stroke: #0b2e27; }
.login-story a { color: #d5e6e1; }
.login-story a:hover { color: #fff; }
.login-story :focus-visible { outline-color: #fff; }
.login-story-title { font-size: clamp(1.75rem, 1.2rem + 1.4vw, 2.25rem); line-height: 1.2; letter-spacing: -0.02em; font-weight: 600; color: #fff; max-width: 16ch; margin: 0 0 24px; }
.login-points { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; max-width: 36ch; }
.login-points li { position: relative; padding-left: 26px; line-height: 1.5; }
.login-points li::before { content: ""; position: absolute; left: 2px; top: 6px; width: 10px; height: 5px; border-left: 2px solid #5ec4ad; border-bottom: 2px solid #5ec4ad; transform: rotate(-45deg); }
.login-form-wrap { display: grid; place-items: center; padding: 40px 24px; background: var(--surface); }
.login-card { width: 100%; max-width: 400px; }
.login-card h1 { font-size: 26px; margin-top: 0; }
.login-card > p { color: var(--muted); font-size: 14px; margin-bottom: 24px; }
.login-card button[type=submit], .login-card > button { width: 100%; margin-top: 4px; }
.login-logo { display: none; margin-bottom: 28px; }
.auth-switch { margin-top: 20px; color: var(--muted); }
.id-callout { display: flex; flex-direction: column; gap: 6px; border: 1px solid var(--border); background: var(--surface-2); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 18px; }
.id-callout code { font-size: 15px; overflow-wrap: anywhere; user-select: all; }
@media (max-width: 1023.98px) {
  .login-shell { display: block; }
  .login-story { display: none; }
  .login-logo { display: inline-flex; }
  .login-form-wrap { min-height: 100dvh; place-items: start center; padding: 40px 24px; background: var(--bg); }
  .login-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 32px; margin-top: 4vh; }
}
@media (max-width: 767.98px) {
  .login-form-wrap { padding: 24px 16px; background: var(--surface); }
  .login-card { border: 0; padding: 0; margin-top: 0; background: transparent; }
  .login-logo { margin-bottom: 24px; }
}
.console-login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: var(--bg); }
.console-login .login-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 32px; }
.console-login .brand { margin-bottom: 24px; gap: 10px; }
@media (max-width: 767.98px) { .console-login .login-card { padding: 24px 20px; } }

/* ---------- Settings ---------- */
.settings-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(240px, 1fr); gap: 24px; align-items: start; }
.settings-form { padding: 24px; }
.aside-note { padding: 20px 24px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.aside-note h2 { font-size: 15px; }
.aside-note p { font-size: 13.5px; color: var(--muted); margin-bottom: 0; }
@media (max-width: 1023.98px) { .settings-layout { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 767.98px) {
  .settings-form { padding: 18px 16px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- Patients ---------- */
.patient-search { padding: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); margin-bottom: 20px; }
.patient-search label { display: block; font-size: 13px; font-weight: 650; margin-bottom: 8px; }
.search-controls { display: flex; gap: 10px; }
.search-controls input { flex: 1; min-width: 0; }
.profile-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.patient-overview { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 20px; align-items: start; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 24px; }
.patient-detail { margin: 0 0 18px; overflow-wrap: anywhere; }
.patient-detail dt { font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.patient-detail dd { font-size: 14px; line-height: 1.5; margin: 0; text-transform: none; }
.patient-timeline { margin: 20px 0 0; padding-left: 20px; }
.patient-timeline li { padding: 0 0 14px 8px; font-size: 14px; }
.registration-details { border: 1px solid var(--border); border-radius: var(--radius); padding: 0 14px; margin-bottom: 16px; }
.registration-details summary { min-height: 44px; display: flex; align-items: center; font-size: 13.5px; font-weight: 650; cursor: pointer; }
.registration-details[open] summary { margin-bottom: 12px; }
.duplicate-matches:not(:empty) { border: 1px solid var(--warning-border); background: var(--warning-bg); padding: 16px; border-radius: var(--radius); margin-bottom: 20px; }
.duplicate-matches h3 { font-size: 15px; margin: 0 0 8px; }
.duplicate-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid #ecd9b4; padding: 12px 0; font-size: 13.5px; }
.duplicate-row p { margin: 4px 0 0; }
.duplicate-row button { flex-shrink: 0; }
@media (max-width: 1023.98px) { .patient-overview { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 767.98px) {
  .patient-search { padding: 16px; }
  .search-controls { flex-direction: column; }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .duplicate-row { align-items: stretch; flex-direction: column; }
  .profile-actions { width: 100%; }
  .profile-actions > * { flex: 1 1 auto; }
}

/* ---------- Scheduling ---------- */
.schedule-toolbar { display: flex; align-items: flex-end; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 16px; }
.schedule-toolbar > .field { flex: 1 1 180px; margin: 0; min-width: 0; }
.schedule-toolbar > button { flex: none; }
main > .row-actions { margin-bottom: 12px; }
main > .row-actions button { min-height: var(--control-h); font-size: 14px; }
.appointment-calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.calendar-day { min-width: 0; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.calendar-day h2 { font-size: 13.5px; margin: 0 0 10px; }
.calendar-day > p { margin: 0; }
.calendar-booking { border-top: 2px solid var(--primary); padding: 10px 0; overflow-wrap: anywhere; }
.calendar-booking p { margin: 4px 0; }
.calendar-booking button { margin-top: 8px; min-height: 32px; font-size: 13px; }
.booking-matches { display: grid; gap: 6px; margin-bottom: 12px; }
.patient-match { justify-content: flex-start; text-align: left; white-space: normal; font-weight: 500; }
.queue-token { font-size: 22px; font-variant-numeric: tabular-nums; }
.appointment-status { white-space: nowrap; }
.status-booked, .status-confirmed { background: var(--info-bg); color: var(--info); }
.status-cancelled, .status-no_show, .status-rescheduled { background: var(--surface-2); color: var(--muted); }
.status-waiting, .status-arrived { background: var(--warning-bg); color: var(--warning); }
.status-in_consultation { background: #ecebfb; color: #4a3f9a; }
.status-completed { background: var(--success-bg); color: var(--success); }
.working-period { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 0 0 16px; min-width: 0; }
.working-period legend { font-weight: 600; padding: 0 6px; }
.schedule-breaks { padding-left: 16px; border-left: 2px solid var(--border); margin-bottom: 12px; }
.schedule-exceptions { padding: 0; list-style: none; }
.schedule-exceptions li { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 10px 0; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; font-size: 14px; }
.slot-status:not(:empty) { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: -4px 0 16px; }
.slot-status .notice, .slot-status .error { margin: 0; flex: 1 1 260px; }
.slot-status p { margin: 0; }
@media (max-width: 1279.98px) { .appointment-calendar { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 767.98px) {
  .appointment-calendar { grid-template-columns: minmax(0, 1fr); }
  .schedule-toolbar > .field { flex-basis: 100%; }
  .schedule-toolbar > button { flex: 1 1 auto; }
  main > .row-actions > * { flex: 1 1 calc(50% - 6px); }
  .schedule-breaks { padding-left: 10px; }
  .calendar-booking button { min-height: var(--control-h); }
}

/* ---------- Consultations and AI summaries ---------- */
.consultation-counts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.consultation-count { display: flex; flex-direction: column; gap: 2px; padding: 16px 20px; }
.consultation-count strong { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.consultation-count span { color: var(--muted); font-size: 13.5px; }
.consultation-link { display: inline-flex; align-items: center; border: 1px solid var(--border-strong); border-radius: var(--radius); text-decoration: none; color: var(--primary); font-weight: 600; }
.consultation-link:hover { background: var(--primary-soft); }
.consultation-layout { display: grid; grid-template-columns: minmax(280px, 0.8fr) minmax(0, 1.7fr); gap: 20px; align-items: start; }
.consultation-context, .clinical-workspace { min-width: 0; }
.consultation-context .profile-card { margin-bottom: 20px; }
.clinical-alert { border-left: 3px solid #b47736; background: var(--warning-bg); padding: 2px 14px; margin-top: 20px; border-radius: 4px; }
.clinical-text { white-space: pre-wrap; overflow-wrap: anywhere; margin: 4px 0 14px; }
.visit-card { padding: 16px 0; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.visit-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.visit-heading h3 { margin: 0; font-size: 15px; }
.visit-card summary, .diagnosis-row summary { cursor: pointer; font-size: 14px; min-height: 40px; display: flex; align-items: center; }
.clinical-detail { margin-top: 12px; }
.previous-visits { max-height: 75vh; overflow-y: auto; }
.clinical-group { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 20px 0; min-width: 0; }
.clinical-group legend { font-weight: 600; padding: 0 6px; }
.clinical-form textarea { width: 100%; min-height: 110px; resize: vertical; }
.consultation-save { position: sticky; top: var(--topbar-h); z-index: 2; background: var(--surface); padding: 12px 0; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.consultation-save p { margin: 0 0 10px; }
.diagnosis-row { border-bottom: 1px solid var(--border); padding: 12px 0; margin-bottom: 14px; }
.ai-summary-card { border-top: 1px solid var(--border); padding: 16px 0; margin-top: 16px; overflow-wrap: anywhere; }
.ai-summary-card h3 { font-size: 15px; }
.ai-summary-card h4 { margin-bottom: 4px; }
.ai-summary-card details { margin: 12px 0; }
.ai-summary-card summary { cursor: pointer; }
@media (max-width: 1023.98px) {
  .consultation-layout { grid-template-columns: minmax(0, 1fr); }
  .previous-visits { max-height: 420px; }
}
@media (max-width: 767.98px) {
  .consultation-counts { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .consultation-count { padding: 12px; }
  .consultation-count strong { font-size: 22px; }
  .consultation-count span { font-size: 12.5px; line-height: 1.35; }
  .consultation-save .row-actions > * { flex: 1 1 auto; min-height: var(--control-h); }
}

/* ---------- Subscription ---------- */
.subscription-grid, .detail-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin-bottom: 24px; align-items: start; }
.detail-columns .panel { margin: 0; }
.summary-list { margin: 0; padding: 6px 20px; }
.summary-list > div { display: grid; grid-template-columns: minmax(120px, 40%) minmax(0, 1fr); gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.summary-list > div:last-child { border-bottom: 0; }
.summary-list dt { color: var(--muted); }
.summary-list dd { margin: 0; overflow-wrap: anywhere; }
.summary-list.compact { padding: 0; }
.usage-meter { display: block; width: 100%; max-width: 220px; height: 6px; margin-top: 8px; appearance: none; border: 0; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.usage-meter::-webkit-progress-bar { background: var(--surface-2); }
.usage-meter::-webkit-progress-value { background: var(--primary); }
.usage-meter::-moz-progress-bar { background: var(--primary); }
.usage-meter.full::-webkit-progress-value { background: #b47736; }
.usage-meter.full::-moz-progress-bar { background: #b47736; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 16px; }
.section-heading h2 { margin: 0; }
.plans-section { margin-bottom: 24px; }
.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.plan-card { display: flex; flex-direction: column; padding: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.plan-card.current { border-color: var(--primary-ring); box-shadow: inset 0 0 0 1px var(--primary-ring); }
.plan-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.plan-card-head h3 { margin: 0; font-size: 17px; }
.plan-price { font-size: 24px; font-weight: 700; margin: 10px 0 12px; letter-spacing: -0.02em; }
.plan-price span { font-size: 13px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.plan-list { list-style: none; padding: 0; margin: 0 0 12px; font-size: 13.5px; }
.plan-list li { padding: 6px 0; border-top: 1px solid var(--border); }
.plan-list.features li { color: var(--muted); }
.plan-card-action { margin-top: auto; padding-top: 8px; }
.plan-card-action button { width: 100%; }
.plan-card-action p { margin: 8px 0 0; }
@media (max-width: 1023.98px) { .subscription-grid, .detail-columns { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 767.98px) {
  .summary-list { padding: 4px 16px; }
  .summary-list > div { grid-template-columns: minmax(0, 1fr); gap: 2px; }
}

/* ---------- Platform console ---------- */
.console .sidebar { background: #13302a; color: #cfdfda; border-right-color: #13302a; }
.console .logo { color: #fff; }
.console .logo-mark-bg { fill: #5ec4ad; }
.console .logo-mark-fg { stroke: #0b2e27; }
.console .brand-tag { color: #b3c7c0; border-color: #36514a; }
.console .nav-link { color: #cfdfda; }
.console .nav-link .icon { color: #93aaa2; }
.console .nav-link:hover { background: #1d3f38; color: #fff; }
.console .nav-link[aria-current=page] { background: #2a5249; color: #fff; }
.console .nav-link[aria-current=page] .icon { color: #fff; }
.console .sidebar :focus-visible { outline-color: #fff; }
.console .drawer-close { color: #fff; }
.console .drawer-close:hover:not(:disabled) { background: #1d3f38; }
.console .sidebar-foot { border-top-color: #2a5249; }
.console .sidebar-foot .muted { color: #93aaa2; }
.console .sidebar-toggle { color: #cfdfda; }
.console .sidebar-toggle:hover:not(:disabled) { background: #1d3f38; color: #fff; }
.console .nav-link[aria-current=page]::before { background: #5ec4ad; }
.console .nav-rail .nav-group { border-bottom-color: #2a5249; }
.stat-panel { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 24px; }
.stat-group { padding: 20px 24px; border-bottom: 1px solid var(--border); min-width: 0; }
.stat-group:nth-child(odd) { border-right: 1px solid var(--border); }
.stat-group:last-child { grid-column: 1 / -1; border-right: 0; border-bottom: 0; }
.stat-group h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 14px; }
.stat-row { display: flex; flex-wrap: wrap; gap: 12px 32px; margin: 0; }
.stat dt { font-size: 12.5px; color: var(--muted); }
.stat dd { margin: 2px 0 0; font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; }
.filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 16px; }
.filter-bar .field { margin: 0; flex: 1 1 180px; max-width: 280px; }
.limits-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 16px; max-height: none; }
.limits-grid legend { grid-column: 1 / -1; }
@media (max-width: 1023.98px) {
  .stat-panel { grid-template-columns: minmax(0, 1fr); }
  .stat-group:nth-child(odd) { border-right: 0; }
}
@media (max-width: 767.98px) {
  .stat-group { padding: 16px; }
  .stat-row { gap: 12px 24px; }
  .stat dd { font-size: 20px; }
  .filter-bar .field { max-width: none; flex-basis: 100%; }
  .filter-bar > button { flex: 1 1 auto; }
}

/* ---------- Prescriptions ---------- */
.prescription-panel { margin-top: 20px; }
.rx-heading { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.rx-heading h2 { margin: 0; }
.rx-status { margin: 0 0 12px; }
.rx-list { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 12px; }
.rx-item { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; background: var(--surface); min-width: 0; }
.rx-item-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; }
.rx-item-head h3 { margin: 0; font-size: 15px; overflow-wrap: anywhere; }
.rx-index { color: var(--muted); font-variant-numeric: tabular-nums; }
.rx-generic { margin: 2px 0 0; }
.rx-facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 16px; margin: 12px 0; }
.rx-facts dt { font-size: 12.5px; color: var(--muted); }
.rx-facts dd { margin: 2px 0 0; font-size: 14px; font-weight: 550; }
.rx-timing { width: auto; min-width: 0; font-size: 13.5px; border: 1px solid var(--border); border-radius: var(--radius-sm); border-collapse: separate; border-spacing: 0; overflow: hidden; }
.rx-timing th, .rx-timing td { padding: 6px 14px; border-bottom: 0; text-align: center; vertical-align: middle; white-space: nowrap; }
.rx-timing thead th { background: var(--surface-2); font-weight: 600; }
.rx-timing tbody th { text-align: left; font-weight: 600; color: var(--text); background: var(--surface); }
.rx-timing tbody td { font-weight: 700; color: var(--primary); }
.rx-timing tbody tr:hover td { background: none; }
.rx-instructions { margin: 10px 0 0; font-size: 14px; color: var(--text); background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 10px; }
.rx-empty { border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.rx-empty .empty { padding: 24px 16px; }
.rx-extra { margin-top: 20px; }
.rx-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.rx-actions:empty { display: none; }
.rx-earlier { margin-top: 16px; font-size: 14px; }
.rx-earlier summary { cursor: pointer; min-height: 40px; display: flex; align-items: center; color: var(--muted); }
.rx-earlier ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.rx-earlier li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rx-earlier button { min-height: 32px; font-size: 13px; }
/* Medicine dialog */
.rx-group { margin: 0 0 16px; }
.rx-label { margin: 4px 0 8px; font-size: 13px; font-weight: 600; }
.rx-choice { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.rx-choice button { flex: 1 1 110px; font-weight: 550; }
.rx-choice button.selected, .rx-choice button[aria-checked="true"] { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-hover); box-shadow: inset 0 0 0 1px var(--primary); }
.rx-dose { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 8px; }
.rx-dose input, .rx-dose select { width: 100%; min-height: var(--control-h); padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); font-size: 14px; font-weight: 400; }
.rx-dose select { -webkit-appearance: none; appearance: none; padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23566a64' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 18px; }
.rx-quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: -6px; }
.rx-quick button { min-height: 32px; padding: 0 10px; font-size: 12.5px; font-weight: 500; border-radius: 999px; }
/* Medicine picker: results stay in the dialog's flow so they are full width on phones. */
.med-search { margin-bottom: 0; }
.med-options { list-style: none; margin: 6px 0 0; padding: 4px; max-height: min(320px, 45vh); overflow-y: auto; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
.med-option { display: flex; flex-direction: column; gap: 2px; min-height: 44px; justify-content: center; padding: 8px 12px; border-radius: var(--radius-sm); cursor: pointer; }
.med-option:hover, .med-option[aria-selected="true"] { background: var(--primary-soft); }
.med-option[aria-selected="true"] { box-shadow: inset 3px 0 0 var(--primary); }
.med-option-name { font-weight: 600; overflow-wrap: anywhere; }
.med-option-detail { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.med-group { padding: 8px 12px 4px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.med-empty { margin-top: 6px; padding: 14px 16px; border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2); }
.med-empty p { margin: 0 0 6px; }
.med-empty p:last-child { margin-bottom: 0; }
.med-empty-title { font-weight: 600; }
.med-hint { display: block; margin-top: 6px; }
.med-chosen { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border: 1px solid var(--primary); border-radius: var(--radius); background: var(--primary-soft); }
.med-chosen[hidden] { display: none; }
.med-chosen-text { min-width: 0; }
.med-chosen-text .rx-label { display: block; margin: 0 0 2px; color: var(--muted); font-size: 12px; }
.med-chosen-text p { margin: 0; overflow-wrap: anywhere; }
.med-chosen-name { font-size: 15px; font-weight: 650; }
.med-chosen button { flex: none; }
/* Medicine master */
.medicine-toolbar > .field:first-child { flex: 3 1 260px; }
.medicine-table .row-muted td { color: var(--muted); }
.medicine-preview { margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.medicine-preview:empty { display: none; }
.medicine-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 20px; margin: 0 0 16px; }
.medicine-facts dt { font-size: 12.5px; color: var(--muted); }
.medicine-facts dd { margin: 2px 0 0; overflow-wrap: anywhere; }
.header-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.import-counts { list-style: none; display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 4px 0 12px; padding: 0; }
.import-columns { overflow-wrap: anywhere; }
.import-result .table-scroll { max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; }
.import-result:empty { display: none; }
.load-more { margin: 16px auto 0; display: flex; }
.rx-preview:not(:empty) { margin-top: 4px; }
.rx-preview p { margin: 0 0 6px; }
.rx-view-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
/* Prescription history on the patient profile */
.rx-history { list-style: none; margin: 0; padding: 0; }
.rx-history li { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px 20px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.rx-history li:last-child { border-bottom: 0; }
.rx-history-main { min-width: 0; }
.rx-history-main p { margin: 0 0 4px; overflow-wrap: anywhere; }
.rx-history-title { font-size: 15px; }
.rx-history-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; flex-shrink: 0; }
/* Symptom chips */
.chip-input-list { list-style: none; padding: 0; margin: 4px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chip-input-list:empty { display: none; }
.chip-input-list li { display: inline-flex; align-items: center; gap: 2px; padding-left: 12px; border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface-2); font-size: 13.5px; font-weight: 500; }
.chip-remove { min-height: 30px; width: 30px; padding: 0; border: 0; border-radius: 999px; background: transparent; font-size: 16px; line-height: 1; color: var(--muted); }
.private-notes { background: var(--surface-2); }
@media (max-width: 767.98px) {
  .rx-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rx-item { padding: 12px; }
  .rx-item-head .row-actions { width: 100%; }
  .rx-item-head .row-actions > * { flex: 1 1 auto; }
  .rx-timing { width: 100%; }
  .rx-timing th, .rx-timing td { padding: 6px 8px; }
  .rx-actions > * { flex: 1 1 100%; }
  .rx-quick button { min-height: var(--control-h); }
  .rx-history li { flex-direction: column; padding: 14px 16px; }
  .rx-history-side { flex-direction: row; align-items: center; justify-content: space-between; width: 100%; }
  .chip-remove { min-height: 44px; width: 44px; }
  .rx-earlier button { min-height: var(--control-h); }
}

/* ---------- Doctor dashboard and doctor details ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { display: flex; flex-direction: column; gap: 2px; padding: 16px 20px; }
.kpi strong { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi span { color: var(--muted); font-size: 13.5px; }
.kpi small { font-size: 12.5px; color: var(--warning); }
.doctor-home { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(280px, 1fr); gap: 20px; align-items: start; }
.doctor-home-main, .doctor-home-side { display: grid; gap: 20px; min-width: 0; }
.doctor-home .profile-card + .profile-card { margin-top: 0; }
.day-list h2 { margin-bottom: 12px; }
.agenda { list-style: none; margin: 0; padding: 0; }
.agenda-item { display: grid; grid-template-columns: minmax(130px, auto) minmax(0, 1fr) auto auto; align-items: center; gap: 8px 14px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.agenda-item:last-child { border-bottom: 0; }
.agenda-time { font-weight: 600; font-variant-numeric: tabular-nums; font-size: 14px; }
.agenda-main { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.agenda-item .consultation-link { min-height: 34px; padding: 0 14px; }
.doctor-facts { display: grid; gap: 10px; margin: 0 0 8px; }
.doctor-facts > div { display: grid; grid-template-columns: minmax(110px, 40%) minmax(0, 1fr); gap: 8px; font-size: 14px; }
.doctor-facts dt { color: var(--muted); }
.doctor-facts dd { margin: 0; overflow-wrap: anywhere; }
.doctor-subheading { font-size: 14px; margin: 16px 0 8px; }
.availability h3 { font-size: 13px; color: var(--muted); margin: 8px 0 4px; }
.availability-table { width: 100%; font-size: 13.5px; }
.availability-table th, .availability-table td { padding: 5px 0; border-bottom: 1px solid var(--border); background: none; color: var(--text); font-weight: 500; }
.availability-table th { width: 56px; font-weight: 600; letter-spacing: 0; }
.availability-table tr:last-child th, .availability-table tr:last-child td { border-bottom: 0; }
.availability-table tbody tr:hover td { background: none; }
.mini-list { list-style: none; margin: 0 0 8px; padding: 0; }
.mini-list li { display: flex; flex-direction: column; gap: 2px; padding: 10px 0; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.mini-list li:last-child { border-bottom: 0; }
.link-button { align-self: flex-start; min-height: 28px; padding: 0; border: 0; background: none; color: var(--primary); text-decoration: underline; text-underline-offset: 2px; font-weight: 600; }
.link-button:hover:not(:disabled) { background: none; color: var(--primary-hover); }
.doctor-login .check { font-weight: 600; }
.doctor-login > div { margin-top: 12px; }
/* Two columns need room for the appointments table beside the profile; below 1280px they stack
   (narrower windows let the table spill under the profile card). */
@media (max-width: 1279.98px) {
  .doctor-home { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 767.98px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 12px 14px; }
  .kpi strong { font-size: 24px; }
  .agenda-item { grid-template-columns: minmax(0, 1fr) auto; }
  .agenda-time { grid-column: 1 / -1; }
  .agenda-item .consultation-link { grid-column: 1 / -1; justify-content: center; min-height: var(--control-h); }
  .link-button { min-height: var(--control-h); }
}
/* A doctor's own list: the Doctor / Branch column only repeats their name. */
.doctor-home-main .day-list th:nth-child(3), .doctor-home-main .day-list td:nth-child(3) { display: none; }

/* ---------- Onboarding (new clinic / hospital) ---------- */
.onboarding { width: 100%; max-width: 960px; margin: 0 auto; padding: 24px var(--gutter) 48px; }
.onboarding:focus { outline: none; }
.onboarding-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; min-height: 56px; margin-bottom: 16px; }
.onboarding-head p { margin: 0; }
.onboarding-progress ol { list-style: none; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin: 0 0 20px; padding: 0; counter-reset: none; }
.onboarding-progress li { display: flex; align-items: center; gap: 8px; padding-top: 10px; border-top: 3px solid var(--border); font-size: 13px; color: var(--muted); font-weight: 550; }
.onboarding-progress li.done { border-top-color: var(--primary-ring); color: var(--text); }
.onboarding-progress li.current { border-top-color: var(--primary); color: var(--primary-hover); font-weight: 700; }
.onboarding-progress-num { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--surface-2); font-size: 12px; font-weight: 700; flex-shrink: 0; }
.onboarding-progress li.current .onboarding-progress-num { background: var(--primary); color: #fff; }
.onboarding-progress li.done .onboarding-progress-num { background: var(--primary-soft); color: var(--primary); }
.onboarding-progress-compact { display: none; }
.onboarding-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 28px 32px 32px; }
.onboarding-card > h1 { margin-top: 0; }
.onboarding-card > p.muted { margin-top: 0; }
.onboarding-subheading { font-size: 15px; margin: 24px 0 12px; padding-top: 20px; border-top: 1px solid var(--border); }
.type-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 8px 0 8px; }
.type-card { display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-start; gap: 6px; min-height: 112px; padding: 16px; text-align: left; border: 1px solid var(--border-strong); border-radius: var(--radius-lg); background: var(--surface); font-weight: 400; white-space: normal; }
.type-card strong { font-size: 16px; font-weight: 650; }
.type-card span { color: var(--muted); font-size: 13.5px; line-height: 1.45; }
.type-card.selected { border-color: var(--primary); background: var(--primary-soft); box-shadow: inset 0 0 0 1px var(--primary); }
.type-card.selected strong { color: var(--primary-hover); }
.onboarding-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.onboarding-plan .plan-card-action button { width: 100%; }
.order-summary { margin: 16px 0; border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 4px 20px; max-width: 560px; }
.order-summary > div { display: flex; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 14.5px; }
.order-summary > div:last-child { border-bottom: 0; }
.order-summary dt { color: var(--muted); }
.order-summary dd { margin: 0; text-align: right; font-weight: 600; overflow-wrap: anywhere; }
.order-summary .total dt, .order-summary .total dd { color: var(--text); font-size: 16px; font-weight: 700; }
.onboarding-result { max-width: 600px; }
.lead-text { font-size: 17px; color: var(--muted); }
.auth-help { margin-top: 16px; }
.auth-divider { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); text-align: center; }
.auth-divider p { margin: 0 0 10px; }
.auth-create { width: 100%; border: 1px solid var(--border-strong); color: var(--text); background: var(--surface); }
.auth-create:hover { background: var(--surface-2); color: var(--text); }
@media (max-width: 767.98px) {
  .onboarding { padding-top: 8px; }
  .onboarding-progress ol { display: none; }
  .onboarding-progress-compact { display: block; margin: 0 0 12px; font-size: 13px; font-weight: 600; color: var(--primary-hover); }
  .onboarding-card { padding: 20px 16px 24px; }
  .type-cards { grid-template-columns: minmax(0, 1fr); }
  .type-card { min-height: 0; }
  /* The continue button stays reachable at the bottom of the screen. */
  .onboarding-actions { position: sticky; bottom: 0; margin: 20px -16px -24px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--border); }
  .onboarding-actions > * { flex: 1 1 0; }
  .order-summary { padding: 0 14px; }
}
@media (min-width: 768px) and (max-width: 1023.98px) {
  .type-cards { grid-template-columns: minmax(0, 1fr); }
  .type-card { min-height: 0; }
}
@media (max-width: 767.98px) { .onboarding-actions.static { position: static; margin: 20px 0 0; padding: 0; border-top: 0; } }
.onboarding-result .onboarding-actions { justify-content: flex-start; }

/* ---------- Clinic settings: branding ---------- */
.settings-subheading { font-size: 15px; margin: 24px 0 12px; padding-top: 20px; border-top: 1px solid var(--border); }
.color-row { display: flex; gap: 8px; align-items: stretch; }
.color-row input[type=text], .color-row input:not([type]) { flex: 1; }
.color-picker { width: 56px; min-height: var(--control-h); padding: 4px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); cursor: pointer; }
.brand-preview { --accent: #0F6657; margin: -6px 0 18px; padding: 10px 14px; border-top: 2px solid var(--accent); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.brand-preview span { color: var(--accent); font-weight: 700; font-size: 14px; }
.logo-preview { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.logo-preview img { max-height: 56px; max-width: 180px; object-fit: contain; border: 1px solid var(--border); border-radius: var(--radius); padding: 6px; background: #fff; }
.logo-preview p { margin: 0; }
.file-input { min-height: var(--control-h); padding: 8px 0; font-size: 14px; }

/* ---------- Clinical images ---------- */
.section-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 14px; }
.section-head h2 { margin: 0 0 4px; }
.section-head p { margin: 0; }
.clinical-images .segmented { margin-bottom: 14px; flex-wrap: wrap; }
.image-filters { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 12px; align-items: end; padding: 14px 14px 0; margin-bottom: 16px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.image-filters .field { margin-bottom: 14px; min-width: 0; }
.image-filters label { font-size: 12.5px; }
.filter-actions { margin-bottom: 14px; display: flex; align-items: center; min-height: var(--control-h); }
@media (max-width: 1023.98px) { .image-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 479.98px) { .image-filters { grid-template-columns: minmax(0, 1fr); } }

/* Type labels are words, not colour alone. */
.image-type { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding: 3px 7px; border-radius: 4px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); }
.image-type.type-before { border-color: #9fb9b2; }
.image-type.type-after { background: var(--text); border-color: var(--text); color: #fff; }
.image-type.on-image { position: absolute; left: 8px; top: 8px; }

.image-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.image-card { height: 100%; display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.image-thumb { position: relative; display: block; width: 100%; padding: 0; border: 0; border-radius: 0; aspect-ratio: 4 / 3; min-height: 0; background: #e9eeec; cursor: zoom-in; }
.image-thumb img, .timeline-thumb img, .image-choice img, .comparison-thumbs img { width: 100%; height: 100%; object-fit: contain; display: block; }
.image-thumb:focus-visible { outline: 3px solid var(--primary-ring); outline-offset: -3px; }
.image-card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.image-card-body p { margin: 0; overflow-wrap: anywhere; }
.image-area { font-weight: 600; font-size: 14px; }
.image-treatment { font-size: 13.5px; }
.image-card-body .row-actions { margin-top: auto; padding-top: 8px; }
.image-count { margin: 12px 2px 0; }

.image-timelines { display: grid; gap: 22px; }
.image-timeline-group h3 { margin: 0 0 10px; font-size: 15px; }
.image-timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.image-timeline li { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 14px; align-items: center; position: relative; padding-bottom: 18px; }
.image-timeline li:not(:last-child)::after { content: ""; position: absolute; left: 60px; top: 92px; bottom: 2px; border-left: 2px solid var(--border-strong); }
.timeline-thumb { width: 120px; height: 90px; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #e9eeec; overflow: hidden; cursor: zoom-in; }
.timeline-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.timeline-text time { font-size: 13px; color: var(--muted); font-weight: 600; }

.comparison-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.comparison-card { display: grid; gap: 10px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.comparison-card p { margin: 2px 0 8px; }
.comparison-thumbs { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; }
.comparison-thumbs figure { margin: 0; aspect-ratio: 4 / 3; background: #e9eeec; border-radius: var(--radius-sm); overflow: hidden; position: relative; }
.comparison-thumbs figcaption { position: absolute; left: 6px; top: 6px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; background: var(--surface); padding: 2px 6px; border-radius: 4px; }

.consultation-images .row-actions { margin: 10px 0 12px; }
.image-strip { list-style: none; margin: 0 0 8px; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.image-strip .image-thumb { border-radius: var(--radius-sm); border: 1px solid var(--border); }

/* Upload */
.dropzone { display: grid; justify-items: center; gap: 6px; text-align: center; padding: 26px 16px; border: 1.5px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2); }
.dropzone.dragging { border-color: var(--primary); background: var(--primary-soft); }
.dropzone p { margin: 0; }
.dropzone .icon { width: 26px; height: 26px; color: var(--muted); }
.dropzone .row-actions { justify-content: center; margin-top: 6px; }
.camera-button { display: none; }
@media (pointer: coarse) { .camera-button { display: inline-flex; } }
.upload-review h3 { font-size: 14px; margin: 20px 0 10px; }
.upload-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.upload-item { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius); }
.upload-item img, .upload-placeholder { width: 64px; height: 48px; object-fit: contain; background: #e9eeec; border-radius: 4px; display: block; }
.upload-item p { margin: 0; overflow-wrap: anywhere; }
.upload-item.state-failed { border-color: var(--error-border); background: var(--error-bg); }
.upload-item.state-done { border-color: #bfdccb; }

/* Viewer and comparison */
dialog.image-viewer { width: min(1180px, calc(100% - 32px)); height: min(92dvh, 960px); max-height: none; }
dialog.image-viewer.is-fullscreen, dialog.image-viewer:fullscreen { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; border-radius: 0; }
.viewer-body { display: flex; flex-direction: column; gap: 12px; padding: 12px 16px 16px; flex: 1; min-height: 0; overflow: hidden !important; }
.viewer-toolbar { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.tool-group { display: inline-flex; align-items: center; gap: 4px; }
.tool-group .icon-button { border: 1px solid var(--border); font-size: 18px; width: var(--control-h); }
.zoom-level, .image-counter { min-width: 52px; text-align: center; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); }
.viewer-main { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 14px; flex: 1; min-height: 0; }
.image-frame { position: relative; overflow: hidden; background: #1d2522; border-radius: var(--radius); min-height: 220px; touch-action: none; }
.image-frame:focus-visible { outline: 3px solid var(--primary-ring); outline-offset: 2px; }
.image-frame.panning { cursor: grabbing; }
.stage-image { position: absolute; max-width: none; transform-origin: center center; user-select: none; -webkit-user-drag: none; }
.viewer-side { overflow-y: auto; min-height: 0; }
.image-info { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 12px; margin: 0 0 14px; font-size: 13.5px; }
.image-info dt { color: var(--muted); }
.image-info dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
@media (max-width: 1023.98px) {
  .viewer-main { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(260px, 1fr) auto; }
  .viewer-side { max-height: 32dvh; }
}
@media (max-width: 767.98px) {
  dialog.image-viewer { width: 100%; height: 100dvh; border-radius: 0; margin: 0; }
  .viewer-body { padding: 10px 12px 12px; }
}

.compare-body { overflow-y: auto !important; }
.compare-header { display: flex; flex-wrap: wrap; gap: 6px 26px; margin: 0; padding: 10px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.compare-header dt { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.compare-header dd { margin: 2px 0 0; font-weight: 600; overflow-wrap: anywhere; }
.compare-stage { flex: 1 0 auto; display: grid; gap: 14px; min-height: 0; }
.compare-stage.mode-side { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.compare-panel { margin: 0; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.compare-panel figcaption { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.compare-panel p { margin: 0; }
.compare-panel .image-frame, .compare-stage .layered { height: clamp(240px, 52dvh, 640px); }
.is-fullscreen .compare-panel .image-frame, .is-fullscreen .compare-stage .layered, :fullscreen .compare-panel .image-frame { height: calc(100dvh - 300px); }
.compare-label strong { font-size: 12px; letter-spacing: .08em; padding: 2px 7px; border: 1.5px solid currentColor; border-radius: 4px; margin-right: 4px; }
.layer { position: absolute; inset: 0; }
.corner-label { position: absolute; top: 10px; z-index: 3; background: rgb(255 255 255 / 92%); color: var(--text); padding: 4px 8px; border-radius: 4px; font-size: 13px; pointer-events: none; }
.corner-label.left { left: 10px; }
.corner-label.right { right: 10px; }
.slider-divider { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: #fff; box-shadow: 0 0 0 1px rgb(0 0 0 / 35%); z-index: 2; pointer-events: none; }
.slider-knob { position: absolute; top: 50%; left: 50%; width: 34px; height: 34px; margin: -17px 0 0 -17px; border-radius: 50%; background: #fff; border: 2px solid var(--text); box-shadow: var(--shadow-sm); }
.slider-knob::before { content: "‹ ›"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 15px; font-weight: 700; color: var(--text); letter-spacing: 2px; }
.slider-input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: ew-resize; z-index: 4; touch-action: none; }
.slider-input:focus-visible + .slider-knob, .layered:has(.slider-input:focus-visible) .slider-knob { outline: 3px solid var(--primary-ring); outline-offset: 2px; }
.compare-controls { display: flex; flex-wrap: wrap; gap: 4px 24px; align-items: center; }
.compare-controls p { margin: 0; }
.opacity-field { display: grid; grid-template-columns: auto minmax(120px, 220px) 3.5em; gap: 10px; align-items: center; margin: 0; }
.opacity-field label { margin: 0; }
.opacity-field input { min-height: 0; padding: 0; }
.compare-footer:empty { display: none; }
.compare-footer { border-top: 1px solid var(--border); padding-top: 12px; }
.compare-notes h3 { font-size: 13px; margin: 0 0 4px; }
.compare-notes p { margin: 0 0 12px; white-space: pre-wrap; }
@media (max-width: 767.98px) {
  /* Narrow screens: before above after, never two small images side by side. */
  .compare-stage.mode-side { grid-template-columns: minmax(0, 1fr); }
  .compare-panel .image-frame { height: clamp(220px, 46dvh, 420px); }
  .compare-stage .layered { height: clamp(260px, 56dvh, 480px); }
  .opacity-field { grid-template-columns: minmax(0, 1fr) 3.5em; }
  .opacity-field label { grid-column: 1 / -1; }
}

.compare-picker .compare-slots { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 767.98px) { .compare-picker .compare-slots { grid-template-columns: minmax(0, 1fr); } }
.compare-slot { min-width: 0; border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px 12px; margin: 0; }
.compare-slot legend { font-weight: 700; padding: 0 4px; }
.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; max-height: 340px; overflow-y: auto; padding: 2px; }
.image-choice { display: grid; gap: 4px; padding: 4px; border: 2px solid transparent; border-radius: var(--radius-sm); cursor: pointer; margin: 0; font-weight: 400; }
.image-choice img { aspect-ratio: 4 / 3; height: auto; background: #e9eeec; border-radius: 4px; }
.image-choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.image-choice:has(input:focus-visible) { outline: 3px solid var(--primary-ring); outline-offset: 1px; }
.choice-text { display: flex; flex-direction: column; gap: 2px; align-items: flex-start; font-size: 12.5px; }
.agenda-links { display: flex; gap: 10px; align-items: center; }

/* ---------- Platform console: control center ---------- */
.console-tools { display: flex; align-items: center; gap: 8px; }
.console-search { display: flex; align-items: center; gap: 8px; min-width: 0; width: clamp(180px, 26vw, 340px); padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.console-search:focus-within { border-color: var(--primary-ring); box-shadow: 0 0 0 3px var(--primary-soft); }
.console-search .icon { width: 16px; height: 16px; color: var(--muted); flex: none; }
.console-search input { border: 0; background: transparent; min-height: calc(var(--control-h) - 6px); padding: 0; width: 100%; min-width: 0; box-shadow: none; }
.console-search input:focus { outline: none; box-shadow: none; }
.bell { position: relative; display: inline-flex; align-items: center; justify-content: center; height: var(--control-h); color: var(--text); border-radius: var(--radius); }
.bell-count { position: absolute; top: 4px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--text); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
@media (max-width: 767.98px) { .console-search { width: auto; flex: 1 1 auto; } .console-tools { flex: 1 1 auto; justify-content: flex-end; min-width: 0; } }
@media (max-width: 479.98px) { .console-search input::placeholder { color: transparent; } .console-search { width: 44px; flex: 0 1 160px; } }

.range-control { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; }
.range-control .segmented { flex-wrap: wrap; }
.range-custom { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; }
.range-custom .field { margin: 0; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.metric { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; min-width: 0; color: inherit; text-decoration: none; }
a.metric:hover { border-color: var(--border-strong); }
a.metric:focus-visible { outline: 3px solid var(--primary-ring); outline-offset: 2px; }
.metric-label { font-size: 12.5px; color: var(--muted); }
.metric-value { font-size: 22px; font-weight: 650; line-height: 1.2; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metric-note { font-size: 12.5px; color: var(--muted); }
@media (max-width: 1023.98px) { .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 479.98px) { .metric-grid { grid-template-columns: minmax(0, 1fr); } }

.dash-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin-bottom: 20px; align-items: start; }
.dash-grid > .panel { margin: 0; min-width: 0; }
.dash-grid + .panel, .metric-grid + .panel { margin-top: 0; }
@media (max-width: 1023.98px) { .dash-grid { grid-template-columns: minmax(0, 1fr); } }
.panel > .small:last-child { display: inline-block; padding: 0 20px 16px; }

.figures { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px 20px; margin: 14px 0 0; }
.figures dt { font-size: 12.5px; color: var(--muted); }
.figures dd { margin: 2px 0 0; font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.lead-figure { margin: 0; color: var(--muted); }
.lead-figure strong { font-size: 24px; color: var(--text); font-variant-numeric: tabular-nums; }

.chart { margin: 0; }
.chart-bars { display: flex; align-items: flex-end; gap: 3px; height: 160px; padding-top: 6px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.chart-col { flex: 1 1 0; min-width: 8px; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; }
.chart-bar { width: 100%; max-width: 36px; background: var(--primary); border-radius: 3px 3px 0 0; opacity: .85; }
.chart-col:hover .chart-bar { opacity: 1; }
.chart-tick { position: absolute; bottom: -20px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.chart figcaption { margin-top: 26px; }
.chart-empty { margin: 8px 0; padding: 24px 12px; text-align: center; color: var(--muted); background: var(--surface-2); border-radius: var(--radius); font-size: 13.5px; }

.bar-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.bar-list li { display: grid; grid-template-columns: minmax(90px, 34%) minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: 13.5px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--primary); border-radius: 4px; }
.bar-value { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 5ch; text-align: right; }

.meter-wrap { display: grid; gap: 6px; margin-bottom: 10px; }
.meter-label { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 13.5px; }
.meter { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--primary); }
.meter.warning > span { background: var(--warning); }
.meter.critical > span { background: var(--error); }

.section-error { margin: 0; padding: 16px 20px; color: var(--muted); font-size: 13.5px; }
.alert-list { list-style: none; margin: 0; padding: 0; }
.alert-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: start; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.alert-item:last-child { border-bottom: 0; }
.alert-item p { margin: 2px 0; font-size: 13.5px; overflow-wrap: anywhere; }
.alert-item.read { opacity: .72; }
.severity-tag { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; padding: 3px 7px; border-radius: 4px; border: 1px solid var(--border-strong); color: var(--muted); background: var(--surface); }
.severity-tag.warning { color: var(--warning); border-color: var(--warning-border); background: var(--warning-bg); }
.severity-tag.critical { color: var(--error); border-color: var(--error-border); background: var(--error-bg); }
@media (max-width: 767.98px) { .alert-item { grid-template-columns: minmax(0, 1fr); padding: 12px 16px; } }

.activity-list { list-style: none; margin: 0; padding: 4px 20px 12px; }
.activity-list li { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) auto; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; align-items: baseline; }
.activity-list li:last-child { border-bottom: 0; }
.activity-clinic { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 767.98px) { .activity-list { padding: 4px 16px 12px; } .activity-list li { grid-template-columns: minmax(0, 1fr); gap: 2px; } }
.result-failure { color: var(--error); font-weight: 600; }

.column-chooser { margin: -6px 0 16px; font-size: 13.5px; }
.column-chooser summary { cursor: pointer; color: var(--primary); font-weight: 600; width: max-content; }
.column-chooser fieldset { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 10px 0 0; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.column-chooser .check { margin: 0; }
.page-header .range-control { justify-content: flex-end; }
/* Grid items align at the top; the stacked-panel spacing rule does not apply inside grids. */
.dash-grid > section.panel + section.panel { margin-top: 0; }
/* Appointment reminders */
.reminder-line { margin: 0; color: var(--muted); }
.reminder-line.reminder-failed, .reminder-line.reminder-partially_sent { color: var(--error); }
.reminder-line.reminder-sent { color: var(--success); }
.reminder-auto { margin: 0 0 14px; }
.reminder-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 20px; margin: 0 0 16px; }
.reminder-facts dt { font-size: 12.5px; color: var(--muted); }
.reminder-facts dd { margin: 2px 0 0; overflow-wrap: anywhere; }
.reminder-heading { font-size: 14px; margin: 8px 0; }
.reminder-channels, .reminder-manual { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 8px; }
.reminder-channel { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); }
.reminder-channel-name { font-weight: 600; min-width: 84px; }
.reminder-channel .small { flex-basis: 100%; }
.reminder-manual li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; }
.reminder-confirm { padding: 12px 14px; margin-bottom: 12px; border: 1px solid var(--warning-border); border-radius: var(--radius); background: var(--warning-bg); }
.reminder-confirm p { margin: 0 0 8px; }
.settings-reminders { margin-top: 24px; }
.reminder-settings .check, .reminder-preferences .check { display: flex; margin: 8px 0; }
.reminder-channel-choice, .reminder-preferences { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; margin: 12px 0; }
.reminder-preferences { grid-column: 1 / -1; }

/* Email delivery log (clinic): recipient name above address. */
.email-recipient { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.email-recipient span { overflow-wrap: anywhere; }
