:root {
  --navy: #102a43;
  --navy-2: #173f5f;
  --teal: #087f8c;
  --teal-dark: #06656f;
  --teal-pale: #e6f5f5;
  --blue-pale: #eff6ff;
  --ink: #203040;
  --muted: #687886;
  --line: #dfe7ec;
  --surface: #ffffff;
  --canvas: #f5f8fa;
  --danger: #b42318;
  --warning: #9a6700;
  --success: #18794e;
  --radius: 16px;
  --shadow: 0 14px 45px rgba(16, 42, 67, 0.08);
}

* { box-sizing: border-box; }
html { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--canvas); }
body { margin: 0; min-height: 100vh; font-size: 15px; line-height: 1.5; }
a { color: var(--teal-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 7px; color: var(--navy); font-size: clamp(1.8rem, 4vw, 2.4rem); line-height: 1.15; letter-spacing: -0.035em; }
h2 { margin-bottom: 6px; color: var(--navy); font-size: 1.08rem; }
p { color: var(--muted); }
small { display: block; color: var(--muted); }
code { padding: 2px 6px; border-radius: 5px; background: #edf2f5; }

.app-shell { padding-left: 244px; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; display: flex; width: 244px; flex-direction: column; padding: 28px 18px 20px; color: #dce8ef; background: linear-gradient(165deg, var(--navy) 0%, #0b3544 100%); box-shadow: 8px 0 32px rgba(16,42,67,.08); }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 9px 24px; color: #fff; font-size: 1.15rem; font-weight: 760; letter-spacing: -.02em; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; width: 36px; height: 36px; place-items: center; flex: 0 0 auto; border-radius: 11px; color: #fff; background: linear-gradient(135deg, #16a3aa, #087f8c); box-shadow: 0 8px 22px rgba(8,127,140,.3); font-weight: 800; }
.clinic-name { overflow: hidden; margin: 0 9px 15px; color: #91aebd; font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-overflow: ellipsis; text-transform: uppercase; white-space: nowrap; }
.language-switcher { margin: 0 9px 15px; }
.language-switcher button { width: 100%; min-height: 36px; padding: 6px 10px; border: 1px solid rgba(255,255,255,.2); border-radius: 8px; color: #e7f4f5; background: rgba(255,255,255,.07); cursor: pointer; font-weight: 700; }
.language-switcher button:hover, .language-switcher button:focus-visible { border-color: #49c7ca; background: rgba(32,193,195,.17); }
.sidebar nav { display: grid; gap: 5px; }
.sidebar nav a { padding: 10px 12px; border-radius: 9px; color: #c8d8e0; font-weight: 590; }
.sidebar nav a:hover { color: #fff; background: rgba(255,255,255,.07); text-decoration: none; }
.sidebar nav a.active { color: #fff; background: rgba(32,193,195,.17); box-shadow: inset 3px 0 #29c2c4; }
.sidebar-user { display: flex; align-items: center; gap: 10px; margin-top: auto; padding: 15px 8px 10px; border-top: 1px solid rgba(255,255,255,.09); }
.sidebar-user strong { display: block; overflow: hidden; max-width: 140px; color: #fff; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user small { color: #91aebd; font-size: .75rem; text-transform: capitalize; }
.avatar { display: inline-grid; width: 34px; height: 34px; place-items: center; flex: 0 0 auto; border-radius: 50%; color: var(--teal-dark); background: var(--teal-pale); font-size: .76rem; font-weight: 800; }
.link-button { padding: 7px 8px; border: 0; color: #91aebd; background: transparent; cursor: pointer; }
.link-button:hover { color: #fff; }
.menu-button { display: none; }
.main-content { width: min(1240px, 100%); min-height: calc(100vh - 50px); margin: 0 auto; padding: 42px clamp(24px, 4vw, 58px); }
.footer { padding: 12px 30px 24px; color: #8b98a3; font-size: .76rem; text-align: center; }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 25px; margin-bottom: 27px; }
.page-header p { margin-bottom: 0; }
.page-header.compact { margin-bottom: 20px; }
.eyebrow { display: block; margin-bottom: 7px; color: var(--teal); font-size: .72rem; font-weight: 800; letter-spacing: .105em; text-transform: uppercase; }
.header-actions { display: flex; align-items: center; gap: 10px; }

.button { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; padding: 10px 17px; border: 1px solid var(--teal); border-radius: 9px; color: #fff; background: var(--teal); box-shadow: 0 6px 18px rgba(8,127,140,.13); font-weight: 700; cursor: pointer; }
.button:hover { border-color: var(--teal-dark); color: #fff; background: var(--teal-dark); text-decoration: none; }
.button:focus-visible, a:focus-visible, .link-button:focus-visible, .menu-button:focus-visible { outline: 3px solid #f4b740; outline-offset: 3px; }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button-secondary { border-color: var(--line); color: var(--navy); background: #fff; box-shadow: none; }
.button-secondary:hover { border-color: #b8c7d1; color: var(--navy); background: #f8fafb; }
.button-danger { border-color: #f3c4be; color: var(--danger); background: #fff; box-shadow: none; }
.button-danger:hover { border-color: var(--danger); color: #fff; background: var(--danger); }
.button-small { min-height: 35px; padding: 6px 10px; font-size: .78rem; }
.button-wide { width: 100%; }
.text-link { align-self: center; font-weight: 650; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; margin-bottom: 22px; }
.stat-card, .panel, .error-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.stat-card { min-height: 142px; padding: 21px; }
.stat-card span { display: block; color: var(--muted); font-size: .81rem; font-weight: 650; }
.stat-card strong { display: block; margin: 7px 0 3px; color: var(--navy); font-size: 2.15rem; line-height: 1.1; letter-spacing: -.04em; }
.stat-card strong.money { font-size: 1.7rem; }
.stat-card small { font-size: .76rem; }
.panel { margin-bottom: 22px; padding: 22px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.panel-header h2, .panel-header p { margin-bottom: 0; }
.panel-header a { font-weight: 700; }
.dashboard-filters { padding-top: 16px; padding-bottom: 16px; }
.stat-card-unavailable { border-style: dashed; background: #fbfcfd; }
.stat-card-unavailable strong { color: var(--muted); }

.queue-list { display: grid; gap: 10px; }
.queue-card { display: grid; grid-template-columns: 90px minmax(220px, 1fr) auto auto; align-items: center; gap: 16px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.queue-card:hover { border-color: #bfd0d8; background: #fbfdfd; }
.queue-time strong, .queue-person strong { display: block; color: var(--navy); }
.queue-time small, .queue-person small { margin-top: 2px; }
.queue-person > a:hover { text-decoration-thickness: 2px; }
.queue-status { justify-self: start; }
.queue-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.queue-actions form { margin: 0; }
.wait-indicator { display: inline-flex; margin-top: 7px; padding: 3px 7px; border-radius: 6px; color: #8a4b08; background: #fff4df; font-size: .74rem; font-weight: 760; }
.information-note { margin-bottom: 22px; padding: 16px 18px; border: 1px solid #cfe2eb; border-radius: 12px; background: #f1f8fb; }
.information-note strong { color: var(--navy); }
.information-note p { margin: 4px 0 0; }
.operational-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; margin-bottom: 22px; }
.operational-grid > .panel { margin: 0; }
.action-list { display: grid; gap: 10px; }
.action-list > a { display: grid; gap: 3px; padding: 14px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); }
.action-list > a:hover { border-color: var(--teal); background: var(--teal-pale); text-decoration: none; }
.action-list span { color: var(--muted); font-size: .8rem; }
.compact-empty { padding: 25px 10px; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th { padding: 10px 12px; border-bottom: 1px solid var(--line); color: #788691; font-size: .7rem; letter-spacing: .07em; text-transform: uppercase; white-space: nowrap; }
td { padding: 14px 12px; border-bottom: 1px solid #edf1f3; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcfd; }
td > a:not(.person) { font-weight: 720; }
.person { display: flex; align-items: center; gap: 10px; color: var(--ink); }
.person:hover { text-decoration: none; }
.person strong { display: block; }
.empty-state { padding: 55px 20px; text-align: center; }
.empty-state strong { display: block; margin-bottom: 5px; color: var(--navy); font-size: 1.08rem; }
.empty-state p { margin-bottom: 0; }

.badge { display: inline-flex; padding: 5px 9px; border-radius: 999px; color: #37505d; background: #eef3f5; font-size: .69rem; font-weight: 780; white-space: nowrap; }
.badge-active, .badge-completed, .badge-confirmed { color: var(--success); background: #e9f7ef; }
.badge-trial, .badge-scheduled { color: #175cd3; background: #edf4ff; }
.badge-checked-in { color: #6941c6; background: #f4f0ff; }
.badge-waiting { color: #8a4b08; background: #fff4df; }
.badge-in-consultation { color: #075985; background: #e7f6ff; }
.badge-cancelled, .badge-suspended, .badge-archived, .badge-inactive { color: var(--danger); background: #fff0ee; }
.badge-no-show { color: var(--warning); background: #fff6df; }

label { display: grid; gap: 7px; color: #425563; font-size: .8rem; font-weight: 680; }
input, select, textarea { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid #cfdbe2; border-radius: 8px; color: var(--ink); background: #fff; outline: 0; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(8,127,140,.11); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.form-panel { max-width: 920px; }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 5px; }
.form-section { grid-column: span 2; padding-top: 10px; border-bottom: 1px solid var(--line); }
.form-section p { margin-bottom: 10px; }
.checkbox { display: flex; align-items: center; gap: 9px; align-self: end; min-height: 42px; }
.checkbox input { width: 17px; min-height: 17px; accent-color: var(--teal); }
.stack-form { display: grid; gap: 15px; }
.filter-row, .search-row, .inline-form { display: flex; align-items: flex-end; gap: 12px; }
.filter-row { flex-wrap: wrap; }
.filter-row label { min-width: 165px; }
.search-input { flex: 1; }
.inline-form select { min-width: 110px; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(300px, .85fr); gap: 22px; }
.detail-grid .panel { margin: 0; }
.span-wide { grid-column: span 2; }
.definition-list { margin: 16px 0 0; }
.definition-list > div { display: grid; grid-template-columns: 125px 1fr; gap: 14px; padding: 12px 0; border-bottom: 1px solid #edf1f3; }
.definition-list > div:last-child { border-bottom: 0; }
.definition-list dt { color: var(--muted); font-size: .78rem; }
.definition-list dd { margin: 0; font-weight: 600; }
.definition-list dd small { margin-top: 2px; }
.timeline { margin-top: 25px; border-top: 1px solid var(--line); padding-top: 15px; }
.timeline > div { display: flex; gap: 10px; padding: 7px 0; }
.timeline > div > span { width: 8px; height: 8px; margin-top: 7px; border-radius: 50%; background: var(--teal); }
.timeline p { margin: 0; }
.timeline strong, .timeline small { display: block; }

.alert { margin-bottom: 18px; padding: 12px 15px; border: 1px solid; border-radius: 9px; transition: opacity .35s; }
.alert-success { border-color: #b9e7cc; color: var(--success); background: #effbf4; }
.alert-error { border-color: #f3c4be; color: var(--danger); background: #fff4f2; }
.alert-warning { border-color: #efcf87; color: #754c00; background: #fff9e8; }
.alert p { margin: 4px 0 0; color: inherit; }
.alert ul { margin-bottom: 0; }
.alert-fade { opacity: .32; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

.guest-shell { display: grid; min-height: 100vh; place-items: center; padding: 30px 18px; background: radial-gradient(circle at 15% 10%, #dff4f4 0, transparent 33%), radial-gradient(circle at 90% 90%, #e8eff9 0, transparent 34%), #f5f8fa; }
.guest-content { width: min(520px, 100%); }
.guest-language { width: max-content; margin: 0 0 12px auto; }
.guest-language button { min-width: 92px; color: var(--navy); border-color: var(--line); background: #fff; }
.auth-card, .error-card { padding: clamp(25px, 5vw, 42px); border: 1px solid var(--line); border-radius: 20px; background: rgba(255,255,255,.96); box-shadow: 0 25px 75px rgba(16,42,67,.13); }
.setup-card { width: min(780px, calc(100vw - 30px)); margin-left: calc((520px - min(780px, calc(100vw - 30px))) / 2); }
.auth-intro { margin-bottom: 25px; }
.auth-intro .brand-mark { margin-bottom: 25px; }
.auth-intro p { margin-bottom: 0; }
.error-card { text-align: center; }
.error-card .button { margin-top: 8px; }
.booking-panel { max-width: 980px; }
.booking-section { padding-top: 18px; }
.booking-section:first-of-type { padding-top: 0; }
.inline-patient { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; padding: 16px; border: 1px solid var(--line); border-radius: 11px; background: #f8fbfc; }
.inline-patient[hidden] { display: none; }

html[dir="rtl"] { font-family: Tahoma, Arial, "Segoe UI", sans-serif; }
html[dir="rtl"] body { text-align: right; }
html[dir="rtl"] .app-shell { padding-right: 244px; padding-left: 0; }
html[dir="rtl"] .sidebar { inset: 0 0 0 auto; }
html[dir="rtl"] .sidebar nav a.active { box-shadow: inset -3px 0 #29c2c4; }
html[dir="rtl"] .main-content { direction: rtl; }
html[dir="rtl"] table { text-align: right; }
html[dir="rtl"] .menu-button { right: 13px; left: auto; }
html[dir="rtl"] .definition-list dd { margin-right: 0; }
html[dir="rtl"] .timeline > div > span { flex: 0 0 auto; }
html[dir="rtl"] .guest-language { margin-right: auto; margin-left: 0; }
html[dir="rtl"] input[type="email"], html[dir="rtl"] input[type="tel"], html[dir="rtl"] input[inputmode="tel"] { direction: ltr; text-align: right; }
html[dir="rtl"] input[type="date"], html[dir="rtl"] input[type="time"], html[dir="rtl"] .money { direction: ltr; text-align: right; }

@media (max-width: 1050px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .queue-card { grid-template-columns: 75px minmax(180px, 1fr) auto; }
  .queue-actions { grid-column: 2 / -1; justify-content: flex-start; }
}

@media (max-width: 900px) {
  .app-shell { padding-left: 0; }
  html[dir="rtl"] .app-shell { padding-right: 0; }
  .sidebar { transform: translateX(-105%); transition: transform .24s ease; }
  html[dir="rtl"] .sidebar { transform: translateX(105%); }
  .sidebar.open { transform: translateX(0); }
  .menu-button { position: fixed; top: 13px; left: 13px; z-index: 19; display: block; width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 10px; color: var(--navy); background: #fff; box-shadow: var(--shadow); }
  .main-content { padding-top: 75px; }
}

@media (max-width: 680px) {
  .main-content { padding-right: 15px; padding-left: 15px; }
  .page-header { align-items: flex-start; flex-direction: column; }
  .stat-grid, .form-grid, .detail-grid { grid-template-columns: 1fr; }
  .operational-grid { grid-template-columns: 1fr; }
  .span-2, .span-wide, .form-section { grid-column: auto; }
  .stat-card { min-height: 120px; }
  .panel { padding: 16px; border-radius: 13px; }
  .definition-list > div { grid-template-columns: 1fr; gap: 3px; }
  .filter-row, .search-row { align-items: stretch; flex-direction: column; }
  .filter-row label, .search-input { width: 100%; }
  .form-actions { justify-content: stretch; }
  .form-actions > * { flex: 1; }
  .setup-card { width: 100%; margin-left: 0; }
  .queue-card { grid-template-columns: 72px 1fr; gap: 10px; }
  .queue-status { grid-column: 1; grid-row: 2; }
  .queue-actions { grid-column: 2; flex-wrap: wrap; }
  .queue-actions .button { min-height: 40px; }
  .inline-patient { grid-template-columns: 1fr; }
}
