/* ============================================================
   OrthoMetry UI Refresh — presentation layer
   Loaded after styles.css and page-specific styles.
   No clinical logic, IDs or data flows are changed.
   ============================================================ */

@font-face {
  font-family: 'Geist';
  src: url('fonts/geist-latin.woff2') format('woff2');
  font-weight: 300 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Geist Mono';
  src: url('fonts/geist-mono-latin.woff2') format('woff2');
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
}

/* ---------- Tokens ---------- */
:root,
[data-theme="light"] {
  --ui-font: 'Geist', 'Segoe UI', system-ui, sans-serif;
  --ui-mono: 'Geist Mono', 'Consolas', monospace;
  --ui-topbar-h: 52px;
  --ui-sidebar-w: 240px;
  --ui-radius: 16px;
  --ui-radius-sm: 10px;
  --ui-surface: #FFFFFF;
  --ui-surface-solid: #FFFFFF;
  --ui-surface-2: #F7F5F0;
  --ui-border: #E6E1D6;
  --ui-border-strong: #D6CFC1;
  --ui-text: #14202E;
  --ui-text-2: #5B6B7E;
  --ui-text-3: #8A97A6;
  --ui-accent: #0F766E;
  --ui-accent-2: #0284C7;
  --ui-accent-soft: rgba(15, 118, 110, 0.10);
  --ui-accent-ring: rgba(15, 118, 110, 0.24);
  --ui-glow: rgba(15, 118, 110, 0.18);
  --ui-nav-active: rgba(15, 118, 110, 0.10);
  --ui-sidebar: #0D1726;
  --ui-sidebar-2: #111E31;
  --ui-sidebar-border: rgba(255, 255, 255, 0.08);
  --ui-sidebar-text: #F4F7FB;
  --ui-sidebar-text-2: #A9B6C8;
  --ui-sidebar-text-3: #6F7E94;
  --ui-shadow: 0 18px 40px -28px rgba(20, 32, 46, 0.28);
  --ui-shadow-hover: 0 24px 50px -24px rgba(20, 32, 46, 0.25);

  /* Existing app tokens */
  --font-family: var(--ui-font);
  --bg-primary: #F3F1EB;
  --bg-secondary: #FFFFFF;
  --bg-tertiary: #F7F5F0;
  --bg-card: #FFFFFF;
  --bg-card-hover: #FCFBF8;
  --bg-input: #F7F5F0;
  --bg-hover: #F2EFE8;
  --bg-sidebar: #0D1726;
  --text-primary: #14202E;
  --text-secondary: #5B6B7E;
  --text-muted: #8A97A6;
  --accent: #0F766E;
  --accent-hover: #0D9488;
  --accent-soft: rgba(15, 118, 110, 0.10);
  --accent-ring: rgba(15, 118, 110, 0.24);
  --accent-primary: #0F766E;
  --accent-gold: #B7791F;
  --accent-gold-hover: #A16207;
  --accent-gold-soft: rgba(183, 121, 31, 0.12);
  --success: #059669;
  --success-soft: rgba(5, 150, 105, 0.10);
  --warning: #B45309;
  --warning-soft: rgba(180, 83, 9, 0.10);
  --danger: #DC2626;
  --danger-soft: rgba(220, 38, 38, 0.09);
  --border-color: #E6E1D6;
  --border-color-strong: #D6CFC1;
  --border-radius-sm: 8px;
  --border-radius: 10px;
  --border-radius-md: 12px;
  --border-radius-lg: 16px;
  --shadow: 0 18px 40px -28px rgba(20, 32, 46, 0.28);
  --shadow-sm: 0 8px 20px -16px rgba(20, 32, 46, 0.18);
  --shadow-md: 0 24px 50px -24px rgba(20, 32, 46, 0.25);
  --scrollbar-thumb: #CFC8BB;
  --scrollbar-track: transparent;
  --transition-speed: 0.18s;
}

[data-theme="dark"],
.dark {
  --ui-surface: #111927;
  --ui-surface-solid: #111927;
  --ui-surface-2: #0C131F;
  --ui-border: rgba(255, 255, 255, 0.08);
  --ui-border-strong: rgba(255, 255, 255, 0.15);
  --ui-text: #F4F7FB;
  --ui-text-2: #A9B6C8;
  --ui-text-3: #6F7E94;
  --ui-accent: #2DD4BF;
  --ui-accent-2: #38BDF8;
  --ui-accent-soft: rgba(45, 212, 191, 0.12);
  --ui-accent-ring: rgba(45, 212, 191, 0.28);
  --ui-glow: rgba(45, 212, 191, 0.24);
  --ui-nav-active: rgba(45, 212, 191, 0.13);
  --ui-sidebar: #080C14;
  --ui-sidebar-2: #0D1420;
  --ui-sidebar-border: rgba(255, 255, 255, 0.075);
  --ui-sidebar-text: #F4F7FB;
  --ui-sidebar-text-2: #A9B6C8;
  --ui-sidebar-text-3: #6F7E94;
  --ui-shadow: 0 22px 50px -28px rgba(0, 0, 0, 0.85);
  --ui-shadow-hover: 0 30px 70px -28px rgba(0, 0, 0, 0.9);

  /* Existing app tokens */
  --font-family: var(--ui-font);
  --bg-primary: #05080D;
  --bg-secondary: #0A0F18;
  --bg-tertiary: #0C131F;
  --bg-card: #111927;
  --bg-card-hover: #162033;
  --bg-input: #0A0F18;
  --bg-hover: rgba(255, 255, 255, 0.055);
  --bg-sidebar: #080C14;
  --text-primary: #F4F7FB;
  --text-secondary: #A9B6C8;
  --text-muted: #6F7E94;
  --accent: #2DD4BF;
  --accent-hover: #5EEAD4;
  --accent-soft: rgba(45, 212, 191, 0.12);
  --accent-ring: rgba(45, 212, 191, 0.28);
  --accent-primary: #2DD4BF;
  --accent-gold: #F5B84B;
  --accent-gold-hover: #FBBF24;
  --accent-gold-soft: rgba(245, 184, 75, 0.14);
  --success: #34D399;
  --success-soft: rgba(52, 211, 153, 0.12);
  --warning: #F5B84B;
  --warning-soft: rgba(245, 184, 75, 0.12);
  --danger: #FB7185;
  --danger-soft: rgba(251, 113, 133, 0.12);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-color-strong: rgba(255, 255, 255, 0.15);
  --shadow: 0 22px 50px -28px rgba(0, 0, 0, 0.85);
  --shadow-sm: 0 10px 24px -18px rgba(0, 0, 0, 0.7);
  --shadow-md: 0 30px 70px -28px rgba(0, 0, 0, 0.9);
  --scrollbar-thumb: rgba(255, 255, 255, 0.14);
  --scrollbar-track: transparent;
  --transition-speed: 0.18s;
}

/* ---------- Base ---------- */
html { font-size: 14px; }
body {
  font-family: var(--ui-font);
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font-family: var(--ui-font); }
svg { flex: none; }
::selection { background: var(--ui-accent); color: #042F2E; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--ui-accent); }
:focus-visible { outline: 2px solid var(--ui-accent); outline-offset: 2px; }
.mono, .stat-value, .kpi-val-financial, .kpi-val-appt, .cal-stat-value,
.finance-amount, [id*="Balance"], [id*="Income"], [id*="Expense"] {
  font-variant-numeric: tabular-nums;
}

/* ---------- Window titlebar ---------- */
.app-window-titlebar {
  height: 38px;
  background: #05080D;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  padding-right: 140px;
}
.titlebar-clinic-title { font-size: 11.5px; font-weight: 600; color: #A9B6C8; }
.titlebar-clinic-tag {
  font-size: 8.5px; font-weight: 600; color: #38BDF8;
  background: rgba(56, 189, 248, 0.10); border-color: rgba(56, 189, 248, 0.22);
  padding: 2px 6px; border-radius: 4px;
}

/* ---------- Shell ---------- */
body.is-electron .sidebar {
  top: 50px !important;
  height: calc(100vh - 62px) !important;
  bottom: auto !important;
  left: 12px;
  width: var(--ui-sidebar-w);
  background: var(--ui-sidebar) !important;
  border: 1px solid var(--ui-sidebar-border);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--ui-shadow);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
body.is-electron .main-content {
  margin-left: calc(var(--ui-sidebar-w) + 24px);
  margin-top: 50px;
  height: calc(100vh - 62px);
  padding: 0 26px 40px;
  background: var(--bg-primary);
  border: 1px solid var(--ui-border);
  border-radius: 18px;
  overflow-y: auto;
  position: relative;
}
body:not(.is-electron) .sidebar {
  top: 12px;
  left: 12px;
  bottom: 12px;
  width: var(--ui-sidebar-w);
  background: var(--ui-sidebar) !important;
  border: 1px solid var(--ui-sidebar-border);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--ui-shadow);
}
body:not(.is-electron) .main-content {
  margin-left: calc(var(--ui-sidebar-w) + 24px);
  margin-top: 12px;
  height: calc(100vh - 24px);
  padding: 0 26px 40px;
  border: 1px solid var(--ui-border);
  border-radius: 18px;
  overflow-y: auto;
  position: relative;
}
body:not(.is-electron) .app-window-titlebar { display: none; }

/* ---------- Sidebar ---------- */
.sidebar-header {
  padding: 15px 14px 10px;
  border-bottom: 1px solid var(--ui-sidebar-border);
}
.app-brand-lockup { gap: 9px; justify-content: flex-start; }
.app-brand-mark { height: 31px; }
.app-brand-wordmark { width: 136px; }
.app-brand-tagline { font-size: 7px; letter-spacing: 0.22em; color: var(--ui-sidebar-text-3); }
.sidebar-header .logo { justify-content: flex-start; }

.nav-menu {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 8px 8px;
  scrollbar-width: thin;
}
.nav-menu::-webkit-scrollbar { width: 4px; }
.nav-menu::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.10); }

.ui-nav-section {
  list-style: none;
  padding: 12px 9px 5px;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ui-sidebar-text-3);
  user-select: none;
}
.ui-nav-section:first-child { padding-top: 3px; }

.ui-nav-glider {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 0;
  height: 42px;
  border-radius: 10px;
  background: var(--ui-nav-active);
  border: 1px solid color-mix(in srgb, var(--ui-accent) 20%, transparent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 8px 20px -14px var(--ui-glow);
  pointer-events: none;
  z-index: 0;
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.nav-item {
  position: relative;
  z-index: 1;
  height: 42px;
  padding: 0 9px;
  margin: 1px 0;
  border-radius: 10px;
  border-left: none;
  gap: 9px;
  color: var(--ui-sidebar-text-2);
  font-size: 12.5px;
  font-weight: 500;
  transition: color 0.18s ease, background 0.18s ease;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.045); color: var(--ui-sidebar-text); }
.nav-item.active {
  background: transparent;
  color: var(--ui-sidebar-text);
  border-left-color: transparent;
  font-weight: 600;
}
.nav-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #D7E1EC;
  box-shadow: none;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}
.nav-icon svg { width: 16px; height: 16px; }
.nav-icon .accent { stroke: var(--icon-accent, #2DD4BF); }
.nav-item:hover .nav-icon {
  transform: none;
  color: #D7E1EC;
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: none;
}
.nav-item.active .nav-icon {
  transform: none;
  color: #D7E1EC;
  background: rgba(255, 255, 255, 0.045);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: none;
}
.nav-label { font-size: 12.5px; }
.nav-badge {
  font-size: 8.5px;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--ui-sidebar-text-3);
}
.nav-item.active .nav-badge {
  color: var(--ui-accent);
  background: var(--ui-accent-soft);
  border-color: color-mix(in srgb, var(--ui-accent) 24%, transparent);
}

.sidebar-footer {
  padding: 9px 10px 11px;
  border-top: 1px solid var(--ui-sidebar-border);
  background: transparent;
}
.theme-toggle {
  height: 36px;
  padding: 0 9px;
  border-radius: 9px;
  color: var(--ui-sidebar-text-2);
  font-size: 11px;
  gap: 9px;
}
.theme-toggle:hover { background: rgba(255, 255, 255, 0.055); color: var(--ui-sidebar-text); }
.theme-icon { font-size: 14px; width: 20px; }
.sidebar-version-pill { font-size: 9px; color: var(--ui-sidebar-text-3); }
.sidebar-user-profile {
  background: rgba(255, 255, 255, 0.04) !important;
  border: 1px solid var(--ui-sidebar-border);
  border-radius: 10px !important;
  padding: 7px 9px !important;
}

/* ---------- Topbar ---------- */
.ui-topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  height: var(--ui-topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 0 -26px 20px;
  padding: 0 26px;
  background: color-mix(in srgb, var(--bg-primary) 88%, transparent);
  border-bottom: 1px solid var(--ui-border);
  border-radius: 18px 18px 0 0;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.ui-topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ui-crumb {
  display: flex; align-items: center; gap: 6px;
  font-size: 10.5px; color: var(--ui-text-3); white-space: nowrap;
}
.ui-crumb svg { width: 11px; height: 11px; }
.ui-crumb strong { color: var(--ui-text-2); font-weight: 600; }
.ui-live-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 7px; border-radius: 999px;
  font-size: 8px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--ui-accent); background: var(--ui-accent-soft);
  border: 1px solid color-mix(in srgb, var(--ui-accent) 20%, transparent);
}
.ui-live-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.ui-topbar-actions { display: flex; align-items: center; gap: 7px; }
.ui-search-trigger {
  width: 286px; height: 34px;
  display: flex; align-items: center; gap: 7px;
  padding: 0 9px; border-radius: 9px;
  background: var(--bg-input); border: 1px solid var(--ui-border);
  color: var(--ui-text-3); font-size: 10.5px; text-align: left; cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}
.ui-search-trigger:hover { border-color: var(--ui-border-strong); background: var(--bg-hover); color: var(--ui-text-2); }
.ui-search-trigger svg { width: 14px; height: 14px; }
.ui-search-trigger span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ui-search-trigger kbd, .ui-palette kbd {
  font-family: var(--ui-mono); font-size: 8px; padding: 2px 5px;
  border-radius: 4px; background: var(--ui-surface-2);
  border: 1px solid var(--ui-border); color: var(--ui-text-3);
}
.ui-search-trigger kbd { margin-left: auto; }
.ui-icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center;
  border-radius: 9px; border: 1px solid var(--ui-border);
  background: var(--ui-surface-2); color: var(--ui-text-2);
  cursor: pointer; position: relative;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.15s ease;
}
.ui-icon-btn:hover { background: var(--bg-hover); border-color: var(--ui-border-strong); color: var(--ui-text); }
.ui-icon-btn:active { transform: scale(0.95); }
.ui-icon-btn svg { width: 16px; height: 16px; }
.ui-icon-btn.has-dot::after {
  content: ''; position: absolute; top: 7px; right: 7px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--danger); border: 2px solid var(--bg-primary);
}
.ui-avatar {
  width: 30px; height: 30px; flex: none; border-radius: 50%;
  display: inline-grid; place-items: center;
  background: linear-gradient(135deg, var(--ui-accent), var(--ui-accent-2));
  color: #FFFFFF; font-size: 9.5px; font-weight: 700;
  border: 2px solid var(--bg-primary); cursor: pointer;
}
.ui-topbar .btn { height: 34px; font-size: 11.5px; padding: 0 12px; border-radius: 9px; }
.ui-topbar .btn svg { width: 14px; height: 14px; }
.ui-icon-btn.active {
  background: var(--ui-accent-soft);
  border-color: color-mix(in srgb, var(--ui-accent) 35%, transparent);
  color: var(--ui-accent);
}

/* ---------- Google Drive activity popover ---------- */
.ui-drive-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 26px;
  z-index: 80;
  width: 390px;
  max-height: min(560px, calc(100vh - 90px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--ui-border-strong);
  border-radius: 14px;
  background: var(--ui-surface-solid);
  color: var(--ui-text);
  box-shadow: var(--ui-shadow-hover);
  animation: uiDrivePanelIn 0.18s cubic-bezier(.16,1,.3,1);
}
.ui-drive-panel[hidden] { display: none; }
@keyframes uiDrivePanelIn {
  from { opacity: 0; transform: translateY(-5px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.ui-drive-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--ui-border);
}
.ui-drive-panel-copy { min-width: 0; }
.ui-drive-eyebrow {
  display: block;
  margin-bottom: 2px;
  font-size: 7.5px;
  font-weight: 700;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--ui-accent);
}
.ui-drive-panel-copy strong { display: block; font-size: 12.5px; font-weight: 650; letter-spacing: -.02em; }
.ui-drive-panel-status {
  flex: none;
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-2);
  color: var(--ui-text-3);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.ui-drive-panel-status.active { color: var(--ui-accent); background: var(--ui-accent-soft); border-color: color-mix(in srgb, var(--ui-accent) 24%, transparent); }
.ui-drive-panel-status.good { color: var(--success); background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 24%, transparent); }
.ui-drive-panel-status.pending { color: var(--warning); background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 24%, transparent); }
.ui-drive-panel-status.error { color: var(--danger); background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 24%, transparent); }
.ui-drive-panel-status.offline { color: var(--ui-text-3); background: var(--ui-surface-2); }
.ui-drive-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--ui-border);
}
.ui-drive-summary > div {
  padding: 7px 8px;
  border-radius: 8px;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-2);
}
.ui-drive-summary span { display: block; font-size: 7px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ui-text-3); }
.ui-drive-summary strong { display: block; margin-top: 2px; font-size: 15px; font-weight: 650; letter-spacing: -.03em; color: var(--ui-text); font-variant-numeric: tabular-nums; }
.ui-drive-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ui-drive-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 8px;
  transition: background .15s ease;
}
.ui-drive-row:hover { background: var(--bg-hover); }
.ui-drive-file-icon {
  width: 27px;
  height: 27px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--ui-accent-soft);
  color: var(--ui-accent);
}
.ui-drive-file-icon svg { width: 13px; height: 13px; }
.ui-drive-file-main { flex: 1; min-width: 0; }
.ui-drive-file-main strong {
  display: block;
  font-size: 9.5px;
  font-weight: 600;
  color: var(--ui-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ui-drive-file-main small {
  display: block;
  margin-top: 1px;
  font-size: 8px;
  color: var(--ui-text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ui-drive-status-badge {
  flex: none;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 7.5px;
  font-weight: 700;
  letter-spacing: .03em;
  color: var(--ui-text-3);
  background: var(--ui-surface-2);
  border: 1px solid var(--ui-border);
}
.ui-drive-status-badge.active { color: var(--ui-accent); background: var(--ui-accent-soft); border-color: color-mix(in srgb, var(--ui-accent) 22%, transparent); }
.ui-drive-status-badge.good { color: var(--success); background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 22%, transparent); }
.ui-drive-status-badge.pending { color: var(--warning); background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 22%, transparent); }
.ui-drive-status-badge.error { color: var(--danger); background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 22%, transparent); }
.ui-drive-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 28px 18px;
  text-align: center;
}
.ui-drive-empty-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  margin-bottom: 4px;
  border-radius: 50%;
  background: var(--success-soft);
  color: var(--success);
}
.ui-drive-empty-icon svg { width: 16px; height: 16px; }
.ui-drive-empty strong { font-size: 10.5px; font-weight: 650; color: var(--ui-text); }
.ui-drive-empty small { font-size: 8.5px; color: var(--ui-text-3); }
.ui-drive-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  border-top: 1px solid var(--ui-border);
  background: var(--ui-surface-2);
  color: var(--ui-text-3);
  font-size: 8px;
  line-height: 1.4;
}
.ui-drive-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
}
.ui-drive-sync {
  flex: none;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface);
  color: var(--ui-text);
  border-radius: 7px;
  padding: 4px 9px;
  font: inherit;
  font-size: 8.5px;
  font-weight: 650;
  cursor: pointer;
}
.ui-drive-sync:hover {
  border-color: color-mix(in srgb, var(--ui-accent) 35%, transparent);
  color: var(--ui-accent);
}
.ui-drive-sync:disabled { opacity: .5; cursor: not-allowed; }
@media (max-width: 760px) {
  .ui-drive-panel {
    position: fixed;
    top: 58px;
    left: 12px;
    right: 12px;
    width: auto;
    max-height: calc(100vh - 74px);
  }
}

/* ---------- Page typography ---------- */
.main-content { color: var(--text-primary); }
.page { animation: none; }
.page.active { animation: uiPageIn 0.22s cubic-bezier(0.16, 1, 0.3, 1) both; }
@keyframes uiPageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.page-header { margin-bottom: 20px; gap: 14px; }
.page-header h1 {
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.035em;
  line-height: 1.1;
  color: var(--text-primary);
}
.page-header .subtitle {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-secondary);
  margin-top: 5px;
}
.page-actions { gap: 7px; }

/* ---------- Cards ---------- */
.stat-card,
.action-card,
.table-container,
.detail-card,
.finance-chart-card,
.finance-ledger-card,
.pi-shell,
.pi-hero,
.calendar-shell,
.calendar-agenda,
.modal,
.auth-card {
  border-radius: var(--ui-radius);
  border: 1px solid var(--ui-border);
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow);
}
.stat-card:hover,
.action-card:hover { transform: translateY(-2px); border-color: var(--ui-border-strong); box-shadow: var(--ui-shadow-hover); }

/* ---------- Dashboard layout ---------- */
#page-dashboard.active {
  display: block;
}
#page-dashboard > .page-header,
#page-dashboard > .stats-grid,
#page-dashboard > .recent-patients-section { grid-column: 1 / -1; }
#page-dashboard > .quick-actions { grid-column: 1; margin-top: 0 !important; }
#page-dashboard > .upcoming-appointments-section { grid-column: 2; margin-top: 0 !important; }
#page-dashboard .page-header { display: block; }
#page-dashboard .page-header .subtitle { margin-top: 4px; }
@media (max-width: 1100px) {
  #page-dashboard.active { display: block; }
  #page-dashboard > .quick-actions,
  #page-dashboard > .upcoming-appointments-section { margin-top: 12px !important; }
}

.ui-stat-spark {
  position: absolute; right: 14px; bottom: 12px;
  width: 124px; height: 34px; opacity: 0.55;
  pointer-events: none;
}
.ui-stat-spark svg { width: 100%; height: 100%; overflow: visible; }
.ui-stat-spark .line { stroke: var(--ui-accent); stroke-width: 1.6; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.ui-stat-spark .area { fill: var(--ui-accent-soft); stroke: none; }

/* ---------- Dashboard stats ---------- */
.stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 11px;
  margin-bottom: 16px;
}
.stat-card {
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 15px 16px;
  min-height: 118px;
  position: relative;
  overflow: hidden;
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.22s ease, box-shadow 0.22s ease;
}
.action-card {
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.22s ease, box-shadow 0.22s ease, background-color 0.22s ease;
}
.stat-card::after {
  content: '';
  position: absolute; right: -34px; top: -44px;
  width: 130px; height: 130px; border-radius: 50%;
  background: radial-gradient(circle, var(--ui-accent-soft), transparent 68%);
  pointer-events: none;
}
.stat-icon {
  width: 32px; height: 32px; flex: none;
  border-radius: 9px;
  display: grid; place-items: center;
  background: var(--ui-surface-2) !important;
  color: var(--ui-accent) !important;
  border: 1px solid var(--ui-border);
  font-size: 0;
}
.stat-icon svg { width: 17px; height: 17px; stroke-width: 1.7; }
.stat-info { gap: 2px; }
.stat-value {
  font-size: 25px;
  font-weight: 650;
  letter-spacing: -0.04em;
  line-height: 1.1;
  color: var(--text-primary);
}
.stat-label { font-size: 10.5px; color: var(--text-muted); margin-top: 2px; }
.finance-stats-grid .stat-value { font-size: 21px; }

/* ---------- Quick actions / recent / appointments ---------- */
.quick-actions,
.upcoming-appointments-section,
.recent-patients-section {
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius);
  padding: 15px 16px;
  margin-top: 12px !important;
  box-shadow: var(--ui-shadow);
}
.quick-actions h2,
.recent-patients-section h2,
.upcoming-appointments-section h2 {
  font-size: 13px !important;
  font-weight: 600 !important;
  letter-spacing: -0.01em;
  margin-bottom: 11px !important;
}
.actions-grid { gap: 8px; margin-bottom: 0; }
.action-card {
  padding: 12px 11px;
  border-radius: 11px;
  background: var(--ui-surface-2);
  border: 1px solid var(--ui-border);
  font-size: 11.5px;
  gap: 10px;
  box-shadow: none;
}
.action-card:hover { background: var(--bg-hover); border-color: var(--ui-border-strong); box-shadow: none; }
.action-icon {
  width: 30px; height: 30px; flex: none;
  border-radius: 9px;
  display: grid; place-items: center;
  background: var(--ui-accent-soft);
  color: var(--ui-accent);
  font-size: 0;
}
.action-icon svg { width: 16px; height: 16px; }

.recent-list { gap: 0; }
.recent-item {
  padding: 9px 4px;
  border: none;
  border-bottom: 1px solid var(--ui-border);
  border-radius: 0;
  background: transparent;
  gap: 10px;
}
.recent-item:last-child { border-bottom: none; }
.recent-item:hover { background: var(--bg-hover); border-color: var(--ui-border); border-radius: 8px; }
.recent-item-name { font-size: 11.5px; font-weight: 600; color: var(--text-primary); }
.recent-item-id { font-size: 9.5px; color: var(--text-muted); }
.recent-item-date { font-size: 9.5px; color: var(--text-muted); font-family: var(--ui-mono); }
.ui-recent-avatar {
  width: 30px; height: 30px; flex: none; border-radius: 50%;
  display: inline-grid; place-items: center;
  background: linear-gradient(135deg, var(--ui-accent), var(--ui-accent-2));
  color: #fff; font-size: 9px; font-weight: 700;
}
.recent-item { display: flex; align-items: center; justify-content: flex-start; }
.recent-item-info { flex: 1; min-width: 0; margin-left: 9px; }
.recent-item-date { margin-left: auto; }

.upcoming-appts-list { gap: 7px; }
.upcoming-appt-card {
  padding: 10px 11px;
  border-radius: 11px;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-2);
  gap: 10px;
}
.upcoming-appt-card:hover { border-color: var(--ui-border-strong); background: var(--bg-hover); }
.upcoming-appt-badge {
  font-size: 8px; font-weight: 700; letter-spacing: 0.06em;
  padding: 3px 7px; border-radius: 999px;
}
.upcoming-appt-badge.today { background: var(--ui-accent-soft); color: var(--ui-accent); }
.upcoming-appt-badge.tomorrow { background: rgba(56, 189, 248, 0.12); color: #38BDF8; }
.upcoming-appt-badge.future { background: var(--ui-surface); color: var(--ui-text-3); border: 1px solid var(--ui-border); }
.upcoming-appt-patient span:first-child { font-size: 11.5px; font-weight: 600; }
.upcoming-appt-meta { font-size: 9.5px; color: var(--ui-text-3); gap: 8px; }
.upcoming-appt-meta strong { color: var(--ui-text-2); }
.upcoming-appt-actions .btn { height: 28px; font-size: 9.5px; padding: 0 9px; border-radius: 7px; }
.empty-state { font-size: 11px; color: var(--text-muted); }

/* ---------- Badges ---------- */
.badge,
.badge-clinic {
  font-size: 9px; font-weight: 600;
  padding: 2px 7px; border-radius: 999px;
  background: var(--ui-surface-2); border: 1px solid var(--ui-border);
  color: var(--ui-text-2);
}
.badge-status {
  font-size: 9px; font-weight: 600;
  padding: 2px 7px; border-radius: 999px;
  border: 1px solid transparent;
}
.badge-status-active { color: var(--ui-accent); background: var(--ui-accent-soft); border-color: color-mix(in srgb, var(--ui-accent) 20%, transparent); }
.badge-status-finished { color: var(--ui-text-3); background: var(--ui-surface-2); border-color: var(--ui-border); }
.badge-status-paused { color: var(--accent-gold); background: var(--accent-gold-soft); border-color: color-mix(in srgb, var(--accent-gold) 20%, transparent); }
.badge-status-missed { color: var(--danger); background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 20%, transparent); }

/* ---------- Tables ---------- */
.table-container {
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  box-shadow: var(--ui-shadow);
  border-radius: var(--ui-radius);
  max-height: calc(100vh - 260px);
}
[data-theme="light"] .table-container { background: var(--ui-surface); }
.data-table thead th {
  padding: 10px 13px;
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.09em;
  color: var(--text-muted);
  background: var(--ui-surface-2);
  border-bottom: 1px solid var(--ui-border);
  text-transform: uppercase;
}
.data-table tbody td {
  padding: 9px 13px;
  font-size: 10.5px;
  border-bottom: 1px solid var(--ui-border);
  color: var(--text-secondary);
}
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table strong { font-size: 11px; color: var(--text-primary); }
.data-table .clickable { cursor: pointer; }
.ui-patient-cell { display: flex; align-items: center; gap: 9px; }
.ui-patient-copy { min-width: 0; }
.ui-patient-avatar {
  width: 28px; height: 28px; flex: none; border-radius: 50%;
  display: inline-grid; place-items: center;
  background: linear-gradient(135deg, var(--ui-accent), var(--ui-accent-2));
  color: #fff; font-size: 8.5px; font-weight: 700;
}
.patient-alert-row { margin-top: 3px; gap: 4px; }
.patient-alert-retention {
  color: var(--accent-gold);
  background: var(--accent-gold-soft);
  border-color: color-mix(in srgb, var(--accent-gold) 38%, transparent);
}
.patient-alert {
  font-size: 8px; padding: 1px 5px; border-radius: 999px;
  background: var(--ui-surface-2); border: 1px solid var(--ui-border);
}
.skeleton-shimmer { background: linear-gradient(90deg, var(--ui-surface-2) 25%, var(--bg-hover) 50%, var(--ui-surface-2) 75%); }

/* ---------- Buttons ---------- */
.btn {
  height: 36px;
  padding: 0 13px;
  border-radius: 9px;
  font-size: 11.5px;
  font-weight: 600;
  gap: 6px;
  letter-spacing: -0.01em;
  transition: transform 0.15s ease, background 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}
.btn:active { transform: scale(0.97); }
.btn svg { width: 14px; height: 14px; }
.btn-primary {
  background: linear-gradient(135deg, var(--ui-accent), color-mix(in srgb, var(--ui-accent) 62%, var(--ui-accent-2)));
  border: 1px solid transparent;
  color: var(--accent-ink, #FFFFFF);
  box-shadow: 0 8px 20px -12px var(--ui-glow), inset 0 1px 0 rgba(255, 255, 255, 0.22);
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent-hover), color-mix(in srgb, var(--accent-hover) 62%, var(--ui-accent-2)));
  border-color: transparent;
  color: var(--accent-ink, #FFFFFF);
  box-shadow: 0 12px 26px -12px var(--ui-glow);
}
[data-theme="dark"] .btn-primary,
.dark .btn-primary { color: #042F2E; }
.btn-outline {
  background: var(--ui-surface-2);
  color: var(--text-secondary);
  border: 1px solid var(--ui-border);
  box-shadow: none;
}
.btn-outline:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--ui-border-strong);
}
.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 24%, transparent);
}
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 10px; border-radius: 8px; }
.btn-chairside { height: 34px; padding: 0 11px; font-size: 10.5px; border-radius: 8px; }
.btn-qa { border-radius: 8px; }
.btn-whatsapp { background: rgba(37, 211, 102, 0.12); color: #25D366; border: 1px solid rgba(37, 211, 102, 0.25); }

/* ---------- Forms ---------- */
input[type="text"], input[type="password"], input[type="email"], input[type="tel"],
input[type="date"], input[type="time"], input[type="number"], input[type="search"],
select, textarea, .form-input {
  background: var(--bg-input);
  border: 1px solid var(--ui-border);
  border-radius: 9px;
  color: var(--text-primary);
  font-size: 11.5px;
  min-height: 36px;
  padding: 0 9px;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}
textarea { padding: 8px 9px; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--text-muted); }
input:focus, select:focus, textarea:focus, .form-input:focus {
  border-color: var(--ui-accent);
  box-shadow: 0 0 0 3px var(--ui-accent-soft);
}
label { font-size: 10.5px; color: var(--text-secondary); }
.form-group { margin-bottom: 13px; }
.form-group label { font-size: 9.5px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 5px; }
.form-row { gap: 10px; }
.search-box {
  background: var(--bg-input);
  border: 1px solid var(--ui-border);
  border-radius: 9px;
  height: 36px;
  padding: 0 9px;
  gap: 7px;
}
.search-box input { background: none; border: none; box-shadow: none; min-height: 0; padding: 0; font-size: 11px; }
.search-box:focus-within { border-color: var(--ui-accent); box-shadow: 0 0 0 3px var(--ui-accent-soft); }
.filter-select { background: var(--bg-input); border: 1px solid var(--ui-border); border-radius: 9px; height: 34px; font-size: 10.5px; color: var(--text-secondary); }
.patient-filter-bar { gap: 10px; padding: 10px 12px; background: var(--ui-surface); border: 1px solid var(--ui-border); border-radius: var(--ui-radius); margin-bottom: 12px; box-shadow: var(--ui-shadow); }
.filter-item label { font-size: 9.5px; color: var(--text-muted); }

/* ---------- Patient detail ---------- */
.patient-executive-header {
  padding: 15px 17px;
  border-radius: var(--ui-radius);
  border: 1px solid var(--ui-border);
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow);
  margin-bottom: 12px;
  gap: 12px;
}
.patient-master-id-bar { gap: 12px; }
.patient-avatar-monogram {
  width: 46px; height: 46px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--ui-accent), var(--ui-accent-2));
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 8px 18px -10px var(--ui-glow);
}
.patient-title-row { gap: 7px; }
.patient-title-row h1 { font-size: 22px; font-weight: 650; letter-spacing: -0.035em; }
.patient-subtitle-row { gap: 6px; font-size: 9.5px; color: var(--text-muted); }
.kpi-mini-meta strong { color: var(--text-secondary); font-weight: 600; }
.meta-dot { opacity: 0.5; }
.patient-kpi-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  padding-top: 11px;
  margin-top: 2px;
  border-top: 1px solid var(--ui-border);
}
.kpi-widget-card {
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--ui-surface-2);
  border: 1px solid var(--ui-border);
  gap: 3px;
}
.kpi-widget-card:hover { border-color: var(--ui-border-strong); transform: none; }
.kpi-widget-label { font-size: 8px; font-weight: 700; letter-spacing: 0.08em; color: var(--text-muted); }
.kpi-widget-val { font-size: 12px; font-weight: 650; }
.kpi-val-financial { color: var(--accent-gold); }
.kpi-val-appt { color: var(--ui-accent); }
.kpi-financial-subtext, .kpi-appt-subtext, .kpi-stage-meta { font-size: 8.5px; color: var(--text-muted); }
.kpi-progress-track { height: 4px; background: var(--track, rgba(255, 255, 255, 0.08)); border-radius: 999px; overflow: hidden; margin: 4px 0 2px; }
[data-theme="light"] .kpi-progress-track { background: rgba(20, 32, 46, 0.08); }
.kpi-progress-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--ui-accent), var(--ui-accent-2)); }
.kpi-wire-pill { padding: 4px 7px; border-radius: 7px; background: var(--ui-accent-soft); border: 1px solid color-mix(in srgb, var(--ui-accent) 18%, transparent); font-size: 9.5px; }
.kpi-wire-icon { font-size: 0; width: 12px; height: 12px; display: inline-grid; place-items: center; }
.kpi-wire-icon::before { content: '⚡'; font-size: 10px; }
.patient-executive-header .chairside-actions .btn span:first-child { font-size: 0; }
.patient-executive-header .chairside-actions .btn span:first-child svg { width: 14px; height: 14px; }

/* ---------- Tabs: two-row rail ---------- */
.tabs.ui-tabs {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  max-width: 100%;
  padding: 6px 10px;
  margin-bottom: 14px;
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: 14px;
  box-shadow: var(--ui-shadow);
  position: sticky;
  top: var(--ui-topbar-h);
  z-index: 35;
  overflow: visible;
}
.ui-tab-row {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: wrap;
  min-width: 0;
}
.tabs.ui-tabs .tab {
  height: 36px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 500;
  gap: 6px;
  position: relative;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}
.tabs.ui-tabs .tab svg { width: 14px; height: 14px; opacity: 0.85; }
.tabs.ui-tabs .tab:hover { background: var(--bg-hover); color: var(--text-primary); }
.tabs.ui-tabs .tab.active {
  background: var(--ui-accent-soft);
  color: var(--ui-accent);
  border-color: color-mix(in srgb, var(--ui-accent) 22%, transparent);
  box-shadow: none;
  font-weight: 600;
}
.tabs.ui-tabs .tab.active::after {
  content: '';
  position: absolute;
  left: 10px; right: 10px; bottom: 2px;
  height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, var(--ui-accent), var(--ui-accent-2));
  transform: scaleX(1);
  transform-origin: left;
}
.tabs.ui-tabs .tab:not(.active)::after { content: none; }
.tab-content.active { animation: uiPanelIn 0.18s cubic-bezier(0.16, 1, 0.3, 1) both; }
@keyframes uiPanelIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.detail-card {
  padding: 17px 19px;
  margin-bottom: 12px;
  border-radius: 14px;
  box-shadow: var(--ui-shadow);
}
.detail-card h3 {
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 12px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--ui-border);
}
.detail-grid { gap: 8px; }
.detail-item { padding: 8px 10px; border-radius: 9px; background: var(--ui-surface-2); border: 1px solid var(--ui-border); }
html[data-direction="porcelain"] #page-patient-detail .detail-item,
html[data-direction="porcelain"] #page-patient-detail .summary-grid > div,
html[data-direction="porcelain"] #page-patient-detail .mini-card,
html[data-direction="porcelain"] #page-patient-detail .aside-stats > div,
html[data-direction="porcelain"] #page-patient-detail .ceph-field,
html[data-direction="porcelain"] #page-patient-detail .ceph-field.highlight-field,
html[data-direction="porcelain"] #page-patient-detail .ceph-input-wrap,
html[data-direction="porcelain"] #page-patient-detail .ceph-input,
html[data-direction="porcelain"] #page-patient-detail input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
html[data-direction="porcelain"] #page-patient-detail select,
html[data-direction="porcelain"] #page-patient-detail textarea,
html[data-direction="porcelain"] #page-patient-detail .form-input {
  background: #FFFFFF !important;
}
html[data-direction="porcelain"] #page-add-patient input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
html[data-direction="porcelain"] #page-add-patient select,
html[data-direction="porcelain"] #page-add-patient textarea,
html[data-direction="porcelain"] #page-add-patient .form-input,
html[data-direction="porcelain"] #page-add-patient .detail-item {
  background: #FFFFFF !important;
}
html[data-direction="porcelain"] #page-settings .direction-option:not(.active),
html[data-direction="porcelain"] #page-settings .drive-connect-row:not(.connected),
html[data-direction="porcelain"] #page-settings .segmented,
html[data-direction="porcelain"] #page-settings .field input,
html[data-direction="porcelain"] #page-settings .field select,
html[data-direction="porcelain"] #page-settings .field textarea {
  background: #FFFFFF;
}

html[data-direction="porcelain"] #page-settings .clinic-logo-preview {
  background: #FFFFFF;
}
html[data-direction="porcelain"] #page-patient-instructions .pi-profile,
html[data-direction="porcelain"] #page-patient-instructions .pi-profile-grid input,
html[data-direction="porcelain"] #page-patient-instructions .pi-lang,
html[data-direction="porcelain"] #page-patient-instructions .pi-lang button:not(.active),
html[data-direction="porcelain"] #page-patient-instructions .pi-doc-card,
html[data-direction="porcelain"] #page-patient-instructions .pi-card,
html[data-direction="porcelain"] #page-patient-instructions .pi-card-actions .btn-outline {
  background: #FFFFFF;
}
html[data-direction="porcelain"] #page-settings .license-manager-section,
html[data-direction="porcelain"] #page-settings .release-publisher-section,
html[data-direction="porcelain"] #page-settings .license-manager-section > div,
html[data-direction="porcelain"] #page-settings .release-publisher-section > div,
html[data-direction="porcelain"] #page-settings .create-doctor-panel,
html[data-direction="porcelain"] #page-settings #adminLicenseTableWrapper > div,
html[data-direction="porcelain"] #page-settings #licenseManagerSection .form-input,
html[data-direction="porcelain"] #page-settings #releasePublisherSection .form-input,
html[data-direction="porcelain"] #page-settings #licenseManagerSection table thead tr {
  background: #FFFFFF !important;
}
html[data-direction="porcelain"] .extraction-pattern-block {
  background: #FFFFFF;
  opacity: 0.88;
}
html[data-direction="porcelain"] .extraction-cross,
html[data-direction="porcelain"] .anchorage-options {
  background: #FFFFFF;
}
html[data-direction="porcelain"] .extraction-tooth-select {
  background-color: #FFFFFF;
}
.detail-label { font-size: 8px; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-muted); }
.detail-value { font-size: 10.5px; color: var(--text-primary); }
.detail-item.full-width { grid-column: 1 / -1; }

/* ---------- Calendar ---------- */
.calendar-layout { gap: 11px; }
.calendar-shell {
  padding: 14px;
  border-radius: var(--ui-radius);
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow);
}
.calendar-summary { gap: 7px; margin-bottom: 10px; }
.cal-stat {
  flex: 1 1 120px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--ui-surface-2);
  border: 1px solid var(--ui-border);
}
.cal-stat-value { font-size: 18px; font-weight: 650; letter-spacing: -0.03em; color: var(--text-primary); }
.cal-stat-label { font-size: 8.5px; color: var(--text-muted); margin-top: 2px; }
.calendar-weekdays { padding: 0 4px 7px; font-size: 8px; font-weight: 700; letter-spacing: 0.08em; color: var(--text-muted); }
.calendar-grid { gap: 4px; }
.cal-day {
  min-height: 66px;
  padding: 6px;
  border-radius: 9px;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-2);
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
.cal-day:hover { background: var(--bg-hover); border-color: var(--ui-border-strong); transform: translateY(-1px); }
.cal-day.other-month { opacity: 0.35; }
.cal-day.today { border-color: color-mix(in srgb, var(--ui-accent) 35%, transparent); background: var(--ui-accent-soft); }
.cal-day.selected { border-color: var(--ui-accent); box-shadow: 0 0 0 2px var(--ui-accent-soft); }
.cal-day-number { font-size: 11px; font-weight: 600; color: var(--text-secondary); }
.cal-day.today .cal-day-number { color: var(--ui-accent); }
.cal-day-pill { font-size: 7.5px; padding: 1px 4px; border-radius: 999px; background: var(--ui-accent-soft); color: var(--ui-accent); }
.cal-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--ui-accent); }
.calendar-agenda {
  padding: 14px;
  border-radius: var(--ui-radius);
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow);
}
.agenda-date { font-size: 13px; font-weight: 600; }
.agenda-sub { font-size: 9px; color: var(--text-muted); }
.agenda-list { gap: 6px; }
.agenda-item, .agenda-card { padding: 9px 10px; border-radius: 9px; border: 1px solid var(--ui-border); background: var(--ui-surface-2); }
.agenda-empty { font-size: 10.5px; color: var(--text-muted); }

/* Calendar keeps the original light-theme colours: white cells and the
   teal gradient for today/selected. */
html[data-direction="porcelain"] .calendar-shell,
html[data-direction="porcelain"] .calendar-agenda,
html[data-direction="porcelain"] .cal-stat {
  background: #FFFFFF;
}
html[data-direction="porcelain"] .calendar-shell {
  background:
    radial-gradient(1200px 240px at 12% -10%, rgba(20, 184, 166, 0.10), transparent 70%),
    #FFFFFF;
}
html[data-direction="porcelain"] .cal-day {
  background: #FFFFFF;
  border-color: #E7ECF2;
}
html[data-direction="porcelain"] .cal-day:hover {
  background: #F8FAFC;
  border-color: rgba(20, 184, 166, 0.45);
}
html[data-direction="porcelain"] .cal-day.other-month { background: #F8FAFC; }
html[data-direction="porcelain"] .cal-day.today,
html[data-direction="porcelain"] .cal-day.selected {
  background: linear-gradient(150deg, #14B8A6 0%, #0D9488 55%, #0F766E 100%);
  border-color: transparent;
  box-shadow: 0 16px 30px -18px rgba(13, 148, 136, 0.9);
}
html[data-direction="porcelain"] .cal-day.today .cal-day-number,
html[data-direction="porcelain"] .cal-day.selected .cal-day-number,
html[data-direction="porcelain"] .cal-day.today .cal-day-count,
html[data-direction="porcelain"] .cal-day.selected .cal-day-count {
  color: #FFFFFF;
}
html[data-direction="porcelain"] .cal-day.today .cal-day-pill,
html[data-direction="porcelain"] .cal-day.selected .cal-day-pill {
  background: rgba(255, 255, 255, 0.22);
  color: #FFFFFF;
}
html[data-direction="porcelain"] .cal-day.today .cal-dot,
html[data-direction="porcelain"] .cal-day.selected .cal-dot {
  background: #FFFFFF;
}

/* ---------- Finance ---------- */
.finance-chart-card, .finance-ledger-card { padding: 16px !important; box-shadow: var(--ui-shadow); }
.finance-chart-card h2, .finance-ledger-card h2 { font-size: 13px !important; letter-spacing: -0.01em; }
.multi-currency-summary-container { font-size: 10.5px; }
.expense-entry-form {
  background: var(--ui-surface-2) !important;
  border: 1px solid var(--ui-border) !important;
  border-radius: 11px !important;
  padding: 12px !important;
  gap: 8px !important;
}
.expense-entry-form label { font-size: 8.5px !important; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-muted) !important; }
.expense-entry-form input, .expense-entry-form select { min-height: 34px !important; font-size: 10.5px !important; }
.chart-currency-pills button { border-radius: 7px; font-size: 9px; }

/* ---------- Patient care ---------- */
.pi-shell { padding: 0; border: none; background: transparent; box-shadow: none; gap: 11px; }
.pi-hero {
  padding: 17px 18px;
  border-radius: var(--ui-radius);
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow);
}
.pi-eyebrow { font-size: 8px; letter-spacing: 0.12em; color: var(--ui-accent); }
.pi-hero h2 { font-size: 17px; font-weight: 650; letter-spacing: -0.025em; }
.pi-hero p { font-size: 10.5px; color: var(--text-secondary); line-height: 1.5; }
.pi-patient-chip { font-size: 9px; padding: 4px 8px; border-radius: 999px; background: var(--ui-accent-soft); color: var(--ui-accent); border: 1px solid color-mix(in srgb, var(--ui-accent) 18%, transparent); }
.pi-controls { gap: 8px; }
.pi-lang { border-radius: 8px; border: 1px solid var(--ui-border); background: var(--ui-surface-2); padding: 2px; }
.pi-lang button { font-size: 9px; border-radius: 6px; }
.pi-profile { border-radius: 11px; border: 1px solid var(--ui-border); background: var(--ui-surface); }
.pi-profile summary { font-size: 10.5px; padding: 9px 11px; }
.pi-profile-grid label { font-size: 9px; color: var(--text-muted); }
.pi-grid { gap: 8px; }
.pi-doc-card { border-radius: 11px; border: 1px solid var(--ui-border); background: var(--ui-surface); padding: 12px; }
.pi-doc-card h3 { font-size: 11.5px; }
.pi-doc-card p { font-size: 9.5px; color: var(--text-muted); }
.pi-footnote { font-size: 9px; color: var(--text-muted); border-top: 1px solid var(--ui-border); padding-top: 10px; }

/* ---------- Modals ---------- */
.modal-overlay {
  background: rgba(2, 5, 10, 0.62);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  padding: 18px;
}
.modal {
  padding: 20px 20px 18px;
  border-radius: 16px;
  border: 1px solid var(--ui-border-strong);
  background: var(--ui-surface);
  box-shadow: 0 40px 100px -20px rgba(0, 0, 0, 0.85);
  animation: uiModalIn 0.22s cubic-bezier(0.16, 1, 0.3, 1) both;
  max-height: calc(100vh - 36px);
  overflow-y: auto;
}
@keyframes uiModalIn { from { opacity: 0; transform: translateY(10px) scale(0.985); } to { opacity: 1; transform: none; } }
.modal h3, .modal-title { font-size: 16px; font-weight: 650; letter-spacing: -0.02em; }
.modal p, .modal-subtitle { font-size: 10.5px; color: var(--text-secondary); line-height: 1.55; }
.modal-header { padding-bottom: 12px; border-bottom: 1px solid var(--ui-border); }
.modal-body { padding: 14px 0; }
.modal-footer { padding-top: 12px; border-top: 1px solid var(--ui-border); gap: 7px; }
.modal-actions { gap: 7px; }
.btn-close { width: 28px; height: 28px; border-radius: 7px; border: 1px solid var(--ui-border); background: var(--ui-surface-2); color: var(--text-muted); display: inline-flex; align-items: center; justify-content: center; padding: 0; line-height: 1; font-size: 15px; }
.btn-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.cal-field-label { font-size: 8.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }
.cal-selected-patient { border-radius: 8px; background: var(--ui-accent-soft); border: 1px solid color-mix(in srgb, var(--ui-accent) 18%, transparent); font-size: 10px; }
.cal-patient-results { border-radius: 9px; border: 1px solid var(--ui-border); background: var(--ui-surface); }
.cal-patient-result { font-size: 10px; padding: 7px 9px; }
.cal-patient-result:hover { background: var(--bg-hover); }

/* ---------- Toasts ---------- */
#toastContainer, .toast-container { z-index: 10050; }
.toast {
  border-radius: 10px;
  border: 1px solid var(--ui-border-strong);
  background: var(--ui-surface);
  color: var(--text-primary);
  font-size: 10.5px;
  box-shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.7);
}

/* ---------- Auth screen ---------- */
.auth-screen-overlay {
  background:
    radial-gradient(900px 600px at 10% -10%, rgba(45, 212, 191, 0.10), transparent 60%),
    radial-gradient(800px 500px at 90% 0%, rgba(56, 189, 248, 0.08), transparent 55%),
    var(--bg-primary);
}
.auth-card {
  max-width: 430px;
  padding: 30px 28px;
  background: var(--ui-surface);
  border: 1px solid var(--ui-border-strong);
  border-radius: 18px;
  box-shadow: 0 40px 100px -30px rgba(0, 0, 0, 0.75);
  color: var(--text-primary);
}
.auth-brand-logo { height: 78px; }
.auth-brand-tagline { color: var(--text-muted); }
.auth-title { font-size: 20px; font-weight: 650; letter-spacing: -0.03em; color: var(--text-primary); }
.auth-subtitle { font-size: 10.5px; color: var(--text-muted); }
.auth-hardware-badge { font-size: 9px; border-radius: 8px; background: var(--ui-surface-2); border: 1px solid var(--ui-border); color: var(--text-muted); }
.auth-form .form-group label { font-size: 9px; color: var(--text-muted); }
.auth-form .form-input,
.auth-card input[type="text"],
.auth-card input[type="password"],
.auth-card input[type="email"] {
  background: var(--bg-input) !important;
  color: var(--text-primary) !important;
  border-color: var(--ui-border) !important;
  min-height: 40px;
  font-size: 12px;
}
.auth-card input::placeholder { color: var(--text-muted) !important; }
.auth-form .form-input:focus,
.auth-card input[type="text"]:focus,
.auth-card input[type="password"]:focus {
  border-color: var(--ui-accent) !important;
  box-shadow: 0 0 0 3px var(--ui-accent-soft) !important;
}
.btn-auth-submit { height: 42px; font-size: 12px; border-radius: 10px; }
.auth-footer-text { font-size: 9px; color: var(--text-muted); }
.auth-alert { border-radius: 9px; font-size: 10px; }

/* ---------- Command palette ---------- */
.ui-palette-overlay {
  position: fixed; inset: 0; z-index: 10060;
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 12vh;
  background: rgba(2, 5, 10, 0.62);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: uiFadeIn 0.18s ease both;
}
.ui-palette-overlay[hidden] { display: none !important; }
@keyframes uiFadeIn { from { opacity: 0; } to { opacity: 1; } }
.ui-palette {
  width: 600px; max-width: 92vw;
  background: var(--ui-surface);
  border: 1px solid var(--ui-border-strong);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 40px 100px -20px rgba(0, 0, 0, 0.85);
  animation: uiPaletteIn 0.22s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes uiPaletteIn { from { opacity: 0; transform: translateY(-8px) scale(0.99); } to { opacity: 1; transform: none; } }
.ui-palette-input-row { display: flex; align-items: center; gap: 9px; padding: 0 14px; height: 52px; border-bottom: 1px solid var(--ui-border); }
.ui-palette-input-row svg { width: 16px; height: 16px; color: var(--text-muted); }
.ui-palette-input-row input { flex: 1; background: none; border: none; box-shadow: none; outline: none; min-height: 0; padding: 0; color: var(--text-primary); font-size: 12px; }
.ui-palette-results { max-height: 380px; overflow-y: auto; padding: 5px; }
.ui-palette-section { padding: 9px 9px 4px; font-size: 7.5px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted); }
.ui-palette-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 8px; border-radius: 8px; cursor: pointer;
  color: var(--text-secondary); font-size: 10.5px;
}
.ui-palette-item.active { background: var(--ui-accent-soft); color: var(--text-primary); }
.ui-palette-item .ui-p-icon {
  width: 26px; height: 26px; flex: none; border-radius: 7px;
  display: grid; place-items: center;
  background: var(--ui-surface-2); border: 1px solid var(--ui-border); color: var(--text-muted);
}
.ui-palette-item .ui-p-icon svg { width: 14px; height: 14px; }
.ui-palette-item strong { font-weight: 600; color: inherit; }
.ui-palette-item .ui-p-meta { margin-left: auto; font-size: 8px; color: var(--text-muted); }
.ui-palette-foot { display: flex; align-items: center; gap: 14px; padding: 7px 13px; border-top: 1px solid var(--ui-border); font-size: 8px; color: var(--text-muted); }
.ui-palette-foot span { display: inline-flex; align-items: center; gap: 3px; }

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
  :root { --ui-sidebar-w: 228px; }
  body.is-electron .main-content, body:not(.is-electron) .main-content { padding-left: 20px; padding-right: 20px; }
  .ui-topbar { margin-left: -20px; margin-right: -20px; padding-left: 20px; padding-right: 20px; }
}
@media (max-width: 1120px) {
  :root { --ui-sidebar-w: 76px; }
  .app-brand-type, .nav-label, .nav-badge, .ui-nav-section, .sidebar-footer .nav-label,
  .sidebar-footer .sidebar-version-pill, .sidebar-user-profile { display: none; }
  .sidebar-header { padding: 14px 8px 9px; }
  .app-brand-lockup { justify-content: center; }
  .app-brand-wordmark { display: none; }
  .app-brand-mark { height: 34px; }
  .nav-item { justify-content: center; padding: 0; }
  .nav-icon { width: 32px; height: 32px; }
  .ui-nav-glider { left: 6px; right: 6px; }
  .theme-toggle { justify-content: center; padding: 0; }
  .ui-search-trigger { width: 36px; padding: 0; justify-content: center; }
  .ui-search-trigger span, .ui-search-trigger kbd { display: none; }
  .tabs.ui-tabs .tab { font-size: 10.5px; padding: 0 8px; }
}
@media (max-width: 1024px) {
  .patient-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .patient-kpi-grid { grid-template-columns: 1fr 1fr; }
  .ui-topbar .btn span { display: none; }
  .ui-topbar .btn { width: 34px; padding: 0; justify-content: center; }
  .calendar-layout { grid-template-columns: 1fr; }
  .finance-stats-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-height: 760px) {
  .sidebar-header { padding-top: 11px; padding-bottom: 8px; }
  .app-brand-mark { height: 27px; }
  .app-brand-wordmark { width: 120px; }
  .nav-item { height: 38px; }
  .ui-nav-glider { height: 38px; }
  .nav-icon { width: 26px; height: 26px; }
  .sidebar-footer { padding-top: 6px; padding-bottom: 8px; }
  .patient-executive-header { padding: 12px 14px; }
  .patient-avatar-monogram { width: 40px; height: 40px; }
  .patient-title-row h1 { font-size: 20px; }
  .tabs.ui-tabs .tab { height: 32px; }
}

/* ---------- Motion preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- Print ---------- */
@media print {
  .ui-topbar, .ui-palette-overlay, .ui-nav-glider { display: none !important; }
  body.is-electron .sidebar, body:not(.is-electron) .sidebar { display: none !important; }
  body.is-electron .main-content, body:not(.is-electron) .main-content {
    margin: 0 !important; padding: 0 !important; height: auto !important;
    border: none !important; border-radius: 0 !important;
  }
}

/* ---------- Noir app shell ---------- */
html[data-direction="noir"] {
  --ui-surface: #141417;
  --ui-surface-solid: #141417;
  --ui-surface-2: #0C0C0E;
  --ui-border: rgba(226, 177, 92, 0.12);
  --ui-border-strong: rgba(226, 177, 92, 0.24);
  --ui-text: #F7F2E8;
  --ui-text-2: #B8AE9C;
  --ui-text-3: #7E7669;
  --ui-accent: #E2B15C;
  --ui-accent-2: #C9923F;
  --ui-accent-soft: rgba(226, 177, 92, 0.12);
  --ui-accent-ring: rgba(226, 177, 92, 0.28);
  --ui-glow: rgba(226, 177, 92, 0.22);
  --ui-nav-active: rgba(226, 177, 92, 0.13);
  --ui-sidebar: #0A0A0C;
  --ui-sidebar-2: #111114;
  --ui-sidebar-border: rgba(226, 177, 92, 0.10);
  --ui-sidebar-text: #F7F2E8;
  --ui-sidebar-text-2: #B8AE9C;
  --ui-sidebar-text-3: #7E7669;
  --bg-primary: #070708;
  --bg-secondary: #0A0A0C;
  --bg-tertiary: #0C0C0E;
  --bg-card: #141417;
  --bg-card-hover: #19191D;
  --bg-input: #0A0A0C;
  --bg-hover: rgba(255, 255, 255, 0.055);
  --bg-sidebar: #0A0A0C;
  --text-primary: #F7F2E8;
  --text-secondary: #B8AE9C;
  --text-muted: #7E7669;
  --accent: #E2B15C;
  --accent-hover: #F0C77A;
  --accent-soft: rgba(226, 177, 92, 0.12);
  --accent-ring: rgba(226, 177, 92, 0.28);
  --accent-primary: #E2B15C;
  --accent-gold: #E2B15C;
  --accent-gold-soft: rgba(226, 177, 92, 0.14);
  --border-color: rgba(226, 177, 92, 0.12);
  --border-color-strong: rgba(226, 177, 92, 0.24);
}

/* Appointment status + clinic-colour badges (Calendar agenda and patient tab) */
.appt-clinic-badge,
.agenda-clinic-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid currentColor;
  font-size: 8.5px;
  font-weight: 600;
  line-height: 1.5;
  vertical-align: middle;
  white-space: nowrap;
}
.appt-clinic-badge i,
.agenda-clinic-badge i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex: none;
}
.appt-completed-badge,
.agenda-completed-tag {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--ui-accent) 32%, transparent);
  background: color-mix(in srgb, var(--ui-accent) 12%, transparent);
  color: var(--ui-accent);
  font-size: 8.5px;
  font-weight: 650;
  line-height: 1.5;
}
.appointment-card-completed { border-color: color-mix(in srgb, var(--ui-accent) 28%, transparent); }
.agenda-item-completed { border-color: color-mix(in srgb, var(--ui-accent) 24%, transparent); }
.agenda-btn-edit:hover,
.agenda-btn-complete:hover {
  color: var(--ui-accent);
  background: color-mix(in srgb, var(--ui-accent) 12%, transparent);
}

/* ===== v1.5.1: Sticky patient-form save bar — direction tints =====
   Geometry lives in styles.css (#page-add-patient > .page-header). The base
   --bg-primary surface is already opaque in all three directions, so these
   rules only tune the tone. Noir lifts to its raised #141417 surface so the
   gold hairline and soft shadow read against the near-black canvas; Porcelain
   and Atrium deliberately stay on the canvas tone to match the sticky topbar. */
html[data-direction="noir"] #page-add-patient > .page-header {
  background: var(--ui-surface, #141417);
}

/* ===== v1.5.1: Patient list current-archwire chips & Previous Visit cell ===== */
/* Markup: .prev-visit-cell > .prev-visit-wires > .patient-wire-chip.wire-u/.wire-l/.wire-none
   plus .patient-wire-date, rendered in Column 6 (Previous Visit) of #patientsTable. */
.prev-visit-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-width: 0;
}
.prev-visit-wires {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  min-width: 0;
  max-width: 100%;
}
.prev-visit-empty {
  color: var(--text-muted, var(--text-secondary));
  font-size: 10.5px;
  line-height: 1;
}
.patient-wire-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 8.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--ui-border, var(--border-color));
  line-height: 1.3;
  max-width: 196px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.patient-wire-tag {
  font-weight: 800;
  font-size: 7.5px;
  letter-spacing: 0.04em;
  opacity: 0.9;
}
.patient-wire-date {
  font-family: var(--ui-mono, 'Geist Mono', monospace);
  font-variant-numeric: tabular-nums;
  font-size: 8.5px;
  line-height: 1.25;
  letter-spacing: 0.01em;
  color: var(--text-muted, var(--text-secondary));
  white-space: nowrap;
}

/* Porcelain / light default: deep sky upper, rich amber lower. */
.patient-wire-chip.wire-u {
  color: #0369A1;
  background: rgba(3, 105, 161, 0.10);
  border-color: rgba(3, 105, 161, 0.30);
}
.patient-wire-chip.wire-l {
  color: #B45309;
  background: rgba(180, 83, 9, 0.10);
  border-color: rgba(180, 83, 9, 0.30);
}

/* Atrium (dark) chips — the html[data-theme="dark"] fallback also covers
   builds that only flip the theme attribute without the direction one. */
html[data-direction="atrium"] .patient-wire-chip.wire-u,
html[data-theme="dark"] .patient-wire-chip.wire-u {
  color: #38BDF8;
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.32);
}
html[data-direction="atrium"] .patient-wire-chip.wire-l,
html[data-theme="dark"] .patient-wire-chip.wire-l {
  color: #FBBF24;
  background: rgba(251, 191, 36, 0.12);
  border-color: rgba(251, 191, 36, 0.32);
}

/* Noir: adapted dark-gold treatment (upper stays a legible light sky).
   Declared after the [data-theme="dark"] pair on purpose so noir wins. */
html[data-direction="noir"] .patient-wire-chip.wire-u {
  color: #A5C8EC;
  background: rgba(165, 200, 236, 0.10);
  border-color: rgba(165, 200, 236, 0.30);
}
html[data-direction="noir"] .patient-wire-chip.wire-l {
  color: #E2B15C;
  background: rgba(226, 177, 92, 0.10);
  border-color: rgba(226, 177, 92, 0.32);
}

/* Combined U&L chip borrows the upper-arch tint. The base rule below is
   declared after both base chip rules so source order lands on the upper
   palette in Porcelain; the dark directions need their own combined rules
   because otherwise the later .wire-l direction rule would win there. */
.patient-wire-chip.wire-u.wire-l {
  color: #0369A1;
  background: rgba(3, 105, 161, 0.10);
  border-color: rgba(3, 105, 161, 0.30);
}
html[data-direction="atrium"] .patient-wire-chip.wire-u.wire-l,
html[data-theme="dark"] .patient-wire-chip.wire-u.wire-l {
  color: #38BDF8;
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.32);
}
html[data-direction="noir"] .patient-wire-chip.wire-u.wire-l {
  color: #A5C8EC;
  background: rgba(165, 200, 236, 0.10);
  border-color: rgba(165, 200, 236, 0.30);
}
.patient-wire-chip.wire-u.wire-l .patient-wire-tag {
  opacity: 1;
}

/* "No wire" stays intentionally quiet. */
.patient-wire-chip.wire-none {
  color: var(--text-muted, var(--text-secondary));
  background: color-mix(in srgb, var(--text-muted, #8A97A6) 8%, transparent);
  border-style: dashed;
  border-color: var(--ui-border-strong, var(--border-color));
}

/* ===== v1.5.1: Patient row right-click context menu ===== */
/* app.js appends #patientRowContextMenu to document.body with fixed left/top
   and toggles the [hidden] attribute, so these rules are intentionally global
   (no @scope, no page-descendant prefixing). Stacking: above the command
   palette (10060) and below #confirmModal (100000). */
#patientRowContextMenu.patient-context-menu {
  position: fixed;
  z-index: 10080;
  min-width: 216px;
  max-width: 320px;
  padding: 6px;
  border-radius: 12px;
  background: var(--ui-surface);
  border: 1px solid var(--ui-border-strong, var(--ui-border));
  box-shadow: var(--ui-shadow, 0 24px 60px -24px rgba(0, 0, 0, 0.55));
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-family: inherit;
}
#patientRowContextMenu.patient-context-menu[hidden] {
  display: none !important;
}
.patient-context-head {
  padding: 6px 10px 8px;
  border-bottom: 1px solid var(--ui-border, var(--border-color));
  margin-bottom: 2px;
}
.patient-context-name {
  color: var(--text-primary);
  font-size: 11px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.patient-context-meta {
  color: var(--text-secondary);
  font-size: 9px;
  margin-top: 2px;
}
.patient-context-wire {
  color: var(--ui-accent, var(--text-secondary));
  font-size: 9px;
  font-weight: 600;
  margin-top: 3px;
}
#patientRowContextMenu.patient-context-menu button[role="menuitem"] {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 500;
  line-height: 1.35;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
#patientRowContextMenu.patient-context-menu button[role="menuitem"]:hover,
#patientRowContextMenu.patient-context-menu button[role="menuitem"]:focus-visible {
  background: var(--bg-hover);
  color: var(--text-primary);
  outline: none;
}
/* Destructive action matches the app's --danger token (.btn-danger). */
#patientRowContextMenu.patient-context-menu button[role="menuitem"].danger {
  color: var(--danger, #E11D48);
}
#patientRowContextMenu.patient-context-menu button[role="menuitem"].danger:hover,
#patientRowContextMenu.patient-context-menu button[role="menuitem"].danger:focus-visible {
  background: var(--danger-soft, rgba(225, 29, 72, 0.12));
  color: var(--danger, #E11D48);
}
/* Active row highlight while the menu is open. */
#patientsTableBody tr.context-active {
  background: var(--bg-hover);
  box-shadow: inset 2px 0 0 var(--ui-accent);
}

