@font-face { font-family: 'Sarabun'; font-weight: 400; font-style: normal; font-display: swap; src: url('/fonts/sarabun-thai-400-normal.woff2') format('woff2'); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Sarabun'; font-weight: 400; font-style: normal; font-display: swap; src: url('/fonts/sarabun-latin-400-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Sarabun'; font-weight: 500; font-style: normal; font-display: swap; src: url('/fonts/sarabun-thai-500-normal.woff2') format('woff2'); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Sarabun'; font-weight: 500; font-style: normal; font-display: swap; src: url('/fonts/sarabun-latin-500-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Sarabun'; font-weight: 600; font-style: normal; font-display: swap; src: url('/fonts/sarabun-thai-600-normal.woff2') format('woff2'); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Sarabun'; font-weight: 600; font-style: normal; font-display: swap; src: url('/fonts/sarabun-latin-600-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Sarabun'; font-weight: 700; font-style: normal; font-display: swap; src: url('/fonts/sarabun-thai-700-normal.woff2') format('woff2'); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Sarabun'; font-weight: 700; font-style: normal; font-display: swap; src: url('/fonts/sarabun-latin-700-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
:root {
  --brand: #4a302a;        /* น้ำตาลเข้ม (แถบเมนู หัวตาราง ปุ่มหลัก) */
  --brand-dark: #38231e;
  --brand-soft: #efe5d6;   /* ครีมเข้ม (แถบสลับสี ป้าย) */
  --accent: #dfe8ef;       /* เมนูที่เลือก */
  --ink: #2b211e;
  --muted: #7a6a63;
  --line: #e7dccb;
  --bg: #f4efe6;
  --card: #fffdf9;
  --stripe: #f8f1e5;
  --warn-bg: #fdf1dc;
  --warn-line: #efcf94;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --ok: #2d6a4f;
  --radius: 14px;
  --tap: 48px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: 'Sarabun', 'Leelawadee UI', 'Tahoma', system-ui, sans-serif;
  font-size: 17px; line-height: 1.5; color: var(--ink); background: var(--bg);
}
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; color: var(--brand); }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.hidden { display: none !important; }
.spacer { flex: 1; }

/* โครงหน้า: แถบเมนูซ้ายสีน้ำตาล + เนื้อหา */
.appshell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--brand); color: #fff; padding: 14px 12px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brandbox {
  background: rgba(255,255,255,.1); border-radius: 12px; padding: 12px; margin-bottom: 10px; text-align: center;
  font-weight: 800; font-size: 1.3rem; letter-spacing: .05em; color: #fff; text-decoration: none; display: block;
}
.sidebar .brandbox img { max-height: 38px; max-width: 100%; vertical-align: middle; }
.sidebar .brandbox small { display: block; font-size: .72rem; font-weight: 400; letter-spacing: 0; opacity: .8; }
.sidebar .group { font-weight: 700; padding: 12px 10px 4px; font-size: 1.02rem; }
.sidebar a.item, .sidebar button.item {
  display: block; width: 100%; text-align: left; padding: 9px 14px 9px 22px; border-radius: 999px; color: #fff; text-decoration: none;
  background: transparent; border: 0; font: inherit; cursor: pointer;
}
.sidebar a.item:hover, .sidebar button.item:hover { background: rgba(255,255,255,.14); }
.sidebar a.item.active { background: var(--accent); color: var(--brand); font-weight: 700; }
.sidebar .bottom { margin-top: auto; padding-top: 12px; display: grid; gap: 8px; }
.sidebar .who { font-size: .82rem; opacity: .85; padding: 0 10px; word-break: break-all; }
.langbtn {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 44px;
  border: 1.5px solid rgba(255,255,255,.7); background: transparent; color: #fff; border-radius: 10px; cursor: pointer; font: inherit; font-weight: 600;
}
.langbtn:hover { background: rgba(255,255,255,.14); }
.langbtn svg { border-radius: 3px; box-shadow: 0 0 0 1px rgba(0,0,0,.25); }
.content { padding: 20px 24px; min-width: 0; }
.content.narrow { max-width: 460px; margin: 0 auto; width: 100%; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--brand); color: #fff; }
.topbar .brandbox { color: #fff; font-weight: 800; letter-spacing: .05em; text-decoration: none; }
.topbar .langbtn { width: auto; padding: 0 14px; }
.authwrap { max-width: 460px; margin: 0 auto; padding: 16px; }

@media (max-width: 860px) {
  .appshell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px; }
  .sidebar .brandbox { margin: 0; padding: 6px 12px; font-size: 1.05rem; }
  .sidebar .brandbox small, .sidebar .group, .sidebar .who { display: none; }
  .sidebar a.item, .sidebar button.item { width: auto; padding: 8px 14px; }
  .sidebar .bottom { margin: 0 0 0 auto; padding: 0; display: flex; }
  .langbtn { min-height: 40px; padding: 0 12px; width: auto; }
  .content { padding: 14px; }
}

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: 0 1px 2px rgba(74,48,42,.05); }
.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* ฟอร์ม */
label { display: block; font-weight: 600; margin: 12px 0 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px; font: inherit; color: var(--ink);
  border: 1.5px solid var(--line); border-radius: 12px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(74,48,42,.22); border-color: var(--brand); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 400; min-height: var(--tap); }
.check input { width: 22px; height: 22px; accent-color: var(--brand); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap);
  padding: 10px 20px; border-radius: 12px; border: 1.5px solid var(--brand); background: var(--brand);
  color: #fff; font: inherit; font-weight: 700; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--brand-dark); }
.btn.secondary { background: #fff; color: var(--brand); }
.btn.secondary:hover { background: var(--brand-soft); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: .9rem; }
.btn.block { width: 100%; margin-top: 16px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }

.notice { padding: 12px 14px; border-radius: 12px; margin: 12px 0; border: 1px solid; }
.notice.error { background: var(--danger-bg); border-color: #f3b9b3; color: var(--danger); }
.notice.warn { background: var(--warn-bg); border-color: var(--warn-line); color: #7a4a05; }
.notice.ok { background: #e8f3ec; border-color: #b9d8c6; color: var(--ok); }
.secret {
  font-family: Consolas, 'Courier New', monospace; font-size: 1.35rem; font-weight: 700; letter-spacing: .06em;
  background: #1b1412; color: #ffe27a; padding: 14px; border-radius: 12px; text-align: center; word-break: break-all; margin: 8px 0;
}

.bignum { font-size: 3rem; font-weight: 800; color: var(--brand); line-height: 1; }
.stat-card { text-align: center; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

/* ตาราง: หัวสีน้ำตาลเข้ม แถวสลับครีม */
.table-wrap { overflow-x: auto; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); }
table { border-collapse: collapse; width: 100%; font-size: .95rem; }
th, td { padding: 11px 14px; text-align: left; vertical-align: middle; }
th { background: var(--brand); color: #fff; white-space: nowrap; font-weight: 700; }
tbody tr:nth-child(even) td { background: var(--stripe); }
tbody tr + tr td { border-top: 1px solid var(--line); }
tr.inactive td { color: var(--muted); }
td:last-child .row { flex-wrap: nowrap; }
td:last-child { white-space: nowrap; }
.badge { display: inline-block; padding: 2px 12px; border-radius: 99px; font-size: .8rem; font-weight: 700; background: #e3efe6; color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: #7a4a05; }
.badge.off { background: #ece7e1; color: #6d625c; }
.badge.example { background: #e5ecf6; color: #2b4a8a; }
.badge.err { background: #fbe3e1; color: var(--danger); }

dialog { border: 0; border-radius: 16px; padding: 20px; width: min(560px, 94vw); background: var(--card); color: var(--ink); box-shadow: 0 10px 40px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(30,18,14,.55); }
dialog h2 { margin-top: 0; }

.drop { border: 2px dashed var(--brand); border-radius: var(--radius); padding: 22px; text-align: center; background: var(--brand-soft); }
.steps { counter-reset: s; padding-left: 0; list-style: none; }
.steps li { counter-increment: s; padding: 4px 0 4px 36px; position: relative; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 4px; width: 26px; height: 26px; border-radius: 50%; background: var(--brand); color: #fff; text-align: center; font-weight: 700; font-size: .9rem; line-height: 26px; }
.path { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.path .chip { background: var(--brand-soft); border-radius: 8px; padding: 4px 10px; font-size: .9rem; }

/* ===== Memo ===== */
.memolist { display: grid; gap: 10px; }
.memorow { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; text-decoration: none; color: var(--ink); }
.memorow:hover { border-color: var(--brand); background: #fff; }
.memorow .top { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 4px; }
.memorow .docno, .docno { font-weight: 800; color: var(--brand); letter-spacing: .02em; }
.memorow .subject { font-weight: 600; font-size: 1.05rem; }
.badge.info { background: #e3ecf9; color: #254a86; }
.badge.ret { background: #ffe9d6; color: #8a4a05; }
.badge.task { background: var(--brand); color: #fff; }
.bignum.small { font-size: 2.2rem; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 12px; }
.tab { border: 1.5px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 16px; font: inherit; cursor: pointer; color: var(--ink); }
.tab.active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.tab .count { margin-left: 8px; background: rgba(0,0,0,.12); border-radius: 99px; padding: 0 8px; font-size: .85rem; }
.filterbar { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 8px; margin-bottom: 12px; align-items: center; }
@media (max-width: 760px) { .filterbar { grid-template-columns: 1fr 1fr; } .filterbar input:first-child { grid-column: 1 / -1; } }

.checkgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; }
.check.boxed { border: 1.5px solid var(--line); border-radius: 12px; padding: 0 12px; background: #fff; cursor: pointer; }
.check.inline { display: inline-flex; min-height: 32px; font-size: .9rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { background: var(--brand-soft); border-radius: 999px; padding: 4px 6px 4px 12px; display: inline-flex; align-items: center; gap: 6px; }
.chip button { border: 0; background: rgba(0,0,0,.12); width: 22px; height: 22px; border-radius: 50%; cursor: pointer; line-height: 1; }
.editor-wrap .editor { min-height: 260px; background: #fff; font-family: inherit; font-size: 1rem; }
.editor-wrap .ql-toolbar { background: var(--brand-soft); border-radius: 12px 12px 0 0; border-color: var(--line); }
.editor-wrap .ql-container { border-color: var(--line); border-radius: 0 0 12px 12px; font-family: inherit; }
.files .filerow { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.routelist { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 8px; }
.routestep { display: grid; grid-template-columns: 160px 1fr; gap: 8px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.routestep .lab { font-weight: 700; color: var(--brand); }
@media (max-width: 600px) { .routestep { grid-template-columns: 1fr; } }
.err-text { color: var(--danger); font-weight: 700; }
.actionbar { position: sticky; bottom: 0; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; background: rgba(244,239,230,.96); border-top: 1px solid var(--line); padding: 10px 0; margin-top: 8px; }

/* กระดาษ Memo */
.paper { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 24px; margin-bottom: 16px; box-shadow: 0 2px 8px rgba(74,48,42,.08); }
.paperhead { display: flex; align-items: center; gap: 12px; border-bottom: 3px solid var(--brand); padding-bottom: 8px; margin-bottom: 10px; }
.memotitle { font-size: 2rem; font-weight: 800; letter-spacing: .12em; color: var(--brand); }
.purposes { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-bottom: 10px; }
.purpose { white-space: nowrap; }
table.meta { width: 100%; margin-bottom: 12px; }
table.meta th { background: transparent; color: var(--muted); width: 120px; padding: 4px 8px 4px 0; position: static; font-weight: 600; }
table.meta td { padding: 4px 0; }
.memo-body { margin: 12px 0; }
.memo-body table { border-collapse: collapse; width: 100%; margin: 8px 0; }
.memo-body td, .memo-body th { border: 1px solid #9aa; padding: 6px 8px; font-size: .95rem; vertical-align: top; }
.memo-body th, .memo-body tr:first-child td[style*="background"] { background: #dbeaf6; color: var(--ink); position: static; }
.memo-body .ql-align-center { text-align: center; } .memo-body .ql-align-right { text-align: right; } .memo-body .ql-align-justify { text-align: justify; }
.memo-body h1, .memo-body h2, .memo-body h3 { color: var(--ink); }
.notebox { background: var(--stripe); padding: 8px 12px; border-radius: 8px; }
.closing { margin-top: 18px; }
.sigrow { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 18px; }
.sigbox { flex: 1 1 180px; max-width: 260px; border: 1px solid var(--line); border-radius: 8px; padding: 8px; text-align: center; background: #fff; }
.sigbox.pending { border-color: var(--brand); background: #fffaf0; }
.sigbox.waiting { opacity: .75; }
.sighead { font-weight: 700; color: var(--brand); margin-bottom: 4px; }
.sigimg { height: 70px; display: flex; align-items: center; justify-content: center; }
.sigimg img { max-height: 66px; max-width: 100%; }
.sigline { border-top: 2px dotted #777; margin: 2px 8px 4px; }
.signame { font-weight: 600; }
.sigproxy { font-size: .82rem; color: #7a4a05; background: var(--warn-bg); border-radius: 6px; padding: 2px 6px; margin: 4px 0; }
.taskcard { border-color: var(--brand); background: #fffaf0; }
.sigprev { background: repeating-conic-gradient(#f3f3f3 0% 25%, #fff 0% 50%) 50% / 16px 16px; border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: inline-block; min-width: 200px; text-align: center; margin: 8px 0; }
.sigprev img { max-height: 90px; max-width: 100%; }
canvas.sigpad { width: 100%; max-width: 700px; height: auto; aspect-ratio: 700 / 240; border: 2px dashed var(--brand); border-radius: 12px; background: #fff; touch-action: none; display: block; margin: 8px 0; }
.timeline ul { list-style: none; padding: 0; margin: 8px 0 0; }
.timeline li { padding: 6px 0; border-bottom: 1px dashed var(--line); }
.timeline .when { color: var(--muted); font-size: .88rem; }
.timeline summary { cursor: pointer; font-weight: 700; color: var(--brand); }
table.kv th { position: static; width: 140px; }
.authwrap.wide { max-width: 860px; }
.hashline { word-break: break-all; font-family: Consolas, monospace; }
dialog.wide { width: min(900px, 96vw); max-height: 92vh; overflow-y: auto; }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: var(--brand-soft) !important; }
.adminfilter { grid-template-columns: 2fr 1fr auto auto; }
.stepcard { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 8px 0; background: #fff; }
.stepextra { display: grid; gap: 8px; margin-top: 8px; }
.timelinelist { list-style: none; padding: 0; margin: 4px 0; }
.timelinelist li { padding: 4px 0; border-bottom: 1px dashed var(--line); font-size: .92rem; }
.card.inactive { opacity: .6; }