/* DentalPro web interface: the desktop application's navy and teal, laid out with logical properties
   so Arabic mirrors without separate rules. */
:root {
  --bg: #f3f6fa; --surface: #ffffff; --surface-2: #f7f9fc; --ink: #0f1c2e; --muted: #56677d; --line: #dbe3ec;
  --navy: #0b1f3a; --nav-ink: #c7d3e3; --nav-active: #13325a;
  --teal: #0d7f75; --teal-ink: #ffffff; --teal-soft: #e3f4f2;
  --danger: #b91c1c; --danger-soft: #fdecec; --warn: #8a5a00; --warn-soft: #fdf3dc; --ok: #15803d; --ok-soft: #e4f6ea;
  --radius: 8px; --shadow: 0 1px 2px rgba(11, 31, 58, .07);
  --font: "Segoe UI", system-ui, -apple-system, "Noto Sans", "Noto Sans Arabic", Tahoma, Arial, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0a1524; --surface: #111f33; --surface-2: #162740; --ink: #e8eef6; --muted: #9db0c6; --line: #24364d;
  --navy: #071221; --nav-ink: #b6c4d6; --nav-active: #15304f;
  --teal: #38c6b6; --teal-ink: #06211e; --teal-soft: #123a3c;
  --danger: #f28b8b; --danger-soft: #3a1a1e; --warn: #f3cf8c; --warn-soft: #3a2b0e; --ok: #7bd99a; --ok-soft: #15331f;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 400 15px/1.45 var(--font); -webkit-text-size-adjust: 100%; }
h1 { font-size: 1.45rem; margin: 0; }
h2 { font-size: 1.15rem; margin: 0; }
h3 { font-size: 1rem; margin: 0 0 10px; }
h4 { font-size: .95rem; margin: 10px 0 2px; }
p { margin: 0 0 8px; }
a { color: var(--teal); }
bdi { white-space: nowrap; }
.page, .content, .tab-body { grid-template-columns: minmax(0, 1fr); }
.grid-2 > *, .tiles > * { min-width: 0; }
.page { display: grid; gap: 14px; align-content: start; min-width: 0; }
.page > * { min-width: 0; }
[hidden] { display: none !important; }
.boot { text-align: center; padding: 20vh 16px; color: var(--muted); font-size: 1.2rem; }
.muted, small.muted { color: var(--muted); }
.grow { flex: 1 1 200px; min-width: 0; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; }

/* controls */
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; width: 100%; min-height: 40px; }
input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; flex: none; accent-color: var(--teal); }
input[type="color"] { padding: 2px; width: 70px; }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--danger); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--muted); }
textarea { resize: vertical; }
.btn { font: inherit; font-weight: 600; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 8px 14px; min-height: 40px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.btn:hover { border-color: var(--teal); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--teal); border-color: var(--teal); color: var(--teal-ink); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); border-color: var(--line); }
.btn.small { padding: 4px 10px; min-height: 32px; font-size: .88rem; font-weight: 500; }
.btn.block { width: 100%; }
.icon-btn { font: inherit; background: transparent; border: 1px solid transparent; border-radius: 6px; min-width: 40px; min-height: 40px; color: var(--ink); cursor: pointer; }
.icon-btn:hover { border-color: var(--line); }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 32px; }
.field { display: grid; gap: 4px; min-width: 0; flex: 1 1 140px; }
.field > label { font-weight: 600; font-size: .88rem; color: var(--muted); }
.field small { color: var(--muted); }
.field-error { color: var(--danger); margin: 0; min-height: 0; white-space: pre-line; }
.form { display: grid; gap: 12px; }
.form.two-col { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 20px; }
.form.two-col > div { display: grid; gap: 12px; align-content: start; }
.row { display: flex; gap: 10px; align-items: flex-end; min-width: 0; }
.row.wrap { flex-wrap: wrap; }
.row.center { align-items: center; flex-wrap: wrap; }
.row.center input { width: 76px; }
.stack { display: grid; gap: 10px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions.end { justify-content: flex-end; margin-bottom: 12px; }

/* layout */
.layout { display: flex; min-height: 100%; }
.sidebar { width: 236px; flex: none; background: var(--navy); color: var(--nav-ink); padding-block: 14px; position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto; }
.brand { padding: 4px 18px 16px; display: grid; gap: 2px; }
.brand strong { color: #fff; font-size: 1.2rem; }
.brand small { font-size: .78rem; opacity: .85; }
.side-nav { display: grid; gap: 2px; padding-inline: 8px; }
.side-nav a { color: var(--nav-ink); text-decoration: none; padding: 10px 12px; border-radius: 6px; font-weight: 500; }
.side-nav a:hover { background: var(--nav-active); color: #fff; }
.side-nav a.active { background: var(--nav-active); color: #fff; box-shadow: inset 3px 0 0 var(--teal); }
[dir="rtl"] .side-nav a.active { box-shadow: inset -3px 0 0 var(--teal); }
.workspace { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 8px max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px)); background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top-search { flex: 1; max-width: 480px; min-width: 0; }
.menu-btn, .scrim { display: none; }
.user-menu { position: relative; }
.user-menu summary { list-style: none; cursor: pointer; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font-weight: 600; white-space: nowrap; max-width: 190px; overflow: hidden; text-overflow: ellipsis; }
.user-menu summary::-webkit-details-marker { display: none; }
.menu { position: absolute; inset-inline-end: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(11, 31, 58, .18); display: grid; gap: 4px; padding: 8px; min-width: 200px; z-index: 30; }
.menu small { color: var(--muted); padding: 2px 8px; }
.content { padding: 18px max(16px, env(safe-area-inset-right, 0px)) 40px max(16px, env(safe-area-inset-left, 0px)); max-width: 1500px; width: 100%; display: grid; gap: 14px; align-content: start; }
.content > * { min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.toolbar > select, .toolbar > input { width: auto; max-width: 100%; }
.tab-body { display: grid; gap: 14px; align-content: start; }
.tab-body > * { min-width: 0; }

/* cards, tiles, tables */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 4px; text-decoration: none; color: inherit; box-shadow: var(--shadow); }
a.tile:hover { border-color: var(--teal); }
.tile-label { color: var(--muted); font-size: .86rem; }
.tile-value { font-size: 1.35rem; line-height: 1.2; overflow-wrap: anywhere; }
.tile-value bdi { white-space: normal; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); gap: 14px; align-items: start; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: start; font-size: .82rem; color: var(--muted); font-weight: 600; padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
.table .num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { color: var(--muted); padding: 18px 4px; text-align: center; margin: 0; }
.tabs { display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: thin; }
.tab { font: inherit; font-weight: 500; color: var(--muted); background: none; border: 0; border-bottom: 2px solid transparent; padding: 9px 12px; cursor: pointer; white-space: nowrap; min-height: 40px; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--teal); border-bottom-color: var(--teal); font-weight: 600; }
.seg .tabs { border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.pill { --pill: #6b7280; display: inline-block; border: 1px solid var(--pill); color: var(--ink); background: color-mix(in srgb, var(--pill) 15%, transparent); border-radius: 999px; padding: 1px 10px; font-size: .82rem; font-weight: 600; white-space: nowrap; }
.pill.st-pending { --pill: #d98806; } .pill.st-confirmed { --pill: #16a34a; } .pill.st-cancelled { --pill: #dc2626; } .pill.st-completed { --pill: #2563eb; } .pill.st-no_show { --pill: #6b7280; } .pill.st-rescheduled { --pill: #7c3aed; }
.tag { display: inline-block; background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 7px; font-size: .8rem; color: var(--muted); }
.tag.danger, .tag.msg-failed { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.tag.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.tag.ok, .tag.msg-delivered, .tag.msg-read { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.alert-box { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger); border-radius: 6px; padding: 8px 12px; font-weight: 600; }
.alert-box.soft { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.warn-box { background: var(--warn-soft); color: var(--warn); border-radius: 6px; padding: 8px 12px; }
.info-box { background: var(--teal-soft); border-radius: 6px; padding: 8px 12px; margin: 0; }
.warn-text { color: var(--warn); }
.kv { display: grid; grid-template-columns: minmax(120px, 210px) minmax(0, 1fr); gap: 6px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.history { margin: 0; padding-inline-start: 18px; display: grid; gap: 4px; }

/* patient */
.patient-head { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.patient-head h1 { font-size: 1.3rem; }
.alt-name { font-weight: 500; color: var(--muted); }
.avatar { width: 62px; height: 62px; border-radius: 50%; background: var(--teal-soft); color: var(--teal); display: grid; place-items: center; font-weight: 700; font-size: 1.15rem; overflow: hidden; flex: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.alert-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--line); border-inline-start: 4px solid var(--muted); border-radius: 6px; padding: 8px 12px; }
.alert-row.sev-critical { border-inline-start-color: var(--danger); } .alert-row.sev-critical strong { color: var(--danger); }
.alert-row.sev-warning { border-inline-start-color: #d98806; }
.visit header { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.visit header .btn { margin-inline-start: auto; }
.rx-item { border: 1px solid var(--line); border-radius: 6px; padding: 10px; margin: 0; display: grid; gap: 8px; min-width: 0; justify-items: stretch; }
.rx-item > .btn { justify-self: end; }
.total-line { font-weight: 700; font-size: 1.05rem; margin: 0; }
.pick-list { display: grid; gap: 4px; max-height: 50vh; overflow-y: auto; }
.pick { font: inherit; text-align: start; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 9px 12px; cursor: pointer; min-height: 40px; }
.pick:hover { border-color: var(--teal); }
.slots { display: flex; flex-wrap: wrap; gap: 6px; align-content: flex-start; max-height: 330px; overflow-y: auto; padding: 2px; }
.logo-box img { max-height: 70px; max-width: 220px; display: block; margin-block-end: 6px; }
.hours { display: grid; gap: 6px; margin-block: 8px; }
.hours-row { display: grid; grid-template-columns: 110px repeat(2, minmax(84px, 112px)) minmax(100px, 130px) repeat(2, minmax(84px, 112px)); gap: 6px; align-items: center; overflow-x: auto; }

/* calendar */
.cal-range { font-size: 1.02rem; white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; }
.cal-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cal-head { display: flex; border-bottom: 1px solid var(--line); }
.cal-corner { width: 52px; flex: none; }
.cal-head-days { flex: 1; display: grid; grid-template-columns: repeat(var(--days), minmax(0, 1fr)); min-width: 0; padding-inline-end: 12px; }
.cal-head-days > div { padding: 7px 2px; text-align: center; font-weight: 600; font-size: .86rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cal-head-days > .today { background: var(--teal-soft); color: var(--teal); }
.cal-scroll { display: flex; max-height: calc(100vh - 290px); min-height: 380px; overflow-y: scroll; }
.cal-times { width: 52px; flex: none; }
.cal-time { color: var(--muted); font-size: .75rem; text-align: center; border-top: 1px solid transparent; }
.cal-cols { flex: 1; display: grid; grid-template-columns: repeat(var(--days), minmax(0, 1fr)); min-width: 0; }
.cal-col { position: relative; border-inline-start: 1px solid var(--line); background-image: repeating-linear-gradient(to bottom, var(--line) 0, var(--line) 1px, transparent 1px, transparent 72px); }
.cal-col.closed { background-color: var(--surface-2); }
.cal-open { position: absolute; inset-inline: 0; background: var(--surface); background-image: repeating-linear-gradient(to bottom, var(--line) 0, var(--line) 1px, transparent 1px, transparent 72px); }
.cal-closure { position: absolute; inset-inline: 0; background: repeating-linear-gradient(135deg, var(--danger-soft) 0 6px, transparent 6px 12px); color: var(--danger); font-size: .78rem; padding: 2px 6px; }
.cal-now { position: absolute; inset-inline: 0; height: 2px; background: var(--danger); z-index: 3; pointer-events: none; }
.cal-block { --st: #6b7280; position: absolute; font: inherit; color: var(--ink); text-align: start; background: color-mix(in srgb, var(--st) 18%, var(--surface)); border: 1px solid var(--st); border-inline-start-width: 4px; border-radius: 5px; padding: 2px 5px; overflow: hidden; display: block; cursor: pointer; z-index: 2; line-height: 1.25; touch-action: pan-y; }
.cal-block strong { display: block; font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-block small { display: block; font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-block.st-cancelled strong { text-decoration: line-through; }
.cal-block.dragging { opacity: .75; z-index: 5; cursor: grabbing; box-shadow: 0 6px 16px rgba(11, 31, 58, .3); }
.cal-block .flag { position: absolute; top: 1px; inset-inline-end: 3px; color: var(--warn); }
.cal-hint { padding: 6px 12px; margin: 0; font-size: .82rem; }
.month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.month-head { padding: 6px; text-align: center; color: var(--muted); font-size: .84rem; font-weight: 600; border-bottom: 1px solid var(--line); }
.month-cell { min-height: 102px; padding: 3px; border-inline-end: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.month-cell.other { background: var(--surface-2); opacity: .75; }
.month-cell.today .day-link { color: var(--teal); font-weight: 700; }
.day-link { font: inherit; background: none; border: 0; color: var(--ink); cursor: pointer; align-self: flex-end; padding: 0 4px; min-height: 24px; }
.month-item { --st: #6b7280; font: inherit; font-size: .74rem; color: var(--ink); text-align: start; background: none; border: 0; border-inline-start: 3px solid var(--st); padding: 0 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }

/* dialogs and messages */
dialog.modal { border: 0; border-radius: 10px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); background: var(--surface); color: var(--ink); box-shadow: 0 18px 50px rgba(0, 0, 0, .35); }
dialog.modal.wide { width: min(880px, calc(100vw - 24px)); }
dialog.modal[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgba(7, 18, 33, .55); }
dialog.modal > header { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 14px 16px; overflow-y: auto; flex: 1; min-height: 0; white-space: pre-line; }
.modal-body .form, .modal-body .stack, .modal-body .table { white-space: normal; }
dialog.modal > footer { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; padding: 10px 16px; border-top: 1px solid var(--line); }
#toasts { position: fixed; inset-block-start: calc(10px + env(safe-area-inset-top, 0px)); inset-inline: 0; display: grid; justify-items: center; gap: 6px; z-index: 2147483647; pointer-events: none; padding-inline: 12px; }
.toast { background: var(--navy); color: #fff; padding: 9px 16px; border-radius: 7px; max-width: min(620px, 100%); box-shadow: 0 6px 20px rgba(0, 0, 0, .3); pointer-events: auto; border-inline-start: 4px solid #2dd4bf; }
.toast.error { border-inline-start-color: #f87171; }
.toast.warn { border-inline-start-color: #fbbf24; }

/* sign-in */
.login { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 4fr); }
.login-hero { background: linear-gradient(150deg, var(--navy), #0d4f5a); color: #dbe7f1; padding: 48px; display: flex; flex-direction: column; justify-content: center; gap: 10px; }
.brand-mark { font-size: 2.3rem; font-weight: 700; color: #fff; }
.login-card { background: var(--surface); padding: 40px max(24px, 6vw); display: flex; flex-direction: column; justify-content: center; gap: 8px; }
.login-card.wide { grid-column: 1 / -1; max-width: 480px; margin: auto; width: 100%; border-radius: 10px; }
.login-foot { margin-top: 10px; }

/* tablets and phones */
@media (max-width: 900px) {
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 50; transform: translateX(-100%); transition: transform .18s; }
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  .nav-open .sidebar { transform: none; }
  .menu-btn { display: inline-block; font-size: 1.2rem; }
  .nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(7, 18, 33, .5); z-index: 40; }
  .form.two-col { grid-template-columns: minmax(0, 1fr); }
  .login { grid-template-columns: minmax(0, 1fr); align-content: start; }
  .login-hero { padding: 26px 20px; }
  .brand-mark { font-size: 1.7rem; }
  .login-card { padding: 22px 20px; }
}
@media (max-width: 640px) {
  body { font-size: 15px; }
  .row:not(.wrap):not(.center) { flex-wrap: wrap; }
  .topbar { flex-wrap: wrap; justify-content: space-between; }
  .top-search { order: 9; flex: 1 1 100%; max-width: none; }
  .user-menu summary { max-width: 140px; }
  .topbar .btn.ghost { padding-inline: 6px; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .kv dt { margin-block-start: 8px; font-size: .85rem; }
  /* Tables become stacked rows: nothing to scroll sideways on a phone. */
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border: 1px solid var(--line); border-radius: 6px; margin-block-end: 8px; padding: 4px 0; background: var(--surface); }
  .table td { border: 0; padding: 4px 10px; display: flex; justify-content: space-between; gap: 12px; text-align: end; overflow-wrap: anywhere; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: .82rem; text-align: start; flex: none; max-width: 45%; }
  .table td[data-label=""]::before { display: none; }
  .table td:empty { display: none; }
  .month-cell { min-height: 62px; }
  .month-item { display: block; font-size: 0; height: 6px; width: 100%; border-inline-start: 0; background: var(--st); border-radius: 2px; padding: 0; }
  .cal-scroll { max-height: none; }
  .hours-row { grid-template-columns: minmax(100px, 1fr) repeat(2, minmax(78px, 1fr)); }
  dialog.modal, dialog.modal.wide { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; margin: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print { .sidebar, .topbar, #toasts { display: none; } }

/* full clinic modules */
.btn.link { background: none; border: 0; padding: 0; color: var(--teal); text-decoration: underline; min-height: 0; font-weight: 400; text-align: start; }
.ok-box { background: var(--ok-soft); color: var(--ok); border-radius: var(--radius); padding: 10px 12px; }
.tag.prio-high, .tag.plan-cancelled, .tag.consent-withdrawn { background: var(--danger-soft); color: var(--danger); }
.tag.plan-approved, .tag.plan-completed, .tag.plan-in_progress, .tag.consent-signed { background: var(--ok-soft); color: var(--ok); }
.tag.plan-proposed, .tag.plan-on_hold, .tag.consent-issued { background: var(--warn-soft); color: var(--warn); }
.stack { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }

/* lock screen */
.veiled { visibility: hidden !important; }
.lock-screen { position: fixed; inset: 0; z-index: 1000; background: var(--navy); display: grid; place-items: center; padding: 16px; }
.lock-card { background: var(--surface); padding: 24px; border-radius: var(--radius); width: min(380px, 100%); }

/* odontogram */
/* Anatomical odontogram. Tooth colours are set in the drawing: enamel and dentine stay natural in both themes. */
.odo-toolbar { align-items: center; display: flex; flex-wrap: wrap; gap: 6px 12px; justify-content: space-between; }
.odo-toolbar select { width: auto; max-width: 170px; }
.odo-toolbar .row { flex: 0 1 auto; gap: 6px; }
.odo-toolbar .actions { flex-wrap: wrap; }
.odo-grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 2.4fr) minmax(300px, 1fr); align-items: start; }
.odo-stage { overflow-x: auto; background: var(--surface-2); border-radius: 10px; padding: 8px; }
.odo-zoom { min-width: 620px; }
.odo-arch { width: 100%; height: auto; display: block; margin-block-end: 4px; }
.odo-midline { stroke: var(--line); stroke-width: .7; stroke-dasharray: 3 3; }
.odo-tooth { cursor: pointer; outline: none; }
.odo-slot { fill: transparent; stroke: transparent; stroke-width: .8; transition: fill .12s; }
.odo-tooth:hover .odo-slot { fill: color-mix(in srgb, var(--teal) 9%, transparent); }
.odo-tooth:focus-visible .odo-slot { stroke: var(--teal); stroke-dasharray: 2 2; }
.odo-tooth.selected .odo-slot { fill: color-mix(in srgb, var(--teal) 16%, transparent); stroke: var(--teal); }
.odo-body { transition: transform .12s; }
.odo-label { font-size: 7.4px; fill: var(--muted); font-weight: 600; }
.odo-label.on { fill: var(--teal); font-weight: 700; }
.odo-tick { font-size: 5.6px; fill: var(--teal); font-weight: 700; }
.odo-planned-dot { fill: none; stroke: var(--muted); stroke-width: .7; stroke-dasharray: 1 .8; }
.t-ghost { fill: none; stroke: var(--muted); stroke-width: .55; stroke-dasharray: 1.6 1.4; }
.t-groove { pointer-events: none; }
.t-surface { stroke: #b8ad97; stroke-width: .3; cursor: pointer; transition: stroke .1s; }
.t-surface:hover { stroke: var(--teal); stroke-width: .9; }
.t-surface.on { stroke: var(--teal); stroke-width: 1.3; }
.t-surface.still { cursor: default; pointer-events: none; }
.odo-side { max-height: 78vh; overflow-y: auto; }
.odo-side-head { display: grid; grid-template-columns: 1fr auto; gap: 0 8px; align-items: start; }
.odo-side-head h3, .odo-side-head p { margin: 0; grid-column: 1; }
.odo-side-head .icon-btn { grid-column: 2; grid-row: 1; }
.odo-empty { padding: 16px 4px; }
.odo-palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 4px; }
.odo-cond { display: flex; align-items: center; gap: 6px; padding: 5px 7px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface, #fff); color: inherit; font: inherit; font-size: .85rem; cursor: pointer; text-align: start; }
.odo-cond:hover { border-color: var(--teal); }
.odo-cond.on { border-color: var(--teal); box-shadow: inset 0 0 0 1px var(--teal); font-weight: 600; }
.odo-surface-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.odo-picker { width: 118px; height: auto; flex: none; }
.odo-chips { display: flex; gap: 4px; flex-wrap: wrap; }
.odo-chip { min-width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface, #fff); color: inherit; font-weight: 600; cursor: pointer; }
.odo-chip.on { background: var(--teal); border-color: var(--teal); color: #fff; }
.odo-roles { display: flex; flex-wrap: wrap; gap: 8px; }
.odo-role { display: inline-flex; gap: 4px; align-items: center; }
.odo-history-head { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; }
.odo-history-meta { margin: 2px 0; }
.odo-link { margin: 2px 0; font-size: .88rem; }
.odo-surface-key { display: inline-block; width: 10px; height: 10px; margin-inline-end: 4px; border: 1px solid var(--muted); border-radius: 50%; vertical-align: middle; }
.chart-grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); align-items: start; }
.chart-stage { overflow-x: auto; }
.chart-caption { margin: 4px 0; }
.odontogram { width: 100%; min-width: 560px; height: auto; display: block; }
.tooth { cursor: pointer; outline: none; }
.tooth .surface { fill: var(--surface); stroke: var(--muted); stroke-width: 1; }
.tooth .surface.planned { fill-opacity: .4; stroke-dasharray: 3 2; }
.tooth:hover .surface, .tooth:focus-visible .surface { stroke: var(--teal); stroke-width: 2; }
.tooth.selected .surface { stroke: var(--teal); stroke-width: 2.5; }
.tooth-label { font-size: 12px; fill: var(--ink); font-family: var(--font); }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: .85rem; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; border: 1px solid var(--line); }
.dot.planned { background: var(--surface); border: 2px dashed var(--muted); }
.surface-check { min-width: 56px; }
.history-row { border-top: 1px solid var(--line); padding: 8px 0; }
.history-row.struck strong { text-decoration: line-through; font-weight: 500; }

/* bar charts: heights come from the data, the numbers are written on the bars */
.bars { margin: 0; }
.bars-plot { display: flex; align-items: stretch; gap: 8px; height: 190px; overflow-x: auto; overflow-y: hidden; padding-inline: 10px; }
.bars-group { flex: 1 1 42px; min-width: 42px; display: flex; flex-direction: column; gap: 4px; }
.bars-stack { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 3px; min-height: 0; padding-top: 16px; }
.bar { position: relative; flex: 1 1 0; max-width: 30px; min-height: 2px; border-radius: 3px 3px 0 0; }
.bar-value { position: absolute; bottom: 100%; inset-inline: -8px; text-align: center; font-size: .68rem; color: var(--muted); }
.bars-label { text-align: center; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* timeline */
.timeline { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }
.timeline-item { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 12px; align-items: start; }
.timeline-when { color: var(--muted); font-size: .85rem; padding-top: 10px; }
.timeline-item .card p { margin: 4px 0 0; }
.t-alert .card { border-inline-start: 3px solid var(--danger); }
.t-visit .card { border-inline-start: 3px solid var(--teal); }
.t-prescription .card, .t-plan .card { border-inline-start: 3px solid #2563eb; }
.t-tooth .card { border-inline-start: 3px solid #9333ea; }
.t-file .card, .t-follow_up .card { border-inline-start: 3px solid var(--muted); }

/* documents */
.doc-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.doc-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.doc-open { border: 0; padding: 0; background: var(--surface-2); cursor: pointer; }
.doc-thumb { height: 130px; display: grid; place-items: center; overflow: hidden; }
.doc-thumb img { width: 100%; height: 100%; object-fit: cover; }
.doc-type { font-weight: 700; color: var(--muted); letter-spacing: .05em; }
.doc-meta { padding: 10px; display: grid; gap: 2px; overflow-wrap: anywhere; }
.doc-preview img { max-width: 100%; max-height: 60vh; display: block; margin: 0 auto 12px; }
.webcam { width: 100%; border-radius: var(--radius); background: #000; }

/* planning */
.capacity { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; } /* without minmax(0, …) the days stretch the page instead of scrolling */
.capacity-days { display: flex; gap: 4px; overflow-x: auto; margin-top: 4px; }
.capacity-day { flex: 0 0 auto; min-width: 54px; text-align: center; border: 1px solid var(--line); border-radius: 6px; padding: 4px; text-decoration: none; display: grid; background: var(--teal-soft); color: var(--ink); }
.capacity-day.full { background: var(--surface-2); color: var(--muted); }

/* WhatsApp templates, import */
.tpl-list { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.tpl-preview { font-size: .85rem; margin-top: 4px; }
.map-grid { display: grid; gap: 8px 12px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.import-table td { vertical-align: top; min-width: 130px; }
.import-map td { vertical-align: middle; }
.import-map td:nth-child(2) { max-width: 220px; overflow-wrap: anywhere; }
.import-format > summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
.merge-table th[scope="row"] { text-align: start; color: var(--muted); font-weight: 500; }
.merge-table td, .merge-table th { vertical-align: top; }
.perm-table td, .perm-table th { vertical-align: middle; }
.perm-table tr.perm-group th { background: var(--surface-2); text-align: start; font-weight: 600; }
.perm-table td.perm-cell { white-space: nowrap; }

@media (max-width: 900px) {
  .chart-grid, .odo-grid { grid-template-columns: minmax(0, 1fr); }
  .odo-side { max-height: none; }
  .timeline-item { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .timeline-when { padding-top: 0; }
}

/* ------------------------------------------------------------------ Dental Chart parts and the Periodontal Chart */
.side-sub { display: none; flex-direction: column; margin-block: 0 4px; padding-inline-start: 14px; }
.side-sub.open { display: flex; }
.side-nav .side-sub a.sub { font-size: .84rem; padding-block: 5px; opacity: .85; }
.side-nav .side-sub a.sub.active { opacity: 1; font-weight: 600; }
.chart-parts { margin-block-end: 10px; }
.chart-parts .tabs { border-bottom: 1px solid var(--line); }
.tooth-input { width: 5.5em; }
.perio-note { display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.perio { display: grid; gap: 8px; min-width: 0; }
.perio-main, .perio-bottom { display: grid; gap: 8px; min-width: 0; }
body.perio-compact .patient-head { padding: 4px 10px; gap: 8px; }
body.perio-compact .patient-head .avatar { width: 28px; height: 28px; font-size: .75rem; }
body.perio-compact .patient-head h1 { font-size: 1rem; margin: 0; }
body.perio-compact .patient-head p { display: inline; margin: 0; font-size: .82rem; }
body.perio-compact .patient-head .grow { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; }
body.perio-compact .patient-head .actions { display: none; }
body.perio-compact .page > .info-box { display: none; }
body.perio-compact .page > .alert-box { padding: 3px 10px; font-size: .85rem; margin: 0; }
body.perio-compact .page { gap: 6px; }
body.perio-compact .patient-tabs .tab, body.perio-compact .chart-parts .tab { padding-block: 3px; font-size: .86rem; }
body.perio-compact .chart-parts { margin-block-end: 4px; }
body.perio-compact .tab-body { padding-block-start: 4px; }
.perio-head .field { display: flex; align-items: center; gap: 6px; }
.perio-head .field label { white-space: nowrap; margin: 0; font-size: .82rem; }
.perio-head input, .perio-head select { padding-block: 3px; min-height: 0; height: 30px; }
.perio-head .field input[type=date] { width: 9.2em; }
.perio-head .field input[type=time] { width: 7.2em; }
.perio-head .field select { max-width: 13em; }
.perio-settings { position: relative; }
.perio-settings > summary { list-style: none; cursor: pointer; }
.perio-settings-body { position: absolute; inset-inline-end: 0; top: calc(100% + 4px); z-index: 5; width: min(340px, 86vw); display: grid; gap: 8px; padding: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.perio-settings-body select { width: 100%; }
.perio-head { display: grid; gap: 4px; background: var(--surface, #fff); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.perio-head-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.perio-head-row.wrap { flex-wrap: wrap; align-items: flex-end; }
.perio-head-row .field { margin: 0; }
.perio-pick { min-width: 0; }
.perio-pick select { width: 100%; }
.perio-save { margin-inline-start: auto; font-size: .85rem; color: var(--muted); }
.perio-save.saving { color: var(--muted); }
.perio-save.saved { color: var(--teal); }
.perio-save.failed { color: var(--danger); font-weight: 600; }
.perio-state.perio-draft { background: var(--surface-2); }
.perio-state.perio-completed { background: var(--teal-soft); color: var(--teal); }
.perio-state.perio-amended { background: var(--warn-soft); color: var(--warn); }
.perio-banners:empty { display: none; }
.perio-banners p { margin: 0; }
.perio-tools { display: grid; gap: 4px; }
.perio-tool-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.perio-tool-row select { width: auto; max-width: 100%; }
.perio-zoom { display: inline-flex; gap: 2px; }
.perio-recording { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.perio-message { margin: 0; min-height: 0; }
.perio-message:empty { display: none; }
.perio-stage { overflow-x: auto; background: var(--surface, #fff); border: 1px solid var(--line); border-radius: 8px; padding: 4px; outline: none; touch-action: manipulation; }
.perio-stage:focus-visible { border-color: var(--teal); box-shadow: 0 0 0 2px var(--teal-soft); }
.perio-arch { display: block; min-width: 800px; user-select: none; -webkit-user-select: none; }
.perio-arch + .perio-arch { margin-block-start: 6px; border-block-start: 1px dashed var(--line); padding-block-start: 4px; }
.perio-arch text { font-family: inherit; pointer-events: none; fill: var(--ink); }
.p-row { font-size: 9px; fill: var(--muted) !important; }
.p-row.small { font-size: 7px; }
.p-side { font-size: 8px; fill: var(--muted) !important; font-weight: 600; }
.p-grid { stroke: var(--line); stroke-width: .5; }
.p-midline { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.p-num { font-size: 12px; font-weight: 600; pointer-events: auto !important; cursor: pointer; }
.p-num.on { fill: var(--teal) !important; }
.p-num-bg { fill: var(--teal-soft); }
.p-badge { font-size: 8.5px; font-weight: 700; fill: var(--muted) !important; }
.p-note { fill: #2563eb; }
.p-cell { fill: transparent; cursor: cell; pointer-events: all; }
.p-cell:hover { fill: var(--teal-soft); }
.p-cell.readonly, .p-cell.diagram { cursor: pointer; }
.p-cell.diagram:hover { fill: transparent; }
.p-cell.flag { cursor: pointer; }
.p-val { font-size: 11.5px; }
.p-val.cal { font-size: 9.5px; fill: var(--muted) !important; }
.p-val.hot { font-weight: 700; }
.p-val.cal.hot { fill: inherit; }
.p-gone { fill: var(--surface-2); cursor: pointer; pointer-events: all; }
.p-gone-text { font-size: 9.5px; fill: var(--muted) !important; }
.p-x { stroke: var(--muted); stroke-width: 1.5; pointer-events: none; }
.p-crown { fill: var(--surface-2); stroke: var(--muted); stroke-width: .7; pointer-events: none; }
.p-root { fill: var(--surface, #fff); stroke: var(--muted); stroke-width: .7; pointer-events: none; }
.p-implant { fill: var(--muted); pointer-events: none; }
.p-implant-line { stroke: var(--muted); stroke-width: 1; pointer-events: none; }
.p-cej { stroke: var(--muted); stroke-width: .6; stroke-dasharray: 2 2; pointer-events: none; }
.p-lines { pointer-events: none; }
.p-tooth { pointer-events: none; }
.p-gingiva { opacity: .2; }
.p-pocket { opacity: .3; pointer-events: none; }
.p-base { fill: none; stroke-width: 1.2; }
.p-base.assumed, .p-depth.assumed { stroke-dasharray: 2 2; }
.p-mm { stroke: var(--line); stroke-width: .35; opacity: .75; }
.p-mm.strong { stroke-width: .6; opacity: 1; }
.p-furc { fill: none; stroke: #7c2d12; stroke-width: 1; }
.p-furc.grade3 { fill: #7c2d12; }
.perio-furc { letter-spacing: 1px; }
.perio-compare { display: flex; flex-wrap: wrap; gap: 12px; width: 100%; }
.perio-compare-col { flex: 1 1 520px; min-width: 0; }
.perio-compare-col h4 { margin: 0 0 4px; }
.perio-compare-col .perio-arch { width: 100%; min-width: 0; }
.p-depth { stroke-width: 2; pointer-events: none; }
.p-margin { fill: none; stroke-width: 1.7; pointer-events: none; }
.p-margin-dot { pointer-events: none; }
.p-mark { pointer-events: none; }
.p-mark.bop { fill: #dc2626; }
.p-mark.plaque { fill: #2563eb; }
.p-mark.supp { fill: #ca8a04; }
.p-mark.none { fill: var(--line); }
.p-cursor { fill: none; stroke: var(--teal); stroke-width: 2; pointer-events: none; }
.perio-pad { display: grid; gap: 6px; }
.perio-pad-label { font-size: .9rem; }
.perio-pad-nums, .perio-pad-side { display: none; }
.perio-key { min-width: 44px; min-height: 44px; padding: 4px 8px; font-size: 1.05rem; touch-action: manipulation; }
.perio-key[aria-pressed="true"] { background: var(--teal); color: #fff; border-color: var(--teal); }
.perio-key.flag { font-size: .85rem; }
.perio-pad-nums { grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 4px; }
.perio-pad-side { flex-wrap: wrap; gap: 4px; }
@media (pointer: coarse) { .perio-pad-nums { display: grid; } .perio-pad-side { display: flex; } }
.perio-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: .8rem; color: var(--muted); }
.perio-sym { display: inline-block; width: 9px; height: 9px; margin-inline-end: 4px; vertical-align: middle; }
.perio-sym.bop { background: #dc2626; border-radius: 50%; }
.perio-sym.plaque { background: #2563eb; }
.perio-sym.supp { background: #ca8a04; transform: rotate(45deg); }
.perio-sym.line { background: #c0395a; height: 2px; width: 14px; }
.perio-sym.base { background: #1d4ed8; height: 2px; width: 14px; }
.perio-sym.gingiva { background: #e8899f; opacity: .6; width: 14px; }
.perio-sym.nomargin { border-top: 2px dashed #1d4ed8; height: 0; width: 14px; }
.perio-sym.cej { border-top: 1px dashed var(--muted); height: 0; width: 14px; }
.perio-sym.gone { background: var(--surface-2); border: 1px solid var(--line); }
.perio-help { flex-basis: 100%; }
.perio-help p { margin: 4px 0; }
.perio-bottom-body { display: grid; gap: 8px; padding-block: 8px; min-width: 0; }
.perio-bottom-body p { margin-block: 0; }
.perio-tiles { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.perio-tile { padding: 8px 10px; }
.perio-tile .tile-value { font-size: 1.1rem; }
.perio-grid { min-width: 0; }
.perio-grid > * { min-width: 0; }
.perio-actions { display: flex; flex-wrap: wrap; gap: 8px; position: sticky; bottom: 0; z-index: 3; padding-block: 6px; background: var(--bg); border-block-start: 1px solid var(--line); }
.perio-actions:empty { display: none; }
body.perio-quick .perio-actions { display: none; }
.perio-chips { display: flex; gap: 4px; }
.perio-site-table th, .perio-site-table td { text-align: center; padding: 3px 6px; }
.perio-disclaimer { font-size: .8rem; }
.perio-trends { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 8px; }
.perio-trend { margin: 0; min-width: 0; }
.perio-trend figcaption { font-size: .82rem; font-weight: 600; }
.perio-trend-plot { position: relative; }
.perio-trend svg { display: block; width: 100%; height: auto; }
.perio-tip { position: absolute; transform: translate(-50%, -130%); background: var(--ink); color: var(--surface, #fff); font-size: .75rem; padding: 2px 6px; border-radius: 4px; white-space: nowrap; pointer-events: none; }
.p-axis { stroke: var(--line); }
.p-tick { font-size: 8.5px; fill: var(--muted); }
.p-tick.strong { fill: var(--ink); font-weight: 600; }
.p-trend { fill: none; stroke: var(--teal); stroke-width: 2; }
.p-trend-dot { fill: var(--teal); stroke: var(--surface, #fff); stroke-width: 2; }
.p-hit { fill: transparent; }

/* Quick entry: only the chart, the patient's alerts and the pad, for the chair */
body.perio-quick .sidebar, body.perio-quick .topbar, body.perio-quick .patient-head, body.perio-quick .patient-tabs, body.perio-quick .chart-parts, body.perio-quick .info-box, body.perio-quick .perio-bottom, body.perio-quick .perio-legend { display: none; }
body.perio-quick .content { padding: 6px 8px; }
.perio-who { display: none; }
body.perio-quick .perio-who { display: block; font-size: .95rem; }
body.perio-quick .perio-head-row.wrap .field, body.perio-quick .perio-pick { display: none; }
body.perio-quick .perio-head-row.wrap { justify-content: flex-end; }
body.perio-quick .perio-head { padding: 4px 8px; }
body.perio-quick .perio-pad { position: sticky; bottom: 0; background: var(--bg, var(--surface, #fff)); border-block-start: 1px solid var(--line); padding-block: 4px; grid-template-columns: repeat(2, minmax(0, 1fr)); z-index: 2; }
body.perio-quick .perio-pad-info, body.perio-quick .perio-pad-nums { grid-column: 1 / -1; }
body.perio-quick .perio-key { min-height: 40px; }
body.perio-quick .perio-pad-nums { display: grid; }
body.perio-quick .perio-pad-side { display: flex; }
@media print { body.perio-quick .perio-pad { display: none; } }
