:root {
  --bg: #f6f6fb;
  --panel: #ffffff;
  --panel-2: #f1f0fa;
  --side: #fbfbfe;
  --text: #17162b;
  --muted: #6b6a86;
  --line: #e7e6f2;
  --brand: #5b4dff;
  --brand-2: #7c6dff;
  --brand-soft: #eceaff;
  --ok: #10b981;
  --warn: #f59e0b;
  --bad: #ef4444;
  --shadow: 0 1px 2px rgba(20, 16, 60, .05), 0 8px 24px rgba(20, 16, 60, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0d18; --panel: #16152a; --panel-2: #1d1c36; --side: #121124;
    --text: #ecebff; --muted: #9b99bd; --line: #29274a;
    --brand: #8b7bff; --brand-2: #a497ff; --brand-soft: #24214a;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e0d18; --panel: #16152a; --panel-2: #1d1c36; --side: #121124;
  --text: #ecebff; --muted: #9b99bd; --line: #29274a;
  --brand: #8b7bff; --brand-2: #a497ff; --brand-soft: #24214a;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14.5px/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 14px; }
[hidden] { display: none !important; }

/* ---------- buttons & inputs ---------- */
.btn { border: 1px solid var(--line); background: var(--panel); padding: 9px 14px; border-radius: 10px; cursor: pointer; font-weight: 500; display: inline-flex; align-items: center; gap: 7px; transition: .15s; white-space: nowrap; }
.btn:hover { border-color: var(--brand-2); }
.btn.primary { background: linear-gradient(135deg, var(--brand-2), var(--brand)); border-color: transparent; color: #fff; box-shadow: 0 4px 14px rgba(91, 77, 255, .3); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: default; }
label.field { display: grid; gap: 6px; font-weight: 500; }
label.field .hint { font-weight: 400; color: var(--muted); font-size: 12.5px; }
input[type=text], input[type=password], input[type=number], input[type=time], input[type=url], textarea, select {
  width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 10px 12px; outline: none; transition: .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { resize: vertical; min-height: 90px; }
input[type=color] { width: 44px; height: 38px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); padding: 3px; }

/* ---------- choice cards ---------- */
.choices { display: grid; gap: 10px; }
.choice { display: flex; gap: 12px; align-items: flex-start; border: 1.5px solid var(--line); border-radius: 12px; padding: 13px 14px; cursor: pointer; background: var(--panel); transition: .15s; }
.choice:hover { border-color: var(--brand-2); }
.choice.on { border-color: var(--brand); background: var(--brand-soft); }
.choice input { margin-top: 3px; accent-color: var(--brand); }
.choice b { display: block; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); margin-left: 6px; vertical-align: 1px; }
.tag.warn { background: #fef3c7; color: #b45309; }
.tag.ok { background: #d1fae5; color: #047857; }
.tag.bad { background: #fee2e2; color: #b91c1c; }

/* ---------- auth & wizard ---------- */
.center { min-height: 100%; display: grid; place-items: center; padding: 32px 16px; background:
  radial-gradient(1200px 500px at 50% -10%, rgba(124, 109, 255, .22), transparent 70%), var(--bg); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); padding: 28px; width: 100%; max-width: 620px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { width: 44px; height: 44px; border-radius: 12px; }
.brand .name { font-weight: 700; font-size: 20px; letter-spacing: -.02em; }
.brand .v { font-size: 11px; font-weight: 600; color: var(--brand); background: var(--brand-soft); padding: 2px 7px; border-radius: 99px; margin-left: 4px; vertical-align: 3px; }
.hero-logo { width: 96px; height: 96px; border-radius: 26px; box-shadow: 0 12px 40px rgba(91, 77, 255, .35); animation: float 4s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-6px); } }
.steps { display: flex; gap: 6px; margin: 18px 0 22px; }
.steps span { flex: 1; height: 5px; border-radius: 99px; background: var(--line); }
.steps span.done { background: linear-gradient(90deg, var(--brand-2), var(--brand)); }
.wizard-title { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.wizard-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 24px; gap: 10px; }
.connect-box { border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: grid; gap: 12px; background: var(--panel); }
.connect-box .head { display: flex; align-items: center; gap: 10px; }
.connect-box .ico { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; font-size: 18px; background: var(--panel-2); }
details.more summary { cursor: pointer; color: var(--brand); font-weight: 500; }
.err { color: var(--bad); font-size: 13px; }
.okmsg { color: var(--ok); font-size: 13px; }

/* ---------- main layout ---------- */
.shell { display: grid; grid-template-columns: 280px 1fr; height: 100vh; height: 100dvh; }
.side { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side .top { padding: 16px 16px 10px; display: flex; align-items: center; justify-content: space-between; }
.side .scroll { flex: 1; overflow: auto; padding: 4px 10px 10px; }
.side .label { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 8px 6px; display: flex; justify-content: space-between; align-items: center; }
.nav { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; cursor: pointer; transition: .12s; position: relative; }
.nav:hover { background: var(--panel-2); }
.nav.on { background: var(--brand-soft); }
.nav .t { flex: 1; min-width: 0; }
.nav .t b { display: block; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav .t span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav .ni { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--panel-2); font-size: 16px; flex: none; }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; background: var(--brand); color: #fff; font-size: 11.5px; font-weight: 600; display: grid; place-items: center; }
.badge.warn { background: var(--warn); }
.side .foot { border-top: 1px solid var(--line); padding: 10px; }

.avatar { width: 38px; height: 38px; border-radius: 13px 13px 13px 5px; display: grid; place-items: center; font-size: 19px; flex: none; position: relative; color: #fff; }
.avatar.lg { width: 52px; height: 52px; font-size: 26px; border-radius: 17px 17px 17px 6px; }
.avatar .dot { position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--side); background: var(--ok); }
.avatar .dot.paused { background: var(--muted); }
.avatar .dot.busy { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.page-head { padding: 16px 24px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 14px; background: var(--panel); }
.page-head h2 { font-size: 18px; }
.page { flex: 1; overflow: auto; padding: 24px; }
.page .inner { max-width: 880px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 16px; }
.grid2 > .panel, .grid3 > .panel, .stack > .panel { margin-top: 0; }
.panel h3 { font-size: 15.5px; margin-bottom: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

/* ---------- chat ---------- */
.chat { flex: 1; overflow: auto; padding: 24px; }
.chat .inner { max-width: 820px; margin: 0 auto; display: grid; gap: 16px; }
.msg { display: flex; gap: 12px; align-items: flex-start; }
.msg.me { flex-direction: row-reverse; }
.bubble { max-width: min(680px, 85%); padding: 12px 15px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); overflow-wrap: anywhere; }
.msg.me .bubble { background: linear-gradient(135deg, var(--brand-2), var(--brand)); color: #fff; border-color: transparent; border-bottom-right-radius: 5px; }
.msg.bot .bubble { border-bottom-left-radius: 5px; }
.msg.task .bubble { background: var(--brand-soft); border-style: dashed; }
.msg.error .bubble { border-color: var(--bad); color: var(--bad); }
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin: 0; }
.bubble ul, .bubble ol { margin: 4px 0 8px; padding-left: 20px; }
.bubble code { background: var(--panel-2); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.msg.me .bubble code { background: rgba(255,255,255,.18); }
.bubble pre { background: var(--panel-2); padding: 10px; border-radius: 8px; overflow: auto; font-size: 12.5px; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { font-size: 15px; margin: 8px 0 4px; }
.meta { font-size: 11.5px; color: var(--muted); margin-top: 6px; display: flex; gap: 8px; flex-wrap: wrap; }
.msg.me .meta { color: rgba(255,255,255,.75); justify-content: flex-end; }
.chip { font-size: 11.5px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 99px; padding: 2px 9px; }
.typing { display: inline-flex; gap: 4px; padding: 6px 2px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }
.composer { padding: 14px 24px 20px; background: linear-gradient(transparent, var(--bg) 30%); }
.composer .box { max-width: 820px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 8px 8px 8px 14px; box-shadow: var(--shadow); }
.composer textarea { border: 0; box-shadow: none !important; min-height: 24px; max-height: 200px; padding: 8px 0; resize: none; background: transparent; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty .avatar { margin: 0 auto 14px; }

/* ---------- usage bars ---------- */
.bar { height: 10px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; }
.cols { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 10px; }
.cols .c { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.cols .c i { width: 100%; max-width: 34px; border-radius: 6px 6px 3px 3px; background: linear-gradient(var(--brand-2), var(--brand)); min-height: 2px; }
.cols .c span { font-size: 10.5px; color: var(--muted); }

/* ---------- misc ---------- */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 500; z-index: 50; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.notif { position: absolute; left: 290px; bottom: 60px; width: 340px; max-height: 60vh; overflow: auto; z-index: 40; }
.notif .n { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.notif .n:last-child { border: 0; }
.mem { display: flex; gap: 8px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.emoji-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-pick button { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); font-size: 18px; cursor: pointer; }
.emoji-pick button.on { border-color: var(--brand); background: var(--brand-soft); }
.hamburger { display: none; }
.dock-tip { display: flex; gap: 14px; align-items: center; background: var(--brand-soft); border-radius: 14px; padding: 14px; }
.dock-tip img { width: 52px; height: 52px; border-radius: 14px; }
.kbd { font-family: ui-monospace, monospace; font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 86%; max-width: 320px; z-index: 30; transform: translateX(-102%); transition: .2s; box-shadow: var(--shadow); }
  .shell.open .side { transform: none; }
  .hamburger { display: inline-flex; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .page, .chat { padding: 16px; }
  .page-head { padding: 10px 14px; flex-wrap: wrap; gap: 8px; }
  .page-head > .grow { flex: 1 1 calc(100% - 60px); }
  .page-head > .btn { flex: 1 1 auto; justify-content: center; }
  .composer { padding: 10px 16px 16px; }
  .card { padding: 20px; }
  .notif { left: 16px; right: 16px; width: auto; }
}
