/* ── Theme Variables (unified dark theme: Shiny Speech + AI Conversation) ── */
:root {
    --primary: #9A81EA;
    --primary-dark: #B8A4F0;
    --accent: #00D2FF;
    --bg: #0B0E17;
    --off-black: #0B0E17;
    --surface: #161B2E;
    --card: #161B2E;
    --surface-border: #2A3050;
    --separator: #2A3050;
    --text: #E8E0FF;
    --text-muted: #8888AA;
    --gray-400: #8888AA;
    --success: #91F5AD;
    --danger: #FF6B6B;
    --bubble-mine: #9A81EA;
    --bubble-other: #2A2854;
    --bubble-other-text: #E8E0FF;
    --radius: 12px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

/* ── App Shell ── */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 600px;
    margin: 0 auto;
    background: var(--bg);
}

.page-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* ── Bottom Tab Bar (global nav) ── */
.tab-bar {
    display: flex;
    background: var(--card);
    border-top: 1px solid var(--separator);
    padding: 4px 8px 0;
    box-shadow: 0 -1px 8px rgba(0, 0, 0, 0.3);
}

.tab-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 0 10px;
    text-decoration: none;
    color: var(--gray-400);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.3px;
    transition: color 0.25s ease, transform 0.15s ease;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

.tab-item:hover { color: var(--primary); }
.tab-item.active { color: var(--primary); font-weight: 600; }

.tab-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 25%;
    width: 50%;
    height: 3px;
    background: var(--primary);
    border-radius: 0 0 3px 3px;
}

.tab-icon { font-size: 22px; line-height: 1; transition: transform 0.15s ease; }
.tab-item.active .tab-icon { transform: scale(1.1); }
.tab-label { margin-top: 3px; }

/* ══════════════════ Speech Page ══════════════════ */
.speech-page { padding: 24px 16px; }

.app-header { text-align: center; margin-bottom: 32px; }
.app-header h1 {
    font-size: 28px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--success));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.app-header p { color: var(--text-muted); font-size: 14px; margin-top: 4px; }

.tabs {
    display: flex;
    gap: 4px;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 4px;
    margin-bottom: 24px;
}
.tab {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.tab.active { background: var(--primary); color: white; }
.tab:hover:not(.active) { color: var(--text); }

.card {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

.card-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.status-bar { display: flex; align-items: center; gap: 8px; }
.status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}
.status-dot.active { background: var(--success); animation: pulse 1.5s infinite; }
.status-dot.error { background: var(--danger); }
.status-text { font-size: 14px; font-weight: 500; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.mode-toggle {
    display: flex;
    gap: 4px;
    background: var(--bg);
    border-radius: 8px;
    padding: 3px;
}
.mode-btn {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.mode-btn.active { background: var(--primary); color: white; }

/* ── Shared Buttons ── */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    width: 100%;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 24px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    transition: all 0.15s;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-danger {
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 24px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    transition: all 0.15s;
}
.btn-danger:hover:not(:disabled) { opacity: 0.85; }
.btn-danger:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--surface-border);
    border-radius: 8px;
    padding: 12px 24px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
}
.btn-ghost:hover:not(:disabled) { border-color: var(--text-muted); color: var(--text); }

.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

.text-output {
    background: var(--bg);
    border: 1px solid var(--surface-border);
    border-radius: 8px;
    padding: 16px;
    min-height: 120px;
    font-size: 16px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.text-output.empty { color: var(--text-muted); font-style: italic; }

.confidence { font-size: 12px; color: var(--text-muted); margin-top: 8px; }

textarea, input[type="text"], select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--surface-border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
}
textarea:focus, input[type="text"]:focus, select:focus {
    outline: none;
    border-color: var(--primary);
}

.speech-page select { appearance: none; cursor: pointer; }

.field { margin-bottom: 12px; }
.field-label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }

.slider-row { display: flex; align-items: center; gap: 12px; }
.slider-row input[type="range"] { flex: 1; accent-color: var(--primary); }
.slider-value { font-size: 13px; color: var(--text-muted); min-width: 40px; text-align: right; }

.voice-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--surface-border);
    border-radius: 8px;
}
.voice-item {
    padding: 8px 12px;
    font-size: 13px;
    border-bottom: 1px solid var(--surface-border);
    cursor: pointer;
    transition: background 0.1s;
}
.voice-item:last-child { border-bottom: none; }
.voice-item:hover { background: rgba(154, 129, 234, 0.1); }
.voice-item.selected { background: rgba(154, 129, 234, 0.2); }
.voice-name { font-weight: 500; }
.voice-lang { color: var(--text-muted); font-size: 12px; margin-left: 8px; }

.divider { height: 1px; background: var(--surface-border); margin: 12px 0; }
.hidden { display: none; }

/* ══════════════════ AI Chat Page ══════════════════ */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 16px;
    line-height: 1.45;
    font-size: 15px;
}

.chat-bubble.mine {
    align-self: flex-end;
    background: var(--bubble-mine);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-bubble.theirs {
    align-self: flex-start;
    background: var(--bubble-other);
    color: var(--bubble-other-text);
    border-bottom-left-radius: 4px;
}

.bubble-time { font-size: 11px; opacity: 0.6; margin-top: 4px; }
.chat-bubble.mine .bubble-time { text-align: right; }

.typing-indicator { display: flex; gap: 4px; padding: 4px 0; }
.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--gray-400);
    animation: typing 1.4s ease-in-out infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

.chat-input-bar {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    background: var(--card);
    border-top: 1px solid var(--separator);
}

.chat-input-bar input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--separator);
    border-radius: 20px;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    outline: none;
}
.chat-input-bar input:focus { border-color: var(--primary); }
.chat-input-bar input::placeholder { color: var(--gray-400); }

.send-button {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.send-button:disabled { opacity: 0.4; cursor: default; }

/* ══════════════════ AI Settings Page ══════════════════ */
.settings-container {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.settings-section h3 {
    font-size: 13px;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    padding: 0 4px;
}

.settings-footer {
    font-size: 12px;
    color: var(--gray-400);
    margin-bottom: 8px;
    padding: 0 4px;
}

.settings-card {
    background: var(--card);
    border: 1px solid var(--separator);
    border-radius: 10px;
    overflow: hidden;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--separator);
}
.settings-row:last-child { border-bottom: none; }

.settings-label {
    font-size: 14px;
    font-weight: 500;
    flex-shrink: 0;
    margin-right: 12px;
}

.settings-value { font-size: 14px; color: var(--text-muted); text-align: right; }

.settings-card input,
.settings-card select {
    flex: 1;
    text-align: right;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 14px;
    outline: none;
    min-width: 0;
}

.settings-card select { cursor: pointer; appearance: auto; }

.settings-card .btn-danger {
    margin: 12px 16px;
    width: calc(100% - 32px);
}

/* ══════════════════ AI Aura Page ══════════════════ */
.aura-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--off-black);
    padding: 20px;
    min-height: 0;
}

.aura-orb-area {
    position: relative;
    width: 300px;
    height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.aura-outer-ring {
    position: absolute;
    width: 250px;
    height: 250px;
    border-radius: 50%;
    border: 3px solid var(--primary);
    background: radial-gradient(circle, transparent 60%, var(--primary) 100%);
    opacity: 0.3;
    transition: border-color 0.5s, opacity 0.5s;
}

.aura-inner-orb {
    position: absolute;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--primary), transparent);
    opacity: 0.5;
    transition: background 0.5s, opacity 0.5s;
}

.aura-ripple {
    position: absolute;
    width: 280px;
    height: 280px;
    border-radius: 50%;
    border: 2px solid var(--accent);
    opacity: 0;
    pointer-events: none;
}

.aura-outer-ring.idle { animation: idle-pulse 3s ease-in-out infinite; }
.aura-inner-orb.idle { animation: idle-orb 3s ease-in-out infinite; }

.aura-outer-ring.listening {
    border-color: #00D2FF;
    background: radial-gradient(circle, transparent 60%, #00D2FF 100%);
    opacity: 0.6;
    animation: listen-ring 1.5s ease-out infinite;
}
.aura-inner-orb.listening {
    background: radial-gradient(circle, #00D2FF, transparent);
    opacity: 0.7;
    animation: listen-orb 1.5s ease-out infinite;
}
.aura-ripple.listening {
    border-color: #00D2FF;
    animation: ripple 1.5s cubic-bezier(0, 0, 0.2, 1) infinite;
}

.aura-outer-ring.thinking {
    border-color: #A29BFE;
    background: radial-gradient(circle, transparent 60%, #A29BFE 100%);
    animation: think-spin 2s linear infinite;
}
.aura-inner-orb.thinking {
    background: radial-gradient(circle, #A29BFE, transparent);
    animation: think-orb 2s ease-in-out infinite;
}

.aura-outer-ring.responding {
    border-color: #00B894;
    background: radial-gradient(circle, transparent 60%, #00B894 100%);
    opacity: 0.7;
    animation: respond-ring 1s ease-in-out infinite;
}
.aura-inner-orb.responding {
    background: radial-gradient(circle, #00B894, transparent);
    opacity: 0.8;
    animation: respond-orb 1s ease-in-out infinite;
}

@keyframes idle-pulse {
    0%, 100% { transform: scale(0.9); opacity: 0.2; }
    50% { transform: scale(1.0); opacity: 0.35; }
}
@keyframes idle-orb {
    0%, 100% { transform: scale(0.85); opacity: 0.3; }
    50% { transform: scale(1.0); opacity: 0.5; }
}
@keyframes listen-ring {
    0%, 100% { transform: scale(0.95); opacity: 0.5; }
    50% { transform: scale(1.1); opacity: 0.8; }
}
@keyframes listen-orb {
    0%, 100% { transform: scale(0.9); opacity: 0.6; }
    50% { transform: scale(1.1); opacity: 0.9; }
}
@keyframes ripple {
    0% { transform: scale(0.6); opacity: 0.8; }
    100% { transform: scale(1.4); opacity: 0; }
}
@keyframes think-spin {
    0% { transform: rotate(0deg); opacity: 0.5; }
    50% { opacity: 0.8; }
    100% { transform: rotate(360deg); opacity: 0.5; }
}
@keyframes think-orb {
    0%, 100% { transform: scale(0.8); opacity: 0.5; }
    25% { transform: scale(0.95); opacity: 0.8; }
    75% { transform: scale(0.85); opacity: 0.6; }
}
@keyframes respond-ring {
    0%, 100% { transform: scale(1.0); opacity: 0.6; }
    50% { transform: scale(1.2); opacity: 1.0; }
}
@keyframes respond-orb {
    0%, 100% { transform: scale(0.9); opacity: 0.7; }
    50% { transform: scale(1.1); opacity: 1.0; }
}

.aura-status {
    font-size: 24px;
    font-weight: 700;
    margin-top: 32px;
    text-align: center;
}

.aura-response-panel {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 40px);
    max-width: 560px;
    background: rgba(26, 26, 46, 0.9);
    border-radius: 16px;
    padding: 16px 20px;
    color: rgba(255, 255, 255, 0.8);
}

.aura-response-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 700;
    color: #A29BFE;
}

.aura-dismiss {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
}

.aura-response-panel p { font-size: 15px; line-height: 1.5; }

/* ── Blazor error UI ── */
#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    padding: 12px;
    background: var(--danger);
    color: white;
    text-align: center;
    z-index: 1000;
}
