/* ClinicPulse — Clinical Management Platform */

:root {
  --font: "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.12);
  --transition: 180ms ease;

  --bg: #f0f5f4;
  --bg-elevated: #ffffff;
  --bg-muted: #e6efed;
  --surface: #ffffff;
  --border: #d5e2df;
  --text: #0f1f1c;
  --text-secondary: #4a635e;
  --text-muted: #7a938d;
  --primary: #0f766e;
  --primary-hover: #0d9488;
  --primary-soft: rgba(15, 118, 110, 0.1);
  --accent: #0369a1;
  --success: #15803d;
  --success-soft: rgba(21, 128, 61, 0.12);
  --warning: #b45309;
  --warning-soft: rgba(180, 83, 9, 0.12);
  --danger: #b91c1c;
  --danger-soft: rgba(185, 28, 28, 0.12);
  --sidebar-w: 260px;
  --topbar-h: 72px;
  --live: #16a34a;
  --live-off: #94a3b8;
}

[data-theme="dark"] {
  --bg: #0b1413;
  --bg-elevated: #13201e;
  --bg-muted: #1a2b28;
  --surface: #152422;
  --border: #243a36;
  --text: #e8f2ef;
  --text-secondary: #a8c0ba;
  --text-muted: #6f8f88;
  --primary: #2dd4bf;
  --primary-hover: #5eead4;
  --primary-soft: rgba(45, 212, 191, 0.14);
  --accent: #38bdf8;
  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, 0.14);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.5);
  --live: #4ade80;
  --live-off: #64748b;
}

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

html {
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  transition: background var(--transition), color var(--transition);
}

[dir="rtl"] body {
  font-feature-settings: "ss01";
}

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

button {
  cursor: pointer;
  border: none;
  background: none;
}

a {
  color: var(--primary);
}

.hidden {
  display: none !important;
}

/* ---------- Boot screen (no login flash) ---------- */
.boot-screen {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  background: var(--bg);
}

body.booting #app-shell {
  visibility: hidden;
}

body:not(.booting) #boot-screen {
  display: none !important;
}

.boot-card {
  text-align: center;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
}

.boot-card .brand-mark {
  width: 48px;
  height: 48px;
  margin: 0;
  color: var(--primary);
}

.boot-card p {
  margin: 0;
  font-weight: 600;
  font-size: 0.9rem;
}

.boot-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.page-login #login-screen {
  display: grid;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  top: 1.25rem;
  left: 50%;
  transform: translateX(-50%) translateY(-120%);
  z-index: 9999;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-weight: 600;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: transform 280ms ease, opacity 280ms ease;
  max-width: min(90vw, 420px);
  text-align: center;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.success {
  border-color: var(--success);
  background: var(--success-soft);
  color: var(--success);
}

.toast.error {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

.toast.info {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

/* ---------- Login ---------- */
.login-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
}

.login-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 10% 20%, rgba(15, 118, 110, 0.22), transparent 55%),
    radial-gradient(ellipse 70% 50% at 90% 80%, rgba(3, 105, 161, 0.18), transparent 50%),
    linear-gradient(160deg, var(--bg) 0%, var(--bg-muted) 100%);
  z-index: 0;
}

[data-theme="dark"] .login-bg {
  background:
    radial-gradient(ellipse 80% 60% at 10% 20%, rgba(45, 212, 191, 0.12), transparent 55%),
    radial-gradient(ellipse 70% 50% at 90% 80%, rgba(56, 189, 248, 0.1), transparent 50%),
    linear-gradient(160deg, #07100f 0%, #0f1c1a 100%);
}

.login-stack {
  position: relative;
  z-index: 1;
  width: min(100%, 420px);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-card {
  position: relative;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 2rem 1.75rem 1.75rem;
  animation: fadeUp 0.45s ease both;
}

.demo-users {
  background: var(--primary-soft);
  border: 1px solid color-mix(in srgb, var(--primary) 38%, var(--border));
  border-radius: 14px;
  padding: 14px 16px 16px;
  animation: fadeUp 0.45s ease 0.08s both;
}

.demo-users-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 12px;
  text-align: start;
}

.demo-users-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.demo-user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: nowrap;
}

.demo-user-btn {
  width: auto;
  flex: none;
  flex-shrink: 0;
  white-space: nowrap;
  text-align: center;
  padding: 8px 14px;
  border-radius: 10px;
  border: none;
  background: var(--primary);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  font-family: inherit;
  transition: background var(--transition), transform 120ms ease;
}

.demo-user-btn:hover {
  background: var(--primary-hover);
}

.demo-user-creds {
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  direction: ltr;
  unicode-bidi: isolate;
  text-align: start;
  white-space: nowrap;
}

.login-footer {
  text-align: center;
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.login-brand {
  text-align: center;
  margin-bottom: 1.5rem;
}

.brand-mark {
  width: 52px;
  height: 52px;
  margin: 0 auto 0.75rem;
  color: var(--primary);
}

.brand-mark svg {
  width: 100%;
  height: 100%;
}

.brand-mark.sm {
  width: 40px;
  height: 40px;
  margin: 0;
  flex-shrink: 0;
}

.brand-name {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 0;
  color: var(--text);
}

.brand-tagline {
  margin: 0.35rem 0 0;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.login-toolbar {
  position: absolute;
  top: 1rem;
  inset-inline-end: 1rem;
  display: flex;
  gap: 0.4rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.otp-hint {
  margin: 0 0 0.5rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.form-error {
  margin: 0;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.875rem;
  font-weight: 500;
}

/* ---------- Fields & Buttons ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.field input,
.field select {
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--bg-elevated);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.8;
}

.field input:focus,
.field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.field select[multiple] {
  min-height: 2.6rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.7rem 1.15rem;
  border-radius: var(--radius-sm);
  font-weight: 650;
  font-size: 0.9rem;
  transition: background var(--transition), color var(--transition), transform 120ms ease, opacity var(--transition);
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-block {
  width: 100%;
}

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

[data-theme="dark"] .btn-primary {
  color: #042f2e;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-muted);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-muted);
  color: var(--text);
}

.btn-sm {
  padding: 0.45rem 0.85rem;
  font-size: 0.8rem;
}

.btn-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  transition: background var(--transition), color var(--transition);
}

.icon-btn:hover {
  color: var(--text);
  background: var(--bg-muted);
}

[data-theme="light"] .icon-moon {
  display: none;
}

[data-theme="dark"] .icon-sun {
  display: none;
}

.lang-btn {
  height: 38px;
  min-width: 42px;
  padding: 0 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font-weight: 700;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

.lang-btn:hover {
  color: var(--primary);
  border-color: var(--primary);
}

/* ---------- App Shell ---------- */
.app-shell {
  display: flex;
  min-height: 100dvh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
  position: sticky;
  top: 0;
  height: 100dvh;
  z-index: 40;
  transition: transform 280ms ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.25rem 0.5rem 1.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.sidebar-brand .brand-name {
  font-size: 1.05rem;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.9rem;
  text-align: start;
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
}

.nav-item:hover {
  background: var(--bg-muted);
  color: var(--text);
}

.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.live-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0 0.35rem;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--live-off);
  flex-shrink: 0;
}

.live-indicator.online .live-dot {
  background: var(--live);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.25);
  animation: pulse 2s ease infinite;
}

.live-indicator.online {
  color: var(--live);
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.35);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(22, 163, 74, 0);
  }
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  background: var(--bg-muted);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

[data-theme="dark"] .user-avatar {
  color: #042f2e;
}

.user-name {
  font-weight: 700;
  font-size: 0.85rem;
  line-height: 1.2;
}

.user-email {
  font-size: 0.7rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 150px;
}

.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-title {
  flex: 1;
  min-width: 0;
}

.topbar-title h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.topbar-title p {
  margin: 0.1rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.content {
  padding: 1.25rem 1.5rem 2.5rem;
  flex: 1;
}

.view {
  display: none;
  animation: fadeUp 0.3s ease both;
}

.view.active {
  display: block;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.filters-bar {
  padding: 1.15rem;
  margin-bottom: 1.15rem;
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.doctors-filters {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}

.field-wide {
  grid-column: 1 / -1;
}

.doctor-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  max-height: 120px;
  overflow-y: auto;
}

.doctor-check-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}

.filter-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  width: 100%;
}

.filter-active {
  margin: 0 0 0.85rem;
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 600;
}

.filters-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.15rem;
}

.stat-card {
  padding: 1.1rem 1.2rem;
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 650;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-top: 0.25rem;
  color: var(--primary);
}

.table-card {
  overflow: hidden;
}

.table-card + .table-card {
  margin-top: 1.15rem;
}

.section-head {
  padding: 1rem 1.15rem 0;
}

.section-head h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th,
.data-table td {
  padding: 0.85rem 1rem;
  text-align: start;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table .col-code {
  text-align: start;
  direction: ltr;
  unicode-bidi: isolate;
  font-variant-numeric: tabular-nums;
}

[dir="rtl"] .data-table .col-code {
  text-align: right;
  direction: ltr;
  unicode-bidi: isolate;
}

.data-table th {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--bg-muted);
  position: sticky;
  top: 0;
}

.data-table tbody tr {
  transition: background var(--transition);
}

.data-table tbody tr:hover {
  background: var(--primary-soft);
}

.data-table .empty-row td {
  text-align: center;
  color: var(--text-muted);
  padding: 2.5rem 1rem;
  white-space: normal;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-unused,
.badge-success {
  background: var(--success-soft);
  color: var(--success);
}

.badge-used,
.badge-muted {
  background: var(--bg-muted);
  color: var(--text-muted);
}

.badge-warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  border-top: 1px solid var(--border);
}

.pager-info {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 5rem;
  text-align: center;
}

.charts-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-bottom: 1.15rem;
}

.chart-card {
  padding: 1.15rem;
}

.chart-card h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 700;
}

.chart-wrap {
  position: relative;
  height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-wrap canvas {
  max-height: 100%;
}

.chart-empty {
  position: absolute;
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.matrix-wrap {
  max-height: 480px;
}

.matrix-table th:first-child,
.matrix-table td:first-child {
  position: sticky;
  inset-inline-start: 0;
  background: var(--surface);
  z-index: 1;
  font-weight: 650;
}

.matrix-table thead th:first-child {
  background: var(--bg-muted);
  z-index: 2;
}

.matrix-cell {
  font-variant-numeric: tabular-nums;
}

.matrix-cell small {
  display: block;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 500;
}

.matrix-table tbody tr.matrix-totals-row {
  background: var(--primary-soft);
  font-weight: 650;
}

.column-picker {
  padding: 1rem 1.15rem;
  margin-bottom: 1rem;
}

.column-picker h4 {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
}

.column-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1.25rem;
}

.column-checks label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 550;
  cursor: pointer;
}

.sidebar-overlay {
  display: none;
}

.mobile-only {
  display: none;
}

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .charts-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .mobile-only {
    display: grid;
  }

  .sidebar {
    position: fixed;
    inset-inline-start: 0;
    top: 0;
    transform: translateX(-105%);
    box-shadow: var(--shadow-lg);
  }

  [dir="rtl"] .sidebar {
    transform: translateX(105%);
  }

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

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 35;
    opacity: 0;
    pointer-events: none;
    transition: opacity 280ms ease;
  }

  .sidebar-overlay.show {
    opacity: 1;
    pointer-events: auto;
  }

  .content {
    padding: 1rem;
  }

  .topbar {
    padding: 0 1rem;
  }

  .filters-grid {
    grid-template-columns: 1fr 1fr;
  }
}

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

  .login-card {
    padding: 1.5rem 1.15rem;
  }

  .stat-value {
    font-size: 1.3rem;
  }

  .topbar-title p {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Modal / Coupon form ---------- */
body.modal-open {
  overflow: hidden;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(100%, 520px);
  max-height: min(92dvh, 720px);
  overflow-y: auto;
  scrollbar-width: thin;
  animation: fadeUp 0.28s ease both;
}

.modal-card-lg {
  width: min(calc(100% - 2rem), 680px);
  max-height: min(94dvh, 680px);
}

.modal-card-sm {
  width: min(100%, 400px);
}

.modal-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1rem;
}

.field-relative {
  position: relative;
}

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

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--border);
}

.modal-head h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 750;
}

.modal-head .icon-btn {
  font-size: 1.4rem;
  line-height: 1;
}

.modal-body {
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.field em {
  color: var(--danger);
  font-style: normal;
}

.field textarea {
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  outline: none;
  resize: vertical;
  min-height: 72px;
  font: inherit;
}

.field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.field-hint {
  margin: 0.25rem 0 0;
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 600;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.35rem;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  filter: brightness(1.08);
}

.actions-cell {
  display: flex;
  gap: 0.35rem;
  white-space: nowrap;
}

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

.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin-top: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.18);
  max-height: 180px;
  overflow-y: auto;
  z-index: 100;
}

.search-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  width: 100%;
  padding: 0.65rem 0.85rem;
  text-align: start;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  background: transparent;
}

.search-item:last-child {
  border-bottom: none;
}

.search-item:hover {
  background: var(--primary-soft);
}

.search-item span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.search-item.muted {
  color: var(--text-muted);
  font-size: 0.85rem;
}

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

  .actions-cell {
    flex-direction: column;
  }
}

/* ---------- ClinicDatePicker Localized Component ---------- */
.field input.clinic-date-input,
.clinic-date-input {
  cursor: pointer;
  background-color: var(--bg-elevated) !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%230f766e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2' ry='2'%3E%3C/rect%3E%3Cline x1='16' y1='2' x2='16' y2='6'%3E%3C/line%3E%3Cline x1='8' y1='2' x2='8' y2='6'%3E%3C/line%3E%3Cline x1='3' y1='10' x2='21' y2='10'%3E%3C/line%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 0.85rem center !important;
  background-size: 16px 16px !important;
  padding-inline-end: 2.5rem !important;
}

[dir="rtl"] .field input.clinic-date-input,
[dir="rtl"] .clinic-date-input {
  background-position: left 0.85rem center !important;
  padding-inline-start: 0.85rem !important;
  padding-inline-end: 2.5rem !important;
}

[data-theme="dark"] .field input.clinic-date-input,
[data-theme="dark"] .clinic-date-input {
  background-color: var(--bg-elevated) !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%232dd4bf' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2' ry='2'%3E%3C/rect%3E%3Cline x1='16' y1='2' x2='16' y2='6'%3E%3C/line%3E%3Cline x1='8' y1='2' x2='8' y2='6'%3E%3C/line%3E%3Cline x1='3' y1='10' x2='21' y2='10'%3E%3C/line%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 0.85rem center !important;
  background-size: 16px 16px !important;
}

[dir="rtl"][data-theme="dark"] .field input.clinic-date-input,
[data-theme="dark"] [dir="rtl"] .field input.clinic-date-input,
[dir="rtl"][data-theme="dark"] .clinic-date-input,
[data-theme="dark"] [dir="rtl"] .clinic-date-input {
  background-position: left 0.85rem center !important;
}

.clinic-datepicker-popup {
  position: fixed;
  z-index: 99999;
  width: 270px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.16), 0 4px 12px rgba(0, 0, 0, 0.08);
  padding: 12px;
  font-family: inherit;
  color: var(--text);
  user-select: none;
  animation: cdpFade 0.15s ease-out;
}

@keyframes cdpFade {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.cdp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.cdp-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  display: flex;
  gap: 6px;
  align-items: center;
}

.cdp-nav {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
  transition: all 0.12s ease;
}

.cdp-nav:hover {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary);
}

.cdp-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 6px;
}

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

.cdp-day {
  aspect-ratio: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  font-weight: 550;
  border-radius: 6px;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text);
  transition: background 0.12s ease, color 0.12s ease;
  padding: 0;
}

.cdp-day:hover {
  background: var(--bg-muted);
  color: var(--primary);
}

.cdp-day.cdp-day-other {
  color: var(--text-muted);
  opacity: 0.4;
}

.cdp-day.cdp-day-today {
  font-weight: 750;
  box-shadow: inset 0 0 0 1.5px var(--primary);
}

.cdp-day.cdp-day-selected {
  background: var(--primary) !important;
  color: #fff !important;
  font-weight: 750;
}

.cdp-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.cdp-footer button {
  padding: 5px 14px;
  font-size: 0.8rem;
  font-weight: 650;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.cdp-clear {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
}

.cdp-clear:hover {
  color: #dc2626;
  border-color: #dc2626;
  background: rgba(220, 38, 38, 0.08);
}

.cdp-today {
  border: 1px solid var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.cdp-today:hover {
  background: var(--primary);
  color: #fff;
}

