/* app.css — หน้าตาระบบ (นอกกระดาษ) · โทนราชการ น้ำเงินเข้ม + ทอง · ตัวหนังสือบนกระดาษอยู่ใน a4.css */
:root {
  --navy: #1f2d4d; --navy-2: #2c3f68; --navy-3: #3b5287;
  --gold: #c9a227; --gold-2: #e0bd4a; --gold-soft: #fbf3d9;
  --bg: #eef1f6; --card: #ffffff; --line: #d6dce7; --text: #1d2433; --muted: #5e6a80;
  --ok: #1e7f4f; --warn: #b26a00; --err: #c0392b; --info: #2c6db3;
  --ui-font: 'Leelawadee UI', 'Segoe UI', Tahoma, 'Noto Sans Thai', sans-serif;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--ui-font); font-size: 15px; color: var(--text); background: var(--bg); }
[hidden] { display: none !important; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.3; }
h2 { font-size: 1.15rem; color: var(--navy); }
h2 small, .muted { color: var(--muted); font-weight: 400; font-size: .9rem; }
a { color: var(--navy-3); }

/* ---------- ปุ่ม ---------- */
.btn { display: inline-flex; align-items: center; gap: .35em; border: 1px solid transparent; border-radius: 8px;
  padding: .5em .95em; cursor: pointer; font-weight: 600; background: #fff; color: var(--navy); line-height: 1.2;
  transition: background .15s, border-color .15s, transform .05s; white-space: nowrap; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.gold { background: var(--gold); color: #1d1606; }
.btn.gold:hover { background: var(--gold-2); }
.btn.ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
.btn.ghost:hover { background: rgba(255,255,255,.12); }
.btn.ghost-dark { background: #fff; border-color: var(--line); color: var(--navy); }
.btn.ghost-dark:hover { border-color: var(--navy-3); background: #f6f8fc; }
.btn.ghost-dark[aria-pressed="true"] { background: var(--gold-soft); border-color: var(--gold); }
.btn.danger { color: var(--err); border-color: #f0c9c4; background: #fff; }
.btn.big { font-size: 1.05rem; padding: .75em 1.3em; }
.btn.tiny { padding: .2em .6em; font-size: .85rem; }
.btn.small { padding: .3em .7em; font-size: .88rem; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- แถบบน ---------- */
.topbar { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .55rem 1rem; background: var(--navy); color: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; }
.brand img { background: #fff; border-radius: 8px; padding: 2px; }
.brand b { display: block; font-size: 1.05rem; letter-spacing: .3px; }
.brand small { display: block; opacity: .8; font-size: .8rem; }
.topnav { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ---------- หน้าหลัก / ตัวช่วยสร้าง ---------- */
.view:not(#view-editor) { max-width: 1180px; margin: 0 auto; padding: 1.2rem 1rem 3rem; }
.hero { display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; flex-wrap: wrap;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-3) 100%); color: #fff; border-radius: 14px; padding: 1.6rem 1.8rem; margin-bottom: 1.2rem; }
.hero h1 { font-size: 1.55rem; }
.hero p { margin: 0; opacity: .9; max-width: 640px; }
.hero-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 1.1rem 1.2rem; margin-bottom: 1.1rem; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .6rem; }
.panel-head h2 { margin: 0; }
.panel-head input[type=search] { min-width: 240px; padding: .45em .7em; border: 1px solid var(--line); border-radius: 8px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .8rem; }
.card { position: relative; text-align: left; background: #fff; border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: .9rem 1rem; cursor: pointer; display: flex; flex-direction: column; gap: .3rem; transition: border-color .15s, box-shadow .15s, transform .1s; }
.card:hover, .card:focus-visible { border-color: var(--gold); box-shadow: 0 4px 14px rgba(31,45,77,.12); transform: translateY(-1px); }
.card .ic { font-size: 1.6rem; line-height: 1; }
.card .ic-img { display: block; width: 125px; height: 35px; max-width: 100%; object-fit: contain; align-self: flex-start; margin: 0 0 .1rem -.15rem; }
.card b { color: var(--navy); font-size: 1.02rem; }
.card span { color: var(--muted); font-size: .88rem; line-height: 1.45; }
.card .tag { position: absolute; top: .55rem; right: .6rem; font-size: .72rem; background: var(--gold-soft); color: #7a5d00; border-radius: 99px; padding: .1em .55em; }
.card .types { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: .2rem; }
.chip { display: inline-block; font-size: .75rem; border-radius: 99px; padding: .12em .6em; background: #eef2fa; color: var(--navy-2); border: 1px solid #dbe3f2; }
.steps { display: flex; gap: .4rem; list-style: none; padding: 0; margin: 0 0 1rem; flex-wrap: wrap; }
.steps li { padding: .4em .9em; border-radius: 99px; background: #fff; border: 1px solid var(--line); color: var(--muted); font-size: .9rem; }
.steps li.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.foot-note { color: var(--muted); font-size: .85rem; text-align: center; }

/* รายการร่าง */
.draft-table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.draft-table th, .draft-table td { text-align: left; padding: .55em .5em; border-bottom: 1px solid #edf0f5; vertical-align: middle; }
.draft-table th { color: var(--muted); font-weight: 600; font-size: .82rem; }
.draft-table td.act { white-space: nowrap; text-align: right; }
.draft-table tr:hover td { background: #fafbfe; }
.empty { color: var(--muted); padding: 1rem 0; text-align: center; }

/* ---------- Editor ---------- */
#view-editor { display: flex; flex-direction: column; height: calc(100vh - 56px); }
.edbar { display: flex; justify-content: space-between; align-items: center; gap: .6rem; flex-wrap: wrap;
  padding: .45rem .8rem; background: #fff; border-bottom: 1px solid var(--line); }
.edbar-left { display: flex; align-items: center; gap: .6rem; min-width: 0; flex: 1 1 260px; }
.edbar-right { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.badge { background: var(--navy); color: #fff; border-radius: 6px; padding: .2em .6em; font-size: .82rem; white-space: nowrap; }
.doc-title { font-weight: 600; color: var(--navy); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropdown { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 40; background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.15); min-width: 260px; padding: .3rem; display: flex; flex-direction: column; }
.menu button, .menu label { text-align: left; background: none; border: 0; padding: .55em .8em; border-radius: 7px; cursor: pointer; font-size: .93rem; }
.menu button:hover:not(:disabled), .menu label:hover, .menu .menu-link:hover { background: #f1f4fa; }
.menu .menu-link { display: block; padding: .55em .8em; border-radius: 7px; font-size: .93rem; color: inherit; text-decoration: none; }
.qr-preview { display: flex; align-items: center; gap: .7rem; margin: -.2rem 0 .8rem; color: var(--muted); font-size: .82rem; }
.qr-preview img { border: 1px solid var(--line); border-radius: 6px; image-rendering: pixelated; }
.lint-list .lmsg { flex: 1; }
.lint-list .fixbtn { flex: 0 0 auto; align-self: center; }
.menu button:disabled { color: #9aa3b5; cursor: not-allowed; }

.split { flex: 1; display: grid; grid-template-columns: minmax(380px, 470px) 1fr; min-height: 0; }
.formpane { position: relative; background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.tabs { display: flex; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; gap: 0; padding: .4rem .5rem 0; border-bottom: 1px solid var(--line); background: #f7f9fc; }
.tabs button { flex: 0 0 auto; white-space: nowrap; border: 1px solid transparent; border-bottom: none; background: none; padding: .5em .5em; border-radius: 8px 8px 0 0; cursor: pointer; color: var(--muted); font-weight: 600; font-size: .86rem; }
.tabs button.on { background: #fff; border-color: var(--line); color: var(--navy); margin-bottom: -1px; }
.tabs .count { display: inline-block; min-width: 1.4em; padding: 0 .35em; border-radius: 99px; background: var(--gold-soft); color: #7a5d00; font-size: .75rem; }
.tabs .count:empty { display: none; }
#docForm { flex: 1; overflow-y: auto; padding: .9rem 1rem 2.5rem; }
.tabpane > h3 { font-size: .98rem; color: var(--navy); margin: 1.1rem 0 .5rem; padding-bottom: .3rem; border-bottom: 2px solid var(--gold-soft); }
.tabpane > h3:first-child { margin-top: 0; }

.fg { margin-bottom: .75rem; }
.fg > label, .fg > .lbl { display: block; font-weight: 600; font-size: .88rem; color: #33405a; margin-bottom: .25rem; }
.fg .hint { color: var(--muted); font-size: .8rem; margin-top: .2rem; line-height: 1.45; }
.fg input[type=text], .fg input[type=date], .fg input[type=number], .fg select, .fg textarea, .para-row textarea, .enc-row input {
  width: 100%; border: 1px solid #c9d1df; border-radius: 8px; padding: .5em .65em; background: #fbfcfe; line-height: 1.45; }
.fg textarea, .para-row textarea { resize: vertical; min-height: 2.6em; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--navy-3); background: #fff; box-shadow: 0 0 0 3px rgba(59,82,135,.15); }
.row { display: flex; gap: .6rem; }
.row > * { flex: 1; min-width: 0; }
.check { display: flex; align-items: center; gap: .45rem; font-weight: 500 !important; cursor: pointer; }
.check input { width: 1.05em; height: 1.05em; accent-color: var(--navy); }
.inline-tools { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .35rem; }
.field-flash { animation: flash 1.2s ease; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 4px rgba(201,162,39,.55); } 100% { box-shadow: none; } }

/* ย่อหน้า */
.para-row { border: 1px solid var(--line); border-radius: 10px; padding: .5rem; margin-bottom: .55rem; background: #fcfdff; }
.para-row.focus { border-color: var(--navy-3); }
.para-head { display: flex; align-items: center; gap: .35rem; margin-bottom: .35rem; font-size: .82rem; color: var(--muted); }
.para-head b { color: var(--navy); }
.para-head select { border: 1px solid var(--line); border-radius: 6px; padding: .15em .3em; font-size: .82rem; background: #fff; }
.para-head .sp { flex: 1; }
.icon-btn { border: 1px solid var(--line); background: #fff; border-radius: 6px; cursor: pointer; padding: .1em .45em; font-size: .85rem; color: var(--navy); }
.icon-btn:hover { border-color: var(--navy-3); }
.icon-btn.del:hover { border-color: var(--err); color: var(--err); }
.phrase-box { border: 1px dashed #cfd7e6; border-radius: 10px; padding: .6rem; background: #fafbfd; }
/* หัวข้อภาคเหตุ/ภาคความประสงค์/ภาคสรุป ในคลังสำนวน — ไฮไลต์เหลืองอ่อนให้เห็นชัด */
.phrase-box .ph-group { display: block; font-size: .86rem; color: #1b2a4a; margin: .6rem 0 .35rem; font-weight: 700; padding: .28em .65em;
  background: #fff6b8; border-left: 4px solid #f0c419; border-radius: 6px; }
.phrase-box .ph-group:first-child { margin-top: .1rem; }
.phrase { display: inline-block; text-align: left; border: 1px solid #dfe5f0; background: #fff; border-radius: 8px; padding: .25em .55em; margin: 0 .3rem .35rem 0; cursor: pointer; font-size: .84rem; line-height: 1.4; }
.phrase:hover { border-color: var(--gold); background: var(--gold-soft); }
.enc-row { display: grid; grid-template-columns: 1fr 9.5em auto; gap: .35rem; margin-bottom: .35rem; }

/* AI */
.ai-warn { background: #fff6e5; border: 1px solid #f1d8a6; color: #6b4a00; border-radius: 10px; padding: .6rem .75rem; font-size: .86rem; line-height: 1.5; margin-bottom: .8rem; }
.ai-off { background: #fdecea; border-color: #f3c3bd; color: #8a1f14; }
.ai-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .45rem; margin: .4rem 0 .6rem; }
.ai-actions .btn { justify-content: center; white-space: normal; text-align: center; }
.prompt-out { font-family: Consolas, 'Courier New', monospace; font-size: .8rem !important; background: #f6f7fb !important; }
details.ai-guide { border: 1px solid var(--line); border-radius: 10px; padding: .5rem .7rem; background: #f8fafd; margin-top: .8rem; }
details.ai-guide summary { cursor: pointer; font-weight: 600; color: var(--navy); }
details.ai-guide ol { margin: .5rem 0 0 1.1rem; padding: 0; font-size: .85rem; line-height: 1.55; }
.result-box { border-radius: 10px; padding: .6rem .75rem; font-size: .87rem; margin-top: .5rem; line-height: 1.5; }
.result-box.ok { background: #e9f6ef; border: 1px solid #b9e0c9; color: #17543a; }
.result-box.err { background: #fdecea; border: 1px solid #f3c3bd; color: #8a1f14; }
.result-box ul { margin: .3rem 0 0 1.1rem; padding: 0; }

/* ตรวจ */
.lint-list { list-style: none; margin: 0; padding: 0; }
.lint-list li { display: flex; gap: .5rem; align-items: flex-start; padding: .55rem .6rem; border: 1px solid var(--line); border-radius: 9px; margin-bottom: .45rem; font-size: .9rem; line-height: 1.5; cursor: pointer; background: #fff; }
.lint-list li:hover { border-color: var(--navy-3); }
.lint-list .lv { flex: 0 0 auto; font-size: .75rem; border-radius: 99px; padding: .1em .55em; font-weight: 700; color: #fff; margin-top: .15em; }
.lv.error { background: var(--err); } .lv.warn { background: var(--warn); } .lv.info { background: var(--info); }
.lint-ok { background: #e9f6ef; color: #17543a; border: 1px solid #b9e0c9; border-radius: 10px; padding: .8rem; }

/* โหมดแก้บนกระดาษ */
.edit-lock { position: absolute; inset: 0; background: rgba(247,249,252,.94); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; padding: 2rem; text-align: center; z-index: 5; }
.edit-lock p { line-height: 1.7; color: var(--navy); }

/* พรีวิว */
.previewpane { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #7c8698; }
.zoombar { position: absolute; top: .5rem; right: 1rem; z-index: 3; display: flex; align-items: center; gap: .3rem; background: rgba(255,255,255,.95);
  border-radius: 99px; padding: .2rem .4rem; box-shadow: 0 2px 8px rgba(0,0,0,.2); font-size: .85rem; }
.zoombar #zoomLabel { min-width: 3.2em; text-align: center; }
.preview-scroll { flex: 1; overflow: auto; padding: 1.2rem 0 2rem; }
.preview-scaler { position: relative; margin: 0 auto; }
.paper { position: absolute; top: 0; left: 0; width: 21cm; transform-origin: top left; }
.paper .a4-page { margin: 0 0 18px; box-shadow: 0 4px 22px rgba(0,0,0,.35); }
.statusbar { display: flex; gap: 1.2rem; flex-wrap: wrap; padding: .4rem 1rem; background: #fff; border-top: 1px solid var(--line); font-size: .85rem; color: var(--muted); }
.statusbar .bad { color: var(--err); font-weight: 700; }
.statusbar .warn { color: var(--warn); font-weight: 600; }
.statusbar .good { color: var(--ok); font-weight: 600; }
.mobile-switch { display: none; }

/* กล่องข้อความ / แจ้งเตือน */
.modal { position: fixed; inset: 0; background: rgba(15,22,38,.55); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 1rem; }
.modal-box { background: #fff; border-radius: 14px; max-width: 560px; width: 100%; padding: 1.2rem 1.3rem; box-shadow: 0 10px 40px rgba(0,0,0,.3); max-height: 85vh; overflow: auto; }
.modal-box h3 { color: var(--navy); }
.modal-box ul { padding-left: 1.2rem; line-height: 1.6; }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
.toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: .6rem 1.1rem; border-radius: 99px; z-index: 120; box-shadow: 0 6px 20px rgba(0,0,0,.25); font-size: .92rem; max-width: 90vw; }

/* ---------- จอเล็ก ---------- */
@media (max-width: 900px) {
  .split { grid-template-columns: minmax(0, 1fr); }
  .mobile-switch { display: flex; background: #fff; border-bottom: 1px solid var(--line); }
  .mobile-switch button { flex: 1; padding: .6rem; border: 0; background: none; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; }
  .mobile-switch button.on { color: var(--navy); border-bottom-color: var(--gold); }
  /* ซ่อนพรีวิวแบบยังวัดขนาดได้ (การแบ่งหน้าต้องวัดความสูงจริง) */
  #view-editor[data-pane="form"] .previewpane { position: fixed; left: -12000px; top: 0; width: 900px; height: 100vh; visibility: hidden; }
  #view-editor[data-pane="preview"] .formpane { display: none; }
  .hero { padding: 1.2rem; }
  .hero h1 { font-size: 1.25rem; }
  .edbar-right .btn { padding: .4em .6em; font-size: .85rem; }
  .brand small { display: none; }
  .topbar { padding: .45rem .6rem; }
  .topnav .btn { padding: .4em .6em; font-size: .85rem; }
  .topnav > .btn.ghost { display: none; }
  .auth-area .btn { font-size: .85rem; padding: .4em .6em; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; }
}

/* ---------- พิมพ์: เหลือเฉพาะกระดาษ ---------- */
@media print {
  .no-print, .topbar, .edbar, .formpane, .zoombar, .statusbar, .mobile-switch, .modal, .toast { display: none !important; }
  body, #view-editor, .split, .previewpane, .preview-scroll { display: block !important; height: auto !important; overflow: visible !important; background: #fff !important; padding: 0 !important; }
  /* ตอนพิมพ์ความกว้างหน้า ~794px ตรงเงื่อนไขจอเล็ก → ต้องคืนค่าพรีวิวที่ซ่อนแบบ off-screen ไว้ด้วย */
  #view-editor[data-pane] .previewpane { display: block !important; position: static !important; left: auto !important;
    width: auto !important; height: auto !important; visibility: visible !important; }
  .preview-scaler { width: auto !important; height: auto !important; margin: 0 !important; }
  .paper { position: static !important; transform: none !important; }
  .paper .a4-page { margin: 0 !important; box-shadow: none !important; }
}

/* ---------- เฟส ๓: บัญชีผู้ใช้ / เอกสารบน host / ผู้ดูแล ---------- */
.auth-area { display: flex; align-items: center; }
.auth-area .menu { min-width: 220px; color: var(--text); }
.menu-head { padding: .45em .8em .55em; font-size: .8rem; color: var(--muted); border-bottom: 1px solid #edf0f5; margin-bottom: .25rem; }
.list-tools { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.list-tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin: .2rem 0 .4rem; border-bottom: 1px solid var(--line); }
.list-tabs button { background: none; border: 0; border-bottom: 3px solid transparent; padding: .45em .85em; cursor: pointer; font-weight: 600; color: var(--muted); }
.list-tabs button.on { color: var(--navy); border-bottom-color: var(--gold); }
.list-tabs button:hover { color: var(--navy); }
.list-note { font-size: .84rem; color: var(--muted); margin: 0 0 .5rem; }
.chip.share { background: #e7f5ee; color: var(--ok); border-color: #c7e8d6; }
.ro-banner { background: #fff7e0; border: 1px solid #f0d58a; color: #6b5200; border-radius: 8px; padding: .6em .8em; margin-bottom: .8rem; font-size: .9rem;
  display: flex; gap: .6rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.formpane.readonly input, .formpane.readonly textarea, .formpane.readonly select { background: #f6f7fa; }
.modal-form h4 { margin: 1rem 0 .4rem; color: var(--navy); font-size: .95rem; border-bottom: 1px solid #edf0f5; padding-bottom: .25rem; }
.modal-form .row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.modal-form input[type=text], .modal-form input[type=password], .modal-form textarea, .modal-form select { width: 100%; }
.modal-form .check { display: flex; gap: .4rem; align-items: center; margin: .4rem 0; }
.mini-list { list-style: none; padding: 0; margin: .3rem 0; max-height: 50vh; overflow: auto; }
.mini-list li { display: flex; justify-content: space-between; align-items: center; gap: .8rem; padding: .5em .2em; border-bottom: 1px solid #edf0f5; }
.mini-list li > span:last-child { white-space: nowrap; }
.card-sep { grid-column: 1 / -1; font-size: .85rem; font-weight: 600; color: var(--muted); margin-top: .4rem; border-top: 1px dashed var(--line); padding-top: .6rem; }
.card.mytpl { border-style: dashed; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem; margin-bottom: .6rem; }
.stat { background: #f6f8fc; border: 1px solid var(--line); border-radius: 10px; padding: .7em .9em; display: flex; flex-direction: column; }
.stat b { font-size: 1.35rem; color: var(--navy); }
.stat span { font-size: .82rem; color: var(--muted); }
#view-admin { max-width: 1200px; margin: 0 auto; padding: 1rem; }
#view-admin .draft-table { margin-top: .4rem; }
#view-admin details summary { cursor: pointer; padding: .2rem 0; }
@media (max-width: 720px) {
  .modal-form .row { grid-template-columns: 1fr; }
  .list-tools { width: 100%; }
  .draft-table th:nth-child(3), .draft-table td:nth-child(3) { display: none; }
  .draft-table.srv th:nth-child(4), .draft-table.srv td:nth-child(4), .draft-table.srv th:nth-child(2), .draft-table.srv td:nth-child(2) { display: none; }
  .draft-table.srv td.act { white-space: normal; }
  .draft-table.srv td.act .btn { margin: 1px 0; }
}

/* ---------- 3.2.0: สวิตช์ ส่วนตัว/แชร์ · ปุ่มลบแม่แบบ · แถบสถานะยังไม่บันทึก ---------- */
.seg { display: inline-flex; align-items: center; border: 1.5px solid var(--line); border-radius: 99px; background: #fff; overflow: hidden; }
.seg[hidden] { display: none !important; }
.seg-lbl { font-size: .78rem; color: var(--muted); padding: 0 .55rem 0 .85rem; white-space: nowrap; }
.seg button { border: 0; border-left: 1px solid var(--line); background: none; padding: .42em .85em; cursor: pointer; font-weight: 600; color: var(--muted); white-space: nowrap; }
.seg button.on { background: var(--navy); color: #fff; }
.seg button:not(.on):hover { background: #eef2fa; color: var(--navy); }
.card-wrap { position: relative; display: flex; }
.card-wrap > .card { flex: 1; }
.card-del { position: absolute; bottom: .5rem; right: .55rem; font-size: .75rem; border: 1px solid #f0c9c4; background: #fff; color: var(--err); border-radius: 99px; padding: .15em .7em; cursor: pointer; }
.card-del:hover, .card-del:focus-visible { background: var(--err); color: #fff; }
.card-sep .muted { font-weight: 400; }
.list-tabs button { text-align: left; }
@media (max-width: 720px) { .seg-lbl { display: none; } }

/* ---------- ระบบสร้างหนังสือราชการจากระบบช่วยเหลือ (Wizard แบบสอบถาม) · 3.2.1 ---------- */
.panel h2 small { font-weight: 400; font-size: .8em; }
.assist-box { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; text-decoration: none; color: inherit;
  background: linear-gradient(135deg, #fff8dc 0%, #eef3ff 100%); border: 1.5px solid var(--gold); border-radius: var(--radius); padding: 1rem 1.2rem;
  transition: box-shadow .15s, transform .1s; }
.assist-box:hover, .assist-box:focus-visible { box-shadow: 0 6px 18px rgba(31,45,77,.16); transform: translateY(-1px); }
.assist-ic { font-size: 2.4rem; line-height: 1; }
.assist-txt { flex: 1 1 360px; display: flex; flex-direction: column; gap: .25rem; }
.assist-txt b { color: var(--navy); font-size: 1.08rem; }
.assist-txt span { color: var(--navy); font-size: 1rem; line-height: 1.55; }
.assist-go { white-space: nowrap; pointer-events: none; }
.assist-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 1rem; align-items: start; }
.assist-form { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.as-q { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 1rem 1.1rem 1.1rem; margin: 0; min-width: 0; }
.as-q[hidden] { display: none; }
.as-q legend { font-weight: 700; color: var(--navy); font-size: 1.05rem; padding: 0 .4rem; }
.as-n { display: inline-block; min-width: 1.7em; text-align: center; background: var(--navy); color: #fff; border-radius: 99px; padding: 0 .35em; margin-right: .25rem; }
.req { font-style: normal; font-weight: 400; font-size: .72rem; background: #fdecea; color: var(--err); border-radius: 99px; padding: .1em .6em; margin-left: .3rem; }
.as-group { font-size: .82rem; font-weight: 700; color: var(--muted); margin: .8rem 0 .35rem; border-bottom: 1px dashed var(--line); padding-bottom: .2rem; }
.as-group:first-of-type { margin-top: .2rem; }
.as-opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .5rem; }
.as-opts.compact { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.as-opt { display: flex; gap: .55rem; align-items: flex-start; border: 1.5px solid var(--line); border-radius: 10px; padding: .55rem .7rem; cursor: pointer; background: #fff; }
.as-opt:hover { border-color: var(--gold); }
.as-opt.on { border-color: var(--navy); background: #f1f5fd; box-shadow: inset 0 0 0 1px var(--navy); }
.as-opt input { margin-top: .3rem; flex: none; }
.as-opt b { display: block; color: var(--navy); font-size: .95rem; }
.as-opt small { display: block; color: var(--muted); font-size: .8rem; line-height: 1.4; margin-top: .1rem; }
.as-sub { margin-top: .8rem; padding: .7rem .8rem; background: #fafbfe; border: 1px solid #e6ebf5; border-radius: 10px; }
.as-sub[hidden] { display: none; }
.as-sub > b { display: block; margin-bottom: .4rem; color: var(--navy); }
.as-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .6rem; }
.as-chk { display: flex; gap: .5rem; align-items: flex-start; margin-top: .4rem; font-size: .92rem; cursor: pointer; }
.as-chk input { margin-top: .3rem; }
.as-chk[hidden] { display: none; }
.as-more { padding: .7rem 1.1rem; }
.as-more summary { cursor: pointer; font-weight: 600; color: var(--navy); }
.as-more[open] summary { margin-bottom: .6rem; }
.as-flash { animation: asflash 1.5s ease; }
@keyframes asflash { 0%, 60% { box-shadow: 0 0 0 3px var(--err); } 100% { box-shadow: 0 0 0 0 transparent; } }
.assist-side { position: sticky; top: 4.2rem; display: flex; flex-direction: column; gap: .8rem; }
.assist-plan { background: #fffdf2; border: 1.5px solid var(--gold); border-radius: 14px; padding: .9rem 1rem; }
.assist-plan h3 { margin: 0 0 .5rem; color: var(--navy); font-size: 1rem; }
.assist-plan dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: .2rem .7rem; font-size: .9rem; }
.assist-plan dt { color: var(--muted); }
.assist-plan dd { margin: 0; }
.as-reasons, .as-warns { margin: .6rem 0 0; padding-left: 1.1rem; font-size: .83rem; color: var(--muted); line-height: 1.5; }
.as-warns { color: #8a4b00; list-style: none; padding-left: 0; }
.assist-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.assist-actions .big { flex: 1 1 100%; }
.assist-err { margin: 0; color: var(--err); font-weight: 600; font-size: .9rem; }
.assist-err[hidden] { display: none; }
@media (max-width: 900px) {
  .assist-wrap { grid-template-columns: minmax(0, 1fr); }
  .assist-side { position: static; }
}

/* ---------- แชร์ PDF (3.2.2) ---------- */
.pdf-bar { height: 10px; border-radius: 99px; background: #e8ecf5; overflow: hidden; margin: .6rem 0; }
.pdf-bar i { display: block; height: 100%; background: var(--gold); transition: width .3s; }
.pdf-ok { color: var(--ok); font-weight: 700; margin: 0 0 .3rem; }
.pdf-name { margin: 0 0 .8rem; word-break: break-all; color: var(--navy); font-weight: 600; }
.pdf-actions { display: flex; flex-direction: column; gap: .5rem; }
.pdf-actions .btn { width: 100%; justify-content: center; }
.pdf-tip { font-size: .85rem; margin: .8rem 0 0; }

/* ===== 3.2.2 · ติดตั้งไอคอนบนมือถือ / จดจำการเข้าสู่ระบบ ===== */
.chk-remember { display: flex; gap: .55rem; align-items: flex-start; margin: .35rem 0 .2rem; cursor: pointer; line-height: 1.4; }
.chk-remember input { width: 1.25rem; height: 1.25rem; margin-top: .15rem; flex: none; accent-color: var(--navy); }
.chk-remember small { display: block; color: var(--muted); font-size: .8rem; font-weight: 400; margin-top: .1rem; }
.install-box { display: flex; align-items: center; gap: .75rem; background: var(--gold-soft); border: 1px solid #ecd98c; border-radius: var(--radius);
  padding: .65rem .8rem; margin: 0 0 1rem; }
.install-ic { font-size: 1.7rem; line-height: 1; }
.install-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; color: var(--navy); }
.install-txt small { color: var(--muted); font-size: .82rem; }
.install-x { border: 0; background: transparent; color: var(--muted); font-size: 1.1rem; padding: .4rem .5rem; cursor: pointer; border-radius: 6px; }
.install-x:hover { background: rgba(0,0,0,.06); }
.pwa-steps { padding-left: 1.3rem; line-height: 1.7; }
.pwa-steps li { margin-bottom: .3rem; }
.login-gate { position: fixed; inset: 0; z-index: 1000; background: linear-gradient(180deg, var(--navy) 0, var(--navy-2) 100%); overflow-y: auto;
  display: flex; align-items: center; justify-content: center; padding: 1rem; }
.gate-card { background: #fff; border-radius: 16px; padding: 1.5rem 1.3rem 1.3rem; width: 100%; max-width: 380px; box-shadow: 0 10px 40px rgba(0,0,0,.35); text-align: center; }
.gate-card img { display: block; margin: 0 auto .4rem; }
.gate-card h1 { font-size: 1.25rem; color: var(--navy); margin: .2rem 0 .1rem; }
.gate-org { color: var(--muted); font-size: .9rem; margin: 0 0 1rem; }
.gate-card .fg { text-align: left; }
.gate-card .fg input { width: 100%; font-size: 1.05rem; padding: .65rem .7rem; border: 1px solid #c9d1df; border-radius: 8px; background: #fbfcfe; }
.gate-card .chk-remember { text-align: left; margin: .6rem 0 1rem; }
.gate-card .btn.big { width: 100%; justify-content: center; }
.gate-skip { margin-top: .9rem; border: 0; background: transparent; color: var(--info); text-decoration: underline; font-size: .92rem; cursor: pointer; padding: .4rem; }
body.gate-on { overflow: hidden; }

/* ===== 3.2.3 · ชื่อไฟล์แก้ได้ + ส่ง PDF เป็นลิงก์ ===== */
.pdf-namebox { margin: .2rem 0 .8rem; }
.pdf-namebox input { width: 100%; border: 1px solid #c9d1df; border-radius: 8px; padding: .55em .7em; background: #fbfcfe; font-size: 1rem; }
#pdfLinkBox { margin-top: .8rem; }
.pdf-linkbox { border-top: 1px dashed #c9d1df; padding-top: .7rem; }
.pdf-url { width: 100%; margin-top: .6rem; border: 1px solid #c9d1df; border-radius: 8px; padding: .45em .6em; font-size: .85rem; background: #f4f6fa; color: var(--muted); }
.pdf-actions a.btn { text-decoration: none; }

/* ===== 3.2.4 · ปุ่ม "แชร์ PDF" สีเขียว ชิดขวา (มือถือ/แท็บเล็ต) · ไม่แสดงบนคอมพิวเตอร์ (ใช้เมนู ⋯ ไฟล์ แทน) ===== */
#btnSharePdf { order: 99; margin-left: auto; background: var(--ok); border-color: var(--ok); color: #fff; font-weight: 700; }
#btnSharePdf:hover, #btnSharePdf:focus-visible { background: #17643e; border-color: #17643e; color: #fff; }
@media (min-width: 901px) and (hover: hover) and (pointer: fine) { #btnSharePdf { display: none; } }
@media (max-width: 900px) { .edbar-right { flex: 1 1 100%; } }

/* ===== 3.2.5 · Wizard: หัวข้อหลักสีเหลืองเข้ม (สีเดียวกับปุ่ม Submit) · หัวข้อรองไฮไลต์เหลืองอ่อน ===== */
.as-q:not(.as-more) > legend { background: var(--gold); color: #1d1606; border-radius: 10px; padding: .35rem .8rem .35rem .45rem; box-shadow: 0 1px 0 rgba(0,0,0,.08); }
.as-q:not(.as-more) > legend .req { color: #5a1d00; }
.as-group { background: #fff3c4; color: #5b4400; border: 0; border-left: 4px solid var(--gold); border-radius: 6px; padding: .3rem .6rem; font-size: .88rem; }
/* ===== 3.2.5 · แท็บ "AI ช่วยร่าง" ไฮไลต์ชมพูอ่อน ===== */
.tabs button.tab-ai { background: #fde4ee; color: #9b1f5a; border-color: #f6c3d8; }
.tabs button.tab-ai.on { background: #fbd0e2; color: #7d1449; border-color: #ef9fc1; }
/* ===== 3.2.5 · ✏️ ตั้งชื่อเรียกในรายการ "เอกสารของฉัน" ===== */
.draft-table td.ttl { min-width: 13rem; }
@media (max-width: 600px) { .draft-table td.ttl a { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }  }
.ttl-w { display: flex; align-items: flex-start; gap: .1rem; }
.ttl-w .rename-btn { flex: none; }
.rename-btn { border: 0; background: transparent; cursor: pointer; font-size: .9rem; padding: .1rem .3rem; margin-left: .25rem; border-radius: 6px; opacity: .65; vertical-align: baseline; }
.rename-btn:hover, .rename-btn:focus-visible { opacity: 1; background: var(--gold-soft); }
.rename-subj { background: #f4f6fa; border-radius: 8px; padding: .45rem .65rem; font-size: .88rem; margin-bottom: .7rem; word-break: break-word; }
.rename-subj span { color: var(--muted); }
/* ===== 3.2.6 · ลบบัญชีผู้ใช้ ===== */
.del-list { padding-left: 1.2rem; line-height: 1.6; font-size: .92rem; margin: .7rem 0; }
