:root {
    --bg: #060b14;
    --bg-panel: #0b1322;
    --bg-panel2: #0f1a2e;
    --border: #1c2c47;
    --text: #d7e3f4;
    --text-dim: #7f93b2;
    --accent: #38c8ff;
    --accent-dim: #1485b3;
    --glow: 0 0 12px rgba(56, 200, 255, .45);
    --danger: #ff5d5d;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 15px;
}

/* ---------- Arc reactor ---------- */
.reactor {
    width: 64px; height: 64px;
    border-radius: 50%;
    border: 2px solid var(--accent);
    box-shadow: var(--glow), inset 0 0 18px rgba(56,200,255,.35);
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto;
    animation: pulse 3s ease-in-out infinite;
}
.reactor-core {
    width: 45%; height: 45%;
    border-radius: 50%;
    background: radial-gradient(circle, #eaffff 0%, var(--accent) 55%, transparent 75%);
}
.reactor.small { width: 28px; height: 28px; border-width: 1.5px; margin: 0; }
.reactor.big   { width: 90px; height: 90px; }
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 8px rgba(56,200,255,.35), inset 0 0 12px rgba(56,200,255,.25); }
    50%      { box-shadow: 0 0 22px rgba(56,200,255,.7),  inset 0 0 22px rgba(56,200,255,.5); }
}

/* ---------- Login ---------- */
.login-body {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh;
    background: radial-gradient(ellipse at 50% 30%, #0c1830 0%, var(--bg) 70%);
}
.login-box {
    width: min(360px, 92vw);
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 36px 30px;
    text-align: center;
    box-shadow: 0 8px 40px rgba(0,0,0,.5);
}
.login-box h1 {
    margin: 18px 0 2px;
    letter-spacing: .35em;
    font-weight: 300;
    color: var(--accent);
    text-shadow: var(--glow);
}
.login-sub { color: var(--text-dim); font-size: 12px; margin: 0 0 24px; }
.login-box input {
    width: 100%; margin-bottom: 12px; padding: 12px 14px;
    background: var(--bg-panel2); color: var(--text);
    border: 1px solid var(--border); border-radius: 8px;
    outline: none; font-size: 15px;
}
.login-box input:focus { border-color: var(--accent-dim); }
.login-box button {
    width: 100%; padding: 12px;
    background: linear-gradient(180deg, var(--accent-dim), #0d5f80);
    color: #eaffff; border: none; border-radius: 8px;
    font-size: 15px; letter-spacing: .06em; cursor: pointer;
}
.login-box button:hover { filter: brightness(1.15); }
.login-error {
    background: rgba(255,93,93,.12); border: 1px solid rgba(255,93,93,.4);
    color: var(--danger); border-radius: 8px;
    padding: 9px; margin-bottom: 14px; font-size: 13px;
}

/* ---------- App layout ---------- */
#app { display: flex; height: 100vh; height: 100dvh; }

#sidebar {
    width: 270px; flex-shrink: 0;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
}
.sidebar-head {
    display: flex; align-items: center; gap: 10px;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}
.brand { letter-spacing: .28em; color: var(--accent); font-weight: 300; }

#new-chat {
    margin: 14px; padding: 10px;
    background: transparent; color: var(--accent);
    border: 1px dashed var(--accent-dim); border-radius: 8px;
    cursor: pointer; font-size: 14px;
}
#new-chat:hover { background: rgba(56,200,255,.08); }

#conv-list { flex: 1; overflow-y: auto; padding: 0 8px; }
.conv-item {
    display: flex; align-items: center;
    padding: 9px 10px; margin-bottom: 4px;
    border-radius: 8px; cursor: pointer;
    color: var(--text-dim); font-size: 13.5px;
}
.conv-item:hover { background: var(--bg-panel2); color: var(--text); }
.conv-item.active { background: var(--bg-panel2); color: var(--accent); }
.conv-item .title {
    flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.conv-item .del {
    visibility: hidden; border: none; background: none;
    color: var(--text-dim); cursor: pointer; font-size: 14px; padding: 0 4px;
}
.conv-item:hover .del { visibility: visible; }
.conv-item .del:hover { color: var(--danger); }

.sidebar-foot { padding: 14px; border-top: 1px solid var(--border); }
.logout { color: var(--text-dim); font-size: 13px; text-decoration: none; }
.logout:hover { color: var(--danger); }

/* ---------- Chat ---------- */
#chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#messages {
    flex: 1; overflow-y: auto;
    padding: 28px clamp(14px, 6vw, 90px);
    scroll-behavior: smooth;
}
.welcome { text-align: center; margin-top: 14vh; color: var(--text-dim); }
.welcome h2 { color: var(--text); font-weight: 300; letter-spacing: .08em; margin: 22px 0 6px; }

.msg { margin-bottom: 22px; max-width: 100%; line-height: 1.55; }
.msg .who {
    font-size: 11px; letter-spacing: .18em; text-transform: uppercase;
    color: var(--text-dim); margin-bottom: 5px;
}
.msg.user .who { color: #9fb6d8; }
.msg.assistant .who { color: var(--accent); }
.msg .bubble {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 13px 17px;
    overflow-wrap: break-word;
}
.msg.user .bubble { background: var(--bg-panel2); }
.msg.assistant .bubble { border-color: rgba(56,200,255,.25); }

.bubble p:first-child { margin-top: 0; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre {
    background: #050a12; border: 1px solid var(--border);
    border-radius: 8px; padding: 12px; overflow-x: auto; font-size: 13px;
}
.bubble code { font-family: Consolas, "Courier New", monospace; color: #9fe8ff; }
.bubble pre code { color: var(--text); }
.bubble a { color: var(--accent); }
.bubble table { border-collapse: collapse; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 6px 10px; }
.bubble blockquote {
    border-left: 3px solid var(--accent-dim);
    margin: 8px 0; padding: 2px 14px; color: var(--text-dim);
}

.typing { display: inline-block; }
.typing span {
    display: inline-block; width: 7px; height: 7px; margin-right: 4px;
    border-radius: 50%; background: var(--accent);
    animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .15; } 40% { opacity: 1; } }

.error-line { color: var(--danger); font-size: 13px; margin-bottom: 18px; }

/* ---------- Composer ---------- */
#composer {
    display: flex; gap: 10px; align-items: flex-end;
    padding: 14px clamp(14px, 6vw, 90px) 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-panel);
}
#prompt {
    flex: 1; resize: none; max-height: 180px;
    background: var(--bg-panel2); color: var(--text);
    border: 1px solid var(--border); border-radius: 10px;
    padding: 12px 14px; font-size: 15px; font-family: inherit;
    outline: none; line-height: 1.4;
}
#prompt:focus { border-color: var(--accent-dim); box-shadow: 0 0 0 2px rgba(56,200,255,.12); }
#send {
    width: 46px; height: 46px; flex-shrink: 0;
    background: linear-gradient(180deg, var(--accent-dim), #0d5f80);
    border: none; border-radius: 10px;
    color: #eaffff; font-size: 17px; cursor: pointer;
}
#send:disabled { opacity: .4; cursor: default; }
#send:not(:disabled):hover { filter: brightness(1.2); }

/* ---------- Mobile ---------- */
#sidebar-toggle {
    display: none;
    position: fixed; top: 12px; left: 12px; z-index: 30;
    width: 40px; height: 40px;
    background: var(--bg-panel); color: var(--accent);
    border: 1px solid var(--border); border-radius: 8px;
    font-size: 18px; cursor: pointer;
}
@media (max-width: 760px) {
    #sidebar {
        position: fixed; z-index: 20; height: 100%;
        transform: translateX(-100%);
        transition: transform .25s ease;
        box-shadow: 4px 0 30px rgba(0,0,0,.6);
    }
    #sidebar.open { transform: translateX(0); }
    #sidebar-toggle { display: block; }
    #messages { padding-top: 64px; }
}
