/* KS Dental Clinica - application interface */
:root {
  --brand: #7a6a5f;
  --brand-600: #66574d;
  --brand-700: #4f433b;
  --brand-50: #f6f3f0;
  --brand-100: #ece6e1;
  --side: #2e2925;
  --side-2: #3a342f;
  --bg: #f4f2ef;
  --card: #fff;
  --text: #1f1c1a;
  --muted: #6f6862;
  --line: #e4dfda;
  --accent: #2f7d6d;
  --accent-50: #e8f4f1;
  --danger: #b4342a;
  --danger-50: #fbeceb;
  --warn: #9a6a00;
  --ok: #24794a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(30, 20, 10, .06), 0 2px 10px rgba(30, 20, 10, .05);
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { font-size: 14px; line-height: 1.45; }
a { color: var(--brand-700); }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 244px 1fr; min-height: 100vh; }
.side { background: var(--side); color: #e8e2dd; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { padding: 18px 18px 12px; display: flex; flex-direction: column; align-items: center; border-bottom: 1px solid rgba(255,255,255,.07); }
.side .brand img { width: 150px; height: auto; }
.side .brand small { color: #b6aca4; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; margin-top: 2px; }
.nav { padding: 10px 10px 18px; display: flex; flex-direction: column; gap: 2px; }
.nav .sec { font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: #9b918a; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: #e8e2dd; text-decoration: none; font-size: 13.5px; }
.nav a:hover { background: var(--side-2); }
.nav a.active { background: #fff; color: var(--side); font-weight: 600; }
.nav a .ico { width: 17px; height: 17px; opacity: .9; }
.side .me { margin-top: auto; padding: 12px 14px; border-top: 1px solid rgba(255,255,255,.07); font-size: 12.5px; display: flex; align-items: center; gap: 8px; }
.side .me .who { flex: 1; min-width: 0; }
.side .me .who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .me .who span { color: #b6aca4; }
.side .me button { color: #e8e2dd; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(244, 242, 239, .92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); padding: 10px 24px; display: flex; align-items: center; gap: 12px; }
.topbar .menu-btn { display: none; }
.content { padding: 22px 24px 60px; max-width: 1280px; width: 100%; margin: 0 auto; }
.content.wide { max-width: none; padding: 0; }
.page-head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .titles { flex: 1; min-width: 240px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* global search */
.gsearch { position: relative; flex: 1; max-width: 560px; }
.gsearch input { padding-left: 36px; }
.gsearch .ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.gsearch .results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px rgba(0,0,0,.12); max-height: 420px; overflow: auto; z-index: 30; }
.gsearch .results a { display: flex; gap: 10px; padding: 9px 12px; text-decoration: none; color: var(--text); border-bottom: 1px solid var(--brand-50); align-items: center; }
.gsearch .results a:hover, .gsearch .results a.sel { background: var(--brand-50); }
.gsearch .results .empty { padding: 12px; color: var(--muted); }

/* ---------- controls ---------- */
.input, select.input, textarea.input {
  width: 100%; padding: 8px 11px; border: 1px solid #d5cec8; border-radius: 8px; background: #fff; font: inherit; color: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(122, 106, 95, .18); }
textarea.input { resize: vertical; min-height: 70px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12.5px; font-weight: 600; color: #4c4540; }
.field .req { color: var(--danger); }
.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }
.span-all { grid-column: 1 / -1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid #d5cec8; background: #fff; color: var(--text); font: inherit; font-weight: 600; font-size: 13.5px;
  cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--brand-50); border-color: #c8c0b9; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand-700); border-color: var(--brand-700); color: #fff; }
.btn.primary:hover { background: var(--brand-600); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.accent:hover { filter: brightness(1.07); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--brand-50); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn .ico { width: 16px; height: 16px; }
.icon-btn { border: 0; background: transparent; cursor: pointer; padding: 6px; border-radius: 6px; font-size: 20px; line-height: 1; color: inherit; display: inline-flex; }
.icon-btn:hover { background: rgba(0,0,0,.06); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.seg { display: inline-flex; border: 1px solid #d5cec8; border-radius: 8px; overflow: hidden; margin-bottom: 12px; }
.seg-btn { border: 0; background: #fff; padding: 7px 14px; font: inherit; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg-btn.active { background: var(--brand-700); color: #fff; }

.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- upcoming adjustments ---------- */
.check-btn { width: 40px; height: 40px; border-radius: 10px; border: 2px solid #cfc6be; background: #fff; display: grid; place-items: center; cursor: pointer; padding: 0; }
.check-btn svg { width: 22px; height: 22px; fill: none; stroke: transparent; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.check-btn:hover { border-color: var(--ok); }
.check-btn.on { background: var(--ok); border-color: var(--ok); }
.check-btn.on svg { stroke: #fff; }
.adj-table tr.is-done td { background: #f6fbf8; }
.adj-table tr.is-done .pname { color: var(--muted); }
.adj-table a[href^="tel:"] { color: var(--accent); text-decoration: none; font-weight: 600; display: inline-flex; gap: 6px; align-items: center; }
.adj-notice { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; text-decoration: none; color: inherit; background: var(--accent-50); border-color: #bfe0d8; }
.nav a { position: relative; }
.nav-badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; background: #d9534f; color: #fff; font-size: 11.5px; font-weight: 700; display: inline-grid; place-items: center; }
.nav-badge[hidden] { display: none; }
@media (max-width: 1279px) and (min-width: 700px) {
  .nav-badges { position: absolute; top: 3px; right: 6px; margin: 0; }
}

.update-banner { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 150; background: #2e2925; color: #fff; padding: 10px 12px 10px 16px; border-radius: 12px; display: flex; gap: 12px; align-items: center; box-shadow: 0 12px 32px rgba(0,0,0,.3); }

/* ---------- procedure history ---------- */
table.tbl.hist-table { table-layout: fixed; min-width: 860px; }
table.tbl.hist-table th, table.tbl.hist-table td { text-align: center; vertical-align: middle; }
table.tbl.hist-table th { padding: 12px 10px; }
table.tbl.hist-table td { padding: 14px 10px; }
.hist-table .c-date { width: 120px; }
.hist-table .c-no { width: 70px; }
.hist-table .c-next { width: 140px; }
.hist-table .c-money { width: 110px; }
.hist-table .c-sig { width: 180px; }
.hist-table .c-by { width: 120px; }
.hist-table td.h-desc { overflow-wrap: anywhere; }
.hist-table .h-date { font-weight: 600; }
.hist-table .h-desc { max-width: 320px; margin: 0 auto; line-height: 1.35; }
.hist-table .h-money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.hist-table .h-bal { font-weight: 700; }
.hist-table tbody tr:nth-child(even) td { background: #fcfbfa; }
.hist-table tbody tr.click:hover td { background: var(--brand-50); }
.next-pill { display: inline-block; padding: 3px 10px; border-radius: 99px; background: #e6eefb; color: #2a4f9a; font-weight: 600; font-size: 12.5px; }
.sig-tags { display: inline-flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.sig-tag { display: inline-flex; align-items: center; gap: 3px; padding: 2px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 650; background: #f1eeeb; color: #9b918a; white-space: nowrap; }
.sig-tag.ok { background: #e3f3e9; color: var(--ok); }

.input.bad-phone { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(180, 52, 42, .12); }

/* ---------- handwriting pad ---------- */
.desc-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.seg.desc-mode { margin: 0; }
.seg.desc-mode .seg-btn { padding: 5px 12px; font-size: 12.5px; display: inline-flex; align-items: center; gap: 5px; }
.seg.desc-mode .seg-btn .ico { width: 14px; height: 14px; }
.inkpad { position: relative; border: 1.5px solid #cfc6be; border-radius: 10px; background: #fff; aspect-ratio: 1800 / 400; overflow: hidden; }
.inkpad canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; z-index: 1; }
.inkpad-line { position: absolute; left: 3%; right: 3%; top: 72%; border-top: 1.5px dashed #ddd5ce; }
.inkpad-ph { position: absolute; inset: 0; display: grid; place-items: center; color: #b8ada4; font-size: 14px; pointer-events: none; }
.inkpad-ph[hidden] { display: none; }
.inkpad-tools { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.h-ink { display: block; height: 30px; }
.h-ink .ink-img { height: 100%; max-width: 100%; object-fit: contain; }
.hist-table td.h-desc .h-ink .ink-img { margin: 0 auto; display: block; }
.wl-proc .h-ink { height: 26px; display: inline-block; vertical-align: middle; }

/* ---------- waiting list ---------- */
.st-waiting { --st: #c27c0e; --st-bg: #fdf3dc; }
.st-treat { --st: #2a62b8; --st-bg: #e7effb; }
.st-pay { --st: #7b4bb7; --st-bg: #f2ecfa; }
.st-done { --st: #24794a; --st-bg: #e3f3e9; }
.wl-legend { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
@media (max-width: 1100px) { .wl-legend { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.wl-pay { color: var(--st, #7b4bb7); font-weight: 650; }
.wl-row.st-pay td { background: #fbf8ff; }
.wl-proc { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: #fff; border: 1px solid var(--line); }
.wl-proc-desc { display: inline-flex; align-items: center; gap: 8px; min-width: 120px; }
.wl-forms { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.wl-forms .btn .ico { width: 15px; height: 15px; }
.today-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 8px 16px; background: var(--st-bg); border-bottom: 1px solid var(--line); border-left: 6px solid var(--st); font-size: 13.5px; }
.today-bar b.st { color: var(--st); }
.wl-visit { flex-direction: column; align-items: stretch; gap: 4px; }
.wl-visit-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 2px 0; border-bottom: 1px dashed var(--line); }
.wl-visit-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; padding-top: 4px; }
.pay-table td, .pay-table th { vertical-align: middle; }
.pay-table th.num, .pay-table td.num { text-align: right; white-space: nowrap; }
.pay-table .h-ink { height: 34px; }
.pay-table .pay-in { width: 120px; text-align: right; margin-left: auto; display: block; }
.pay-table td:first-child { min-width: 160px; }
.pay-table th { white-space: nowrap; }
.pay-sum { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; margin-top: 12px; padding: 10px 14px; background: var(--brand-50); border-radius: 8px; font-variant-numeric: tabular-nums; }
.pay-sum b { text-align: right; }
.pay-sum .pay-due { font-size: 16px; font-weight: 700; }
.wl-money { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.wl-money b { color: var(--text); }
.nav-badges { margin-left: auto; display: inline-flex; gap: 4px; }
.nav-badges .nav-badge { margin: 0; position: static; }
.nav-badge.b-payment { background: #7b4bb7; }
.wl-count { display: flex; align-items: center; gap: 14px; padding: 14px 18px; text-decoration: none; color: inherit; border: 2px solid transparent; border-left: 6px solid var(--st); }
.wl-count .n { font-size: 34px; font-weight: 750; color: var(--st); min-width: 40px; text-align: center; letter-spacing: -.02em; }
.wl-count .dot { display: none; }
.wl-count.active { border-color: var(--st); border-left-width: 6px; background: var(--st-bg); }
.wl-next { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px; padding: 12px 16px; margin-bottom: 14px; border-radius: var(--radius); background: #fff; border: 1px dashed #d8b46a; }
.wl-next-name { font-size: 17px; }
.qno { display: inline-grid; place-items: center; min-width: 38px; height: 30px; padding: 0 8px; border-radius: 8px; background: var(--brand-100); color: var(--brand-700); font-weight: 750; font-size: 14px; }
.wl-table td, .wl-table th { vertical-align: middle; }
.wl-table th.c, .wl-table td.c { text-align: center; }
.wl-row td:first-child { box-shadow: inset 5px 0 0 var(--st); }
.wl-row.st-done td, .wl-row.st-done .pname { color: var(--muted); }
.wl-row.st-treat td { background: #f7faff; }
.wl-name { font-size: 15px; margin-bottom: 3px; }
.wl-notes { margin-top: 3px; color: #5a514b; font-style: italic; }
.wl-wait { color: #9a5d00; font-weight: 650; }
.wl-table .seg { margin: 0; border-color: var(--line); }
.wl-table .seg button { border: 0; border-left: 1px solid var(--line); background: #fff; padding: 8px 12px; font: inherit; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; }
.wl-table .seg button:first-child { border-left: 0; }
.wl-table .seg button:hover { background: var(--st-bg); color: var(--st); }
.wl-table .seg button.on { background: var(--st); color: #fff; }
.wl-date .input { width: auto; }
.wl-results { max-height: 260px; margin-top: 6px; }
.wl-linked { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid #bfe0d8; background: var(--accent-50); border-radius: 8px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 5px 12px; font: inherit; font-size: 12.5px; cursor: pointer; color: var(--brand-700); }
.chip:hover { background: var(--brand-50); }
.chip.on { background: var(--brand-700); border-color: var(--brand-700); color: #fff; }
.chip-more { border-style: dashed; color: var(--muted); }
.chip-extra { margin-top: 6px; padding-top: 8px; border-top: 1px dashed var(--line); }
.wl-reasons { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.wl-dash { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; padding: 12px 16px; margin-bottom: 16px; text-decoration: none; color: inherit; }
.wl-dash .t { font-size: 15px; }
.wl-pill { display: inline-flex; align-items: baseline; gap: 5px; padding: 4px 12px; border-radius: 99px; background: var(--st-bg); color: var(--st); font-weight: 600; }
.wl-pill b { font-size: 17px; }
.show-sm { display: none; }
@media (pointer: coarse) {
  .wl-table .seg button { padding: 12px 14px; }
  .chip { padding: 9px 14px; }
}
@media (max-width: 699px) {
  .wl-legend { grid-template-columns: 1fr; gap: 8px; }
  .show-sm { display: block; }
  .wl-table .seg button { padding: 8px; font-size: 12px; }
}

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -4px 0 14px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 10px 16px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 2.5px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--brand-700); border-bottom-color: var(--brand-700); }
.tab .count { display: inline-block; min-width: 22px; padding: 1px 7px; border-radius: 99px; background: var(--brand-100); color: var(--brand-700); font-size: 12px; margin-left: 4px; text-align: center; }
@media (pointer: coarse) { .tab { padding: 13px 18px; } }

/* ---------- cards / tables ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head h2, .card-head h3 { flex: 1; }
.card-body { padding: 16px 18px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: inherit; }
.stat:hover { border-color: #cfc6be; }
.stat .n { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.stat .l { color: var(--muted); font-size: 13px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #faf8f6; white-space: nowrap; }
table.tbl td { padding: 11px 14px; border-bottom: 1px solid #efebe7; vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl tbody tr.click { cursor: pointer; }
table.tbl tbody tr.click:hover { background: var(--brand-50); }
table.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }
.pname { font-weight: 650; color: var(--text); text-decoration: none; }
.pname:hover { text-decoration: underline; }
.empty-state { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty-state .ico { width: 34px; height: 34px; margin-bottom: 8px; opacity: .6; }
.pager { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.toolbar { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); align-items: center; flex-wrap: wrap; }
.search { position: relative; flex: 1; min-width: 220px; max-width: 460px; }
.search input { padding-left: 34px; }
.search .ico { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 650; background: var(--brand-100); color: var(--brand-700); white-space: nowrap; }
.badge.ortho { background: #e6eefb; color: #2a4f9a; }
.badge.general { background: #fdeceb; color: #a0352b; }
.badge.ok { background: #e3f3e9; color: var(--ok); }
.badge.warn { background: #fdf3dc; color: var(--warn); }
.badge.danger { background: var(--danger-50); color: var(--danger); }

/* ---------- profile ---------- */
.profile-head { display: flex; gap: 18px; align-items: flex-start; padding: 20px; flex-wrap: wrap; }
.avatar { width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 20px; background: var(--brand-100); color: var(--brand-700); flex: none; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 22px; padding: 0 20px 20px; }
.kv div span { display: block; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.kv div b { font-weight: 600; word-break: break-word; }
.doc-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.doc-card { display: flex; gap: 12px; padding: 14px 16px; text-decoration: none; color: inherit; align-items: flex-start; }
.doc-card:hover { border-color: #c7bdb5; background: #fffdfb; }
.doc-card .thumb { width: 42px; height: 52px; border-radius: 4px; border: 1px solid var(--line); background: #fff; display: grid; place-items: center; color: var(--brand); flex: none; }
.doc-card b { display: block; }
.doc-card .meta { font-size: 12px; color: var(--muted); }
.section { margin-top: 22px; }
.section > .sec-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.section > .sec-head h2 { flex: 1; }

/* ---------- document editor ---------- */
.doc-bar { background: #fff; border-bottom: 1px solid var(--line); padding: 8px 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; box-shadow: 0 2px 8px rgba(0,0,0,.04); }
.doc-bar { flex-wrap: nowrap; }
.doc-bar .title { min-width: 0; flex: 1; line-height: 1.3; }
.doc-bar .title b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-bar .title span { font-size: 12.5px; color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.save-state { font-size: 12.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.save-state.dirty { color: var(--warn); }
.save-state.error { color: var(--danger); font-weight: 600; }
.save-state.ok { color: var(--ok); }
.doc-sub { display: flex; gap: 8px; align-items: center; padding: 8px 16px; background: #faf8f6; border-bottom: 1px solid var(--line); flex-wrap: wrap; font-size: 13px; }
.doc-sub .sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.doc-canvas { background: #e7e3df; padding: 26px 16px 60px; overflow-x: auto; min-height: calc(100vh - 110px); touch-action: pan-x pan-y; }
.doc-canvas.annotating .f-draw canvas { touch-action: none; }
.sheet-stack { width: max-content; margin: 0 auto; }
.half-page { position: relative; overflow: hidden; margin: 0 auto 28px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.18), 0 8px 28px rgba(0,0,0,.12); }
.half-page > .sheet { margin: 0 !important; box-shadow: none; }
.doc-sub .seg-btn { padding: 6px 12px; font-size: 13px; }
.doc-sub > * { flex-shrink: 0; }
.sheet-caption { font-size: 12px; color: #6d655f; margin: 0 0 6px 2px; font-weight: 600; letter-spacing: .02em; }
.annot-tools { display: none; gap: 6px; align-items: center; }
.annotating .annot-tools, .annot-tools.on { display: inline-flex; }
.swatch { width: 20px; height: 20px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px #bbb; cursor: pointer; }
.swatch.sel { box-shadow: 0 0 0 2px var(--text); }
.legend { display: inline-flex; gap: 10px; align-items: center; color: var(--muted); }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 50%; vertical-align: -1px; margin-right: 4px; }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(28, 22, 18, .45); display: grid; place-items: center; z-index: 100; padding: 20px; animation: fade .12s ease-out; }
@keyframes fade { from { opacity: 0; } }
.modal { background: #fff; border-radius: 14px; box-shadow: 0 24px 64px rgba(0,0,0,.25); width: 100%; max-height: calc(100vh - 40px); display: flex; flex-direction: column; }
.modal-sm { max-width: 440px; } .modal-md { max-width: 640px; } .modal-lg { max-width: 880px; }
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { flex: 1; font-size: 16.5px; }
.modal-body { padding: 18px; overflow: auto; }
.modal-body p { margin-top: 0; }
.modal-foot { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); align-items: center; justify-content: flex-end; }
.hint { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }
.notice { padding: 10px 12px; border-radius: 8px; background: var(--brand-50); border: 1px solid var(--line); font-size: 13px; }
.notice.warn { background: #fdf6e3; border-color: #f0dca6; }
.notice.danger { background: var(--danger-50); border-color: #f0c4c0; color: #7c231b; }
.sigpad { position: relative; border: 1px dashed #bdb3ab; border-radius: 10px; background: #fff; }
.sigpad canvas { width: 100%; height: auto; aspect-ratio: 10 / 3; display: block; touch-action: none; cursor: crosshair; }
.sigpad-line { position: absolute; left: 6%; right: 6%; bottom: 22%; border-bottom: 1px solid #ccc; pointer-events: none; }
.sig-preview { font-size: 32px; min-height: 60px; padding: 8px; border-bottom: 1px solid #ccc; margin-top: 12px; }
.sig-thumb { display: flex; align-items: center; gap: 10px; }
.sig-thumb .box { height: 46px; min-width: 150px; border: 1px solid var(--line); border-radius: 6px; display: flex; align-items: center; justify-content: center; padding: 2px 8px; background: #fff; }
.sig-thumb .box img { max-height: 40px; max-width: 200px; }
.sig-thumb .box .sig-typed { font-size: 18px; }

.picker-list { max-height: 360px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; margin-top: 10px; }
.picker-list button { display: flex; width: 100%; text-align: left; gap: 10px; padding: 9px 12px; border: 0; border-bottom: 1px solid var(--brand-50); background: #fff; cursor: pointer; font: inherit; align-items: center; }
.picker-list button:hover { background: var(--brand-50); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 20% 0%, #d9d1ca 0%, transparent 60%), linear-gradient(160deg, #c0b8b2, #9e938a); }
.auth-card { width: 100%; max-width: 400px; background: #fff; border-radius: 16px; box-shadow: 0 30px 70px rgba(40, 30, 20, .25); padding: 28px; }
.auth-card .logo { display: flex; justify-content: center; margin: -4px 0 14px; }
.auth-card .logo img { width: 210px; }
.auth-card h1 { font-size: 19px; text-align: center; }
.auth-card p.sub { text-align: center; color: var(--muted); margin: 6px 0 20px; }
.auth-card form { display: grid; gap: 14px; }
.auth-card.wide { max-width: 620px; }
.setup-acct { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px 14px; margin: 0; }
.setup-acct legend { padding: 0 6px; display: flex; gap: 8px; align-items: center; }
.acct-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 10px; }
.acct { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 8px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; cursor: pointer; font: inherit; color: var(--text); }
.acct:hover { border-color: #c8c0b9; }
.acct.sel { border-color: var(--brand-700); background: var(--brand-50); box-shadow: 0 0 0 3px rgba(79, 67, 59, .15); }
.acct small { color: var(--muted); font-size: 11.5px; }
.acct-av { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-100); color: var(--brand-700); font-weight: 700; font-size: 17px; }
.acct.sel .acct-av { background: var(--brand-700); color: #fff; }
.perm-table td, .perm-table th { text-align: center; }
.perm-table td:first-child, .perm-table th:first-child { text-align: left; }
.perm-table input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--brand-700); cursor: pointer; }
.perm-table tr.area td { background: #faf8f6; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; padding-top: 8px; padding-bottom: 8px; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---------- toasts ---------- */
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #2e2925; color: #fff; padding: 10px 14px; border-radius: 9px; box-shadow: 0 10px 30px rgba(0,0,0,.25); font-size: 13.5px; max-width: 380px; transition: opacity .3s, transform .3s; }
.toast-success { background: #1f6b43; } .toast-error { background: #9c2b22; } .toast-warn { background: #8a5d00; }
.toast.leaving { opacity: 0; transform: translateY(8px); }

/* ---------- document editor header (sticky, one block) ---------- */
.doc-head { position: sticky; top: 0; z-index: 25; }
.doc-head .doc-bar { position: static; }
.doc-sub { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; white-space: nowrap; }
.doc-sub::-webkit-scrollbar { display: none; }
.doc-bar .bl { display: inline; }
body.doc-open .topbar { display: none; }
.nav a .short { display: none; }

/* ---------- touch screens (tablets) ---------- */
@media (pointer: coarse) {
  body { font-size: 15px; -webkit-tap-highlight-color: transparent; }
  .btn { min-height: 44px; padding: 10px 16px; font-size: 14.5px; }
  .btn.sm { min-height: 38px; padding: 7px 12px; font-size: 13.5px; }
  .icon-btn { padding: 10px; }
  .input, select.input { min-height: 46px; font-size: 16px; padding: 10px 12px; }
  textarea.input { font-size: 16px; }
  table.tbl td { padding: 14px; }
  table.tbl th { padding: 12px 14px; }
  .nav a { padding: 11px 12px; }
  .seg-btn { padding: 10px 18px; }
  .gsearch .results a { padding: 13px 14px; }
  .picker-list button { padding: 14px; }
  .swatch { width: 30px; height: 30px; }
  .modal-foot { padding: 14px 18px; }
  .sigpad canvas { aspect-ratio: 5 / 2; }
  .doc-canvas { -webkit-overflow-scrolling: touch; }
}

/* ---------- tablet: icon rail navigation (portrait and landscape) ---------- */
@media (max-width: 1279px) and (min-width: 700px) {
  .shell { grid-template-columns: 88px 1fr; }
  .side .brand { padding: 14px 6px 10px; }
  .side .brand img { width: 70px; }
  .side .brand small { display: none; }
  .nav { padding: 8px 6px; gap: 4px; }
  .nav .sec { font-size: 0; padding: 6px 0; margin: 4px 14px; border-top: 1px solid rgba(255,255,255,.1); }
  .nav a { flex-direction: column; gap: 4px; padding: 10px 2px; font-size: 11px; line-height: 1.15; text-align: center; }
  .nav a .ico { width: 22px; height: 22px; }
  .nav a .full { display: none; }
  .nav a .short { display: block; }
  .side .me { flex-direction: column; padding: 10px 4px; gap: 4px; }
  .side .me .who { display: none; }
  .content { padding: 18px 18px 50px; }
  .topbar { padding: 10px 18px; }
  .hide-md { display: none !important; }
  .doc-bar .bl { display: none; }
  .doc-bar .btn { padding-left: 12px; padding-right: 12px; }
  .doc-canvas { padding: 16px 8px 60px; }
  .two-col { grid-template-columns: 1fr; }
  .kv { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

/* ---------- phones: slide-out menu ---------- */
@media (max-width: 699px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 60; transform: translateX(-100%); transition: transform .2s; }
  .shell.nav-open .side { transform: none; box-shadow: 0 0 60px rgba(0,0,0,.35); }
  .topbar .menu-btn { display: inline-flex; }
  .content { padding: 16px 12px 50px; }
  .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; }
  .span2, .span3 { grid-column: auto; }
  .hide-sm, .hide-md { display: none !important; }
  .doc-bar .bl { display: none; }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 1100px) and (min-width: 700px) {
  .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media print {
  .side, .topbar, .doc-bar, .doc-sub, .no-print { display: none !important; }
}

/* ---------- privacy consent ---------- */
.consent-notice { border: 1px solid var(--line); border-radius: 8px; background: var(--bg, #faf8f5); padding: 12px 14px; font-size: 14px; line-height: 1.55; }
.consent-notice p { margin: 0 0 8px; }
.consent-notice p:last-child { margin-bottom: 0; }
.consent-title { font-weight: 600; }
.consent-checks { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; font-size: 15px; }
.consent-checks label { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.consent-checks input { width: 22px; height: 22px; margin-top: 1px; flex: none; }
.consent-sig { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 110px; margin-top: 10px; border: 1.5px dashed var(--line); border-radius: 8px; background: #fff; cursor: pointer; font: inherit; }
.consent-sig.signed { border-style: solid; }
.consent-sig img { max-height: 90px; max-width: 80%; }
.consent-sig .sig-typed { font-size: 28px; }
.consent-status { display: flex; align-items: center; gap: 10px; margin-top: 14px; padding: 10px 14px; border-radius: 8px; font-size: 14px; }
.consent-status.ok { background: #eef6ec; color: #2c5b25; }
.consent-status.missing { background: #fdf3e2; color: #6b4708; }
.consent-status .tick { font-weight: 700; }
.badge-btn { border: 0; cursor: pointer; font-family: inherit; }

/* Past records: photos of the old paper records, between the patient information record and the treatment record */
.photo-panel { margin: 0 auto 28px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px 16px; box-sizing: border-box; }
.photo-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.photo-head > div { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.photo-head b { font-size: 15px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.photo-tile { display: flex; flex-direction: column; align-items: stretch; gap: 4px; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; font: inherit; color: var(--text); text-align: left; }
.photo-tile img { width: 100%; height: 150px; object-fit: cover; border-radius: 4px; background: var(--brand-50); }
.photo-tile > span { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.photo-tile:hover { border-color: var(--brand); }
.photo-tile.add, .photo-tile.busy { align-items: center; justify-content: center; min-height: 176px; border-style: dashed; border-width: 1.5px; color: var(--brand-700); text-align: center; }
.photo-tile.add .ico { width: 28px; height: 28px; }
.photo-tile.busy { cursor: default; }
.modal-xl { max-width: min(1200px, 96vw); }
.photo-view { height: min(68vh, 900px); overflow: hidden; background: #2e2925; border-radius: 8px; display: flex; align-items: center; justify-content: center; cursor: zoom-in; }
.photo-view img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.photo-view.zoomed { overflow: auto; display: block; cursor: zoom-out; }
.photo-view.zoomed img { max-width: none; max-height: none; width: auto; }
.photo-view-bar { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.photo-view-bar .grow, .modal-foot .grow { flex: 1; }
