:root {
  --bg: #0b0f14;
  --bg2: #111820;
  --panel: #151c27;
  --panel2: #1a2332;
  --border: rgba(255,255,255,.08);
  --text: #eef3f9;
  --muted: #93a0b4;
  --gold: #d4a017;
  --gold2: #f0c14b;
  --accent: #6ea8ff;
  --danger: #ff6b7a;
  --ok: #3dd68c;
  --radius: 16px;
  --shadow: 0 20px 60px rgba(0,0,0,.45);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 10% -10%, #1a2740 0%, transparent 55%),
              radial-gradient(900px 500px at 100% 0%, #2a2110 0%, transparent 40%),
              var(--bg);
  color: var(--text);
}
button, textarea, input { font: inherit; }
body.from-auth { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
body.from-auth .app {
  flex: 1;
  height: auto;
  min-height: 0;
}
.auth-return-banner {
  position: sticky; top: 0; z-index: 100;
  background: linear-gradient(90deg, #1a2a4a, #243a1a 55%, #2a2410);
  border-bottom: 1px solid rgba(110,168,255,.35);
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.auth-return-banner.hidden { display: none; }
.auth-return-inner {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 10px 16px; max-width: 1400px; margin: 0 auto;
}
.auth-return-text { display: flex; flex-direction: column; gap: 2px; font-size: 13px; max-width: 820px; }
.auth-return-text strong { color: var(--gold2); font-size: 13px; }
.auth-return-text span { color: var(--muted); line-height: 1.4; }
.auth-return-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.auth-return-side {
  background: rgba(110,168,255,.12) !important;
  border-color: rgba(110,168,255,.4) !important;
  color: #cfe0ff !important;
  font-weight: 700;
  text-decoration: none;
  text-align: center;
}
.auth-return-side.hidden, .auth-return-top.hidden { display: none !important; }
.auth-return-top {
  text-decoration: none;
  border-color: rgba(110,168,255,.35) !important;
  color: #cfe0ff !important;
  font-weight: 600;
}
.app { display: grid; grid-template-columns: 300px 1fr; height: 100vh; height: 100dvh; }
.sidebar {
  background: linear-gradient(180deg, #101722, #0d1219);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px; gap: 14px;
}
.brand { display: flex; gap: 12px; align-items: center; cursor: pointer; }
.brand-logo { width: 40px; height: 40px; object-fit: contain; border-radius: 10px; background: #000; }
.brand-name { font-weight: 700; letter-spacing: .2px; }
.brand-sub { color: var(--muted); font-size: 12px; }
.btn {
  border: 1px solid var(--border); background: var(--panel2); color: var(--text);
  border-radius: 12px; padding: 10px 14px; cursor: pointer; transition: .15s ease;
}
.btn:hover { border-color: rgba(255,255,255,.18); transform: translateY(-1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--gold), #b8860b);
  border: none; color: #111; font-weight: 700;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: transparent; }
.full { width: 100%; }
.section-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin: 6px 0;
}
.agent-list { display: flex; flex-direction: column; gap: 6px; overflow: auto; max-height: 42vh; }
.agent-item {
  display: flex; gap: 10px; align-items: flex-start; text-align: left;
  padding: 10px; border-radius: 12px; border: 1px solid transparent; background: transparent;
  color: var(--text); cursor: pointer;
}
.agent-item:hover { background: rgba(255,255,255,.04); }
.agent-item.active { background: rgba(212,160,23,.12); border-color: rgba(212,160,23,.35); }
.agent-item .ico { font-size: 18px; line-height: 1.2; }
.agent-item .meta { min-width: 0; }
.agent-item .name { font-weight: 600; font-size: 13px; }
.agent-item .desc { color: var(--muted); font-size: 11px; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.agent-item .lock { margin-left: auto; font-size: 12px; opacity: .7; }
.hint { font-size: 12px; color: var(--muted); background: rgba(255,255,255,.03); border: 1px dashed var(--border); border-radius: 12px; padding: 10px; }
.sidebar-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.usage-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 12px; }
.usage-title { font-size: 12px; color: var(--muted); }
.usage-bar { height: 6px; background: rgba(255,255,255,.06); border-radius: 99px; overflow: hidden; margin: 8px 0; }
.usage-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--gold), var(--gold2)); transition: width .3s ease; }
.usage-text { font-size: 12px; }
.auth-box { display: flex; flex-direction: column; gap: 8px; }
.user-chip { font-size: 13px; color: var(--muted); padding: 4px 2px; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 56px; display: flex; align-items: center; gap: 10px;
  padding: 0 16px; border-bottom: 1px solid var(--border); backdrop-filter: blur(10px);
}
.top-agent { font-weight: 600; flex: 1; }
.top-actions { display: flex; gap: 8px; }
.icon-btn { background: transparent; border: 1px solid var(--border); color: var(--text); border-radius: 10px; width: 36px; height: 36px; cursor: pointer; }
.mobile-only { display: none; }

.chat { flex: 1; overflow: auto; padding: 24px 16px 12px; }
.welcome { max-width: 720px; margin: 8vh auto 0; text-align: center; }
.welcome-logo { width: 72px; height: 72px; object-fit: contain; margin-bottom: 12px; filter: drop-shadow(0 8px 24px rgba(212,160,23,.25)); }
.welcome h1 { font-size: clamp(1.6rem, 3vw, 2.2rem); margin: 0 0 8px; letter-spacing: -.02em; }
.welcome p { color: var(--muted); margin: 0 auto 20px; max-width: 520px; line-height: 1.5; }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 640px; margin: 0 auto; }
.chip {
  text-align: left; background: rgba(255,255,255,.03); border: 1px solid var(--border);
  color: var(--text); border-radius: 14px; padding: 12px 14px; cursor: pointer;
}
.chip:hover { border-color: rgba(212,160,23,.4); background: rgba(212,160,23,.08); }

.messages { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.msg { display: flex; gap: 12px; align-items: flex-start; }
.msg .avatar {
  width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center;
  background: var(--panel2); border: 1px solid var(--border); flex: 0 0 auto; font-size: 14px;
}
.msg.user .avatar { background: rgba(110,168,255,.15); }
.msg.assistant .avatar { background: rgba(212,160,23,.12); }
.msg .bubble {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 12px 14px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; max-width: 100%;
}
.msg.user .bubble { background: rgba(110,168,255,.08); }
.msg .who { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.typing { opacity: .7; font-style: italic; }

.composer-wrap { padding: 8px 16px 16px; }
.composer {
  max-width: 820px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end;
  background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 10px;
  box-shadow: var(--shadow);
}
.composer textarea {
  flex: 1; resize: none; max-height: 160px; min-height: 24px; border: none; outline: none;
  background: transparent; color: var(--text); padding: 8px 10px; line-height: 1.4;
}
.send {
  width: 40px; height: 40px; border-radius: 12px; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--gold), #b8860b); color: #111; font-weight: 800; font-size: 18px;
}
.send:disabled { opacity: .4; cursor: not-allowed; }
.fineprint { text-align: center; color: var(--muted); font-size: 11px; margin-top: 8px; }
.limit-banner {
  max-width: 820px; margin: 0 auto 10px; padding: 12px 14px; border-radius: 14px;
  background: rgba(255,107,122,.1); border: 1px solid rgba(255,107,122,.35); color: #ffd0d5;
}
.limit-banner button { margin-left: 8px; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center;
  z-index: 50; padding: 16px; backdrop-filter: blur(6px);
}
.modal-card {
  width: min(420px, 100%); background: #121925; border: 1px solid var(--border);
  border-radius: 20px; padding: 22px; position: relative; box-shadow: var(--shadow);
}
.modal-card.wide { width: min(860px, 100%); }
.modal-close {
  position: absolute; right: 12px; top: 10px; border: none; background: transparent;
  color: var(--muted); font-size: 24px; cursor: pointer;
}
.field {
  width: 100%; margin: 8px 0; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: #0d131c; color: var(--text);
}
.muted { color: var(--muted); }
.switch { text-align: center; margin-top: 12px; }
.switch a { color: var(--gold2); }
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-top: 14px; }
.plan-card {
  border: 1px solid var(--border); border-radius: 16px; padding: 16px; background: rgba(255,255,255,.02);
}
.plan-card h3 { margin: 0 0 6px; }
.plan-price { font-size: 28px; font-weight: 800; }
.plan-price span { font-size: 13px; color: var(--muted); font-weight: 500; }
.plan-card ul { margin: 12px 0; padding-left: 18px; color: var(--muted); font-size: 13px; }
.hidden { display: none !important; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(86vw, 320px); z-index: 40;
    transform: translateX(-105%); transition: transform .2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: inline-grid; place-items: center; }
  .suggestions { grid-template-columns: 1fr; }
}


/* realtime stream */
.stream-text { white-space: pre-wrap; }
.cursor {
  display: inline-block; width: 8px; height: 1.05em; margin-left: 2px;
  background: var(--gold2); vertical-align: text-bottom; animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.live-pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--ok);
  background: rgba(61,214,140,.08); border: 1px solid rgba(61,214,140,.25);
  border-radius: 999px; padding: 4px 10px; width: fit-content;
}
.live-pill .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 8px var(--ok); animation: pulse 1.4s ease infinite;
}
@keyframes pulse { 50% { opacity: .35; transform: scale(.85); } }
.msg .body { min-width: 0; flex: 1; }


/* Marketplace / wizard */
.nav-stack { display:flex; flex-direction:column; gap:6px; margin:10px 0; }
.nav-btn {
  text-align:left; border:1px solid transparent; background:transparent; color:var(--text);
  border-radius:12px; padding:10px 12px; cursor:pointer;
}
.nav-btn:hover { background:rgba(255,255,255,.04); }
.nav-btn.active { background:rgba(212,160,23,.12); border-color:rgba(212,160,23,.35); }
.byline { font-size:11px; color:var(--muted); text-align:center; margin-top:6px; }
.view { flex:1; display:flex; flex-direction:column; min-height:0; }
.panel { padding:20px; overflow:auto; flex:1; }
.panel.narrow { max-width:720px; margin:0 auto; width:100%; }
.panel-head { display:flex; justify-content:space-between; gap:12px; align-items:flex-start; margin-bottom:14px; flex-wrap:wrap; }
.panel h2 { margin:0 0 4px; }
.filters { display:flex; flex-direction:column; gap:10px; margin-bottom:14px; }
.tabs { display:flex; flex-wrap:wrap; gap:8px; }
.tab {
  border:1px solid var(--border); background:rgba(255,255,255,.03); color:var(--text);
  border-radius:999px; padding:7px 12px; cursor:pointer; font-size:12px;
}
.tab.active { background:rgba(212,160,23,.15); border-color:rgba(212,160,23,.4); }
.search { max-width:360px; }
.cards { display:grid; grid-template-columns:repeat(auto-fill,minmax(240px,1fr)); gap:12px; }
.card {
  border:1px solid var(--border); border-radius:16px; padding:14px; background:rgba(255,255,255,.025);
  display:flex; flex-direction:column; gap:8px; min-height:170px;
}
.card .badge { font-size:10px; letter-spacing:.08em; color:var(--gold2); text-transform:uppercase; }
.card h3 { margin:0; font-size:15px; }
.card p { margin:0; color:var(--muted); font-size:12px; flex:1; }
.card .actions { display:flex; gap:8px; margin-top:6px; }
.wizard label { display:block; margin:10px 0 4px; font-size:13px; color:var(--muted); }
.grid-2 { display:grid; grid-template-columns:1fr 1fr; gap:14px; }
.box { border:1px solid var(--border); border-radius:16px; padding:14px; background:rgba(255,255,255,.02); }
.agent-hero { margin:12px 0 16px; padding:16px; border-radius:16px; border:1px solid rgba(212,160,23,.25); background:linear-gradient(135deg,rgba(212,160,23,.08),rgba(255,255,255,.02)); }
.agent-hero code { background:rgba(0,0,0,.35); padding:2px 8px; border-radius:8px; }
.know-list { margin-top:10px; display:flex; flex-direction:column; gap:6px; max-height:220px; overflow:auto; }
.know-item { font-size:12px; color:var(--muted); border:1px dashed var(--border); border-radius:10px; padding:8px; }
.test-msgs { min-height:220px; max-height:340px; overflow:auto; display:flex; flex-direction:column; gap:8px; margin-bottom:10px; }
.test-msgs .bubble { border:1px solid var(--border); border-radius:12px; padding:8px 10px; font-size:13px; white-space:pre-wrap; }
.test-msgs .me { background:rgba(110,168,255,.08); }
.test-msgs .bot { background:rgba(212,160,23,.08); }
.composer.mini { max-width:none; margin:0; }
@media (max-width: 960px) {
  .grid-2 { grid-template-columns:1fr; }
}

.steps { display:flex; gap:8px; margin:12px 0 18px; flex-wrap:wrap; }
.step {
  flex:1; min-width:100px; text-align:center; padding:10px 8px; border-radius:12px;
  border:1px solid var(--border); color:var(--muted); font-size:12px; font-weight:600;
}
.step.active { color:#111; background:linear-gradient(135deg,var(--gold),#b8860b); border-color:transparent; }
.step.done { border-color:rgba(61,214,140,.4); color:var(--ok); }
.wiz-pane { animation: fade .2s ease; }
@keyframes fade { from{opacity:0; transform:translateY(4px)} to{opacity:1; transform:none} }
.actions-row { display:flex; gap:10px; margin-top:12px; flex-wrap:wrap; }
.scan-results { margin-top:12px; display:flex; flex-direction:column; gap:8px; max-height:260px; overflow:auto; }
.scan-item { border:1px solid var(--border); border-radius:12px; padding:10px; font-size:12px; color:var(--muted); }
.scan-item b { color:var(--text); }
.docs-preview {
  margin-top:12px; max-height:320px; overflow:auto; white-space:pre-wrap; font-size:12px;
  background:rgba(0,0,0,.35); border:1px solid var(--border); border-radius:12px; padding:12px; color:#d7e0ec;
}
