:root {
  --primary: #10b8b0;
  --primary-dark: #078a85;
  --ink: #17212b;
  --muted: #697586;
  --line: #d9e1e8;
  --soft: #f5f9fa;
  --panel: #ffffff;
  --danger: #b42318;
  --ok: #0f766e;
  --shadow: 0 16px 40px rgba(21, 42, 52, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: #eef5f6;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  border: 0;
  cursor: pointer;
}

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

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(360px, 1.05fr);
  background:
    linear-gradient(135deg, rgba(16, 184, 176, 0.14), rgba(255, 255, 255, 0.72)),
    url("https://images.unsplash.com/photo-1519494026892-80bbd2d6fd0d?auto=format&fit=crop&w=1500&q=80") center/cover;
}

.brand-pane {
  padding: 48px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: white;
  background: rgba(0, 80, 82, 0.46);
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
  font-size: 1.1rem;
}

.brand-symbol {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  font-weight: 900;
}

.brand-pane h1 {
  max-width: 560px;
  margin: 0;
  font-size: clamp(2.4rem, 4.2vw, 4.8rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.brand-pane p {
  max-width: 540px;
  color: rgba(255, 255, 255, 0.88);
  font-size: 1.04rem;
  line-height: 1.7;
}

.auth-panel {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
  background: rgba(255, 255, 255, 0.88);
}

.auth-card,
.panel,
.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-card {
  width: min(100%, 520px);
  padding: 28px;
}

.auth-tabs,
.segmented {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.auth-tabs button,
.segmented button {
  flex: 1;
  padding: 10px 12px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
}

.auth-tabs button.active,
.segmented button.active {
  color: var(--ink);
  background: white;
  box-shadow: 0 1px 6px rgba(20, 40, 60, 0.08);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

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

label {
  color: #344054;
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: white;
  outline: 0;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(16, 184, 176, 0.16);
}

.primary,
.secondary,
.ghost,
.danger {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 7px;
  font-weight: 800;
}

.primary.compact,
.secondary.compact,
.ghost.compact,
.danger.compact {
  min-height: 30px;
  padding: 6px 9px;
  border-radius: 6px;
  font-size: 0.78rem;
}

.primary {
  background: var(--primary);
  color: white;
}

.secondary {
  background: #e6fbfa;
  color: var(--primary-dark);
}

.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

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

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 268px 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  background: #ffffff;
  border-right: 1px solid var(--line);
}

.nav {
  display: grid;
  gap: 8px;
  margin-top: 28px;
}

.nav button {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 7px;
  color: #475467;
  background: transparent;
  text-align: left;
}

.nav button.active,
.nav button:hover {
  color: var(--ink);
  background: #eaf8f7;
}

.main {
  min-width: 0;
  padding: 26px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.clinic-switch {
  min-width: 250px;
  display: grid;
  gap: 6px;
}

.clinic-switch span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.topbar h2,
.panel h3,
.modal h3 {
  margin: 0;
  letter-spacing: 0;
}

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

.grid {
  display: grid;
  gap: 16px;
}

.stats {
  grid-template-columns: repeat(5, minmax(120px, 1fr));
}

.dashboard-charts {
  display: grid;
  grid-template-columns: minmax(360px, 1.15fr) minmax(320px, 0.85fr);
  gap: 16px;
  margin-top: 16px;
}

.chart-panel {
  min-height: 320px;
}

.chart-wrap {
  display: grid;
  gap: 12px;
}

.chart-wrap svg {
  width: 100%;
  height: 230px;
  display: block;
}

.chart-axis {
  stroke: #98a2b3;
  stroke-width: 1;
}

.chart-grid {
  stroke: #e4ebf0;
  stroke-width: 1;
}

.chart-label {
  fill: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chart-legend i {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.bar-chart {
  display: grid;
  gap: 14px;
}

.bar-row {
  display: grid;
  gap: 8px;
}

.bar-row strong {
  font-size: 0.9rem;
}

.bar-stack {
  display: grid;
  gap: 7px;
}

.bar-line {
  display: grid;
  grid-template-columns: 76px 1fr 42px;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 0.78rem;
}

.bar-line em {
  color: var(--ink);
  font-style: normal;
  font-weight: 800;
  text-align: right;
}

.bar-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf3f5;
}

.bar-track i {
  height: 100%;
  display: block;
  border-radius: inherit;
}

.bar-doctors {
  background: #10b8b0;
}

.bar-patients {
  background: #344054;
}

.bar-labs {
  background: #7c3aed;
}

.bar-specialists {
  background: #f59e0b;
}

/* ── Chart interactivity ── */
.chart-wrap[data-interactive-line] {
  position: relative;
}

.chart-tooltip {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  background: #1e293b;
  color: #f1f5f9;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.78rem;
  line-height: 1.6;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0,0,0,0.22);
  animation: tooltipIn 0.15s ease;
}

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

.tooltip-date {
  font-weight: 800;
  margin-bottom: 4px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
}

.tooltip-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tooltip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chart-crosshair {
  stroke: var(--muted);
  stroke-width: 1;
  stroke-dasharray: 4 3;
  opacity: 0.5;
  pointer-events: none;
}

.chart-dot {
  transition: r 0.15s ease, opacity 0.2s ease;
  cursor: pointer;
}

.chart-line {
  transition: opacity 0.25s ease;
}

.chart-area {
  transition: opacity 0.25s ease;
}

.chart-line, .chart-area {
  pointer-events: none;
}

.chart-legend-item {
  transition: opacity 0.2s ease;
  user-select: none;
}

.chart-legend-item:hover {
  opacity: 0.75;
}

.chart-legend-item--off {
  opacity: 0.35;
  text-decoration: line-through;
}

[data-interactive-bars] {
  position: relative;
}

[data-interactive-bars] .chart-tooltip {
  position: absolute;
}

.bar-line {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  border-radius: 6px;
  padding: 2px 6px;
  margin: 0 -6px;
  cursor: default;
}

.bar-line--highlight {
  background: rgba(16, 184, 176, 0.07);
  box-shadow: inset 0 0 0 1px rgba(16, 184, 176, 0.18);
}

.bar-track i {
  transition: width 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

.chart-wrap svg {
  transition: filter 0.2s ease;
}

.chart-wrap:hover svg {
  filter: saturate(1.08);
}

.dashboard-controls {
  display: flex;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}

.inline-filter {
  min-width: 220px;
  display: grid;
  gap: 6px;
}

.stat {
  padding: 18px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stat strong {
  display: block;
  margin-top: 10px;
  font-size: 2rem;
}

.panel {
  padding: 18px;
}

.panel + .panel {
  margin-top: 16px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: #475467;
  font-size: 0.78rem;
  text-transform: uppercase;
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ghost.compact.active {
  color: var(--ink);
  background: #eaf8f7;
  border-color: rgba(16, 184, 176, 0.35);
}

.profile-cell,
.patient-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.patient-head {
  margin-bottom: 14px;
}

.avatar {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid var(--line);
  object-fit: cover;
  background: #e6fbfa;
  color: var(--primary-dark);
  font-size: 0.82rem;
  font-weight: 900;
}

.avatar.large {
  width: 72px;
  height: 72px;
  font-size: 1.1rem;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-bottom: 14px;
}

.appointment-filters {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(180px, 0.35fr) minmax(180px, 0.35fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.appointment-filter-actions {
  align-items: end;
  padding-bottom: 1px;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.85fr) minmax(320px, 1.15fr);
  gap: 16px;
}

.section-tabs {
  margin-bottom: 16px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.pagination label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.pagination select {
  width: auto;
  min-height: 34px;
  padding: 6px 28px 6px 9px;
}

.readonly-box {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.readonly-box span {
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.dictation-button {
  justify-self: start;
  margin-top: -4px;
}

.timeline {
  display: grid;
  gap: 12px;
}

.entry {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.entry h4 {
  margin: 0 0 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eaf8f7;
  color: var(--ok);
  font-size: 0.78rem;
  font-weight: 800;
}

.order-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.order-summary div {
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.order-summary strong,
.order-summary span {
  display: block;
}

.order-summary strong {
  font-size: 1.15rem;
}

.order-summary span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(9, 30, 41, 0.46);
  z-index: 20;
}

.modal {
  width: min(920px, 100%);
  max-height: 92vh;
  overflow: auto;
  padding: 20px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  padding: 13px 15px;
  border-radius: 8px;
  color: white;
  background: #102a35;
  box-shadow: var(--shadow);
  z-index: 30;
}

.mobile-bar {
  display: none;
}

.print-header {
  display: none;
}

@media (max-width: 980px) {
  .auth-shell,
  .app-shell,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .brand-pane {
    min-height: 42vh;
  }

  .auth-panel {
    min-height: auto;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 286px;
    transform: translateX(-105%);
    transition: transform 180ms ease;
    z-index: 15;
  }

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

  .mobile-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: white;
    border-bottom: 1px solid var(--line);
  }

  .main {
    padding: 16px;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-charts {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .brand-pane,
  .auth-panel {
    padding: 22px;
  }

  .form-grid,
  .search-row,
  .appointment-filters,
  .order-summary,
  .dashboard-charts,
  .stats {
    grid-template-columns: 1fr;
  }

  .topbar,
  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .clinic-switch {
    width: 100%;
  }

  .pagination {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media print {
  body {
    background: white;
  }

  .sidebar,
  .topbar,
  .mobile-bar,
  .row-actions,
  .no-print,
  .toast {
    display: none !important;
  }

  .app-shell,
  .detail-grid {
    display: block;
  }

  .main {
    padding: 0;
  }

  .panel,
  .entry,
  .stat {
    box-shadow: none;
    border-color: #ccd5dd;
    break-inside: avoid;
  }

  .print-header {
    display: block;
    margin-bottom: 16px;
  }
}
