/* SARABUN.AI web app — ไม่พึ่งไฟล์ภายนอก */
:root {
  --bg: #f3f5f8; --surface: #fff; --surface-2: #f8f9fb; --ink: #1b2433; --muted: #5d6879; --line: #dde2ea;
  --accent: #0b5cad; --accent-ink: #fff; --accent-soft: #e6f0fb;
  --ok: #17803d; --warn: #a15c00; --warn-soft: #fff4e0; --err: #c42b2b; --err-soft: #fdecec;
  --hl: #fff27a; --focus: #2b7bd6;
  --radius: 10px; --top: 56px;
  --ui: "Sarabun", "Noto Sans Thai", "Leelawadee UI", "Leelawadee", "Tahoma", system-ui, sans-serif;
  --doc: "TH SarabunPSK", "TH Sarabun New", "Sarabun", "Leelawadee UI", serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 15px/1.5 var(--ui); color: var(--ink); background: var(--bg); }
button, select, input, textarea { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; z-index: 50; background: #fff; padding: 8px 12px; border-radius: 8px; }
.skip:focus { left: 8px; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
mark, .ph { background: var(--hl); color: inherit; border-radius: 3px; padding: 0 2px; }

/* ── buttons ── */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface);
  border-radius: 8px; padding: 7px 14px; cursor: pointer; white-space: nowrap; min-height: 36px; }
.btn:hover:not(:disabled) { border-color: #b9c3d2; background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #094c90; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #eef1f5; }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: 14px; }
.btn.warn-btn { background: var(--warn-soft); border-color: #f0c98a; color: #6e3f00; }
.icon { border: 1px solid transparent; background: transparent; border-radius: 8px; width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.icon:hover:not(:disabled) { background: #eef1f5; }
.icon:disabled { opacity: .35; cursor: not-allowed; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
select { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: var(--surface); min-height: 36px; }

/* ── top bar ── */
.topbar { height: var(--top); display: flex; align-items: center; gap: 10px; padding: 0 16px; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; font-size: 19px; letter-spacing: .3px; }
.brand b { color: var(--accent); }
.docmeta { display: flex; align-items: center; gap: 10px; min-width: 0; margin-left: 12px; }
.chip { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 2px 10px; font-weight: 600; font-size: 14px; white-space: nowrap; }
.saved { color: var(--muted); font-size: 13px; }
.badge { font-size: 13px; border-radius: 999px; padding: 3px 10px; background: #eef1f5; color: var(--muted); white-space: nowrap; }
.badge.internal { background: #e7f6ec; color: var(--ok); }
.badge.external { background: var(--warn-soft); color: var(--warn); }
.badge.demo { background: #efe9fb; color: #5b3aa6; }
.badge.error { background: var(--err-soft); color: var(--err); }

/* ── layout ── */
.layout { display: grid; grid-template-columns: minmax(320px, 380px) 1fr minmax(300px, 360px); height: calc(100vh - var(--top)); }
.pane { min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.chat { background: var(--surface); border-right: 1px solid var(--line); }
.side { background: var(--surface); border-left: 1px solid var(--line); }
.mobilebar { display: none; }
.mobile-only { display: none !important; }

/* ── chat ── */
.messages { flex: 1; overflow-y: auto; padding: 18px 16px 8px; display: flex; flex-direction: column; gap: 12px; }
.empty h1 { font-size: 22px; margin: 6px 0 6px; }
.empty p { margin: 0 0 14px; color: var(--muted); }
.empty .note { font-size: 13.5px; margin-top: 16px; }
.examples { display: flex; flex-direction: column; gap: 8px; }
.ex { text-align: left; border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.ex:hover { border-color: var(--accent); background: var(--accent-soft); }
.blank-start { margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--line); }
.blank-start label { display: block; font-weight: 600; margin-bottom: 6px; }
.blank-start select { flex: 1; min-width: 0; }

.msg { max-width: 92%; padding: 10px 13px; border-radius: 14px; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.bot.error { background: var(--err-soft); border-color: #f2c2c2; }
.msg .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; white-space: normal; }
.msg .actions .btn { min-height: 32px; padding: 4px 11px; font-size: 14px; }
.msg .sub { font-size: 13.5px; color: var(--muted); margin-top: 4px; }
.msg .changed-list { margin: 6px 0 0; padding-left: 18px; }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.suggest button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 11px; font-size: 13.5px; cursor: pointer; }
.suggest button:hover { border-color: var(--accent); color: var(--accent); }
.typing { display: flex; align-items: center; gap: 10px; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.composer { border-top: 1px solid var(--line); padding: 10px 12px 12px; background: var(--surface); }
.composer-opts { display: flex; gap: 6px; margin-bottom: 8px; }
.composer-opts select { flex: 1; min-width: 0; font-size: 14px; min-height: 32px; padding: 4px 8px; }
.secret-warn { font-size: 13.5px; background: var(--warn-soft); color: #6e3f00; border-radius: 8px; padding: 6px 10px; margin-bottom: 8px; }
.input-row { display: flex; gap: 8px; align-items: flex-end; }
.input-row textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; max-height: 180px; min-height: 44px; }
.input-row textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.send { width: 44px; height: 44px; padding: 0; justify-content: center; border-radius: 10px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ── document ── */
.doc { background: #e9edf2; }
.doc-toolbar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.doc-toolbar .group { display: flex; align-items: center; gap: 6px; }
.props label { font-size: 13.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.props select { min-height: 30px; padding: 2px 6px; font-size: 14px; }
.canvas { flex: 1; overflow: auto; padding: 24px; }
.doc-foot { margin: 0; padding: 6px 14px; font-size: 12.5px; color: var(--muted); background: var(--surface); border-top: 1px solid var(--line); }
.doc-empty { display: flex; flex-direction: column; align-items: center; gap: 14px; color: var(--muted); padding-top: 4vh; }
.paper.ghost { width: 300px; height: 420px; padding: 40px 34px; display: flex; flex-direction: column; gap: 14px; }
.paper.ghost div { height: 10px; background: #edf0f4; border-radius: 4px; }
.paper.ghost div:nth-child(1) { width: 40%; align-self: center; height: 16px; }
.paper.ghost div:nth-child(3) { width: 85%; } .paper.ghost div:nth-child(5) { width: 60%; }
.zoomwrap { margin: 0 auto; width: max-content; }

/* กระดาษ A4: ขนาด ขอบ และฟอนต์ใกล้เคียงไฟล์ Word (ไฟล์ .docx คือฉบับที่ถูกต้อง) */
.paper { background: #fff; box-shadow: 0 2px 10px rgba(20, 30, 50, .12); border-radius: 2px; }
#paper { width: 21cm; min-height: 29.7cm; padding: 1.5cm 2cm 2cm 3cm; font: 16pt/1.18 var(--doc); color: #000; position: relative; }
#paper .center { text-align: center; }
#paper .bold { font-weight: 700; }
#paper .just { text-align: justify; }
#paper .indent { text-indent: 2.5cm; }
#paper .gap { margin-top: 6pt; }
#paper .gap2 { margin-top: 12pt; }
#paper .speed { color: #d00; font-weight: 700; font-size: 26pt; }
#paper .secrecy { text-align: center; color: #d00; font-weight: 700; font-size: 18pt; }
#paper .emblem { display: block; margin: 0 auto; width: 2.8cm; height: 2.8cm; object-fit: contain; }
#paper .emblem.small { width: 2.2cm; height: 2.2cm; margin: 0; }
#paper .emblem.ph { border: 2px dashed #b9c3d2; border-radius: 50%; background: none; }
#paper .memo-head { display: flex; align-items: flex-end; gap: .5cm; margin-bottom: 4pt; }
#paper .memo-title { flex: 1; text-align: center; font-size: 29pt; font-weight: 700; line-height: 1; padding-right: 2.2cm; }
#paper .memo-line { display: flex; gap: 6pt; align-items: baseline; border-bottom: 1.5px dotted #777; }
#paper .memo-line b { font-size: 20pt; white-space: nowrap; }
#paper .memo-line .f { flex: 1; }
#paper .twocol { display: flex; justify-content: space-between; gap: 1cm; }
#paper .right-block { margin-left: 9cm; }
#paper .sign { margin-top: 30pt; margin-left: 6.5cm; text-align: center; }
#paper .label-row { display: flex; gap: 8pt; }
#paper .label-row > .lbl { width: 1.6cm; flex: none; }
#paper .label-row > .lbl.wide { width: 3.1cm; }
#paper .label-row > .vals { flex: 1; }
#paper .sep { width: 4.5cm; margin: 4pt auto 8pt; border-top: 1.5px solid #000; }
#paper .u { text-decoration: underline; }
#paper .agenda { font-weight: 700; margin-top: 10pt; }

/* ช่องที่แก้ไขได้ */
#paper .f { outline: none; border-radius: 3px; min-width: 1.2em; display: inline; transition: background .15s; cursor: text; }
#paper div.f, #paper p.f { display: block; }
#paper p { margin: 0; }
#paper .f:hover { background: #eef5ff; box-shadow: 0 0 0 2px #eef5ff; }
#paper .f:focus { background: #e3efff; box-shadow: 0 0 0 2px #9cc3f0; }
#paper .f:empty::before { content: attr(data-hint); color: #9aa3b1; }
#paper .f.flash { animation: flash 1.8s ease-out; }
@keyframes flash { 0% { background: #c9f0d4; box-shadow: 0 0 0 3px #c9f0d4; } 100% { background: transparent; } }
#paper .f.bad { box-shadow: 0 0 0 2px #f2c2c2; }
#paper .addbtn { font: 13px var(--ui); color: var(--accent); background: none; border: 1px dashed #b9cde6; border-radius: 6px;
  padding: 1px 8px; cursor: pointer; margin: 2pt 0; }
#paper .addbtn:hover { background: var(--accent-soft); }

/* ── side panel ── */
.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 8px; }
.tabs [role=tab] { border: 0; background: none; padding: 12px 12px 10px; cursor: pointer; border-bottom: 3px solid transparent; font-weight: 600; color: var(--muted); }
.tabs [role=tab][aria-selected=true] { color: var(--accent); border-bottom-color: var(--accent); }
.count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: #eef1f5; font-size: 12px; text-align: center; }
.count.err { background: var(--err); color: #fff; } .count.warn { background: #f3b545; color: #3b2400; }
.panel { flex: 1; overflow-y: auto; padding: 14px; min-height: 0; display: flex; flex-direction: column; }
.summary { margin-bottom: 10px; }
.summary .big { font-size: 17px; font-weight: 700; }
.summary .ok { color: var(--ok); }
.findings { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.findings li button { width: 100%; text-align: left; border: 1px solid var(--line); border-left-width: 4px; background: var(--surface);
  border-radius: 8px; padding: 8px 10px; cursor: pointer; display: block; }
.findings li button:hover { background: var(--surface-2); }
.findings .error button { border-left-color: var(--err); }
.findings .warning button { border-left-color: #e0a12a; }
.findings .info button { border-left-color: #9fb3c8; }
.findings .lv { font-size: 12px; font-weight: 700; text-transform: none; }
.findings .error .lv { color: var(--err); } .findings .warning .lv { color: var(--warn); } .findings .info .lv { color: var(--muted); }
.findings .where { font-size: 12.5px; color: var(--muted); }
.json-bar { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.json { margin: 0; flex: 1; overflow: auto; background: #0f1b2d; color: #d6e2f0; border-radius: 8px; padding: 12px; font: 12.5px/1.55 ui-monospace, "Cascadia Mono", Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
.json .k { color: #8cc8ff; } .json .s { color: #b9e6a8; } .json .n { color: #ffcf8a; } .json .l { color: #f4a3c4; }
.json-edit { display: flex; flex-direction: column; gap: 8px; flex: 1; }
.json-edit textarea { flex: 1; min-height: 300px; font: 12.5px/1.5 ui-monospace, Consolas, monospace; border: 1px solid var(--line); border-radius: 8px; padding: 10px; resize: vertical; }
.json-err { color: var(--err); font-size: 13.5px; white-space: pre-wrap; }

/* ── dialogs / toast ── */
dialog { border: 0; border-radius: 14px; padding: 22px; width: min(640px, 94vw); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
dialog::backdrop { background: rgba(15, 25, 40, .45); }
dialog h2 { margin: 0 0 4px; font-size: 19px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0 18px; }
.grid2 label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-weight: 600; }
.grid2 small { font-weight: 400; color: var(--muted); }
.grid2 input, .grid2 textarea { border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font-weight: 400; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1b2433; color: #fff; padding: 10px 16px;
  border-radius: 10px; box-shadow: 0 8px 30px rgba(0, 0, 0, .25); z-index: 60; max-width: 90vw; }
.toast .btn { background: transparent; color: #9fd0ff; border-color: #5a7394; }
.toast .btn:hover { background: rgba(255, 255, 255, .08); }

/* ── responsive ── */
@media (max-width: 1280px) {
  .layout { grid-template-columns: minmax(300px, 340px) 1fr minmax(280px, 320px); }
}
@media (max-width: 1080px) {
  .topbar .lbl { display: none; }
  .docmeta .muted, .docmeta .saved { display: none; }
  .toast { bottom: 72px; }
  .layout { grid-template-columns: 1fr; height: calc(100vh - var(--top) - 56px); }
  .layout > .pane { display: none; }
  .layout[data-view=chat] > .chat, .layout[data-view=doc] > .doc, .layout[data-view=side] > .side { display: flex; }
  .chat, .side { border: 0; }
  .mobilebar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: 56px; background: var(--surface);
    border-top: 1px solid var(--line); z-index: 20; }
  .mobilebar button { flex: 1; border: 0; background: none; font-weight: 600; color: var(--muted); }
  .mobilebar button[aria-current=page] { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }
  .canvas { padding: 12px; }
  .mobile-only { display: inline-flex !important; }
  .grid2 { grid-template-columns: 1fr; }
}
/* จอเล็ก: แสดงเอกสารแบบไหลตามความกว้างจอเพื่อให้อ่านและแก้ได้สะดวก (รูปแบบจริงอยู่ในไฟล์ Word) */
@media (max-width: 700px) {
  .zoomwrap { width: auto; }
  #paper { width: auto; min-height: 0; padding: 20px 16px 28px; font-size: 14pt; }
  #paper .indent { text-indent: 1.2cm; }
  #paper .sign { margin-left: 30%; }
  #paper .memo-title { font-size: 22pt; padding-right: 0; }
  #paper .memo-line b { font-size: 15pt; }
  #paper .emblem { width: 2cm; height: 2cm; } #paper .emblem.small { width: 1.5cm; height: 1.5cm; }
  #paper .twocol { flex-direction: column; gap: 4pt; }
  #paper [style*="margin-left:6cm"], #paper [style*="margin-left:5cm"], #paper [style*="margin-left:7cm"] { margin-left: 0 !important; }
  #paper .sign[style*="margin-left:7cm"] { margin-left: 30% !important; }
  #paper .label-row > .lbl.wide { width: auto; }
}
@media (max-width: 520px) { .badge { display: none; } .brand { font-size: 17px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
