:root {
  --bg: #0a0c18;
  --bg2: #10132a;
  --panel: #161a35;
  --panel2: #1e2344;
  --panel3: #262c52;
  --border: #2b3157;
  --border-soft: #232849;
  --text: #eceffb;
  --muted: #9aa3c7;
  --accent: #5b8cff;
  --accent2: #8a6cff;
  --green: #2dd4a0;
  --orange: #ffb454;
  --red: #ff6b7a;
  --yellow: #ffd166;
  --cyan: #4cc9f0;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(91, 140, 255, 0.14), transparent 60%),
    radial-gradient(900px 420px at 0% 0%, rgba(138, 108, 255, 0.12), transparent 55%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body { display: flex; flex-direction: column; }

/* ---------- Header ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 26px;
  border-bottom: 1px solid var(--border-soft);
  background: linear-gradient(180deg, rgba(30, 35, 68, 0.6), transparent);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  font-size: 26px;
  border-radius: 13px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 6px 20px rgba(91, 140, 255, 0.4);
}
.brand h1 { margin: 0; font-size: 19px; font-weight: 800; letter-spacing: 0.2px; }
.brand p { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); }

.top-actions { display: flex; align-items: center; gap: 12px; position: relative; }
.action-menu { display: flex; align-items: center; gap: 12px; }
.menu-btn { display: none; }

.server-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--muted);
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
}
.server-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.server-status.ok { color: var(--green); border-color: rgba(45, 212, 160, 0.4); }
.server-status.ok .dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.server-status.err { color: var(--red); border-color: rgba(255, 107, 122, 0.4); }
.server-status.err .dot { background: var(--red); }

/* ---------- Stats ---------- */
.stats-wrap { padding: 18px 26px 0; }
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  max-width: 1180px;
  margin: 0 auto;
}
.stat {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel), var(--panel2));
  box-shadow: var(--shadow);
}
.stat .s-icon {
  width: 42px; height: 42px;
  border-radius: 11px;
  display: grid; place-items: center;
  font-size: 20px;
  flex-shrink: 0;
}
.stat .s-num { font-size: 24px; font-weight: 800; line-height: 1; }
.stat .s-label { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.stat.total .s-icon { background: rgba(91, 140, 255, 0.16); }
.stat.waiting .s-icon { background: rgba(255, 180, 84, 0.16); }
.stat.active .s-icon { background: rgba(255, 209, 102, 0.14); }
.stat.done .s-icon { background: rgba(45, 212, 160, 0.14); }
.stat.waiting .s-num { color: var(--orange); }
.stat.active .s-num { color: var(--yellow); }
.stat.done .s-num { color: var(--green); }

/* ---------- Layout ---------- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 330px 1fr;
  gap: 22px;
  padding: 18px 26px 26px;
  min-height: 0;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}

.sidebar {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.task-list { display: flex; flex-direction: column; gap: 8px; }

.task-item {
  padding: 12px 14px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: var(--panel2);
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
}
.task-item:hover { border-color: var(--accent); transform: translateY(-1px); }
.task-item.active { border-color: var(--accent); background: linear-gradient(135deg, rgba(91,140,255,0.12), rgba(138,108,255,0.08)); box-shadow: inset 0 0 0 1px rgba(91,140,255,0.25); }
.task-item .t-title { font-weight: 600; font-size: 14px; margin-bottom: 6px; line-height: 1.35; }
.task-item .t-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.task-item .t-ais { display: flex; gap: 4px; margin-bottom: 6px; font-size: 13px; }

.detail { overflow-y: auto; padding: 2px; }

/* ---------- Empty / onboarding ---------- */
.empty {
  height: 100%;
  min-height: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
  gap: 12px;
}
.empty-icon {
  font-size: 56px;
  width: 96px; height: 96px;
  display: grid; place-items: center;
  border-radius: 24px;
  background: linear-gradient(135deg, rgba(91,140,255,0.16), rgba(138,108,255,0.16));
  border: 1px solid var(--border);
  color: var(--accent);
}

.onboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 8px;
  max-width: 620px;
  width: 100%;
}
.onboard .ob-step {
  padding: 18px 16px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--panel);
  text-align: left;
}
.ob-step .ob-num {
  width: 26px; height: 26px;
  border-radius: 8px;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700;
  background: var(--accent); color: #fff;
  margin-bottom: 10px;
}
.ob-step b { display: block; font-size: 14px; margin-bottom: 4px; }
.ob-step span { font-size: 12.5px; color: var(--muted); line-height: 1.5; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--panel3);
  color: var(--text);
  padding: 10px 15px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13.5px;
  font-family: inherit;
  font-weight: 500;
  transition: filter .12s, background .12s, border-color .12s, transform .08s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-color: transparent;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(91, 140, 255, 0.35);
}
.btn.ghost { background: transparent; }
.btn.danger { background: rgba(255, 107, 122, 0.12); border-color: rgba(255, 107, 122, 0.5); color: var(--red); }
.btn.small { padding: 6px 11px; font-size: 12.5px; }
.btn.full { width: 100%; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
}
.badge.pending { background: rgba(154, 163, 199, 0.14); color: var(--muted); }
.badge.running { background: rgba(255, 209, 102, 0.14); color: var(--yellow); }
.badge.awaiting_approval { background: rgba(255, 180, 84, 0.16); color: var(--orange); border-color: rgba(255, 180, 84, 0.5); }
.badge.completed { background: rgba(45, 212, 160, 0.14); color: var(--green); }
.badge.stopped { background: rgba(154, 163, 199, 0.14); color: var(--muted); }
.badge.error { background: rgba(255, 107, 122, 0.14); color: var(--red); border-color: rgba(255, 107, 122, 0.5); }

/* ---------- Detail ---------- */
.detail-head { margin-bottom: 18px; }
.detail-title { font-size: 23px; font-weight: 800; margin: 0 0 6px; }
.detail-sub { color: var(--muted); font-size: 13.5px; margin: 0 0 12px; white-space: pre-wrap; line-height: 1.55; }
.detail-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ---------- Pipeline ---------- */
.pipeline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 16px 0;
}
.pipe-step {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  font-size: 13px;
  font-weight: 500;
}
.pipe-step .num {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
  background: var(--panel3); color: var(--muted);
  flex-shrink: 0;
}
.pipe-step.done { border-color: rgba(45, 212, 160, 0.4); background: rgba(45, 212, 160, 0.06); }
.pipe-step.done .num { background: var(--green); color: #06251b; }
.pipe-step.current { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(91, 140, 255, 0.18); background: rgba(91, 140, 255, 0.08); }
.pipe-step.current .num { background: var(--accent); color: #fff; }
.pipe-step.error { border-color: var(--red); background: rgba(255, 107, 122, 0.06); }
.pipe-step.error .num { background: var(--red); color: #fff; }
.pipe-arrow { color: var(--muted); opacity: 0.5; font-size: 15px; }

/* ---------- Steps ---------- */
.steps { display: flex; flex-direction: column; gap: 14px; }
.step {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.step-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--panel2);
  font-size: 13px;
  flex-wrap: wrap;
}
.step-head .who { font-weight: 700; }
.step-head .when { color: var(--muted); font-size: 12px; margin-left: auto; }
.step-body { padding: 16px; }
.step-body .output { white-space: normal; word-break: break-word; line-height: 1.6; font-size: 14px; color: #dbe1f5; }
.step-body .err { color: var(--red); white-space: pre-wrap; font-size: 13.5px; }
.step.pending-approval { border-color: var(--orange); box-shadow: 0 0 0 2px rgba(255, 180, 84, 0.14); }

/* Markdown */
.output p { margin: 0 0 9px; }
.output ul, .output ol { margin: 4px 0 12px; padding-left: 24px; }
.output li { margin: 3px 0; }
.output h2 { font-size: 17px; margin: 14px 0 6px; }
.output h3 { font-size: 15px; margin: 12px 0 6px; }
.output h4 { font-size: 14px; margin: 10px 0 5px; }
.output code {
  background: var(--panel3);
  padding: 1px 7px;
  border-radius: 6px;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 13px;
}
.output pre.code {
  background: #0b0e1c;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px;
  overflow-x: auto;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
}
.output a { color: var(--accent); }
.output .sp { height: 6px; }
.output blockquote {
  margin: 8px 0;
  padding: 4px 14px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

.copy-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 7px;
  font-size: 11px;
  padding: 4px 9px;
  cursor: pointer;
  font-family: inherit;
}
.copy-btn:hover { color: var(--text); border-color: var(--accent); }

/* ---------- Modals ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 14, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-box {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px;
  box-shadow: var(--shadow);
  animation: pop .18s ease;
}
.modal-x {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.modal-x:hover { background: rgba(255, 255, 255, .08); color: var(--text); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-box h2 { margin: 0 0 12px; font-size: 18px; font-weight: 700; }
.modal-box label { display: block; margin: 14px 0 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
.modal-box input[type="text"],
.modal-box input[type="password"],
.modal-box input[type="number"],
.modal-box textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg2);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  transition: border-color .15s;
}
.modal-box input:focus, .modal-box textarea:focus { outline: none; border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.hint { font-size: 12.5px; color: var(--muted); line-height: 1.55; margin: 6px 0; }
.hint code { background: var(--panel3); padding: 1px 6px; border-radius: 5px; font-family: "JetBrains Mono", monospace; }

/* Pipeline builder */
.pipeline-builder { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.pb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg2);
  font-size: 13.5px;
}
.pb-item .pb-num { color: var(--muted); font-size: 12px; width: 18px; font-family: "JetBrains Mono", monospace; }
.pb-item .pb-label { flex: 1; font-weight: 600; }
.pb-item .pb-ctrl { display: flex; gap: 4px; }
.pb-item button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 7px;
  cursor: pointer;
  width: 28px; height: 28px;
  font-size: 13px;
}
.pb-item button:hover { color: var(--text); border-color: var(--accent); }
.pb-item button:disabled { opacity: 0.3; cursor: not-allowed; }
.add-ai-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.pb-item-col { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg2); padding: 8px 10px; }
.pb-item-col .pb-item { border: none; background: transparent; padding: 0 0 8px; }
.pb-extra { display: flex; gap: 8px; flex-wrap: wrap; }
.pb-extra select, .pb-extra input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.pb-extra input { flex: 1; min-width: 180px; }
.role-tag { font-size: 11px; color: var(--cyan); background: rgba(76, 201, 240, 0.12); padding: 1px 7px; border-radius: 999px; margin-left: 4px; }
.analyze-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; margin-top: 10px; }
.analyze-card { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg2); padding: 12px 13px; }
.analyze-card .ps-head { font-weight: 700; margin-bottom: 6px; }
.analyze-text { font-size: 12.5px; color: var(--muted); line-height: 1.5; white-space: pre-wrap; }
.analyze-card .btn { margin-top: 8px; }

/* Provider settings */
.provider-setting {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 15px;
  margin-bottom: 12px;
  background: var(--bg2);
}
.provider-setting .ps-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-weight: 700; }
.provider-setting .ps-head .vendor { color: var(--muted); font-weight: 400; font-size: 12px; }
.provider-setting .key-ok { color: var(--green); font-size: 12px; font-weight: 600; }
.provider-setting .key-miss { color: var(--orange); font-size: 12px; font-weight: 600; }
.provider-setting label { display: block; margin: 11px 0 5px; font-size: 12px; color: var(--muted); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel3);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 13px 20px;
  font-size: 14px;
  z-index: 100;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.55);
  max-width: 80vw;
}
.toast.hidden { display: none; }
.toast.ok { border-color: var(--green); }
.toast.err { border-color: var(--red); }

/* ---------- Spinner ---------- */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.overlay-note {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 15px;
  border-radius: 11px;
  border: 1px solid rgba(255, 209, 102, 0.4);
  background: rgba(255, 209, 102, 0.08);
  color: var(--yellow);
  font-size: 13.5px;
  margin: 12px 0;
  line-height: 1.5;
}

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--panel3); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--border); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Login ---------- */
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(1100px 520px at 50% -10%, rgba(91, 140, 255, 0.2), transparent 60%),
    radial-gradient(900px 420px at 0% 100%, rgba(138, 108, 255, 0.14), transparent 55%),
    var(--bg);
}
.auth-screen.hidden { display: none; }
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 34px 30px;
  box-shadow: var(--shadow);
  text-align: center;
  animation: pop .2s ease;
}
.auth-logo {
  width: 60px; height: 60px;
  margin: 0 auto 14px;
  display: grid; place-items: center;
  font-size: 32px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  box-shadow: 0 8px 24px rgba(91, 140, 255, 0.4);
}
.auth-card h1 { margin: 0; font-size: 21px; font-weight: 800; }
.auth-sub { color: var(--muted); margin: 6px 0 20px; font-size: 13.5px; }
.auth-card input {
  width: 100%;
  padding: 11px 13px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg2);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
.auth-card input:focus { outline: none; border-color: var(--accent); }
.login-err { color: var(--red); font-size: 13px; min-height: 18px; margin: 10px 0 0; }

/* ---------- Account modal ---------- */
.account-self {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 15px;
  background: var(--bg2);
}
.account-self .ps-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-weight: 700; }
.account-self .ps-head .vendor { color: var(--muted); font-weight: 400; font-size: 12px; }
.account-self input { margin-top: 8px; }

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg2);
  margin-bottom: 6px;
}
.user-row .u-info { display: flex; align-items: center; gap: 8px; font-size: 13.5px; flex-wrap: wrap; }
.user-row .u-actions { display: flex; gap: 6px; flex-shrink: 0; }
.share-select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg2);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}

/* ---------- Usage ---------- */
.usage-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 4px;
}
.u-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg2);
  padding: 14px 12px;
  text-align: center;
}
.u-card .u-num { font-size: 22px; font-weight: 800; }
.u-card .u-label { font-size: 12px; color: var(--muted); margin-top: 4px; }
.usage-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.usage-table th, .usage-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border-soft); }
.usage-table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.usage-table tr.me td { background: rgba(91, 140, 255, 0.08); }

/* ---------- Studio ---------- */
.modal-box.wide { max-width: 680px; }
.studio-tabs { display: flex; gap: 8px; margin: 14px 0; }
.studio-tabs .tab {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg2);
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  font-weight: 600;
}
.studio-tabs .tab.active { background: linear-gradient(135deg, var(--accent), var(--accent2)); border-color: transparent; color: #fff; }
.gen-options { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-top: 10px; }
.gen-options label { margin: 0; font-size: 12.5px; }
.gen-options select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg2);
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
}
.gen-status { margin-top: 12px; color: var(--yellow); font-size: 13.5px; display: flex; align-items: center; gap: 8px; min-height: 20px; }
.gen-status.err { color: var(--red); }
.gen-result { margin-top: 12px; }
.gen-result img, .gen-result video { max-width: 100%; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.g-item {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: var(--bg2);
  overflow: hidden;
}
.g-item .g-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 8px 10px;
  font-size: 11.5px;
  color: var(--muted);
}
.g-item .g-owner { margin-left: auto; }
.g-item .g-time { font-size: 11px; }
.g-dims { font-size: 11.5px; color: var(--muted); font-family: "JetBrains Mono", monospace; }

/* ---------- Code Agent ---------- */
.agent-log {
  margin-top: 12px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: #0b0e1c;
  padding: 12px;
  max-height: 320px;
  overflow-y: auto;
  font-size: 13px;
}
.al-status { color: var(--muted); margin: 4px 0; }
.al-tool { color: var(--cyan); margin: 8px 0 2px; font-family: "JetBrains Mono", monospace; font-size: 12.5px; }
.al-result pre { margin: 0 0 8px; padding: 8px 10px; background: var(--bg2); border-radius: 6px; white-space: pre-wrap; word-break: break-word; color: #c6cdea; }
.al-final { margin-top: 10px; padding: 10px 12px; border: 1px solid rgba(45, 212, 160, 0.35); border-radius: 8px; background: rgba(45, 212, 160, 0.07); }
.al-final.err { border-color: var(--red); background: rgba(255, 107, 122, 0.07); }
.al-final.perm { border-color: var(--orange); background: rgba(255, 180, 84, 0.08); }
.perm-msg { margin-bottom: 10px; line-height: 1.5; word-break: break-word; }
.perm-actions { display: flex; gap: 8px; }
.agent-files { display: flex; flex-wrap: wrap; gap: 6px; max-height: 160px; overflow-y: auto; }
.af-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  padding: 5px 9px;
  font-size: 12.5px;
  cursor: pointer;
  font-family: "JetBrains Mono", monospace;
}
.af-item:hover { border-color: var(--accent); }
.af-item.dir { opacity: 0.6; cursor: default; }
.agent-fileview {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0b0e1c;
  padding: 12px;
  max-height: 260px;
  overflow: auto;
  font-family: "JetBrains Mono", monospace;
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
}
.agent-fileview.hidden { display: none; }

/* ---------- Responsive (mobile) ---------- */
@media (max-width: 900px) {
  .topbar { padding: 12px 16px; }
  .brand h1 { font-size: 17px; }
  .brand p { display: none; }
  #serverStatusText { display: none; }
  .menu-btn { display: inline-flex; }
  .action-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 16px;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    min-width: 190px;
    padding: 8px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    display: none;
    z-index: 60;
  }
  .action-menu.open { display: flex; }
  .action-menu .btn { width: 100%; justify-content: flex-start; text-align: left; padding: 11px 14px; }

  .stats-wrap { padding: 12px 16px 0; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 12px 14px; gap: 10px; }
  .stat .s-icon { width: 36px; height: 36px; font-size: 17px; }
  .stat .s-num { font-size: 20px; }
  .stat .s-label { font-size: 11.5px; }

  .layout { grid-template-columns: 1fr; padding: 12px 16px 20px; gap: 14px; }
  .sidebar { max-height: 32vh; }
  .detail { padding: 0; }

  .detail-title { font-size: 20px; }
  .detail-sub { font-size: 13px; }
  .pipeline { gap: 6px; }
  .pipe-step { padding: 6px 10px; font-size: 12.5px; }
  .detail-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .detail-actions .btn { width: 100%; }

  .modal { padding: 0; align-items: flex-end; }
  .modal-box { max-width: 100%; max-height: 92vh; border-radius: 18px 18px 0 0; padding: 18px; }
  .modal-box.wide { max-width: 100%; }
  .modal-box h2 { font-size: 17px; }

  .onboard { grid-template-columns: 1fr; }
  .analyze-results { grid-template-columns: 1fr; }
  .pb-item-col { padding: 8px; }
  .pb-extra { flex-direction: column; gap: 6px; }
  .pb-extra input, .pb-extra select { width: 100%; min-width: 0; }

  .agent-log { max-height: 44vh; }
  .gallery { grid-template-columns: repeat(2, 1fr); }
  .usage-cards { grid-template-columns: repeat(2, 1fr); }

  /* Chống iOS zoom khi focus input + nút to dễ chạm */
  .modal-box input, .modal-box textarea, .modal-box select,
  .auth-card input, .gen-options select, .pb-extra input, .pb-extra select {
    font-size: 16px;
  }
  .btn { padding: 11px 15px; }
  .btn.small { padding: 8px 12px; }
}

@media (max-width: 480px) {
  .topbar { padding: 10px 12px; }
  .brand h1 { font-size: 16px; }
  .logo { width: 40px; height: 40px; font-size: 22px; border-radius: 11px; }
  .stats-wrap { padding: 10px 12px 0; }
  .stats { gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat .s-num { font-size: 18px; }
  .layout { padding: 10px 12px 18px; }
  .detail-actions { grid-template-columns: 1fr; }
  .gallery { grid-template-columns: 1fr; }
  .usage-cards { grid-template-columns: repeat(2, 1fr); }
  .modal-box { padding: 16px; }
  .login-err { font-size: 12.5px; }
}

/* Kéo-thả pipeline */
.pb-item-col { cursor: grab; }
.pb-item-col:active { cursor: grabbing; }
.pb-drop { outline: 2px dashed #6c5ce7; outline-offset: 4px; border-radius: 12px; }

/* Nút sửa pipeline trong chi tiết tác vụ */
.pipe-ctrl { display: inline-flex; gap: 2px; margin-left: 6px; }
.pipe-ctrl button { border: 0; background: rgba(255,255,255,.08); color: #8b94b8; border-radius: 6px; padding: 1px 5px; font-size: 11px; cursor: pointer; }
.pipe-ctrl button:hover { color: #e8ebf7; }
.pipe-ctrl button:disabled { opacity: .35; cursor: default; }

/* Phân công việc cho từng AI trong chi tiết tác vụ */
.pipe-edit { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.pe-title { font-size: 12.5px; color: #8b94b8; margin-bottom: 2px; }
.pipe-edit-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pe-ai { min-width: 130px; font-size: 12.5px; font-weight: 600; }
.pipe-edit-row select { min-width: 160px; }
.pipe-edit-row input { flex: 1; min-width: 200px; }

/* Chat trong tác vụ */
.task-chat { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 12px; }
.tc-title { font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.tc-list { display: flex; flex-direction: column; gap: 6px; max-height: 280px; overflow-y: auto; margin-bottom: 8px; }
.tc-msg { padding: 8px 10px; border-radius: 10px; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
.tc-msg.user { background: #2a2350; border: 1px solid #4a3f8a; align-self: flex-end; }
.tc-msg.assistant { background: var(--panel2); border: 1px solid var(--border); }
.tc-input { display: flex; gap: 8px; align-items: center; }
.tc-input input { flex: 1; }

/* Sửa yêu cầu tác vụ */
.task-edit { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.task-edit label { font-size: 12.5px; color: #8b94b8; margin-top: 4px; }
.task-edit input, .task-edit textarea { width: 100%; }

/* Chat tự do (giống DSH) */
.chat-modal {
  display: flex; width: 100%; max-width: 1100px; height: 82vh; padding: 0;
  overflow: hidden; border-radius: 16px;
}
.cm-side { width: 250px; border-right: 1px solid var(--border); padding: 12px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.cm-list { display: flex; flex-direction: column; gap: 6px; }
.cm-item { padding: 9px 10px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; }
.cm-item:hover { background: var(--panel2); }
.cm-item.active { background: var(--panel2); border-color: var(--accent); }
.cm-item-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cm-item-sub { font-size: 11.5px; color: var(--muted); }
.cm-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.cm-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.cm-msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.cm-msg { max-width: 85%; padding: 10px 12px; border-radius: 12px; font-size: 13.5px; overflow-wrap: anywhere; }
.cm-msg.user { align-self: flex-end; background: var(--accent); }
.cm-msg.assistant { align-self: flex-start; background: var(--panel2); border: 1px solid var(--border); }
.cm-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); align-items: flex-end; }
.cm-input textarea { flex: 1; resize: none; }
@media (max-width: 760px) {
  .cm-side { display: none; }
  .chat-modal { height: 92vh; }
}

/* Chat: chừa chỗ nút X, gom nhóm công cụ */
.cm-head { padding-right: 46px; }
.cm-tools { display: flex; align-items: center; gap: 10px; }
.cm-tools select { max-width: 130px; }

/* Dự án: chat là trung tâm, quy trình thu gọn */
.workflow { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 10px; }
.workflow summary { cursor: pointer; font-weight: 700; font-size: 13px; margin-bottom: 10px; color: var(--text); }
.task-chat { margin-top: 6px; }
.tc-list { min-height: 240px; max-height: 55vh; }
