:root {
  --bg: #f6f5f2; --panel: #ffffff; --ink: #1d1d1f; --muted: #6b6b70; --line: #e4e2dc;
  --accent: #d9480f; --accent-ink: #ffffff; --ok: #1a7f37; --warn: #b26a00; --bad: #c62828; --info: #1d5fbf;
  --chip: #f0eee8; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --yt: #e62117; --tt: #111111; --fb: #1877f2; --ig: #c13584;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416; --panel: #1d1d20; --ink: #ececee; --muted: #a0a0a8; --line: #2e2e33;
    --accent: #ff7a3d; --accent-ink: #1a0d05; --ok: #4cc276; --warn: #e8a33a; --bad: #ff6b6b; --info: #6ea8ff;
    --chip: #28282d; --shadow: none; --tt: #e8e8e8;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: "Noto Sans Thai", system-ui, sans-serif; font-size: 15px; line-height: 1.55; }
a { color: var(--info); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.02rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

header { position: sticky; top: 0; z-index: 10; background: var(--panel); border-bottom: 1px solid var(--line); }
.bar { max-width: 1200px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.brand span { color: var(--accent); }
nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
nav button { background: none; border: 0; padding: 7px 12px; border-radius: 8px; color: var(--muted); font: inherit; cursor: pointer; white-space: nowrap; }
nav button.on { background: var(--chip); color: var(--ink); font-weight: 600; }
nav .badge { background: var(--accent); color: var(--accent-ink); border-radius: 99px; padding: 0 6px; font-size: .75rem; margin-left: 4px; }

main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 80px; }
section[data-tab] { display: none; }
section[data-tab].on { display: block; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }

button.btn, a.btn, label.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 8px; padding: 7px 14px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button.btn:hover, a.btn:hover, label.btn:hover { border-color: var(--muted); }
button.primary, a.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: wait; }
input, textarea, select { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; }
textarea { resize: vertical; min-height: 90px; }
label { display: block; font-size: .88rem; color: var(--muted); margin-bottom: 4px; }
label.btn { display: inline-flex; font-size: inherit; color: var(--ink); margin: 0; }
label.check { display: inline-flex; gap: 6px; align-items: center; color: var(--ink); font-size: .95rem; margin: 0; }
label.check input { width: auto; }

.chip { display: inline-block; background: var(--chip); border-radius: 99px; padding: 1px 10px; font-size: .82rem; margin: 2px 4px 2px 0; white-space: nowrap; }
.st { display: inline-block; border-radius: 99px; padding: 1px 9px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.st.done, .st.draft_sent { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.st.scheduled, .st.queued, .st.processing, .st.running { background: color-mix(in srgb, var(--info) 15%, transparent); color: var(--info); }
.st.failed { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.st.cancelled, .st.none { background: var(--chip); color: var(--muted); }
.pf { font-weight: 700; }
.pf.youtube { color: var(--yt); } .pf.tiktok { color: var(--tt); } .pf.facebook, .pf.meta { color: var(--fb); } .pf.instagram { color: var(--ig); }

.conn { display: flex; flex-direction: column; gap: 8px; }
.conn .who { font-size: .9rem; }
.big { font-size: 1.7rem; font-weight: 700; }

.clips { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.clip { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.clip video { width: 100%; aspect-ratio: 9/16; max-height: 360px; object-fit: cover; background: #000; display: block; }
.clip .body { padding: 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.clip .ser { font-size: .82rem; color: var(--muted); }
.clip .ttl { font-weight: 600; }
.clip .sts { display: flex; flex-wrap: wrap; gap: 4px; }
.series-h { margin: 22px 0 10px; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tablewrap { overflow-x: auto; }
.thumb { width: 96px; border-radius: 6px; display: block; }
.ellipsis { max-width: 420px; }

.bars { display: flex; flex-direction: column; gap: 6px; }
.barrow { display: grid; grid-template-columns: 150px 1fr 70px; gap: 8px; align-items: center; font-size: .88rem; }
.barrow .track { background: var(--chip); border-radius: 4px; height: 12px; overflow: hidden; }
.barrow .fill { background: var(--accent); height: 100%; }
.chart-box { position: relative; height: 260px; }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(980px, calc(100vw - 24px)); max-height: calc(100vh - 24px); background: var(--panel); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.dlg-head { position: sticky; top: 0; background: var(--panel); padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; z-index: 1; }
.dlg-body { padding: 16px; display: grid; gap: 16px; grid-template-columns: 240px 1fr; }
.dlg-body video { width: 100%; border-radius: 10px; background: #000; }
.ptabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; }
.ptabs button { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 5px 12px; border-radius: 99px; cursor: pointer; }
.ptabs button.on { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.counter { font-size: .78rem; color: var(--muted); text-align: right; }
.counter.over { color: var(--bad); font-weight: 600; }
.md { line-height: 1.7; }
.md h2 { margin-top: 1.2em; font-size: 1.12rem; }
.md ul { padding-left: 1.3em; }
.hint { background: color-mix(in srgb, var(--info) 8%, transparent); border-left: 3px solid var(--info); padding: 8px 12px; border-radius: 6px; font-size: .9rem; }
.warnbox { background: color-mix(in srgb, var(--warn) 10%, transparent); border-left: 3px solid var(--warn); padding: 8px 12px; border-radius: 6px; font-size: .9rem; }
code, .mono { font-family: ui-monospace, Consolas, monospace; font-size: .85em; background: var(--chip); padding: 1px 5px; border-radius: 4px; word-break: break-all; }
details summary { cursor: pointer; font-weight: 600; }
details { margin-top: 8px; }
ol.steps { padding-left: 1.3em; margin: 6px 0; }
ol.steps li { margin-bottom: 4px; }

/* viewers can look but not act: hide the main action buttons (the server refuses them anyway) */
body[data-role="viewer"] main button.primary, body[data-role="viewer"] main label.btn,
body[data-role="viewer"] main [data-open], body[data-role="viewer"] #rt-new { display: none; }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--panel); padding: 10px 18px; border-radius: 10px; max-width: calc(100vw - 32px); z-index: 100; display: none; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
#toast.bad { background: var(--bad); color: #fff; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: sp .8s linear infinite; vertical-align: -2px; }
@keyframes sp { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }

@media (max-width: 720px) {
  .dlg-body { grid-template-columns: 1fr; }
  .dlg-body video { max-height: 300px; object-fit: contain; }
  .barrow { grid-template-columns: 100px 1fr 56px; }
  .brand { width: 100%; }
}
