:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --bg-strong: #e8edf2;
  --surface: #fdfefe;
  --surface-muted: #f8fafb;
  --surface-strong: #eef3f5;
  --ink: #14202b;
  --text: #1d2a35;
  --muted: #667581;
  --muted-strong: #42505b;
  --line: #d9e1e7;
  --line-strong: #c4d0d8;
  --accent: #127b70;
  --accent-strong: #075f58;
  --accent-soft: #e1f2ef;
  --accent-quiet: #f1faf8;
  --blue: #2f6fbb;
  --blue-soft: #e8f1fb;
  --warning: #a56718;
  --warning-soft: #fff3dc;
  --danger: #a33a3a;
  --danger-soft: #fae8e8;
  --success: #18714b;
  --success-soft: #e2f4eb;
  --info: #2f6fbb;
  --info-soft: #e7f0fb;
  --professional: #6a5ca8;
  --professional-soft: #efecfb;
  --focus: #be7a18;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(20, 32, 43, 0.06);
  --shadow-md: 0 18px 45px rgba(20, 32, 43, 0.1);
  --sidebar-width: 300px;
  font-family:
    "Inter Tight", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1418;
  --bg-strong: #151d22;
  --surface: #171f25;
  --surface-muted: #1d272e;
  --surface-strong: #24313a;
  --ink: #f4f7f9;
  --text: #e8eef2;
  --muted: #9cabb5;
  --muted-strong: #bfccd4;
  --line: #2d3c45;
  --line-strong: #42535e;
  --accent: #52c7b7;
  --accent-strong: #7edacc;
  --accent-soft: #183f3b;
  --accent-quiet: #122b29;
  --blue: #8ab8f0;
  --blue-soft: #192f49;
  --warning: #e4ae5d;
  --warning-soft: #3a2c16;
  --danger: #f0a0a0;
  --danger-soft: #3a2022;
  --success: #8ad8ad;
  --success-soft: #173726;
  --info: #8ab8f0;
  --info-soft: #192f49;
  --professional: #b6a8ff;
  --professional-soft: #28233f;
  --focus: #e3ae52;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.24);
  --shadow-md: 0 18px 45px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--bg);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
  overflow-x: hidden;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: rgba(18, 123, 112, 0.16);
}

:root[data-theme="dark"] body {
  background: var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.button-link {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.62rem 0.9rem;
  color: #f7fffc;
  background: var(--accent);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  text-decoration: none;
  font-weight: 720;
  letter-spacing: 0;
  white-space: nowrap;
  touch-action: manipulation;
}

button:hover,
.button-link:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

button:active,
.button-link:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

a {
  color: var(--accent-strong);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.skip-link:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.ghost-button,
.button-link {
  color: var(--accent-strong);
  background: var(--surface);
  border-color: var(--line-strong);
  box-shadow: none;
}

.ghost-button:hover,
.button-link:hover {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.icon-button {
  display: inline-grid;
  width: 44px;
  min-width: 44px;
  padding: 0;
  place-items: center;
}

.theme-toggle-button {
  width: 38px;
  min-width: 38px;
  min-height: 38px;
  color: var(--muted-strong);
  background: var(--surface);
  border-color: var(--line-strong);
  box-shadow: none;
}

.theme-toggle-button:hover {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.theme-toggle-button svg {
  width: 18px;
  height: 18px;
}

.compact-button {
  min-height: 36px;
  padding: 0.42rem 0.62rem;
  font-size: 0.86rem;
}

.skip-link {
  position: fixed;
  z-index: 60;
  left: 1rem;
  top: 1rem;
  transform: translateY(-170%);
  padding: 0.65rem 0.85rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
}

body.keyboard-user .skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
}

body.is-login {
  min-height: 100vh;
  min-height: 100dvh;
  background: color-mix(in srgb, var(--bg) 86%, var(--accent-quiet));
}

body.is-login .skip-link,
body.is-login .main,
body.is-login .sidebar > .session-card:nth-of-type(2),
body.is-login .nav-list {
  display: none;
}

body.is-login .app-shell {
  min-height: 100vh;
  place-items: center;
  padding: clamp(1rem, 4vw, 2rem);
}

body.is-login .sidebar {
  width: min(100%, 440px);
  gap: 1rem;
  padding: 1.1rem;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(18px);
}

body.is-login .brand-lockup {
  padding: 0.25rem 0.15rem 0.9rem;
}

body.is-login .session-card {
  padding: 1.1rem;
  border-color: var(--line-strong);
  box-shadow: none;
}

body.is-login .session-card .section-heading h2 {
  font-size: 1.55rem;
}

body.is-login .session-summary {
  justify-content: center;
}

:root[data-theme="dark"] body.is-login {
  background: color-mix(in srgb, var(--bg) 88%, var(--accent-quiet));
}

:root[data-theme="dark"] body.is-login .sidebar {
  background: rgba(23, 31, 37, 0.88);
}

.sidebar {
  display: grid;
  gap: 1rem;
  align-content: start;
  padding: 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.brand-lockup {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  min-width: 0;
  padding: 0.25rem 0.15rem 0.75rem;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: inline-grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  color: #f7fffc;
  background: var(--accent);
  border-radius: var(--radius);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
  font-weight: 840;
}

.brand-lockup h1,
.section-heading h2,
.section-heading h3,
.topbar h2 {
  margin: 0;
  color: var(--ink);
  font-weight: 620;
  letter-spacing: 0;
  text-wrap: balance;
}

.brand-lockup h1 {
  font-size: 1.35rem;
  line-height: 1.1;
}

.session-card,
.view {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.session-card {
  display: grid;
  gap: 0.9rem;
  padding: 0.95rem;
}

.main {
  display: grid;
  gap: 1rem;
  align-content: start;
  width: min(100%, 1360px);
  margin: 0 auto;
  padding: clamp(0.9rem, 2.4vw, 1.6rem);
}

.topbar,
.section-heading,
.panel-heading,
.session-actions {
  display: flex;
  gap: 0.85rem;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  padding: 0.9rem 1rem;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(14px);
}

.topbar > div:first-child {
  min-width: 0;
}

body.is-authenticated .sidebar {
  background: color-mix(in srgb, var(--surface) 92%, var(--bg));
}

body.is-authenticated .sidebar > .session-card {
  display: none;
}

body.is-authenticated .brand-lockup {
  margin-bottom: 0.35rem;
}

:root[data-theme="dark"] .topbar {
  background: rgba(23, 31, 37, 0.86);
}

.topbar h2 {
  font-size: clamp(1.2rem, 2vw, 1.55rem);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.topbar-actions,
.toolbar,
.action-row,
.row-actions,
.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  min-width: 0;
}

.topbar-actions {
  justify-content: flex-end;
}

.topbar time {
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.view {
  display: none;
  padding: clamp(1rem, 2.5vw, 1.35rem);
}

.view.active {
  display: grid;
  gap: 1rem;
}

.view > .section-heading:first-child {
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--line);
}

.section-heading.compact {
  align-items: start;
}

.subheading {
  margin-top: 0.25rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 0.2rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 780;
  letter-spacing: 0.06em;
  line-height: 1.15;
  text-transform: uppercase;
}

.muted,
.form-message {
  color: var(--muted);
}

.form-message {
  min-height: 1.4em;
  margin: 0;
  font-size: 0.92rem;
}

.form-message.error,
.form-message:not(:empty) {
  color: var(--danger);
}

.form-message.success {
  color: var(--success);
}

.stack,
.form-grid {
  display: grid;
  gap: 0.8rem;
  margin-top: 0;
}

.stack.narrow {
  max-width: 560px;
}

.form-grid {
  padding: 0.95rem;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.form-grid.dense {
  padding: 0.8rem;
  background: var(--accent-quiet);
}

label {
  display: grid;
  gap: 0.35rem;
  min-width: 0;
  color: var(--muted-strong);
  font-size: 0.9rem;
  font-weight: 680;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 0.68rem 0.72rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  box-shadow: inset 0 1px 0 rgba(20, 32, 43, 0.02);
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--muted);
}

input::placeholder,
textarea::placeholder {
  color: color-mix(in srgb, var(--muted) 78%, transparent);
}

textarea {
  min-height: 104px;
  resize: vertical;
}

.checkbox-label {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  color: var(--text);
}

.checkbox-label input {
  width: 1.05rem;
  min-height: 1.05rem;
  accent-color: var(--accent);
}

.session-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.demo-login {
  display: grid;
  gap: 0.65rem;
  padding: 0.8rem;
  background: var(--accent-quiet);
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius);
}

.demo-login .muted {
  margin: 0;
}

.demo-buttons {
  display: grid;
  gap: 0.5rem;
}

.demo-buttons button {
  justify-content: space-between;
  text-align: left;
}

.search-field {
  min-width: min(100%, 300px);
}

.section-heading .toolbar .search-field + button {
  align-self: end;
}

#session-status {
  display: inline-flex;
  min-width: 0;
  min-height: 34px;
  align-items: center;
  max-width: min(34vw, 360px);
  padding: 0.38rem 0.65rem;
  overflow-wrap: anywhere;
  color: var(--muted-strong);
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 560;
}

.clinic-list,
.appointment-list,
.compact-list,
.timeline-list,
.data-table {
  display: grid;
  gap: 0.65rem;
  min-width: 0;
}

.clinic-row,
.appointment-row,
.compact-row,
.timeline-row,
.table-row {
  display: grid;
  gap: 0.42rem;
  min-width: 0;
  padding: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.clinic-row {
  background: var(--surface-muted);
}

.appointment-row {
  grid-template-columns: minmax(74px, 0.18fr) minmax(0, 1fr);
  align-items: start;
  background: color-mix(in srgb, var(--accent-soft) 28%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line));
}

.timeline-row {
  grid-template-columns: 74px minmax(0, 1fr);
  align-items: center;
}

.table-row {
  grid-template-columns: 1fr;
}

.time-pill,
.status-pill {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  justify-content: center;
  min-height: 27px;
  border-radius: 999px;
  padding: 0.25rem 0.58rem;
  font-size: 0.78rem;
  font-weight: 780;
  font-variant-numeric: tabular-nums;
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.time-pill {
  color: var(--blue);
  background: var(--blue-soft);
}

#today-appointments .time-pill {
  width: 62px;
  justify-self: center;
  align-self: center;
}

#today-appointments {
  gap: 0.62rem;
}

#today-appointments .timeline-row {
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 0.9rem;
  align-items: center;
  min-height: 86px;
  padding: 0.78rem 1rem;
  background: color-mix(in srgb, var(--surface-muted) 76%, var(--surface));
  border-color: color-mix(in srgb, var(--warning) 46%, var(--line));
  border-left: 3px solid var(--warning);
  box-shadow: none;
}

#today-appointments .timeline-row.confirmed {
  background: color-mix(in srgb, var(--success-soft) 58%, var(--surface));
  border-color: color-mix(in srgb, var(--success) 44%, var(--line));
  border-left-color: var(--success);
}

#today-appointments .timeline-row.completed {
  background: color-mix(in srgb, var(--info-soft) 58%, var(--surface));
  border-color: color-mix(in srgb, var(--info) 44%, var(--line));
  border-left-color: var(--info);
}

#today-appointments .timeline-row.cancelled,
#today-appointments .timeline-row.no_show {
  background: color-mix(in srgb, var(--danger-soft) 48%, var(--surface));
  border-color: color-mix(in srgb, var(--danger) 44%, var(--line));
  border-left-color: var(--danger);
}

#today-appointments .timeline-main,
#today-appointments .timeline-meta {
  display: flex;
  min-width: 0;
  align-items: center;
}

#today-appointments .timeline-main {
  gap: 1.05rem;
}

#today-appointments .timeline-time {
  flex: 0 0 48px;
  color: color-mix(in srgb, var(--warning) 72%, var(--muted-strong));
  font-size: 0.96rem;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
}

#today-appointments .timeline-patient {
  display: grid;
  gap: 0.55rem;
  min-width: 0;
}

#today-appointments .timeline-patient strong {
  color: var(--ink);
  font-size: 0.94rem;
  font-weight: 780;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

#today-appointments .timeline-patient span {
  font-size: 0.78rem;
}

#today-appointments .timeline-meta {
  justify-content: flex-end;
  gap: 0.9rem;
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

#today-appointments .room-chip {
  min-width: 2.2rem;
  padding: 0.22rem 0.42rem;
  color: var(--ink);
  background: color-mix(in srgb, var(--surface) 88%, var(--warning-soft));
  border-radius: 5px;
  text-align: center;
  font-weight: 720;
}

#today-appointments .status-text {
  font-size: 0.78rem;
  font-weight: 780;
}

#today-appointments .status-text.confirmed {
  color: var(--success);
}

#today-appointments .status-text.completed {
  color: var(--info);
}

#today-appointments .status-text.pending {
  color: var(--warning);
}

#today-appointments .status-text.cancelled,
#today-appointments .status-text.no_show {
  color: var(--danger);
}

#today-appointments .timeline-meta button {
  min-height: 30px;
  padding: 0.34rem 0.72rem;
  color: var(--text);
  background: var(--surface);
}

.status-pill.confirmed,
.status-pill.completed {
  color: var(--success);
  background: var(--success-soft);
}

.status-pill.cancelled,
.status-pill.no_show {
  color: var(--danger);
  background: var(--danger-soft);
}

.status-pill.pending {
  color: var(--warning);
  background: var(--warning-soft);
}

.metric-grid {
  display: grid;
  gap: 0.9rem;
}

.metric {
  position: relative;
  min-width: 0;
  padding: 1.2rem 1.3rem;
  overflow: hidden;
  border: 1px solid #f3ede6;
  background: #fdfefe;
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(80, 55, 40, 0.06);
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    transform 0.15s ease;
}

.metric:hover,
#today-appointments .timeline-row:hover {
  box-shadow:
    0 1px 3px rgba(80, 55, 40, 0.05),
    0 4px 14px rgba(80, 55, 40, 0.04);
  transform: translateY(-1px);
}

.metric::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: #c4b5a5;
}

:root[data-theme="dark"] .metric {
  background: var(--surface);
  border-color: var(--line);
}

:root[data-theme="dark"] .metric strong {
  color: var(--ink);
}

:root[data-theme="dark"] .metric span {
  color: var(--muted);
}

.metric-success {
  border-color: #f3ede6;
  background: #fdfefe;
}

.metric-success::before {
  background: #6b8f71;
}

.metric-warning {
  border-color: #f3ede6;
  background: #fdfefe;
}

.metric-warning::before {
  background: #b8924a;
}

.metric-danger {
  border-color: #f3ede6;
  background: #fdfefe;
}

.metric-danger::before {
  background: #a05555;
}

.metric-info {
  border-color: #f3ede6;
  background: #fdfefe;
}

.metric-info::before {
  background: #5a9ac4;
}

.metric-neutral {
  border-color: #f3ede6;
  background: #fdfefe;
}

.metric-neutral::before {
  background: #9e8b7a;
}

.metric strong {
  display: block;
  color: #2b241e;
  font-size: 2rem;
  font-weight: 560;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.metric-success strong {
  color: #4a7550;
}

.metric-warning strong {
  color: #8f6f30;
}

.metric-danger strong {
  color: #a05555;
}

.metric-info strong {
  color: #5a9ac4;
}

.metric span,
.compact-row span,
.appointment-row span,
.timeline-row span,
.table-row span {
  display: block;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.metric span {
  margin-top: 0.35rem;
  color: #9a8a7c;
  font-size: 0.64rem;
  font-weight: 760;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

:root[data-theme="dark"] #today-appointments .timeline-row {
  background: color-mix(in srgb, var(--surface) 88%, var(--warning-soft));
  border-color: color-mix(in srgb, var(--warning) 42%, var(--line));
}

:root[data-theme="dark"] #today-appointments .timeline-row.confirmed {
  background: color-mix(in srgb, var(--surface) 86%, var(--success-soft));
  border-color: color-mix(in srgb, var(--success) 44%, var(--line));
}

:root[data-theme="dark"] #today-appointments .timeline-row.completed {
  background: color-mix(in srgb, var(--surface) 86%, var(--info-soft));
  border-color: color-mix(in srgb, var(--info) 44%, var(--line));
}

:root[data-theme="dark"] #today-appointments .timeline-row.cancelled,
:root[data-theme="dark"] #today-appointments .timeline-row.no_show {
  background: color-mix(in srgb, var(--surface) 86%, var(--danger-soft));
  border-color: color-mix(in srgb, var(--danger) 44%, var(--line));
}

:root[data-theme="dark"] #today-appointments .timeline-patient strong,
:root[data-theme="dark"] #today-appointments .room-chip {
  color: var(--ink);
}

:root[data-theme="dark"] #today-appointments .timeline-time,
:root[data-theme="dark"] #today-appointments .timeline-meta,
:root[data-theme="dark"] #today-appointments .timeline-info {
  color: var(--muted);
}

:root[data-theme="dark"] #today-appointments .timeline-meta button {
  color: var(--text);
  background: var(--surface-muted);
  border-color: var(--line);
}

.compact-row strong,
.appointment-row strong,
.timeline-row strong,
.table-row strong {
  color: var(--ink);
  overflow-wrap: anywhere;
}

.patient-row,
.professional-row {
  align-items: center;
}

.danger-action {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, var(--line));
}

.danger-action:hover {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: var(--danger);
}

.schedule-board {
  min-width: 0;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overscroll-behavior-x: contain;
  overscroll-behavior-y: auto;
  touch-action: pan-x pinch-zoom;
}

.schedule-head,
.schedule-row {
  display: grid;
  grid-template-columns: 74px repeat(var(--schedule-columns), minmax(min(220px, calc(100vw - 100px)), 1fr));
  min-width: calc(74px + (var(--schedule-columns) * 220px));
}

.schedule-head {
  position: sticky;
  z-index: 4;
  top: 0;
  color: #f7fffc;
  background: var(--accent-strong);
  border-bottom: 1px solid var(--line);
}

.schedule-time-head,
.schedule-head-cell {
  min-height: 44px;
  padding: 0.8rem 0.9rem;
  border-right: 1px solid rgba(255, 255, 255, 0.16);
  font-size: 0.72rem;
  font-weight: 820;
  letter-spacing: 0.14em;
  text-align: center;
  text-transform: uppercase;
}

.schedule-time-head {
  color: rgba(255, 255, 255, 0.76);
}

.schedule-row {
  min-height: 72px;
  border-bottom: 1px solid var(--line);
}

.schedule-row:nth-child(even) {
  background: color-mix(in srgb, var(--surface-muted) 54%, transparent);
}

.schedule-time {
  padding: 0.72rem 0.55rem;
  color: var(--muted-strong);
  border-right: 1px solid var(--line);
  font-size: 0.82rem;
  font-weight: 780;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.schedule-cell {
  display: grid;
  align-content: start;
  gap: 0.42rem;
  min-width: 0;
  min-height: 72px;
  padding: 0.48rem;
  border-right: 1px solid var(--line);
  cursor: pointer;
}

.schedule-cell:hover {
  background: var(--accent-quiet);
}

.schedule-appointment {
  display: grid;
  gap: 0.4rem;
  min-width: 0;
  padding: 0.62rem 0.7rem;
  background: color-mix(in srgb, var(--warning-soft) 42%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--warning) 32%, var(--line));
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.schedule-appointment span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  overflow-wrap: anywhere;
  max-width: 100%;
}

.schedule-appointment strong {
  color: var(--ink);
  font-size: 0.92rem;
  overflow-wrap: anywhere;
  max-width: 100%;
}

.schedule-appointment.confirmed {
  background: color-mix(in srgb, var(--success-soft) 62%, var(--surface));
  border-color: color-mix(in srgb, var(--success) 30%, var(--line));
}

.schedule-appointment.completed {
  background: color-mix(in srgb, var(--info-soft) 62%, var(--surface));
  border-color: color-mix(in srgb, var(--info) 30%, var(--line));
}

.schedule-appointment.cancelled,
.schedule-appointment.no_show {
  background: color-mix(in srgb, var(--danger-soft) 54%, var(--surface));
  border-color: color-mix(in srgb, var(--danger) 30%, var(--line));
}

.schedule-actions {
  gap: 0.35rem;
}

.nav-list {
  display: grid;
  gap: 0.25rem;
}

.nav-item {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  gap: 0.55rem;
  align-items: center;
  min-height: 42px;
  border-color: transparent;
  color: var(--muted-strong);
  background: transparent;
  box-shadow: none;
  text-align: left;
  font-weight: 560;
}

.nav-item:hover,
.nav-item.active {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: transparent;
}

.nav-item.active {
  background: var(--accent-soft);
  border-color: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 680;
}

.nav-item kbd {
  min-width: 1.35rem;
  padding: 0.1rem 0.28rem;
  color: var(--muted);
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  text-align: center;
  font-size: 0.7rem;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

.dialog {
  width: min(760px, calc(100vw - 2rem));
  max-height: min(820px, calc(100dvh - 2rem));
  max-height: min(820px, calc(100vh - 2rem));
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  overscroll-behavior: contain;
}

.dialog::backdrop {
  background: rgba(7, 15, 20, 0.58);
  backdrop-filter: blur(4px);
}

.dialog-card {
  display: grid;
  gap: 1rem;
  padding: clamp(1rem, 3vw, 1.4rem);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.dialog-body {
  display: grid;
  gap: 0.85rem;
  max-height: min(590px, calc(100dvh - 220px));
  max-height: min(590px, calc(100vh - 220px));
  overflow: auto;
  overscroll-behavior: contain;
  padding-right: 0.1rem;
}

.dialog-body .form-grid {
  margin-top: 0;
  padding: 0;
  background: transparent;
  border: 0;
}

@media (prefers-reduced-motion: no-preference) {
  button,
  .button-link,
  .nav-item,
  input,
  select,
  textarea,
  .clinic-row,
  .appointment-row,
  .compact-row,
  .timeline-row,
  .table-row {
    transition:
      background-color 0.16s ease,
      border-color 0.16s ease,
      color 0.16s ease,
      box-shadow 0.16s ease,
      opacity 0.16s ease,
      transform 0.16s ease;
  }
}

@media (hover: hover) {
  .appointment-row:hover,
  .compact-row:hover,
  .timeline-row:hover,
  .table-row:hover {
    border-color: var(--line-strong);
    box-shadow: 0 10px 24px rgba(20, 32, 43, 0.08);
    transform: translateY(-1px);
  }
}

@media (min-width: 760px) {
  .app-shell {
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  }

.sidebar {
  position: sticky;
  top: 0;
  min-height: 100vh;
  min-height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: auto;
  border-right: 1px solid var(--line);
  border-bottom: 0;
}

  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid > button,
  .form-grid .form-message,
  .wide-field {
    grid-column: 1 / -1;
  }

  .metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .table-row {
    grid-template-columns: 1.05fr 0.9fr 0.9fr auto;
    align-items: center;
  }

  .patient-row {
    grid-template-columns: minmax(190px, 1.2fr) minmax(145px, 0.7fr) minmax(210px, 1.2fr) minmax(180px, 1fr) auto;
  }

  .professional-row {
    grid-template-columns: minmax(190px, 1.15fr) minmax(180px, 1fr) minmax(145px, 0.8fr) minmax(170px, 0.9fr) auto;
  }
}

@media (min-width: 1080px) {
  .appointment-list {
    grid-template-columns: 1fr;
  }

  .view[data-section="patients"].active,
  .view[data-section="professionals"].active,
  .view[data-section="admin"].active {
    grid-template-columns: minmax(330px, 0.36fr) minmax(0, 1fr);
    align-items: start;
  }

  .view[data-section="patients"].active {
    grid-template-columns: 1fr;
  }

  .view[data-section="patients"] > .section-heading,
  .view[data-section="professionals"] > .section-heading,
  .view[data-section="admin"] > .section-heading {
    grid-column: 1 / -1;
  }

  .view[data-section="patients"] #patient-form {
    display: none;
  }

  .view[data-section="patients"] #patients,
  .view[data-section="professionals"] #professionals,
  .view[data-section="admin"] #memberships {
    grid-column: 2;
    grid-row: 2 / span 4;
  }

  .view[data-section="patients"] #patients {
    grid-column: 1;
    grid-row: auto;
  }

  .view[data-section="professionals"] #rooms,
  .view[data-section="professionals"] #availability,
  .view[data-section="professionals"] #blocks,
  .view[data-section="admin"] #clinics {
    grid-column: 2;
  }
}

@media (max-width: 759px) {
  body.is-authenticated .sidebar {
    gap: 0.7rem;
  }

  body.is-authenticated .brand-lockup {
    padding-bottom: 0.55rem;
  }

  body.is-authenticated .session-card {
    padding: 0.8rem;
  }

  body.is-authenticated .session-card .section-heading h2 {
    font-size: 1.05rem;
  }

  body.is-authenticated .clinic-row {
    padding: 0.75rem;
  }

  body.is-authenticated .nav-list {
    grid-template-columns: 1fr;
    gap: 0.35rem;
  }

  body.is-authenticated .nav-item {
    grid-template-columns: 22px minmax(0, 1fr);
  }

  body.is-authenticated .nav-item span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  body.is-authenticated .nav-item kbd {
    display: none;
  }

  .topbar,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar,
  .topbar-actions,
  .action-row,
  .row-actions,
  .dialog-actions {
    width: 100%;
  }

  .toolbar > *,
  .action-row > *,
  .dialog-actions > button {
    flex: 1 1 auto;
  }

  .topbar-actions > * {
    flex: 0 1 auto;
  }

  #session-status {
    max-width: 100%;
  }

  .appointment-row,
  .timeline-row {
    grid-template-columns: 1fr;
  }

  #today-appointments .timeline-row {
    grid-template-columns: 1fr;
  }

  #today-appointments .timeline-main,
  #today-appointments .timeline-meta {
    width: 100%;
  }

  #today-appointments .timeline-meta {
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 0.55rem;
    white-space: normal;
  }
}

body.is-login .app-shell {
  grid-template-columns: 1fr;
}

body.is-login .sidebar {
  position: static;
  min-height: auto;
  max-height: none;
  overflow: visible;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

/* ── Navigation groups ── */

.nav-group {
  display: grid;
  gap: 0.18rem;
}

.nav-sep {
  width: 100%;
  height: 1px;
  margin: 0.35rem 0;
  background: var(--line);
  border: 0;
}

/* ── Tab bar ── */

.tab-bar {
  display: flex;
  gap: 0.2rem;
  padding: 0.25rem;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.tab-item {
  min-height: 44px;
  padding: 0.5rem 1rem;
  color: var(--muted-strong);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  box-shadow: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
  transition: background-color 0.16s ease, color 0.16s ease;
}

.tab-item:hover {
  color: var(--text);
  background: var(--surface);
}

.tab-item.active,
.tab-item[aria-selected="true"] {
  color: var(--accent-strong);
  background: var(--surface);
  border-color: var(--line);
  box-shadow: var(--shadow-sm);
}

.tab-panel[hidden] {
  display: none !important;
}

.tab-panel {
  display: grid;
  gap: 1rem;
}

/* ── Toolbar separator ── */

.toolbar-sep {
  display: inline-block;
  width: 1px;
  height: 28px;
  background: var(--line);
  align-self: center;
  margin: 0 0.2rem;
}

/* ── View toggle icons ── */

.icon-button.active {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.icon-button svg {
  display: block;
}

/* ── Active filters ── */

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  min-height: 0;
}

.active-filters:empty {
  display: none;
}

.filter-badge {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
  min-height: 44px;
  padding: 0.25rem 0.45rem 0.25rem 0.65rem;
  color: var(--accent-strong);
  background: var(--accent-quiet);
  border: 1px solid var(--accent-soft);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 640;
}

.filter-badge button {
  min-height: 44px;
  width: 44px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  box-shadow: none;
  font-size: 1rem;
  line-height: 1;
  display: inline-grid;
  place-items: center;
}

.filter-badge button:hover {
  color: var(--danger);
}

/* ── Integration cards ── */

.integration-cards {
  display: grid;
  gap: 1rem;
}

.integration-card {
  display: grid;
  gap: 0.8rem;
  padding: 1.05rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.integration-card .section-heading.compact {
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--line);
}

@media (min-width: 900px) {
  .integration-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ── Empty states with CTA ── */

.empty-state {
  display: grid;
  gap: 0.75rem;
  justify-items: center;
  padding: 2.5rem 1.5rem;
  text-align: center;
  background: var(--surface-muted);
  border: 2px dashed var(--line);
  border-radius: var(--radius);
}

.empty-state-icon {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 50%;
}

.empty-state-icon svg {
  width: 24px;
  height: 24px;
}

.empty-state p,
.empty-state span {
  max-width: 360px;
  color: var(--muted);
  font-size: 0.92rem;
}

.empty-state strong {
  max-width: 420px;
  color: var(--ink);
  font-size: 0.98rem;
  font-weight: 720;
}

/* ── Loading skeleton ── */

.skeleton {
  min-height: 1em;
  background: var(--surface-strong);
  border-radius: var(--radius-sm);
  animation: skeleton-shimmer 1.8s ease-in-out infinite;
}

@keyframes skeleton-shimmer {
  0%,
  100% {
    opacity: 0.5;
  }
  50% {
    opacity: 0.85;
  }
}

.skeleton-row {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr) auto;
  gap: 0.9rem;
  align-items: center;
  min-height: 64px;
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.skeleton-row .skeleton:first-child {
  width: 54px;
  height: 1.1rem;
}

.skeleton-row .skeleton:nth-child(2) {
  height: 1rem;
}

.skeleton-row .skeleton:last-child {
  width: 86px;
  height: 1rem;
}

/* ── Button loading state ── */

button[disabled].is-loading::after {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.55s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Performance: content-visibility ── */

.compact-list,
.data-table,
.appointment-list,
.timeline-list {
  content-visibility: auto;
  contain-intrinsic-size: auto 400px;
}

/* ── Dialog refinements ── */

#entity-dialog[aria-modal="true"] {
  overscroll-behavior: contain;
}

/* ── Status toast (inline success) ── */

.toast-success {
  display: inline-flex;
  gap: 0.5rem;
  align-items: center;
  min-height: 38px;
  padding: 0.5rem 0.8rem;
  color: var(--success);
  background: var(--success-soft);
  border: 1px solid var(--success);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 640;
  animation: toast-in 0.3s ease-out;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Quick action button in rows ── */

.quick-action {
  min-height: 44px;
  padding: 0.4rem 0.65rem;
  font-size: 0.82rem;
  font-weight: 680;
}

/* ── Responsive nav groups on mobile ── */

@media (max-width: 759px) {
  .nav-group {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .nav-sep {
    display: none;
  }

  .tab-bar {
    overflow-x: auto;
    white-space: nowrap;
  }

  .toolbar-sep {
    display: none;
  }

  .integration-cards {
    grid-template-columns: 1fr;
  }

  .dialog {
    width: calc(100vw - 1rem);
    max-height: calc(100dvh - 1rem);
    max-height: calc(100vh - 1rem);
    margin: 0.5rem;
  }

  .dialog-body {
    max-height: calc(100dvh - 180px);
    max-height: calc(100vh - 180px);
  }

  .schedule-board {
    font-size: 0.88rem;
  }

  .schedule-head-cell,
  .schedule-time-head {
    padding: 0.6rem 0.65rem;
    font-size: 0.68rem;
  }
}

/* ── Improved focus ring for keyboard ── */

body.keyboard-user .tab-item:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: -2px;
}

/* ── Row hover refinement ── */

.compact-row,
.appointment-row,
.timeline-row,
.table-row {
  display: grid;
  gap: 0.42rem;
  min-width: 0;
  padding: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ── Dark mode for new components ── */

:root[data-theme="dark"] .tab-bar {
  background: var(--surface-strong);
  border-color: var(--line);
}

:root[data-theme="dark"] .tab-item.active,
:root[data-theme="dark"] .tab-item[aria-selected="true"] {
  background: var(--surface-muted);
}

:root[data-theme="dark"] .empty-state {
  background: var(--surface-strong);
  border-color: var(--line);
}

:root[data-theme="dark"] .filter-badge {
  background: var(--accent-soft);
  border-color: transparent;
}

:root[data-theme="dark"] .integration-card {
  background: var(--surface-muted);
}

/* ── Reduce motion ── */

@media (prefers-reduced-motion: reduce) {
  .skeleton {
    animation: none;
    opacity: 0.6;
  }

  button[disabled].is-loading::after {
    animation: none;
    opacity: 0.6;
  }

  .toast-success {
    animation: none;
  }
}
