:root {
  --page: #f4f5f7; --panel: #fff; --layer: #e9ebee; --line: #d9dce1;
  --ink: #1b1d21; --ink2: #545a63; --ink3: #6a7079;
  --accent: #b5391f; --accent-hover: #96301a; --accent-tint: #f6e3dc;
  --ok: #2e7d5b; --warn: #a86f0e; --off: #6a7079;
  --r: 8px; --shadow: 0 1px 2px rgb(27 29 33 / .06), 0 8px 24px rgb(27 29 33 / .08);
  --ease: cubic-bezier(.16, 1, .3, 1);
}
* { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font-family: 'IBM Plex Sans Thai', 'IBM Plex Sans', system-ui, sans-serif; font-size: 1rem; line-height: 1.7;
  font-variant-numeric: tabular-nums; caret-color: var(--accent);
}
::selection { background: var(--accent-tint); color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { color: var(--accent-hover); }
h1, h2, h3 { line-height: 1.35; margin: 0; font-weight: 600; text-wrap: balance; }
h1 { font-size: 1.375rem; } h2 { font-size: 1.125rem; } h3 { font-size: 1rem; }
p { margin: 0; }
.small { font-size: .875rem; } .tiny { font-size: .8125rem; }
.muted { color: var(--ink2); }
svg.i { width: 1.1em; height: 1.1em; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.18em; flex: none; }

/* ---------- แถบบน ---------- */
#topbar { position: sticky; top: 0; z-index: 20; background: var(--panel); border-bottom: 1px solid var(--line); }
.bar { display: flex; align-items: center; gap: 4px 16px; flex-wrap: wrap; max-width: 1440px; margin: 0 auto; padding: 10px 20px; }
.brand { font-weight: 600; font-size: 1.125rem; color: var(--ink); text-decoration: none; letter-spacing: -.01em; }
.brand b { color: var(--accent); font-weight: 600; }
.nav { display: flex; gap: 4px; }
.nav a { padding: 6px 12px; border-radius: var(--r); color: var(--ink2); text-decoration: none; font-weight: 500; font-size: .875rem; }
.nav a:hover { background: var(--layer); color: var(--ink); }
.nav a[aria-current] { background: var(--accent-tint); color: var(--accent-hover); }
.spacer { flex: 1; }
.who { display: flex; align-items: center; gap: 10px; }

/* ---------- ปุ่มและช่องกรอก ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: var(--r); border: 1px solid var(--line); background: var(--panel);
  color: var(--ink); font: inherit; font-size: .875rem; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .16s var(--ease), border-color .16s var(--ease); }
.btn:hover { background: var(--layer); color: var(--ink); border-color: #c3c8cf; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn.quiet { border-color: transparent; background: none; color: var(--ink2); }
.btn.quiet:hover { background: var(--layer); color: var(--ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.big { padding: 11px 20px; font-size: 1rem; }
input, select { font: inherit; font-size: .9375rem; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 8px 12px; min-width: 0; }
input::placeholder { color: var(--ink3); }
input:focus-visible, select:focus-visible { outline-offset: 0; border-color: var(--accent); }
label.check { display: inline-flex; align-items: center; gap: 6px; font-size: .875rem; color: var(--ink2); cursor: pointer; }
label.check input { accent-color: var(--accent); width: 16px; height: 16px; padding: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--panel); }
.seg button { border: 0; background: none; font: inherit; font-size: .875rem; font-weight: 500; padding: 6px 14px; color: var(--ink2); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }

/* ---------- โครงหน้า ---------- */
.wrap { max-width: 1440px; margin: 0 auto; padding: 20px; }
.narrow { max-width: 30rem; margin: 12vh auto 0; padding: 0 20px; }
.narrow h1 { font-size: 1.75rem; margin-bottom: 8px; }
.narrow .btn { margin-top: 24px; width: 100%; justify-content: center; }
.narrow ul { margin: 20px 0 0; padding-left: 1.2em; color: var(--ink2); }
.split { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; }
body.pane-open .split { grid-template-columns: minmax(0, 1fr) minmax(360px, 440px); }
.notice { padding: 12px 16px; border-radius: var(--r); background: var(--layer); color: var(--ink2); font-size: .875rem; }
.notice.bad { background: var(--accent-tint); color: var(--accent-hover); }

/* ---------- ค้นหา ---------- */
.searchbox { display: flex; gap: 8px; }
.searchbox input { flex: 1; padding: 11px 14px; font-size: 1rem; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-top: 12px; }
.filters input[type=number] { width: 5.5rem; padding: 6px 8px; font-size: .875rem; }
.filters select { padding: 6px 8px; font-size: .875rem; }
.listhead { display: flex; align-items: baseline; gap: 12px; margin: 24px 0 4px; }
.rows { list-style: none; margin: 0; padding: 0; }
.row { border-top: 1px solid var(--line); padding: 14px 12px; margin: 0 -12px; cursor: pointer; border-radius: 6px; transition: background .16s var(--ease); }
.row:hover { background: var(--layer); }
.row[aria-selected="true"] { background: var(--accent-tint); }
.row h3 { font-weight: 500; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 12px; margin-top: 4px; color: var(--ink2); font-size: .8125rem; }
.meta .src { max-width: 28ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { display: inline-flex; align-items: center; gap: 5px; font-size: .8125rem; font-weight: 500; white-space: nowrap; }
.tag::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.tag.system { color: var(--ok); } .tag.manual { color: var(--warn); } .tag.closed { color: var(--off); }
.tag.in { color: var(--accent); }
.skeleton .row { cursor: default; }
.skeleton .row div { height: 14px; border-radius: 4px; background: var(--layer); margin: 6px 0; }
.empty { padding: 40px 0; color: var(--ink2); max-width: 60ch; }
.empty h2 { color: var(--ink); margin-bottom: 6px; }

/* ---------- แผงรายละเอียด ---------- */
#pane { position: sticky; top: 76px; align-self: start; max-height: calc(100vh - 96px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
#pane h2 { font-size: 1.125rem; padding-right: 36px; }
#pane .close { position: absolute; top: 12px; right: 12px; padding: 6px; }
#pane section { margin-top: 18px; }
#pane section > h3 { font-size: .8125rem; color: var(--ink2); font-weight: 500; margin-bottom: 6px; }
#pane .abstract { font-size: .9375rem; max-width: 70ch; }
#pane .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.files { list-style: none; margin: 0; padding: 0; font-size: .875rem; }
.files li { padding: 8px 0; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.files li:first-child { border-top: 0; padding-top: 0; }
.filestate { padding: 12px 14px; border-radius: var(--r); background: var(--layer); font-size: .875rem; }
.filestate .tag { font-size: .9375rem; }

/* ---------- โปรเจกต์ ---------- */
.projects { display: grid; gap: 0; }
.proj { display: flex; align-items: center; gap: 12px; border-top: 1px solid var(--line); padding: 14px 0; }
.proj a.name { font-weight: 500; color: var(--ink); text-decoration: none; flex: 1; min-width: 0; }
.proj a.name:hover { color: var(--accent); }
.usage { color: var(--ink2); font-size: .875rem; white-space: nowrap; }
.newproj { display: flex; gap: 8px; margin-top: 16px; max-width: 32rem; }
.newproj input { flex: 1; }
.tabs { display: flex; gap: 20px; border-bottom: 1px solid var(--line); margin: 16px 0 0; }
.tabs a { padding: 8px 0; color: var(--ink2); text-decoration: none; font-weight: 500; font-size: .9375rem; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a[aria-current] { color: var(--ink); border-color: var(--accent); }
.crumb { color: var(--ink2); font-size: .875rem; text-decoration: none; }

/* ---------- กราฟ ---------- */
.gtools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin: 14px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .8125rem; color: var(--ink2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.legend i.ring { background: none; border: 2px solid var(--ink); }
.legend i.dash { background: none; border: 2px dashed var(--ink3); }
#graph { height: calc(100vh - 290px); min-height: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; position: relative; }
#graph .hint { position: absolute; left: 14px; bottom: 10px; font-size: .8125rem; color: var(--ink3); pointer-events: none; }
.float-tooltip-kap, .scene-tooltip { font-family: inherit !important; font-size: .8125rem !important; background: var(--ink) !important; color: #fff !important; padding: 6px 10px !important; border-radius: 6px !important; max-width: 320px; line-height: 1.5; }

#toast { position: fixed; left: 50%; bottom: 24px; translate: -50% 0; z-index: 50; display: grid; gap: 8px; }
#toast div { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--r); font-size: .875rem; box-shadow: var(--shadow); max-width: 90vw; }

@media (max-width: 900px) {
  .bar { padding: 8px 14px; } .wrap { padding: 14px; }
  body.pane-open .split { grid-template-columns: minmax(0, 1fr); }
  #pane { position: fixed; inset: 0; top: 0; width: 100%; height: 100dvh; max-height: none; border-radius: 0; border: 0; z-index: 30; padding: 18px 16px 32px; }
  .who .name { display: none; }
  .searchbox { flex-wrap: wrap; } .searchbox .btn { flex: 1; justify-content: center; }
  #graph { height: calc(100vh - 250px); min-height: 360px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
