@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&display=swap');

:root {
    --chat-surface: rgba(18, 8, 30, 0.72);
    --chat-surface-strong: rgba(22, 10, 36, 0.9);
    --chat-border: rgba(255, 255, 255, 0.14);
    --chat-soft: rgba(255, 255, 255, 0.08);
    --chat-text: #f8f5ff;
    --chat-text-muted: rgba(248, 245, 255, 0.72);
    --chat-accent: #9ee3ff;
    --chat-accent-soft: rgba(158, 227, 255, 0.22);
    --chat-danger: #ff7676;
    --chat-warning: #ffcc73;
}

html,
body {
    margin: 0;
    height: 100%;
    min-height: 100%;
}

body {
    font-family: 'Manrope', 'Segoe UI', sans-serif;
    color: var(--chat-text);
    overflow: hidden;
}

.chat-page {
    height: 100vh;
    height: 100dvh;
    min-height: 100vh;
    min-height: 100dvh;
    position: relative;
}

.chat-shell {
    width: min(100%, 980px);
    height: 100%;
    max-height: 100%;
    min-height: 0;
    margin: 0 auto;
    padding: 12px;
    box-sizing: border-box;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 12px;
    position: relative;
    z-index: 1;
    overflow: hidden;
}

.chat-topbar {
    position: relative;
    z-index: 30;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    background: var(--chat-surface);
    border: 1px solid var(--chat-border);
    border-radius: 18px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 10px 12px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    text-decoration: none;
    color: #fff;
    font-weight: 700;
    letter-spacing: 0.2px;
}

.brand img {
    width: 32px;
    height: 32px;
    object-fit: contain;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.3));
}

.plan-chip {
    justify-self: center;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.92rem;
    color: var(--chat-text-muted);
    background: var(--chat-soft);
    border: 1px solid var(--chat-border);
    padding: 7px 10px;
    border-radius: 999px;
}

.menu-root {
    position: relative;
}

.menu-button {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid var(--chat-border);
    background: var(--chat-soft);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.menu-button:hover {
    background: rgba(255, 255, 255, 0.18);
}

.menu-button svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.menu-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 190px;
    background: var(--chat-surface-strong);
    border: 1px solid var(--chat-border);
    border-radius: 14px;
    padding: 6px;
    display: grid;
    gap: 4px;
    box-shadow: 0 16px 35px rgba(0, 0, 0, 0.35);
    z-index: 50;
}

.menu-dropdown button {
    border: 0;
    background: transparent;
    color: var(--chat-text);
    border-radius: 10px;
    text-align: left;
    padding: 10px 12px;
    cursor: pointer;
    font-size: 0.92rem;
}

.menu-dropdown button:hover {
    background: rgba(255, 255, 255, 0.12);
}

.menu-dropdown .menu-danger {
    color: #ffd0d0;
}

.chat-stream {
    position: relative;
    z-index: 1;
    min-height: 0;
    overflow: auto;
    background: var(--chat-surface);
    border: 1px solid var(--chat-border);
    border-radius: 20px;
    padding: 16px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    overflow-y: auto;
}

.empty-state {
    min-height: 100%;
    display: grid;
    place-content: center;
    text-align: center;
    gap: 8px;
    color: var(--chat-text-muted);
}

.empty-state h1 {
    margin: 0;
    color: #fff;
    font-size: 1.15rem;
}

.empty-state p {
    margin: 0;
}

.message-row {
    display: flex;
    margin-bottom: 10px;
}

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

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

.message-bubble {
    max-width: min(82%, 680px);
    border-radius: 16px;
    border: 1px solid var(--chat-border);
    padding: 10px 12px;
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.2);
}

.bubble-user {
    background: linear-gradient(135deg, rgba(132, 214, 255, 0.25), rgba(112, 165, 255, 0.18));
}

.bubble-assistant {
    background: rgba(255, 255, 255, 0.08);
}

.message-bubble.bubble-error {
    border-color: rgba(255, 118, 118, 0.68);
    background: rgba(255, 118, 118, 0.1);
}

.retry-request-btn {
    margin-top: 10px;
    border: 1px solid rgba(255, 255, 255, 0.26);
    border-radius: 10px;
    padding: 7px 10px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--chat-text);
    font: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
}

.retry-request-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.18);
}

.retry-request-btn:focus-visible {
    outline: 2px solid var(--chat-accent);
    outline-offset: 2px;
}

.retry-request-btn:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.bubble-clarify {
    border-color: rgba(255, 211, 125, 0.68);
    background: rgba(255, 211, 125, 0.12);
}

.bubble-timer {
    border-color: rgba(255, 204, 115, 0.72);
    background: linear-gradient(135deg, rgba(255, 204, 115, 0.2), rgba(255, 164, 92, 0.1));
    box-shadow: inset 3px 0 0 var(--chat-warning), 0 10px 22px rgba(0, 0, 0, 0.2);
}

.timer-message-label {
    margin-bottom: 7px;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--chat-warning);
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.timer-message-label svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.message-text {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.45;
}

.message-time {
    margin-top: 8px;
    display: block;
    font-size: 0.75rem;
    color: var(--chat-text-muted);
}

.message-audio {
    margin-top: 10px;
}

.message-audio audio {
    display: none;
}

.audio-btn {
    border: 1px solid var(--chat-border);
    background: rgb(0 0 0 / 30%);
    color: #fff;
    border-radius: 10px;
    padding: 6px 10px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    font-size: 0.86rem;
}

.audio-btn svg {
    width: 15px;
    height: 15px;
    fill: currentColor;
}

.typing-state {
    margin-top: 8px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--chat-text-muted);
    font-size: 0.9rem;
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--chat-accent);
    animation: dotBlink 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.15s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes dotBlink {
    0%, 80%, 100% { opacity: 0.3; transform: scale(1); }
    40% { opacity: 1; transform: scale(1.3); }
}

.chat-footer {
    position: relative;
    z-index: 20;
    background: var(--chat-surface);
    border: 1px solid var(--chat-border);
    border-radius: 18px;
    padding: 10px;
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr) 58px;
    align-items: stretch;
    gap: 10px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.response-mode-root {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: center;
}

.response-mode-trigger {
    width: 52px;
    height: 52px;
    border: 1px solid var(--chat-border);
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(158, 227, 255, 0.3), rgba(134, 171, 255, 0.22));
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.response-mode-trigger:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.response-mode-trigger:focus-visible,
.response-mode-menu button:focus-visible {
    outline: 2px solid var(--chat-accent);
    outline-offset: 2px;
}

.response-mode-menu {
    position: absolute;
    left: 0;
    bottom: calc(100% + 8px);
    z-index: 40;
    min-width: 170px;
    padding: 6px;
    display: grid;
    gap: 4px;
    border: 1px solid var(--chat-border);
    border-radius: 14px;
    background: var(--chat-surface-strong);
    box-shadow: 0 16px 35px rgba(0, 0, 0, 0.35);
}

.response-mode-menu button {
    border: 0;
    border-radius: 10px;
    padding: 9px 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    background: transparent;
    color: var(--chat-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.response-mode-menu button:hover,
.response-mode-menu button.is-active {
    background: var(--chat-accent-soft);
}

.response-mode-icon {
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    display: inline-flex;
}

.response-mode-icon svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
    overflow: visible;
}

.response-mode-icon text {
    fill: #fff;
    stroke: #24102f;
    stroke-width: 2px;
    paint-order: stroke;
    font: 800 12px 'Manrope', sans-serif;
}

.response-mode-icon .mode-mark-outline,
.response-mode-icon .mode-mark {
    fill: none;
    stroke-linecap: round;
}

.response-mode-icon .mode-mark-outline {
    stroke: #24102f;
    stroke-width: 5.5px;
}

.response-mode-icon .mode-mark {
    stroke: #fff;
    stroke-width: 2.7px;
}

.composer-center {
    min-height: 98px;
    height: 100%;
}

.composer-center textarea {
    width: 100%;
    height: 100%;
    min-height: 0;
    max-height: none;
    resize: none;
    border-radius: 12px;
    border: 1px solid var(--chat-border);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font: inherit;
    line-height: 1.4;
    padding: 11px 12px;
}

.composer-center textarea:focus {
    outline: none;
    border-color: rgba(158, 227, 255, 0.62);
    box-shadow: 0 0 0 3px rgba(158, 227, 255, 0.15);
}

.composer-center textarea::placeholder {
    color: rgba(248, 245, 255, 0.56);
}

.voice-panel {
    border: 1px solid var(--chat-border);
    border-radius: 12px;
    padding: 9px 10px 10px;
    background: rgba(255, 255, 255, 0.08);
    min-height: 0;
    height: 100%;
}

.waveform {
    width: 100%;
    height: 42px;
    display: block;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
}

.voice-meta {
    margin-top: 8px;
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.82rem;
    color: var(--chat-text-muted);
}

.voice-progress {
    margin-top: 7px;
    height: 5px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    overflow: hidden;
}

.voice-progress-fill {
    height: 100%;
    width: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, #8de5ff, #a6ffcf);
    transition: width 0.2s linear, background 0.2s linear;
}

.voice-panel.is-warning .voice-progress-fill {
    background: linear-gradient(90deg, #ffd37d, #ffb64e);
}

.voice-panel.is-critical .voice-progress-fill {
    background: linear-gradient(90deg, #ff8d8d, #ff6565);
}

.send-controls {
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 3px;
    align-items: end;
    justify-items: center;
}

.icon-btn,
.send-btn {
    border: 1px solid var(--chat-border);
    background: rgba(255, 255, 255, 0.09);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.send-secondary {
    width: 42px;
    height: 38px;
    border-radius: 10px;
}

.send-primary {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(158, 227, 255, 0.42), rgba(134, 171, 255, 0.32));
}

.icon-btn:disabled,
.send-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.send-secondary svg {
    width: 28px;
    fill: currentColor;
}

.send-primary svg {
    width: 36px;
    fill: currentColor;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 4, 12, 0.6);
    display: grid;
    place-items: center;
    z-index: 80;
}

.modal {
    width: min(90vw, 760px);
    max-height: min(80vh, 640px);
    overflow: auto;
    background: var(--chat-surface-strong);
    border: 1px solid var(--chat-border);
    border-radius: 14px;
    padding: 14px;
}

.modal h3 {
    margin: 0 0 10px;
}

.log-area {
    max-height: 55vh;
    overflow: auto;
    padding: 10px;
    border: 1px solid var(--chat-border);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.22);
}

.log-area pre {
    margin: 0 0 8px;
    white-space: pre-wrap;
    word-break: break-word;
    color: #d6d6d6;
    font-size: 0.82rem;
}

.llm-log-record {
    margin: 0 0 8px;
    border: 1px solid rgba(158, 227, 255, 0.35);
    border-radius: 8px;
    overflow: hidden;
    background: rgba(158, 227, 255, 0.08);
}

.llm-log-record.is-from {
    border-color: rgba(194, 255, 173, 0.35);
    background: rgba(194, 255, 173, 0.08);
}

.llm-log-record summary {
    padding: 8px 10px;
    color: var(--chat-accent);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    user-select: none;
}

.llm-log-record.is-from summary {
    color: #c2ffad;
}

.llm-log-record pre {
    margin: 0;
    padding: 10px;
    border-top: 1px solid currentColor;
    background: rgba(0, 0, 0, 0.18);
}

.close-modal {
    margin-top: 10px;
    border: 1px solid var(--chat-border);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    border-radius: 10px;
    padding: 8px 12px;
    cursor: pointer;
}

@media (max-width: 900px) {
    .chat-shell {
        width: 100%;
        padding: 10px;
    }

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

@media (max-width: 640px) {
    .chat-topbar {
        grid-template-columns: auto 1fr auto;
        gap: 8px;
    }

    .brand span {
        font-size: 0.94rem;
    }

    .plan-chip {
        font-size: 0.78rem;
        padding: 6px 8px;
    }

    .chat-footer {
        grid-template-columns: 50px minmax(0, 1fr) 50px;
        gap: 8px;
        padding: 8px;
    }

    .composer-center {
        min-height: 90px;
    }

    .send-secondary {
        width: 34px;
        height: 30px;
    }

    .send-primary {
        width: 46px;
        height: 46px;
    }

    .response-mode-trigger {
        width: 46px;
        height: 46px;
    }
}
