/* Look follows the Nichapa Agent dashboard (same palette, Sarabun, sidebar, KPI cards, panels). */
:root {
  --brand: #b5446e;
  --brand-weak: #fbeff4;
  --ink: #1f2328;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f7f7f8;
  --card: #fff;
  --ok: #16a34a;
  --warn: #b45309;
  --bad: #dc2626;
  color-scheme: light;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: 'Sarabun', 'Leelawadee UI', system-ui, sans-serif; background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.5; }
a { color: var(--brand); }
h1 { font-size: 22px; margin: 4px 0 16px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 16px 0 8px; }
code { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }

/* ---------- shell: sidebar + content ---------- */
.shell { display: flex; min-height: 100vh; }
.side { width: 230px; flex: 0 0 230px; background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side .brand { background: var(--brand); color: #fff; font-weight: 700; font-size: 18px; padding: 16px 18px; margin: 0; }
.side nav { display: flex; flex-direction: column; padding: 8px; gap: 2px; overflow-y: auto; flex: 1; }
.side nav button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 0; border-radius: 8px; background: none; color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.side nav button:hover { background: var(--bg); }
.side nav button.active { background: var(--brand-weak); color: var(--brand); font-weight: 600; }
.side nav .ico { width: 22px; text-align: center; }
.side nav details summary { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; cursor: pointer; list-style: none; color: var(--ink); margin: 0; }
.side nav details summary::-webkit-details-marker { display: none; }
.side nav details summary:hover { background: var(--bg); }
.side nav details summary:after { content: '▸'; margin-left: auto; color: var(--muted); }
.side nav details[open] summary:after { content: '▾'; }
.side nav details.on summary { color: var(--brand); font-weight: 600; }
.side nav .sub button { padding-left: 34px; }
.side .me .me-link { color: var(--brand); }
body:not(.is-admin) .admin-only { display: none !important; }
.side .me { border-top: 1px solid var(--line); padding: 12px 18px; font-size: 14px; display: grid; gap: 6px; justify-items: start; }
.side .me a { color: var(--bad); text-decoration: none; }
.content { flex: 1; min-width: 0; }
.topbar { display: none; background: var(--brand); color: #fff; padding: 10px 14px; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 20; }
.topbar label { font-size: 24px; line-height: 1; cursor: pointer; padding: 2px 6px; }
.topbar b { font-size: 17px; }
#menu { display: none; }
.scrim { display: none; }
main { max-width: 1280px; margin: 0 auto; padding: 20px 16px; }
@media (max-width: 820px) {
  .topbar { display: flex; }
  .side { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform 0.2s; box-shadow: 0 0 24px #0003; }
  #menu:checked ~ .side { transform: none; }
  #menu:checked ~ .scrim { display: block; position: fixed; inset: 0; background: #0004; z-index: 30; }
}

/* ---------- building blocks ---------- */
.card, .panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; min-width: 0; }
.panel h3, .card-head { margin: 0 0 2px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.panel h3 { font-size: 15px; }
.panel h3 a { font-size: 13px; font-weight: 400; }
.cap { color: var(--muted); font-size: 12.5px; margin-bottom: 10px; }
.card-head { margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.card-head select { width: auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; margin-bottom: 12px; }
.wide { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; margin: 10px 0 0; }
label.row, fieldset label { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
fieldset { border: 1px solid var(--line); border-radius: 8px; display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 10px; }
legend { font-weight: 600; padding: 0 4px; }
input, textarea, select { width: 100%; padding: 9px 10px; border: 1px solid #cbd0d6; border-radius: 8px; font: inherit; font-weight: 400; background: #fff; color: var(--ink); }
input[type='checkbox'] { width: 18px; height: 18px; accent-color: var(--brand); }
input[type='file'] { border: 0; padding: 0; }
textarea { min-height: 70px; }
button, .btn { display: inline-block; background: #fff; color: var(--brand); border: 1px solid var(--brand); border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
button:hover, .btn:hover { background: var(--brand-weak); }
button.primary { background: var(--brand); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); border-color: var(--bad); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0; align-items: center; }
.actions select { width: auto; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 13px; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
#jobs tbody tr { cursor: pointer; }
#jobs tbody tr:hover td { background: var(--bg); }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; background: #f3f4f6; color: var(--muted); white-space: nowrap; }
.pill.ok { background: #dcfce7; color: var(--ok); }
.pill.warn { background: #fef3c7; color: var(--warn); }
.pill.err { background: #fee2e2; color: var(--bad); }
.muted { color: var(--muted); }
.hint { font-weight: 400; color: var(--muted); font-size: 13px; }
.small { font-size: 13px; }
.flash, .err-box, .ok-box { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; white-space: pre-wrap; }
.err-box { background: #fee2e2; color: #991b1b; }
.ok-box { background: #dcfce7; color: #166534; }
.err-text { color: var(--bad); }
.inline { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.inline input { width: auto; }
.btn-link { color: var(--bad); text-decoration: none; }
pre.token { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg); padding: 8px; border-radius: 6px; user-select: all; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; background: #cbd5e1; vertical-align: middle; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

/* ---------- overview ---------- */
.ov-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.ov-head h1 { margin: 0; }
.ov-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.status-pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 99px; font-weight: 600; font-size: 14px; background: #dcfce7; color: #166534; }
.status-pill.off { background: #fee2e2; color: #991b1b; }
.status-pill i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; position: relative; overflow: hidden; cursor: pointer; }
.kpi:hover { border-color: var(--brand); }
.kpi:before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent, var(--brand)); }
.kpi .k { font-size: 13px; color: var(--muted); }
.kpi .v { font-size: 26px; font-weight: 700; margin: 2px 0; letter-spacing: -0.3px; font-variant-numeric: tabular-nums; }
.kpi .d { font-size: 12.5px; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; }
.grid2e { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid2, .grid2e { grid-template-columns: 1fr; } }
.flow { display: flex; gap: 6px; flex-wrap: wrap; align-items: stretch; }
.flow .st { flex: 1 1 92px; background: var(--bg); border-radius: 10px; padding: 8px 10px; text-align: center; cursor: pointer; }
.flow .st b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.flow .st span { font-size: 12px; color: var(--muted); }
.flow .st.hot { background: #fef3c7; }
.flow .st.hot b { color: #b45309; }
.ptab td, .ptab th { font-size: 14px; text-align: center; }
.ptab td:first-child, .ptab th:first-child { text-align: left; }
.wk { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.wk:last-child { border-bottom: 0; }
.wk .nm { font-weight: 600; min-width: 140px; }
.wk .ls { color: var(--muted); font-size: 13px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed .it { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.feed .it:last-child { border-bottom: 0; }
.feed .t { color: var(--muted); font-size: 12.5px; min-width: 44px; }
.feed .a { font-weight: 600; white-space: nowrap; }
.feed .m { color: #374151; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed .it.error .a { color: var(--bad); }
.feed .it.warn .a { color: var(--warn); }
.feed .it.ok .a { color: var(--ok); }

/* ---------- server status ---------- */
.todo { background: #fffbeb; border: 1px solid #fde68a; border-radius: 12px; padding: 12px 16px; margin-bottom: 16px; }
.todo b { display: block; margin-bottom: 4px; }
.todo div { font-size: 14.5px; padding: 2px 0; }
.status-pill.warn { background: #fef3c7; color: #92400e; }
.meter { display: grid; grid-template-columns: 120px 1fr auto; gap: 10px; align-items: center; padding: 6px 0; font-size: 14px; }
.meter .lbl { color: var(--muted); }
.bar { height: 7px; background: var(--bg); border-radius: 99px; overflow: hidden; min-width: 70px; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.bar i.warn { background: #f59e0b; }
.bar i.bad { background: var(--bad); }
.kvs { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 14px; margin-top: 8px; }
.kvs dt { color: var(--muted); }
.kvs dd { margin: 0; }
.check-row { display: flex; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.check-row:last-child { border-bottom: 0; }
.spark { width: 100%; height: 120px; }

/* ---------- job detail ---------- */
dialog { width: min(980px, calc(100vw - 24px)); max-height: calc(100vh - 24px); border: 0; border-radius: 12px; background: var(--card); color: var(--ink); padding: 0; box-shadow: 0 20px 60px #0004; }
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.detail-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; background: var(--brand); color: #fff; padding: 12px 16px; position: sticky; top: 0; z-index: 2; }
.detail-head h2 { margin: 0; font-size: 17px; }
.detail-head button { background: none; color: #fff; border: 0; font-size: 18px; }
#d-body { padding: 16px; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 300px) 1fr; gap: 16px; }
@media (max-width: 700px) { .detail-grid { grid-template-columns: 1fr; } }
video { width: 100%; max-height: 70vh; background: #000; border-radius: 10px; }
.logs { font: 13px/1.5 ui-monospace, Consolas, monospace; max-height: 260px; overflow: auto; background: var(--bg); border-radius: 8px; padding: 8px; white-space: pre-wrap; }
.lv-error { color: var(--bad); }
.lv-warn { color: var(--warn); }
.lv-ok { color: var(--ok); }
.scene { border-left: 3px solid var(--brand-weak); padding-left: 8px; margin-bottom: 8px; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.thumbs img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.upload { display: inline-flex; align-items: center; justify-content: center; width: 96px; height: 96px; border: 1px dashed #cbd0d6; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 400; margin: 0; }
.scenes { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 12px; }
.scene-card { display: grid; gap: 4px; align-content: start; }
.scene-media img, .scene-media video { width: 100%; aspect-ratio: 9 / 16; object-fit: cover; border-radius: 8px; background: #000; max-height: none; }
.placeholder { aspect-ratio: 9 / 16; border: 1px dashed #cbd0d6; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; }
details summary { cursor: pointer; color: var(--muted); margin: 8px 0; }
