:root {
    --bg: #0B0D17;
    --surface: #12152A;
    --card: #191D38;
    --code: #0E1124;
    --outline: #2A3057;
    --violet: #8B5CFF;
    --cyan: #22D3EE;
    --text: #E8EAF6;
    --dim: #9AA0C3;
    --danger: #FF6B6B;
    --grad: linear-gradient(135deg, #22D3EE, #8B5CFF);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.55;
    -webkit-text-size-adjust: 100%;
}
.hidden { display: none !important; }
.muted { color: var(--dim); }
.small { font-size: 12px; }
.center { text-align: center; }
a { color: var(--cyan); }
button, input, select, textarea { font: inherit; color: inherit; }
svg { display: block; }

.grad {
    background: var(--grad);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
}
.wordmark { font-weight: 800; letter-spacing: .5px; font-size: 22px; }
.wordmark.sm { font-size: 18px; line-height: 1.1; }
.wordmark.big { font-size: 38px; margin: 6px 0 4px; text-align: center; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border: 1px solid var(--outline); background: var(--card); color: var(--text);
    padding: 10px 16px; border-radius: 14px; cursor: pointer; font-weight: 600;
}
.btn:hover { border-color: var(--cyan); }
.btn.primary { background: var(--violet); border-color: var(--violet); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.small-btn { padding: 6px 12px; font-size: 12px; font-weight: 500; border-radius: 10px; }
.icon-btn {
    width: 38px; height: 38px; flex: 0 0 38px; display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: 0; border-radius: 12px; color: var(--dim); cursor: pointer;
}
.icon-btn:hover { background: var(--card); color: var(--text); }
.icon-btn.accent { color: var(--cyan); }
.icon-btn.tiny { width: 30px; height: 30px; flex-basis: 30px; }
.icon-btn.tiny svg { width: 16px; height: 16px; }

/* ---------- Layout ---------- */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.sidebar {
    width: 300px; flex: 0 0 300px; background: var(--surface); border-right: 1px solid var(--outline);
    display: flex; flex-direction: column; padding: 16px; gap: 10px;
}
.sb-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.logo-mark { border-radius: 11px; }
.sb-label { color: var(--dim); font-size: 12px; margin-top: 6px; }
.search {
    width: 100%; background: var(--card); border: 1px solid var(--outline); border-radius: 12px;
    padding: 8px 12px; outline: none;
}
.search:focus { border-color: var(--cyan); }
.conv-list { flex: 1; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }
.conv {
    display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 10px; border-radius: 12px; cursor: pointer;
    color: var(--text);
}
.conv:hover, .conv.active { background: var(--card); }
.conv .ic { color: var(--dim); flex: 0 0 auto; }
.conv.active .ic { color: var(--cyan); }
.conv .meta { flex: 1; min-width: 0; }
.conv .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.conv .s { color: var(--dim); font-size: 11px; }
.conv .acts { display: none; }
.conv:hover .acts, .conv.active .acts { display: flex; }
.empty-note { color: var(--dim); font-size: 13px; padding: 10px; }
.sb-foot { display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--outline); padding-top: 10px; }
.sb-foot .btn { justify-content: flex-start; border-color: transparent; }
.sb-foot .btn:hover { background: var(--card); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.topbar {
    display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--outline);
    padding-top: calc(8px + env(safe-area-inset-top));
}
.title-box { flex: 1; min-width: 0; }
.conv-title { color: var(--dim); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-select {
    background: var(--card); border: 1px solid var(--outline); border-radius: 20px; padding: 7px 12px;
    font-weight: 600; font-size: 13px; outline: none; cursor: pointer; max-width: 140px;
}
.model-select:focus { border-color: var(--cyan); }
.mobile-only { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 18px 16px 8px; scroll-behavior: auto; }
.msg { max-width: 860px; margin: 0 auto 24px; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.bubble {
    background: #2A2F66; padding: 10px 14px; border-radius: 18px 18px 4px 18px;
    white-space: pre-wrap; word-break: break-word; max-width: min(680px, 94%);
}
.msg-head { display: flex; align-items: center; gap: 8px; color: var(--dim); font-size: 12px; margin-bottom: 8px; }
.msg-head img { border-radius: 7px; }
.msg-actions { display: flex; align-items: center; gap: 2px; margin-top: 4px; flex-wrap: wrap; }
.zip-btn { color: var(--cyan); display: inline-flex; align-items: center; gap: 6px; background: none; border: 0; cursor: pointer; padding: 6px 10px; border-radius: 10px; font-size: 13px; }
.zip-btn:hover { background: var(--card); }
.retry-row { max-width: 860px; margin: 0 auto 24px; text-align: center; }
.typing { color: var(--cyan); font-size: 12px; animation: pulse 1.1s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: .25; } to { opacity: 1; } }

/* ---------- Markdown ---------- */
.md > * { margin: 0 0 10px; }
.md > *:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 14px 0 6px; line-height: 1.3; }
.md h1 { font-size: 22px; } .md h2 { font-size: 19px; } .md h3 { font-size: 17px; } .md h4 { font-size: 16px; }
.md ul, .md ol { padding-left: 22px; }
.md li { margin: 3px 0; }
.md li::marker { color: var(--cyan); }
.md blockquote { margin: 0 0 10px; padding: 2px 0 2px 12px; border-left: 3px solid var(--violet); color: var(--dim); }
.md code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; background: var(--code); color: var(--cyan); padding: 1px 6px; border-radius: 6px; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border: 1px solid var(--outline); padding: 6px 10px; }
.md th { background: var(--card); }
.md hr { border: 0; border-top: 1px solid var(--outline); }
.md img { max-width: 100%; }

.code-card { margin: 0 0 12px; border: 1px solid var(--outline); background: var(--code); border-radius: 12px; overflow: hidden; }
.code-head { display: flex; align-items: center; gap: 8px; background: var(--card); padding: 2px 4px 2px 12px; }
.code-icon { color: var(--violet); display: inline-flex; }
.code-icon svg { width: 15px; height: 15px; }
.code-name { flex: 1; min-width: 0; color: var(--cyan); font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.code-card pre { margin: 0; padding: 12px; overflow-x: auto; }
.code-card pre code { background: none; color: #D6DBF5; padding: 0; font-size: 12.5px; line-height: 1.5; border-radius: 0; white-space: pre; }
.code-card pre code.hljs { background: none; padding: 0; }
.code-more { display: block; width: 100%; background: none; border: 0; border-top: 1px solid var(--outline); color: var(--cyan); font-size: 12px; padding: 8px; cursor: pointer; }

/* ---------- Welcome ---------- */
.welcome { max-width: 560px; margin: 6vh auto 0; text-align: center; display: flex; flex-direction: column; align-items: center; }
.welcome .glow { position: relative; width: 190px; height: 150px; display: flex; align-items: center; justify-content: center; }
.welcome .glow::before { content: ""; position: absolute; inset: -20px; background: radial-gradient(closest-side, rgba(139, 92, 255, .38), transparent); }
.welcome .glow img { position: relative; border-radius: 24px; }
.ideas { width: 100%; margin-top: 22px; display: flex; flex-direction: column; gap: 8px; }
.idea {
    display: flex; align-items: center; gap: 10px; text-align: left; width: 100%;
    background: var(--card); border: 1px solid var(--outline); border-radius: 14px; padding: 12px 14px; cursor: pointer; font-size: 13.5px;
}
.idea:hover { border-color: var(--cyan); }
.idea svg { color: var(--cyan); flex: 0 0 auto; }

/* ---------- Composer ---------- */
.composer { padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); max-width: 900px; width: 100%; margin: 0 auto; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; }
.chips:empty { display: none; }
.chip {
    display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--outline);
    border-radius: 12px; padding: 5px 4px 5px 10px; flex: 0 0 auto; max-width: 260px;
}
.chip.ro { padding-right: 10px; }
.chip svg { color: var(--cyan); flex: 0 0 auto; }
.chip .n { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }
.chip .s { color: var(--dim); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--outline); border-top-color: var(--cyan); animation: spin .8s linear infinite; align-self: center; flex: 0 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea {
    flex: 1; resize: none; background: var(--card); border: 1px solid transparent; border-radius: 22px;
    padding: 11px 16px; max-height: 200px; outline: none; line-height: 1.4;
}
.composer textarea:focus { border-color: var(--outline); }
.composer textarea::placeholder { color: var(--dim); }
.send-btn {
    width: 44px; height: 44px; flex: 0 0 44px; border-radius: 50%; border: 0; cursor: pointer; color: #fff;
    display: inline-flex; align-items: center; justify-content: center; background: var(--grad);
}
.send-btn:disabled { background: var(--card); color: var(--dim); cursor: not-allowed; }
.hint { text-align: center; color: var(--dim); font-size: 11px; margin-top: 6px; }
.scroll-btn {
    position: absolute; right: 18px; bottom: 120px; width: 38px; height: 38px; border-radius: 50%;
    background: var(--card); border: 1px solid var(--outline); color: var(--text); cursor: pointer;
    display: flex; align-items: center; justify-content: center; z-index: 5;
}
.drop-overlay {
    position: absolute; inset: 8px; z-index: 20; border: 2px dashed var(--cyan); border-radius: 18px;
    background: rgba(11, 13, 23, .85); display: flex; align-items: center; justify-content: center;
    color: var(--cyan); font-weight: 700; font-size: 18px; pointer-events: none;
}

/* ---------- Dialog ---------- */
.dlg { border: 1px solid var(--outline); background: var(--surface); color: var(--text); border-radius: 22px; padding: 0; width: min(560px, 94vw); max-height: 92vh; }
.dlg::backdrop { background: rgba(0, 0, 0, .6); }
.dlg-body { display: flex; flex-direction: column; gap: 12px; padding: 18px; max-height: 92vh; overflow-y: auto; }
.dlg-title { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; }
.dlg-title img { border-radius: 8px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--dim); }
.field input, .field select, .field textarea, .dlg select, .dlg input[type=number] {
    background: var(--card); border: 1px solid var(--outline); border-radius: 12px; padding: 10px 12px;
    color: var(--text); outline: none; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--cyan); }
.field textarea { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; resize: vertical; }
.row-between { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: center; }
.check { display: inline-flex; gap: 6px; align-items: center; color: var(--dim); }
.link { color: var(--cyan); }
.pw { border: 1px solid var(--outline); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }
.pw summary { cursor: pointer; color: var(--dim); }
.pw[open] summary { margin-bottom: 8px; }

.toast {
    position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
    background: var(--card); border: 1px solid var(--outline); color: var(--text); padding: 10px 16px; border-radius: 14px;
    z-index: 100; max-width: min(520px, 92vw); box-shadow: 0 8px 30px rgba(0, 0, 0, .5); white-space: pre-wrap; font-size: 14px;
}
.toast.error { border-color: var(--danger); }

/* ---------- Login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card {
    position: relative; width: min(400px, 100%); background: var(--surface); border: 1px solid var(--outline);
    border-radius: 26px; padding: 30px 24px 22px; display: flex; flex-direction: column; gap: 12px; align-items: stretch; overflow: hidden;
}
.login-glow { position: absolute; top: -80px; left: 50%; width: 320px; height: 240px; transform: translateX(-50%); background: radial-gradient(closest-side, rgba(139, 92, 255, .35), transparent); pointer-events: none; }
.login-logo { position: relative; align-self: center; border-radius: 22px; }
.login-card > * { position: relative; }
.alert { background: rgba(255, 107, 107, .12); border: 1px solid var(--danger); color: #FFB4B4; border-radius: 12px; padding: 10px 12px; font-size: 13px; }

/* ---------- Mobile ---------- */
.backdrop { display: none; }
@media (max-width: 820px) {
    .mobile-only { display: inline-flex; }
    .desktop-only { display: none; }
    .sidebar {
        position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; width: min(320px, 86vw);
        transform: translateX(-102%); transition: transform .2s ease;
        padding-top: calc(16px + env(safe-area-inset-top)); padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
    .sidebar.open { transform: translateX(0); }
    .backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 30; }
    .conv .acts { display: flex; }
    .messages { padding: 14px 12px 6px; }
    .wordmark.big { font-size: 32px; }
}
