/* Shifa design system — hand-written, no build step. Logical properties keep RTL/LTR symmetric. */
:root {
  --brand: #0d9488; --brand-600: #0f766e; --brand-50: #f0fdfa; --brand-100: #ccfbf1;
  --ink: #0f172a; --ink-2: #334155; --muted: #64748b; --line: #e2e8f0; --line-2: #f1f5f9;
  --bg: #f6f8fb; --card: #ffffff; --danger: #dc2626; --warn: #d97706; --ok: #16a34a; --info: #2563eb;
  --radius: 14px; --radius-sm: 10px; --shadow: 0 1px 2px rgba(15,23,42,.04), 0 4px 16px rgba(15,23,42,.05);
  --shadow-lg: 0 10px 40px rgba(15,23,42,.14);
  --sidebar: 256px; --font: 'Cairo', 'Inter', system-ui, sans-serif;
}
html[lang="en"] { --font: 'Inter', 'Cairo', system-ui, sans-serif; }
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 14.5px; line-height: 1.6; color: var(--ink); background: var(--bg); }
a { color: var(--brand-600); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.3; font-weight: 700; }
h1 { font-size: 1.55rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
bdi, .num { unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
:focus-visible { outline: 3px solid #5eead4; outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[x-cloak] { display: none !important; }

/* ---------- App shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { background: #0b1324; color: #cbd5e1; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; padding: 18px 14px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 800; font-size: 1.15rem; padding: 4px 8px 18px; }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, #14b8a6, #0ea5e9); display: grid; place-items: center; color: #fff; flex: none; }
.brand small { display: block; font-size: .72rem; font-weight: 500; color: #94a3b8; }
/* Uploaded Shifa logo (platform console → Brand); white tile keeps dark logos readable on the dark sidebar */
.brand-logo { height: 36px; width: auto; max-width: 150px; object-fit: contain; background: #fff; border-radius: 10px; padding: 3px; flex: none; }
.nav-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: #64748b; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: #cbd5e1; font-weight: 600; font-size: .92rem; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav a.active { background: rgba(20,184,166,.16); color: #5eead4; }
.nav a .count { margin-inline-start: auto; background: #ef4444; color: #fff; border-radius: 999px; font-size: .72rem; padding: 0 7px; min-width: 20px; text-align: center; }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.07); }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 64px; background: rgba(255,255,255,.85); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 0 24px; position: sticky; top: 0; z-index: 20; }
.topbar .search { flex: 1; max-width: 460px; position: relative; }
.topbar .search input { padding-inline-start: 38px; background: var(--line-2); border-color: transparent; }
.topbar .search svg { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); width: 18px; color: var(--muted); }
.topbar-actions { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; }
.content { padding: 24px; max-width: 1440px; width: 100%; margin: 0 auto; }
.menu-btn { display: none; }
.demo-bar { background: linear-gradient(90deg, #f59e0b, #f97316); color: #fff; padding: 8px 24px; font-weight: 600; font-size: .88rem; display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
.demo-bar a, .demo-bar button { color: #fff; }
.demo-bar .roles { display: flex; gap: 6px; flex-wrap: wrap; margin-inline-start: auto; }
.demo-bar .roles a { background: rgba(255,255,255,.2); border-radius: 999px; padding: 2px 12px; font-size: .82rem; }
.demo-bar .roles a.on { background: #fff; color: #c2410c; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { color: var(--muted); margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Cards / grid ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.card-head h2, .card-head h3 { margin: 0; font-size: 1rem; }
.card-body { padding: 16px 20px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.split-r { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(0, 2.2fr); gap: 16px; align-items: start; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.tiny { font-size: .76rem; }
.bold { font-weight: 700; }
.mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; }
.hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

/* Stat tiles */
.stat { padding: 16px 18px; display: flex; gap: 14px; align-items: center; }
.stat .ico { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.stat .ico svg { width: 22px; height: 22px; }
.stat .val { font-size: 1.5rem; font-weight: 800; line-height: 1.1; }
.stat .lbl { color: var(--muted); font-size: .84rem; }
.tone-teal { background: #ccfbf1; color: #0f766e; } .tone-blue { background: #dbeafe; color: #1d4ed8; }
.tone-amber { background: #fef3c7; color: #b45309; } .tone-violet { background: #ede9fe; color: #6d28d9; }
.tone-rose { background: #ffe4e6; color: #be123c; } .tone-green { background: #dcfce7; color: #15803d; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 700; font-size: .9rem; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s; }
.btn:hover { background: var(--line-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn svg { width: 17px; height: 17px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); }
.btn-dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-dark:hover { background: #1e293b; }
.btn-danger { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { height: 32px; padding: 0 11px; font-size: .82rem; border-radius: 8px; }
.btn-lg { height: 48px; padding: 0 24px; font-size: 1rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: #fff; display: inline-grid; place-items: center; cursor: pointer; color: var(--ink-2); position: relative; }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn .dot { position: absolute; top: 7px; inset-inline-end: 8px; width: 8px; height: 8px; border-radius: 50%; background: #ef4444; border: 2px solid #fff; }

/* ---------- Forms ---------- */
label, .label { display: block; font-weight: 700; font-size: .85rem; margin-bottom: 6px; color: var(--ink-2); }
.input, input:not([type]), input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], input[type=datetime-local], input[type=tel], input[type=search], select, textarea {
  width: 100%; height: 42px; padding: 8px 12px; font: inherit; color: var(--ink); background: #fff; border: 1px solid #cbd5e1; border-radius: 10px; transition: border-color .15s, box-shadow .15s; }
textarea { height: auto; min-height: 84px; resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(13,148,136,.18); }
input[type=tel], input[type=email], .ltr-input { direction: ltr; text-align: start; }
html[dir=rtl] input[type=tel], html[dir=rtl] input[type=email] { text-align: right; }
.field { margin-bottom: 14px; }
.field .hint { color: var(--muted); font-size: .78rem; margin-top: 4px; }
.field .err, .err { color: var(--danger); font-size: .8rem; margin-top: 4px; font-weight: 600; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; margin: 0; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-opt input { position: absolute; opacity: 0; pointer-events: none; }
.chip-opt > span { display: inline-block; padding: 6px 14px; border: 1px solid #cbd5e1; border-radius: 999px; cursor: pointer; font-weight: 600; font-size: .86rem; background: #fff; user-select: none; }
.chip-opt input:checked + span { background: var(--brand-50); border-color: var(--brand); color: var(--brand-600); }
.chip-opt input:focus-visible + span { outline: 3px solid #5eead4; }
.seg { display: inline-flex; background: var(--line-2); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg a, .seg button { padding: 6px 14px; border-radius: 8px; font-weight: 700; font-size: .85rem; color: var(--ink-2); border: 0; background: none; cursor: pointer; font-family: inherit; }
.seg a:hover { text-decoration: none; }
.seg .on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.scale { display: flex; gap: 4px; flex-wrap: wrap; }
.scale label { margin: 0; }
.scale input { position: absolute; opacity: 0; }
.scale span { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; border: 1px solid #cbd5e1; cursor: pointer; font-weight: 700; }
.scale input:checked + span { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: start; font-size: .78rem; text-transform: uppercase; letter-spacing: .02em; color: var(--muted); font-weight: 700; padding: 10px 16px; background: #f8fafc; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafcff; }
.table .num { text-align: end; }

/* ---------- Badges / avatars ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 999px; font-size: .76rem; font-weight: 700; white-space: nowrap; background: var(--line-2); color: var(--ink-2); }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.plain::before { display: none; }
.b-slate { background: #f1f5f9; color: #475569; } .b-blue { background: #dbeafe; color: #1d4ed8; } .b-amber { background: #fef3c7; color: #b45309; }
.b-violet { background: #ede9fe; color: #6d28d9; } .b-cyan { background: #cffafe; color: #0e7490; } .b-teal { background: #ccfbf1; color: #0f766e; }
.b-green { background: #dcfce7; color: #15803d; } .b-red { background: #fee2e2; color: #b91c1c; } .b-gray { background: #f3f4f6; color: #6b7280; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--brand-100); color: var(--brand-600); display: inline-grid; place-items: center; font-weight: 800; font-size: .85rem; flex: none; }
.avatar.lg { width: 64px; height: 64px; font-size: 1.3rem; }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who .name { font-weight: 700; color: var(--ink); }
.who .sub { color: var(--muted); font-size: .8rem; }

/* ---------- Alerts ---------- */
.alert { padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; font-weight: 600; display: flex; gap: 10px; align-items: flex-start; }
.alert svg { width: 20px; flex: none; margin-top: 1px; }
.alert-ok { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alert-err { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warn { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.allergy-strip { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; padding: 8px 14px; border-radius: 10px; font-weight: 700; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.allergy-strip.unknown { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.allergy-strip.none { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; margin-bottom: 16px; scrollbar-width: none; }
.tabs a, .tabs button { padding: 10px 14px; font-weight: 700; color: var(--muted); border: 0; background: none; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; font-family: inherit; font-size: .92rem; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs .on { color: var(--brand-600); border-bottom-color: var(--brand); }

/* ---------- Queue board / calendar ---------- */
.board { display: grid; grid-template-columns: repeat(4, minmax(220px, 1fr)); gap: 14px; overflow-x: auto; }
.lane { background: #eef2f6; border-radius: var(--radius); padding: 10px; min-height: 200px; }
.lane h3 { font-size: .9rem; display: flex; justify-content: space-between; padding: 4px 6px 10px; margin: 0; }
.ticket { background: #fff; border-radius: 12px; padding: 12px; margin-bottom: 10px; box-shadow: var(--shadow); border-inline-start: 4px solid var(--brand); }
.ticket .qn { font-size: 1.3rem; font-weight: 800; color: var(--brand-600); }
.timeline-day { display: grid; grid-template-columns: 64px 1fr; }
.slot-row { display: contents; }
.slot-time { color: var(--muted); font-size: .8rem; padding: 10px 0; border-top: 1px dashed var(--line); text-align: center; }
.slot-cell { border-top: 1px dashed var(--line); padding: 6px 0; min-height: 44px; display: flex; flex-direction: column; gap: 6px; }
.appt { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 10px; background: #fff; border: 1px solid var(--line); border-inline-start: 4px solid var(--c, var(--brand)); box-shadow: 0 1px 2px rgba(0,0,0,.03); flex-wrap: wrap; }
.appt:hover { border-color: #cbd5e1; text-decoration: none; }
.week { display: grid; grid-template-columns: repeat(7, minmax(130px, 1fr)); gap: 10px; overflow-x: auto; }
.week .day { background: #fff; border: 1px solid var(--line); border-radius: 12px; min-height: 220px; }
.week .day.today { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-100); }
.week .day h4 { font-size: .85rem; padding: 8px 10px; border-bottom: 1px solid var(--line); margin: 0; display: flex; justify-content: space-between; }
.week .mini { margin: 6px; padding: 5px 8px; border-radius: 8px; background: var(--line-2); font-size: .78rem; border-inline-start: 3px solid var(--c, var(--brand)); display: block; color: var(--ink); }
.slots { display: flex; flex-wrap: wrap; gap: 6px; }
.slots button { border: 1px solid #99f6e4; background: var(--brand-50); color: var(--brand-600); border-radius: 8px; padding: 4px 10px; cursor: pointer; font-weight: 700; font-family: inherit; }
.slots button.on { background: var(--brand); color: #fff; }

/* ---------- Patient header & timeline ---------- */
.patient-head { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.patient-head .meta { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--ink-2); font-size: .88rem; }
.tl { position: relative; padding-inline-start: 26px; }
.tl::before { content: ''; position: absolute; inset-inline-start: 8px; top: 4px; bottom: 4px; width: 2px; background: var(--line); }
.tl-item { position: relative; padding-bottom: 18px; }
.tl-item::before { content: ''; position: absolute; inset-inline-start: -23px; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 3px solid var(--brand); }
.tl-item.signed::before { border-color: var(--ok); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); font-size: .85rem; }
.kv dd { margin: 0; font-weight: 600; }
.vitals-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.vital { background: var(--line-2); border-radius: 10px; padding: 10px 12px; }
.vital .v { font-size: 1.15rem; font-weight: 800; }
.vital .u { font-size: .74rem; color: var(--muted); }
.vital.flag { background: #fef2f2; color: #991b1b; }

/* ---------- Dental chart ---------- */
.dental { display: grid; gap: 6px; direction: ltr; }
.dental .jaw { display: flex; justify-content: center; gap: 3px; flex-wrap: wrap; }
.dental .gap { width: 14px; }
.tooth { width: 38px; height: 46px; border: 1px solid #cbd5e1; border-radius: 10px 10px 14px 14px; background: #fff; display: grid; place-items: center; font-size: .72rem; font-weight: 800; cursor: pointer; position: relative; font-family: inherit; color: var(--ink-2); }
.tooth.lower { border-radius: 14px 14px 10px 10px; }
.tooth[data-s=caries] { background: #fee2e2; border-color: #f87171; color: #991b1b; }
.tooth[data-s=filled] { background: #dbeafe; border-color: #60a5fa; color: #1e40af; }
.tooth[data-s=missing] { background: repeating-linear-gradient(45deg, #f1f5f9, #f1f5f9 4px, #e2e8f0 4px, #e2e8f0 8px); color: #94a3b8; }
.tooth[data-s=crown] { background: #fef3c7; border-color: #f59e0b; color: #92400e; }
.tooth[data-s=rct] { background: #ede9fe; border-color: #a78bfa; color: #5b21b6; }
.tooth[data-s=implant] { background: #ccfbf1; border-color: #2dd4bf; color: #115e59; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .78rem; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; margin-inline-end: 4px; border: 1px solid #cbd5e1; }

/* ---------- Chat ---------- */
.chat { display: grid; grid-template-columns: 300px 1fr; height: calc(100vh - 180px); min-height: 480px; overflow: hidden; }
.chat-list { border-inline-end: 1px solid var(--line); overflow-y: auto; }
.chat-list a { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line-2); color: var(--ink); }
.chat-list a:hover, .chat-list a.on { background: var(--brand-50); text-decoration: none; }
.chat-pane { display: flex; flex-direction: column; min-width: 0; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 18px; background: #f8fafc; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: min(78%, 520px); padding: 10px 14px; border-radius: 16px; background: #fff; border: 1px solid var(--line); align-self: flex-start; white-space: pre-wrap; word-wrap: break-word; }
.bubble.me { align-self: flex-end; background: var(--brand); color: #fff; border-color: var(--brand); }
.bubble .t { font-size: .7rem; opacity: .7; margin-top: 4px; display: block; }
.bubble a { color: inherit; text-decoration: underline; }
.bubble img { border-radius: 10px; margin-top: 6px; max-height: 220px; display: block; }
.chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); background: #fff; align-items: flex-end; }
.chat-form textarea { min-height: 42px; height: 42px; max-height: 140px; }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal { background: #fff; border-radius: 18px; width: min(560px, 100%); max-height: 92vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal.wide { width: min(860px, 100%); }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }

/* Dropdown */
.dd { position: relative; }
.dd-menu { position: absolute; inset-inline-end: 0; top: calc(100% + 6px); background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); min-width: 220px; padding: 6px; z-index: 40; }
.dd-menu a, .dd-menu button { display: flex; gap: 8px; align-items: center; width: 100%; padding: 8px 12px; border-radius: 8px; color: var(--ink); background: none; border: 0; font: inherit; cursor: pointer; text-align: start; }
.dd-menu a:hover, .dd-menu button:hover { background: var(--line-2); text-decoration: none; }

/* Empty state */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty svg { width: 44px; height: 44px; opacity: .45; margin-bottom: 8px; }

/* Bars (simple charts) */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 10px; }
.bars .bar { flex: 1; background: linear-gradient(180deg, #2dd4bf, #0d9488); border-radius: 6px 6px 2px 2px; min-height: 2px; position: relative; }
.bars .bar:hover::after { content: attr(data-v); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; font-size: .72rem; padding: 2px 6px; border-radius: 6px; white-space: nowrap; margin-bottom: 4px; }
.bar-x { display: flex; gap: 6px; font-size: .68rem; color: var(--muted); }
.bar-x span { flex: 1; text-align: center; overflow: hidden; }
.hbar { display: grid; grid-template-columns: minmax(90px, 160px) 1fr max-content; gap: 10px; align-items: center; margin-bottom: 8px; font-size: .88rem; }
.hbar .track { background: var(--line-2); height: 10px; border-radius: 99px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--brand); border-radius: 99px; }

/* Pagination */
.pager { display: flex; gap: 4px; justify-content: center; padding: 14px; flex-wrap: wrap; }
.pager a, .pager span { min-width: 36px; height: 36px; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--line); background: #fff; padding: 0 10px; font-weight: 700; }
.pager .on { background: var(--brand); color: #fff; border-color: var(--brand); }
.pager .off { opacity: .45; }

/* Auth / public pages */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-side { background: radial-gradient(1200px 600px at 20% 10%, #14b8a6 0, #0f766e 40%, #0b1324 100%); color: #e2e8f0; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-side h2 { color: #fff; font-size: 2rem; line-height: 1.35; }
.auth-form { display: grid; place-items: center; padding: 32px 20px; }
.auth-card { width: min(420px, 100%); }

/* Print */
.print-only { display: none; }
@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; font-size: 12.5pt; }
  .sidebar, .topbar, .demo-bar, .no-print, .btn, .alert { display: none !important; }
  .shell { display: block; } .content { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; }
  .print-only { display: block; }
  .rx-sheet { page-break-inside: auto; } .rx-item { page-break-inside: avoid; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split, .split-r { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 920px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: 280px; z-index: 70; transform: translateX(-105%); transition: transform .2s; }
  html[dir=rtl] .sidebar { transform: translateX(105%); }
  .sidebar.open { transform: none !important; }
  .menu-btn { display: inline-grid; }
  .scrim { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 65; }
  .g3 { grid-template-columns: minmax(0, 1fr); }
  .board { grid-template-columns: repeat(4, minmax(240px, 85vw)); }
  .chat { grid-template-columns: 1fr; height: auto; }
  .chat-list { max-height: 220px; border-inline-end: 0; border-bottom: 1px solid var(--line); }
  .chat-msgs { min-height: 50vh; max-height: 60vh; }
  .auth { grid-template-columns: 1fr; }
  .auth-side { display: none; }
}
@media (max-width: 640px) {
  .content { padding: 16px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar .search { display: none; }
  .g2, .g4, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .page-head h1 { font-size: 1.3rem; }
  .table.stack-sm thead { display: none; }
  .table.stack-sm tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  .table.stack-sm td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 6px 14px; }
  .table.stack-sm td::before { content: attr(data-l); color: var(--muted); font-size: .8rem; font-weight: 700; }
  .table.stack-sm td.num { text-align: start; }
  .demo-bar { padding: 8px 12px; }
  .tooth { width: 30px; height: 40px; font-size: .64rem; }
  .hbar { grid-template-columns: 90px 1fr max-content; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* Form rows that must wrap instead of overflowing (prescription lines, invoice lines). */
input, select, textarea { min-width: 0; }
.rx-row { display: grid; grid-template-columns: minmax(0, 2fr) repeat(5, minmax(0, 1fr)) auto; gap: 6px; margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px dashed var(--line); }
.rx-row > :first-child { grid-column: auto; }
@media (max-width: 1100px) { .rx-row { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); } }

/* Keyboard users: skip link becomes visible on focus. */
.skip-link { position: absolute; inset-inline-start: 12px; top: -60px; z-index: 100; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 700; }
.skip-link:focus { top: 12px; text-decoration: none; }

/* ---------- Chat v2: fixed-height pane, compact bubbles, pinned composer ---------- */
.chat { height: calc(100dvh - 230px); min-height: 440px; grid-template-rows: minmax(0, 1fr); }
body:has(.demo-bar) .chat { height: calc(100dvh - 268px); }
.chat-list, .chat-pane { min-height: 0; }
.chat-pane { overflow: hidden; }
.chat-pane > .card-head { flex: none; }
.chat-msgs { min-height: 0; padding: 16px 20px; gap: 6px; background: #f1f5f9; background-image: radial-gradient(#e2e8f0 1px, transparent 1px); background-size: 18px 18px; }
.bubble { white-space: normal; padding: 8px 12px 6px; border-radius: 14px; border-start-start-radius: 4px; box-shadow: 0 1px 1px rgba(15,23,42,.06); max-width: min(72%, 520px); line-height: 1.55; }
.bubble.me { border-start-start-radius: 14px; border-start-end-radius: 4px; }
.bubble .txt { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble .t { font-size: .68rem; opacity: .65; margin-top: 2px; text-align: end; }
.bubble .file { display: flex; align-items: center; gap: 8px; padding: 6px 8px; margin-top: 4px; border-radius: 10px; background: rgba(15,23,42,.06); text-decoration: none; }
.bubble.me .file { background: rgba(255,255,255,.18); }
.bubble img { max-width: 260px; width: 100%; max-height: 240px; object-fit: cover; }
.day-sep { align-self: center; font-size: .72rem; color: var(--muted); background: #fff; border: 1px solid var(--line); padding: 2px 12px; border-radius: 999px; margin: 8px 0; }
.chat-form { flex: none; align-items: center; }
.chat-form textarea { height: 44px; min-height: 44px; border-radius: 22px; padding: 10px 16px; resize: none; overflow-y: hidden; line-height: 1.5; }
.chat-form .btn-primary { width: 44px; height: 44px; border-radius: 50%; padding: 0; flex: none; }
.chat-list a { align-items: center; }
.chat-list .who-name { font-weight: 700; font-size: .9rem; }
.chat-back { display: none; }
@media (max-width: 920px) {
  .chat { grid-template-columns: 1fr; height: calc(100dvh - 190px); min-height: 380px; }
  body:has(.demo-bar) .chat { height: calc(100dvh - 240px); }
  .chat-list { max-height: none; border-inline-end: 0; }
  .chat.has-thread .chat-list { display: none; }
  .chat:not(.has-thread) .chat-pane { display: none; }
  .chat-back { display: inline-grid; }
  .chat-msgs { min-height: 0; max-height: none; }
  .bubble { max-width: 85%; }
}

/* ---------- Mobile app feel ---------- */
.bottom-nav { display: none; }
@media (max-width: 920px) {
  .bottom-nav { display: flex; position: fixed; inset-inline: 0; bottom: 0; z-index: 50; background: #fff; border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); box-shadow: 0 -4px 16px rgba(15,23,42,.06); }
  .bottom-nav a, .bottom-nav button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .68rem; font-weight: 700; color: var(--muted);
    background: none; border: 0; font-family: inherit; padding: 4px 0; position: relative; text-decoration: none; cursor: pointer; }
  .bottom-nav svg { width: 22px; height: 22px; }
  .bottom-nav .active { color: var(--brand-600); }
  .bottom-nav .count { position: absolute; top: 0; inset-inline-start: calc(50% + 6px); background: #ef4444; color: #fff; border-radius: 999px; font-size: .62rem; min-width: 16px; padding: 0 4px; }
  .main { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  body:has(.chat) .main, body:has(#portal-chat) main { padding-bottom: 0; }
}
@media (max-width: 640px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .g4 .stat { padding: 12px; gap: 10px; flex-direction: column; align-items: flex-start; }
  .g4 .stat .ico { width: 36px; height: 36px; border-radius: 10px; }
  .g4 .stat .val { font-size: 1.2rem; }
  .demo-bar { flex-wrap: nowrap; overflow-x: auto; white-space: nowrap; font-size: .78rem; gap: 10px; scrollbar-width: none; }
  .demo-bar .demo-text { display: none; }
  .demo-bar .roles { margin-inline-start: 0; flex-wrap: nowrap; }
  .page-head .actions .btn { flex: 1 1 auto; }
}
/* Visit screen on phones/tablets: the note first, the patient summary after it. */
@media (max-width: 1180px) { .split-r > aside { order: 2; } }

/* The hidden attribute must always win over component display rules (e.g. .btn, inline display:flex). */
[hidden] { display: none !important; }

/* The hidden attribute must always win over component display rules (e.g. .btn, inline display:flex). */
[hidden] { display: none !important; }
