/* ThaiForm — ไทยคลาสสิก "ผู้ดีสมัยรัชกาลที่ ๕" (thai_classic_design_skill)
   ชุดสี ตู้ลายทอง: ลูกหว้า #3A173E (หลัก 60) · เลื่อมประภัสสร #EFCB57 (ลายทอง 30) · นาก #96362C (เน้น 10)
   พื้นกระดาษงาช้าง กรอบทองคู่ ลายประจำยามจาง ๆ บนแผงสีหลัก */
:root {
  --bg: #f4e9d8;
  --bg-2: #ecdcc2;
  --paper: #fbf6ec;
  --surface: rgba(255, 251, 243, 0.62);
  --surface-strong: rgba(255, 251, 243, 0.93);
  --line: rgba(58, 23, 62, 0.12);
  --line-strong: rgba(58, 23, 62, 0.24);
  --ink: #2a2320;
  --ink-2: #5d5148;
  --ink-3: #8b7d70;
  --accent: #3a173e;            /* ลูกหว้า */
  --accent-top: #57295c;
  --accent-ink: #fbefd8;
  --accent-soft: rgba(58, 23, 62, 0.08);
  --h2: #3a173e;
  --gold: #8a6d24;              /* ทองสำหรับตัวหนังสือบนกระดาษ */
  --orn: #efcb57;               /* เลื่อมประภัสสร: เส้นลาย */
  --orn-deep: #c9a23e;
  --orn-soft: #f1d991;
  --gold-soft: rgba(239, 203, 87, 0.2);
  --gold-line: rgba(201, 162, 62, 0.55);
  --red: #96362c;               /* นาก */
  --red-soft: rgba(150, 54, 44, 0.1);
  --danger: #9b2c22;
  --danger-soft: rgba(155, 44, 34, 0.1);
  --ok: #3d6b3a;
  --aurora-1: rgba(241, 217, 145, 0.75);
  --aurora-2: rgba(58, 23, 62, 0.42);
  --aurora-3: rgba(150, 54, 44, 0.3);
  --aurora-op: 0.36;
  --glass-border: rgba(255, 255, 255, 0.7);
  --shadow: 0 1px 2px rgba(60, 40, 20, 0.06), 0 10px 30px rgba(60, 40, 20, 0.09);
  --shadow-lg: 0 2px 4px rgba(60, 40, 20, 0.08), 0 18px 44px rgba(60, 40, 20, 0.14);
  --box: rgba(58, 23, 62, 0.85);
  --box-bg: rgba(58, 23, 62, 0.1);
  --r-btn: 10px;
  --r-card: 18px;
  --r-modal: 24px;
  --font-head: "Noto Serif Thai", "Taviraj", Georgia, serif;
  --font-body: "Sarabun", "Leelawadee UI", system-ui, "Segoe UI", sans-serif;
  --font-orn: "Cormorant Garamond", "Cormorant", Georgia, serif;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}
:root[data-theme="dark"] {
  --bg: #1d0f20;
  --bg-2: #130913;
  --paper: #2a1630;
  --surface: rgba(255, 240, 220, 0.05);
  --surface-strong: rgba(40, 20, 44, 0.95);
  --line: rgba(241, 217, 145, 0.13);
  --line-strong: rgba(241, 217, 145, 0.26);
  --ink: #f4e7cf;
  --ink-2: #cdb9a0;
  --ink-3: #9c8a78;
  --accent: #efcb57;
  --accent-top: #f6dc8c;
  --accent-ink: #2a1230;
  --accent-soft: rgba(239, 203, 87, 0.13);
  --h2: #f1d991;
  --gold: #efcb57;
  --orn: #efcb57;
  --orn-deep: #c9a23e;
  --orn-soft: #f1d991;
  --gold-soft: rgba(239, 203, 87, 0.14);
  --gold-line: rgba(239, 203, 87, 0.38);
  --red: #e6a091;
  --red-soft: rgba(230, 160, 145, 0.13);
  --danger: #ec9a8c;
  --danger-soft: rgba(236, 154, 140, 0.13);
  --ok: #9cc994;
  --aurora-1: rgba(239, 203, 87, 0.22);
  --aurora-2: rgba(110, 50, 118, 0.6);
  --aurora-3: rgba(150, 54, 44, 0.4);
  --aurora-op: 0.5;
  --glass-border: rgba(241, 217, 145, 0.16);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.3), 0 24px 60px rgba(0, 0, 0, 0.55);
  --box: rgba(239, 203, 87, 0.9);
  --box-bg: rgba(239, 203, 87, 0.12);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink);
  font: 400 16px/1.7 var(--font-body); -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--font-head); font-weight: 600; line-height: 1.3; margin: 0; }
h1 { font-size: clamp(1.65rem, 3.2vw, 2.2rem); font-weight: 600; text-wrap: balance; }
h2 { font-size: 1.2rem; color: var(--h2); }
h3 { font-size: 1.05rem; }
p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.dim { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: 0.875rem; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- พื้นหลัง: กระดาษงาช้าง แสงสามสี เกรนกระดาษ ---------- */
.aurora { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none;
  background: radial-gradient(ellipse at 50% 0%, color-mix(in srgb, var(--paper) 70%, transparent) 0%, transparent 60%), linear-gradient(180deg, var(--bg), var(--bg-2)); }
.aurora i { position: absolute; border-radius: 50%; filter: blur(90px); opacity: var(--aurora-op); animation: drift 26s ease-in-out infinite alternate; }
.aurora i:nth-child(1) { width: 46vw; height: 46vw; top: -16%; right: -8%; background: radial-gradient(circle, var(--aurora-1), transparent 65%); }
.aurora i:nth-child(2) { width: 40vw; height: 40vw; bottom: -18%; left: 8%; background: radial-gradient(circle, var(--aurora-2), transparent 65%); animation-duration: 32s; }
.aurora i:nth-child(3) { width: 30vw; height: 30vw; top: 30%; right: 18%; background: radial-gradient(circle, var(--aurora-3), transparent 65%); animation-duration: 38s; }
.aurora::after { content: ""; position: absolute; inset: 0; opacity: .35; mix-blend-mode: multiply; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 .55 0 0 0 0 .45 0 0 0 0 .3 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E"); }
:root[data-theme="dark"] .aurora::after { mix-blend-mode: screen; opacity: .12; }
@keyframes drift { to { transform: translate(4vw, 3vh) scale(1.08); } }

/* ---------- glass ---------- */
.glass {
  position: relative; background: var(--surface);
  -webkit-backdrop-filter: blur(22px) saturate(160%); backdrop-filter: blur(22px) saturate(160%);
  border: 1px solid var(--glass-border); border-radius: var(--r-card); box-shadow: var(--shadow);
}
.glass::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; padding: 1px; pointer-events: none;
  background: linear-gradient(160deg, rgba(255,250,235,.55), rgba(255,255,255,.04) 40%, transparent);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude;
}
.glass::after { content: ""; position: absolute; inset: 6px; border-radius: calc(var(--r-card) - 6px); border: 1px solid var(--gold-line); opacity: .6; pointer-events: none; }
@supports not (backdrop-filter: blur(1px)) { .glass { background: var(--surface-strong); } }
.card { padding: 24px; }
.card + .card { margin-top: 16px; }
/* การ์ดที่วางคู่กันในตาราง ระยะห่างมาจาก gap แล้ว ขอบบนต้องตรงกัน */
:where(.split, .grid, .stats) > .card + .card { margin-top: 0; }

/* ---------- แถบบน ---------- */
.topbar { position: sticky; top: 0; z-index: 20; padding: 12px 16px 0; }
.nav { max-width: 1240px; margin: 0 auto; display: flex; align-items: center; gap: 16px; padding: 8px 10px 8px 14px; border-radius: 16px;
  background: linear-gradient(180deg, #4a2150 0%, #2d132d 100%); color: #fbefd8; border-color: rgba(239,203,87,.4);
  box-shadow: 0 10px 30px rgba(45,19,45,.28), inset 0 0 0 1px rgba(239,203,87,.12); }
:root[data-theme="dark"] .nav { background: linear-gradient(180deg, #321636 0%, #1a0b1c 100%); }
.nav.glass::before { display: none; }
.nav.glass::after { inset: 0; border: 0; border-radius: inherit; opacity: .08; background-color: #fbefd8; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='44' height='44'%3E%3Cpath d='M22 12l4 4-4 4-4-4zM22 24l4 4-4 4-4-4zM16 18l4 4-4 4-4-4zM28 18l4 4-4 4-4-4z'/%3E%3Ccircle cx='22' cy='22' r='1.2'/%3E%3Ccircle cx='0' cy='0' r='1.2'/%3E%3Ccircle cx='44' cy='0' r='1.2'/%3E%3Ccircle cx='0' cy='44' r='1.2'/%3E%3Ccircle cx='44' cy='44' r='1.2'/%3E%3C/svg%3E") 0 0 / 44px 44px; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='44' height='44'%3E%3Cpath d='M22 12l4 4-4 4-4-4zM22 24l4 4-4 4-4-4zM16 18l4 4-4 4-4-4zM28 18l4 4-4 4-4-4z'/%3E%3Ccircle cx='22' cy='22' r='1.2'/%3E%3Ccircle cx='0' cy='0' r='1.2'/%3E%3Ccircle cx='44' cy='0' r='1.2'/%3E%3Ccircle cx='0' cy='44' r='1.2'/%3E%3Ccircle cx='44' cy='44' r='1.2'/%3E%3C/svg%3E") 0 0 / 44px 44px; }
.nav > * { position: relative; z-index: 1; }
.nav :focus-visible { outline-color: #f1d991; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: #fbefd8; }
.mark { width: 36px; height: 36px; color: #f1d991; flex: none; }
.bname { font: italic 600 1.55rem/1 var(--font-orn); letter-spacing: .02em; }
.ver { font: 500 0.72rem var(--font-body); color: rgba(251,239,216,.75); padding: 1px 7px; border: 1px solid rgba(239,203,87,.4); border-radius: 99px; }
.ver:empty { display: none; }
.links { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.links::-webkit-scrollbar { display: none; }
.links a { white-space: nowrap; flex: none; text-decoration: none; color: rgba(251,239,216,.8); padding: 7px 12px; border-radius: 10px; font: 500 0.98rem var(--font-head); transition: background .2s, color .2s; }
.links a:hover { background: rgba(251,239,216,.08); color: #fbefd8; }
.links a.on { background: rgba(241,217,145,.16); color: #fbefd8; box-shadow: inset 0 -2px 0 #efcb57, inset 0 0 0 1px rgba(241,217,145,.25); }
.links .keychip { margin-left: auto; border: 1px solid rgba(239,203,87,.35); font-size: 0.9rem; }
.links .keychip.own { border-color: #efcb57; color: #f1d991; }
.tools { display: flex; gap: 4px; }
.icon-btn { width: 38px; height: 38px; display: grid; place-items: center; border: 0; border-radius: 10px; background: transparent; cursor: pointer; color: var(--ink-2); }
.icon-btn:hover { background: var(--accent-soft); color: var(--ink); }
.nav .icon-btn { color: rgba(251,239,216,.8); }
.nav .icon-btn:hover { background: rgba(251,239,216,.1); color: #fbefd8; }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- เนื้อหา ---------- */
main { max-width: 1240px; margin: 0 auto; padding: 32px 16px 96px; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head .titles { display: grid; gap: 6px; max-width: 70ch; }
.eyebrow { font: italic 500 1.15rem/1.2 var(--font-orn); letter-spacing: .04em; color: var(--red); display: inline-flex; align-items: center; gap: 10px; }
.eyebrow::before { content: ""; width: 6px; height: 6px; background: var(--orn-deep); transform: rotate(45deg); }
.eyebrow::after { content: ""; width: 40px; height: 1px; background: linear-gradient(90deg, var(--orn-deep), transparent); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.split { display: grid; gap: 20px; grid-template-columns: minmax(0, 1.35fr) minmax(320px, 1fr); align-items: start; }
@media (max-width: 960px) { .split { grid-template-columns: 1fr; } }
.stack { display: grid; gap: 12px; }
.sticky { position: sticky; top: 88px; }
@media (max-width: 960px) { .sticky { position: static; } }

/* ---------- ปุ่ม ฟอร์ม ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; min-height: 42px;
  border-radius: var(--r-btn); border: 1px solid var(--gold-line); cursor: pointer; font-family: var(--font-head); font-weight: 500; font-size: .95rem;
  background: linear-gradient(180deg, var(--accent-top), var(--accent)); color: var(--accent-ink); box-shadow: inset 0 1px 0 rgba(255,255,255,.18), 0 6px 18px rgba(45,19,45,.22);
  transition: transform .2s var(--ease), box-shadow .2s, background .2s; text-decoration: none; white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.ghost { background: color-mix(in srgb, var(--paper) 70%, transparent); color: var(--ink); border-color: var(--gold-line); box-shadow: none; }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.gold { background: linear-gradient(180deg, #f6dc8c, #e2b945); color: #3a2a10; border-color: #c9a23e; box-shadow: inset 0 1px 0 rgba(255,255,255,.45), 0 6px 18px rgba(201,162,62,.3); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger-soft); box-shadow: none; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 6px 12px; min-height: 34px; font-size: 0.9rem; border-radius: 9px; }
.btn.lg { padding: 13px 22px; min-height: 50px; font-size: 1.05rem; }
.btn.block { width: 100%; }
label { display: grid; gap: 6px; font-size: 0.92rem; color: var(--ink-2); font-weight: 500; font-family: var(--font-head); }
label input, label select, label textarea { font-family: var(--font-body); }
.check { font-family: var(--font-body); }
input[type=text], input[type=email], input[type=password], input[type=number], input:not([type]), select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line-strong);
  background: var(--surface-strong); color: var(--ink); font-size: 1rem; transition: border-color .2s, box-shadow .2s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 80px; resize: vertical; line-height: 1.6; }
input[type=color] { width: 44px; height: 40px; padding: 2px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--surface-strong); }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; color: var(--ink); cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 4px; accent-color: var(--accent); }

/* ---------- เข้าสู่ระบบ ---------- */
.auth-wrap { min-height: calc(100vh - 140px); display: grid; place-items: center; }
.auth { width: min(440px, 100%); padding: 32px; display: grid; gap: 18px; }
.auth .art { width: 120px; margin: 0 auto -4px; display: block; }
.auth .head { text-align: center; display: grid; gap: 8px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; border-radius: 12px; background: var(--accent-soft); }
.tabs button { font-family: var(--font-head); border: 0; background: transparent; padding: 8px; border-radius: 9px; cursor: pointer; font-weight: 500; color: var(--ink-2); }
.tabs button.on { background: var(--surface-strong); color: var(--ink); box-shadow: var(--shadow); }
.notice { display: flex; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--gold-soft); color: var(--ink); font-size: 0.9rem; line-height: 1.6; }
.notice .ic { color: var(--gold); margin-top: 2px; }
.notice.info { background: var(--accent-soft); }
.notice.info .ic { color: var(--accent); }

/* ---------- การ์ดแม่แบบ ---------- */
.tile { padding: 20px; display: flex; flex-direction: column; gap: 12px; transition: transform .25s var(--ease), box-shadow .25s; }
.tile > * { position: relative; z-index: 1; }
.tile .actions { margin-top: auto; padding-top: 6px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tile .thumb { position: relative; }
.tile-mv { position: absolute; top: 8px; right: 8px; z-index: 2; padding: 2px 4px; border-radius: 9px; background: var(--surface-strong); border: 1px solid var(--gold-line); box-shadow: var(--shadow); }
.tile.drop-at { box-shadow: -3px 0 0 var(--gold), var(--shadow); }
.tile-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.tile-head h3 { font-size: 1.08rem; }
.dthumb { aspect-ratio: 200 / 140; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: var(--surface-strong); }
.dthumb svg { display: block; width: 100%; height: 100%; }
.tile:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.tile .thumb { aspect-ratio: 1 / 1.25; border-radius: 12px; background: var(--surface-strong); border: 1px solid var(--line); overflow: hidden; display: grid; place-items: center; }
.tile .thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.tile .meta { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 99px; font-size: 0.8rem; background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.chip.gold { background: var(--gold-soft); color: var(--gold); }
.chip.gray { background: var(--line); color: var(--ink-2); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.empty { text-align: center; padding: 56px 24px; display: grid; gap: 14px; justify-items: center; }
.empty .art { width: 150px; }

/* ---------- ขั้นตอน ---------- */
.steps { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; counter-reset: s; }
.steps span { counter-increment: s; display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px 6px 8px; border-radius: 99px; background: var(--surface); border: 1px solid var(--line); color: var(--ink-3); font-size: 0.9rem; }
.steps span::before { content: counter(s); width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--line); font-size: 0.8rem; font-weight: 600; }
.steps span.on { color: var(--ink); border-color: var(--accent); }
.steps span.on::before { background: var(--accent); color: var(--accent-ink); }
.steps span.done::before { content: "✓"; background: var(--accent-soft); color: var(--accent); }

/* ---------- พื้นที่วางไฟล์ ---------- */
.drop { border: 1.5px dashed var(--line-strong); border-radius: 16px; padding: 28px 20px; text-align: center; display: grid; gap: 10px; justify-items: center; cursor: pointer; transition: border-color .2s, background .2s; background: var(--surface); }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .ic { width: 30px; height: 30px; color: var(--accent); }
.drop.compact { padding: 16px; grid-auto-flow: column; justify-content: start; text-align: left; }
.drop.compact .ic { width: 24px; height: 24px; }
.drop input { display: none; }

/* ---------- หน้าแบบฟอร์ม + ช่อง ---------- */
.pagebar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.pagebar .sp { flex: 1; }
.sheet { position: relative; background: #fff; border-radius: 6px; box-shadow: var(--shadow-lg); overflow: hidden; user-select: none; touch-action: none; }
.sheet img, .sheet canvas { display: block; width: 100%; height: auto; }
.sheet.adding { cursor: crosshair; }
.box {
  position: absolute; border: 1.5px solid var(--box); background: var(--box-bg); border-radius: 3px;
  cursor: move; display: flex; align-items: flex-start;
}
.box .n { position: absolute; left: -1px; top: -18px; font: 600 11px/16px var(--font-body); padding: 0 5px; border-radius: 4px 4px 0 0; background: var(--box); color: var(--accent-ink); white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.box.sel { border-color: #c9a23e; background: rgba(201,162,62,.2); z-index: 2; }
.box.sel .n { background: #c9a23e; color: #2a1230; }
.box .h { position: absolute; right: -6px; bottom: -6px; width: 12px; height: 12px; border-radius: 3px; background: #c9a23e; cursor: nwse-resize; display: none; }
.box.sel .h { display: block; }
.box.unbound { border-style: dashed; }
.draft { position: absolute; border: 1.5px dashed #c9a23e; background: rgba(201,162,62,.15); pointer-events: none; }

.flist { display: grid; gap: 8px; max-height: 62vh; overflow: auto; padding-right: 4px; }
.fitem { display: grid; grid-template-columns: 30px 1fr auto; gap: 8px; align-items: start; padding: 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-strong); }
.fitem.sel { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.fitem .no { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-size: .8rem; font-weight: 600; }
.fitem .body { display: grid; gap: 6px; min-width: 0; }
.fitem .ctx { font-size: .8rem; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fitem input, .fitem select { padding: 7px 10px; font-size: .92rem; }
.fitem .x { border: 0; background: transparent; color: var(--ink-3); cursor: pointer; padding: 4px; border-radius: 8px; }
.fitem .x:hover { color: var(--danger); background: var(--danger-soft); }
.fitem textarea { min-height: 64px; padding: 7px 10px; font-size: .9rem; }
.fitem label.small { display: grid; gap: 4px; color: var(--ink-3); }
.fitem .opts summary { cursor: pointer; color: var(--ink-3); }
.fitem .opts textarea { margin-top: 6px; width: 100%; }
.seg { display: inline-flex; width: max-content; border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 4px 10px; font-size: .8rem; color: var(--ink-3); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.srcrow { display: grid; grid-template-columns: 1fr 1.2fr auto auto; gap: 8px; align-items: center; border-radius: 10px; }
@media (max-width: 560px) { .srcrow { grid-template-columns: 1fr; } }

/* ---------- หน้ากรอก ---------- */
.srccard { padding: 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface-strong); display: grid; gap: 10px; }
.srccard .top { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.srccard.done { border-color: rgba(63,125,79,.4); }
.status { font-size: .88rem; color: var(--ink-2); display: flex; gap: 8px; align-items: center; }
.status.ok { color: var(--ok); }
.status.err { color: var(--danger); }
.spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--accent); animation: rot .8s linear infinite; flex: none; }
@keyframes rot { to { transform: rotate(360deg); } }
.vals { display: grid; gap: 10px; }
.val { display: grid; grid-template-columns: minmax(120px, 0.9fr) 1.4fr; gap: 10px; align-items: center; }
.val .lab { font-size: .9rem; color: var(--ink-2); line-height: 1.35; }
.val .lab small { display: block; color: var(--ink-3); font-size: .76rem; }
.val input.empty, .val select.empty { border-color: var(--gold); background: var(--gold-soft); }
@media (max-width: 560px) { .val { grid-template-columns: 1fr; gap: 4px; } }
.fontbar { display: grid; grid-template-columns: 1.6fr 0.7fr auto; gap: 10px; align-items: end; }
.preview { display: grid; gap: 14px; }
.preview canvas { width: 100%; height: auto; background: #fff; border-radius: 6px; box-shadow: var(--shadow-lg); display: block; }

hr.sep { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: .92rem; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }
.meter { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--gold)); border-radius: inherit; }

/* ---------- toast + skeleton ---------- */
.toasts { position: fixed; z-index: 50; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; width: min(520px, calc(100% - 32px)); }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px; border-radius: 14px; background: var(--surface-strong); border: 1px solid var(--line); box-shadow: var(--shadow-lg); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); animation: up .35s var(--ease); }
.toast.err .ic { color: var(--danger); }
.toast.ok .ic { color: var(--ok); }
@keyframes up { from { opacity: 0; transform: translateY(10px); } }
.skeleton { display: grid; gap: 12px; }
.skeleton span { height: 16px; border-radius: 8px; background: linear-gradient(90deg, var(--line), var(--line-strong), var(--line)); background-size: 200% 100%; animation: shine 1.4s linear infinite; }
.skeleton span:nth-child(2) { width: 80%; } .skeleton span:nth-child(3) { width: 55%; }
@keyframes shine { to { background-position: -200% 0; } }
.reveal { animation: rise .6s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

.modal-back { position: fixed; inset: 0; z-index: 40; background: rgba(17,21,42,.42); display: grid; place-items: center; padding: 16px; animation: fade .2s; }
.modal { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 26px; border-radius: var(--r-modal); background: var(--surface-strong); box-shadow: var(--shadow-lg); display: grid; gap: 14px; }
@keyframes fade { from { opacity: 0; } }

@media (max-width: 720px) {
  .nav { flex-wrap: wrap; gap: 6px; }
  .links { order: 3; flex: 1 1 100%; overflow-x: auto; }
  .links a { white-space: nowrap; }
  .links { scrollbar-width: none; }
  .links::-webkit-scrollbar { display: none; }
  .tools { margin-left: auto; }
  .brand .ver { display: none; }
  .card { padding: 18px; }
  main { padding-top: 22px; }
  .fontbar { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- สลับลำดับ ---------- */
.side { display: grid; gap: 4px; justify-items: center; align-content: start; }
.mv { display: grid; gap: 2px; justify-items: center; }
.mv.h { grid-auto-flow: column; align-items: center; }
.mv button { border: 0; background: transparent; color: var(--ink-3); width: 26px; height: 22px; display: grid; place-items: center; border-radius: 6px; cursor: pointer; padding: 0; }
.mv button .ic { width: 16px; height: 16px; }
.mv button:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent); }
.mv button:disabled { opacity: .25; cursor: default; }
.grip { color: var(--ink-3); cursor: grab; display: grid; place-items: center; width: 26px; height: 20px; border-radius: 6px; touch-action: none; }
.grip:hover { color: var(--gold); background: var(--gold-soft); }
.grip .ic { width: 16px; height: 16px; }
[data-idx].dragging { opacity: .45; }
[data-idx].drop-at { box-shadow: 0 -3px 0 var(--gold); }

/* ---------- แถบหน้าของแบบฟอร์ม ---------- */
.pages { display: flex; gap: 10px; overflow-x: auto; padding: 4px 2px 10px; margin-bottom: 6px; align-items: flex-start; }
.pages.busy { opacity: .55; pointer-events: none; }
.pg { flex: none; width: 92px; display: grid; gap: 4px; justify-items: center; padding: 6px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
.pg.on { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.pg.drop-at { box-shadow: -3px 0 0 var(--gold); }
.pgthumb { border: 0; padding: 0; background: #fff; border-radius: 4px; cursor: pointer; width: 78px; overflow: hidden; box-shadow: var(--shadow); }
.pgthumb canvas { display: block; width: 100%; height: auto; }
.pgfoot { display: flex; align-items: center; justify-content: space-between; width: 100%; gap: 4px; color: var(--ink-3); }
.pgfoot .x { border: 0; background: transparent; color: var(--ink-3); cursor: pointer; padding: 2px; border-radius: 6px; }
.pgfoot .x .ic { width: 16px; height: 16px; }
.pgfoot .x:hover { color: var(--danger); background: var(--danger-soft); }
.pgadd { flex: none; width: 92px; min-height: 120px; display: grid; place-items: center; align-content: center; gap: 4px; border: 1.5px dashed var(--line-strong); border-radius: 12px; cursor: pointer; color: var(--ink-3); font-weight: 500; }
.pgadd:hover { border-color: var(--gold); color: var(--gold); background: var(--gold-soft); }
.pgadd input { display: none; }

/* ---------- ลวดลายไทย (สไปรต์ใน index.html) ---------- */
.corner { position: absolute; width: 22px; height: 22px; color: var(--orn-deep); opacity: .9; z-index: 2; pointer-events: none; }
.corner.tl { top: 11px; left: 11px; } .corner.tr { top: 11px; right: 11px; transform: scaleX(-1); }
.corner.bl { bottom: 11px; left: 11px; transform: scaleY(-1); } .corner.br { bottom: 11px; right: 11px; transform: scale(-1); }
.seal { width: 64px; height: 64px; color: var(--orn-deep); display: block; margin: 0 auto; }
.rule { display: flex; align-items: center; gap: 12px; margin: 6px 0 2px; }
.rule::before, .rule::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, transparent, var(--gold-line), transparent); }
.rule span { font: 500 .88rem var(--font-head); color: var(--red); letter-spacing: .06em; display: flex; align-items: center; gap: 10px; }
.rule span::before, .rule span::after { content: "◆"; font-size: 7px; color: var(--orn-deep); }
.modal::after { content: ""; position: absolute; inset: 7px; border: 1px solid var(--gold-line); border-radius: calc(var(--r-modal) - 7px); pointer-events: none; opacity: .7; }
label.drop, label.check { font-family: var(--font-body); }

/* ================= V1.7 ================= */
.modal { position: relative; }
.modal > * { position: relative; z-index: 1; }
.mclose { position: absolute !important; top: 14px; right: 14px; z-index: 3 !important; }
.sec { margin: 30px 0 12px; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.sec .eyebrow { font-size: 1rem; }
.sec-sub { margin: -6px 0 14px; }
.chip .ic { width: 14px; height: 14px; }
.chip.red { background: var(--danger-soft); color: var(--danger); }
.chip.warn { background: var(--gold-soft); color: var(--gold); border: 1px solid var(--gold-line); }
.chip.uses { background: linear-gradient(180deg, rgba(246,220,140,.35), rgba(226,185,69,.22)); color: var(--gold); border: 1px solid var(--gold-line); }
.reject-note { color: var(--danger); display: flex; gap: 6px; align-items: flex-start; }
.reject-note .ic { width: 15px; height: 15px; margin-top: 3px; flex: none; }
.btn.text { background: transparent; border-color: transparent; box-shadow: none; color: var(--accent); padding-inline: 8px; }
.btn.text:hover { background: var(--accent-soft); }
.danger-t { color: var(--danger) !important; }
.row.nowrap { flex-wrap: nowrap; align-items: center; }
.ic.big { width: 40px; height: 40px; color: var(--gold); }

/* แถบเมนู: ปุ่มบัญชี / ลงชื่อเข้าใช้ */
.accbtn { display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px 0 4px; border-radius: 99px; border: 1px solid rgba(239,203,87,.35); background: rgba(251,239,216,.06); color: #fbefd8; cursor: pointer; font: 500 .92rem var(--font-head); max-width: 210px; }
.accbtn:hover { background: rgba(251,239,216,.14); border-color: #efcb57; }
.accbtn.guest { padding: 0 14px; background: linear-gradient(180deg, #f6dc8c, #e2b945); color: #3a2a10; border-color: #c9a23e; }
.accbtn .ic { width: 18px; height: 18px; }
.accname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; display: inline-grid; place-items: center; background: linear-gradient(135deg, #f6dc8c, #c9a23e); color: #3a173e; font: 700 .9rem var(--font-head); flex: none; box-shadow: 0 0 0 2px rgba(239,203,87,.5); }
.avatar.xl { width: 96px; height: 96px; font-size: 2.2rem; box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--orn-deep); }
@media (max-width: 720px) { .accname { display: none; } .accbtn { padding: 0 4px; } .accbtn.guest span { display: none; } .accbtn.guest { padding: 0 10px; } }

/* หน้าต่างลงชื่อ */
.authm { width: min(460px, 100%); padding: 30px; }
.authm .head { text-align: center; display: grid; gap: 6px; justify-items: center; padding: 6px 0 4px; }
.mark.big { width: 54px; height: 54px; color: var(--orn-deep); }
.formerr { color: var(--danger); background: var(--danger-soft); border-radius: 10px; padding: 8px 12px; font-size: .9rem; margin: 0; }
.pwbox { position: relative; display: block; }
.pwbox input { padding-right: 44px; }
.eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; display: grid; place-items: center; border: 0; background: transparent; color: var(--ink-3); cursor: pointer; border-radius: 8px; }
.eye:hover { color: var(--ink); background: var(--accent-soft); }
.eye .ic { width: 18px; height: 18px; }
.pwwarn { color: var(--gold); font: 500 .82rem var(--font-body); }
input.otp { font: 600 1.6rem/1 var(--font-body); letter-spacing: .5em; text-align: center; padding: 12px; }
.guest-card { text-align: center; justify-items: center; padding: 40px 24px; }
.tabs.wide { display: inline-grid; grid-template-columns: auto auto; margin: 6px 0 4px; }
.tabs a { font-family: var(--font-head); text-decoration: none; padding: 8px 16px; border-radius: 9px; color: var(--ink-2); font-weight: 500; }
.tabs a.on { background: var(--surface-strong); color: var(--ink); box-shadow: var(--shadow); }

/* ขยายภาพ */
.zoomable { cursor: zoom-in; }
.sheetwrap { position: relative; }
.zoom-btn { position: absolute; top: 10px; right: 10px; z-index: 4; display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 99px; border: 1px solid rgba(239,203,87,.5); font: 500 .85rem var(--font-head); color: #fbefd8; background: rgba(42,18,48,.82); backdrop-filter: blur(6px); cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,.2); opacity: .9; }
.zoom-btn:hover { opacity: 1; }
.zoom-btn .ic { width: 15px; height: 15px; }
.preview canvas { cursor: zoom-in; transition: box-shadow .2s; }
.preview canvas:hover { box-shadow: 0 0 0 3px var(--gold-soft), var(--shadow-lg); }
.lightbox { position: fixed; inset: 0; z-index: 90; background: rgba(20, 10, 22, .9); backdrop-filter: blur(6px); display: flex; flex-direction: column; animation: fade .2s both; }
.lb-bar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; color: #e9dcc2; font-size: .85rem; flex-wrap: wrap; }
.lb-title { font: 600 1rem var(--font-head); color: #f1d991; margin-right: 8px; }
.lb-hint { flex: 1; opacity: .7; }
.lb-num { min-width: 44px; text-align: center; }
.lb-btn { min-width: 36px; height: 36px; padding: 0 10px; display: inline-grid; place-items: center; border: 0; border-radius: 10px; background: rgba(255,255,255,.1); color: #fbefd8; cursor: pointer; font-size: 1rem; }
.lb-btn:hover:not(:disabled) { background: rgba(255,255,255,.22); }
.lb-btn:disabled { opacity: .3; cursor: default; }
.lb-btn .ic { width: 18px; height: 18px; }
.lb-stage { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; overflow: hidden; padding: 0 20px 20px; touch-action: none; }
.lb-stage img { max-width: calc(100vw - 40px); max-height: calc(100vh - 86px); object-fit: contain; background: #fff; border-radius: 6px; box-shadow: 0 20px 60px rgba(0,0,0,.45); cursor: grab; transform-origin: center; transition: transform .06s; user-select: none; }
.lb-stage img.grab { cursor: grabbing; transition: none; }
.lb-stage .spin { position: absolute; }
@media (max-width: 720px) { .lb-hint { display: none; } }

/* ลากเรียง: เส้นทองบอกตำแหน่งที่จะวาง */
[data-idx].drop-before { box-shadow: 0 -3px 0 var(--orn-deep), var(--shadow); }
[data-idx].drop-after { box-shadow: 0 3px 0 var(--orn-deep), var(--shadow); }
.grid > [data-idx].drop-before, .pages > [data-idx].drop-before { box-shadow: -4px 0 0 var(--orn-deep), var(--shadow); }
.grid > [data-idx].drop-after, .pages > [data-idx].drop-after { box-shadow: 4px 0 0 var(--orn-deep), var(--shadow); }
.fitem .no.grip { width: 26px; height: 26px; cursor: grab; color: var(--accent); background: var(--accent-soft); font-size: .8rem; font-weight: 600; transition: background .2s, color .2s; }
.fitem .no.grip:hover { background: var(--gold-soft); color: var(--gold); }
.fitem .no.grip:active { cursor: grabbing; }
.sorting .fitem input, .sorting .fitem textarea, .sorting .fitem select { pointer-events: none; }

/* กำกับข้อมูล + คำที่เป็นไปได้ */
.guide { display: grid; gap: 6px; }
.mini { display: grid; grid-template-columns: 96px 1fr; align-items: center; gap: 8px; font-size: .8rem; font-weight: 600; color: var(--ink-3); }
.mini > span:first-child { display: flex; flex-direction: column; line-height: 1.25; }
.mini small { font-weight: 400; color: var(--gold); font-size: .74rem; }
.mini input, .mini textarea { font-size: .88rem; padding: 6px 10px; min-height: 34px; }
.mini textarea { resize: vertical; line-height: 1.45; }
.mini .row { gap: 6px; }
@media (max-width: 560px) { .mini { grid-template-columns: 1fr; gap: 3px; } }
.tryval { font-size: .85rem; padding: 4px 10px; border-radius: 8px; background: rgba(61,107,58,.08); color: var(--ok); white-space: pre-wrap; }
.tryval.warn { background: var(--gold-soft); color: var(--gold); }

/* ประเภทเอกสาร: ภาพประกอบด้านบน */
.art-banner { display: grid; grid-template-columns: minmax(180px, 300px) 1fr; gap: 22px; align-items: center; margin-bottom: 18px; }
.dthumb.big { box-shadow: var(--shadow); }
@media (max-width: 640px) { .art-banner { grid-template-columns: 1fr; } }
.sample { display: grid; grid-template-columns: 88px 1fr; gap: 14px; align-items: start; padding: 12px; border-radius: 14px; border: 1px solid var(--gold-line); background: var(--gold-soft); }
.sthumb { position: relative; width: 88px; aspect-ratio: 3 / 4; border-radius: 8px; overflow: hidden; background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow); display: grid; place-items: center; flex: none; }
.sthumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.pgcount { position: absolute; bottom: 4px; right: 4px; font-size: .7rem; padding: 1px 6px; border-radius: 99px; background: rgba(42,18,48,.8); color: #fbefd8; }

/* หน้ากรอก: ช่องที่ต้องตรวจ */
.srcbody { display: flex; gap: 12px; align-items: flex-start; }
.val .ctl { display: grid; gap: 3px; min-width: 0; }
.val input.warn, .val select.warn { border-color: var(--orn-deep); background: #fff6d8; box-shadow: 0 0 0 3px var(--gold-soft); }
[data-theme="dark"] .val input.warn, [data-theme="dark"] .val select.warn { background: rgba(239,203,87,.16); }
.flagnote { color: var(--gold); font-size: .78rem; display: flex; gap: 5px; align-items: center; }
.flagnote .ic { width: 14px; height: 14px; }

/* หน้าแรก / ห้องแบ่งปัน */
.share-cta { margin-top: 30px; display: grid; grid-template-columns: auto 1fr auto; gap: 18px; align-items: center; }
@media (max-width: 640px) { .share-cta { grid-template-columns: 1fr; text-align: center; justify-items: center; } }
.searchbar { margin-bottom: 16px; max-width: 520px; }
.tablewrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.t th { text-align: left; font: 600 .82rem var(--font-head); color: var(--ink-3); padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.t td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t td.num { font-variant-numeric: tabular-nums; }
.picklist { display: grid; gap: 8px; max-height: 60vh; overflow: auto; }
.pick { display: grid; grid-template-columns: 52px 1fr; gap: 12px; align-items: center; padding: 8px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-align: left; color: var(--ink); }
.pick:hover { border-color: var(--gold); background: var(--gold-soft); }
.pick img, .pick > .ic { width: 52px; height: 64px; object-fit: cover; object-position: top; border-radius: 6px; background: #fff; }
.pick span { display: grid; gap: 2px; }
.pick b { font-family: var(--font-head); }

/* บัญชี */
.avatar-edit { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: center; }
.avatar-btn { position: relative; border: 0; padding: 0; background: transparent; cursor: pointer; border-radius: 50%; }
.avcam { position: absolute; right: 0; bottom: 0; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow); }
.avcam .ic { width: 15px; height: 15px; }

/* แนะนำทีมงาน */
.letter { position: relative; }
.letter textarea { min-height: 180px; background-image: repeating-linear-gradient(transparent, transparent 31px, var(--line) 31px, var(--line) 32px); line-height: 32px; }

/* ผู้ดูแล */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { padding: 16px; border-radius: 16px; display: grid; gap: 2px; }
.stat b { font: 700 1.8rem/1.1 var(--font-head); color: var(--accent); }
.stat span { color: var(--ink-3); font-size: .85rem; }
.admin-item.pending { box-shadow: 0 0 0 2px var(--gold-line), var(--shadow); }
.note-box { display: flex; gap: 6px; padding: 8px 10px; border-radius: 10px; background: var(--accent-soft); }
.note-box .ic { width: 15px; height: 15px; flex: none; margin-top: 3px; }
.msg { display: grid; gap: 8px; }
.msg.read { opacity: .72; }
.msgtext { white-space: pre-wrap; line-height: 1.7; }
aside .mini { grid-template-columns: 1fr; gap: 3px; }
aside .mini > span:first-child { flex-direction: row; gap: 6px; align-items: baseline; }

/* ห้องแบ่งปัน: ประเภทเอกสาร */
.modal.wide { width: min(820px, 100%); }
.tabs.wide.three { grid-template-columns: auto auto auto; }
.tile .labels { display: flex; flex-wrap: wrap; gap: 6px; }
