:root {
  --bg: #0d0e10; --bg2: #141519; --card: #17181d; --line: #262830; --line2: #31343e;
  --tx: #e9eaee; --mut: #8b8f9c; --acc: #d4ff3a; --acc-tx: #0d0e10;
  --ok: #4ade80; --warn: #fbbf24; --bad: #f87171; --info: #60a5fa;
  --r: 12px; --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--tx); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
a { color: inherit; }
code, pre { font-family: var(--mono); font-size: 12.5px; }
h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
h4 { margin: 18px 0 8px; font-size: 13px; color: var(--mut); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--mut); } .small { font-size: 12px; }
input, select, textarea {
  width: 100%; background: var(--bg2); color: var(--tx); border: 1px solid var(--line2); border-radius: 9px;
  padding: 9px 11px; font: inherit; outline: none; transition: border-color .15s;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--acc); }
label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--mut); font-weight: 500; min-width: 0; }
label.check { flex-direction: row; align-items: center; gap: 8px; }
label.check input { width: auto; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--bg2); color: var(--tx);
  border: 1px solid var(--line2); border-radius: 9px; padding: 8px 14px; font: inherit; font-weight: 500; cursor: pointer;
  text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s; user-select: none;
}
.btn:hover { border-color: #4a4e5a; background: #1c1d23; }
.btn.primary { background: var(--acc); color: var(--acc-tx); border-color: var(--acc); font-weight: 650; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.primary:disabled { opacity: .35; cursor: not-allowed; filter: none; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 9px; font-size: 12px; border-radius: 7px; }
.btn.wide { width: 100%; }
.big-btn { padding: 13px; font-size: 15px; }
.link { background: none; border: 0; color: var(--acc); cursor: pointer; font: inherit; font-size: 12px; text-decoration: none; padding: 0; }
.err { color: var(--bad); min-height: 18px; font-size: 13px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(700px 400px at 70% 10%, rgba(212,255,58,.08), transparent 70%), var(--bg); }
.login-card { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login-card p { margin: -6px 0 6px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand.big { font-size: 22px; }
.logo { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--acc); color: var(--acc-tx); font-size: 12px; }

/* layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--line); background: var(--bg2); padding: 18px 12px; display: flex; flex-direction: column; gap: 22px; }
.side .brand { padding: 0 8px; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: var(--mut); text-decoration: none; font-weight: 500; }
nav a i { font-style: normal; width: 18px; text-align: center; opacity: .8; }
nav a:hover { color: var(--tx); background: #1b1c22; }
nav a.on { color: var(--tx); background: #22242b; }
nav a.on i { color: var(--acc); opacity: 1; }
.badge { margin-left: auto; background: var(--acc); color: var(--acc-tx); border-radius: 10px; font-size: 11px; padding: 0 7px; font-weight: 700; }
.me { margin-top: auto; border-top: 1px solid var(--line); padding: 14px 8px 0; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.me .who { display: flex; justify-content: space-between; align-items: center; }
main { padding: 26px 28px 60px; min-width: 0; max-width: 1400px; }
.view { display: none; flex-direction: column; gap: 16px; }
.view.on { display: flex; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; min-width: 0; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar input { max-width: 320px; }
.toolbar select { width: auto; }
.grow { flex: 1; }
.center { display: flex; justify-content: center; }
.row2, .row3, .row4, .row5 { display: grid; gap: 12px; align-items: end; }
.row2 { grid-template-columns: 1fr 1fr; }
.row3 { grid-template-columns: repeat(3, 1fr); }
.row4 { grid-template-columns: repeat(4, 1fr); }
.row5 { grid-template-columns: 1fr 1.6fr 2fr .7fr auto; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.cols > div { display: flex; flex-direction: column; gap: 16px; }
.inline { display: flex; gap: 8px; align-items: center; }
.sec-head { display: flex; justify-content: space-between; align-items: baseline; }
.sec-head h3 { margin: 0; }

/* segmented */
.seg { display: inline-flex; background: var(--bg2); border: 1px solid var(--line2); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { background: none; border: 0; color: var(--mut); padding: 6px 11px; border-radius: 7px; cursor: pointer; font: inherit; font-size: 13px; font-weight: 500; }
.seg button:hover { color: var(--tx); }
.seg button.on { background: #2a2d36; color: var(--tx); }
.seg button:disabled { opacity: .3; cursor: not-allowed; }

/* switch */
.switch { display: inline-flex; align-items: center; gap: 8px; height: 38px; cursor: pointer; }
.switch input { display: none; }
.switch span { width: 38px; height: 22px; border-radius: 11px; background: var(--line2); position: relative; transition: .2s; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: var(--acc); }
.switch input:checked + span::after { left: 19px; background: var(--acc-tx); }
.switch em { font-style: normal; color: var(--tx); font-size: 13px; }

/* generate */
.gen-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, .65fr); gap: 18px; align-items: start; }
.gen-form { display: flex; flex-direction: column; gap: 16px; }
.frames { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.slot { border: 1px dashed var(--line2); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.slot .st { font-size: 12px; color: var(--mut); font-weight: 500; display: flex; justify-content: space-between; }
.slot .prev { height: 86px; border-radius: 7px; background: var(--bg2) center/cover no-repeat; display: grid; place-items: center; color: var(--mut); font-size: 12px; cursor: pointer; overflow: hidden; position: relative; }
.slot .prev video { width: 100%; height: 100%; object-fit: cover; }
.slot input[type=text] { padding: 6px 9px; font-size: 12px; }
.refs { display: flex; flex-direction: column; gap: 10px; }
.refs-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--mut); font-weight: 500; }
.drop { border: 1px dashed var(--line2); border-radius: 10px; padding: 14px; cursor: pointer; transition: .15s; }
.drop.over { border-color: var(--acc); background: rgba(212,255,58,.04); }
.drop-hint { color: var(--mut); text-align: center; font-size: 13px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumbs:not(:empty) { margin-top: 12px; }
.thumb { width: 74px; height: 74px; border-radius: 8px; background: var(--bg2) center/cover no-repeat; position: relative; display: grid; place-items: center; font-size: 11px; color: var(--mut); border: 1px solid var(--line); overflow: hidden; }
.thumb video { width: 100%; height: 100%; object-fit: cover; }
.thumb .x, .slot .x { position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; background: rgba(0,0,0,.75); color: #fff; border: 0; cursor: pointer; font-size: 12px; line-height: 20px; padding: 0; }
.thumb .kind { position: absolute; left: 4px; bottom: 3px; font-size: 10px; background: rgba(0,0,0,.7); color: #fff; padding: 0 5px; border-radius: 4px; }
.adv summary { cursor: pointer; color: var(--mut); font-size: 13px; margin-bottom: 10px; }
.quote { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: 13px; min-height: 46px; }
.quote .price { margin-left: auto; font-size: 20px; font-weight: 700; color: var(--acc); font-variant-numeric: tabular-nums; }
.quote .tag { background: #23252d; padding: 2px 8px; border-radius: 6px; font-family: var(--mono); font-size: 12px; }
.quote.bad { border-color: rgba(248,113,113,.4); color: var(--bad); }
.progress { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--acc); transition: width .2s; }
.recent { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 20px; }
.recent-list { display: flex; flex-direction: column; gap: 10px; }

/* jobs */
.job-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.job { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.job .media { aspect-ratio: 16/10; background: #0a0a0c; display: grid; place-items: center; position: relative; }
.job .media video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.job .media .ph { color: var(--mut); font-size: 13px; text-align: center; padding: 12px; }
.job .body { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.job .meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; color: var(--mut); align-items: center; }
.job .meta b { color: var(--tx); font-weight: 600; }
.job .prompt { font-size: 13px; color: #c9cbd2; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.job .acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }
.job .error { font-size: 12px; color: var(--bad); word-break: break-word; }
.job.mini { flex-direction: row; }
.job.mini .media { width: 112px; flex: none; aspect-ratio: auto; min-height: 84px; }
.job.mini .body { padding: 9px 12px; gap: 5px; }
.job.mini .prompt { -webkit-line-clamp: 2; font-size: 12px; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 650; padding: 2px 8px; border-radius: 20px; background: #23252d; color: var(--mut); white-space: nowrap; }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.ok { color: var(--ok); background: rgba(74,222,128,.1); }
.chip.run { color: var(--warn); background: rgba(251,191,36,.1); }
.chip.run::before { animation: pulse 1.2s infinite; }
.chip.bad { color: var(--bad); background: rgba(248,113,113,.1); }
@keyframes pulse { 50% { opacity: .25; } }
.spin { width: 26px; height: 26px; border: 3px solid var(--line2); border-top-color: var(--acc); border-radius: 50%; animation: rot .9s linear infinite; margin: 0 auto 8px; }
@keyframes rot { to { transform: rotate(360deg); } }

/* stats */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.kpi .v { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi .l { font-size: 12px; color: var(--mut); }
.chart svg { width: 100%; height: 220px; display: block; }
.chart .bar { fill: var(--acc); }
.chart .bar:hover { fill: #e8ff8a; }
.chart text { fill: var(--mut); font-size: 10px; }
.chart .grid { stroke: var(--line); }

/* tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; color: var(--mut); font-weight: 500; font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl.small td { padding: 5px 8px; }
.tbl td.num { font-variant-numeric: tabular-nums; text-align: right; }
.tbl td .acts { display: flex; gap: 5px; justify-content: flex-end; flex-wrap: wrap; }
.tbl td[contenteditable] { outline: none; border-radius: 4px; font-family: var(--mono); font-size: 12px; }
.tbl td[contenteditable]:focus { background: var(--bg2); box-shadow: inset 0 0 0 1px var(--acc); }
.tbl td.dirty { color: var(--acc); }
.card:has(> .tbl) { overflow-x: auto; }
.bar-u { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; min-width: 90px; margin-top: 4px; }
.bar-u div { height: 100%; background: var(--acc); }
.bar-u.hot div { background: var(--warn); } .bar-u.full div { background: var(--bad); }
.mono { font-family: var(--mono); font-size: 12px; }
.tokenrow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tok { background: var(--bg2); border: 1px solid var(--line2); padding: 8px 10px; border-radius: 8px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
pre.code { background: var(--bg2); border: 1px solid var(--line); border-radius: 9px; padding: 12px; overflow-x: auto; margin: 0; white-space: pre; color: #cfd2da; }
#setForm { display: flex; flex-direction: column; gap: 12px; }

/* modal + toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--card); border: 1px solid var(--line2); border-radius: 16px; padding: 22px; width: 100%; max-width: 460px; display: flex; flex-direction: column; gap: 12px; max-height: 90vh; overflow: auto; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #23252d; border: 1px solid var(--line2); border-left: 3px solid var(--acc); padding: 10px 14px; border-radius: 9px; max-width: 380px; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.4); word-break: break-word; }
.toast.bad { border-left-color: var(--bad); }

/* mail */
.mail-grid { display: grid; grid-template-columns: minmax(300px, 420px) 1fr; gap: 14px; align-items: start; }
.mail-list { padding: 0; overflow: hidden; max-height: calc(100vh - 140px); overflow-y: auto; }
.mail-view { min-height: 400px; position: sticky; top: 20px; }
.center-pad { padding: 60px 0; text-align: center; }
.mrow { display: grid; grid-template-columns: 22px 1fr auto; gap: 4px 10px; padding: 11px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.mrow:hover { background: #1b1c22; }
.mrow.on { background: #23252d; }
.mrow.unread .subj { font-weight: 700; color: var(--tx); }
.mrow.unread .dot { background: var(--acc); }
.mrow .dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 6px; }
.mrow input { width: auto; margin: 2px 0 0; grid-row: span 3; }
.mrow .to { font-family: var(--mono); font-size: 12px; color: var(--acc); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mrow .when { font-size: 11px; color: var(--mut); white-space: nowrap; }
.mrow .subj { grid-column: 2 / 4; font-size: 13px; color: #cfd2da; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mrow .from, .mrow .snip { grid-column: 2 / 4; font-size: 12px; color: var(--mut); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code-chip { display: inline-flex; gap: 6px; align-items: center; background: rgba(212,255,58,.12); color: var(--acc); border: 1px solid rgba(212,255,58,.3); border-radius: 7px; padding: 2px 8px; font-family: var(--mono); font-weight: 700; font-size: 13px; cursor: pointer; }
.mv-head { display: flex; flex-direction: column; gap: 6px; border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 12px; }
.mv-head h2 { margin: 0; font-size: 18px; }
.mv-head .kv { font-size: 12.5px; color: var(--mut); word-break: break-all; }
.mv-head .kv b { color: var(--tx); font-weight: 500; }
.mv-acts { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.mv-frame { width: 100%; height: 68vh; border: 0; border-radius: 9px; background: #fff; }
.mv-text { white-space: pre-wrap; word-break: break-word; font-family: var(--mono); font-size: 12.5px; background: var(--bg2); padding: 14px; border-radius: 9px; max-height: 68vh; overflow: auto; margin: 0; }
.mv-att { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.mx-help { margin: 12px 0; font-size: 13px; color: var(--mut); }
.mx-help code { background: var(--bg2); padding: 1px 6px; border-radius: 5px; color: var(--tx); }
.ok-t { color: var(--ok); } .bad-t { color: var(--bad); }

/* responsive */
@media (max-width: 1100px) {
  .gen-grid { grid-template-columns: 1fr; }
  .recent { position: static; }
  .row5 { grid-template-columns: 1fr 1fr; }
  .cols { grid-template-columns: 1fr; }
  .mail-grid { grid-template-columns: 1fr; }
  .mail-view { position: static; }
  .mail-list { max-height: 50vh; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .side { position: sticky; z-index: 10; height: auto; flex-direction: row; align-items: center; padding: 10px 16px; gap: 12px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .side .brand span:not(.logo) { display: none; }
  nav { flex-direction: row; }
  nav a { padding: 7px 9px; white-space: nowrap; font-size: 13px; }
  nav a i { display: none; }
  .me { display: none; }
  main { padding: 16px 16px 60px; }
  .row2, .row3, .row4, .row5, .frames { grid-template-columns: 1fr 1fr; }
  .row3 { grid-template-columns: 1fr; }
  .toolbar input { max-width: none; }
}
