:root {
    color-scheme: dark;
    --bg: #0d1117;
    --panel: #111827;
    --panel-2: #161b22;
    --border: #263244;
    --text: #e6edf3;
    --muted: #8b949e;
    --accent: #2f81f7;
    --accent-2: #10b981;
    --danger: #ef4444;
    --code: #0b1020;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
    font: inherit;
}

.app-shell {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    border-right: 1px solid var(--border);
    background: #0b1220;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: white;
    font-weight: 800;
}

.brand strong,
.brand span {
    display: block;
}

.brand span,
.hint,
.topbar p,
.history-item small {
    color: var(--muted);
    font-size: 13px;
}

.field {
    display: grid;
    gap: 7px;
}

.voice-panel {
    display: grid;
    gap: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(17, 24, 39, 0.62);
    padding: 12px;
}

.voice-title {
    color: #c9d1d9;
    font-size: 13px;
    font-weight: 800;
}

.toggle-row {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 32px;
    color: var(--text);
    font-weight: 600;
}

.toggle-row input {
    width: 16px;
    height: 16px;
}

label,
.history-head {
    color: #c9d1d9;
    font-size: 13px;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #0f172a;
    color: var(--text);
    outline: none;
}

input,
select {
    height: 40px;
    padding: 0 11px;
}

textarea {
    padding: 14px;
    resize: vertical;
    line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(47, 129, 247, 0.18);
}

button {
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.primary-btn,
.secondary-btn,
.ghost-btn {
    min-height: 40px;
    padding: 0 14px;
}

.primary-btn {
    background: var(--accent);
    color: #fff;
}

.secondary-btn {
    background: #273449;
    color: var(--text);
}

.ghost-btn {
    background: transparent;
    color: var(--muted);
}

.history-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
}

.history-list {
    display: grid;
    gap: 8px;
    overflow-y: auto;
    min-height: 0;
}

.history-item {
    display: grid;
    gap: 4px;
    width: 100%;
    padding: 10px;
    text-align: left;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
}

.history-item:hover,
.history-item.active {
    border-color: var(--border);
    background: #111c2f;
}

.history-item span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-panel {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    min-width: 0;
    min-height: 100vh;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 28px;
    border-bottom: 1px solid var(--border);
    background: rgba(13, 17, 23, 0.9);
}

.topbar h1 {
    margin: 0 0 4px;
    font-size: 21px;
}

.topbar p {
    margin: 0;
}

.status-pill {
    white-space: nowrap;
    border: 1px solid var(--border);
    background: var(--panel-2);
    border-radius: 999px;
    padding: 7px 12px;
    color: var(--muted);
    font-size: 13px;
}

.messages {
    overflow-y: auto;
    padding: 28px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.empty-state {
    margin: auto;
    max-width: 680px;
    color: var(--muted);
    text-align: center;
    line-height: 1.7;
}

.message {
    width: min(100%, 980px);
    display: grid;
    grid-template-columns: 86px minmax(0, 1fr);
    gap: 14px;
}

.message.user {
    align-self: flex-end;
}

.message-content {
    min-width: 0;
}

.role {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0;
    padding-top: 10px;
}

.bubble {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel);
    padding: 16px;
    min-width: 0;
    line-height: 1.65;
}

.user .bubble {
    background: #10213d;
}

.bubble p:first-child,
.bubble pre:first-child {
    margin-top: 0;
}

.bubble p:last-child,
.bubble pre:last-child {
    margin-bottom: 0;
}

.bubble pre {
    position: relative;
    overflow: auto;
    border: 1px solid #263244;
    border-radius: 8px;
    background: var(--code);
    padding: 44px 14px 14px;
}

.bubble code {
    font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
    font-size: 13px;
}

.bubble :not(pre) > code {
    border: 1px solid var(--border);
    border-radius: 5px;
    background: #101826;
    padding: 2px 5px;
}

.code-toolbar {
    position: absolute;
    inset: 0 0 auto 0;
    height: 34px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 8px 0 12px;
    border-bottom: 1px solid #263244;
    background: #111827;
    color: var(--muted);
    font-size: 12px;
}

.copy-code {
    min-height: 24px;
    padding: 0 9px;
    background: #263244;
    color: var(--text);
    border-radius: 6px;
    font-size: 12px;
}

.message-tools {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.mini-btn {
    min-height: 30px;
    padding: 0 10px;
    background: #263244;
    color: var(--text);
    border-radius: 6px;
    font-size: 12px;
}

.composer {
    border-top: 1px solid var(--border);
    background: #0b1220;
    padding: 18px 28px;
}

.composer-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
}

.composer-actions .hint {
    margin-right: auto;
}

#voicePlayer {
    display: block;
    width: 100%;
    height: 38px;
    margin-top: 12px;
}

#voicePlayer:not([src]) {
    display: none;
}

@media (max-width: 860px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .history-list {
        max-height: 170px;
    }

    .message {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .topbar,
    .messages,
    .composer {
        padding-left: 16px;
        padding-right: 16px;
    }
}
