:root {
  --bg: #0a0d14;
  --sidebar: #0d1119;
  --panel: #131824;
  --panel-2: #171d2b;
  --inset: #0c1017;
  --border: #212838;
  --border-soft: #1a2130;
  --text: #e6eaf2;
  --muted: #8a93a6;
  --muted-2: #5f6779;
  --brand: #6366f1;
  --brand-2: #8b5cf6;
  --accent: #22d3ee;
  --accent-2: #38bdf8;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --grad: linear-gradient(135deg, #6366f1, #8b5cf6);
  --grad-cyan: linear-gradient(90deg, #22d3ee, #38bdf8);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }

.icon {
  width: 1.15em; height: 1.15em; display: inline-block; vertical-align: -0.2em;
  fill: none; stroke: currentColor; stroke-width: 1.9;
  stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0;
}
.icon-fill { fill: currentColor; stroke: none; }

body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, sans-serif;
  font-size: 14px; -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }

.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w); background: var(--sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0;
}
.sb-brand { display: flex; align-items: center; gap: 10px; padding: 22px 22px; font-weight: 700; font-size: 16px; }
.sb-brand .mark { width: 30px; height: 30px; border-radius: 8px; background: var(--grad); display: grid; place-items: center; color: #fff; }
.sb-brand .mark .icon { width: 17px; height: 17px; }
.sb-nav { padding: 8px 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sb-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 10px;
  color: var(--muted); font-size: 14.5px; cursor: pointer; transition: all .12s;
}
.sb-item:hover { background: var(--panel); color: var(--text); }
.sb-item.active { background: var(--grad); color: #fff; box-shadow: 0 6px 18px rgba(99,102,241,.35); }
.sb-item .ic { width: 18px; display: inline-flex; align-items: center; justify-content: center; }
.sb-item .ic .icon { width: 18px; height: 18px; }
.sb-plan {
  margin: 12px; padding: 16px; border-radius: 12px; background: var(--panel);
  border: 1px solid var(--border); font-size: 13px;
}
.sb-plan .lbl { color: var(--muted-2); font-size: 12px; }
.sb-plan .name { font-weight: 700; font-size: 16px; margin: 4px 0; background: var(--grad-cyan); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sb-plan .exp { color: var(--muted); font-size: 12px; }
.sb-help { padding: 14px 20px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; cursor: pointer; display: flex; align-items: center; gap: 10px; }

/* Main */
.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; padding: 18px 28px;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: rgba(10,13,20,.85);
  backdrop-filter: blur(10px); z-index: 10;
}
.topbar-title { display: flex; align-items: center; gap: 12px; }
.topbar-title h1 { font-size: 19px; margin: 0; font-weight: 700; }
.status-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ok); background: rgba(52,211,153,.1); padding: 4px 10px; border-radius: 999px; border: 1px solid rgba(52,211,153,.25); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.err { background: var(--err); box-shadow: 0 0 8px var(--err); }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.balance-card { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--border); padding: 8px 14px; border-radius: 10px; font-weight: 600; }
.balance-card .ic { color: var(--accent); display: inline-flex; align-items: center; }
.balance-card .ic .icon { width: 16px; height: 16px; }
.balance-card small { color: var(--muted); font-weight: 400; }
.avatar { width: 34px; height: 34px; border-radius: 9px; background: var(--grad); display: grid; place-items: center; color: #fff; }
.avatar .icon { width: 18px; height: 18px; }

.content { padding: 24px 28px; display: flex; flex-direction: column; gap: 20px; }
.view { display: none; }
.view.active { display: block; }

/* Layout rows */
.row { display: grid; gap: 20px; }
.row.main-row { grid-template-columns: 1.7fr 1fr; }
.row.result-row { grid-template-columns: 1.7fr 1fr; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 22px; }
.panel-title { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 700; margin: 0 0 18px; }
.panel-title .tag { margin-left: auto; }

/* Stepper */
.stepper { display: flex; align-items: center; margin: 4px 0 22px; }
.step { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13.5px; }
.step .idx { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--border); font-size: 12.5px; }
.step.active { color: var(--text); }
.step.active .idx { background: var(--grad); border-color: transparent; color: #fff; }
.step.done .idx { background: rgba(52,211,153,.15); border-color: rgba(52,211,153,.4); color: var(--ok); }
.step-line { flex: 1; height: 1px; background: var(--border); margin: 0 12px; }

/* Fields */
.field { margin-bottom: 16px; }
.field > label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; font-weight: 600; }
.input-wrap { position: relative; display: flex; align-items: center; }
input[type=text], input[type=password] {
  width: 100%; background: var(--inset); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; color: var(--text); font-size: 14px; font-family: inherit;
}
input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(99,102,241,.15); }
.input-icon { position: absolute; right: 12px; color: var(--muted); cursor: pointer; background: none; border: none; font-size: 15px; }
.token-row { display: flex; gap: 10px; }
.token-row .input-wrap { flex: 1; }
.verify-msg { font-size: 12.5px; margin-top: 8px; display: none; }
.verify-msg.show { display: block; }
.verify-msg.ok { color: var(--ok); }
.verify-msg.err { color: var(--err); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 20px; border-radius: 10px; font-weight: 600; font-size: 14px; cursor: pointer; border: 1px solid transparent; font-family: inherit; transition: all .12s; }
.btn-primary { background: var(--grad); color: #fff; }
.btn-primary:hover { filter: brightness(1.12); }
.btn-cyan { background: var(--grad-cyan); color: #06202a; }
.btn-cyan:hover { filter: brightness(1.08); }
.btn-ghost { background: var(--panel-2); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--brand); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-block { width: 100%; }

.cost-bar { display: flex; align-items: center; justify-content: space-between; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--border-soft); }
.cost-bar .cost { font-size: 13.5px; color: var(--muted); }
.cost-bar .cost b { color: var(--accent); font-size: 15px; }

/* Usage stat card */
.stat-block { text-align: left; }
.stat-hero .big { font-size: 44px; font-weight: 800; line-height: 1; background: var(--grad-cyan); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stat-hero .big small { font-size: 18px; color: var(--muted); font-weight: 500; -webkit-text-fill-color: var(--muted); }
.progress { height: 8px; border-radius: 999px; background: var(--inset); overflow: hidden; margin: 14px 0 6px; }
.progress > span { display: block; height: 100%; background: var(--grad-cyan); border-radius: 999px; transition: width .4s; }
.progress-lbl { text-align: right; font-size: 12px; color: var(--muted); }
.stat-two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--border-soft); }
.stat-two .k { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.stat-two .v { font-size: 26px; font-weight: 800; }
.stat-two .v.ok { color: var(--ok); } .stat-two .v.cyan { color: var(--accent); }
.stat-two .v small { font-size: 14px; color: var(--muted); font-weight: 500; }

/* Result panels */
.result-cols { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.rcard { background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; }
.rcard h4 { margin: 0 0 12px; font-size: 13.5px; display: flex; align-items: center; gap: 7px; color: var(--text); }
.rcard h4 .cnt { margin-left: auto; font-size: 11.5px; color: var(--accent); background: rgba(34,211,238,.1); padding: 2px 8px; border-radius: 999px; }
.copy-text { font-size: 13px; color: var(--muted); line-height: 1.7; white-space: pre-wrap; max-height: 200px; overflow-y: auto; flex: 1; }
.rcard-actions { display: flex; gap: 8px; margin-top: 14px; }
.rcard-actions .btn { flex: 1; }
.video-box { position: relative; border-radius: 10px; overflow: hidden; background: #000; aspect-ratio: 16/10; display: grid; place-items: center; }
.video-box img, .video-box video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.video-box .ph { color: var(--muted-2); font-size: 13px; padding: 20px; text-align: center; }
.video-box .play { position: absolute; width: 52px; height: 52px; border-radius: 50%; background: rgba(255,255,255,.92); display: grid; place-items: center; color: #111; pointer-events: none; }
.video-box .play .icon { width: 22px; height: 22px; margin-left: 2px; }

/* Result header */
.result-head { display: flex; gap: 16px; padding: 18px 20px; margin-bottom: 18px; border-radius: 14px;
  background: linear-gradient(135deg, rgba(99,102,241,.12), rgba(34,211,238,.06)); border: 1px solid var(--border); }
.rh-main { flex: 1; min-width: 0; }
.rh-title { font-size: 17px; font-weight: 700; line-height: 1.4; margin-bottom: 10px; word-break: break-word; }
.rh-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.rh-chips .chip { font-size: 12.5px; padding: 4px 11px; border-radius: 999px; background: var(--inset); border: 1px solid var(--border-soft); color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.rh-chips .chip b { color: var(--text); font-weight: 600; }
.rh-chips .chip.brand { background: var(--brand-soft); border-color: var(--brand); color: #c7b9fe; }
.rh-chips .chip.cyan { background: rgba(34,211,238,.12); border-color: rgba(34,211,238,.3); color: var(--accent); }

.rcard h4 .cnt { margin-left: auto; }
.empty-state svg { display: block; margin: 0 auto; }

/* Image lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.88); display: none; align-items: center; justify-content: center; z-index: 300; padding: 24px; cursor: zoom-out; }
.lightbox.show { display: flex; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.video-meta { font-size: 12px; color: var(--muted); margin: 10px 0; text-align: center; }
.img-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
.img-grid a { aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--inset); }
.img-grid img { width: 100%; height: 100%; object-fit: cover; }

/* JSON preview */
.json-panel { display: flex; flex-direction: column; }
.json-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.json-view { background: var(--inset); border: 1px solid var(--border-soft); border-radius: 12px; padding: 16px; font-family: var(--mono); font-size: 12.5px; line-height: 1.6; overflow: auto; max-height: 340px; }
.json-view .ln { display: flex; }
.json-view .ln .n { width: 28px; color: var(--muted-2); user-select: none; text-align: right; padding-right: 12px; flex-shrink: 0; }
.j-key { color: #7dd3fc; } .j-str { color: #86efac; } .j-num { color: #fca5a5; } .j-punc { color: var(--muted); }
select { background: var(--inset); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 6px 10px; font-size: 12.5px; font-family: inherit; }

/* Task row */
.task-row { display: flex; align-items: center; gap: 16px; padding: 16px 22px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; font-size: 13.5px; }
.task-row .tick { width: 22px; height: 22px; border-radius: 50%; background: rgba(52,211,153,.15); color: var(--ok); display: grid; place-items: center; font-size: 12px; }
.task-row .tid { font-weight: 600; }
.task-row .st { color: var(--ok); font-size: 12px; }
.task-row .muted { color: var(--muted); }
.task-row .spacer { flex: 1; }

/* Status / empty */
.notice { padding: 12px 16px; border-radius: 10px; font-size: 13.5px; margin-bottom: 16px; display: none; }
.notice.show { display: block; }
.notice.ok { background: rgba(52,211,153,.1); color: var(--ok); border: 1px solid rgba(52,211,153,.25); }
.notice.err { background: rgba(248,113,113,.1); color: var(--err); border: 1px solid rgba(248,113,113,.25); }
.notice.load { background: rgba(99,102,241,.1); color: #a5b4fc; border: 1px solid rgba(99,102,241,.25); }
.spinner { display: inline-block; width: 13px; height: 13px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; margin-right: 7px; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { color: var(--muted-2); text-align: center; padding: 40px 20px; font-size: 13.5px; }

/* Records table */
.rec-table { width: 100%; border-collapse: collapse; }
.rec-table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12.5px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.rec-table td { padding: 12px; border-bottom: 1px solid var(--border-soft); font-size: 13px; }
.rec-table tr:hover td { background: var(--panel-2); }
.st-pill { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; }
.st-pill.ok { background: rgba(52,211,153,.12); color: var(--ok); }
.st-pill.err { background: rgba(248,113,113,.12); color: var(--err); }

.plan-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 16px; }

/* Batch dropzone */
.dropzone { border: 2px dashed var(--border); border-radius: 14px; background: var(--inset); padding: 28px 20px;
  text-align: center; cursor: pointer; transition: all .15s; }
.dropzone:hover { border-color: var(--brand); background: var(--panel-2); }
.dropzone.dragover { border-color: var(--brand-2); background: var(--brand-soft); }
.dz-idle .icon { margin-bottom: 10px; }
.dz-title { font-size: 14.5px; font-weight: 600; color: var(--text); }
.dz-sub { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.dz-file { display: flex; align-items: center; gap: 12px; text-align: left; }
.dz-fmeta { flex: 1; min-width: 0; }
.dz-fname { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dz-fsize { font-size: 12px; color: var(--muted); margin-top: 2px; }

.batch-stats { display: flex; justify-content: space-between; margin-top: 10px; font-size: 13px; color: var(--muted); flex-wrap: wrap; gap: 8px; }
.batch-stats b { color: var(--text); }
.batch-stats b.cyan { color: var(--accent); }
.dotc { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: 0; }
.dotc.ok { background: var(--ok); } .dotc.err { background: var(--err); }

.st-pill.run { background: var(--brand-soft); color: #c7b9fe; }
.st-pill.wait { background: var(--inset); color: var(--muted); }
.mini-spin { display: inline-block; width: 10px; height: 10px; border: 2px solid #c7b9fe; border-top-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; margin-right: 5px; vertical-align: -1px; }
.bi-url { color: var(--muted-2); font-size: 12px; font-family: var(--mono); margin-top: 3px; }
.bi-cover-cell { width: 64px; }
.bi-cover { width: 52px; height: 52px; object-fit: cover; border-radius: 7px; cursor: zoom-in; background: var(--inset); display: block; }
.bi-nocover { color: var(--muted-2); }
.bi-title { font-size: 13px; }
.bi-likes { color: #f0abfc; font-size: 12px; margin-left: 4px; white-space: nowrap; }
.bi-err { color: var(--err); font-size: 11.5px; margin-top: 4px; line-height: 1.4; }
.bi-dl { color: var(--accent); font-size: 12.5px; }
.bi-retry { margin-top: 6px; padding: 3px 12px; }

/* Detail modal */
.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none; align-items: center; justify-content: center; z-index: 200; padding: 20px; backdrop-filter: blur(2px); }
.modal-mask.show { display: flex; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; width: 580px; max-width: 100%; max-height: 85vh; overflow: auto; padding: 24px; }
.detail-row { display: flex; padding: 11px 0; border-bottom: 1px solid var(--border-soft); font-size: 13.5px; gap: 14px; }
.detail-row:last-child { border-bottom: 0; }
.detail-row .k { width: 120px; color: var(--muted); flex-shrink: 0; }
.detail-row .v { color: var(--text); word-break: break-all; flex: 1; }
.detail-row .v.mono { font-family: var(--mono); font-size: 12.5px; }
.detail-row .v a { color: var(--accent); }
.rec-table tbody tr { cursor: pointer; }

/* Admin login gate */
.login-mask { position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; z-index: 100; }
.login-card { width: 380px; max-width: 90vw; background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 32px; }
.login-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; margin-bottom: 6px; }
.login-brand .mark { width: 32px; height: 32px; border-radius: 9px; background: var(--grad); display: grid; place-items: center; color: #fff; }
.login-brand .mark .icon { width: 18px; height: 18px; }
.login-sub { color: var(--muted); font-size: 14px; margin: 0 0 22px; }

/* Admin KPI grid */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 20px 22px; }
.kpi .k { color: var(--muted); font-size: 13px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.kpi .k .icon { width: 15px; height: 15px; color: var(--accent); }
.kpi .v { font-size: 30px; font-weight: 800; }
.kpi .v small { font-size: 14px; color: var(--muted); font-weight: 500; }
.kpi .v.grad { background: var(--grad-cyan); -webkit-background-clip: text; background-clip: text; color: transparent; }

.create-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 14px; align-items: end; }
.create-row .field { margin: 0; }
.create-row .btn { height: 44px; }
.cnt-tag { margin-left: auto; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.table-scroll { overflow-x: auto; }
.mono-key { font-family: var(--mono); font-size: 12px; color: var(--accent); }

/* status toggle */
.toggle { display: inline-flex; align-items: center; cursor: pointer; }
.toggle input { display: none; }
.toggle .track { width: 38px; height: 20px; border-radius: 999px; background: var(--border); position: relative; transition: background .15s; }
.toggle .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.toggle input:checked + .track { background: var(--ok); }
.toggle input:checked + .track::after { transform: translateX(18px); }
.act-btns { display: flex; gap: 6px; }

@media (max-width: 980px) {
  .sidebar { display: none; }
  .main { margin-left: 0; }
  .row.main-row, .row.result-row { grid-template-columns: 1fr; }
  .result-cols { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .create-row { grid-template-columns: 1fr; }
}
