:root {
    --bg: #050b14;
    --bg-2: #0a1422;
    --surface: rgba(10, 20, 34, 0.85);
    --surface-2: rgba(20, 35, 55, 0.7);
    --primary: #00d4ff;
    --primary-glow: rgba(0, 212, 255, 0.4);
    --primary-soft: rgba(0, 212, 255, 0.1);
    --primary-hover: #00a8cc;
    --accent: #ffb347;
    --text: #e6f4ff;
    --text-dim: #6a8aa3;
    --text-muted: #4a6a83;
    --border: rgba(0, 212, 255, 0.15);
    --error: #ff5577;
    --success: #00ff9d;
    --warn: #ffb347;
    --font: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --font-display: 'Orbitron', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background:
        radial-gradient(ellipse 80% 60% at 50% 50%, rgba(0, 80, 130, 0.18) 0%, transparent 60%),
        linear-gradient(rgba(0, 212, 255, 0.025) 1px, transparent 1px) 0 0 / 50px 50px,
        linear-gradient(90deg, rgba(0, 212, 255, 0.025) 1px, transparent 1px) 0 0 / 50px 50px,
        var(--bg);
}

#jarvis-canvas {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: 0.5;
}

/* ── Boot overlay ───────────────────────────────────────────── */
.boot-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 30px;
    transition: opacity 0.6s ease, visibility 0.6s;
}
.boot-overlay.hidden { opacity: 0; visibility: hidden; }

.boot-rings {
    position: relative;
    width: 140px;
    height: 140px;
}
.boot-ring {
    position: absolute;
    inset: 0;
    border: 2px solid var(--primary);
    border-radius: 50%;
    border-top-color: transparent;
    animation: bootSpin 1.6s linear infinite;
    box-shadow: 0 0 25px var(--primary-glow);
}
.boot-ring:nth-child(2) { inset: 14px; animation-duration: 2.2s; animation-direction: reverse; opacity: 0.7; }
.boot-ring:nth-child(3) { inset: 28px; animation-duration: 3s; opacity: 0.45; }
@keyframes bootSpin { to { transform: rotate(360deg); } }

.boot-text {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 6px;
    color: var(--primary);
    text-shadow: 0 0 30px var(--primary-glow);
}
.boot-status {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-dim);
    letter-spacing: 1px;
}

/* ── App layout ─────────────────────────────────────────────── */
.app {
    position: relative;
    z-index: 1;
    display: flex;
    height: 100vh;
    height: 100dvh;
}

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
    width: 280px;
    background: var(--surface);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 10;
}
.sidebar.collapsed { transform: translateX(-100%); position: absolute; height: 100%; }

.sidebar-header {
    padding: 18px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--primary) 0%, transparent 70%);
    position: relative;
    box-shadow: 0 0 20px var(--primary-glow);
}
.brand-mark::after {
    content: '';
    position: absolute;
    inset: 6px;
    border-radius: 50%;
    border: 1.5px solid var(--primary);
    border-top-color: transparent;
    animation: bootSpin 4s linear infinite;
}
.brand-name {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 2px;
    color: var(--primary);
}
.brand-sub { font-size: 10px; color: var(--text-muted); font-family: var(--font-mono); margin-top: 2px; }

.icon-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    width: 32px; height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}
.icon-btn:hover { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

.chat-list { flex: 1; overflow-y: auto; padding: 8px; }
.chat-item {
    padding: 10px 12px;
    margin-bottom: 4px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 13px;
    color: var(--text-dim);
    border: 1px solid transparent;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-item:hover { background: var(--surface-2); color: var(--text); }
.chat-item.active { background: var(--primary-soft); border-color: var(--border); color: var(--primary); }

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.footer-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    font-family: var(--font);
    transition: all 0.2s;
}
.footer-btn:hover { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 5;
}
.sidebar-overlay.show { display: block; }

/* ── Main area ──────────────────────────────────────────────── */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-2);
}

.topbar {
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface);
    backdrop-filter: blur(20px);
}
.topbar-left { display: flex; align-items: center; gap: 16px; }

.pulse-orbit {
    position: relative;
    width: 44px; height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.orbit-core {
    width: 12px; height: 12px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 20px var(--primary-glow);
    animation: corePulse 2s ease-in-out infinite;
    z-index: 2;
}
@keyframes corePulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.7; }
}
.orbit-ring {
    position: absolute;
    inset: 0;
    border: 1.5px solid var(--primary);
    border-radius: 50%;
    border-top-color: transparent;
    border-right-color: transparent;
    opacity: 0.5;
    animation: bootSpin 4s linear infinite;
}
.orbit-ring.r2 { inset: 4px; animation-duration: 6s; animation-direction: reverse; opacity: 0.35; }
.orbit-ring.r3 { inset: 8px; animation-duration: 8s; opacity: 0.2; }

.pulse-orbit.thinking .orbit-core { animation-duration: 0.5s; }
.pulse-orbit.thinking .orbit-ring { animation-duration: 1s; }
.pulse-orbit.speaking .orbit-core { background: var(--accent); box-shadow: 0 0 25px rgba(255, 179, 71, 0.6); }

.topbar-title { display: flex; flex-direction: column; }
.title-main { font-family: var(--font-display); font-size: 16px; letter-spacing: 2px; font-weight: 700; color: var(--text); }
.title-sub { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); margin-top: 2px; }

.status-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 100px;
    font-size: 12px;
    color: var(--text-dim);
    font-family: var(--font-mono);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.status-dot.connected { background: var(--success); box-shadow: 0 0 10px var(--success); }
.status-dot.disconnected { background: var(--error); }
.status-dot.connecting { background: var(--warn); animation: corePulse 1s infinite; }

/* ── Chat area ──────────────────────────────────────────────── */
.chat { flex: 1; overflow-y: auto; padding: 24px; scroll-behavior: smooth; }
.messages { max-width: 900px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }

.welcome {
    text-align: center;
    padding: 60px 20px;
    color: var(--text);
}
.welcome-arc {
    width: 100px; height: 100px;
    margin: 0 auto 30px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(0, 212, 255, 0.3) 0%, transparent 70%);
    border: 2px solid var(--primary);
    box-shadow: 0 0 60px var(--primary-glow);
    animation: corePulse 3s ease-in-out infinite;
}
.welcome h2 {
    font-family: var(--font-display);
    font-size: 26px;
    letter-spacing: 3px;
    margin-bottom: 12px;
    color: var(--text);
}
.welcome p { color: var(--text-dim); margin-bottom: 30px; line-height: 1.6; }

.quick-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    max-width: 600px;
    margin: 0 auto;
}
.qa {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}
.qa:hover { background: var(--primary-soft); border-color: var(--primary); transform: translateY(-1px); }
.qa-icon { font-size: 18px; }

.message {
    display: flex;
    gap: 14px;
    animation: msgIn 0.3s ease-out;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.message-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    border: 1px solid var(--border);
}
.message.user .message-avatar { background: var(--surface-2); color: var(--text-dim); }
.message.assistant .message-avatar {
    background: radial-gradient(circle, var(--primary) 0%, var(--primary-hover) 100%);
    color: var(--bg);
    font-weight: 700;
    box-shadow: 0 0 15px var(--primary-glow);
}
.message-content {
    flex: 1;
    min-width: 0;
    padding-top: 4px;
}
.message-role {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-bottom: 4px;
    letter-spacing: 1px;
    text-transform: uppercase;
}
.message-text {
    line-height: 1.6;
    color: var(--text);
    word-wrap: break-word;
}
.message-text p { margin-bottom: 10px; }
.message-text p:last-child { margin-bottom: 0; }
.message-text code {
    font-family: var(--font-mono);
    background: var(--surface-2);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    color: var(--primary);
}
.message-text pre {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
    margin: 10px 0;
}
.message-text pre code { background: transparent; padding: 0; }

.message-thought {
    margin-top: 10px;
    padding: 10px 12px;
    background: var(--surface-2);
    border-left: 2px solid var(--accent);
    border-radius: 6px;
    font-size: 12px;
    color: var(--text-dim);
    font-family: var(--font-mono);
    white-space: pre-wrap;
    max-height: 200px;
    overflow-y: auto;
}
.thought-label { color: var(--accent); font-weight: 600; margin-bottom: 4px; }

.tool-call {
    margin-top: 8px;
    padding: 8px 10px;
    background: rgba(0, 212, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--text-dim);
}
.tool-call .tool-name { color: var(--primary); font-weight: 600; }

/* Typing indicator */
.typing { display: flex; gap: 4px; padding: 4px 0; }
.typing span {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--primary);
    animation: typingDot 1.4s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingDot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Composer ───────────────────────────────────────────────── */
.composer {
    border-top: 1px solid var(--border);
    background: var(--surface);
    backdrop-filter: blur(20px);
    padding: 12px 24px 16px;
}
.composer-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.ctl {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 100px;
    color: var(--text-dim);
    font-size: 12px;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.2s;
}
.ctl:hover { color: var(--primary); border-color: var(--primary); }
.ctl[data-active="true"] {
    background: var(--primary-soft);
    color: var(--primary);
    border-color: var(--primary);
}
.ctl.recording {
    background: rgba(255, 85, 119, 0.15);
    color: var(--error);
    border-color: var(--error);
    animation: corePulse 1s infinite;
}
.ctl-spacer { flex: 1; }

.tts-engine-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 100px;
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}
.tts-engine-pill .dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
}

.composer-input {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 8px 8px 8px 16px;
    transition: all 0.2s;
}
.composer-input:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
#user-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    resize: none;
    max-height: 160px;
    outline: none;
    line-height: 1.5;
}
#user-input::placeholder { color: var(--text-muted); }
.send-btn {
    width: 40px; height: 40px;
    border-radius: 10px;
    background: var(--primary);
    border: none;
    color: var(--bg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}
.send-btn:hover { background: var(--primary-hover); transform: scale(1.05); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Modal ──────────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal[hidden] { display: none; }
.modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-head {
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-head h3 { font-family: var(--font-display); font-size: 14px; letter-spacing: 2px; color: var(--primary); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }

.loading { color: var(--text-dim); text-align: center; padding: 30px; }

.status-section { margin-bottom: 24px; }
.status-section h4 {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 10px;
    font-family: var(--font-mono);
}
.status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.status-row:last-child { border-bottom: none; }
.status-key { color: var(--text-dim); }
.status-val { color: var(--text); font-family: var(--font-mono); }
.status-val.good { color: var(--success); }
.status-val.warn { color: var(--warn); }

.mcp-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
}
.mcp-chip {
    padding: 8px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.mcp-chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); box-shadow: 0 0 6px var(--success); }
.mcp-chip.offline .dot { background: var(--error); box-shadow: 0 0 6px var(--error); }

.memory-add { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.memory-add input, .memory-add textarea {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
}
.memory-add input:focus, .memory-add textarea:focus { border-color: var(--primary); }
.memory-add textarea { min-height: 70px; resize: vertical; }
.primary-btn {
    background: var(--primary);
    color: var(--bg);
    border: none;
    border-radius: 8px;
    padding: 10px 16px;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font);
    transition: all 0.2s;
}
.primary-btn:hover { background: var(--primary-hover); }

.memory-list { display: flex; flex-direction: column; gap: 8px; }
.memory-item {
    padding: 10px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 12px;
}
.memory-item .key { color: var(--primary); font-weight: 600; margin-bottom: 4px; font-family: var(--font-mono); }
.memory-item .value { color: var(--text-dim); }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        height: 100%;
        transform: translateX(-100%);
    }
    .sidebar.show { transform: translateX(0); }
    .quick-actions { grid-template-columns: 1fr; }
    .composer { padding: 10px 14px 12px; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }
