:root {
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --subtle: #94a3b8;
  --teal: #0d7a6f;
  --teal-dark: #095c53;
  --teal-light: #149689;
  --mint: #e6f5f2;
  --mint-border: #bce3dc;
  --line: #e2e8f0;
  --line-soft: #eef2f6;
  --bg: #f3f6f9;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --orange: #b45309;
  --red: #dc2626;
  --blue: #2563eb;
  --purple: #7c3aed;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.04), 0 6px 20px -4px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06), 0 12px 28px -6px rgba(15, 23, 42, 0.07);
  --shadow-modal: 0 24px 72px rgba(15, 23, 42, 0.24), 0 8px 24px rgba(15, 23, 42, 0.1);
  --ring: 0 0 0 3px rgba(13, 122, 111, 0.15);
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --font-sans: 'Inter', 'Segoe UI Variable', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.55;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a,
input,
select,
textarea {
  outline-offset: 2px;
}

button:focus:not(:focus-visible) {
  outline: none;
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

button {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 9px 14px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
  box-shadow: var(--shadow-xs);
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease), box-shadow 0.15s var(--ease), transform 0.12s var(--ease);
}

button:hover:not(:disabled) {
  background: var(--surface-soft);
  border-color: #cbd5e1;
}

button:active:not(:disabled) {
  transform: translateY(0.5px);
}

button.primary {
  background: linear-gradient(180deg, #0f877b 0%, var(--teal) 100%);
  border-color: var(--teal);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(13, 122, 111, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

button.primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #0d7a6f 0%, var(--teal-dark) 100%);
  border-color: var(--teal-dark);
  box-shadow: 0 4px 12px rgba(13, 122, 111, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

button.soft {
  background: var(--mint);
  border-color: transparent;
  color: var(--teal-dark);
  font-weight: 600;
  box-shadow: none;
}

button.soft:hover:not(:disabled) {
  background: #d5efe9;
  border-color: var(--mint-border);
}

button.icon-btn {
  padding: 8px;
  background: transparent;
  border: 1px solid transparent;
  box-shadow: none;
  border-radius: 9px;
  color: var(--ink-soft);
}

button.icon-btn:hover:not(:disabled) {
  background: #f1f5f9;
  border-color: transparent;
  color: var(--ink);
}

button.text {
  border: 0;
  padding: 2px 0;
  background: transparent;
  color: var(--teal);
  font-weight: 600;
  box-shadow: none;
}

button.text:hover:not(:disabled) {
  background: transparent;
  color: var(--teal-dark);
  text-decoration: underline;
  text-underline-offset: 3px;
}

button.text.danger {
  color: var(--red);
}

button.text.danger:hover:not(:disabled) {
  color: #b91c1c;
}

button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  transform: none;
}

a.button,
.file-pick {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  padding: 9px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 550;
  color: var(--ink);
  box-shadow: var(--shadow-xs);
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease);
}

a.button:hover,
.file-pick:hover {
  background: var(--surface-soft);
  border-color: #cbd5e1;
}

.icon {
  width: 18px;
  height: 18px;
  display: inline-block;
  flex-shrink: 0;
  vertical-align: middle;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.positive {
  color: var(--teal);
}

.negative {
  color: var(--red);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 25px;
  letter-spacing: -0.028em;
  font-weight: 700;
  line-height: 1.28;
  color: var(--ink);
}

h2 {
  font-size: 15.5px;
  font-weight: 650;
  letter-spacing: -0.015em;
  color: var(--ink);
}

h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

a {
  color: var(--teal);
  text-decoration: none;
}

/* Sidebar */
#sidebar {
  width: 248px;
  background: #ffffff;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 14px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 2px 8px 18px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 8px;
}

.brand-mark {
  background: var(--teal);
  width: 38px;
  height: 38px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  color: #ffffff;
  flex-shrink: 0;
}

.brand-mark .icon {
  width: 24px;
  height: 24px;
}

.brand b {
  font-size: 17px;
  letter-spacing: -0.03em;
  white-space: nowrap;
}

.brand span {
  font-size: 9px;
  display: block;
  color: var(--muted);
  letter-spacing: 0.9px;
  margin-top: 2px;
  text-transform: uppercase;
}

.nav-scroll {
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  padding-right: 2px;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}

.nav-scroll::-webkit-scrollbar {
  width: 5px;
}

.nav-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.nav-scroll::-webkit-scrollbar-thumb {
  background: #dce3eb;
  border-radius: 99px;
}

.nav-scroll:hover::-webkit-scrollbar-thumb {
  background: #b8c4d1;
}

.nav-label {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--subtle);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 18px 10px 7px;
}

.nav-item {
  display: flex;
  width: 100%;
  gap: 10px;
  border: 0;
  background: transparent;
  padding: 9px 11px;
  margin: 2px 0;
  text-align: left;
  justify-content: flex-start;
  color: #475569;
  font-weight: 500;
  border-radius: 9px;
  font-size: 13px;
  line-height: 1.4;
  white-space: normal;
  box-shadow: none;
  position: relative;
}

.nav-item:hover:not(:disabled) {
  background: #f4f7fa;
  color: var(--ink);
  border-color: transparent;
}

.nav-item.active {
  background: var(--mint);
  color: var(--teal-dark);
  font-weight: 650;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 7px;
  bottom: 7px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--teal);
}

.nav-item .icon {
  width: 17px;
  height: 17px;
  opacity: 0.85;
}

.nav-item.active .icon {
  stroke-width: 2.1;
  opacity: 1;
  color: var(--teal);
}

.nav-count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  border-radius: 99px;
  padding: 1px 7px;
  background: var(--teal);
  color: #ffffff;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.sidebar-bottom {
  margin-top: 12px;
  border-top: 1px solid var(--line-soft);
  padding-top: 10px;
}

.sidebar-bottom .nav-item {
  font-size: 12.5px;
  padding: 8px 11px;
}

.profile {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 8px 2px;
  margin-top: 4px;
}

.sidebar-bottom .profile b {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  display: block;
  line-height: 1.3;
}

.sidebar-bottom .profile .icon-btn {
  margin-left: auto;
}

.avatar {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  font-size: 11.5px;
  font-weight: 700;
  background: #e0eefb;
  color: #1d4ed8;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.avatar.lilac {
  background: #ede9fe;
  color: #6d28d9;
}

.avatar.peach {
  background: #ffedd5;
  color: #c2410c;
}

.avatar.green {
  background: var(--mint);
  color: var(--teal-dark);
}

.avatar.large {
  width: 54px;
  height: 54px;
  font-size: 18px;
  border-radius: 14px;
}

/* Workspace & Topbar */
.workspace {
  margin-left: 248px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

#topbar {
  height: 68px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
  gap: 20px;
}

.breadcrumb {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.breadcrumb .icon {
  width: 15px;
  height: 15px;
  color: var(--subtle);
}

.breadcrumb strong {
  font-weight: 650;
  color: var(--ink);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.global-search {
  display: flex;
  gap: 8px;
  align-items: center;
  width: 260px;
  color: var(--muted);
  background: #f1f5f9;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0 12px;
  height: 38px;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.global-search:focus-within {
  background: #ffffff;
  border-color: var(--teal);
  box-shadow: var(--ring);
}

.global-search .icon {
  width: 16px;
  height: 16px;
  color: var(--subtle);
}

.global-search input {
  border: 0;
  width: 100%;
  padding: 6px 0;
  background: transparent;
  font-size: 13px;
  box-shadow: none;
}

.global-search input:focus {
  outline: none;
  box-shadow: none;
}

.clinic {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--ink-soft);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 6px 12px;
}

.online-dot {
  width: 7px;
  height: 7px;
  background: #10b981;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18);
}

.bell {
  position: relative;
}

.bell::after {
  content: '';
  position: absolute;
  top: 7px;
  right: 8px;
  width: 6px;
  height: 6px;
  border: 2px solid #ffffff;
  box-sizing: content-box;
  background: #f59e0b;
  border-radius: 50%;
}

/* Main Content */
#main {
  padding: 28px 32px 32px;
  max-width: 1640px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
}

.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 24px;
}

.page-heading p {
  color: var(--muted);
  margin-top: 4px;
  font-size: 13.5px;
}

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

.date-button {
  font-size: 13px;
  background: #ffffff;
  font-variant-numeric: tabular-nums;
}

.notice {
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(135deg, #ebf8f5 0%, #f2faf8 100%);
  border: 1px solid #bfe3da;
  border-left: 4px solid var(--teal);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  margin-bottom: 22px;
  color: #115e54;
}

.notice .icon {
  width: 22px;
  height: 22px;
  color: var(--teal);
}

.notice strong {
  font-weight: 650;
}

.notice p {
  font-size: 13px;
  color: #3f6d65;
  margin-top: 2px;
}

.notice .text {
  margin-left: auto;
  font-size: 13px;
}

.notice.small {
  font-size: 12.5px;
  padding: 12px 14px;
}

.clinical-patient-notice {
  display: block;
  margin-bottom: 16px;
}

.clinical-patient-notice .actions {
  margin-top: 12px;
  flex-wrap: wrap;
}

/* KPI Stat Cards */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(195px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.stat {
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  transition: transform 0.16s var(--ease), box-shadow 0.16s var(--ease), border-color 0.16s var(--ease);
}

.stat:hover {
  border-color: #cbd5e1;
  box-shadow: var(--shadow-md);
}

.stat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--muted);
}

.stat-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--mint);
  display: grid;
  place-items: center;
  color: var(--teal);
  flex-shrink: 0;
}

.stat-icon.orange {
  background: #fef3c7;
  color: #b45309;
}

.stat-icon.blue {
  background: #dbeafe;
  color: #1d4ed8;
}

.stat-icon.purple {
  background: #ede9fe;
  color: #6d28d9;
}

.stat-value {
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.22;
  margin: 10px 0 6px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.stat-foot {
  font-size: 12px;
  color: var(--muted);
}

.stat-foot b {
  font-weight: 600;
  margin-right: 5px;
}

/* Panels & Layouts */
.grid-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 22px;
  align-items: start;
}

.stack {
  display: grid;
  gap: 22px;
}

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

.panel.panel-body {
  padding: 22px;
}

.panel.panel-body > label,
.panel.panel-body > form > label {
  display: block;
  font-size: 13px;
  font-weight: 550;
  color: var(--ink-soft);
  margin-bottom: 14px;
}

.panel.panel-body > label > input,
.panel.panel-body > label > select,
.panel.panel-body > form > label > input,
.panel.panel-body > form > label > select {
  margin-top: 6px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 22px 14px;
}

.panel-head p {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 3px;
}

.panel-head .text {
  font-size: 12.5px;
}

.panel-body {
  padding: 0 22px 22px;
}

.panel-body > p + .actions,
.panel-body > p + p + .actions {
  margin-top: 14px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 99px;
  padding: 3px 10px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  background: #f1f5f9;
  color: #475569;
}

.pill.green {
  background: #dcfce7;
  color: #166534;
}

.pill.orange {
  background: #fef3c7;
  color: #92400e;
}

.pill.red {
  background: #fee2e2;
  color: #b91c1c;
}

.pill.blue {
  background: #dbeafe;
  color: #1e40af;
}

.pill.purple {
  background: #ede9fe;
  color: #5b21b6;
}

.tabs {
  display: flex;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  padding: 0 22px;
  background: #fbfcfd;
}

.tab {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 12px 2px;
  font-size: 13px;
  font-weight: 550;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  box-shadow: none;
}

.tab:hover:not(:disabled) {
  background: transparent;
  color: var(--ink);
  border-color: transparent;
}

.tab.active {
  color: var(--teal);
  font-weight: 650;
  border-bottom-color: var(--teal);
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.045em;
  background: #f8fafc;
  padding: 11px 18px;
  border-bottom: 1px solid var(--line);
}

td {
  padding: 13px 18px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

td b {
  color: var(--ink);
  font-weight: 600;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: #f8fbfb;
}

.person {
  display: flex;
  align-items: center;
  gap: 11px;
}

.person-name {
  font-size: 13px;
  font-weight: 600;
  display: block;
  color: var(--ink);
}

.person-meta {
  display: block;
  color: var(--muted);
  font-size: 11.5px;
  margin-top: 2px;
}

.table-bottom {
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 22px;
  font-size: 12px;
  color: var(--muted);
  background: #fbfcfd;
}

/* Charts & Dashboard widgets */
.chart-top {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding-top: 4px;
  margin-bottom: 10px;
}

.chart-top strong {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
}

.chart {
  height: 155px;
  display: flex;
  gap: 16px;
  align-items: flex-end;
  padding: 12px 10px 22px 38px;
  position: relative;
  margin-top: 16px;
  background: repeating-linear-gradient(to top, transparent 0px, transparent 39px, #f1f5f9 39px, #f1f5f9 40px);
}

.bar-group {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 5px;
  height: 100%;
  position: relative;
}

.bar {
  width: 11px;
  min-height: 3px;
  border-radius: 4px 4px 0 0;
  background: var(--teal);
}

.bar.alt {
  background: #cce7e2;
}

.bar-group span {
  position: absolute;
  bottom: -21px;
  font-size: 10px;
  color: var(--muted);
}

.axis {
  position: absolute;
  left: 0;
  top: 5px;
  bottom: 17px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-size: 10px;
  color: var(--subtle);
}

.legend {
  display: flex;
  align-items: center;
  gap: 15px;
  font-size: 12px;
  color: var(--muted);
}

.legend i {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: #2a9b8d;
  border-radius: 3px;
  margin-right: 6px;
}

.legend i.alt {
  background: #d7ebe5;
}

.appointment {
  display: flex;
  gap: 13px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line-soft);
}

.appointment:last-child {
  border-bottom: 0;
}

.appt-time {
  width: 46px;
  font-size: 12.5px;
  font-weight: 650;
  flex-shrink: 0;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.appt-detail {
  border-left: 3px solid #67c4b5;
  padding-left: 13px;
  flex: 1;
}

.appointment:nth-child(3n) .appt-detail {
  border-color: #a78bfa;
}

.appointment h3 {
  font-size: 13px;
}

.appointment p {
  font-size: 12px;
  color: var(--muted);
  margin: 3px 0 7px;
}

.appointment .pill {
  font-size: 11px;
}

.full {
  width: 100%;
}

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

.rule-summary:last-child {
  border: 0;
}

.rule-summary .symbol {
  background: var(--mint);
  color: var(--teal);
  border-radius: 10px;
  padding: 8px;
  display: grid;
  place-items: center;
}

.rule-summary h3 {
  font-size: 13px;
}

.rule-summary p {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
}

.rule-summary .switch {
  margin-left: auto;
}

.switch {
  background: var(--teal);
  width: 36px;
  height: 20px;
  border-radius: 99px;
  padding: 2px;
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.12);
  transition: background-color 0.18s var(--ease);
}

.switch:hover:not(:disabled) {
  background: var(--teal-dark);
}

.switch::after {
  content: '';
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.22);
}

.switch.off {
  background: #cbd5e1;
  justify-content: flex-start;
}

.switch.off:hover:not(:disabled) {
  background: #94a3b8;
}

/* Toolbars & Filters */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line-soft);
  flex-wrap: wrap;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 360px;
  flex: 1;
  min-width: 190px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  background: var(--surface-soft);
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.search-field:focus-within {
  background: #ffffff;
  border-color: var(--teal);
  box-shadow: var(--ring);
}

.search-field input {
  width: 100%;
  border: 0;
  padding: 9px 0;
  background: transparent;
  box-shadow: none;
}

.search-field input:focus {
  outline: none;
  box-shadow: none;
}

.toolbar select {
  width: auto;
  min-width: 160px;
}

.toolbar > input:not([type=checkbox]):not([type=radio]) {
  flex: 1 1 240px;
  width: auto;
  max-width: 380px;
}

.toolbar .right {
  margin-left: auto;
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

label.field {
  display: block;
  font-size: 13px;
  font-weight: 550;
  color: var(--ink-soft);
}

label.field > span {
  display: block;
  margin-bottom: 6px;
}

input,
select,
textarea {
  border: 1px solid #d5dee7;
  border-radius: 10px;
  padding: 9px 12px;
  width: 100%;
  color: var(--ink);
  background: #ffffff;
  min-width: 0;
  font-size: 13px;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), background-color 0.15s var(--ease);
}

input:hover:not(:disabled),
select:hover:not(:disabled),
textarea:hover:not(:disabled) {
  border-color: #b7c4d3;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: var(--ring);
  outline: none;
}

input:disabled,
select:disabled,
textarea:disabled {
  background: #f1f5f9;
  color: var(--muted);
}

input[type=checkbox] {
  width: 16px;
  height: 16px;
  accent-color: var(--teal);
  cursor: pointer;
}

input[type=number] {
  appearance: textfield;
}

textarea {
  resize: vertical;
  min-height: 90px;
}

.form-help {
  font-size: 12px;
  color: var(--muted);
  margin-top: 7px;
  font-weight: 400;
  line-height: 1.5;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
}

.form-divider {
  border-top: 1px solid var(--line-soft);
  padding-top: 20px;
  margin-top: 20px;
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding-top: 22px;
  flex-wrap: wrap;
}

.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.empty .icon {
  display: block;
  margin: 0 auto 12px;
  width: 32px;
  height: 32px;
  color: #94a3b8;
}

/* Rule cards */
.rule-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.rule-card {
  padding: 22px;
}

.rule-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.rule-card p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 6px;
}

.rule-flow {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 0;
}

.rule-flow span {
  font-size: 12px;
  font-weight: 550;
  background: var(--mint);
  border: 1px solid #d1eae4;
  border-radius: 8px;
  padding: 7px 11px;
  color: var(--teal-dark);
}

.rule-card-footer {
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.preview-box {
  padding: 18px;
  background: #eef7f5;
  border: 1px solid #cce7e0;
  border-radius: 12px;
  line-height: 1.7;
  font-size: 13px;
}

.preview-box p {
  margin-top: 8px;
}

/* Detail & Timeline */
.detail-header {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 22px;
}

.detail-header h2 {
  font-size: 20px;
  font-weight: 700;
}

.detail-header p {
  color: var(--muted);
  margin-top: 3px;
  font-size: 13px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.detail-tile {
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  border-radius: 11px;
}

.detail-tile span {
  display: block;
  color: var(--muted);
  font-size: 11.5px;
  margin-bottom: 5px;
}

.detail-tile b {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
}

.timeline {
  margin-top: 14px;
}

.timeline-item {
  padding: 0 0 18px 20px;
  position: relative;
  border-left: 2px solid #dcebe7;
  margin-left: 6px;
}

.timeline-item:last-child {
  padding-bottom: 4px;
}

.timeline-item::before {
  content: '';
  position: absolute;
  top: 4px;
  left: -5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 3px var(--mint);
}

.timeline-item p {
  font-size: 13px;
  margin-top: 3px;
}

.timeline-item span {
  font-size: 11.5px;
  color: var(--muted);
}

.rule-detail {
  margin: 14px 0;
  border-radius: 10px;
  background: #f1f8f6;
  border: 1px solid #d5ece6;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--ink-soft);
}

.two-columns {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(290px, 1fr);
  gap: 22px;
}

.info-strip {
  border: 1px solid #dbe6f0;
  background: #f4f8fc;
  padding: 13px 16px;
  border-radius: 11px;
  color: #475569;
  font-size: 13px;
  line-height: 1.55;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.info-strip .icon {
  color: #3b82f6;
}

/* Appointments Calendar Strip */
.calendar-strip {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line-soft);
}

.day {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 11px 4px;
  font-size: 11px;
  color: var(--muted);
  border-radius: 11px;
}

.day b {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.day.selected {
  background: linear-gradient(180deg, #0f877b 0%, var(--teal) 100%);
  color: #d1fae5;
  border-color: var(--teal);
  box-shadow: 0 4px 12px rgba(13, 122, 111, 0.25);
}

.day.selected b {
  color: #ffffff;
}

.schedule-list {
  padding: 4px 22px 12px;
}

.schedule-list .appointment {
  padding: 18px 0;
}

.schedule-list .appointment h3 {
  font-size: 14px;
}

.schedule-list .appointment p {
  font-size: 13px;
}

.schedule-list .appt-time {
  width: 66px;
  font-size: 13.5px;
}

.schedule-list .appt-detail {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 9px;
}

.module-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.module {
  padding: 22px;
  transition: transform 0.16s var(--ease), box-shadow 0.16s var(--ease), border-color 0.16s var(--ease);
}

.module:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: #cbd5e1;
}

.module .icon {
  width: 24px;
  height: 24px;
  color: var(--teal);
}

.module h3 {
  margin: 12px 0 6px;
  font-size: 15px;
}

.module p {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}

.section-space {
  margin-top: 22px;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line-soft);
}

.metric-row:last-child {
  border: 0;
}

.metric-row span {
  font-size: 13px;
  color: var(--muted);
}

.metric-row b {
  font-size: 15.5px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

/* Modal Dialog */
@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

dialog {
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: var(--radius-xl);
  width: min(670px, calc(100vw - 32px));
  padding: 0;
  box-shadow: var(--shadow-modal);
  max-height: 90vh;
  color: var(--ink);
  background: #ffffff;
}

dialog[open] {
  animation: modalIn 0.18s var(--ease);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(5px);
}

.modal-head {
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  z-index: 2;
}

.modal-head h2 {
  font-size: 17.5px;
  font-weight: 700;
}

.modal-content {
  padding: 22px 24px 24px;
}

.modal-error {
  display: none;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  padding: 11px 13px;
  border-radius: 10px;
  margin-top: 15px;
  font-size: 13px;
  line-height: 1.5;
}

.modal-error.visible {
  display: block;
}

/* Toast */
#toast {
  position: fixed;
  bottom: 24px;
  left: calc(50% + 124px);
  transform: translate(-50%, 16px);
  padding: 12px 18px;
  border-radius: 12px;
  background: #0f172a;
  color: #ffffff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
  z-index: 100;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.24);
  font-size: 13px;
  font-weight: 500;
  max-width: min(90vw, 560px);
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

footer {
  max-width: 1640px;
  width: 100%;
  margin: auto auto 0;
  padding: 10px 32px 20px;
  display: flex;
  gap: 15px;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}

.menu-toggle {
  display: none;
}

.chart-legend {
  display: flex;
  gap: 15px;
  margin-top: 18px;
}

.progress {
  height: 7px;
  border-radius: 99px;
  background: #e2e8f0;
  overflow: hidden;
  margin-top: 10px;
}

.progress > i {
  display: block;
  height: 100%;
  background: var(--teal);
  border-radius: 99px;
}

.audit-table td {
  white-space: normal;
}

.settings-block {
  padding: 22px;
}

.settings-block h2 {
  margin-bottom: 16px;
}

.preview-bubble {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  font-size: 13px;
  line-height: 1.75;
}

.preview-phone {
  background: #f1f5f9;
  padding: 20px;
  border-radius: 14px;
}

.preview-phone h3 {
  margin-bottom: 12px;
  font-size: 13px;
}

.tag-line {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

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

.mini-table th,
.mini-table td {
  padding: 10px 10px;
}

.summary-total {
  padding: 16px;
  background: var(--mint);
  border-radius: 11px;
  margin-top: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.summary-total strong {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.badge-count {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  background: #f1f5f9;
  color: var(--ink-soft);
  border-radius: 99px;
  margin-left: 6px;
  font-variant-numeric: tabular-nums;
}

.design-note {
  font-size: 12px;
  color: var(--muted);
  margin-top: 14px;
}

.segmented {
  display: flex;
  gap: 4px;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 9px;
}

.segmented button {
  border: 0;
  background: transparent;
  padding: 6px 12px;
  font-size: 12px;
  box-shadow: none;
}

.segmented button.active {
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.08);
}

.file-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-top: 10px;
  background: var(--surface-soft);
  font-weight: 550;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease);
}

.file-link:hover {
  background: #eef4f7;
  border-color: #cbd5e1;
}

.nowrap {
  white-space: nowrap;
}

.data-path {
  overflow-wrap: anywhere;
  font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  font-size: 12px;
}

#system-management .checkbox-label {
  margin: 14px 0;
}

#system-management .panel-head p {
  margin-top: 4px;
}

#restore-preview .notice {
  line-height: 1.75;
}

#restore-status {
  color: var(--red);
  font-weight: 600;
}

.permission-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 8px 0 18px;
}

.permission-chips .pill {
  white-space: normal;
}

details.panel > summary {
  cursor: pointer;
  font-weight: 650;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

details.panel > summary::after {
  content: '▾';
  color: var(--muted);
  font-size: 13px;
  transition: transform 0.15s var(--ease);
}

details.panel[open] > summary::after {
  transform: rotate(180deg);
}

/* Auth & Onboarding */
.auth-mode #sidebar,
.auth-mode .workspace {
  display: none;
}

#auth-root {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 14% 18%, rgba(13, 122, 111, 0.12) 0%, transparent 42%),
    radial-gradient(circle at 86% 80%, rgba(79, 70, 229, 0.09) 0%, transparent 45%),
    linear-gradient(155deg, #f1f6f8 0%, #f8fafc 60%, #edf5f3 100%);
}

.auth-card {
  width: min(460px, 100%);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  padding: 36px;
  border: 1px solid #e2e8f0;
  border-radius: 22px;
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.09), 0 4px 16px rgba(15, 23, 42, 0.04);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  font-size: 21px;
  margin-bottom: 26px;
}

.auth-brand .icon {
  width: 34px;
  height: 34px;
}

.auth-card h1 {
  font-size: 25px;
  margin-bottom: 6px;
}

.auth-card form {
  display: grid;
  gap: 15px;
  margin-top: 22px;
}

.auth-card [data-auth="master-login"] {
  margin-top: 14px;
  font-size: 12.5px;
}

.auth-footer {
  font-size: 12px;
  color: var(--muted);
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
}

.auth-error {
  font-size: 13px;
  color: #b91c1c;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 9px;
  padding: 10px 12px;
}

.auth-error:empty {
  display: none;
}

/* Responsive */
@media (min-width: 1550px) {
  .grid-main {
    grid-template-columns: minmax(0, 1fr) 375px;
  }
  td {
    padding: 15px 20px;
  }
  .chart {
    height: 180px;
  }
  .stat {
    padding: 22px;
  }
}

@media (max-width: 1200px) {
  #sidebar {
    width: 220px;
    padding-left: 10px;
    padding-right: 10px;
  }
  .workspace {
    margin-left: 220px;
  }
  #main {
    padding: 22px;
  }
  .grid-main {
    grid-template-columns: minmax(0, 1fr) 290px;
    gap: 16px;
  }
  .stack {
    gap: 16px;
  }
  .stats {
    gap: 12px;
  }
  .stat {
    padding: 15px;
  }
  .global-search {
    width: 185px;
  }
  .clinic {
    display: none;
  }
  #topbar {
    padding: 0 22px;
  }
  .table-wrap table {
    min-width: 620px;
  }
  .panel-head {
    padding: 16px 18px 12px;
  }
  .panel-body {
    padding: 0 18px 18px;
  }
  .stat-value {
    font-size: 23px;
  }
  .brand b {
    font-size: 16px;
  }
  .legend {
    font-size: 11px;
    gap: 10px;
  }
}

@media (max-width: 1000px) {
  .grid-main {
    grid-template-columns: 1fr;
  }
  .grid-main > .stack:last-child {
    grid-template-columns: 1fr 1fr;
  }
  .stats {
    grid-template-columns: repeat(2, 1fr);
  }
  .two-columns {
    grid-template-columns: 1fr;
  }
  .module-list {
    grid-template-columns: 1fr 1fr;
  }
  .rule-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  #sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s var(--ease);
    box-shadow: 12px 0 36px rgba(15, 23, 42, 0.16);
  }
  #sidebar.open {
    transform: translateX(0);
  }
  .workspace {
    margin-left: 0;
  }
  .menu-toggle {
    display: inline-flex;
  }
  #topbar {
    padding: 0 16px;
    height: 62px;
    gap: 10px;
  }
  .top-actions {
    gap: 6px;
  }
  .global-search {
    width: 155px;
  }
  .breadcrumb {
    display: none;
  }
  #main {
    padding: 18px 16px 24px;
  }
  .page-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }
  h1 {
    font-size: 23px;
  }
  .notice {
    align-items: flex-start;
    padding: 13px;
    flex-wrap: wrap;
  }
  .notice .text {
    margin-left: 34px;
  }
  .stats {
    gap: 10px;
  }
  .stat {
    padding: 14px;
  }
  .stat-value {
    font-size: 22px;
  }
  .grid-main > .stack:last-child {
    grid-template-columns: 1fr;
  }
  .page-heading > .actions {
    width: 100%;
    justify-content: flex-start;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .form-grid .span-2 {
    grid-column: auto;
  }
  .module-list {
    grid-template-columns: 1fr;
  }
  .detail-grid {
    grid-template-columns: 1fr;
  }
  .rule-flow {
    flex-wrap: wrap;
  }
  .modal-content {
    padding: 18px;
  }
  .modal-head {
    padding: 16px 18px;
  }
  .schedule-list .appt-detail {
    display: block;
  }
  .schedule-list .actions {
    margin-top: 12px;
  }
  .calendar-strip {
    gap: 5px;
    padding: 14px 10px;
  }
  .day {
    padding: 10px 4px;
  }
  .toolbar {
    padding: 14px 16px;
  }
  .toolbar .right {
    margin-left: 0;
  }
  footer {
    padding: 0 16px 20px;
    flex-direction: column;
    gap: 5px;
  }
  #toast {
    left: 50%;
  }
  .chart {
    gap: 8px;
  }
  .panel-head {
    gap: 8px;
  }
  .legend {
    display: none;
  }
  .top-actions > .avatar {
    display: none;
  }
  .check-columns {
    grid-template-columns: 1fr;
  }
}

@media print {
  #sidebar,
  #topbar,
  footer,
  .page-heading .actions,
  .toolbar,
  dialog .form-actions,
  dialog .modal-head button {
    display: none !important;
  }
  .workspace {
    margin: 0;
  }
  body {
    background: #ffffff;
  }
  dialog[open] {
    position: absolute;
    inset: 0;
    max-height: none;
    width: 100%;
    box-shadow: none;
  }
  body:has(dialog[open]) .workspace {
    display: none;
  }
  .panel {
    break-inside: avoid;
    box-shadow: none;
  }
  #main {
    padding: 0;
  }
}

/* Custom hospital-style prescription sheet */
.print-sheet[data-custom-layout="prescription"] {
  color: #000000;
  font-family: "Times New Roman", Times, serif;
}
.rx-sheet {
  color: #000000;
  line-height: 1.45;
}
.rx-sheet-code {
  font-size: 0.92em;
  font-weight: 700;
  margin-bottom: 6px;
}
.rx-sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 8px;
}
.rx-sheet-clinic {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.rx-sheet-logo {
  width: 56px;
  height: 56px;
  object-fit: contain;
  flex-shrink: 0;
}
.rx-sheet-clinic-info {
  font-size: 0.95em;
  line-height: 1.35;
}
.rx-sheet-clinic-name {
  font-weight: 700;
  font-size: 1.08em;
  text-transform: uppercase;
}
.rx-sheet-barcode {
  flex-shrink: 0;
  text-align: right;
}
.rx-sheet-barcode .rx-barcode {
  margin: 0;
}
.rx-sheet-title {
  text-align: center;
  font-size: 1.5em;
  font-weight: 700;
  letter-spacing: 0.4px;
  margin: 10px 0 12px;
  color: #000000;
  border: 0;
  padding: 0;
}
.rx-sheet-patient {
  margin-bottom: 10px;
}
.rx-sheet-row {
  margin-bottom: 3px;
}
.rx-sheet-row-3 {
  display: grid;
  grid-template-columns: 1.6fr 0.8fr 0.7fr;
  gap: 8px;
}
.rx-sheet-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.rx-sheet-pat-name {
  font-size: 1.05em;
  letter-spacing: 0.2px;
}
.rx-sheet-section-label {
  font-weight: 700;
  margin: 8px 0 4px;
}
.print-sheet .rx-sheet-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 8px;
  background: #ffffff;
  border-radius: 0;
  box-shadow: none;
  border: 1px solid #000000;
}
.print-sheet .rx-sheet-table th,
.print-sheet .rx-sheet-table td {
  border: 1px solid #000000;
  padding: 5px 7px;
  color: #000000;
  background: #ffffff;
  font-size: inherit;
  border-radius: 0;
}
.print-sheet .rx-sheet-table th {
  text-align: center;
  font-weight: 700;
}
.print-sheet .rx-sheet-table td {
  vertical-align: top;
}
.rx-col-stt {
  width: 38px;
  text-align: center;
}
.rx-col-unit {
  width: 56px;
  text-align: center;
}
.rx-col-qty {
  width: 48px;
  text-align: center;
}
.rx-drug-title {
  font-weight: 700;
}
.rx-drug-usage {
  font-style: italic;
  margin-top: 2px;
}
.rx-sheet-price {
  font-size: 0.85em;
  color: #333333;
  margin-top: 2px;
}
.rx-sheet-closing p {
  margin: 3px 0;
}
.rx-sheet-sign-wrap {
  display: flex;
  justify-content: flex-end;
  margin: 12px 0 18px;
}
.rx-sheet-sign-box {
  width: 240px;
  text-align: center;
}
.rx-sheet-date {
  font-style: italic;
}
.rx-sheet-sign-role {
  font-weight: 700;
  margin-top: 2px;
}
.rx-sheet-sign-space {
  height: 54px;
}
.rx-sheet-doctor {
  font-weight: 700;
  font-size: 1.05em;
}
.rx-sheet-license {
  font-size: 0.9em;
}
.rx-sheet-footer {
  display: block;
  font-style: italic;
  font-size: 0.95em;
  line-height: 1.5;
  margin-top: 8px;
  text-align: left;
  border: 0;
  padding: 0;
}

