/* ── Reset & base ──────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* ── Palette — matches souravtripathy.com night mode ───────────────────── */
    --bg: #0c1f16;
    --bg-raise: #112318;
    --bg-surface: #162c1e;
    --border: #1e3828;
    --text: #d4e8dc;
    --text-muted: #7a9a87;
    --text-faint: #2e4c3c;
    --accent: #d4e8dc;
    /* same mint-white — links/highlights */
    --accent-dim: rgba(212, 232, 220, 0.08);
    --accent-pulse: rgba(212, 232, 220, 0.35);
    --green-glow: rgba(72, 187, 112, 0.18);

    /* ── Typography ────────────────────────────────────────────────────────── */
    --font-mono: 'Space Mono', 'Courier New', monospace;
    --font-serif: 'Spectral', Georgia, serif;

    /* ── Layout ────────────────────────────────────────────────────────────── */
    --sidebar-w: 300px;
    --header-h: 48px;

    /* ── Animation ─────────────────────────────────────────────────────────── */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

html,
body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}

/* ── Scrollbars ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 3px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

/* ── App shell ──────────────────────────────────────────────────────────────── */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* ── Header ────────────────────────────────────────────────────────────────── */
header {
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    position: relative;
    z-index: 20;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

#sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}

#sidebar-toggle:hover {
    color: var(--text);
    background: var(--bg-surface);
}

.site-title {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.02em;
}

.site-title a {
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 1px dotted var(--text-faint);
    font-size: 0.75rem;
    font-weight: 400;
    margin-left: 8px;
    letter-spacing: 0;
    transition: color 0.2s, border-color 0.2s;
}

.site-title a:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

/* Status indicator */
.status-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--text-faint);
    transition: background 0.4s;
}

.status-dot.online {
    background: #4bbb70;
    box-shadow: 0 0 0 0 var(--green-glow);
    animation: pulse 2.8s ease-in-out infinite;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
    margin-left: 10px;
    display: flex;
    align-items: center;
}

.icon-btn:hover {
    color: var(--text);
    background: var(--bg-surface);
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(75, 187, 112, 0.5);
    }

    60% {
        box-shadow: 0 0 0 7px rgba(75, 187, 112, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(75, 187, 112, 0);
    }
}

#status-label {
    font-size: 0.68rem;
    color: var(--text-muted);
    letter-spacing: 0.06em;
    font-family: var(--font-mono);
}

/* ── Main content ───────────────────────────────────────────────────────────── */
main {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
#sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 32px 24px 40px;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    gap: 0;
}

.sidebar-block {
    margin-bottom: 28px;
}

.sidebar-label {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    color: var(--text-faint);
    letter-spacing: 0.16em;
    text-transform: uppercase;
    margin-bottom: 10px;
}

.sidebar-prose {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.85;
    font-family: var(--font-mono);
}

.sidebar-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

/* Spec table */
.spec-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
    font-family: var(--font-mono);
}

.spec-table td {
    padding: 3px 0;
    vertical-align: top;
}

.spec-table td:first-child {
    color: var(--text-faint);
    padding-right: 14px;
    white-space: nowrap;
    letter-spacing: 0.06em;
}

.spec-table td:last-child {
    color: var(--text-muted);
}

/* Offline notice — shown only when backend is down */
.offline-notice {
    display: none;
    font-size: 0.74rem;
    color: var(--text-muted);
    line-height: 1.9;
    font-family: var(--font-mono);
    padding: 14px 0 0;
    border-top: 1px solid var(--border);
}

body.offline .offline-notice {
    display: block;
}

/* ── Chat area ───────────────────────────────────────────────────────────────── */
#chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
}

/* ── Logs Panel ─────────────────────────────────────────────────────────────── */
#logs-panel {
    width: var(--sidebar-w);
    flex-shrink: 0;
    border-left: 1px solid var(--border);
    background: var(--bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.3s var(--ease-out);
}

.logs-header {
    height: 48px;
    display: flex;
    align-items: center;
    padding: 0 24px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.logs-title {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    color: var(--text-faint);
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

#logs-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.72rem;
    font-family: var(--font-mono);
    color: var(--text-muted);
}

.log-entry {
    word-break: break-all;
    border-bottom: 1px dashed var(--border);
    padding-bottom: 8px;
    margin-bottom: 8px;
}

.log-entry.error {
    color: #e27d60;
}

/* Message log */
#chat-log {
    flex: 1;
    overflow-y: auto;
    padding: 36px 52px;
    display: flex;
    flex-direction: column;
    gap: 22px;
}

/* Empty state */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 8px;
    color: var(--text-faint);
    pointer-events: none;
    user-select: none;
    padding: 0 0 60px;
}

.empty-state-title {
    font-family: var(--font-serif);
    font-style: italic;
    font-size: 1.25rem;
    color: var(--text-muted);
    font-weight: 400;
}

.empty-state-sub {
    font-size: 0.72rem;
    font-family: var(--font-mono);
    color: var(--text-faint);
    letter-spacing: 0.04em;
}

/* ── Messages ────────────────────────────────────────────────────────────────── */
.message {
    display: flex;
    animation: slide-up 0.22s var(--ease-out) both;
}

.message.user {
    justify-content: flex-end;
}

.message.assistant {
    justify-content: flex-start;
}

@keyframes slide-up {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.bubble {
    max-width: 74%;
    padding: 11px 16px;
    border-radius: 6px;
    font-size: 0.82rem;
    line-height: 1.8;
    word-break: break-word;
}

.message.user .bubble {
    background: var(--accent-dim);
    color: var(--text);
    border: 1px solid rgba(212, 232, 220, 0.12);
    border-bottom-right-radius: 2px;
    font-family: var(--font-mono);
}

.message.assistant .bubble {
    background: var(--bg-surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 2px;
    font-family: var(--font-mono);
}

/* Code blocks */
.bubble pre {
    background: var(--bg-raise);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 10px;
    margin: 10px 0 2px;
    overflow-x: auto;
}

.bubble code {
    font-family: var(--font-mono);
    font-size: 0.76rem;
    color: #8ecfa8;
}

/* Thinking dots */
.bubble.thinking {
    padding: 13px 18px;
    display: flex;
    gap: 5px;
    align-items: center;
}

.bubble.thinking .dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: blink 1.2s ease-in-out infinite;
}

.bubble.thinking .dot:nth-child(2) {
    animation-delay: 0.2s;
}

.bubble.thinking .dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes blink {

    0%,
    80%,
    100% {
        opacity: 0.2;
        transform: scale(1);
    }

    40% {
        opacity: 1;
        transform: scale(1.15);
    }
}

/* ── Metrics bar ─────────────────────────────────────────────────────────────── */
#metrics-bar {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    color: var(--text-faint);
    text-align: center;
    padding: 4px 0;
    letter-spacing: 0.06em;
    opacity: 0;
    transition: opacity 0.4s;
}

/* ── Input row ───────────────────────────────────────────────────────────────── */
#input-row {
    padding: 14px 52px 26px;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

#chat-input {
    flex: 1;
    resize: none;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.7;
    padding: 9px 13px;
    max-height: 160px;
    outline: none;
    transition: border-color 0.2s;
}

#chat-input::placeholder {
    color: var(--text-faint);
}

#chat-input:focus {
    border-color: rgba(212, 232, 220, 0.3);
}

#send-btn {
    flex-shrink: 0;
    background: var(--bg-surface);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 5px;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s, transform 0.1s;
}

#send-btn:hover:not(:disabled) {
    color: var(--text);
    border-color: rgba(212, 232, 220, 0.3);
}

#send-btn:active:not(:disabled) {
    transform: scale(0.93);
}

#send-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ── Responsive — mobile ─────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    #sidebar-toggle {
        display: flex;
    }

    #sidebar {
        position: fixed;
        inset: var(--header-h) 0 0 0;
        width: 100%;
        z-index: 30;
        border-right: none;
        border-bottom: 1px solid var(--border);
        transform: translateY(-100%);
        opacity: 0;
        pointer-events: none;
        transition: transform 0.3s var(--ease-out), opacity 0.25s;
        max-height: 65vh;
        overflow-y: auto;
    }

    #sidebar.open {
        transform: translateY(0);
        opacity: 1;
        pointer-events: auto;
    }

    #logs-panel {
        position: fixed;
        inset: var(--header-h) 0 0 0;
        width: 100%;
        z-index: 30;
        border-left: none;
        border-bottom: 1px solid var(--border);
        transform: translateY(-100%);
        opacity: 0;
        pointer-events: none;
        transition: transform 0.3s var(--ease-out), opacity 0.25s;
        max-height: 50vh;
    }

    #logs-panel.open {
        transform: translateY(0);
        opacity: 1;
        pointer-events: auto;
        display: flex;
    }

    #chat-log {
        padding: 24px 20px;
    }

    #input-row {
        padding: 12px 20px 20px;
    }

    .bubble {
        max-width: 92%;
    }
}