:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg-dark: #0f172a;
    --bg-card: rgba(30, 41, 59, 0.7);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #10b981;
    --error: #ef4444;
    --border: rgba(255, 255, 255, 0.1);
    --field-height: 46px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
    background: radial-gradient(circle at top right, #1e1b4b, #0f172a);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 2rem;
}

.main-layout {
    display: grid;
    gap: 1.5rem;
    width: 100%;
    max-width: 1080px;
    animation: fadeIn 0.8s ease-out;
}

.demo-nav {
    align-items: center;
    background: rgba(15, 23, 42, 0.52);
    border: 1px solid var(--border);
    border-radius: 16px;
    display: flex;
    gap: 0.5rem;
    padding: 0.4rem;
    width: max-content;
}

.demo-nav a {
    border-radius: 12px;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1;
    padding: 0.75rem 1rem;
    text-decoration: none;
    transition: all 0.2s;
}

.demo-nav a:hover,
.demo-nav a.active {
    background: rgba(99, 102, 241, 0.22);
    color: var(--text-main);
}

.call-card,
.settings-card {
    width: 100%;
}

.call-grid,
.settings-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1.25rem;
}

.call-panel {
    min-width: 0;
}

.call-panel .form-group:last-child,
.call-panel .grid .form-group {
    margin-bottom: 0;
}

.browser-header {
    align-items: flex-start;
    display: flex;
    gap: 1rem;
    justify-content: space-between;
}

.mic-state {
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-muted);
    flex: 0 0 auto;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    min-width: 86px;
    padding: 0.55rem 0.8rem;
    text-align: center;
    text-transform: uppercase;
}

.mic-state.live {
    background: rgba(16, 185, 129, 0.12);
    border-color: rgba(16, 185, 129, 0.34);
    color: var(--accent);
}

.mic-state.connecting {
    background: rgba(251, 191, 36, 0.1);
    border-color: rgba(251, 191, 36, 0.28);
    color: #fbbf24;
}

.mic-controls {
    display: grid;
    gap: 1rem;
    grid-template-columns: minmax(0, 1fr) 160px;
}

.conversation-panel {
    background: rgba(2, 6, 23, 0.62);
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1.5rem;
    max-height: 360px;
    min-height: 180px;
    overflow-y: auto;
    padding: 1rem;
}

.conversation-empty {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin: auto;
}

.conversation-message {
    max-width: min(760px, 88%);
}

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

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

.conversation-role {
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    margin-bottom: 0.3rem;
    text-transform: uppercase;
}

.conversation-text {
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-main);
    font-size: 0.92rem;
    line-height: 1.5;
    padding: 0.75rem 0.9rem;
    text-align: left;
    white-space: pre-wrap;
    word-break: break-word;
}

.conversation-message.user .conversation-text {
    background: rgba(99, 102, 241, 0.24);
    border-color: rgba(129, 140, 248, 0.32);
}

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

.card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 2.5rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

h1 {
    font-size: 1.875rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(to right, #818cf8, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

p.subtitle {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 2rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

input, select, textarea {
    width: 100%;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    color: var(--text-main);
    font-size: 1rem;
    transition: all 0.2s;
}

input, select {
    height: var(--field-height);
}

input[type="file"] {
    color: var(--text-muted);
    line-height: 1;
    padding: 0.45rem 1rem;
}

input[type="file"]::file-selector-button {
    background: rgba(99, 102, 241, 0.22);
    border: 1px solid rgba(129, 140, 248, 0.35);
    border-radius: 10px;
    color: var(--text-main);
    cursor: pointer;
    font-weight: 600;
    height: 28px;
    margin-right: 0.75rem;
    padding: 0 0.7rem;
}

textarea {
    min-height: 120px;
    resize: vertical;
    font-size: 0.9rem;
    line-height: 1.5;
}

#system_prompt {
    min-height: 180px;
}

#greeting_message {
    min-height: 72px;
}

select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='rgba(255, 255, 255, 0.7)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1.2rem;
    padding-right: 2.5rem; /* Make room for the arrow */
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.2);
    background: rgba(15, 23, 42, 0.8);
}

.grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.account-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.context-preview {
    background: rgba(15, 23, 42, 0.38);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.context-preview__meta {
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.75rem 1rem;
}

.context-preview pre {
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.5;
    margin: 0;
    max-height: 220px;
    overflow: auto;
    padding: 1rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.section-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-title::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
}

button {
    width: 100%;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 1rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-top: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(99, 102, 241, 0.4);
    filter: brightness(1.1);
}

button:active {
    transform: translateY(0);
}

button.secondary-button {
    background: rgba(15, 23, 42, 0.55);
    border: 1px solid rgba(129, 140, 248, 0.35);
}

button.secondary-button:hover {
    box-shadow: 0 10px 15px -3px rgba(15, 23, 42, 0.45);
}

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

.status {
    margin-top: 1.5rem;
    padding: 1rem;
    border-radius: 12px;
    font-size: 0.875rem;
    display: none;
    animation: slideUp 0.3s ease-out;
}

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

.status.success {
    display: block;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    color: var(--accent);
}

.status.error {
    display: block;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--error);
}

.loading-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
    display: none;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading .loading-spinner {
    display: block;
}

.loading .btn-text {
    display: none;
}

@media (max-width: 760px) {
    body {
        padding: 1rem;
    }

    .demo-nav {
        width: 100%;
    }

    .demo-nav a {
        flex: 1;
        text-align: center;
    }

    .card {
        padding: 1.5rem;
    }

    .call-grid,
    .settings-grid,
    .grid {
        grid-template-columns: 1fr;
    }

    .call-panel + .call-panel {
        border-top: 1px solid var(--border);
        padding-top: 1.25rem;
    }

    .browser-header {
        align-items: stretch;
        flex-direction: column;
    }

    .mic-controls {
        grid-template-columns: 1fr;
    }

    .conversation-message {
        max-width: 100%;
    }
}

/* Real-time Logs */
.logs-card {
    padding: 1.5rem 2rem;
}

.logs-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.logs-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.icon-button {
    width: auto;
    background: transparent;
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    margin-top: 0;
    font-size: 1.1rem;
    opacity: 0.7;
}

.icon-button:hover {
    opacity: 1;
    transform: scale(1.1);
    box-shadow: none;
}

.ws-status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #4b5563;
    transition: all 0.3s;
}

.ws-status.connected {
    background: var(--accent);
    box-shadow: 0 0 10px var(--accent);
}

.ws-status.error {
    background: var(--error);
    box-shadow: 0 0 10px var(--error);
}

.log-viewer {
    background: #020617;
    border-radius: 12px;
    padding: 1rem;
    font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
    font-size: 0.8rem;
    height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    border: 1px solid var(--border);
}

.log-entry {
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-all;
    border-left: 3px solid transparent;
    padding-left: 0.75rem;
}

.log-entry.INFO { color: #f8fafc; border-color: #3b82f6; }
.log-entry.WARNING { color: #fbbf24; border-color: #fbbf24; }
.log-entry.ERROR { color: #f87171; border-color: #ef4444; }
.log-entry.DEBUG { color: #94a3b8; border-color: #64748b; }
.log-entry.system { color: #6366f1; border-color: transparent; font-style: italic; opacity: 0.8; }

/* ─── Cost Dashboard ─────────────────────────────────────────────── */

.cost-card {
    padding: 2rem 2.5rem;
}

.cost-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}

.cost-summary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.cost-stat-card {
    background: rgba(15, 23, 42, 0.55);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.25rem 1rem;
    text-align: center;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}

.cost-stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px -6px rgba(0, 0, 0, 0.4);
}

.cost-stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: 16px 16px 0 0;
}

.cost-stat-card.total::before {
    background: linear-gradient(to right, #6366f1, #8b5cf6);
}

.cost-stat-card.stt::before {
    background: linear-gradient(to right, #06b6d4, #22d3ee);
}

.cost-stat-card.llm::before {
    background: linear-gradient(to right, #a78bfa, #c084fc);
}

.cost-stat-card.tts::before {
    background: linear-gradient(to right, #f59e0b, #fbbf24);
}

.cost-stat-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.cost-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    font-variant-numeric: tabular-nums;
}

.cost-stat-card.total .cost-stat-value {
    background: linear-gradient(to right, #818cf8, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.cost-stat-card.stt .cost-stat-value { color: #22d3ee; }
.cost-stat-card.llm .cost-stat-value { color: #c084fc; }
.cost-stat-card.tts .cost-stat-value { color: #fbbf24; }

.cost-stat-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.cost-table-header {
    margin-bottom: 0.75rem;
}

.cost-table-wrapper {
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

.cost-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.825rem;
    font-variant-numeric: tabular-nums;
}

.cost-table thead th {
    background: rgba(15, 23, 42, 0.7);
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.cost-table tbody td {
    padding: 0.65rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    color: var(--text-main);
}

.cost-table tbody tr:last-child td {
    border-bottom: none;
}

.cost-table tbody tr {
    transition: background 0.15s;
}

.cost-table tbody tr:hover {
    background: rgba(99, 102, 241, 0.06);
}

.cost-table .call-id {
    font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cost-table .cost-value {
    font-weight: 600;
}

.cost-table .cost-value.stt { color: #22d3ee; }
.cost-table .cost-value.llm { color: #c084fc; }
.cost-table .cost-value.tts { color: #fbbf24; }
.cost-table .cost-value.total-cell {
    background: linear-gradient(to right, #818cf8, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 700;
}

.cost-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem 1rem !important;
    font-style: italic;
}

.cost-table .active-badge {
    display: inline-block;
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent);
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    margin-left: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

@media (max-width: 760px) {
    .cost-summary {
        grid-template-columns: repeat(2, 1fr);
    }

    .cost-table-wrapper {
        overflow-x: auto;
    }

    .cost-table {
        min-width: 540px;
    }
}
