/* DR Design Studio — shared theme (DR red / black / white, Kanit).
 * Breakpoints (UX round 3 — the only ones used in this file):
 *   phone   ≤ 640px           @media (max-width: 640px)
 *   tablet  641–1023px        @media (max-width: 1023.98px) / (min-width: 1024px)
 *   laptop  1024–1279px       @media (max-width: 1279.98px) / (min-width: 1280px)
 *   desktop ≥ 1280px
 * plus (pointer: coarse) for touch sizes, prefers-reduced-motion and print. */
:root {
  --red: #cb212a; --red-dark: #9e1820; --red-soft: #fdecec; --ink: #141414; --muted: #555; --line: #dcdcdc;
  --bg: #f4f4f4; --card: #fff; --ok: #1f6b3d; --ok-soft: #e7f4ec; --warn: #8a5200; --warn-soft: #fff4e0;
  --focus: #1d4ed8; --radius: 12px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); min-height: 100vh; display: flex; flex-direction: column;
  font-family: Kanit, 'Leelawadee UI', 'Noto Sans Thai', sans-serif; font-weight: 300; font-size: 15px; line-height: 1.6;
}
a { color: var(--red); } a:hover { color: var(--red-dark); }
h1, h2, h3 { font-weight: 500; line-height: 1.3; margin: 0; }
h1 { font-size: 24px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }

/* ---------- shell ---------- */
.app-header {
  background: #fff; border-bottom: 4px solid var(--red); padding: 10px 24px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; color: var(--ink); }
.brand img { height: 44px; width: auto; }
.brand b { display: block; font-weight: 600; font-size: 19px; line-height: 1.2; }
.brand small { font-size: 13px; color: var(--muted); }
.user { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.user .who { text-align: right; line-height: 1.3; }
.user .who strong { display: block; color: var(--ink); font-weight: 500; font-size: 14px; }
.user form { margin: 0; }
.app-nav { background: var(--ink); padding: 0 24px; display: flex; gap: 4px; flex-wrap: wrap; overflow-x: auto; }
.app-nav a { color: #d6d6d6; text-decoration: none; padding: 10px 14px; font-size: 14px; border-bottom: 3px solid transparent; white-space: nowrap; }
.app-nav a:hover { color: #fff; }
.app-nav a[aria-current="page"] { color: #fff; font-weight: 500; border-bottom-color: var(--red); }
.app-main { width: 100%; max-width: 1400px; margin: 0 auto; padding: 16px 24px 32px; flex: 1; display: flex; flex-direction: column; gap: 16px; }
.app-footer { background: var(--red); color: #fff; padding: 8px 24px; font-family: Arial, sans-serif; font-weight: 700; font-size: 13px; letter-spacing: .3px; }

/* ---------- building blocks ---------- */
.layout { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.layout > aside { flex: 1 1 280px; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.layout > main { flex: 3 1 600px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; }
.hint, .muted { color: var(--muted); font-size: 13px; }
.kicker { color: var(--red); font-weight: 500; font-size: 13px; letter-spacing: .3px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 8px 16px;
  border-radius: 8px; border: 1px solid var(--red); background: var(--red); color: #fff; font-weight: 500; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--red-dark); border-color: var(--red-dark); color: #fff; }
.btn.secondary { background: #fff; color: var(--ink); border-color: #9a9a9a; font-weight: 400; }
.btn.secondary:hover { background: #f2f2f2; color: var(--ink); }
.btn.ghost { background: transparent; color: var(--red); border-color: transparent; }
.btn.danger { background: #fff; color: var(--red); border-color: var(--red); }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.list-btn {
  width: 100%; text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer;
  display: flex; flex-direction: column; gap: 2px; min-height: 44px;
}
.list-btn:hover { border-color: #9a9a9a; }
.list-btn[aria-current="true"] { border: 2px solid var(--red); background: var(--red-soft); }
.list-btn .t { font-weight: 500; }
.list-btn .s { font-size: 13px; color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 10px; font-size: 13px; background: #eee; color: var(--ink); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); } .pill.warn { background: var(--warn-soft); color: var(--warn); } .pill.red { background: var(--red-soft); color: var(--red-dark); }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button:not(.btn) { min-height: 40px; border-radius: 999px; padding: 4px 14px; border: 1px solid #9a9a9a; background: #fff; cursor: pointer; }
.seg button:not(.btn)[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
input[type=text], input[type=email], input[type=date], input[type=number], select, textarea {
  border: 1px solid #9a9a9a; border-radius: 8px; padding: 8px 10px; min-height: 40px; background: #fff; width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
.empty { color: var(--muted); font-size: 14px; padding: 12px; border: 1px dashed var(--line); border-radius: 10px; text-align: center; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); max-width: min(92vw, 560px); z-index: 50;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.2); font-size: 14px;
}
.toast.err { background: var(--red-dark); }
.progress { height: 10px; background: #eee; border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--red); width: 0; transition: width .2s; }
.checks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.checks li::before { content: '✓ '; color: var(--ok); font-weight: 600; }
.checks li.warn::before { content: '! '; color: var(--warn); }
.checks li.err::before { content: '✕ '; color: var(--red); }

/* ---------- files ---------- */
.drop {
  border: 2px dashed #b9b9b9; border-radius: var(--radius); padding: 24px; text-align: center; display: flex; flex-direction: column;
  align-items: center; gap: 8px; background: #fafafa; cursor: pointer;
}
.drop.over { border-color: var(--red); background: var(--red-soft); }
.file-row { display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid #eee; }
.file-row:first-of-type { border-top: 0; }
.thumb { width: 64px; height: 64px; border-radius: 8px; border: 1px solid var(--line); background: repeating-conic-gradient(#eee 0 25%, #fff 0 50%) 0 0 / 12px 12px; display: grid; place-items: center; overflow: hidden; font-size: 13px; color: var(--muted); }
.thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.file-row .meta { display: flex; flex-direction: column; min-width: 0; }
.file-row .meta b { font-weight: 500; overflow-wrap: anywhere; }
.file-row .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.upload-item { display: flex; flex-direction: column; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; }

@media (max-width: 640px) {
  .app-header, .app-nav, .app-main, .app-footer { padding-left: 16px; padding-right: 16px; }
  .brand small, .user .who span { display: none; }
  .layout > aside { max-width: none; }
  .file-row { grid-template-columns: 48px 1fr; }
  .file-row .actions { grid-column: 1 / -1; justify-content: flex-start; }
  .thumb { width: 48px; height: 48px; }
}
.seg-col { display: flex; flex-direction: column; gap: 8px; }
body.readonly .needs-write { display: none !important; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid2 .wide { grid-column: 1 / -1; }
fieldset.items { border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; margin: 0; }
fieldset.items legend { font-weight: 500; padding: 0 6px; }
.item-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.item-row select { width: auto; min-width: 140px; flex: 1 1 140px; }
.item-row input[type=number] { width: 90px; }
.msg-err { margin: 0; background: var(--red-soft); color: #8a1118; border: 1px solid #f3b7bb; border-radius: 8px; padding: 8px 12px; font-size: 14px; }
.history { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
input[type=search] { border: 1px solid #9a9a9a; border-radius: 8px; padding: 8px 10px; min-height: 40px; width: 100%; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }
@media (pointer: coarse), (max-width: 640px) { .btn.small, .seg button:not(.btn) { min-height: 44px; } }

/* ---------- design workspace ---------- */
.topline { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px; }
.topline h1 { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.field.inline { flex-direction: row; align-items: center; gap: 6px; }
.field.inline select { width: auto; max-width: 320px; }
.design { display: grid; grid-template-columns: minmax(220px, 280px) minmax(0, 1fr) minmax(300px, 400px); gap: 16px; align-items: start; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 0; font-size: 14px; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; font-weight: 400; overflow-wrap: anywhere; }
.std { background: #fafafa; border: 1px solid #eee; border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.std ul { margin: 6px 0 0; padding-left: 18px; }
.num { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--ink); color: #fff; font-size: 13px; margin-right: 6px; vertical-align: 2px; }
.chat { min-height: 70vh; }
.thread { flex: 1; min-height: 380px; max-height: 62vh; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding: 4px 2px; }
.empty-chat { margin: auto; text-align: center; color: var(--muted); display: flex; flex-direction: column; gap: 6px; max-width: 460px; }
.empty-chat b { color: var(--ink); font-size: 17px; }
.msg { display: flex; gap: 10px; align-items: flex-start; }
.msg.user { justify-content: flex-end; }
.msg .body { display: flex; flex-direction: column; gap: 6px; max-width: min(640px, 92%); }
.msg.user .body { background: var(--ink); color: #fff; border-radius: 14px 14px 4px 14px; padding: 10px 14px; }
.msg.user .who { color: #cfcfcf; }
.msg.assistant .body { background: #fff; border: 1px solid var(--line); border-radius: 14px 14px 14px 4px; padding: 10px 14px; }
.msg.error .body { border-color: #f3b7bb; background: var(--red-soft); }
.msg .who { font-size: 13px; color: var(--muted); }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.avatar { flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--red); color: #fff; display: grid; place-items: center; font-weight: 600; }
.thinking::after { content: ''; display: inline-block; width: 1em; animation: dots 1.2s steps(4) infinite; overflow: hidden; vertical-align: bottom; }
@keyframes dots { from { width: 0; } to { width: 1.2em; } }
@media (prefers-reduced-motion: reduce) { .thinking::after { animation: none; } }
.questions { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.direction { border-top: 1px solid #eee; padding-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.direction dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; margin: 0; font-size: 14px; }
.direction dt { color: var(--muted); } .direction dd { margin: 0; }
.swatches { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.sw { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; }
.sw i { width: 16px; height: 16px; border-radius: 4px; border: 1px solid #0002; display: inline-block; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.composer { border-top: 1px solid #eee; padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer-row .grow { flex: 1; }
.composer textarea { min-height: 48px; }
.btn.icon { min-width: 44px; padding: 8px; font-size: 18px; }
.attached { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 4px 2px 8px; font-size: 13px; background: #fafafa; }
.chip img { width: 28px; height: 28px; object-fit: cover; border-radius: 6px; }
.steps { display: flex; flex-direction: column; gap: 16px; }
textarea.prompt { font-size: 13px; min-height: 160px; background: #fafafa; }
ul.plain { margin: 4px 0; padding-left: 18px; font-size: 14px; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; }
label.check input { width: 20px; height: 20px; flex: none; margin-top: 2px; }
.version { border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.version + .version { margin-top: 10px; }
.version.approved { border: 2px solid var(--ok); }
.vimg { display: block; background: repeating-conic-gradient(#eee 0 25%, #fff 0 50%) 0 0 / 14px 14px; border-radius: 8px; text-align: center; }
.vimg img { max-width: 100%; max-height: 340px; object-fit: contain; display: inline-block; }
.texts { display: flex; flex-direction: column; gap: 6px; }
.text-check { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.text-check .quote { font-weight: 500; }
.version .seg input[type=text] { flex: 1 1 180px; }
/* design page layouts per breakpoint: see the UX round 3 block at the end of this file */
.table-wrap { overflow-x: auto; position: relative; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid #eee; vertical-align: middle; }
.table th { font-weight: 500; color: var(--muted); font-size: 13px; }
.crumbs { font-size: 13px; color: var(--muted); }
.crumbs b { color: var(--ink); font-weight: 500; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.lib-item { margin: 0; border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 6px; background: #fff; }
.lib-item img { width: 100%; height: 120px; object-fit: contain; background: repeating-conic-gradient(#eee 0 25%, #fff 0 50%) 0 0 / 12px 12px; border-radius: 6px; }
.lib-item figcaption { display: flex; flex-direction: column; gap: 2px; font-size: 13px; overflow-wrap: anywhere; }
.seg button[role=tab] { min-height: 40px; }
ol.steps-list { margin: 0 0 8px; padding-left: 20px; font-size: 14px; }
.pack-panel:empty { display: none; }
canvas.pack-page { width: 100%; height: auto; border: 1px solid var(--line); border-radius: 8px; }

/* phase 10: AI files, DR Bridge, deliverables */
.row-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.row-form input[type=text] { width: 170px; }
.row-form .progress { flex: 1 1 100%; }
.row-form .hint { flex: 1 1 100%; }
label.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; min-height: 44px; }
label.check input { width: 20px; height: 20px; }
.ok-text { color: var(--ok); font-size: 14px; font-weight: 500; }
.pieces-check { margin: 10px 0 14px; padding: 10px 12px; border: 1px solid var(--line, #e3e3e3); border-radius: 8px; }
.pieces-check p { margin: 0 0 6px; font-size: 14px; }
.pieces-check ul { margin: 4px 0 8px 18px; font-size: 13px; line-height: 1.5; }
ul.plain.inline { display: flex; flex-wrap: wrap; gap: 4px 14px; list-style: none; padding: 0; }
ul.plain.inline a, ul.plain.jobs details { min-height: 32px; }
ul.plain.jobs { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.rev h3 { font-size: 16px; margin: 4px 0 6px; }
.rev + .rev { margin-top: 8px; }
@media (max-width: 640px) {
  .ai-table thead { display: none; }
  .ai-table tr { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  .ai-table td { border: 0; padding: 0; }
  .ai-table td:nth-child(1) b { font-size: 18px; }
  .ai-table td:nth-child(n+3) { grid-column: 1 / -1; }
  .ai-table .btn { white-space: nowrap; }
}

/* ---------- UX round 1 (2026-11-28) ---------- */
/* grid columns never grow past the screen because of one long word in the chat/prompt */
.design > * { min-width: 0; }
/* 2 · phones: nothing wider than the screen (job/request pickers, file inputs, long words) */
input[type=file] { max-width: 100%; }
@media (max-width: 640px) {
  .topline > * { min-width: 0; max-width: 100%; }
  .topline .seg { width: 100%; }
  .field.inline { flex: 1 1 100%; min-width: 0; }
  .field.inline select, .field.inline input { flex: 1 1 auto; width: 100%; min-width: 0; max-width: none; }
}
/* 10 · AI file upload: Thai drop zone + item number */
.upload-ai { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.upload-ai .drop { padding: 16px; }
.upload-ai .row-form { margin-top: 0; }
.upload-ai .field.inline input { width: 120px; }
.drop-file { font-weight: 500; overflow-wrap: anywhere; }
.warn-text { color: var(--warn); }
/* 11 · touch screens: every control at least 44px tall, 8px apart */
@media (pointer: coarse), (max-width: 640px) {
  .btn, .btn.small, .seg button, .seg button[role=tab], select,
  input[type=text], input[type=email], input[type=date], input[type=number], input[type=search] { min-height: 44px; }
  summary { min-height: 44px; padding: 10px 0; cursor: pointer; }
  .app-nav a { min-height: 44px; display: inline-flex; align-items: center; }
  ul.plain.inline a, ul.plain.jobs details, .ok-link { min-height: 44px; display: inline-flex; align-items: center; }
  ul.plain.inline { gap: 8px 14px; }
}
/* 7 · proof that can't be made yet */
.empty-state { border-left: 4px solid var(--warn); }
.empty-state p { margin: 0; }

/* ---------- UX round 2 (2026-11-28): branch page as 5 steps ---------- */
/* 6 · branch detail: no client list (breadcrumb is the way back) — set before first paint by branch-pre.js */
.branch-detail .layout > aside { display: none; }
.branch-detail .layout > main { flex-basis: 100%; }
.branch-head { display: flex; flex-direction: column; gap: 2px; }
/* 1 · step bar: left column on desktop (layout B), one sticky scrolling line on tablets and phones */
.stepbar ol { list-style: none; margin: 0; padding: 0; display: flex; gap: 6px; }
.stepbar a { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 10px; border-radius: 10px; text-decoration: none; color: var(--ink); background: #fff; border: 1px solid var(--line); }
.stepbar a:hover { border-color: #9a9a9a; color: var(--ink); }
.stepbar .sn { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: #e6e6e6; font-weight: 600; font-size: 14px; }
.stepbar a.done .sn { background: var(--ok); color: #fff; }
.stepbar a[aria-current="step"] { border: 2px solid var(--red); background: var(--red-soft); }
.stepbar a[aria-current="step"] .sn { background: var(--red); color: #fff; }
.stepbar .st { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.stepbar .st b { font-weight: 500; font-size: 14px; }
.stepbar .ss { font-size: 13px; color: var(--muted); }
.step-body { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.step { scroll-margin-top: 84px; }
.step.current { border-color: var(--red); box-shadow: inset 4px 0 0 var(--red); }
.step.done h2 .num { background: var(--ok); }
.step h2:focus { outline: none; }
.step h2:focus-visible { outline: 3px solid var(--focus); }
.step h3 { margin-top: 6px; }
@media (min-width: 1024px) {
  .branch-steps { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 20px; align-items: start; }
  .stepbar { position: sticky; top: 12px; }
  .stepbar ol { flex-direction: column; }
  .step { scroll-margin-top: 12px; }
}
@media (max-width: 1023.98px) {
  .branch-steps { display: flex; flex-direction: column; gap: 16px; }
  .stepbar { position: sticky; top: 0; z-index: 20; background: var(--bg); margin: 0 -24px; padding: 6px 24px; overflow-x: auto; border-bottom: 1px solid var(--line); }
  .stepbar ol { width: max-content; }
  .stepbar a { white-space: nowrap; }
}
@media (max-width: 640px) { .stepbar { margin: 0 -16px; padding: 6px 16px; } }
/* 12 · counts that filter the table instead of a wall of warnings */
.count-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 14px; }
.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.items-box { display: flex; flex-direction: column; gap: 8px; }
.items-box > .btn { align-self: flex-start; }
.why { margin-top: 4px; font-size: 13px; color: var(--warn); }
/* 5 · one primary per step; bulk approve with an in-page confirmation */
.step-action { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.reason { color: var(--warn); margin: 0; }
.confirm-box { border: 2px solid var(--red); border-radius: 10px; padding: 12px; background: var(--red-soft); display: flex; flex-direction: column; gap: 8px; align-self: stretch; }
.ok-box { background: var(--ok-soft); color: var(--ok); border: 1px solid #b6dcc4; border-radius: 8px; padding: 8px 12px; font-size: 14px; }
td.pick { width: 44px; }
label.tick { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; cursor: pointer; }
label.tick input { width: 20px; height: 20px; }
.bridge { display: flex; flex-direction: column; gap: 6px; }
@media (max-width: 640px) {
  .ai-table tr { grid-template-columns: auto auto 1fr; }
  .ai-table td:nth-child(1) b { font-size: inherit; }
  .ai-table td:nth-child(2) b { font-size: 18px; }
  .ai-table td:nth-child(n+3) { grid-column: auto; }
  .ai-table td:nth-child(n+4) { grid-column: 1 / -1; }
  .ai-table td { align-self: center; }
}
/* 5 · files page: delete lives in a "⋯" menu */
.row-menu { position: relative; }
.row-menu > summary { list-style: none; display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 36px; padding: 0 10px; border: 1px solid #9a9a9a; border-radius: 8px; background: #fff; cursor: pointer; font-size: 18px; line-height: 1; }
.row-menu > summary::-webkit-details-marker { display: none; }
.row-menu[open] > summary { background: #f2f2f2; }
.row-menu .menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 30; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.15); display: flex; flex-direction: column; gap: 6px; min-width: 180px; }
@media (pointer: coarse), (max-width: 640px) { .row-menu > summary { min-height: 44px; padding: 0 12px; } }
@media (max-width: 640px) { .row-menu .menu { right: auto; left: 0; } }
.drop.compact { padding: 10px 14px; flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 2px 12px; }
.drop.compact .progress { flex: 1 1 100%; }

/* ---------- UX round 3 (2026-11-29) ---------- */
/* 4 · nothing jumps while loading: the shell is in the HTML, the footer always starts below the first screen,
   and parts filled from the API stay hidden ([data-boot]) behind a placeholder (.skel) until drawn in one go */
.app-main { min-height: 100vh; }
.skel { display: grid; gap: 16px; }
.skel > span { display: block; border-radius: var(--radius); background: #ebebeb; border: 1px solid #e2e2e2; }
.design-skel { grid-template-columns: minmax(0, 1fr) minmax(300px, 400px); min-height: 70vh; }
.design-skel > span:first-child { grid-row: span 2; }
.page-skel { min-height: 60vh; }
.page-skel > span { min-height: 60vh; }
/* user box: name + sign out inline on wide screens, a round button with a panel on phones */
.user { position: relative; }
.user-btn { display: none; }
.user-panel { display: flex; align-items: center; gap: 12px; }
.user .who strong, .user .who span { white-space: nowrap; }
.stepbar .ss.stale { color: var(--warn); }
/* 3 · phones: a small header and a one-line main menu (≤ 15% of the screen) */
@media (max-width: 640px) {
  .app-header { padding-top: 6px; padding-bottom: 6px; border-bottom-width: 3px; flex-wrap: nowrap; }
  .brand { gap: 10px; min-width: 0; }
  .brand img { height: 34px; width: auto; }
  .brand b { font-size: 16px; }
  .user-btn { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; border: 1px solid #9a9a9a; background: #fff; cursor: pointer; padding: 0; }
  .user-ini { font-weight: 600; font-size: 17px; color: var(--ink); }
  .user-panel { display: none; position: absolute; right: 0; top: calc(100% + 8px); z-index: 40; background: #fff; border: 1px solid var(--line); border-radius: 12px;
    box-shadow: 0 8px 28px rgba(0,0,0,.18); padding: 12px; flex-direction: column; align-items: stretch; min-width: 240px; max-width: calc(100vw - 32px); }
  .user.open .user-panel { display: flex; }
  .user .who { text-align: left; }
  .user .who span { display: block; white-space: normal; overflow-wrap: anywhere; }
  .app-nav { flex-wrap: nowrap; gap: 0; scrollbar-width: thin; }
  .app-nav a { padding: 0 12px; }
}

/* 14 · the one job picker (layout A: search box + drop-down list at the top of the page) */
.job-picker { display: flex; align-items: center; gap: 8px; min-width: 0; }
.jp-label { font-size: 14px; white-space: nowrap; }
.jp-box { position: relative; flex: 1 1 auto; min-width: 0; width: min(420px, 100%); }
.jp-box input { width: 100%; min-height: 44px; border: 1px solid #9a9a9a; border-radius: 8px; padding: 8px 10px; background: #fff; text-overflow: ellipsis; }
.jp-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 45; margin: 0; padding: 6px; list-style: none; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.18); max-height: min(60vh, 420px); overflow-y: auto; overscroll-behavior: contain; }
.jp-list li { display: flex; flex-direction: column; justify-content: center; min-height: 44px; padding: 6px 10px; border-radius: 8px; cursor: pointer; }
.jp-list li.active { background: var(--red-soft); outline: 2px solid var(--red); outline-offset: -2px; }
.jp-list li .jp-t { font-weight: 500; overflow-wrap: anywhere; }
.jp-cur { color: var(--ok); }
.jp-list li.jp-empty { cursor: default; color: var(--muted); }
.pickers { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.pickers .job-picker { flex: 1 1 360px; }
.page-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.page-bar .job-picker { flex: 1 1 360px; max-width: 640px; }
@media (max-width: 640px) {
  .pickers, .page-bar { width: 100%; }
  .pickers .job-picker, .page-bar .job-picker { flex: 1 1 100%; max-width: none; }
  .jp-box { width: 100%; }
}

/* 9 + 17 · design page: 3 columns ≥ 1280 · 2 columns (chat | steps) 641–1279 · tabs ≤ 640 */
.design { grid-template-areas: "facts chat steps"; }
.design > .facts-card { grid-area: facts; }
.design > .chat { grid-area: chat; }
.design > .steps { grid-area: steps; }
.design > .tabs { display: none; }
.facts-toggle { display: none; }
.facts-body { display: flex; flex-direction: column; gap: 10px; }
.prompt-text { font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; background: #fafafa; border: 1px solid #9a9a9a; border-radius: 8px; padding: 8px 10px; line-height: 1.6; }
.prompt-text.clamped { max-height: calc(6 * 1.6em + 16px); overflow: hidden; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }
.btn.more { align-self: flex-start; }
@media (min-width: 641px) {
  /* the chat card fills the rest of the screen (height set by fitChat), its input box is always on screen,
     and the thread is the only scroll box */
  .design > .chat { position: sticky; top: 12px; height: var(--chat-h, auto); min-height: 440px; }
  .thread { min-height: 0; max-height: none; overscroll-behavior: contain; }
}
@media (max-width: 1279.98px) {
  .design { grid-template-columns: minmax(0, 1fr) minmax(300px, 380px); grid-template-areas: "chat facts" "chat steps"; grid-template-rows: auto 1fr; }
  .facts-toggle { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 44px; padding: 8px 12px;
    border: 1px solid #9a9a9a; border-radius: 8px; background: #fff; cursor: pointer; font-weight: 500; text-align: left; }
  .facts-toggle::after { content: '▾'; margin-left: auto; }
  .facts-card.open .facts-toggle::after { content: '▴'; }
  .facts-card:not(.open) .facts-body { display: none; }
  .facts-card { padding: 10px; }
}
@media (max-width: 640px) {
  .design { grid-template-columns: minmax(0, 1fr); grid-template-areas: "facts" "tabs" "chat" "steps"; grid-template-rows: none; gap: 12px; }
  .design-skel { grid-template-columns: minmax(0, 1fr); }
  .design > .tabs { grid-area: tabs; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
  .design > .tabs[hidden] { display: none; }
  .tabs [role=tab] { display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 56px; padding: 6px 2px; border: 1px solid var(--line);
    border-radius: 10px; background: #fff; cursor: pointer; text-align: center; line-height: 1.2; }
  .tabs [role=tab][aria-selected="true"] { border: 2px solid var(--red); background: var(--red-soft); }
  .tabs .tn { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: #e6e6e6; font-weight: 600; font-size: 13px; }
  .tabs [role=tab].done .tn { background: var(--ok); color: #fff; }
  .tabs [role=tab][aria-selected="true"] .tn { background: var(--red); color: #fff; }
  .tabs .tt { display: flex; flex-direction: column; min-width: 0; }
  .tabs .tt b { font-weight: 500; font-size: 13px; }
  .tabs .ts { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
  .tab-off { display: none !important; }
  .design > .chat { min-height: 0; }
  .thread { min-height: 200px; max-height: none; overflow: visible; }
  /* the chat input box stays at the bottom of the screen */
  .composer { position: sticky; bottom: 0; z-index: 5; background: #fff; margin: 0 -16px -16px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    border-radius: 0 0 var(--radius) var(--radius); box-shadow: 0 -6px 16px rgba(0,0,0,.06); }
  .composer .hint { display: none; }
}
.stack { display: flex; flex-direction: column; gap: 16px; }
.page-bar > .pickers { flex: 1 1 100%; }
.pickers .job-picker { max-width: 560px; }
@media (max-width: 640px) { .pickers .job-picker { max-width: none; } }
@media (max-width: 640px) {
  /* design page on phones: the job picker already names the job, so the kicker goes; request + "+ คำขอใหม่" share a row */
  .pickers .field.inline { flex: 1 1 0; min-width: 0; }
  .pickers #btn-new { flex: none; }
  #app > .topline .kicker { display: none; }
  #app > .topline h1 { font-size: 19px; gap: 6px 8px; }
  .facts-card { padding: 0; border: 0; background: transparent; }
  .facts-card.open { padding: 10px; border: 1px solid var(--line); background: var(--card); }
  .prompt-text.clamped { max-height: calc(4 * 1.6em + 16px); }
}
.thread > .older { align-self: center; }
ul.recent { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; min-height: 120px; }
ul.recent .list-btn { text-decoration: none; color: var(--ink); }
@media (max-width: 640px) { .brand { min-height: 44px; } }
/* 4 · images keep their space before they load (width/height from the version) */
.vimg img[width][height] { width: 100%; height: auto; max-height: 340px; object-fit: contain; display: block; }
@media (max-width: 640px) { .vimg img[width][height] { max-height: 200px; } }
@media (max-width: 640px) { .page-bar > .job-picker { flex: 1 1 0; } .page-bar > #btn-new { flex: none; } }
/* 4 · the breadcrumb is filled after the data loads: keep its line from the start */
nav.crumbs { min-height: 21px; }
/* 4 · the request picker has a fixed width: loading its options must not re-wrap the bar (tablet CLS 0.41) */
.pickers .field.inline { flex: 1 1 300px; max-width: 420px; }
.pickers .field.inline select { width: 100%; max-width: none; }
@media (max-width: 640px) { .pickers .field.inline { flex: 1 1 0; max-width: none; } }

/* ---------- Phase 11 on the web: "ให้ AI เสนอแบบ" (step 4) ---------- */
.warn-text { color: var(--warn); }
.ai-design { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin-top: 12px; }
.ai-design > .btn { align-self: flex-start; }
.ai-pick { width: 100%; }
ul.plain.ai-items { list-style: none; padding: 0; max-height: 360px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; }
ul.plain.ai-items .pill { margin-left: 6px; }
.bbox { width: 100%; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 4px; }
.bbox h4 { margin: 0 0 4px; font-size: 15px; }
ul.plain.bprompts { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.bprompt .prompt-text { margin: 6px 0; }
/* touch: every row of the item list and the list toggle are ≥ 44px tall (round-1 rule) */
ul.plain.ai-items label.check, .ai-design > label.check, .ai-pick > label.check { min-height: 44px; align-items: center; }
.ai-pick > summary, .bbox details > summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; }
.bbox input[type=file] { min-height: 44px; max-width: 100%; }
/* step 2 table: the status picker shows its whole word ("ใช้แบบเดิม" / "ปรับขนาด" / "แบบใหม่") at 1280–1440 */
#items-table td select { min-width: 8.5em; }

/* step 2: pieces with their own quantity (3361 review) */
.table ul.parts { margin: 4px 0 0; padding-left: 16px; font-size: .85em; color: var(--muted, #555); }

/* step 2: correcting an item (3361 review) */
.edit-row > td { background: var(--red-soft, #fdecec); }
.edit-form .edit-grid { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 12px; align-items: start; margin-bottom: 8px; }
.edit-form .edit-grid input[type=text], .edit-form .edit-grid textarea { width: 100%; max-width: 520px; }
.edit-form .edit-grid input[type=number] { width: 120px; }
.edit-form .field-err { display: block; color: var(--red, #cb212a); font-size: 13px; }
.spec { margin-top: 4px; font-size: 13px; }
@media (max-width: 640px) { .edit-form .edit-grid { grid-template-columns: minmax(0, 1fr); } }
.edit-form input, .edit-form textarea { box-sizing: border-box; max-width: 100%; }
.edit-row .edit-form { position: sticky; left: 0; max-width: min(100%, calc(100vw - 56px)); }
.lib-item.chosen { outline: 3px solid var(--ok, #1f7a3a); outline-offset: 2px; }
.lib-item .btn { margin-top: 6px; }

/* step 2: "ให้ AI อ่านรูปใน pack" */
.look-box { border: 1px solid var(--line, #d9d9d9); border-radius: 8px; padding: 12px 14px; margin: 0 0 12px; }
.look-box p { margin: 0 0 6px; }
.look-box ul { margin: 0 0 8px; }
details.look { margin-top: 4px; font-size: 0.875rem; }
details.look > summary { cursor: pointer; }

/* ---------- "ตรวจชิ้น": the pack picture beside the designer's artboard, pieces framed (piece-check.js) ---------- */
.count-cell { align-items: center; gap: 6px; }
dialog.piece-dialog { width: min(1280px, 96vw); max-height: 94vh; border: 0; border-radius: var(--radius); padding: 16px 20px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog.piece-dialog::backdrop { background: rgba(20,20,20,.55); }
.pc-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.pc-std { display: flex; flex-direction: column; gap: 4px; margin: 0 0 10px; font-size: 14px; }
.pc-cols { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 14px; align-items: start; }
.pc-cols figure { margin: 0; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.pc-cols figcaption { font-weight: 500; font-size: 14px; }
.pc-pack img { width: 100%; height: auto; border: 1px solid var(--line); border-radius: 8px; }
.pc-scroll { overflow: auto; max-height: 62vh; border: 1px solid var(--line); border-radius: 8px; background: #fafafa; }
.pc-stage { position: relative; width: 100%; line-height: 0; touch-action: none; user-select: none; }
.pc-stage.zoom { width: 220%; }
.pc-stage.drawing { cursor: crosshair; }
.pc-stage img { width: 100%; height: auto; display: block; pointer-events: none; }
.pc-layer { position: absolute; inset: 0; }
.pc-box { position: absolute; border: 2.5px solid var(--red); background: rgba(255,255,255,.06); padding: 0; cursor: pointer; border-radius: 2px; min-width: 6px; min-height: 6px; }
.pc-box.sel { box-shadow: 0 0 0 3px rgba(29,78,216,.55); background: rgba(29,78,216,.10); }
.pc-box.ghost { border-style: dashed; border-color: var(--focus); pointer-events: none; }
.pc-stage.drawing .pc-box { pointer-events: none; }
.pc-tag { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px; color: #fff; font-size: 12px; font-weight: 500; line-height: 1; }
.pc-box .pc-tag { position: absolute; left: 2px; top: 2px; box-shadow: 0 0 0 1.5px #fff; }
.pc-table tr.sel td { background: #eef3ff; }
.pc-table .pc-qty { width: 84px; }
.pc-table select, .pc-table input[type=text] { min-height: 36px; max-width: 100%; }
.pc-sum { margin: 8px 0; }
@media (max-width: 900px) { .pc-cols { grid-template-columns: 1fr; } }
