/* public/css/shell.css — fonts, toolbar, banners, modals, A4 sheet preview, shared print rules, fallback + home pages. */

@font-face { font-family: 'Sarabun'; font-style: normal; font-weight: 400; font-display: swap; src: url('/fonts/sarabun-latin-400.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Sarabun'; font-style: normal; font-weight: 400; font-display: swap; src: url('/fonts/sarabun-thai-400.woff2') format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Sarabun'; font-style: normal; font-weight: 700; font-display: swap; src: url('/fonts/sarabun-latin-700.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Sarabun'; font-style: normal; font-weight: 700; font-display: swap; src: url('/fonts/sarabun-thai-700.woff2') format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }

/* Theme tokens in shadcn/ui's vocabulary (https://ui.shadcn.com/docs/theming), hand-written: the screen chrome
   (toolbar, pickers, modals, home) is styled from these, the printed documents keep their own CSS. */
:root {
  --ink: #243b53; --brand: #2b6cb0; --chrome: #f4f7fb; --line: #d9e2ec; --text-scale: 1;
  --background: #ffffff; --foreground: #0f172a;
  --muted: #f1f5f9; --muted-foreground: #64748b;
  --accent: #f1f5f9; --accent-foreground: #0f172a;
  --primary: #2b6cb0; --primary-foreground: #ffffff;
  --border: #e2e8f0; --input: #e2e8f0; --ring: #2b6cb0;
  --radius: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, .1), 0 2px 4px -2px rgba(15, 23, 42, .1);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, .1), 0 4px 6px -4px rgba(15, 23, 42, .1);
}
* { box-sizing: border-box; }
/* The hidden attribute must beat author display rules (.empty is flex, the vitals line is flex) — found in the
   Task 14 browser check: without this, "No vital signs…" showed under real data on screen. */
[hidden] { display: none !important; }
body { margin: 0; background: var(--chrome); color: var(--ink); font-family: 'Sarabun', 'Segoe UI', sans-serif; }

/* toolbar */
.toolbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--background); border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm); flex-wrap: wrap; }
.tb-home { display: inline-flex; align-items: center; height: 36px; padding: 2px 6px; border-radius: var(--radius); }
.tb-home img { height: 30px; width: auto; display: block; }
.tb-home:hover { background: var(--accent); }
.tb-home:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.tb-title { font-weight: 700; color: var(--foreground); }
.tb-th { font-weight: 400; color: var(--muted-foreground); }
.tb-mock { background: #fde68a; color: #92400e; font-size: 11px; padding: 1px 6px; border-radius: 4px; font-weight: 700; }
.tb-group { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted-foreground); }
.tb-label { font-weight: 500; }
.tb-unit { color: var(--muted-foreground); }
.tb-spacer { flex: 1; }
/* buttons (shadcn "outline" / "default" variants) */
.tb-btn { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border: 1px solid var(--input); border-radius: var(--radius); background: var(--background); color: var(--foreground); font: inherit; font-size: 14px; font-weight: 500; line-height: 1; cursor: pointer; box-shadow: var(--shadow-sm); transition: background-color .12s, border-color .12s, color .12s; }
.tb-btn:hover { background: var(--accent); color: var(--accent-foreground); }
.tb-btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.tb-btn:disabled { opacity: .5; cursor: default; pointer-events: none; }
.tb-btn .ico { width: 16px; height: 16px; flex: 0 0 auto; }
.tb-icon { width: 36px; padding: 0; justify-content: center; }
.tb-primary { background: var(--primary); color: var(--primary-foreground); border-color: var(--primary); }
.tb-primary:hover { background: #245c96; color: var(--primary-foreground); }
/* inputs (shadcn "input") */
.tb-group input[type=number] { width: 64px; height: 36px; padding: 0 8px; border: 1px solid var(--input); border-radius: var(--radius); background: var(--background); color: var(--foreground); font: inherit; font-size: 14px; box-shadow: var(--shadow-sm); }
.tb-group input[type=number]:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
/* segmented control (shadcn "toggle group"): the Paper A4 / A5 switch of a document that offers both */
.tb-seg { display: inline-flex; gap: 2px; padding: 3px; background: var(--muted); border-radius: var(--radius); }
.tb-seg-btn { height: 28px; padding: 0 12px; border: 0; border-radius: 6px; background: transparent; color: var(--muted-foreground); font: inherit; font-size: 13px; font-weight: 600; line-height: 1; cursor: pointer; transition: background-color .12s, color .12s, box-shadow .12s; }
.tb-seg-btn:hover { color: var(--foreground); }
.tb-seg-btn.is-on { background: var(--background); color: var(--foreground); box-shadow: var(--shadow-sm); }
.tb-seg-btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
/* combobox (shadcn "combobox": a trigger button, a popover with a search box and a scrollable list) */
.combo { position: relative; display: inline-block; }
.combo-btn { display: inline-flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 190px; max-width: 320px; height: 36px; padding: 0 10px 0 12px; border: 1px solid var(--input); border-radius: var(--radius); background: var(--background); color: var(--foreground); font: inherit; font-size: 14px; cursor: pointer; box-shadow: var(--shadow-sm); }
.combo-btn:hover { background: var(--accent); }
.combo-btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.combo-btn .combo-value { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.combo-btn .ico { width: 16px; height: 16px; flex: 0 0 auto; color: var(--muted-foreground); }
.combo-pop { position: absolute; top: calc(100% + 4px); left: 0; z-index: 30; width: 340px; max-width: calc(100vw - 32px); background: var(--background); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); overflow: hidden; }
.combo-search { display: flex; align-items: center; gap: 8px; padding: 0 10px; border-bottom: 1px solid var(--border); }
.combo-search .ico { width: 16px; height: 16px; color: var(--muted-foreground); flex: 0 0 auto; }
.combo-search input { flex: 1 1 auto; min-width: 0; height: 40px; border: 0; outline: 0; background: transparent; font: inherit; font-size: 14px; color: var(--foreground); }
.combo-search input::placeholder { color: var(--muted-foreground); }
.combo-list { list-style: none; margin: 0; padding: 4px; max-height: 300px; overflow-y: auto; overscroll-behavior: contain; }
.combo-list li { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 6px; font-size: 14px; color: var(--foreground); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.combo-list li .ico, .combo-list li .combo-gap { width: 16px; height: 16px; flex: 0 0 auto; }
.combo-list li.is-active, .combo-list li:hover { background: var(--accent); color: var(--accent-foreground); }
.combo-list li[aria-selected="true"] { font-weight: 600; }
.combo-empty { padding: 14px 10px; font-size: 13px; color: var(--muted-foreground); text-align: center; }
/* × on a screen-only helper (empty-state notice, Insert-a-note bar): puts it away; Undo / Reset bring it back */
.dismiss { margin-left: auto; flex: 0 0 auto; width: 20px; height: 20px; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: #fff; color: #627d98; font: inherit; font-weight: 700; line-height: 18px; text-align: center; cursor: pointer; }
.dismiss:hover { color: #b91c1c; border-color: #fca5a5; }
.tb-hist { gap: 4px; }
.tb-hist .tb-btn { padding: 6px 9px; }
.tb-hist [data-action=undo], .tb-hist [data-action=redo] { font-size: 17px; line-height: 1; padding: 4px 9px; }
.banner { margin: 10px auto 0; max-width: 210mm; background: #fff7ed; border: 1px solid #fdba74; color: #7c2d12; border-radius: 6px; padding: 8px 12px; font-size: 14px; }

/* sheet preview at natural paper width (the body class comes from manifest.page) */
.sheet-wrap { display: flex; justify-content: center; padding: 14px 8px 40px; }
.sheet { width: 210mm; min-height: 297mm; background: #fff; box-shadow: 0 4px 18px rgba(0,0,0,.10); padding: 12mm 14mm; }
.page-A5 .sheet { width: 148mm; min-height: 210mm; padding: 6mm 8mm; }
.doc-body { font-size: calc(1em * var(--text-scale)); }

/* editing affordances (screen only) */
[contenteditable="true"]:hover { outline: 1px dotted #93c5fd; outline-offset: 1px; }
[contenteditable="true"]:focus { outline: 2px solid #60a5fa; outline-offset: 1px; background: #eff6ff; }
[data-block] { position: relative; }
.block-remove { position: absolute; top: -6px; right: -8px; display: none; width: 22px; height: 22px; border-radius: 50%; border: 1px solid #fca5a5; background: #fff; color: #b91c1c; cursor: pointer; font-weight: 700; line-height: 18px; text-align: center; z-index: 2; }
[data-block]:hover > .block-remove { display: block; }
/* a single field inside a block (data-item) gets a smaller × of its own */
[data-item] { position: relative; }
.item-remove { position: absolute; top: -5px; right: -6px; display: none; width: 15px; height: 15px; padding: 0; border-radius: 50%; border: 1px solid #fca5a5; background: #fff; color: #b91c1c; cursor: pointer; font-weight: 700; font-size: 11px; line-height: 13px; text-align: center; z-index: 3; }
[data-item]:hover > .item-remove { display: block; }
/* while the pointer is on a nested block or field, the enclosing block's × steps aside so the click lands
   on the small one (both used to sit on the same corner) */
[data-block]:has([data-block]:hover, [data-item]:hover) > .block-remove { display: none; }
.btn-sm { border: 1px solid var(--input); background: var(--background); border-radius: 6px; padding: 3px 9px; cursor: pointer; font: inherit; font-size: 12px; font-weight: 500; color: var(--foreground); box-shadow: var(--shadow-sm); }
.btn-sm:hover { background: var(--accent); }

/* modals */
.modal { position: fixed; inset: 0; background: rgba(16,42,67,.45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal[hidden] { display: none; }
.modal-card { background: var(--background); color: var(--foreground); border: 1px solid var(--border); border-radius: 12px; padding: 22px 26px; max-width: 520px; width: calc(100% - 32px); box-shadow: var(--shadow-lg); }
.modal-wide { max-width: 720px; }
.modal-card h2 { margin: 0 0 10px; font-size: 20px; }
.modal-card ul { padding-left: 20px; } .modal-card li { margin: 4px 0; }
.modal-close { margin-top: 10px; border: 1px solid var(--primary); background: var(--primary); color: var(--primary-foreground); border-radius: var(--radius); padding: 8px 14px; cursor: pointer; font: inherit; font-size: 14px; font-weight: 500; }
.modal-close:hover { background: #245c96; }
.modal-close:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.thai { color: #334e68; font-size: 13px; margin-top: 12px; line-height: 1.5; }
.picker-list { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow: auto; }
.picker-list li { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; margin: 6px 0; cursor: pointer; }
.picker-list li:hover { background: var(--accent); }
.picker-list .pk-meta { font-size: 12px; color: #627d98; }
.picker-list .pk-line { font-size: 14px; }
.picker-list li label { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.picker-list li input { margin: 3px 0 0; flex: 0 0 auto; }
.picker-list li.on-card { opacity: .55; cursor: default; }
.modal-sub { color: #627d98; font-size: 13px; margin: 0 0 10px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal-ghost { background: var(--background); color: var(--foreground); border: 1px solid var(--input); }
.modal-ghost:hover { background: var(--accent); }
/* note picker: search + folder filter above a scrollable list; ticks survive filtering (state lives in editor.js) */
.picker-tools { display: flex; gap: 8px; align-items: center; margin: 0 0 10px; }
.picker-search { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 10px; border: 1px solid var(--input); border-radius: var(--radius); background: var(--background); }
.picker-search:focus-within { border-color: var(--ring); box-shadow: 0 0 0 2px var(--ring); }
.picker-search .ico { width: 16px; height: 16px; color: var(--muted-foreground); flex: 0 0 auto; }
.picker-search input { flex: 1 1 auto; min-width: 0; border: 0; outline: 0; background: transparent; font: inherit; font-size: 14px; color: var(--foreground); }
.picker-search input::placeholder { color: var(--muted-foreground); }
.picker-tools .combo { flex: 0 0 auto; }
.picker-tools .combo-btn { min-width: 170px; max-width: 240px; box-shadow: none; }
.picker-tools .combo-pop { width: max-content; min-width: 100%; max-width: 340px; left: auto; right: 0; } /* at least the button, as wide as its longest folder name, anchored right so it stays inside the modal card */
.picker-folder { flex: 0 0 auto; max-width: 210px; height: 36px; padding: 0 8px; border: 1px solid var(--input); border-radius: var(--radius); background: var(--background); font: inherit; font-size: 14px; color: var(--foreground); } /* only visible if editor.js did not run */
.picker-count { flex: 0 0 auto; font-size: 12px; color: var(--muted-foreground); white-space: nowrap; min-width: 60px; text-align: right; }
.picker-list { max-height: 55vh; min-height: 96px; border-top: 1px solid var(--border); padding-top: 4px; }
.picker-list li.is-picked { background: var(--accent); border-color: var(--ring); }
.picker-list li.pk-none { border: 0; color: var(--muted-foreground); text-align: center; cursor: default; }
.picker-list .pk-meta em { font-style: normal; color: #b45309; font-weight: 600; }

/* fallback cards */
.fallback .card { max-width: 560px; margin: 7vh auto; background: #fff; border-radius: 12px; box-shadow: 0 4px 18px rgba(0,0,0,.08); padding: 34px; }
.fallback .icon { font-size: 54px; text-align: center; }
.fallback h1 { font-size: 23px; margin: 14px 0 6px; text-align: center; }
.fallback .sub { color: #627d98; text-align: center; }
.fallback .steps { background: #f0f5ff; border: 1px solid #d6e4ff; border-radius: 8px; padding: 14px 18px; }
.fallback details { margin-top: 24px; } .fallback summary { cursor: pointer; color: #9fb3c8; font-size: 12px; }
.fallback pre { background: #f7f9fc; border: 1px solid #e1e8f0; border-radius: 6px; padding: 10px; font-size: 11px; overflow: auto; }
.fallback .doc-list a { color: var(--brand); } .thai-inline { color: #627d98; }

/* home — the whole window width behind a gutter that grows with the screen; the cards five to a row on a wide
   monitor, then four / three / two / one as the window narrows (each card stays about 270 px or wider) */
.home { --gutter: clamp(16px, 2.5vw, 40px); padding: 0 var(--gutter) 40px; }
.home-head { display: flex; align-items: center; gap: 14px; margin: 24px 0 8px; }
.home-head img { height: 48px; } .home-head h1 { font-size: 24px; margin: 0; }
.home-settings { color: var(--muted-foreground); text-decoration: none; }
.home-empty { margin: 24px auto; color: var(--muted-foreground); text-align: center; } .home-empty a { color: var(--brand); }
.home-banner { margin: 0 0 16px; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; }
.home-banner.muted { color: #627d98; }
.home-tools { display: flex; align-items: center; gap: 12px; margin: 0 0 16px; }
.home-search { flex: 1 1 auto; min-width: 0; max-width: 480px; height: 40px; padding: 0 14px; border: 1px solid var(--input); border-radius: var(--radius); background: var(--background); font: inherit; font-size: 14px; box-shadow: var(--shadow-sm); }
.home-search:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
.home-count { font-size: 13px; color: var(--muted-foreground); white-space: nowrap; }
.doc-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 20px; }
@media (max-width: 1499px) { .doc-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 1199px) { .doc-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 899px) { .doc-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; } }
@media (max-width: 599px) { .doc-grid { grid-template-columns: minmax(0, 1fr); } }
.doc-card { display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; text-decoration: none; color: var(--ink); box-shadow: var(--shadow-sm); transition: border-color .12s, box-shadow .12s, transform .12s; }
.doc-card:hover { border-color: var(--brand); box-shadow: 0 8px 22px rgba(43,108,176,.14); transform: translateY(-1px); }
/* the preview: the blank form's thumbnail (npm run previews) on a grey "desk", the sheet keeping its paper shape.
   The desk and the sheet scale with the card (so a wide column shows a bigger thumbnail, the same top part of it). */
.doc-card-preview { display: flex; align-items: flex-start; justify-content: center; aspect-ratio: 5 / 4; max-height: 320px; min-height: 0; padding: 18px 18px 0; background: linear-gradient(180deg, #e9eef5, #f4f7fb); overflow: hidden; border-bottom: 1px solid var(--line); }
.doc-card-preview img, .doc-card-paper { display: block; width: 80%; background: #fff; border: 1px solid #cfd8e3; box-shadow: 0 6px 16px rgba(15, 23, 42, .14); }
.page-A5 .doc-card-preview img, .page-A5 .doc-card-paper { width: 61%; }
.doc-card-paper { aspect-ratio: 210 / 297; display: flex; align-items: center; justify-content: center; color: #9fb3c8; font-weight: 700; font-size: 22px; }
.page-A5 .doc-card-paper { aspect-ratio: 148 / 210; }
.doc-card-body { padding: 14px 16px 6px; }
.doc-card-title { font-weight: 700; font-size: 17px; } .doc-card-th { color: #627d98; } .doc-card-desc { font-size: 13px; margin-top: 6px; color: #486581; }
.doc-card-foot { display: flex; align-items: center; gap: 10px; padding: 8px 16px 14px; margin-top: auto; }
.doc-card-page { font-size: 11px; font-weight: 600; color: #627d98; border: 1px solid var(--line); border-radius: 999px; padding: 1px 7px; }

/* shared print rules (documents add their own in public/css/documents/<slug>.css) */
@media print {
  body { background: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .no-print, .toolbar, .banner, .modal, .block-remove, .item-remove { display: none !important; }
  .sheet-wrap { padding: 0; display: block; }
  .sheet { width: auto; min-height: 0; box-shadow: none; padding: 0 14mm; }
  .page-A5 .sheet { padding: 0 8mm; }
  [contenteditable="true"] { outline: none !important; background: transparent !important; }
}

/* home cards: the main link opens the document with the patient; the small link below opens the blank form */
.doc-card-main { display: block; color: inherit; text-decoration: none; }
.doc-card-blank { display: inline-block; font-size: 12px; color: var(--brand); margin-left: auto; }
.fallback .alt { text-align: center; margin-top: 14px; }
