:root {
  --primary: #ff6a00;
  --primary-hover: #e85f00;
  --primary-light: #fff3e9;
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e6e8eb;
  --text: #1f2329;
  --text-2: #646a73;
  --text-3: #8f959e;
  --green: #34c759;
  --red: #f54a45;
  --blue: #1456f0;
  --radius: 8px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px; color: var(--text); background: var(--bg);
}
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 14px; color: var(--text); }
a { color: var(--blue); text-decoration: none; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #f7f8fa 0%, #eef1f5 50%, #fdf1e7 100%);
}
.login-card {
  width: 400px; background: var(--panel); border-radius: 12px; padding: 40px 36px;
  box-shadow: 0 8px 40px rgba(31, 35, 41, .08); border: 1px solid var(--border);
}
.login-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.logo-mark {
  width: 36px; height: 36px; border-radius: 8px; background: var(--primary);
  color: #fff; font-weight: 700; font-size: 18px; display: flex; align-items: center; justify-content: center;
}
.login-logo b { font-size: 18px; }
.login-sub { color: var(--text-2); margin-bottom: 28px; font-size: 13px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.field input {
  width: 100%; height: 40px; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0 12px; outline: none; transition: border-color .15s;
}
.field input:focus { border-color: var(--primary); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  border-radius: var(--radius); height: 36px; padding: 0 16px; font-size: 14px;
  transition: all .15s;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn-primary:disabled { background: #ffb98a; border-color: #ffb98a; cursor: not-allowed; }
.btn-block { width: 100%; height: 42px; font-size: 15px; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 6px; }
.btn-danger:hover { border-color: var(--red); color: var(--red); }
.login-error { color: var(--red); font-size: 13px; min-height: 20px; margin: 4px 0 8px; }
.login-foot { margin-top: 24px; text-align: center; color: var(--text-3); font-size: 12px; }

/* ---------- shell ---------- */
.shell { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  height: 56px; background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 20px; gap: 14px; flex-shrink: 0;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; }
.topbar .brand .logo-mark { width: 30px; height: 30px; font-size: 15px; border-radius: 6px; }
.topbar .brand b { font-size: 15px; }
.topbar .divider { width: 1px; height: 20px; background: var(--border); }
.topbar .app-name { font-size: 14px; color: var(--text-2); }
.region-chip {
  font-size: 12px; color: var(--text-2); background: var(--bg); border: 1px solid var(--border);
  padding: 3px 10px; border-radius: 20px; display: inline-flex; align-items: center; gap: 5px;
}
.region-chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
.topbar .spacer { flex: 1; }
.token-chip {
  display: flex; align-items: center; gap: 8px; background: var(--primary-light);
  border: 1px solid #ffd9bf; border-radius: 20px; padding: 5px 14px; font-size: 13px;
}
.token-chip .coin { width: 16px; height: 16px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 10px; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.token-chip b { color: var(--primary); font-variant-numeric: tabular-nums; }
.token-chip .total { color: var(--text-3); font-size: 12px; }
.user-menu { display: flex; align-items: center; gap: 10px; }
.user-menu .uname { font-size: 13px; color: var(--text-2); }
.role-badge { font-size: 11px; background: #eef3ff; color: var(--blue); border-radius: 4px; padding: 2px 6px; }
.role-badge.trainer { background: var(--primary-light); color: var(--primary); }

.body { display: flex; flex: 1; overflow: hidden; }
.sidebar {
  width: 232px; background: var(--panel); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 12px 8px; flex-shrink: 0;
}
.side-group { margin-bottom: 6px; }
.side-group-title { font-size: 12px; color: var(--text-3); padding: 8px 12px 4px; }
.side-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: var(--radius);
  cursor: pointer; color: var(--text); font-size: 13px; transition: background .12s;
}
.side-item:hover { background: var(--bg); }
.side-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.side-item .m-icon { width: 22px; height: 22px; border-radius: 5px; display: flex; align-items: center; justify-content: center; font-size: 12px; flex-shrink: 0; }
.m-icon.image { background: #e8f7ee; color: #00a854; }
.m-icon.video { background: #eef3ff; color: var(--blue); }
.m-icon.tts { background: #f3e8ff; color: #8b5cf6; }
.m-icon.asr { background: #fff7e6; color: #d48806; }
.m-icon.realtime { background: #ffece8; color: var(--red); }
.side-item .m-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-sep { height: 1px; background: var(--border); margin: 10px 12px; }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.main-head {
  padding: 14px 24px; background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: baseline; gap: 12px; flex-shrink: 0;
}
.main-head h2 { font-size: 16px; }
.main-head .desc { color: var(--text-2); font-size: 13px; }
.main-head .price { margin-left: auto; color: var(--text-3); font-size: 12px; }
.work-area { flex: 1; display: flex; overflow: hidden; }
.center { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.results { flex: 1; overflow-y: auto; padding: 20px 24px; }
.empty-tip { color: var(--text-3); text-align: center; padding: 60px 20px; font-size: 13px; line-height: 2; }

.params {
  width: 296px; background: var(--panel); border-left: 1px solid var(--border);
  overflow-y: auto; padding: 16px; flex-shrink: 0;
}
.params h3 { font-size: 14px; margin-bottom: 14px; }
.p-field { margin-bottom: 18px; }
.p-field > label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 8px; }
.p-field select, .p-field input[type=number], .p-field input[type=text], .p-field textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px; outline: none;
}
.p-field textarea { resize: vertical; min-height: 60px; }
.p-field select:focus, .p-field input:focus, .p-field textarea:focus { border-color: var(--primary); }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; font-size: 13px;
  background: var(--panel); color: var(--text-2);
}
.chip.active { border-color: var(--primary); color: var(--primary); background: var(--primary-light); font-weight: 600; }
.switch-row { display: flex; align-items: center; justify-content: space-between; }
.switch { position: relative; width: 36px; height: 20px; background: #c9cdd4; border-radius: 20px; border: none; transition: background .15s; }
.switch.on { background: var(--primary); }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch.on::after { left: 18px; }
.range-row { display: flex; align-items: center; gap: 10px; }
.range-row input[type=range] { flex: 1; accent-color: var(--primary); }
.range-row .val { font-size: 13px; color: var(--text); min-width: 36px; text-align: right; font-variant-numeric: tabular-nums; }
.p-note { font-size: 12px; color: var(--text-3); line-height: 1.7; }

.prompt-bar {
  border-top: 1px solid var(--border); background: var(--panel); padding: 14px 24px; flex-shrink: 0;
}
.prompt-box { display: flex; gap: 10px; align-items: flex-end; }
.prompt-box textarea {
  flex: 1; border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px;
  min-height: 64px; max-height: 160px; resize: vertical; outline: none; line-height: 1.6;
}
.prompt-box textarea:focus { border-color: var(--primary); }
.gen-btn { height: 42px; padding: 0 22px; font-size: 14px; flex-shrink: 0; }
.gen-cost { font-size: 11px; opacity: .85; }

/* ---------- results ---------- */
.work-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px; margin-bottom: 14px;
}
.work-card .wc-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 12px; color: var(--text-3); }
.status-chip { font-size: 11px; border-radius: 4px; padding: 2px 8px; }
.status-chip.succeeded { background: #e8f7ee; color: #00a854; }
.status-chip.pending, .status-chip.running { background: #fff7e6; color: #d48806; }
.status-chip.failed { background: #ffece8; color: var(--red); }
.wc-prompt { font-size: 13px; color: var(--text-2); margin-bottom: 10px; line-height: 1.6; word-break: break-all; }
.img-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.img-grid img { max-width: 320px; max-height: 320px; border-radius: 8px; border: 1px solid var(--border); cursor: zoom-in; }
.work-card video { max-width: 480px; width: 100%; border-radius: 8px; background: #000; }
.work-card audio { width: 100%; max-width: 480px; }
.wc-text { background: var(--bg); border-radius: 8px; padding: 12px; font-size: 13px; line-height: 1.8; white-space: pre-wrap; word-break: break-all; }
.wc-error { color: var(--red); font-size: 13px; }
.wc-tokens { margin-left: auto; color: var(--primary); font-size: 12px; font-variant-numeric: tabular-nums; }
.spinner {
  width: 18px; height: 18px; border: 2px solid #ffd9bf; border-top-color: var(--primary);
  border-radius: 50%; animation: spin 1s linear infinite; display: inline-block; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress-note { color: var(--text-3); font-size: 13px; padding: 8px 0; }

/* ---------- upload ---------- */
.dropzone {
  border: 1.5px dashed var(--border); border-radius: 10px; background: var(--panel);
  padding: 22px; text-align: center; color: var(--text-3); font-size: 13px; cursor: pointer;
  transition: border-color .15s; margin-bottom: 12px;
}
.dropzone:hover, .dropzone.drag { border-color: var(--primary); color: var(--primary); }
.upload-previews { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.upload-previews .thumb { position: relative; }
.upload-previews img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.upload-previews .rm {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--red); color: #fff; border: none; font-size: 12px; line-height: 1;
}

/* ---------- realtime ---------- */
.rt-wrap { display: flex; flex-direction: column; height: 100%; }
.rt-transcript { flex: 1; overflow-y: auto; padding: 20px 24px; }
.rt-msg { max-width: 70%; margin-bottom: 12px; padding: 10px 14px; border-radius: 12px; font-size: 14px; line-height: 1.6; white-space: pre-wrap; }
.rt-msg.user { margin-left: auto; background: var(--primary-light); border: 1px solid #ffd9bf; }
.rt-msg.bot { background: var(--panel); border: 1px solid var(--border); }
.rt-msg .who { font-size: 11px; color: var(--text-3); margin-bottom: 4px; }
.rt-controls { border-top: 1px solid var(--border); background: var(--panel); padding: 16px 24px; display: flex; align-items: center; gap: 16px; }
.mic-btn {
  width: 56px; height: 56px; border-radius: 50%; border: none; background: var(--primary); color: #fff;
  font-size: 22px; display: flex; align-items: center; justify-content: center; transition: all .15s;
}
.mic-btn.off { background: #c9cdd4; }
.mic-btn.live { background: var(--red); animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(245,74,69,.4);} 50% { box-shadow: 0 0 0 12px rgba(245,74,69,0);} }
.rt-status { font-size: 13px; color: var(--text-2); }
.rt-level { width: 120px; height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.rt-level > div { height: 100%; width: 0; background: var(--green); transition: width .08s; }

/* ---------- admin ---------- */
.admin-wrap { flex: 1; overflow-y: auto; padding: 20px 24px; }
.admin-tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.admin-tab { border: none; background: none; padding: 8px 16px; font-size: 14px; color: var(--text-2); border-radius: 6px; }
.admin-tab.active { background: var(--panel); color: var(--primary); font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input { height: 34px; border: 1px solid var(--border); border-radius: 6px; padding: 0 10px; width: 140px; outline: none; }
.toolbar select { height: 34px; border: 1px solid var(--border); border-radius: 6px; padding: 0 8px; outline: none; }
table.grid { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
table.grid th, table.grid td { text-align: left; padding: 10px 14px; font-size: 13px; border-bottom: 1px solid var(--border); }
table.grid th { background: #fafbfc; color: var(--text-2); font-weight: 600; font-size: 12px; }
table.grid tr:last-child td { border-bottom: none; }
table.grid td.num { font-variant-numeric: tabular-nums; }
.quota-input { width: 96px; height: 28px; border: 1px solid var(--border); border-radius: 6px; padding: 0 8px; font-size: 13px; outline: none; }
.quota-input:focus { border-color: var(--primary); }
.bar { width: 90px; height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 8px; }
.bar > div { height: 100%; background: var(--primary); }
.bar > div.over { background: var(--red); }

/* ---------- modal & toast ---------- */
.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: var(--panel); border-radius: 12px; padding: 24px; width: 380px; }
.modal h3 { font-size: 15px; margin-bottom: 16px; }
.modal .field input { width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
#toasts { position: fixed; top: 68px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--primary);
  border-radius: 8px; padding: 10px 16px; font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,.1);
  max-width: 360px; animation: slidein .2s;
}
.toast.error { border-left-color: var(--red); }
.toast.success { border-left-color: var(--green); }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.8); display: flex; align-items: center; justify-content: center; z-index: 150; cursor: zoom-out; }
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 6px; }

@media (max-width: 900px) {
  .params { display: none; }
  .sidebar { width: 180px; }
}