:root {
  color-scheme: dark;
  --bg: #07090f;
  --bg2: #0b0e17;
  --panel: #0e111b;
  --panel2: #121624;
  --panel3: #161a28;
  --line: rgba(255,255,255,.08);
  --line2: rgba(255,255,255,.12);
  --muted: #8b91a7;
  --text: #eef0fa;
  --text2: #c5cada;
  --purple: #9b7bff;
  --purple2: #7c5cff;
  --cyan: #65d9e8;
  --green: #58e0a1;
  --pink: #f472b6;
  --gold: #fbbf24;
  --red: #f87171;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 20px 60px rgba(0,0,0,.45);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-family: var(--font);
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f9;
  --bg2: #eef0f6;
  --panel: #ffffff;
  --panel2: #f8f9fc;
  --panel3: #eef1f7;
  --line: rgba(15,20,40,.08);
  --line2: rgba(15,20,40,.12);
  --muted: #6b728a;
  --text: #111827;
  --text2: #374151;
  --shadow: 0 20px 50px rgba(15,20,40,.12);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--purple); }
.hidden { display: none !important; }

/* ========== AUTH SCREEN ========== */
.auth-screen {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  overflow: auto; padding: 24px;
}
.auth-bg {
  position: absolute; inset: 0; overflow: hidden;
  background: radial-gradient(ellipse 80% 60% at 50% -10%, #2a1f55 0%, transparent 55%),
              radial-gradient(ellipse 50% 40% at 90% 80%, #0f2a3a 0%, transparent 50%),
              #07090f;
}
.auth-orb {
  position: absolute; border-radius: 50%; filter: blur(80px); opacity: .45;
  animation: float 12s ease-in-out infinite;
}
.auth-orb-1 { width: 420px; height: 420px; background: #6d4aff; top: -80px; left: -60px; }
.auth-orb-2 { width: 320px; height: 320px; background: #1a8a9a; bottom: -40px; right: 10%; animation-delay: -4s; }
.auth-orb-3 { width: 200px; height: 200px; background: #a855f7; top: 40%; left: 55%; animation-delay: -7s; opacity: .3; }
.auth-grid {
  position: absolute; inset: 0;
  background-image: linear-gradient(rgba(255,255,255,.03) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(255,255,255,.03) 1px, transparent 1px);
  background-size: 48px 48px; mask-image: radial-gradient(ellipse at center, black 20%, transparent 70%);
}
@keyframes float {
  0%, 100% { transform: translate(0,0) scale(1); }
  50% { transform: translate(20px, -15px) scale(1.05); }
}

.auth-layout {
  position: relative; z-index: 2;
  display: grid; grid-template-columns: 1fr 420px; gap: 48px;
  width: min(980px, 100%); align-items: center;
}
.auth-hero { color: #e8eaf5; }
.auth-logo { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 13px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #b19aff, #7351e8);
  color: #fff; font-size: 22px;
  box-shadow: 0 8px 28px rgba(121,86,232,.4);
}
.brand-mark.large { width: 52px; height: 52px; font-size: 26px; border-radius: 16px; }
.auth-logo strong { display: block; font-size: 20px; letter-spacing: -.4px; }
.auth-logo span { font-size: 12px; color: #9aa0b8; }
.auth-tagline {
  font-size: clamp(28px, 4vw, 38px); font-weight: 800;
  letter-spacing: -1.2px; line-height: 1.15; margin: 0 0 14px;
}
.auth-tagline em { font-style: normal; background: linear-gradient(90deg, #c4b5fd, #67e8f9); -webkit-background-clip: text; background-clip: text; color: transparent; }
.auth-desc { color: #a0a6be; font-size: 15px; line-height: 1.65; margin: 0 0 28px; max-width: 420px; }
.auth-features { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.auth-features li {
  display: flex; align-items: center; gap: 12px;
  font-size: 14px; color: #c8cde0;
}
.auth-features li span {
  width: 28px; height: 28px; border-radius: 8px;
  background: rgba(155,123,255,.12); border: 1px solid rgba(155,123,255,.2);
  display: grid; place-items: center; font-size: 13px; color: #c4b5fd;
}

.auth-card {
  background: rgba(14,17,27,.82);
  backdrop-filter: blur(24px);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 24px;
  padding: 28px 28px 24px;
  box-shadow: var(--shadow);
}
.auth-tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  background: rgba(0,0,0,.25); border-radius: 12px; padding: 4px; margin-bottom: 22px;
}
.auth-tab {
  padding: 10px; border-radius: 9px; font-weight: 600; font-size: 13px;
  color: #8b91a7; transition: .2s;
}
.auth-tab.active {
  background: linear-gradient(135deg, #9b7bff, #7c5cff);
  color: #fff; box-shadow: 0 4px 16px rgba(124,92,255,.35);
}
.auth-card h1 { font-size: 24px; letter-spacing: -.6px; margin: 0 0 6px; font-weight: 700; }
.auth-copy { font-size: 13px; color: #8b91a7; margin: 0 0 18px; line-height: 1.5; }
.auth-card label { display: block; font-size: 11px; font-weight: 600; color: #b9bfd0; margin: 14px 0 6px; letter-spacing: .2px; }
.auth-card input {
  width: 100%; border: 1px solid rgba(255,255,255,.1);
  background: #090c14; border-radius: 11px; padding: 12px 14px;
  color: #f0f0f8; outline: none; font-size: 14px; transition: border .2s;
}
.auth-card input:focus { border-color: rgba(155,123,255,.55); box-shadow: 0 0 0 3px rgba(155,123,255,.12); }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 44px; }
.toggle-pass {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px; border-radius: 8px; color: #8b91a7; font-size: 14px;
}
.toggle-pass:hover { background: rgba(255,255,255,.06); }
.password-strength { margin-top: 8px; }
.password-strength .bar {
  height: 4px; border-radius: 4px; background: rgba(255,255,255,.08); overflow: hidden;
}
.password-strength .bar i {
  display: block; height: 100%; width: 0; border-radius: 4px; transition: width .3s, background .3s;
}
.password-strength span { font-size: 11px; color: #8b91a7; margin-top: 4px; display: block; }
.auth-submit {
  width: 100%; margin-top: 20px; padding: 13px;
  border-radius: 12px; font-weight: 650; font-size: 14px;
  background: linear-gradient(135deg, #9b7bff, #6d4aff);
  color: #fff; box-shadow: 0 8px 24px rgba(109,74,255,.35);
  transition: transform .15s, box-shadow .15s;
}
.auth-submit:hover { transform: translateY(-1px); box-shadow: 0 12px 28px rgba(109,74,255,.45); }
.auth-submit:disabled { opacity: .6; transform: none; cursor: wait; }
.auth-foot { text-align: center; margin: 18px 0 0; font-size: 11px; color: #6b728a; line-height: 1.5; }

@media (max-width: 860px) {
  .auth-layout { grid-template-columns: 1fr; gap: 28px; }
  .auth-hero { text-align: center; }
  .auth-logo { justify-content: center; }
  .auth-desc { margin-left: auto; margin-right: auto; }
  .auth-features { justify-items: center; }
  .auth-features li { justify-content: center; }
}

/* ========== APP SHELL ========== */
.app-shell {
  display: flex; height: 100dvh; overflow: hidden;
  background: radial-gradient(ellipse at 70% -15%, rgba(91,65,166,.14), transparent 45%), var(--bg);
}
.sidebar {
  width: 272px; flex-shrink: 0;
  border-right: 1px solid var(--line);
  background: rgba(11,13,22,.92);
  backdrop-filter: blur(12px);
  padding: 18px 12px 12px;
  display: flex; flex-direction: column; z-index: 20;
}
[data-theme="light"] .sidebar { background: rgba(255,255,255,.9); }

.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 2px 8px 20px;
}
.brand strong { font-size: 15px; letter-spacing: -.3px; display: block; }
.brand small { font-size: 9px; letter-spacing: 1.4px; color: var(--muted); display: block; margin-top: 2px; font-weight: 600; }

.icon-btn {
  border: 1px solid var(--line); background: rgba(255,255,255,.03);
  border-radius: 10px; width: 34px; height: 34px;
  display: grid; place-items: center; color: var(--text2); font-size: 15px;
  transition: background .15s, border .15s;
}
.icon-btn:hover { background: rgba(255,255,255,.07); border-color: var(--line2); }
.mobile-close, .menu-btn { display: none; }

.new-chat {
  height: 42px; border: 1px solid rgba(155,123,255,.35);
  border-radius: 11px;
  background: linear-gradient(110deg, rgba(155,123,255,.18), rgba(110,91,208,.06));
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px; font-weight: 600; text-align: left; width: 100%;
  transition: background .2s;
}
.new-chat:hover { background: linear-gradient(110deg, rgba(155,123,255,.28), rgba(110,91,208,.1)); }
.new-chat > span { font-size: 18px; color: #b8a5ff; }
.new-chat kbd {
  margin-left: auto; color: var(--muted); font-size: 10px;
  border: 1px solid var(--line); padding: 2px 5px; border-radius: 5px; font-family: var(--font);
}

.side-label, .history-head {
  font-size: 9px; letter-spacing: 1.5px; color: var(--muted);
  font-weight: 700; padding: 22px 10px 8px; display: flex; align-items: center; justify-content: space-between;
}
.history-actions { display: flex; gap: 4px; }
.tiny-btn {
  width: 24px; height: 24px; border-radius: 6px; font-size: 12px;
  color: var(--muted); display: grid; place-items: center;
}
.tiny-btn:hover { background: rgba(255,255,255,.06); color: var(--text); }

.side-link {
  border: 0; background: transparent; width: 100%;
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border-radius: 10px;
  color: var(--text2); font-size: 13px; font-weight: 500;
  transition: background .15s;
}
.side-link:hover { background: rgba(255,255,255,.04); }
.side-link.active {
  background: rgba(155,123,255,.12);
  color: var(--text); border: 1px solid rgba(155,123,255,.18);
}
.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green); margin-left: auto;
  box-shadow: 0 0 8px var(--green); animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .5; }
}

.history-search { padding: 0 6px 8px; }
.history-search input {
  width: 100%; border: 1px solid var(--line); background: var(--panel2);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; outline: none;
}
.history-search input:focus { border-color: rgba(155,123,255,.4); }

.history-list { flex: 1; overflow-y: auto; padding: 0 4px; min-height: 0; }
.history-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: 9px; cursor: pointer;
  color: var(--text2); font-size: 13px; margin-bottom: 2px;
  transition: background .15s;
}
.history-item:hover { background: rgba(255,255,255,.04); }
.history-item.active { background: rgba(155,123,255,.1); color: var(--text); }
.history-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.empty-history { padding: 16px 10px; color: var(--muted); font-size: 12px; text-align: center; }

.sidebar-bottom { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--line); }
.plan-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 11px; border-radius: 12px;
  background: linear-gradient(135deg, rgba(155,123,255,.1), rgba(101,217,232,.05));
  border: 1px solid rgba(155,123,255,.15); margin-bottom: 8px;
}
.plan-icon {
  width: 32px; height: 32px; border-radius: 9px;
  background: rgba(155,123,255,.2); display: grid; place-items: center;
  color: #c4b5fd; font-size: 14px;
}
.plan-card b { display: block; font-size: 12px; }
.plan-card small { font-size: 10px; color: var(--muted); }
.pulse {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green); margin-left: auto;
  animation: pulse 1.8s infinite;
}

.profile {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px 9px; border-radius: 11px;
  text-align: left; transition: background .15s;
}
.profile:hover { background: rgba(255,255,255,.04); }
.avatar {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, #9b7bff, #58e0a1);
  display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff;
}
.profile b { display: block; font-size: 12px; }
.profile small { font-size: 10px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; display: block; }
.profile-more { margin-left: auto; color: var(--muted); font-size: 12px; }

/* ========== MAIN ========== */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.topbar {
  height: 54px; display: flex; align-items: center; gap: 12px;
  padding: 0 16px; border-bottom: 1px solid var(--line);
  background: rgba(7,9,15,.6); backdrop-filter: blur(10px);
}
.crumb { display: flex; align-items: center; gap: 7px; flex: 1; min-width: 0; font-size: 13px; }
.crumb-muted { color: var(--muted); }
.crumb-slash { color: var(--muted); opacity: .5; }
.model-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,.04); border: 1px solid var(--line);
  border-radius: 20px; padding: 3px 10px 3px 8px; font-size: 11px; color: var(--muted);
}
.green-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); box-shadow: 0 0 6px var(--green); }
.top-actions { display: flex; align-items: center; gap: 8px; }
.secure-label {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--muted); padding: 4px 8px;
  border: 1px solid var(--line); border-radius: 8px;
}

.chat-scroll {
  flex: 1; overflow-y: auto; padding: 24px 20px 12px;
  scroll-behavior: smooth;
}
.welcome {
  max-width: 720px; margin: 40px auto 20px; text-align: center;
}
.hero-orb {
  position: relative; width: 90px; height: 90px; margin: 0 auto 28px;
}
.orb-core {
  width: 70px; height: 70px; border-radius: 50%;
  background: linear-gradient(145deg, #b19aff, #5b3fd4);
  display: grid; place-items: center; font-size: 28px; color: #fff;
  margin: 10px auto; box-shadow: 0 0 40px rgba(155,123,255,.4);
  position: relative; z-index: 2;
}
.orbit {
  position: absolute; inset: 0; border: 1px solid rgba(155,123,255,.25);
  border-radius: 50%; animation: spin 12s linear infinite;
}
.orbit-two { inset: -8px; animation-duration: 18s; animation-direction: reverse; border-color: rgba(101,217,232,.2); }
.orbit-three { inset: -16px; animation-duration: 24s; border-color: rgba(244,114,182,.15); }
@keyframes spin { to { transform: rotate(360deg); } }
.orb-spark { position: absolute; font-size: 12px; color: #c4b5fd; animation: spark 3s ease-in-out infinite; }
.orb-spark.s1 { top: 0; right: 8px; }
.orb-spark.s2 { bottom: 4px; left: 4px; animation-delay: 1.2s; }
@keyframes spark {
  0%, 100% { opacity: .4; transform: scale(.8); }
  50% { opacity: 1; transform: scale(1.1); }
}

.eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 11px; letter-spacing: 1.5px; font-weight: 700;
  color: var(--muted); margin-bottom: 12px;
}
.eyebrow-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--purple); }
.welcome h1 {
  font-size: clamp(28px, 5vw, 40px); font-weight: 800;
  letter-spacing: -1.2px; margin: 0 0 12px; line-height: 1.15;
}
.welcome h1 span {
  background: linear-gradient(90deg, #c4b5fd, #67e8f9);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.welcome-copy {
  color: var(--muted); font-size: 15px; max-width: 480px;
  margin: 0 auto 28px; line-height: 1.6;
}
.suggestions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  text-align: left; margin-bottom: 24px;
}
.suggestion {
  display: flex; align-items: center; gap: 12px;
  padding: 14px; border-radius: 14px;
  border: 1px solid var(--line); background: rgba(255,255,255,.02);
  transition: border .2s, background .2s, transform .15s;
  text-align: left; width: 100%;
}
.suggestion:hover {
  border-color: rgba(155,123,255,.35);
  background: rgba(155,123,255,.06);
  transform: translateY(-1px);
}
.suggestion-icon {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center; font-size: 15px; flex-shrink: 0;
}
.suggestion-icon.purple { background: rgba(155,123,255,.15); color: #c4b5fd; }
.suggestion-icon.blue { background: rgba(101,217,232,.12); color: #67e8f9; }
.suggestion-icon.pink { background: rgba(244,114,182,.12); color: #f9a8d4; }
.suggestion-icon.gold { background: rgba(251,191,36,.12); color: #fcd34d; }
.suggestion b { display: block; font-size: 13px; margin-bottom: 2px; }
.suggestion small { font-size: 11px; color: var(--muted); }
.suggestion-arrow { margin-left: auto; color: var(--muted); font-size: 14px; }
.capability-note {
  font-size: 12px; color: var(--muted);
  display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap;
}

/* Messages */
.messages { max-width: 780px; margin: 0 auto; display: grid; gap: 18px; padding-bottom: 12px; }
.message { display: flex; gap: 12px; align-items: flex-start; }
.message-avatar {
  width: 32px; height: 32px; border-radius: 10px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 13px; font-weight: 600;
  background: rgba(255,255,255,.06); border: 1px solid var(--line);
}
.message.assistant .message-avatar {
  background: linear-gradient(145deg, #9b7bff, #5b3fd4); color: #fff; border: none;
}
.message.user .message-avatar { background: rgba(101,217,232,.15); color: #67e8f9; }
.message-body {
  flex: 1; min-width: 0; padding: 2px 0;
  font-size: 14.5px; line-height: 1.65; color: var(--text);
}
.message.user .message-body {
  background: rgba(255,255,255,.04); border: 1px solid var(--line);
  border-radius: 14px 14px 4px 14px; padding: 12px 14px;
}
.message-body p { margin: 0 0 10px; }
.message-body p:last-child { margin-bottom: 0; }
.message-body h1, .message-body h2, .message-body h3 { margin: 14px 0 8px; letter-spacing: -.3px; }
.message-body ul { margin: 8px 0; padding-left: 20px; }
.message-body li { margin: 4px 0; }
.message-body code {
  font-family: var(--mono); font-size: 12.5px;
  background: rgba(155,123,255,.12); padding: 2px 6px; border-radius: 5px;
}
.message-body a { color: var(--cyan); }
.code-wrap {
  margin: 12px 0; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--line); background: #0a0c14;
}
[data-theme="light"] .code-wrap { background: #1e2030; }
.code-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; background: rgba(255,255,255,.04);
  font-size: 11px; color: var(--muted); font-family: var(--mono);
}
.copy-code {
  font-size: 11px; padding: 3px 8px; border-radius: 6px;
  border: 1px solid var(--line); color: var(--text2);
}
.copy-code:hover { background: rgba(255,255,255,.06); }
.code-wrap pre {
  margin: 0; padding: 14px; overflow-x: auto;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.55;
  color: #e2e5f0;
}
.code-wrap code { background: none; padding: 0; }

.agent-events {
  background: rgba(155,123,255,.06); border: 1px solid rgba(155,123,255,.15);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; font-size: 12px;
}
.event-title {
  display: flex; align-items: center; gap: 6px;
  font-weight: 600; color: #c4b5fd; margin-bottom: 6px; font-size: 11px;
}
.event-line {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 3px 0; color: var(--text2);
}
.event-icon { width: 14px; flex-shrink: 0; text-align: center; }
.event-line code { font-size: 11px; }

.agent-status {
  max-width: 780px; margin: 8px auto 0;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: 14px;
  background: rgba(155,123,255,.08); border: 1px solid rgba(155,123,255,.18);
}
.thinking-orb { display: flex; gap: 4px; }
.thinking-orb i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--purple);
  animation: bounce 1.2s ease-in-out infinite;
}
.thinking-orb i:nth-child(2) { animation-delay: .15s; }
.thinking-orb i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .4; }
  40% { transform: translateY(-5px); opacity: 1; }
}
.agent-status b { display: block; font-size: 13px; }
.agent-status small { font-size: 11px; color: var(--muted); }
.status-spinner {
  width: 16px; height: 16px; border: 2px solid rgba(155,123,255,.25);
  border-top-color: var(--purple); border-radius: 50%;
  margin-left: auto; animation: spin 0.8s linear infinite;
}

/* Composer */
.composer-area {
  padding: 0 16px 14px; max-width: 820px; width: 100%; margin: 0 auto;
}
.composer-wrap {
  border: 1px solid var(--line2); border-radius: 18px;
  background: var(--panel); box-shadow: 0 8px 32px rgba(0,0,0,.2);
  padding: 10px 12px 8px; transition: border .2s;
}
.composer-wrap:focus-within { border-color: rgba(155,123,255,.4); }
.composer-tools {
  display: flex; align-items: center; gap: 10px;
  padding: 0 4px 6px; font-size: 11px; color: var(--muted);
}
.agent-badge {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(155,123,255,.12); border: 1px solid rgba(155,123,255,.2);
  border-radius: 8px; padding: 3px 8px; font-weight: 600; color: #c4b5fd;
}
.agent-badge-icon { font-size: 11px; }
#prompt {
  width: 100%; border: 0; background: transparent; resize: none;
  min-height: 44px; max-height: 180px; padding: 4px 6px;
  outline: none; font-size: 14.5px; line-height: 1.5; color: var(--text);
}
.composer-bottom {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 4px;
}
.composer-left { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tool-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 9px; border-radius: 8px; font-size: 12px;
  color: var(--muted); border: 1px solid transparent;
}
.tool-btn:hover { background: rgba(255,255,255,.05); color: var(--text); border-color: var(--line); }
.composer-tip { font-size: 10px; color: var(--muted); opacity: .7; }
.send-btn {
  width: 36px; height: 36px; border-radius: 11px;
  background: linear-gradient(135deg, #9b7bff, #6d4aff);
  color: #fff; display: grid; place-items: center; font-size: 16px;
  box-shadow: 0 4px 14px rgba(109,74,255,.35);
  transition: transform .15s, opacity .15s;
}
.send-btn:hover { transform: scale(1.05); }
.send-btn:disabled { opacity: .45; transform: none; cursor: wait; }
.disclaimer {
  text-align: center; font-size: 11px; color: var(--muted);
  margin-top: 8px; opacity: .75;
}

/* Toast */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1a1e2e; border: 1px solid var(--line2); color: var(--text);
  padding: 10px 18px; border-radius: 12px; font-size: 13px;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; z-index: 200; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Modals */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0,0,0,.55); backdrop-filter: blur(6px);
  display: grid; place-items: center; padding: 18px; overflow: auto;
}
.modal {
  width: min(520px, 100%); background: var(--panel);
  border: 1px solid var(--line2); border-radius: 20px;
  padding: 22px; box-shadow: var(--shadow); max-height: 90dvh; overflow-y: auto;
}
.modal-wide { width: min(680px, 100%); }
.modal-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  margin-bottom: 8px;
}
.modal-kicker {
  font-size: 10px; letter-spacing: 1.4px; font-weight: 700; color: var(--muted);
}
.modal-head h2 { margin: 4px 0 0; font-size: 20px; letter-spacing: -.4px; }
.modal-help { font-size: 12px; color: var(--muted); line-height: 1.55; margin: 0 0 16px; }
.connection-section { margin-top: 8px; }
.connection-head {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
}
.connection-head h3 { font-size: 13px; margin: 0; }
.connection-head-actions { display: flex; gap: 6px; }
.connection-list { display: grid; gap: 8px; margin-top: 10px; }
.connection-item {
  border: 1px solid var(--line); background: var(--panel2);
  border-radius: 12px; padding: 12px;
  display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap;
}
.connection-info { min-width: 0; flex: 1; }
.connection-info b { font-size: 13px; display: block; overflow-wrap: anywhere; }
.connection-info small { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; overflow-wrap: anywhere; }
.connection-actions { display: flex; flex-wrap: wrap; gap: 5px; }
.connection-actions button, .connection-head button { font-size: 11px; padding: 6px 10px; }
.secondary-btn {
  border: 1px solid var(--line); background: rgba(255,255,255,.03);
  border-radius: 9px; padding: 8px 12px; font-size: 12px; font-weight: 500;
  transition: background .15s;
}
.secondary-btn:hover { background: rgba(255,255,255,.07); }
.primary-btn {
  background: linear-gradient(135deg, #9b7bff, #6d4aff);
  color: #fff; border-radius: 10px; padding: 9px 14px;
  font-weight: 600; font-size: 13px;
  box-shadow: 0 4px 14px rgba(109,74,255,.3);
}
.danger-btn, .danger-text { color: var(--red) !important; }
.connection-form {
  margin-top: 16px; border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px; background: var(--panel2);
}
.connection-form summary {
  cursor: pointer; font-weight: 600; font-size: 13px; padding: 4px 0;
}
.connection-form label {
  display: block; font-size: 11px; color: var(--muted); margin: 12px 0 5px; font-weight: 600;
}
.connection-form input, .connection-form textarea {
  width: 100%; border: 1px solid var(--line); background: var(--bg);
  border-radius: 9px; padding: 10px 11px; outline: none; font-size: 13px;
}
.connection-form input:focus, .connection-form textarea:focus {
  border-color: rgba(155,123,255,.45);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.connection-footer {
  display: flex; justify-content: space-between; gap: 10px;
  margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line);
}
.settings-warning {
  margin-top: 14px; font-size: 11px; color: var(--muted);
  background: rgba(255,255,255,.03); border-radius: 10px; padding: 10px 12px;
  line-height: 1.5;
}
.settings-warning code {
  font-family: var(--mono); font-size: 11px;
  background: rgba(155,123,255,.12); padding: 1px 5px; border-radius: 4px;
}

/* Template grid */
.template-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.template-card {
  border: 1px solid var(--line); background: var(--panel2);
  border-radius: 12px; padding: 14px; text-align: left; cursor: pointer;
  transition: border .2s, background .2s;
}
.template-card:hover {
  border-color: rgba(155,123,255,.35);
  background: rgba(155,123,255,.06);
}
.template-card b { display: block; font-size: 13px; margin-bottom: 4px; }
.template-card small { font-size: 11px; color: var(--muted); line-height: 1.4; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: 8px 0 40px rgba(0,0,0,.4);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-close, .menu-btn { display: grid; }
  .suggestions { grid-template-columns: 1fr; }
  .template-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .secure-label { display: none; }
  .composer-tip { display: none; }
}

/* VPS auth method tabs */
.auth-method-tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  margin: 8px 0 12px; background: rgba(0,0,0,.2); padding: 4px; border-radius: 11px;
}
.auth-method-tab {
  padding: 9px 8px; border-radius: 8px; font-size: 11px; font-weight: 600;
  color: var(--muted); transition: .2s; text-align: center; line-height: 1.3;
}
.auth-method-tab.active {
  background: linear-gradient(135deg, #9b7bff, #6d4aff);
  color: #fff; box-shadow: 0 4px 14px rgba(109,74,255,.3);
}
.file-upload-label { display: inline-block; margin-top: 8px; cursor: pointer; }
.file-upload-label .secondary-btn { display: inline-block; pointer-events: none; }

/* Live agent events while streaming */
.live-events {
  max-width: 780px; margin: 8px auto;
  border: 1px solid rgba(155,123,255,.2);
  background: rgba(155,123,255,.06);
  border-radius: 14px; padding: 12px 14px;
}
.live-events .live-title {
  font-size: 11px; font-weight: 700; color: #c4b5fd;
  margin-bottom: 8px; display: flex; align-items: center; gap: 6px;
}
.live-events .live-line {
  font-size: 12px; color: var(--text2); padding: 3px 0;
  display: flex; gap: 8px; align-items: flex-start;
}
.live-events .live-line code { font-size: 11px; }

.event-detail, .live-line .event-detail {
  display: inline;
  color: var(--muted);
  font-size: 11px;
  font-family: var(--mono);
  word-break: break-all;
}
.live-line code, .event-line code {
  background: rgba(155,123,255,.18);
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 11px;
}

/* Comfort: mobile + desktop */
@media (max-width: 768px) {
  .chat-scroll { padding: 12px 10px 8px; }
  .composer-area { padding: 0 10px 10px; }
  .composer-wrap { border-radius: 14px; padding: 8px 10px 6px; }
  .message { gap: 8px; }
  .message-avatar { width: 28px; height: 28px; font-size: 12px; }
  .live-events { margin: 8px 4px; padding: 10px; }
  .topbar { padding: 0 10px; height: 48px; }
  .auth-card { padding: 20px 16px; }
  .modal { padding: 16px; border-radius: 16px; }
  .suggestion { padding: 12px; }
}
.composer-wrap { -webkit-tap-highlight-color: transparent; }
#prompt { font-size: 16px; } /* iOS zoom prevent */
body { overscroll-behavior: none; }
.app-shell { min-height: 100dvh; }

/* ===== File attach chips ===== */
.attach-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 4px 4px 8px; max-width: 100%;
}
.attach-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(155,123,255,.12); border: 1px solid rgba(155,123,255,.25);
  border-radius: 999px; padding: 4px 8px 4px 10px;
  font-size: 11px; max-width: 100%;
}
.attach-chip b {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px;
}
.attach-chip small { color: var(--muted); }
.attach-chip button {
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(255,255,255,.08); color: var(--text2); font-size: 12px;
  display: grid; place-items: center; line-height: 1;
}
.attach-chip button:hover { background: rgba(248,113,113,.25); color: var(--red); }
.composer-wrap.drag-over {
  border-color: rgba(155,123,255,.55) !important;
  box-shadow: 0 0 0 3px rgba(155,123,255,.15);
}

/* ===== Overflow / text safety ===== */
.message-body, .event-line, .live-line, .history-title, .connection-info b, .connection-info small {
  overflow-wrap: anywhere; word-break: break-word;
}
.message-body {
  max-width: 100%; min-width: 0;
}
.message {
  max-width: 100%;
}
.messages, .chat-scroll, .live-events, .agent-events {
  max-width: 100%;
}
.event-detail, .live-line .event-detail {
  display: inline;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.code-wrap, .code-wrap pre {
  max-width: 100%;
}
.agent-events, .live-events {
  overflow-x: hidden;
}
.model-pill, .crumb b {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw;
}
.topbar { min-width: 0; }
.crumb { min-width: 0; overflow: hidden; }

/* ===== Light theme completeness ===== */
[data-theme="light"] body,
[data-theme="light"] .app-shell {
  background: var(--bg);
  color: var(--text);
}
[data-theme="light"] .sidebar {
  background: #ffffff;
  border-right-color: var(--line);
}
[data-theme="light"] .topbar {
  background: rgba(255,255,255,.85);
}
[data-theme="light"] .composer-wrap {
  background: #fff;
  border-color: var(--line2);
  box-shadow: 0 4px 24px rgba(15,20,40,.06);
}
[data-theme="light"] .message.user .message-body {
  background: #eef1f8;
  border-color: var(--line);
}
[data-theme="light"] .agent-events,
[data-theme="light"] .live-events,
[data-theme="light"] .agent-status {
  background: rgba(124,92,255,.06);
  border-color: rgba(124,92,255,.18);
}
[data-theme="light"] .code-wrap {
  background: #1e2230;
}
[data-theme="light"] .side-link.active {
  background: rgba(124,92,255,.1);
  border-color: rgba(124,92,255,.2);
}
[data-theme="light"] .auth-screen .auth-bg {
  background: radial-gradient(ellipse 80% 60% at 50% -10%, #c4b5fd 0%, transparent 55%), #f4f5f9;
}
[data-theme="light"] .auth-card {
  background: rgba(255,255,255,.95);
  border-color: var(--line);
  color: var(--text);
}
[data-theme="light"] .auth-card input {
  background: #f4f5f9;
  color: var(--text);
  border-color: var(--line);
}
[data-theme="light"] .modal {
  background: #fff;
  color: var(--text);
}
[data-theme="light"] .connection-form input,
[data-theme="light"] .connection-form textarea,
[data-theme="light"] .connection-item {
  background: var(--panel2);
  color: var(--text);
}
[data-theme="light"] .toast {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}
[data-theme="light"] .suggestion {
  background: #fff;
}
[data-theme="light"] .history-item:hover {
  background: rgba(15,20,40,.04);
}
[data-theme="light"] .plan-card {
  background: linear-gradient(135deg, rgba(124,92,255,.08), rgba(101,217,232,.05));
}
[data-theme="light"] .new-chat {
  background: linear-gradient(110deg, rgba(124,92,255,.12), rgba(110,91,208,.04));
}
[data-theme="light"] .auth-features li span {
  background: rgba(124,92,255,.1);
  border-color: rgba(124,92,255,.2);
  color: #6d4aff;
}

/* Live label polish */
.live-line code, .event-line code {
  background: linear-gradient(135deg, rgba(155,123,255,.22), rgba(101,217,232,.12));
  color: #c4b5fd;
  font-weight: 600;
  white-space: nowrap;
}
[data-theme="light"] .live-line code,
[data-theme="light"] .event-line code {
  color: #5b3fd4;
  background: rgba(124,92,255,.12);
}

/* Typewriter caret */
.caret-blink {
  display: inline-block;
  color: var(--purple);
  font-weight: 700;
  animation: blink 1s step-end infinite;
  margin-left: 1px;
}
@keyframes blink {
  50% { opacity: 0; }
}
.typing-stream {
  display: inline;
}
.typing-stream p:last-child { display: inline; }

/* === Professional polish v2 === */
.message.assistant .message-body {
  max-width: min(720px, 100%);
}
.agent-events {
  font-size: 12px;
  line-height: 1.45;
  max-height: 280px;
  overflow-y: auto;
}
.event-line code, .live-line code {
  font-size: 11px;
  word-break: break-all;
}
.status-chip, .live-status {
  transition: opacity .2s ease;
}
.composer-wrap textarea {
  font-size: 15px;
  line-height: 1.45;
  max-height: 160px;
}
.send-btn {
  transition: transform .12s ease, box-shadow .12s ease;
}
.send-btn:active { transform: scale(.94); }
.send-btn:disabled { opacity: .45; cursor: not-allowed; }
.history-item.active {
  box-shadow: inset 2px 0 0 var(--accent, #9b7bff);
}
.toast {
  z-index: 9999;
  border-radius: 12px;
  backdrop-filter: blur(12px);
}
@media (max-width: 640px) {
  .agent-events { max-height: 200px; }
  .message-body { font-size: 14px; }
  .topbar-title { max-width: 42vw; }
}
