:root {
  --bg: #f8f9fb;
  --surface: #ffffff;
  --surface-alt: #fafafa;
  --surface-hover: #f4f4f5;
  --border: #e5e7eb;
  --border-subtle: #eff1f4;
  --border-strong: #d4d4d8;
  --text: #111827;
  --text-secondary: #3f3f46;
  --text-muted: #71717a;
  --text-faint: #a1a1aa;

  /* Crisp neutral obsidian primary (matching reference SaaS aesthetic) */
  --primary: #18181b;
  --primary-dark: #09090b;
  --primary-soft: #f4f4f5;
  --accent: #b45309;
  --accent-soft: #fffbeb;
  --ai: #4f46e5;
  --ai-soft: #f5f3ff;
  --ok: #15803d;
  --ok-soft: #f0fdf4;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --whatsapp: #15803d;
  --whatsapp-soft: #f0fdf4;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.03);
  --shadow-md: 0 8px 24px rgba(17, 24, 39, 0.08);
  --sidebar-w: 254px;
  --topbar-h: 64px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Malayalam", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.58;
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(9, 9, 11, 0.42);
  backdrop-filter: blur(2px);
  z-index: 38;
}
.sidebar-backdrop[hidden] {
  display: none;
}

/* Accessibility utilities */
.skip-link {
  position: absolute;
  top: -100px;
  left: 12px;
  background: var(--primary);
  color: #fff;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  z-index: 999;
  text-decoration: none;
  font-weight: 500;
}
.skip-link:focus {
  top: 12px;
}

.visually-hidden:where(:not(:focus-within, :active)) {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

/* App Layout */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100dvh;
  transition: grid-template-columns 0.18s ease;
}
.app-shell.sidebar-collapsed {
  grid-template-columns: 72px minmax(0, 1fr);
}
.app-shell.sidebar-collapsed .brand-text,
.app-shell.sidebar-collapsed .sidebar-search,
.app-shell.sidebar-collapsed .nav-section-label,
.app-shell.sidebar-collapsed .nav-item span:not(.nav-icon),
.app-shell.sidebar-collapsed .kcea-badge,
.app-shell.sidebar-collapsed #net-label {
  display: none;
}
.app-shell.sidebar-collapsed .nav-item {
  justify-content: center;
  padding: 10px 0;
}
.app-shell.sidebar-collapsed .sidebar-brand {
  justify-content: center;
  padding: 14px 10px;
}
.app-shell.sidebar-collapsed .desktop-collapse-btn {
  display: none;
}
.app-shell.sidebar-collapsed .brand-mark {
  cursor: pointer;
}

/* Crisp Light Sidebar (matching Nutri OS reference) */
.sidebar {
  background: var(--surface);
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  position: sticky;
  top: 0;
  border-right: 1px solid var(--border);
  z-index: 40;
}

.sidebar-brand {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  flex: 1;
  min-width: 0;
}
.brand-text strong {
  font-size: 0.96rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}
.brand-text span {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 400;
}

.sidebar-search {
  padding: 12px 14px 4px;
}
.sidebar-search input {
  width: 100%;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 7px 11px;
  font-size: 0.81rem;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.sidebar-search input::placeholder {
  color: var(--text-faint);
}
.sidebar-search input:focus {
  outline: none;
  background: #fff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(24, 24, 27, 0.06);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 6px 12px 20px;
}
.sidebar-nav::-webkit-scrollbar {
  width: 5px;
}
.sidebar-nav::-webkit-scrollbar-thumb {
  background: #e4e4e7;
  border-radius: 999px;
}

.nav-section-label {
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--text-muted);
  padding: 20px 10px 7px;
}
.nav-section-label:first-child {
  padding-top: 8px;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  margin-bottom: 3px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.91rem;
  font-weight: 500;
  letter-spacing: -0.005em;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
}
.nav-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.nav-item.active {
  background: #f4f4f5;
  border-color: #e4e4e7;
  color: var(--text);
  font-weight: 600;
}
.nav-item.nav-ai.active {
  background: #f5f3ff;
  border-color: #ddd6fe;
  color: #3730a3;
}
.nav-item.restricted {
  opacity: 0.45;
}

.nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--text-muted);
  transition: color 0.14s;
}
.nav-icon svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.nav-item:hover .nav-icon,
.nav-item.active .nav-icon {
  color: var(--text);
}
.nav-item.nav-ai .nav-icon {
  color: #6366f1;
}
.nav-item.nav-ai.active .nav-icon {
  color: #4338ca;
}

.nav-badge {
  margin-left: auto;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: #18181b;
  color: #ffffff;
  border: 1px solid #09090b;
  box-shadow: 0 2px 5px rgba(24, 24, 27, 0.22);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.16);
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.kcea-badge {
  font-size: 0.7rem;
  color: var(--text-faint);
  font-weight: 500;
}
.offline-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 7px;
  color: var(--text-secondary);
  font-weight: 500;
  transition: background 0.14s;
}
.offline-pill:hover {
  background: var(--surface-hover);
}
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.dot-ok { background: #16a34a; }
.dot-warn { background: #d97706; }
.dot-danger { background: #dc2626; }

/* Main area & Topbar */
.main-area {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  min-width: 0;
}

.topbar-page-title {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text);
  white-space: nowrap;
}
.topbar-page-title .nav-icon {
  color: var(--text-muted);
}

.global-search-box {
  position: relative;
  width: 100%;
  max-width: 310px;
}
.global-search-box input {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.83rem;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.global-search-box input::placeholder {
  color: var(--text-faint);
}
.global-search-box input:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(24, 24, 27, 0.06);
}
.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  max-height: 320px;
  overflow-y: auto;
  z-index: 60;
}
.search-hit {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
}
.search-hit:last-child { border-bottom: 0; }
.search-hit:hover { background: var(--surface-hover); }

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.select-compact {
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 500;
  font-family: inherit;
  max-width: 175px;
  transition: border-color 0.15s;
}
.select-compact:hover {
  border-color: var(--border-strong);
}
.select-compact:focus {
  outline: none;
  border-color: var(--primary);
}

.main-content {
  padding: 28px 34px 64px;
  max-width: 1460px;
  width: 100%;
  margin: 0 auto;
}

/* Crisp White Card Page Header (matching Patients header bar in screenshot) */
.page-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 26px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.page-header h1 {
  margin: 0;
  font-size: 1.38rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.page-header h1 > .badge {
  font-size: 0.74rem;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: 6px;
}
.page-subtitle {
  display: none;
}
.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

/* Buttons (Obsidian Primary + Crisp White Outline) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: -0.005em;
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s, color 0.14s, box-shadow 0.14s;
  font-family: inherit;
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: translateY(0.5px); }
.btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  pointer-events: none;
  box-shadow: none;
}
.btn-sm { padding: 8px 14px; font-size: 0.86rem; }
.btn-xs { padding: 6px 11px; font-size: 0.81rem; border-radius: 7px; }

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}
.btn-primary:hover {
  background: #27272a;
  border-color: #27272a;
}

.btn-ai {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}
.btn-ai:hover {
  background: #27272a;
}

.btn-whatsapp {
  background: #15803d;
  color: #ffffff;
  border-color: #15803d;
}
.btn-whatsapp:hover {
  background: #166534;
}

.btn-outline {
  background: #ffffff;
  color: var(--text);
  border-color: var(--border);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.02);
}
.btn-outline:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #fecaca;
}
.btn-danger:hover {
  background: #fee2e2;
}

.btn-soft {
  background: #f4f4f5;
  color: var(--text);
  border-color: #e4e4e7;
}
.btn-soft:hover {
  background: #e4e4e7;
}

.icon-btn {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.9rem;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
}
.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--border-strong);
}

/* Cards & Grids */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 26px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.card-header h2, .card-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}
.kpi-grid-6 {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}
.kpi-grid-6 .kpi-card {
  padding: 15px 17px;
  gap: 6px;
  border-radius: 10px;
}
.kpi-grid-6 .kpi-label {
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi-grid-6 .kpi-value {
  font-size: 1.42rem;
  letter-spacing: -0.02em;
}
.kpi-grid-6 .kpi-meta {
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Patient EMR Table Row Numbering, Action Grid & Pagination */
.row-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  border-radius: 7px;
  background: #f4f4f5;
  color: #52525b;
  font-size: 0.8rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.link-btn {
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.link-btn:hover {
  text-decoration: underline;
}
.pt-action-grid,
.appt-action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(90px, auto));
  gap: 6px;
  justify-content: end;
}
.table-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 20px;
  border-top: 1px solid var(--border-subtle);
  background: var(--surface);
}
.pagination-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}
.page-btn {
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
}
.page-btn:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-strong);
  color: var(--text);
}
.page-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  font-weight: 600;
}
.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.kpi-label {
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--text-muted);
}
.kpi-value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text);
  line-height: 1.2;
}
.kpi-meta {
  font-size: 0.83rem;
  color: var(--text-muted);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 22px;
}
.grid-sidebar-split {
  display: grid;
  grid-template-columns: 350px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

/* Solid Filled Badges & Pills with White Text & Elevation Shadow */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  color: #ffffff;
  border: 1px solid transparent;
  box-shadow: 0 2px 6px rgba(17, 24, 39, 0.18);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.16);
}
.badge-primary { background: #18181b; border-color: #09090b; color: #ffffff; box-shadow: 0 2px 6px rgba(24, 24, 27, 0.26); }
.badge-ok { background: #16a34a; border-color: #15803d; color: #ffffff; box-shadow: 0 2px 6px rgba(22, 163, 74, 0.28); }
.badge-warn { background: #d97706; border-color: #b45309; color: #ffffff; box-shadow: 0 2px 6px rgba(217, 119, 6, 0.28); }
.badge-danger { background: #dc2626; border-color: #b91c1c; color: #ffffff; box-shadow: 0 2px 6px rgba(220, 38, 38, 0.3); }
.badge-ai { background: #4f46e5; border-color: #4338ca; color: #ffffff; box-shadow: 0 2px 6px rgba(79, 70, 229, 0.28); }
.badge-gold { background: #b45309; border-color: #92400e; color: #ffffff; box-shadow: 0 2px 6px rgba(180, 83, 9, 0.28); }
.badge-wa { background: #15803d; border-color: #166534; color: #ffffff; box-shadow: 0 2px 6px rgba(21, 128, 61, 0.28); }
.badge-neutral { background: #52525b; border-color: #3f3f46; color: #ffffff; box-shadow: 0 2px 6px rgba(82, 82, 91, 0.24); }
.badge-sm {
  font-size: 0.68rem;
  padding: 2px 7px;
  line-height: 1.25;
  box-shadow: 0 1px 4px rgba(17, 24, 39, 0.16);
}
.cell-stack {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}
.action-stack-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  width: 122px;
}
.action-stack-2 .btn {
  width: 100%;
  justify-content: center;
}
.portal-support-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 8px;
}
.support-chip {
  padding: 11px 13px;
  background: var(--surface-alt);
  border: 1px solid var(--border-subtle);
  border-radius: 9px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.support-chip-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.support-chip-val {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}

/* Clean Semantic Plain Text Inside All Data Tables (No Colored Boxes) */
.data-table .badge {
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  text-shadow: none !important;
  padding: 0 !important;
  border-radius: 0 !important;
  font-size: 0.85rem;
  font-weight: 600;
}
.data-table .badge-primary { color: #18181b !important; }
.data-table .badge-ok,
.data-table .badge-wa { color: #15803d !important; }
.data-table .badge-warn,
.data-table .badge-gold { color: #b45309 !important; }
.data-table .badge-danger { color: #dc2626 !important; }
.data-table .badge-ai { color: #4f46e5 !important; }
.data-table .badge-neutral { color: #52525b !important; }

/* Universal Table Filter Toolbar & Pagination */
.auto-table-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: #fafafa;
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
}
.auto-table-bar + .table-wrapper {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}
.table-wrapper.has-auto-pager {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}
.auto-table-pager {
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
}
.auto-table-search {
  flex: 1;
  min-width: 190px;
  max-width: 320px;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text);
  font-family: inherit;
  font-size: 0.84rem;
}
.auto-table-search:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(24, 24, 27, 0.06);
}
.auto-table-count {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Plain Text Status Indicators (no colored boxes) */
.text-status-ok { color: #15803d; font-weight: 600; font-size: 0.86rem; }
.text-status-danger { color: #dc2626; font-weight: 600; font-size: 0.86rem; }
.text-status-warn { color: #b45309; font-weight: 600; font-size: 0.86rem; }
.text-status-dark { color: #18181b; font-weight: 600; font-size: 0.86rem; }
.text-status-subtle { color: #71717a; font-weight: 500; font-size: 0.78rem; margin-top: 2px; }

/* Uniform Icon Action Buttons with Hover Tooltip */
.icon-action-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}
.btn-start {
  height: 36px;
  min-height: 36px !important;
  padding: 0 14px;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: 8px;
}
.icon-action-btn {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: #18181b;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
}
.icon-action-btn:hover:not(:disabled),
.icon-action-btn:focus-visible:not(:disabled) {
  background: #f4f4f5;
  border-color: #a1a1aa;
}
.icon-action-btn.icon-action-primary {
  background: #18181b;
  border-color: #18181b;
  color: #ffffff;
}
.icon-action-btn.icon-action-primary:hover:not(:disabled),
.icon-action-btn.icon-action-primary:focus-visible:not(:disabled) {
  background: #27272a;
  border-color: #27272a;
}
.icon-action-btn:disabled {
  background: #f4f4f5;
  border-color: #e4e4e7;
  color: #a1a1aa;
  opacity: 0.55;
  cursor: not-allowed;
}
.icon-action-btn::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%) translateY(3px);
  background: #18181b;
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 500;
  padding: 4px 9px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  z-index: 20;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.16);
  transition: opacity 0.14s ease, transform 0.14s ease;
}
.icon-action-btn:hover::after,
.icon-action-btn:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
tbody tr:first-child .icon-action-btn::after {
  bottom: auto;
  top: calc(100% + 7px);
  transform: translateX(-50%) translateY(-3px);
}
tbody tr:first-child .icon-action-btn:hover::after,
tbody tr:first-child .icon-action-btn:focus-visible::after {
  transform: translateX(-50%) translateY(0);
}

/* Banners */
.banner {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid;
  font-size: 0.84rem;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.banner-ai {
  background: #fafafa;
  border-color: var(--border);
  color: var(--text-secondary);
}
.banner-warn {
  background: var(--warn-soft);
  border-color: #fde68a;
  color: #78350f;
}
.banner-info {
  background: #fafafa;
  border-color: var(--border);
  color: var(--text-secondary);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  overflow-x: auto;
}
.tab-btn {
  padding: 9px 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}
.tab-btn.active {
  color: var(--text);
  font-weight: 600;
  border-bottom-color: var(--primary);
}

/* Responsive Data Tables (spacious Nutri OS density + modern-web-guidance responsive-table) */
.table-wrapper {
  overflow: auto;
  max-inline-size: 100%;
  max-block-size: min(560px, 72vh);
  container-type: inline-size;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.table-wrapper:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.92rem;
}
.data-table caption {
  text-align: left;
  font-size: 0.83rem;
  color: var(--text-muted);
  padding: 13px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border-subtle);
  font-weight: 500;
}
.data-table thead {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
}
.data-table thead th {
  background: #fafafa;
  color: var(--text-muted);
  text-align: left;
  font-size: 0.84rem;
  font-weight: 500;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table tbody th {
  position: sticky;
  inset-inline-start: 0;
  background: var(--surface);
  text-align: left;
  font-weight: 600;
  color: var(--text);
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-subtle);
  line-height: 1.55;
  z-index: 1;
}
.data-table tbody td {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  vertical-align: middle;
  line-height: 1.55;
}
.data-table tbody tr:last-child td,
.data-table tbody tr:last-child th {
  border-bottom: 0;
}
.data-table tbody tr:hover td,
.data-table tbody tr:hover th {
  background: #fafafa;
}

/* Keep tables as true horizontally scrollable tables on mobile & compact containers */
.table-wrapper {
  -webkit-overflow-scrolling: touch;
}
@container (width < 640px) {
  .data-table {
    min-width: 640px;
    font-size: 0.84rem;
  }
  .data-table thead th {
    padding: 11px 13px;
    font-size: 0.78rem;
  }
  .data-table tbody th {
    position: static;
    padding: 12px 13px;
  }
  .data-table tbody td {
    padding: 12px 13px;
  }
}

/* Forms & Validation (per modern-web-guidance validate-input-after-interaction) */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 18px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field.span-2 {
  grid-column: span 2;
}
.field label {
  font-size: 0.87rem;
  font-weight: 500;
  color: var(--text);
}
.hint {
  display: block;
  color: var(--text-muted);
  font-size: 0.8rem;
}
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.91rem;
  background: #ffffff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input::placeholder,
.field textarea::placeholder {
  color: var(--text-faint);
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(24, 24, 27, 0.07);
}
.error-msg {
  display: none;
  color: var(--danger);
  font-size: 0.77rem;
  font-weight: 500;
}
:is(input, select, textarea):is(:user-invalid, .user-invalid-fallback) {
  border-color: var(--danger);
  background-color: #fff8f8;
}
:is(input, select, textarea):is(:user-invalid, .user-invalid-fallback) + .error-msg {
  display: block;
}
:is(input, select, textarea):user-valid {
  border-color: #16a34a;
}

/* Native Modal Dialogs (per modern-web-guidance dialog & light-dismiss-a-dialog) */
dialog:modal {
  overscroll-behavior: contain;
}
dialog::backdrop {
  background: rgba(9, 9, 11, 0.45);
  backdrop-filter: blur(2px);
  overflow: hidden;
  overscroll-behavior: contain;
}
.app-dialog {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0;
  width: min(760px, 94vw);
  max-height: 90dvh;
  box-shadow: 0 24px 64px rgba(9, 9, 11, 0.2);
  background: var(--surface);
  color: var(--text);
  overflow: hidden;
}
.app-dialog[open] {
  display: flex;
  flex-direction: column;
}
.app-dialog-wide {
  width: min(920px, 95vw);
}
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--surface);
  flex-shrink: 0;
}
.dialog-title {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.dialog-body {
  padding: 26px 28px 30px;
  overflow-y: auto;
  line-height: 1.55;
}
.dialog-body .form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px 22px;
}
.dialog-body .field {
  gap: 7px;
}
.dialog-body .field input,
.dialog-body .field select,
.dialog-body .field textarea {
  padding: 11px 14px;
}
.dialog-body form > .between.mt-3,
.dialog-body form > .flex.mt-3,
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid var(--border-subtle);
}
.modal-stack {
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.modal-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 16px 18px;
  background: #fafafa;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
}
.modal-hero-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: auto;
}
.modal-kv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 18px;
}
.modal-kv {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 13px 15px;
  background: #fafafa;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
}
.modal-kv.span-2 {
  grid-column: span 2;
}
.modal-kv-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.modal-kv-val {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.45;
}
.modal-section {
  padding-top: 18px;
  border-top: 1px solid var(--border-subtle);
}
.modal-doc-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.83rem;
  font-weight: 500;
  color: var(--text);
}

/* Minimalist Monochrome Clinical AI Styles */
.ai-note {
  margin: 4px 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.ai-pill-mono {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: #f4f4f5;
  border: 1px solid #e4e4e7;
  color: #27272a;
  font-size: 0.76rem;
  font-weight: 600;
}
.ai-pill-dark {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  background: #27272a;
  color: #e4e4e7;
  font-size: 0.72rem;
  font-weight: 600;
}
.ai-kv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.ai-kv {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 13px 15px;
  background: #fafafa;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
}
.ai-kv-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.ai-kv-val {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.45;
}
.ai-brief {
  padding: 15px 17px;
  background: #fafafa;
  border: 1px solid var(--border-subtle);
  border-left: 3px solid #18181b;
  border-radius: 10px;
}
.ai-brief p {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text-secondary);
}
.ai-trend-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ai-trend-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px 15px;
  background: #ffffff;
}
.ai-trend-card.is-flagged {
  border-color: #a1a1aa;
  background: #fafafa;
}
.ai-row-flagged td,
.ai-row-flagged th {
  background: #fafafa !important;
}
.ai-flag-text {
  font-size: 0.76rem;
  font-weight: 600;
  color: #18181b;
  margin-top: 3px;
}
.ai-text-strong {
  font-weight: 600;
  color: #18181b;
}
.ai-prompt-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

/* Fullscreen Token Queue TV Dialog */
.tv-dialog {
  border: 0;
  padding: 0;
  width: 98vw;
  max-width: 98vw;
  height: 94dvh;
  max-height: 94dvh;
  border-radius: 14px;
  background: #09090b;
  color: #fafafa;
  overflow: hidden;
}
.tv-dialog[open] {
  display: flex;
  flex-direction: column;
}
.tv-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  background: #18181b;
  border-bottom: 1px solid #27272a;
}
.tv-header h1 { margin: 0; font-size: 1.35rem; font-weight: 600; letter-spacing: -0.02em; }
.tv-header p { margin: 4px 0 0; color: #a1a1aa; font-size: 0.9rem; }
.tv-header-right { display: flex; align-items: center; gap: 16px; }
.tv-clock { font-family: var(--font-mono); font-size: 1.3rem; font-weight: 600; color: #fafafa; }
.tv-board-body {
  flex: 1;
  padding: 26px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 20px;
  overflow-y: auto;
}
.tv-room-card {
  background: #18181b;
  border: 1px solid #27272a;
  border-radius: 14px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.tv-token-big {
  font-size: 3.6rem;
  font-weight: 700;
  color: #ffffff;
  font-family: var(--font-mono);
  line-height: 1.05;
  margin: 12px 0;
  letter-spacing: -0.03em;
}
.tv-ticker {
  background: #18181b;
  border-top: 1px solid #27272a;
  color: #d4d4d8;
  padding: 12px 24px;
  font-size: 0.88rem;
  font-weight: 500;
}

/* Toolbars & Inline Inputs */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.input-inline {
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: inherit;
  background: #ffffff;
  color: var(--text);
}
.input-inline::placeholder {
  color: var(--text-faint);
}
.input-inline:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(24, 24, 27, 0.06);
}

/* Redesigned OPD Active Patient Profile Card */
.opd-patient-card {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.section-kicker {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.patient-identity-box {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  background: var(--surface-alt);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
}
.patient-avatar {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: #18181b;
  color: #ffffff;
  font-size: 0.92rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}
.patient-identity-meta {
  min-width: 0;
  flex: 1;
}
.patient-identity-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.25;
}
.patient-identity-sub {
  font-size: 0.84rem;
  color: var(--text-secondary);
  margin-top: 2px;
}
.patient-identity-ids {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 5px;
  word-break: break-word;
}
.patient-meta-section {
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
}
.history-paragraph {
  margin: 0;
  padding: 12px 14px;
  background: #fafafa;
  border: 1px solid var(--border-subtle);
  border-left: 3px solid #18181b;
  border-radius: 8px;
  font-size: 0.88rem;
  line-height: 1.65;
  color: var(--text-secondary);
}
.consult-timeline-item {
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #ffffff;
  margin-bottom: 10px;
}
.consult-timeline-item:last-child {
  margin-bottom: 0;
}
.consult-date {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}
.consult-bp {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: #f4f4f5;
  padding: 2px 8px;
  border-radius: 6px;
}
.consult-dx {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  margin-bottom: 5px;
}
.consult-plan {
  margin: 0;
  font-size: 0.83rem;
  line-height: 1.55;
  color: var(--text-muted);
}

/* =========================================================================
   BLACK & GREY APPOINTMENT TIMELINE CALENDAR
   ========================================================================= */
.appt-summary-strip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  padding: 16px 0;
  margin-bottom: 18px;
}
.appt-stat {
  padding: 2px 20px;
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.appt-stat:last-child {
  border-right: 0;
}
.appt-stat-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
}
.appt-stat-val {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.cal-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.cal-legend {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-left: 6px;
}
.cal-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.cal-swatch {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 3px;
}
.cal-sw-black { background: #18181b; }
.cal-sw-charcoal { background: #52525b; }
.cal-sw-break { background: #e4e4e7; border: 1px solid #d4d4d8; }
.cal-sw-muted { background: #a1a1aa; }

.cal-timeline-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 22px;
}
.cal-day-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
  box-shadow: var(--shadow-sm);
}
.cal-day-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.cal-day-title {
  font-size: 1.02rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.015em;
}
.cal-status-chip {
  font-size: 0.74rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
}
.cal-chip-dark {
  background: #18181b;
  color: #ffffff;
}
.cal-chip-grey {
  background: #e4e4e7;
  color: #27272a;
}
.cal-chip-light {
  background: #f4f4f5;
  color: #52525b;
  border: 1px solid #e4e4e7;
}

.cal-day-row {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) 92px 84px;
  align-items: end;
  gap: 18px;
}
.cal-side-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-bottom: 4px;
}
.cal-side-divider {
  border-left: 1px solid var(--border-subtle);
  padding-left: 16px;
}
.cal-side-label {
  font-size: 0.73rem;
  color: var(--text-muted);
  font-weight: 500;
}
.cal-side-val {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.cal-timeline-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.cal-ruler {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  user-select: none;
}
.cal-track {
  position: relative;
  height: 36px;
  background: #f4f4f5;
  border: 1px solid #e4e4e7;
  border-radius: 8px;
  overflow: hidden;
}
.cal-seg {
  position: absolute;
  top: 3px;
  bottom: 3px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  font-size: 0.73rem;
  font-weight: 600;
  font-family: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 0;
  transition: filter 0.14s, transform 0.1s;
}
button.cal-seg {
  cursor: pointer;
}
button.cal-seg:hover {
  filter: brightness(1.12);
  z-index: 3;
}
.cal-seg-black {
  background: #18181b;
  color: #ffffff;
  border-left: 2px solid #09090b;
  border-right: 2px solid #09090b;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}
.cal-seg-charcoal {
  background: #52525b;
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14);
}
.cal-seg-muted {
  background: #a1a1aa;
  color: #ffffff;
}
.cal-seg-break {
  background: #e4e4e7;
  color: #52525b;
  border: 1px solid #d4d4d8;
}
.cal-seg-off {
  background: #d4d4d8;
  color: #27272a;
}

/* =========================================================================
   5-DAY VERTICAL TIME-GRID CALENDAR (BLACK & GREY MONOCHROME)
   ========================================================================= */
.wcal-shell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.wcal-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-subtle);
}
.wcal-topbar-left,
.wcal-topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.wcal-month-title {
  font-size: 1.06rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}
.wcal-week-pill {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  background: #f4f4f5;
  border: 1px solid #e4e4e7;
  padding: 3px 10px;
  border-radius: 999px;
}

.wcal-filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 11px 20px;
  border-bottom: 1px solid var(--border);
  background: #fafafa;
}
.wcal-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid #e4e4e7;
  background: #ffffff;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s, color 0.14s;
}
.wcal-filter-chip:hover {
  background: #f4f4f5;
  border-color: #d4d4d8;
}
.wcal-filter-chip.active {
  background: #18181b;
  border-color: #18181b;
  color: #ffffff;
}
.wcal-filter-chip.active .wcal-dot {
  background: #ffffff;
}
.wcal-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.wcal-dot-black { background: #18181b; }
.wcal-dot-charcoal { background: #52525b; }
.wcal-dot-slate { background: #71717a; }
.wcal-dot-muted { background: #a1a1aa; }

.wcal-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.wcal-grid {
  min-width: calc(74px + var(--cal-cols, 5) * 195px);
}
.wcal-head-row {
  display: grid;
  grid-template-columns: 74px repeat(var(--cal-cols, 5), minmax(195px, 1fr));
  border-bottom: 1px solid var(--border);
  background: #ffffff;
  position: sticky;
  top: 0;
  z-index: 4;
}
.wcal-corner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 6px;
  border-right: 1px solid var(--border-subtle);
}
.wcal-mini-nav {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.wcal-mini-nav:hover {
  background: #f4f4f5;
  color: var(--text);
}
.wcal-day-head {
  padding: 10px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--border-subtle);
}
.wcal-day-head:last-child {
  border-right: 0;
}
.wcal-day-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 9px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  width: 100%;
  max-width: 190px;
}
.wcal-day-pill.is-today {
  background: #18181b;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(24, 24, 27, 0.22);
}
.wcal-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: #f4f4f5;
  color: #52525b;
  font-size: 0.72rem;
  font-weight: 600;
}
.wcal-day-pill.is-today .wcal-count {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

.wcal-body-row {
  display: grid;
  grid-template-columns: 74px repeat(var(--cal-cols, 5), minmax(195px, 1fr));
}
.wcal-time-axis {
  position: relative;
  border-right: 1px solid var(--border-subtle);
  background: #ffffff;
}
.wcal-time-cell {
  position: absolute;
  left: 0;
  right: 10px;
  text-align: right;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  padding-top: 6px;
  user-select: none;
}
.wcal-now-badge {
  position: absolute;
  left: 8px;
  transform: translateY(-50%);
  background: #18181b;
  color: #ffffff;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 5px;
  z-index: 3;
}

.wcal-day-col {
  position: relative;
  border-right: 1px solid var(--border-subtle);
  background: #ffffff;
}
.wcal-day-col:last-child {
  border-right: 0;
}
.wcal-day-col.is-today-col {
  background: #fcfcfd;
}
.wcal-grid-slot {
  border-bottom: 1px solid #f1f2f5;
  cursor: pointer;
  transition: background 0.12s;
}
.wcal-grid-slot:hover {
  background: #f4f4f5;
}
.wcal-now-line {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1.5px dashed #18181b;
  z-index: 2;
  pointer-events: none;
}

/* Monochrome Black & Grey Appointment Event Cards */
.wcal-event {
  position: absolute;
  left: 6px;
  right: 6px;
  border-radius: 9px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-align: left;
  font-family: inherit;
  cursor: pointer;
  z-index: 3;
  transition: transform 0.12s, box-shadow 0.14s, border-color 0.14s;
  overflow: hidden;
}
.wcal-event:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(24, 24, 27, 0.12);
  z-index: 5;
}
.wcal-ev-black {
  background: #ffffff;
  border: 1px solid #e4e4e7;
  border-left: 3.5px solid #18181b;
  color: #111827;
}
.wcal-ev-charcoal {
  background: #f7f7f8;
  border: 1px solid #d4d4d8;
  border-left: 3.5px solid #3f3f46;
  color: #18181b;
}
.wcal-ev-slate {
  background: #f4f4f5;
  border: 1px solid #d4d4d8;
  border-left: 3.5px solid #71717a;
  color: #18181b;
}
.wcal-ev-muted {
  background: #fafafa;
  border: 1px dashed #a1a1aa;
  border-left: 3.5px solid #a1a1aa;
  color: #3f3f46;
}

.wcal-ev-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.wcal-ev-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: #111827;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wcal-tag {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}
.wcal-tag-dark {
  background: #18181b;
  color: #ffffff;
}
.wcal-tag-grey {
  background: #e4e4e7;
  color: #27272a;
}
.wcal-ev-time {
  font-size: 0.72rem;
  color: #52525b;
  font-weight: 500;
}
.wcal-ev-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.wcal-ev-doc {
  font-size: 0.7rem;
  color: #71717a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wcal-ev-dot {
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: #18181b;
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.wcal-ev-charcoal .wcal-ev-dot { background: #3f3f46; }
.wcal-ev-slate .wcal-ev-dot { background: #71717a; }
.wcal-ev-muted .wcal-ev-dot { background: #a1a1aa; }

/* Token Cards */
.token-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-sm);
}
.token-card.serving {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}
.token-number {
  font-family: var(--font-mono);
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

/* WhatsApp Chat Simulator */
.wa-phone {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #f4f4f5;
  display: flex;
  flex-direction: column;
  height: 510px;
  box-shadow: var(--shadow-sm);
}
.wa-header {
  background: #18181b;
  color: #ffffff;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.wa-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.wa-bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.85rem;
  line-height: 1.5;
  white-space: pre-wrap;
  border: 1px solid var(--border);
}
.wa-in {
  align-self: flex-start;
  background: #ffffff;
  border-top-left-radius: 3px;
}
.wa-out {
  align-self: flex-end;
  background: #18181b;
  color: #ffffff;
  border-color: #18181b;
  border-top-right-radius: 3px;
}
.wa-out .wa-time {
  color: #a1a1aa;
}
.wa-time {
  display: block;
  font-size: 0.68rem;
  color: var(--text-faint);
  text-align: right;
  margin-top: 4px;
}
.wa-input-row {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: #ffffff;
  border-top: 1px solid var(--border);
}
.wa-input-row input {
  flex: 1;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  font-family: inherit;
}
.wa-input-row input:focus {
  outline: none;
  border-color: var(--primary);
}

/* Patient Portal Frame */
.portal-shell {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.portal-hero {
  background: #18181b;
  color: #ffffff;
  padding: 22px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

/* AI Prescription Canvas */
.rx-canvas-box {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: #fafafa;
  padding: 14px;
  text-align: center;
}
.rx-canvas-box canvas {
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
}

/* Charts */
.chart-box {
  width: 100%;
  overflow-x: auto;
}
.chart-legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 8px;
}

/* Printable Documents */
.print-canvas {
  padding: 22px 26px;
  overflow-y: auto;
  background: #ffffff;
}
.doc-sheet {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 26px;
  background: #ffffff;
  color: #111827;
}
.doc-letterhead {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid #18181b;
  padding-bottom: 14px;
  margin-bottom: 18px;
  gap: 12px;
}
.doc-letterhead h2 { margin: 0; color: #111827; font-weight: 600; letter-spacing: -0.02em; }
.doc-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 20px;
  font-size: 0.85rem;
  margin-bottom: 18px;
  padding: 12px 14px;
  background: #fafafa;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}
.toast {
  background: #18181b;
  color: #ffffff;
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  font-size: 0.84rem;
  font-weight: 500;
  border-left: 3px solid #22c55e;
  animation: toastIn 0.18s ease-out;
}
.toast.toast-warn { border-left-color: #f59e0b; }
.toast.toast-danger { border-left-color: #ef4444; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Misc utilities */
.muted { color: var(--text-muted); }
.mono { font-family: var(--font-mono); }
.text-right { text-align: right; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 20px; }
.mb-2 { margin-bottom: 14px; }
.flex { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.mobile-only { display: none; }

/* =========================================================================
   RESPONSIVE ARCHITECTURE
   High-Res Mac / 4K (>=1800px, >=2400px) · Small Mac (1024–1366px)
   iPad & Tablet Portrait/Landscape (768–1023px) · iPhone & Android (<=767px)
   ========================================================================= */

/* High-Resolution Desktop / 27" Studio Display / 4K */
@media (min-width: 1800px) {
  :root {
    --sidebar-w: 280px;
    --topbar-h: 68px;
  }
  html, body {
    font-size: 17px;
  }
  .topbar {
    padding: 0 36px;
  }
  .global-search-box {
    max-width: 380px;
  }
  .main-content {
    max-width: 1780px;
    padding: 34px 44px 72px;
  }
  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(245px, 1fr));
    gap: 22px;
  }
  .kpi-grid-6 {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 14px;
  }
  .card {
    padding: 28px 30px;
  }
}

@media (min-width: 2400px) {
  :root {
    --sidebar-w: 300px;
  }
  html, body {
    font-size: 18px;
  }
  .main-content {
    max-width: 2120px;
    padding: 40px 56px 84px;
  }
}

/* Smaller MacBook Resolutions (1280x800, 1366x768) & iPad Pro Landscape */
@media (max-width: 1366px) {
  :root {
    --sidebar-w: 232px;
  }
  .topbar {
    padding: 0 18px;
    gap: 10px;
  }
  .topbar-left {
    gap: 12px;
  }
  .global-search-box {
    max-width: 225px;
  }
  .select-compact {
    max-width: 148px;
    font-size: 0.8rem;
  }
  .main-content {
    padding: 22px 24px 52px;
  }
  .grid-sidebar-split {
    grid-template-columns: 290px minmax(0, 1fr);
    gap: 18px;
  }
}

/* Compact Laptop / iPad Landscape (1024px–1180px) */
@media (max-width: 1180px) {
  :root {
    --sidebar-w: 218px;
  }
  .global-search-box {
    max-width: 185px;
  }
  .grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .topbar-controls {
    gap: 6px;
  }
  .topbar .btn-sm {
    padding: 7px 10px;
    font-size: 0.8rem;
  }
}

/* Tablets & iPad Portrait (<= 1023px): Slide-Over Drawer Navigation */
@media (max-width: 1023px) {
  .app-shell,
  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(290px, 84vw);
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    transform: translateX(-100%);
    transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 50;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 12px 0 36px rgba(9, 9, 11, 0.2);
  }
  .mobile-only { display: inline-flex; }
  .desktop-collapse-btn { display: none; }

  .topbar {
    height: auto;
    min-height: var(--topbar-h);
    padding: calc(10px + env(safe-area-inset-top)) 18px 10px;
    flex-wrap: wrap;
    gap: 10px;
  }
  .topbar-left {
    flex: 1 1 auto;
  }
  .global-search-box {
    max-width: 240px;
  }
  .main-content {
    padding: 20px 20px calc(48px + env(safe-area-inset-bottom));
  }
  .grid-sidebar-split {
    grid-template-columns: 1fr;
  }
  .grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
  }
  .grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
  }
  .kpi-grid-6 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
  }
  .appt-summary-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    row-gap: 14px;
  }
  .cal-day-row {
    grid-template-columns: 76px minmax(0, 1fr) 76px 72px;
    gap: 12px;
  }
}

/* Mobile Phones — iPhone (375–430px) & Android (360–412px) */
@media (max-width: 767px) {
  html, body {
    font-size: 16px;
  }
  .topbar {
    padding: calc(10px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) 10px calc(14px + env(safe-area-inset-left));
    gap: 10px;
  }
  .topbar-left {
    width: 100%;
    flex-wrap: wrap;
    gap: 10px;
  }
  .topbar-page-title {
    font-size: 1rem;
    flex: 1;
    min-width: 0;
  }
  .global-search-box {
    order: 3;
    flex: 1 1 100%;
    max-width: none;
  }
  .topbar-controls {
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
    gap: 8px;
  }
  .topbar-controls::-webkit-scrollbar {
    display: none;
  }
  .topbar-controls > * {
    flex-shrink: 0;
  }
  .select-compact {
    max-width: 150px;
  }

  /* Prevent iOS Safari input auto-zoom (requires >= 16px) & ensure 44px touch targets */
  input, select, textarea {
    font-size: 16px !important;
  }
  .btn, .icon-btn, .nav-item, .select-compact {
    min-height: 42px;
  }
  .btn-xs {
    min-height: 36px;
    padding: 6px 12px;
  }
  .icon-btn {
    width: 40px;
    height: 40px;
  }

  .main-content {
    padding: 16px calc(14px + env(safe-area-inset-right)) calc(44px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
  }
  .page-header {
    padding: 16px 16px;
    margin-bottom: 16px;
    gap: 12px;
  }
  .page-header h1 {
    font-size: 1.2rem;
  }
  .header-actions {
    width: 100%;
  }
  .header-actions .btn,
  .header-actions select {
    flex: 1 1 auto;
  }

  .card {
    padding: 16px 16px;
    margin-bottom: 16px;
    border-radius: 12px;
  }
  .card-header {
    margin-bottom: 14px;
  }

  .kpi-grid,
  .kpi-grid-6 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
  }
  .pt-action-grid,
  .appt-action-grid {
    grid-template-columns: repeat(2, 1fr);
    width: 100%;
  }
  .action-stack-2 {
    width: 100%;
    grid-template-columns: repeat(2, 1fr);
  }
  .portal-support-grid {
    grid-template-columns: 1fr;
  }
  .appt-summary-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 12px 0;
  }
  .appt-stat {
    padding: 8px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--border-subtle);
  }
  .cal-day-card {
    padding: 14px 14px;
  }
  .cal-day-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
  }
  .cal-timeline-col {
    grid-column: 1 / -1;
    order: -1;
  }
  .cal-side-divider {
    border-left: 0;
    padding-left: 0;
  }
  .kpi-card {
    padding: 14px 15px;
    gap: 4px;
  }
  .kpi-value {
    font-size: 1.38rem;
  }
  .kpi-label {
    font-size: 0.78rem;
  }
  .kpi-meta {
    font-size: 0.75rem;
  }

  .grid-2, .grid-3, .grid-sidebar-split, .form-grid, .dialog-body .form-grid, .modal-kv-grid, .ai-kv-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .field.span-2,
  .modal-kv.span-2 {
    grid-column: auto;
  }
  .modal-hero-actions {
    margin-left: 0;
    width: 100%;
  }
  .doc-meta-grid {
    grid-template-columns: 1fr;
  }
  .doc-letterhead {
    flex-direction: column;
  }
  .doc-letterhead .text-right {
    text-align: left;
  }
  .wa-phone {
    height: min(520px, 68dvh);
  }
  .portal-hero {
    padding: 16px;
  }

  /* Native Bottom-Sheet Modals on Phones */
  .app-dialog,
  .app-dialog-wide {
    width: 100vw;
    max-width: 100vw;
    max-height: 92dvh;
    margin: auto 0 0 0;
    border-radius: 16px 16px 0 0;
    border-bottom: 0;
  }
  .dialog-header {
    padding: 14px 16px;
  }
  .dialog-body {
    padding: 16px 16px calc(22px + env(safe-area-inset-bottom));
  }
  .print-canvas {
    padding: 14px 12px calc(22px + env(safe-area-inset-bottom));
  }
  .doc-sheet {
    padding: 14px;
  }
  .tv-dialog {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }
  .tv-header {
    padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .tv-board-body {
    padding: 14px;
    grid-template-columns: 1fr;
  }
  .toast-container {
    left: 14px;
    right: 14px;
    bottom: calc(14px + env(safe-area-inset-bottom));
    max-width: none;
  }
}

/* Ultra-narrow Android phones (<= 360px) */
@media (max-width: 360px) {
  .kpi-grid,
  .kpi-grid-6 {
    grid-template-columns: 1fr;
  }
}

/* Print Styles */
@media print {
  body > *:not(#print-modal) { display: none !important; }
  #print-modal {
    position: static !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: none !important;
    box-shadow: none !important;
    border: 0 !important;
  }
  .no-print { display: none !important; }
  .doc-sheet { border: 0 !important; padding: 0 !important; }
}
