:root {
  --bg: #0b0e14;
  --panel: #11151f;
  --panel-2: #171c2a;
  --border: #232a3a;
  --text: #e6e9f0;
  --muted: #8b93a7;
  --accent: #7c5cff;
  --accent-2: #4fd1c5;
  --user-bubble: #26304a;
  --danger: #ff7a90;
  --code-bg: #0e1119;
  --radius: 12px;
  --sidebar-w: 280px;
}
body[data-theme="light"] {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --panel-2: #f1f3f7;
  --border: #e3e6ec;
  --text: #1a1d24;
  --muted: #6b7280;
  --user-bubble: #e9eefc;
  --code-bg: #f4f6fa;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow-x: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.link { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 0; font-family: inherit; }
.link:hover { color: var(--text); }
b { font-weight: 600; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #3a4a6a; }

/* brand + landing */
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 800; letter-spacing: -.01em; }
.brand.small { font-size: 16px; }
.mark { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-size: 15px; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 0 20px rgba(124,92,255,.5); }
.landing { min-height: 100vh; display: flex; flex-direction: column; }
.land-nav { display: flex; align-items: center; justify-content: space-between; padding: 22px 32px; }
.land-nav-r { display: flex; align-items: center; gap: 16px; }
.hero { text-align: center; padding: 80px 20px 40px; max-width: 820px; margin: 0 auto; }
.hero-badge { display: inline-block; font-size: 12.5px; color: #cfd6ff; background: rgba(124,92,255,.16); border: 1px solid rgba(124,92,255,.3); border-radius: 999px; padding: 7px 16px; margin-bottom: 22px; }
.hero h1 { font-size: 52px; line-height: 1.08; letter-spacing: -.03em; margin-bottom: 18px; }
.hero .grad { background: linear-gradient(90deg, var(--accent), var(--accent-2), #ff6ec7); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { color: var(--muted); font-size: 18px; max-width: 600px; margin: 0 auto 28px; }
.cta { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 13px 26px; border-radius: 999px; border: none; cursor: pointer; background: linear-gradient(135deg, var(--accent), #5f8bff); color: #fff; font-weight: 700; font-size: 15px; text-decoration: none; box-shadow: 0 10px 30px rgba(124,92,255,.35); }
.cta:hover { filter: brightness(1.05); }
.cta.full { width: 100%; }
.cta.small { padding: 9px 18px; font-size: 13.5px; }
.cta.big { padding: 16px 36px; font-size: 17px; }

/* auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 420px; padding: 34px 30px; border-radius: 20px; background: var(--panel); border: 1px solid var(--border); box-shadow: 0 30px 80px rgba(0,0,0,.4); }
.auth-card .brand { margin-bottom: 16px; }
.auth-card h1 { font-size: 23px; margin-bottom: 6px; }
.auth-card .sub { color: var(--muted); font-size: 14px; margin-bottom: 18px; }
.tabs { display: flex; gap: 6px; background: var(--panel-2); border-radius: 12px; padding: 4px; margin-bottom: 18px; }
.tabs button { flex: 1; background: transparent; border: none; color: var(--muted); padding: 9px; border-radius: 9px; cursor: pointer; font-size: 14px; }
.tabs button.active { background: var(--accent); color: #fff; }
.auth-form { display: flex; flex-direction: column; gap: 11px; }
input, textarea, select { width: 100%; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; color: var(--text); font-size: 15px; outline: none; font-family: inherit; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: none; }
input.code { font-size: 26px; letter-spacing: 12px; text-align: center; font-weight: 700; }
.verify-hint { color: var(--muted); font-size: 13.5px; text-align: center; }
.err { color: var(--danger); font-size: 13.5px; margin-top: 10px; text-align: center; }

/* APP layout */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; height: 100vh; height: 100dvh; }
.app.has-artifacts { grid-template-columns: var(--sidebar-w) 1fr 460px; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 14px; gap: 12px; min-height: 0; }
.sb-top { display: flex; flex-direction: column; gap: 10px; }
.new-chat { display: flex; align-items: center; gap: 8px; justify-content: center; padding: 11px; border-radius: 10px; border: 1px solid var(--border); background: transparent; color: var(--text); font-weight: 600; cursor: pointer; font-size: 14px; }
.new-chat:hover { background: var(--panel-2); }
.sb-search { border-radius: 8px; padding: 9px 12px; font-size: 13.5px; }
.sb-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.group-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 8px 4px; }
.chat-item { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 13.5px; color: var(--muted); }
.chat-item:hover { background: var(--panel-2); color: var(--text); }
.chat-item.active { background: var(--panel-2); color: var(--text); }
.chat-item .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .pin { color: var(--accent-2); font-size: 11px; }
.chat-item .acts { display: none; gap: 2px; }
.chat-item:hover .acts { display: flex; }
.chat-item .acts button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 12px; padding: 2px 4px; }
.chat-item .acts button:hover { color: var(--danger); }
.sb-bottom { border-top: 1px solid var(--border); padding-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.sb-link { text-align: left; background: none; border: none; color: var(--muted); padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13.5px; font-family: inherit; }
.sb-link:hover { background: var(--panel-2); color: var(--text); }
.sb-user { display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin-top: 4px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: grid; place-items: center; font-size: 14px; color: #fff; flex-shrink: 0; }
.sb-user-info { flex: 1; min-width: 0; }
.sb-user-info div:first-child { font-size: 13.5px; font-weight: 600; }

/* MAIN chat */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.chat-top { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.hamburger { display: none; background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; }
.chat-title { flex: 1; font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-top-actions { display: flex; gap: 6px; }
.top-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 16px; padding: 6px 8px; border-radius: 8px; }
.top-btn:hover { background: var(--panel-2); color: var(--text); }
.msgs { flex: 1; overflow-y: auto; padding: 24px 0; min-height: 0; }
.msg-row { max-width: 800px; margin: 0 auto; padding: 8px 24px; }
.msg-row.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg-bubble { padding: 12px 16px; border-radius: 16px; font-size: 15.5px; word-break: break-word; overflow-wrap: anywhere; }
.msg-row.user .msg-bubble { background: var(--user-bubble); border-bottom-right-radius: 4px; max-width: 85%; white-space: pre-wrap; }
.msg-row.assistant .msg-bubble { max-width: 100%; }
.msg-actions { display: flex; gap: 4px; margin-top: 6px; opacity: 0.5; transition: opacity .15s; }
.msg-row:hover .msg-actions { opacity: 1; }
.msg-actions button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 4px 6px; border-radius: 6px; }
.msg-actions button:hover { background: var(--panel-2); color: var(--text); }
.msg-actions button.bad:hover { color: var(--danger); }
.msg-actions button.good:hover { color: var(--accent-2); }

/* markdown + code */
.msg-bubble p { margin: 0 0 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul, .msg-bubble ol { margin: 0 0 8px 20px; }
.msg-bubble li { margin: 2px 0; }
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 { margin: 12px 0 6px; }
.msg-bubble h1 { font-size: 20px; } .msg-bubble h2 { font-size: 18px; } .msg-bubble h3 { font-size: 16px; }
.msg-bubble table { border-collapse: collapse; margin: 8px 0; }
.msg-bubble th, .msg-bubble td { border: 1px solid var(--border); padding: 6px 10px; font-size: 14px; }
.msg-bubble code { background: var(--code-bg); border-radius: 5px; padding: 1px 5px; font-size: 13.5px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.msg-bubble pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px; padding: 14px; overflow-x: auto; margin: 8px 0; }
.msg-bubble pre code { background: none; padding: 0; font-size: 13.5px; }
.msg-bubble img, .msg-bubble table, .msg-bubble pre, .msg-bubble video { max-width: 100%; }
.msg-bubble a { color: var(--accent-2); }
.msg-bubble blockquote { border-left: 3px solid var(--accent); padding-left: 12px; color: var(--muted); margin: 8px 0; }
.artifact-btn { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--accent); background: rgba(124,92,255,.12); color: var(--text); cursor: pointer; font-size: 13px; }

/* composer */
.composer-wrap { position: relative; max-width: 800px; margin: 0 auto; width: 100%; padding: 0 24px 20px; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.att { display: inline-flex; align-items: center; gap: 6px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; font-size: 13px; }
.att img { max-height: 44px; border-radius: 6px; }
.att button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; }
.composer { display: flex; align-items: flex-end; gap: 8px; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 10px 12px; box-shadow: 0 8px 30px rgba(0,0,0,.25); }
.composer textarea { flex: 1; background: transparent; border: none; resize: none; max-height: 200px; padding: 4px; font-size: 15.5px; line-height: 1.5; }
.c-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 18px; padding: 6px 8px; border-radius: 8px; }
.c-btn:hover { background: var(--panel-2); color: var(--text); }
.c-btn.model { font-size: 12.5px; font-weight: 600; border: 1px solid var(--border); border-radius: 999px; padding: 6px 10px; }
.c-send { width: 36px; height: 36px; border-radius: 50%; border: none; background: var(--accent); color: #fff; cursor: pointer; font-size: 16px; flex-shrink: 0; }
.c-send:disabled { opacity: .4; cursor: default; }
.token-count { white-space: nowrap; padding: 6px 4px; }
.c-right { display: flex; align-items: center; gap: 6px; }
.model-drop { position: absolute; right: 24px; bottom: 66px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; min-width: 220px; box-shadow: 0 16px 40px rgba(0,0,0,.4); padding: 6px; z-index: 60; }
.model-item { display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left; background: none; border: none; color: var(--muted); padding: 9px 11px; border-radius: 8px; cursor: pointer; font-family: inherit; }
.model-item:hover { background: var(--panel-2); color: var(--text); }
.model-item.sel { color: var(--text); background: rgba(124,92,255,.14); }
.model-item .mn { font-weight: 600; font-size: 14px; color: var(--text); display: flex; align-items: center; gap: 7px; }
.model-item .md { font-size: 12px; }
.badge-premium { font-size: 9.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: #111; background: linear-gradient(135deg, #ffd76a, #ff9d5c); border-radius: 999px; padding: 2px 7px; }
.attach-menu { position: absolute; left: 24px; bottom: 66px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; min-width: 150px; box-shadow: 0 16px 40px rgba(0,0,0,.4); padding: 6px; display: flex; flex-direction: column; z-index: 60; }
.attach-menu label { display: block; padding: 10px 12px; border-radius: 8px; color: var(--text); font-size: 14px; cursor: pointer; }
.attach-menu label:hover { background: var(--panel-2); }

/* artifacts */
.artifacts { width: 460px; border-left: 1px solid var(--border); background: var(--panel); display: flex; flex-direction: column; }
.art-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 600; }
.art-head button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 16px; }
#artifacts-frame { flex: 1; border: none; background: #fff; }

/* modal + tools */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 200; padding: 20px; }
.modal-box { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; width: 100%; max-width: 640px; max-height: 86vh; display: flex; flex-direction: column; padding: 20px; gap: 12px; overflow: hidden; box-shadow: 0 40px 100px rgba(0,0,0,.5); }
.modal-box.onboard { max-width: 560px; }
.modal-box.tools { max-width: 720px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; font-weight: 700; }
.modal-head button { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.tools-tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.tools-tabs button { background: none; border: none; color: var(--muted); padding: 7px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; font-family: inherit; }
.tools-tabs button.active { background: var(--panel-2); color: var(--text); }
.tools-body { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.card h3 { font-size: 15px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; }
.chip span { display: inline-block; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); font-size: 13px; cursor: pointer; }
.chip input:checked + span { background: rgba(124,92,255,.18); color: var(--text); border-color: var(--accent); }
.model-options { display: flex; flex-direction: column; gap: 8px; }
.model-option { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border); cursor: pointer; }
.model-option.sel { border-color: var(--accent); background: rgba(124,92,255,.1); }
.model-option input { display: none; }
.model-option .mname { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 7px; }
.model-option .mdesc { color: var(--muted); font-size: 12.5px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.item .t { font-weight: 600; font-size: 14px; }
.item .d { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 8px; }
.row button, .note-actions button { background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); border-radius: 7px; padding: 5px 12px; cursor: pointer; font-size: 12.5px; font-family: inherit; }
.row button.del, .note-actions button.del { color: var(--danger); }
.note-text { white-space: pre-wrap; word-break: break-word; }
.note-actions { display: flex; gap: 8px; margin-top: 8px; }
.artifact-body { margin-top: 6px; white-space: pre-wrap; word-break: break-word; background: var(--code-bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px; font-size: 13px; }

/* toasts */
#toasts { position: fixed; bottom: 22px; right: 22px; z-index: 300; display: flex; flex-direction: column; gap: 6px; max-width: 340px; }
.toast { background: var(--panel); border: 1px solid var(--border); color: var(--text); border-radius: 10px; padding: 12px 16px; box-shadow: 0 12px 34px rgba(0,0,0,.4); animation: slide .2s ease; }
.toast.ok { border-left: 3px solid var(--accent-2); }
.toast.err { border-left: 3px solid var(--danger); }
@keyframes slide { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* typing cursor */
.cursor { display: inline-block; width: 8px; height: 16px; background: var(--accent-2); margin-left: 2px; vertical-align: -2px; animation: blink .8s infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* mobile */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .app.has-artifacts { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 100; width: 280px; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.5); }
  .sidebar.open { transform: translateX(0); }
  .hamburger { display: block; }
  .artifacts { position: fixed; right: 0; top: 0; bottom: 0; width: 92%; z-index: 90; }
  .msg-row { padding: 8px 12px; }
  .msg-bubble { font-size: 15px; }
  .composer-wrap { padding: 0 10px calc(10px + env(safe-area-inset-bottom)); }
  .token-count { display: none; }
  .chat-top { padding: 10px 12px; }
  .msgs { padding: 16px 0; }
  .hero h1 { font-size: 34px; }
  .hero p { font-size: 16px; }
  .model-drop, .attach-menu { max-width: 92vw; }
}

/* AGENT: plan + log */
.cta.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); box-shadow: none; }
.agent-plan-head { font-weight: 700; margin-bottom: 8px; }
.agent-plan { margin-left: 20px; margin-bottom: 4px; }
.agent-plan li { margin: 3px 0; }
.agent-progress { margin-bottom: 10px; }
.prog-bar { height: 6px; background: var(--panel-2); border-radius: 999px; overflow: hidden; margin-bottom: 5px; }
.prog-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s; }
.prog-label { margin-bottom: 8px; }
.agent-log { display: flex; flex-direction: column; gap: 8px; max-height: 340px; overflow-y: auto; }
.tool-call { border-left: 2px solid var(--accent-2); padding-left: 10px; background: var(--code-bg); border-radius: 8px; padding: 8px 10px; }
.tc-head { font-weight: 600; font-size: 13.5px; margin-bottom: 3px; color: var(--accent-2); }
.tc-io { word-break: break-word; }

/* canvas edit bar */
.art-edit { display: flex; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.art-edit input { flex: 1; }
.art-edit .cta { flex-shrink: 0; }
