/* Cabin Chat — Tesla-friendly voice UI */

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

:root {
    --ink: #040b12;
    --ink-soft: #102433;
    --mist: #f3fbff;
    --fog: rgba(243, 251, 255, 0.78);
    --glass: rgba(6, 20, 30, 0.62);
    --glass-strong: rgba(4, 14, 22, 0.88);
    --line: rgba(243, 251, 255, 0.16);
    --line-strong: rgba(243, 251, 255, 0.32);
    --teal: #3cffd0;
    --teal-deep: #0b8f7f;
    --amber: #ffc14a;
    --danger: #ff6b6b;
    --ok: #34d399;
    --warn: #fbbf24;
    --text: #f4fbff;
    --text-dim: #9eb8c6;
    --radius: 22px;
    --radius-sm: 14px;
    --dock-h: clamp(160px, 24vh, 220px);
    --top-h: 96px;
    --touch: 68px;
    --font-display: "Syne", "Avenir Next", "Segoe UI", sans-serif;
    --font-body: "Figtree", "Avenir Next", "Segoe UI", sans-serif;
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

html,
body {
    height: 100%;
}

body {
    font-family: var(--font-body);
    color: var(--text);
    background: var(--ink);
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

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

button {
    border: 0;
    cursor: pointer;
    background: none;
}

/* Atmosphere */
.atmosphere {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background:
        radial-gradient(90% 70% at 50% -5%, rgba(60, 255, 208, 0.28), transparent 52%),
        radial-gradient(55% 45% at 90% 12%, rgba(255, 193, 74, 0.18), transparent 48%),
        radial-gradient(40% 35% at 8% 70%, rgba(56, 189, 248, 0.12), transparent 55%),
        linear-gradient(180deg, #123246 0%, #0a1a26 38%, #040b12 72%, #02060a 100%);
}

.sky-wash {
    position: absolute;
    inset: 0 0 40% 0;
    background: linear-gradient(180deg, rgba(90, 220, 255, 0.12), transparent 70%);
    animation: skyShift 14s ease-in-out infinite alternate;
}

.horizon {
    position: absolute;
    left: -10%;
    right: -10%;
    bottom: 30%;
    height: 3px;
    background: linear-gradient(90deg, transparent, rgba(60, 255, 208, 0.85), rgba(255, 193, 74, 0.55), transparent);
    filter: blur(0.4px);
    animation: horizonPulse 5.5s ease-in-out infinite;
}

.lane-lines {
    position: absolute;
    left: 50%;
    bottom: 0;
    width: min(420px, 40vw);
    height: 34%;
    transform: translateX(-50%) perspective(420px) rotateX(58deg);
    background:
        linear-gradient(180deg, transparent 0%, rgba(243, 251, 255, 0.08) 18%, transparent 19%),
        repeating-linear-gradient(
            180deg,
            rgba(243, 251, 255, 0.55) 0 18px,
            transparent 18px 46px
        );
    mask-image: linear-gradient(180deg, transparent, #000 35%, #000 80%, transparent);
    opacity: 0.35;
    animation: lanesRush 1.8s linear infinite;
}

.road-glow {
    position: absolute;
    left: 50%;
    bottom: -22%;
    width: 130%;
    height: 58%;
    transform: translateX(-50%);
    background: radial-gradient(ellipse at center, rgba(60, 255, 208, 0.22), transparent 62%);
    animation: roadDrift 10s ease-in-out infinite alternate;
}

.grain {
    position: absolute;
    inset: 0;
    opacity: 0.11;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    mix-blend-mode: soft-light;
}

@keyframes horizonPulse {
    0%, 100% { opacity: 0.5; transform: scaleX(0.94); }
    50% { opacity: 1; transform: scaleX(1); }
}

@keyframes roadDrift {
    from { transform: translateX(-52%) scale(1); }
    to { transform: translateX(-48%) scale(1.06); }
}

@keyframes skyShift {
    from { opacity: 0.7; transform: translateY(0); }
    to { opacity: 1; transform: translateY(-12px); }
}

@keyframes lanesRush {
    from { background-position: 0 0, 0 0; }
    to { background-position: 0 0, 0 64px; }
}

.app-container {
    position: relative;
    z-index: 1;
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-rows: var(--top-h) minmax(0, 1fr) auto;
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 clamp(16px, 2.5vw, 32px);
}

/* Top bar */
.top-bar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 1rem;
    min-height: var(--top-h);
    padding: 0.75rem 0;
}

.brand-block {
    justify-self: start;
}

.brand-mark {
    font-family: var(--font-display);
    font-size: clamp(1.85rem, 3vw, 2.45rem);
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1;
    background: linear-gradient(115deg, #ffffff 8%, var(--teal) 42%, #7dd3fc 68%, var(--amber) 100%);
    background-size: 180% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: brandSheen 7s ease-in-out infinite;
}

@keyframes brandSheen {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.brand-tag {
    margin-top: 0.25rem;
    color: var(--text-dim);
    font-size: 0.95rem;
    letter-spacing: 0.02em;
}

.status-indicator {
    justify-self: center;
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    min-height: 44px;
    padding: 0.55rem 1.1rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--glass);
    backdrop-filter: blur(14px);
    color: var(--text-dim);
    font-weight: 600;
    font-size: 0.95rem;
}

.status-indicator i {
    font-size: 0.55rem;
    color: var(--text-dim);
}

.status-indicator.connected {
    border-color: rgba(52, 211, 153, 0.35);
    color: var(--mist);
}

.status-indicator.connected i,
.status-indicator .connected {
    color: var(--ok);
}

.status-indicator.warning {
    border-color: rgba(251, 191, 36, 0.4);
}

.status-indicator.warning i,
.status-indicator .warning {
    color: var(--warn);
}

.top-actions {
    justify-self: end;
    display: flex;
    gap: 0.65rem;
}

.ghost-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    min-height: var(--touch);
    min-width: var(--touch);
    padding: 0 1.15rem;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.04);
    color: var(--mist);
    font-weight: 600;
    transition: transform 0.2s var(--ease), background 0.2s var(--ease), border-color 0.2s var(--ease);
}

.ghost-btn:hover,
.ghost-btn:focus-visible {
    background: rgba(45, 212, 191, 0.12);
    border-color: rgba(45, 212, 191, 0.4);
    outline: none;
}

.ghost-btn:active {
    transform: scale(0.97);
}

/* Settings */
.settings-panel {
    position: absolute;
    top: calc(var(--top-h) - 4px);
    left: clamp(16px, 2.5vw, 32px);
    right: clamp(16px, 2.5vw, 32px);
    z-index: 20;
    max-height: calc(100vh - var(--top-h) - 24px);
    overflow: auto;
    border: 1px solid var(--line-strong);
    border-radius: calc(var(--radius) + 4px);
    background: var(--glass-strong);
    backdrop-filter: blur(22px);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
    animation: panelIn 0.35s var(--ease);
}

@keyframes panelIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.settings-content {
    padding: clamp(1.25rem, 2.5vw, 2rem);
    display: grid;
    gap: 1.5rem;
}

.settings-intro h2 {
    font-family: var(--font-display);
    font-size: 1.6rem;
    letter-spacing: -0.02em;
}

.settings-intro p {
    margin-top: 0.35rem;
    color: var(--text-dim);
    max-width: 42rem;
}

.config-grid,
.settings-options {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 1rem;
}

.field {
    grid-column: span 4;
}

.api-key-input {
    grid-column: span 5;
}

.save-btn {
    grid-column: span 3;
    align-self: end;
}

.option-group {
    grid-column: span 6;
}

label {
    display: block;
    margin-bottom: 0.45rem;
    font-weight: 600;
    color: var(--mist);
}

.option-description {
    margin-top: 0.45rem;
    color: var(--text-dim);
    font-size: 0.9rem;
    line-height: 1.4;
}

select,
input[type="password"],
input[type="text"],
textarea {
    width: 100%;
    min-height: var(--touch);
    padding: 0.9rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}

select:focus,
input:focus,
textarea:focus {
    outline: none;
    border-color: rgba(45, 212, 191, 0.65);
    background: rgba(45, 212, 191, 0.08);
}

.input-with-icon {
    position: relative;
}

.input-with-icon input {
    padding-right: 3.5rem;
}

.toggle-btn {
    position: absolute;
    right: 0.45rem;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    border-radius: 12px;
    color: var(--text-dim);
}

.toggle-btn:hover {
    color: var(--teal);
    background: rgba(45, 212, 191, 0.1);
}

.preferred-provider {
    margin-top: 0.7rem;
}

.preferred-provider label {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin: 0;
    font-weight: 500;
    color: var(--text-dim);
}

.preferred-provider input {
    width: 1.15rem;
    height: 1.15rem;
    min-height: 0;
    accent-color: var(--teal);
}

.save-btn {
    min-height: var(--touch);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    padding: 0 1.25rem;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--teal) 0%, var(--teal-deep) 100%);
    color: #04201c;
    font-weight: 700;
    transition: transform 0.2s var(--ease), filter 0.2s var(--ease);
}

.save-btn:hover {
    filter: brightness(1.06);
}

.save-btn:active {
    transform: scale(0.98);
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    min-height: var(--touch);
    margin: 0;
    cursor: pointer;
}

.toggle-checkbox {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.toggle-slider {
    width: 56px;
    height: 32px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid var(--line);
    position: relative;
    flex-shrink: 0;
    transition: background 0.2s var(--ease);
}

.toggle-slider::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--mist);
    transition: transform 0.2s var(--ease);
}

.toggle-checkbox:checked + .toggle-slider {
    background: rgba(45, 212, 191, 0.35);
    border-color: rgba(45, 212, 191, 0.55);
}

.toggle-checkbox:checked + .toggle-slider::after {
    transform: translateX(24px);
    background: var(--teal);
}

.toggle-text {
    font-weight: 600;
}

/* Main stage */
.main-stage {
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 140px;
    gap: 1rem;
    padding-bottom: 0.5rem;
}

.chat-section,
.chat-container,
.chat-messages {
    min-height: 0;
    height: 100%;
}

.chat-container {
    border: 1px solid var(--line-strong);
    border-radius: calc(var(--radius) + 8px);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02)),
        linear-gradient(135deg, rgba(60, 255, 208, 0.08), transparent 40%);
    backdrop-filter: blur(16px);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.08),
        0 24px 60px rgba(0, 0, 0, 0.35);
    overflow: hidden;
}

.chat-messages {
    overflow-y: auto;
    padding: clamp(1rem, 2vw, 1.75rem);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scroll-behavior: smooth;
}

.welcome-message {
    margin: auto;
    max-width: 34rem;
    text-align: center;
    padding: 2rem 1rem 3rem;
    animation: welcomeIn 0.7s var(--ease);
}

@keyframes welcomeIn {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

.welcome-kicker {
    display: inline-block;
    margin-bottom: 0.75rem;
    color: var(--teal);
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-size: 0.8rem;
}

.welcome-message h2 {
    font-family: var(--font-display);
    font-size: clamp(2rem, 4vw, 3rem);
    line-height: 1.05;
    letter-spacing: -0.03em;
    margin-bottom: 0.85rem;
}

.welcome-message p:last-child {
    color: var(--text-dim);
    font-size: 1.05rem;
    line-height: 1.5;
}

.message {
    max-width: min(720px, 92%);
    animation: msgIn 0.35s var(--ease);
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

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

.message.assistant,
.message.error {
    align-self: flex-start;
}

.message-content {
    padding: 1rem 1.15rem;
    border-radius: 20px;
    border: 1px solid var(--line);
    background: rgba(8, 22, 32, 0.55);
}

.message.user .message-content {
    background: linear-gradient(145deg, rgba(45, 212, 191, 0.22), rgba(15, 118, 110, 0.28));
    border-color: rgba(45, 212, 191, 0.35);
}

.message.error .message-content {
    background: rgba(255, 107, 107, 0.12);
    border-color: rgba(255, 107, 107, 0.35);
}

.message-header {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin-bottom: 0.45rem;
    color: var(--text-dim);
    font-size: 0.85rem;
    font-weight: 600;
}

.provider-name {
    color: var(--teal);
    letter-spacing: 0.04em;
}

.message-content p {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.55;
    font-size: 1.05rem;
}

.tts-btn {
    margin-left: auto;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    color: var(--text-dim);
    transition: background 0.2s var(--ease), color 0.2s var(--ease);
}

.tts-btn:hover,
.tts-btn.speaking {
    color: var(--teal);
    background: rgba(45, 212, 191, 0.12);
}

/* Metrics */
.metrics-rail {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
}

.metric-item {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.85rem 0.9rem;
    border-left: 2px solid rgba(45, 212, 191, 0.35);
}

.metric-label {
    color: var(--text-dim);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
}

.metric-value {
    font-family: var(--font-display);
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* Voice dock */
.voice-dock {
    padding: 0.75rem 0 1.1rem;
    min-height: var(--dock-h);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 0.75rem;
}

.voice-status {
    text-align: center;
}

.listening-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 44px;
    padding: 0.55rem 1.2rem;
    border-radius: 999px;
    background: rgba(45, 212, 191, 0.12);
    border: 1px solid rgba(45, 212, 191, 0.35);
    color: var(--teal);
    font-weight: 700;
}

.pulse {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--teal);
    box-shadow: 0 0 0 0 rgba(45, 212, 191, 0.55);
    animation: pulse 1.4s ease-out infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(45, 212, 191, 0.55); }
    70% { box-shadow: 0 0 0 14px rgba(45, 212, 191, 0); }
    100% { box-shadow: 0 0 0 0 rgba(45, 212, 191, 0); }
}

.input-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 168px 128px;
    gap: 0.95rem;
    align-items: stretch;
}

.text-input-container {
    min-width: 0;
}

#messageInput {
    min-height: 112px;
    max-height: 180px;
    resize: none;
    border-radius: 28px;
    padding: 1.25rem 1.35rem;
    font-size: 1.2rem;
    line-height: 1.4;
    border-color: rgba(60, 255, 208, 0.28);
    background: rgba(4, 14, 22, 0.72);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03), 0 12px 40px rgba(0, 0, 0, 0.25);
}

.voice-btn {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 112px;
    border-radius: 32px;
    background: radial-gradient(circle at 35% 28%, #9ffff0, #3cffd0 28%, #0b8f7f 68%, #064e47 100%);
    color: #031815;
    font-weight: 800;
    overflow: hidden;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.2),
        0 18px 40px rgba(11, 143, 127, 0.45),
        0 0 50px rgba(60, 255, 208, 0.25);
    transition: transform 0.2s var(--ease), filter 0.2s var(--ease);
}

.voice-btn .voice-orb {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.28), transparent 55%);
    opacity: 0.7;
    animation: orbBreath 3.2s ease-in-out infinite;
}

.voice-btn i,
.voice-btn .voice-label {
    position: relative;
    z-index: 1;
}

.voice-btn i {
    font-size: 2.1rem;
}

.voice-btn .voice-label {
    font-size: 0.95rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.voice-btn:hover {
    filter: brightness(1.08);
}

.voice-btn:active {
    transform: scale(0.97);
}

.voice-btn.listening {
    background: radial-gradient(circle at 35% 30%, #fde68a, #f0b429 55%, #b45309 100%);
    animation: listenPulse 1.2s ease-in-out infinite;
}

.voice-btn.conversation-mode {
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35);
}

.voice-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    filter: grayscale(0.4);
}

@keyframes orbBreath {
    0%, 100% { transform: scale(1); opacity: 0.55; }
    50% { transform: scale(1.08); opacity: 0.85; }
}

@keyframes listenPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.03); }
}

.send-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-height: 112px;
    border-radius: 32px;
    border: 1px solid rgba(255, 193, 74, 0.35);
    background: linear-gradient(160deg, rgba(255, 193, 74, 0.22), rgba(255, 255, 255, 0.05));
    color: var(--mist);
    font-weight: 700;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
    transition: background 0.2s var(--ease), border-color 0.2s var(--ease), transform 0.2s var(--ease);
}

.send-btn i {
    font-size: 1.35rem;
}

.send-btn:not(:disabled):hover {
    background: rgba(45, 212, 191, 0.16);
    border-color: rgba(45, 212, 191, 0.45);
}

.send-btn:not(:disabled):active {
    transform: scale(0.97);
}

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar,
.settings-panel::-webkit-scrollbar {
    width: 10px;
}

.chat-messages::-webkit-scrollbar-thumb,
.settings-panel::-webkit-scrollbar-thumb {
    background: rgba(157, 180, 191, 0.35);
    border-radius: 999px;
}

/* Responsive — portrait / smaller panes */
@media (max-width: 980px) {
    .main-stage {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 1fr) auto;
    }

    .metrics-rail {
        flex-direction: row;
        justify-content: space-between;
        gap: 0.5rem;
        overflow-x: auto;
    }

    .metric-item {
        min-width: 92px;
        border-left: 0;
        border-top: 2px solid rgba(45, 212, 191, 0.35);
        padding: 0.65rem 0.4rem;
    }

    .field,
    .api-key-input,
    .save-btn,
    .option-group {
        grid-column: span 12;
    }

    .top-bar {
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto;
    }

    .status-indicator {
        grid-column: 1 / -1;
        justify-self: start;
        order: 3;
    }
}

@media (max-width: 720px) {
    .brand-tag,
    .ghost-btn span:last-child,
    .send-btn span {
        display: none;
    }

    .input-controls {
        grid-template-columns: minmax(0, 1fr) 104px 84px;
    }

    .voice-btn,
    .send-btn,
    #messageInput {
        min-height: 96px;
    }

    .voice-btn {
        border-radius: 22px;
    }
}

/* Prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}
