@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Thai:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
  --ink: #18242f;
  --ink-2: #44525e;
  --ink-3: #7a8691;
  --paper: #f5f4ef;
  --card: #ffffff;
  --line: #e2e0d8;
  --line-2: #ecebe5;
  --accent: #0d5f63;
  --accent-2: #0f7a7f;
  --accent-soft: #e3efee;
  --todo: #8a939b;   --todo-bg: #eef0f1;
  --doing: #a8650b;  --doing-bg: #fbf0dc;
  --done: #1d7a46;   --done-bg: #e2f2e8;
  --plan: #2f5ea8;   --plan-bg: #e5edf9;
  --danger: #b4372f; --danger-bg: #fbe7e5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(24, 36, 47, .05), 0 4px 16px rgba(24, 36, 47, .05);
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  padding-top: env(safe-area-inset-top, 0);
  font-family: 'IBM Plex Sans Thai', system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 20px;
  background: var(--ink); color: #fff;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: #fff; min-width: 0; }
.mark {
  flex: none; width: 36px; height: 36px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--accent-2); font-family: var(--mono); font-weight: 600; font-size: 14px; letter-spacing: .5px;
}
.brand-text { min-width: 0; }
.brand-text b { display: block; font-weight: 600; font-size: 15px; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text small { display: block; color: #a9b6c0; font-size: 12px; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topnav { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.topnav a, .topnav button {
  color: #d5dde3; text-decoration: none; background: none; border: 0; cursor: pointer;
  padding: 6px 10px; border-radius: 6px; font-size: 14px; white-space: nowrap;
}
.topnav a:hover, .topnav button:hover, .topnav a.on { background: rgba(255,255,255,.1); color: #fff; }
.who { font-size: 13px; color: #a9b6c0; padding-left: 8px; border-left: 1px solid rgba(255,255,255,.15); margin-left: 4px; white-space: nowrap; }
.who b { color: #fff; font-weight: 500; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 280px 1fr; min-height: calc(100vh - 56px); }
.side {
  border-right: 1px solid var(--line); background: #faf9f6;
  padding: 18px 12px 40px; position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto;
}
.side h4 { margin: 4px 10px 10px; font-size: 12px; font-weight: 600; letter-spacing: .4px; color: var(--ink-3); text-transform: uppercase; }
.side a {
  display: grid; grid-template-columns: 34px 1fr auto; gap: 6px; align-items: start;
  text-decoration: none; color: var(--ink-2); padding: 7px 10px; border-radius: 8px; font-size: 13.5px; line-height: 1.4;
}
.side a:hover { background: var(--line-2); color: var(--ink); }
.side a.on { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.side .sno { font-family: var(--mono); font-size: 12.5px; color: var(--ink-3); padding-top: 1px; }
.side a.on .sno { color: var(--accent); }
.side .cnt { font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); padding-top: 2px; white-space: nowrap; }
.side .cnt.full { color: var(--done); }
.side .parent { margin: 12px 10px 4px; font-size: 12.5px; color: var(--ink-3); font-weight: 500; }
.side .none { opacity: .55; }

main { padding: 28px 36px 120px; max-width: 1180px; width: 100%; min-width: 0; }

/* ---------- common ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid var(--line); background: var(--card); padding: 7px 14px; border-radius: 8px;
  cursor: pointer; font-size: 14px; text-decoration: none; color: var(--ink); white-space: nowrap;
}
.btn:hover { border-color: #cfccc2; background: #fbfaf7; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.mono { font-family: var(--mono); }
.muted { color: var(--ink-3); }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 99px;
  font-size: 12.5px; font-weight: 500; white-space: nowrap;
}
.pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-todo { color: var(--todo); background: var(--todo-bg); }
.st-doing { color: var(--doing); background: var(--doing-bg); }
.st-done { color: var(--done); background: var(--done-bg); }
.st-plan { color: var(--plan); background: var(--plan-bg); }
.mt { font-family: var(--mono); font-size: 12px; color: var(--ink-2); background: var(--line-2); padding: 1px 7px; border-radius: 5px; white-space: nowrap; }
.code { font-family: var(--mono); font-weight: 600; color: var(--accent); white-space: nowrap; }
.verdict { font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 5px; white-space: nowrap; }
.v-accept { background: var(--done-bg); color: var(--done); }
.v-more { background: var(--danger-bg); color: var(--danger); }
input[type=text], input[type=password], input[type=date], textarea, select {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 11px; background: #fff;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; min-height: 110px; line-height: 1.6; }
label.f { display: block; font-size: 13px; font-weight: 500; color: var(--ink-2); margin: 12px 0 5px; }

/* ---------- overview ---------- */
.hero { padding: 26px 28px; display: grid; grid-template-columns: 1fr 260px; gap: 28px; }
.eyebrow { font-size: 12.5px; font-weight: 600; color: var(--accent); letter-spacing: .3px; }
.hero h1 { font-size: 24px; line-height: 1.35; margin: 4px 0 10px; font-weight: 600; }
.hero dl { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; margin: 0; font-size: 14px; }
.hero dt { color: var(--ink-3); }
.hero dd { margin: 0; }
.countdown { border-left: 1px solid var(--line); padding-left: 26px; display: flex; flex-direction: column; justify-content: center; }
.countdown .big { font-size: 46px; font-weight: 600; line-height: 1; font-family: var(--mono); }
.countdown .big.late { color: var(--danger); }
.intro { margin-top: 18px; padding: 16px 20px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 8px 8px 0; white-space: pre-wrap; }

.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin: 18px 0; }
.stat { padding: 14px 16px; }
.stat .n { font-family: var(--mono); font-size: 26px; font-weight: 600; line-height: 1.2; }
.stat .l { font-size: 13px; color: var(--ink-2); }
.stat.s-done .n { color: var(--done); } .stat.s-doing .n { color: var(--doing); }
.stat.s-plan .n { color: var(--plan); } .stat.s-todo .n { color: var(--todo); }
.bar { height: 10px; border-radius: 99px; background: var(--line-2); overflow: hidden; display: flex; }
.bar span { display: block; height: 100%; }
.bar .b-done { background: var(--done); } .bar .b-plan { background: var(--plan); } .bar .b-doing { background: #e0a43c; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 26px 0 12px; }
.toolbar h2 { font-size: 18px; margin: 0 auto 0 0; font-weight: 600; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--card); padding: 4px 12px; border-radius: 99px; font-size: 13px; cursor: pointer; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.search { max-width: 240px; }

.sec { margin-top: 18px; overflow: hidden; }
.sec-h { display: flex; align-items: baseline; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); background: #fbfaf7; }
.sec-h .sno { font-family: var(--mono); font-weight: 600; color: var(--accent); }
.sec-h h3 { margin: 0; font-size: 15.5px; font-weight: 600; }
.sec-h .meta { margin-left: auto; font-size: 12.5px; color: var(--ink-3); white-space: nowrap; }
.sec-none { padding: 12px 18px; color: var(--ink-3); font-size: 14px; }
.row {
  display: grid; grid-template-columns: 74px 1fr 128px 70px; gap: 14px; align-items: center;
  padding: 12px 18px; border-top: 1px solid var(--line-2); text-decoration: none; color: inherit;
}
.row:first-of-type { border-top: 0; }
.row:hover { background: #fafaf7; }
.row .txt { font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row .txt .grp { color: var(--ink-3); font-size: 12.5px; display: block; }
.row .meta2 { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.row .files { font-size: 13px; color: var(--ink-3); text-align: right; white-space: nowrap; }
.row .files b { color: var(--ink); font-family: var(--mono); }
.grp-h { padding: 10px 18px 4px; font-size: 13px; color: var(--ink-2); border-top: 1px solid var(--line-2); background: #fcfcfa; }

.report-strip { display: flex; align-items: center; gap: 10px; padding: 14px 18px; margin-top: 14px; flex-wrap: wrap; }
.rs-ic { width: 40px; height: 46px; border-radius: 6px; background: #c0392b; color: #fff; display: grid; place-items: center; font-family: var(--mono); font-weight: 600; font-size: 12px; flex: none; }
.rs-t { margin-right: auto; display: flex; flex-direction: column; line-height: 1.4; min-width: 200px; }
.rs-t span { font-size: 13px; }
.rep-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 10px 0; border-top: 1px solid var(--line-2); font-size: 14px; }
.rep-row .muted { margin-right: auto; }

/* ---------- item page ---------- */
.crumb { font-size: 13px; color: var(--ink-3); margin-bottom: 10px; }
.crumb a { color: var(--ink-3); text-decoration: none; }
.crumb a:hover { color: var(--accent); }
.item-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.item-head .code { font-size: 22px; }
.rec { padding: 20px 24px; }
.rec .lbl { font-size: 12.5px; font-weight: 600; color: var(--ink-3); margin-bottom: 6px; letter-spacing: .3px; }
.rec .group { color: var(--ink-2); font-size: 14px; margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px dashed var(--line); }
.rec blockquote { margin: 0; font-size: 16.5px; line-height: 1.75; }
.blk { margin-top: 16px; padding: 20px 24px; }
.blk h3 { margin: 0 0 12px; font-size: 15.5px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.blk h3 .r { margin-left: auto; }
.action-text { white-space: pre-wrap; }
.kv { display: flex; gap: 4px 22px; flex-wrap: wrap; margin-top: 12px; font-size: 13.5px; color: var(--ink-2); }
.kv b { color: var(--ink); font-weight: 500; }
.empty { color: var(--ink-3); font-style: italic; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 14px; }

.evid { display: grid; grid-template-columns: 290px 1fr; gap: 16px; }
.flist { display: flex; flex-direction: column; gap: 6px; }
.fitem {
  display: grid; grid-template-columns: 34px 1fr; gap: 10px; align-items: center; text-align: left;
  border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 10px; cursor: pointer; width: 100%;
}
.fitem:hover { border-color: #cfccc2; }
.fitem.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.ficon { width: 34px; height: 40px; border-radius: 5px; display: grid; place-items: center; font-family: var(--mono); font-size: 10px; font-weight: 600; color: #fff; background: var(--ink-3); }
.ficon.pdf { background: #c0392b; } .ficon.img { background: #2f7d5b; } .ficon.doc { background: #2f5ea8; } .ficon.xls { background: #1d7a46; }
.fname { font-size: 13.5px; line-height: 1.35; word-break: break-word; }
.fname small { display: block; color: var(--ink-3); font-size: 12px; }
.fnum { font-family: var(--mono); color: var(--accent); font-weight: 600; margin-right: 4px; }
.viewer { border: 1px solid var(--line); border-radius: 8px; background: #3a3f44; min-height: 640px; display: flex; flex-direction: column; overflow: hidden; }
.viewer-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.viewer-bar .t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: auto; font-weight: 500; }
.viewer iframe { flex: 1; width: 100%; border: 0; background: #fff; min-height: 600px; }
.viewer .imgwrap { flex: 1; overflow: auto; display: grid; place-items: center; padding: 16px; }
.viewer img { max-width: 100%; height: auto; background: #fff; }
.viewer .nopre { flex: 1; display: grid; place-items: center; color: #e6e9ec; text-align: center; padding: 30px; }
.viewer .nopre p { max-width: 380px; }
.viewer.empty-v { min-height: 160px; background: #fbfaf7; border-style: dashed; }
.viewer.empty-v .nopre { color: var(--ink-3); }
.drop {
  border: 2px dashed #cfccc2; border-radius: 10px; padding: 18px; text-align: center; color: var(--ink-2);
  margin-top: 12px; cursor: pointer; background: #fcfcfa; font-size: 14px;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.prog { height: 6px; background: var(--line-2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.prog span { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.fadmin { display: flex; gap: 2px; margin-top: 4px; }

.verdicts { display: flex; gap: 8px; flex-wrap: wrap; }
.vbtn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 14px; cursor: pointer; font-size: 14px; }
.vbtn.on.accept { background: var(--done); border-color: var(--done); color: #fff; }
.vbtn.on.more { background: var(--danger); border-color: var(--danger); color: #fff; }
.comments { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.cm { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; background: #fcfcfa; }
.cm.cm-viewer { background: #fffaf0; border-color: #efdcb4; }
.cm .h { font-size: 12.5px; color: var(--ink-3); display: flex; gap: 8px; align-items: center; }
.cm .h b { color: var(--ink); font-weight: 600; }
.cm .h button { margin-left: auto; }
.cm .b { white-space: pre-wrap; font-size: 14.5px; margin-top: 2px; }

.pager {
  position: fixed; bottom: 0; left: 280px; right: 0; z-index: 15;
  display: flex; align-items: center; gap: 10px; padding: 10px 36px;
  background: rgba(245, 244, 239, .94); backdrop-filter: blur(6px); border-top: 1px solid var(--line);
}
.pager .mid { margin: 0 auto; font-size: 13px; color: var(--ink-3); }
.toast {
  position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 14px; box-shadow: var(--shadow);
}
.toast.err { background: var(--danger); }

/* ---------- print / summary ---------- */
.ptable { width: 100%; border-collapse: collapse; font-size: 13.5px; background: #fff; }
.ptable th, .ptable td { border: 1px solid #cfccc2; padding: 7px 9px; vertical-align: top; text-align: left; }
.ptable th { background: #efeee8; font-weight: 600; }
.ptable td.c { white-space: nowrap; }
.ptable .sec-row td { background: #f6f5f0; font-weight: 600; }
.ptable ol { margin: 0; padding-left: 18px; }
.phead { text-align: center; margin-bottom: 18px; }
.phead h1 { font-size: 20px; margin: 0; }
.phead p { margin: 2px 0; }

.log { font-size: 13px; }
.log div { padding: 5px 0; border-bottom: 1px solid var(--line-2); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: 100%; max-width: 420px; padding: 32px; }
.login .mark { margin-bottom: 14px; color: #fff; }
.login h1 { font-size: 20px; margin: 0 0 4px; line-height: 1.4; }
.login p { margin: 0 0 6px; color: var(--ink-2); font-size: 14px; }
.login .btn { width: 100%; margin-top: 18px; padding: 10px; }
.login .err { color: var(--danger); font-size: 14px; margin-top: 10px; min-height: 1em; }

/* ---------- install app ---------- */
.topnav a.install-link { color: #ffd58a; }
.install-cta { display: block; text-align: center; margin-top: 16px; font-size: 14px; color: var(--accent); text-decoration: none; padding: 9px; border: 1px dashed #b9d6d4; border-radius: 8px; background: var(--accent-soft); }
.install-modal { position: fixed; inset: 0; z-index: 100; background: rgba(24, 36, 47, .5); display: grid; place-items: center; padding: 16px; }
.im-card { background: #fff; border-radius: 14px; max-width: 440px; width: 100%; padding: 22px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.im-head { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.im-head img { width: 52px; height: 52px; border-radius: 12px; }
.im-head b { display: block; font-size: 16.5px; }
.im-head small { color: var(--ink-3); font-size: 13px; }
.im-card ol { padding-left: 20px; margin: 10px 0 18px; line-height: 1.75; }
.im-card .btn { width: 100%; }

/* ---------- responsive ---------- */
.side-toggle { display: none; }
@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; top: 56px; left: 0; width: 290px; z-index: 30; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .side.open { transform: none; }
  .side-toggle { display: inline-flex; }
  .pager { left: 0; padding: 10px 16px; }
  .pager .mid { visibility: hidden; }
  main { padding: 20px 16px 110px; }
  .hero { grid-template-columns: 1fr; gap: 16px; padding: 20px; }
  .countdown { border-left: 0; padding-left: 0; border-top: 1px solid var(--line); padding-top: 14px; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .evid { grid-template-columns: 1fr; }
  .viewer, .viewer iframe { min-height: 480px; }
  .form-grid { grid-template-columns: 1fr; }
  .brand-text small, .who span { display: none; }
}
@media (max-width: 620px) {
  .row { grid-template-columns: 56px 1fr; }
  .row .meta2 { grid-column: 2; flex-direction: row; flex-wrap: wrap; }
  .row .files { grid-column: 2; text-align: left; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .brand-text, .who { display: none; }
  .topnav { gap: 0; }
  .topnav .tn-label, .brand .mark { display: none; }
  .topbar { gap: 6px; padding: 10px 12px; }
  .topnav a, .topnav button { padding: 6px 8px; }
  .search { max-width: none; flex: 1; }
}

@media print {
  .topbar, .side, .pager, .noprint, .toast { display: none !important; }
  .shell { display: block; }
  main { padding: 0; max-width: none; }
  body { background: #fff; font-size: 12.5px; }
  .card { box-shadow: none; }
  .ptable { font-size: 11.5px; }
  .ptable tr { page-break-inside: avoid; }
  a { color: #000; }
  @page { size: A4 landscape; margin: 12mm; }
}
