/* LaiSen Studio · สีหลักตามชุดเล่ม Xtraseal (แดง #c1121f) พื้นเทาอมแดงอ่อน */
@font-face { font-family: "Sarabun"; src: local("Sarabun"), local("Sarabun Regular"); }
:root {
  --bg: #f6f4f4; --surface: #ffffff; --surface-2: #faf8f8; --line: #e6e0e0; --line-2: #d6cfcf;
  --fg: #1d1a1a; --fg-2: #5c5454; --fg-3: #8a8181;
  --accent: #c1121f; --accent-2: #9d0e19; --accent-soft: #fdecee;
  --ok: #1f7a3d; --ok-soft: #e7f4ec; --warn: #9a6a00; --warn-soft: #fff6dc; --bad: #b3261e; --bad-soft: #fdeceb;
  --shadow: 0 1px 2px rgba(40, 10, 10, .06), 0 4px 16px rgba(40, 10, 10, .06);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171415; --surface: #201c1d; --surface-2: #262122; --line: #352e2f; --line-2: #463d3e;
    --fg: #f1ecec; --fg-2: #bdb3b3; --fg-3: #8e8484;
    --accent: #e5484d; --accent-2: #ff6b6f; --accent-soft: #3a1c1f;
    --ok: #4cc27a; --ok-soft: #173023; --warn: #e2b34a; --warn-soft: #33290f; --bad: #ff6b62; --bad-soft: #3a1a18;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.55 "Sarabun", "Noto Sans Thai", "Leelawadee UI", Tahoma, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0; text-wrap: balance; }
h2 { font-size: 17px; margin: 0 0 10px; }
[hidden] { display: none !important; }

button { background: var(--surface); border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
button:hover { border-color: var(--fg-3); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-2); }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--surface-2); }
button.mini { padding: 0 7px; line-height: 20px; font-size: 14px; border-radius: 6px; }
button.big { padding: 10px; font-size: 16px; }
button:disabled { opacity: .5; cursor: default; }
.danger-text { color: var(--bad); }
input, select, textarea { background: var(--surface); border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 10px; width: 100%; }
textarea { resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
label { display: grid; gap: 4px; font-size: 14px; color: var(--fg-2); }
.sub { color: var(--fg-2); margin: 0; }
.err { color: var(--bad); min-height: 1.4em; margin: 0; }

.th-name { font-weight: 400; color: var(--fg-3); font-size: 15px; }
.brand-mark { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: .01em; }
.logo { width: 22px; height: 22px; border-radius: 6px; background:
  linear-gradient(var(--accent), var(--accent)) 2px 3px / 9px 6px no-repeat,
  linear-gradient(var(--accent), var(--accent)) 11px 13px / 9px 6px no-repeat,
  linear-gradient(var(--fg-2), var(--fg-2)) 6px 9px / 2px 7px no-repeat,
  linear-gradient(var(--fg-2), var(--fg-2)) 6px 14px / 6px 2px no-repeat, var(--accent-soft); }

/* ---------- เข้าสู่ระบบ ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow); }

/* ---------- หน้าแรก ---------- */
.home { height: 100%; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 16px; padding: 10px 18px; background: var(--surface); border-bottom: 1px solid var(--line); }
.search { flex: 1; max-width: 560px; }
.search input { border-radius: 20px; padding: 7px 16px; background: var(--surface-2); }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.user { display: flex; gap: 8px; align-items: center; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.layout { flex: 1; display: grid; grid-template-columns: 240px 1fr; min-height: 0; }
.side { border-right: 1px solid var(--line); background: var(--surface); padding: 12px 8px; overflow-y: auto; overflow-x: hidden; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.nav-group { display: grid; gap: 2px; }
.nav-group.bottom { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
.nav, .tree button.f { text-align: left; border: 0; background: none; padding: 6px 10px; border-radius: 7px; width: 100%; display: flex; gap: 6px; align-items: center; }
.nav:hover, .tree button.f:hover { background: var(--surface-2); }
.nav.on, .tree button.f.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; letter-spacing: .06em; color: var(--fg-3); padding: 12px 10px 4px; }
.tree { display: grid; gap: 1px; }
.tree .row { display: flex; align-items: center; min-width: 0; }
.tree button.f { min-width: 0; }
.tree button.f .fn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tree .tw { width: 18px; flex: none; border: 0; background: none; padding: 0; color: var(--fg-3); font-size: 11px; }
.tree .count, .nav .count { margin-left: auto; color: var(--fg-3); font-size: 12px; font-weight: 400; font-variant-numeric: tabular-nums; }
.tree .drop { outline: 2px dashed var(--accent); }
.tags { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 8px; }
.tag { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line-2); border-radius: 20px; padding: 1px 9px; font-size: 13px; background: var(--surface); }
.tag i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.tag.on { border-color: var(--accent); color: var(--accent); }

.main { overflow: auto; padding: 18px 24px 40px; min-width: 0; }
.main-head { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: end; margin-bottom: 14px; }
.crumbs { margin: 2px 0 0; color: var(--fg-3); font-size: 13px; }
.filters { display: flex; gap: 8px; }
.filters select { width: auto; }
.bulk { position: sticky; top: 0; z-index: 3; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 12px; box-shadow: var(--shadow); }
.bulk span { font-weight: 600; margin-right: 8px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.card { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; display: flex; flex-direction: column; transition: box-shadow .15s, border-color .15s; }
.card:hover { box-shadow: var(--shadow); border-color: var(--line-2); }
.card.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.thumb { aspect-ratio: 4 / 3; background: #fff; display: grid; place-items: center; border-bottom: 1px solid var(--line); overflow: hidden; }
.thumb img { width: 92%; height: 92%; object-fit: contain; }
.thumb .ph { color: #9a8f8f; font-size: 13px; }
.card .meta { padding: 9px 12px 11px; display: grid; gap: 3px; min-width: 0; }
.card .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .info { font-size: 12.5px; color: var(--fg-3); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.card .chk { position: absolute; top: 8px; left: 8px; width: 22px; height: 22px; accent-color: var(--accent); opacity: 0; }
.card:hover .chk, .card.sel .chk, .grid.selecting .chk { opacity: 1; }
.card .star { position: absolute; top: 6px; right: 40px; border: 0; background: rgba(255,255,255,.9); border-radius: 6px; padding: 0 6px; color: #b9a9a9; font-size: 16px; opacity: 0; }
.card .star.on { color: #d79b00; opacity: 1; }
.card:hover .star { opacity: 1; }
.card .more { position: absolute; top: 6px; right: 6px; border: 0; background: rgba(255,255,255,.9); border-radius: 6px; padding: 0 8px; font-weight: 700; color: #333; opacity: 0; }
.card:hover .more { opacity: 1; }
.pill { font-size: 11.5px; border-radius: 20px; padding: 0 8px; border: 1px solid var(--line-2); white-space: nowrap; }
.pill.draft { color: var(--fg-2); }
.pill.review { color: var(--warn); border-color: var(--warn); background: var(--warn-soft); }
.pill.approved { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
.empty { text-align: center; color: var(--fg-2); padding: 60px 20px; border: 1px dashed var(--line-2); border-radius: var(--radius); background: var(--surface); }
.empty h2 { margin-bottom: 6px; }
.section-title { font-size: 13px; letter-spacing: .06em; color: var(--fg-3); margin: 22px 0 10px; }

/* แม่แบบและหน้าสร้างภาพ */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.tpl { text-align: left; display: grid; gap: 4px; padding: 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); white-space: normal; }
.tpl:hover { border-color: var(--accent); }
.tpl b { font-size: 15px; }
.tpl span { font-size: 12.5px; color: var(--fg-2); }
.tpl .k { color: var(--accent); font-size: 12px; }

/* ตั้งค่า */
.settings { display: grid; gap: 18px; max-width: 980px; }
.box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.box h2 { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.sw { display: flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 8px; padding: 3px 4px 3px 3px; }
.sw input[type=color] { width: 28px; height: 26px; padding: 0; border: 0; background: none; }
.sw button { padding: 0 5px; border: 0; }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th, table.list td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list th { color: var(--fg-3); font-weight: 500; font-size: 12.5px; }
.table-wrap { overflow-x: auto; }
.secret { font-family: ui-monospace, Consolas, monospace; background: var(--surface-2); border: 1px solid var(--line-2); padding: 8px 10px; border-radius: 8px; user-select: all; }

/* ---------- ตัวแก้ไข ---------- */
.editor { height: 100%; display: flex; flex-direction: column; }
.etop { display: flex; align-items: center; gap: 10px; padding: 7px 12px; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.ename { flex: 1; min-width: 200px; display: flex; align-items: center; gap: 10px; }
.ename input { border-color: transparent; font-weight: 600; font-size: 16px; max-width: 420px; }
.ename input:hover { border-color: var(--line-2); }
.etop select { width: auto; }
.eacts { display: flex; gap: 6px; flex-wrap: wrap; }
.estate { font-size: 13px; color: var(--fg-3); white-space: nowrap; }
.estate.ok { color: var(--ok); } .estate.bad { color: var(--bad); }
.ebody { flex: 1; display: flex; min-height: 0; }
#frame { flex: 1; border: 0; background: #fff; }
.panel { width: 340px; border-left: 1px solid var(--line); background: var(--surface); overflow: auto; padding: 14px 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.issue { display: grid; grid-template-columns: 22px 1fr; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.issue i { font-style: normal; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.issue.ok i { background: var(--ok-soft); color: var(--ok); }
.issue.warn i { background: var(--warn-soft); color: var(--warn); }
.issue.bad i { background: var(--bad-soft); color: var(--bad); }
.issue.info i { background: var(--surface-2); color: var(--fg-3); }
.ver { display: grid; grid-template-columns: 64px 1fr; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.ver img, .ver .noimg { width: 64px; height: 48px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
.ver .vt { font-weight: 600; font-size: 14px; }
.ver .vm { font-size: 12.5px; color: var(--fg-3); }
.ver .va { display: flex; gap: 6px; margin-top: 4px; }
.ver .va button { font-size: 12.5px; padding: 2px 8px; }
.ver.cur { background: var(--accent-soft); margin: 0 -8px; padding: 10px 8px; border-radius: 8px; }

/* ---------- หน้าต่าง ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(20, 10, 10, .45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 14px; padding: 20px 22px; width: min(480px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 10px 40px rgba(0,0,0,.25); display: grid; gap: 12px; }
.modal.wide { width: min(1000px, 100%); }
.modal form { display: grid; gap: 12px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.menu { position: fixed; z-index: 60; background: var(--surface); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: var(--shadow); padding: 4px; min-width: 190px; display: grid; }
.menu button { border: 0; text-align: left; background: none; border-radius: 6px; padding: 7px 12px; }
.menu button:hover { background: var(--surface-2); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #2a2223; color: #fff; padding: 9px 18px; border-radius: 8px; z-index: 80; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.toast.bad { background: var(--bad); }

/* ตัวอย่างรูปจริง */
.pv .tabs { display: flex; gap: 6px; }
.pv .tabs button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.facts { font-size: 14px; color: var(--fg-2); }
.facts .ok { color: var(--ok); font-weight: 700; } .facts .bad { color: var(--bad); font-weight: 700; }
.paper { background: #8f8787; padding: 18px; border-radius: 8px; overflow: auto; max-height: 62vh; }
.sheet { background: #fff; width: 21.59cm; min-height: 12cm; margin: 0 auto; padding: 1.5cm 2.5cm 1.5cm 3.2cm; box-shadow: 0 2px 10px rgba(0,0,0,.3); text-align: center; color: #111; }
.sheet .cap { font-family: "TH SarabunPSK", "Sarabun", serif; font-size: 16pt; margin-top: 6px; }
.choice { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.choice button { padding: 12px; text-align: left; display: grid; gap: 2px; white-space: normal; }
.choice button span { font-size: 12.5px; color: var(--fg-2); }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); max-height: 40vh; }
  .top { flex-wrap: wrap; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .main { padding: 14px 16px 30px; }
  .panel { position: absolute; right: 0; top: 0; bottom: 0; width: min(340px, 100%); box-shadow: var(--shadow); }
  .ebody { position: relative; }
  .card .star, .card .more, .card .chk { opacity: 1; }
}
