/* Fortal Gen Lab — โทนเดียวกับ fortal.studio (dark) จาก design/tokens.css */
:root {
  color-scheme: dark;
  --shell: #0d0c0f; --bg: #080808; --card: #0d0d0f; --card2: #111114; --pop: #141417;
  --line: #ffffff17; --line2: #ffffff26;
  --fg: #f4efe5; --fg2: #c8c1b7; --muted: #8f887f;
  --gold: #f0b956; --gold-hi: #f6cf7a; --gold-soft: #f0b9561a; --gold-line: #f0b9565c; --ink: #160f08;
  --grad: linear-gradient(135deg, #f6cf7a, #bc7f25);
  --teal: #3dc3c0; --green: #3fd28a; --violet: #a78bfa; --red: #ff5a5a;
  --ui: "Google Sans", "Noto Sans Thai", system-ui, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --r-sm: 8px; --r: 12px; --r-lg: 18px; --r-xl: 22px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--shell); color: var(--fg); font: 400 14px/1.55 var(--ui); }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; }
[hidden] { display: none !important; }

/* ---------- common ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 18px; border: 0; border-radius: 999px; font: 700 13.5px var(--ui); white-space: nowrap; cursor: pointer; transition: transform .15s, opacity .15s; }
.btn svg { width: 17px; height: 17px; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-gold { background: var(--grad); color: var(--ink); box-shadow: 0 10px 24px -14px var(--gold); }
.btn-line { box-shadow: inset 0 0 0 1px var(--line2); color: var(--fg); background: #ffffff08; }
.btn-line:hover { background: #ffffff12; }
.btn.sm { height: 34px; padding: 0 14px; font-size: 12.5px; }
.btn.xs { height: 28px; padding: 0 11px; font-size: 12px; }
.btn.wide { width: 100%; height: 44px; }
.btn.danger { color: #ff9b9b; }
.eyebrow { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--gold); }
.eyebrow::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.mono { font-family: var(--mono); font-size: 10.5px; letter-spacing: .16em; text-transform: uppercase; }
.mono-t { font-family: var(--mono); font-size: 12px; color: var(--fg2); word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: #ff9b9b; }
.note { margin: 10px 2px 0; color: var(--muted); font-size: 12.5px; }
.st { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.st::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-open, .st-succeeded { background: #3fd28a24; color: var(--green); }
.st-up, .st-needs_approval { background: var(--gold-soft); color: var(--gold); }
.st-past { background: #ffffff12; color: var(--muted); }
.st-run, .st-running, .st-submitting, .st-downloading { background: #3dc3c01f; color: var(--teal); }
.st-bad, .st-failed { background: #ff5a5a1f; color: #ff8a8a; }
.alert { margin: 0 0 16px; padding: 11px 14px; border-radius: var(--r); font-size: 13px; box-shadow: inset 0 0 0 1px var(--line2); background: #ffffff08; }
.alert.ok { box-shadow: inset 0 0 0 1px #3fd28a55; background: #3fd28a12; color: #9ff0c4; }
.alert.bad { box-shadow: inset 0 0 0 1px #ff5a5a55; background: #ff5a5a12; color: #ffb3b3; }
.alert.warn { box-shadow: inset 0 0 0 1px var(--gold-line); background: var(--gold-soft); color: var(--gold-hi); }
.fld { display: grid; gap: 6px; font-size: 12.5px; color: var(--fg2); }
.fld input, .fld select { height: 40px; padding: 0 12px; border-radius: var(--r-sm); border: 0; background: #ffffff0a; box-shadow: inset 0 0 0 1px var(--line2); outline: none; min-width: 0; }
.fld input:focus, .fld select:focus { box-shadow: inset 0 0 0 1px var(--gold-line); }
select option { background: var(--pop); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: var(--shell); }
.sb-brand { display: flex; align-items: center; gap: 4px; height: 62px; padding: 0 14px; }
.sb-brand .mark { width: 30px; height: 30px; }
.sb-brand .word { width: 92px; height: auto; margin-left: 4px; }
.sb-stack { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; }
.sb-item { display: flex; align-items: center; gap: 12px; height: 44px; padding: 0 10px; border-radius: 10px; color: var(--fg2); font-size: 13.5px; font-weight: 500; }
.sb-item:hover { background: #ffffff0a; }
.sb-item svg { width: 23px; height: 23px; flex: none; }
.sb-item.on { background: #282018; color: var(--fg); font-weight: 700; }
.sb-item.on svg { color: var(--gold); }
.sb-sep { margin: 8px 6px; border: 0; border-top: 1px solid #ffffff14; }
.sb-foot { margin-top: auto; padding: 16px 22px 22px; color: var(--muted); }
.sb-foot .mono { color: var(--gold); }
.sb-foot p { margin: 6px 0 0; font-size: 12px; }
.main { display: flex; flex-direction: column; min-width: 0; }
.head { height: 62px; display: flex; align-items: center; gap: 14px; padding: 0 22px 0 8px; }
.head-logo { display: none; }
.head-logo img { width: 28px; height: 28px; }
.crumb { font-weight: 500; color: var(--fg2); }
.head-right { margin-left: auto; display: flex; align-items: center; gap: 10px; min-width: 0; }
.conn { display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.conn::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.conn.on { color: var(--green); background: #3fd28a14; box-shadow: inset 0 0 0 1px #3fd28a3d; }
.conn.off { color: var(--muted); background: #ffffff0a; box-shadow: inset 0 0 0 1px var(--line2); }
.who { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.ava { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--grad); color: var(--ink); font-weight: 700; flex: none; }
.who-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px; }
.icon-btn { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; color: var(--muted); }
.icon-btn:hover { background: #ffffff0f; color: var(--fg); }
.icon-btn svg { width: 19px; height: 19px; }
.panel { flex: 1; background: var(--bg); border-top-left-radius: var(--r-xl); box-shadow: inset 1px 1px 0 var(--line); min-width: 0; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 34px 32px 64px; }
.page-title { margin-bottom: 22px; }
.page-title h1 { margin: 8px 0 4px; font-size: 30px; font-weight: 700; letter-spacing: -.01em; }
.page-title .sub { margin: 0; color: var(--fg2); }

/* ---------- composer ---------- */
.composer { background: var(--card); border-radius: var(--r-xl); box-shadow: inset 0 0 0 1px var(--line2), 0 30px 60px -40px #000; padding: 16px; }
.composer:focus-within { box-shadow: inset 0 0 0 1px var(--gold-line), 0 30px 60px -40px #000; }
.composer textarea { width: 100%; min-height: 104px; resize: vertical; border: 0; outline: none; background: transparent; font-size: 15.5px; line-height: 1.6; padding: 4px 6px; }
.composer textarea::placeholder { color: #8f887fb3; }
.composer.is-off textarea { opacity: .5; }
.comp-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.chip { display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 12px; border-radius: 999px; background: #ffffff0a; box-shadow: inset 0 0 0 1px var(--line2); font-size: 12.5px; font-weight: 500; color: var(--fg2); white-space: nowrap; }
.chip svg { width: 14px; height: 14px; }
.chip.lock { color: var(--gold-hi); background: var(--gold-soft); box-shadow: inset 0 0 0 1px var(--gold-line); font-weight: 700; }
.chip.sel span { color: var(--muted); }
.chip select { border: 0; background: transparent; outline: none; font-weight: 700; color: var(--fg); cursor: pointer; padding-right: 2px; }
.count { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.comp-msg { margin-top: 12px; padding: 10px 12px; border-radius: var(--r); background: var(--gold-soft); color: var(--gold-hi); font-size: 13px; }
.comp-err { margin-top: 12px; padding: 10px 12px; border-radius: var(--r); background: #ff5a5a14; color: #ffb3b3; font-size: 13px; }

/* แนบเรฟ */
.chip.attach { position: relative; cursor: pointer; color: var(--fg); }
.chip.attach:hover { background: #ffffff12; }
.chip.attach svg { width: 16px; height: 16px; }
.chip.attach input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.composer.is-off .chip.attach { opacity: .5; pointer-events: none; }
.refs { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 2px 10px; }
.ref { position: relative; width: 74px; height: 74px; border-radius: 12px; overflow: hidden; background: #000; box-shadow: inset 0 0 0 1px var(--line2); }
.ref img, .ref video { width: 100%; height: 100%; object-fit: cover; display: block; }
.ref .aud { display: grid; place-items: center; height: 100%; font-size: 26px; color: var(--teal); }
.ref-n { position: absolute; left: 5px; bottom: 5px; padding: 1px 6px; border-radius: 6px; background: #000c; color: var(--gold-hi); font: 700 11px var(--mono); }
.ref-t { position: absolute; right: 5px; bottom: 5px; padding: 1px 5px; border-radius: 6px; background: #000c; font-size: 10.5px; color: var(--fg2); }
.ref-x { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: #000c; color: var(--fg); font-size: 15px; line-height: 1; cursor: pointer; }
.ref-x:hover { background: #ff5a5a; }
.ref-hint { margin: 2px 6px 0; color: var(--muted); font-size: 12px; }
.ref-hint b { color: var(--gold-hi); font-family: var(--mono); }
/* ความยาว: แถบลาก */
.chip.dur { gap: 10px; padding-right: 14px; }
.chip.dur > span { color: var(--muted); }
.chip.dur output { min-width: 40px; font-weight: 700; color: var(--fg); font-variant-numeric: tabular-nums; }
.chip.dur input[type=range] { --p: 5%; -webkit-appearance: none; appearance: none; width: 150px; height: 18px; background: transparent; cursor: pointer; margin: 0; }
.chip.dur input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(90deg, var(--gold) var(--p), #ffffff26 var(--p)); }
.chip.dur input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: #ffffff26; }
.chip.dur input[type=range]::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--gold); }
.chip.dur input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border-radius: 50%; background: var(--gold-hi); box-shadow: 0 0 0 3px #f0b95633; border: 0; }
.chip.dur input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--gold-hi); border: 0; }
.chip.dur input[type=range]:focus-visible { outline: 2px solid var(--gold-line); outline-offset: 2px; border-radius: 4px; }
.chip.dur input:disabled { opacity: .5; cursor: not-allowed; }
.under { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: space-between; }
.under .note { margin-top: 10px; }
.quota { display: inline-flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 12.5px; color: var(--fg2); }
.quota b { color: var(--fg); }
.quota.low { color: #ff9b9b; }
.bar { display: inline-block; width: 90px; height: 5px; border-radius: 5px; background: #ffffff1f; overflow: hidden; vertical-align: middle; }
.bar i { display: block; height: 100%; background: var(--grad); border-radius: 5px; }
.quota.low .bar i { background: #ff5a5a; }
.job-refs { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.jr { position: relative; width: 38px; height: 38px; border-radius: 8px; overflow: hidden; background: #ffffff0d; box-shadow: inset 0 0 0 1px var(--line2); display: grid; place-items: center; font-size: 10px; color: var(--fg2); }
.jr img { width: 100%; height: 100%; object-fit: cover; }
.jr i { position: absolute; left: 2px; bottom: 1px; font: 700 9.5px var(--mono); font-style: normal; color: var(--gold-hi); text-shadow: 0 1px 2px #000; }

/* ---------- gallery ---------- */
.sec-h { display: flex; align-items: baseline; gap: 12px; margin: 34px 0 14px; }
.sec-h h2 { margin: 0; font-size: 22px; font-weight: 500; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.empty { grid-column: 1 / -1; padding: 40px 0; text-align: center; }
.job { background: var(--card); border-radius: var(--r-lg); box-shadow: inset 0 0 0 1px var(--line); overflow: hidden; }
.media { position: relative; background: #000; max-height: 520px; width: 100%; }
.media video { width: 100%; height: 100%; display: block; object-fit: contain; background: #000; }
.ph { position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 12px; color: var(--muted); font-size: 13px; text-align: center; padding: 16px;
  background: radial-gradient(120% 90% at 50% 0%, #f0b9560f, transparent 60%), #0b0b0d; }
.ph.bad { color: #ff9b9b; }
.ph.run { color: var(--teal); }
.spin { width: 26px; height: 26px; border-radius: 50%; border: 2.5px solid #3dc3c033; border-top-color: var(--teal); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }
.meta { padding: 12px 14px 14px; }
.meta-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.icon-link { margin-left: auto; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px; color: var(--fg2); box-shadow: inset 0 0 0 1px var(--line2); }
.icon-link:hover { color: var(--gold); }
.icon-link svg { width: 16px; height: 16px; }
.meta .p { margin: 8px 0 0; color: var(--fg2); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
.meta .err { margin: 6px 0 0; }

/* ---------- admin ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.card { background: var(--card); border-radius: var(--r-lg); box-shadow: inset 0 0 0 1px var(--line); padding: 18px 20px 20px; margin-bottom: 16px; min-width: 0; }
.grid2 .card { margin-bottom: 0; }
.grid2 { margin-bottom: 16px; }
.card-h { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-h h2 { margin: 0; font-size: 18px; font-weight: 500; }
.card-h > :last-child:not(h2) { margin-left: auto; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; margin: 0 0 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; }
.row-btns { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.lock-chip { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 700; color: var(--gold-hi); background: var(--gold-soft); box-shadow: inset 0 0 0 1px var(--gold-line); }
.lock-chip svg { width: 13px; height: 13px; }
.login-box { margin: 0 0 14px; padding: 14px; border-radius: var(--r); background: #f0b9560d; box-shadow: inset 0 0 0 1px var(--gold-line); display: grid; gap: 10px; justify-items: start; font-size: 13px; }
.login-box p { margin: 0; }
.code-row { display: flex; align-items: baseline; gap: 12px; }
.code-row span { color: var(--muted); }
.code-row b { font-family: var(--mono); font-size: 22px; letter-spacing: .12em; color: var(--gold-hi); }
.ceil-form { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.inline-fld input { width: 160px; }
.tbl-wrap { overflow-x: auto; margin: 0 -4px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 8px; border-bottom: 1px solid var(--line2); white-space: nowrap; }
.tbl td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr.hl td { background: var(--gold-soft); }
.tbl.small td, .tbl.small th { padding: 6px 8px; font-size: 12px; }
.acts { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.acts input { height: 28px; width: 110px; padding: 0 9px; border-radius: 8px; border: 0; background: #ffffff0a; box-shadow: inset 0 0 0 1px var(--line2); font-size: 12px; outline: none; }
.approve input { width: 84px; }
.prompt-cell { max-width: 300px; color: var(--fg2); }
.add-user { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)) auto; gap: 10px; align-items: end; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.add-acc { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.add-acc .fld { flex: 1 1 260px; max-width: 380px; }
.badge-gold { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; color: var(--ink); background: var(--grad); vertical-align: 1px; }
.tbl tr.off td { opacity: .55; }
.user-set select { height: 28px; padding: 0 8px; border-radius: 8px; border: 0; background: #ffffff0a; box-shadow: inset 0 0 0 1px var(--line2); font-size: 12px; outline: none; max-width: 150px; }
.user-set input { width: 96px; }
.acc-sum { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.acc-sum > div { padding: 12px 14px; border-radius: var(--r); background: #ffffff06; box-shadow: inset 0 0 0 1px var(--line); }
.acc-sum small { display: block; color: var(--muted); font-size: 12px; }
.acc-sum b { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.inline input[type=number], .inline input[type=password] { height: 28px; padding: 0 9px; border-radius: 8px; border: 0; background: #ffffff0a; box-shadow: inset 0 0 0 1px var(--line2); color: var(--fg); font-size: 12px; outline: none; }
.inline input:focus { box-shadow: inset 0 0 0 1px var(--gold-line); }
.acc-budget input { width: 104px; }
.acc-budget input.day { width: 54px; }
.acc-tbl .bar { width: 120px; margin-top: 4px; }
@media (max-width: 760px) { .acc-sum { grid-template-columns: 1fr 1fr; } }
.rules { margin: 12px 0 0; padding-left: 18px; color: var(--fg2); font-size: 12.5px; display: grid; gap: 4px; }
.rules b { color: var(--fg); }
details.models, details.raw { margin-top: 14px; }
details summary { cursor: pointer; color: var(--fg2); font-size: 12.5px; }
details.raw { margin-top: 0; width: 100%; }
details.raw pre { max-width: 520px; max-height: 260px; overflow: auto; font-size: 11px; background: #000; padding: 10px; border-radius: 8px; white-space: pre-wrap; word-break: break-all; }

/* ---------- auth pages ---------- */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(80% 60% at 50% 0%, #f0b95614, transparent 60%), var(--shell); }
.auth-card { width: min(400px, 100%); background: var(--card); border-radius: var(--r-xl); box-shadow: inset 0 0 0 1px var(--line2), 0 40px 80px -50px #000; padding: 28px 26px; display: grid; gap: 14px; }
.auth-brand { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.auth-brand img { width: 32px; height: 32px; }
.auth-brand .word { width: 96px; height: auto; }
.auth-card h1 { margin: 0; font-size: 26px; }
.auth-card .sub { margin: -8px 0 4px; color: var(--fg2); font-size: 13px; }
.auth-card .alert { margin: 0; }
.auth-switch { margin: 2px 0 0; text-align: center; font-size: 12.5px; color: var(--muted); }
.auth-switch a { text-decoration: underline; text-underline-offset: 3px; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .grid2 { grid-template-columns: 1fr; }
  .add-user { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .head { padding: 0 16px; }
  .head-logo { display: block; }
  .panel { border-top-left-radius: 0; }
  .wrap { padding: 22px 16px 48px; }
  .page-title h1 { font-size: 25px; }
  .who-name { display: none; }
  .gallery { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .conn { font-size: 0; padding: 0; width: 32px; justify-content: center; }
  .conn::before { width: 9px; height: 9px; }
  .comp-bar .btn { width: 100%; }
  .count { margin-left: 0; }
  .add-user { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
}
