:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-card: #1c2129;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent-blue: #58a6ff;
    --accent-green: #3fb950;
    --accent-red: #f85149;
    --accent-yellow: #d29922;
    --accent-purple: #bc8cff;
    --accent-orange: #f0883e;
    --border: #30363d;
    --radius: 10px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

/* --- Header --- */

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 28px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.header-left {
    display: flex;
    align-items: baseline;
    gap: 14px;
}

h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--accent-blue);
}

.subtitle {
    font-size: 13px;
    color: var(--text-secondary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.model-badge {
    font-size: 11px;
    color: var(--text-secondary);
    background: var(--bg-primary);
    padding: 5px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-weight: 600;
    letter-spacing: 0.3px;
}

.status-badge {
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-badge.connected {
    background: rgba(63, 185, 80, 0.15);
    color: var(--accent-green);
}

.status-badge.disconnected {
    background: rgba(248, 81, 73, 0.15);
    color: var(--accent-red);
}

.status-badge.connecting {
    background: rgba(210, 153, 34, 0.15);
    color: var(--accent-yellow);
}

/* --- Main Layout --- */

main {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 0;
    min-height: calc(100vh - 60px);
}

.content-area {
    padding: 32px 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* --- Mic Section --- */

.mic-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 0 24px;
    width: 100%;
    max-width: 700px;
}

.mic-btn {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: var(--bg-secondary);
    border: 3px solid var(--border);
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    outline: none;
}

.mic-btn:hover {
    border-color: var(--accent-blue);
    color: var(--text-primary);
    background: rgba(88, 166, 255, 0.08);
}

.mic-btn.listening {
    border-color: var(--accent-green);
    color: var(--accent-green);
    background: rgba(63, 185, 80, 0.08);
    animation: mic-pulse 1.5s infinite;
}

.mic-btn.processing {
    border-color: var(--accent-yellow);
    color: var(--accent-yellow);
    background: rgba(210, 153, 34, 0.08);
    animation: mic-spin 1.2s linear infinite;
}

@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(63, 185, 80, 0.4); }
    50% { box-shadow: 0 0 0 20px rgba(63, 185, 80, 0); }
}

@keyframes mic-spin {
    0% { box-shadow: 0 0 0 4px rgba(210, 153, 34, 0.3); }
    50% { box-shadow: 0 0 0 12px rgba(210, 153, 34, 0); }
    100% { box-shadow: 0 0 0 4px rgba(210, 153, 34, 0.3); }
}

.audio-level-bar {
    width: 200px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 16px;
}

.audio-level-bar > div {
    height: 100%;
    background: var(--accent-green);
    border-radius: 2px;
    transition: width 0.08s ease-out;
    width: 0%;
}

/* Processing Pipeline */
.processing-pipeline {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    justify-content: center;
    flex-wrap: wrap;
}
.pipeline-step {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
    transition: all 0.3s;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-secondary);
}
.pipeline-step.active {
    border-color: var(--accent-yellow);
    color: var(--accent-yellow);
    background: rgba(210, 153, 34, 0.1);
    animation: stepPulse 0.8s ease infinite;
}
.pipeline-step.done {
    border-color: var(--accent-green);
    color: var(--accent-green);
    background: rgba(63, 185, 80, 0.08);
    animation: none;
}
.pipeline-step.done .pipeline-icon {
    color: var(--accent-green);
}
.pipeline-step.pending {
    opacity: 0.4;
}
.pipeline-icon { font-size: 14px; }
.pipeline-label { font-weight: 600; }
.pipeline-detail {
    font-size: 10px;
    color: var(--text-secondary);
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
@keyframes stepPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(210, 153, 34, 0.3); }
    50% { box-shadow: 0 0 0 6px rgba(210, 153, 34, 0); }
}

/* Thinking dots animation */
.thinking-dots::after {
    content: '';
    animation: dots 1.2s steps(4, end) infinite;
}
@keyframes dots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}

.mic-status {
    margin-top: 12px;
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
    min-height: 22px;
}

.interim-transcript {
    margin-top: 16px;
    font-size: 16px;
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    max-width: 600px;
    min-height: 24px;
    line-height: 1.5;
}

.final-transcript {
    margin-top: 8px;
    font-size: 18px;
    color: var(--text-primary);
    font-weight: 500;
    text-align: center;
    max-width: 600px;
    min-height: 0;
    line-height: 1.5;
}

/* --- Results Section --- */

.results-section {
    width: 100%;
    max-width: 900px;
    margin-top: 24px;
    animation: fadeInUp 0.4s ease-out;
}

.results-section.hidden {
    display: none;
}

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

.results-summary {
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
    padding: 16px 20px;
    background: rgba(88, 166, 255, 0.07);
    border-radius: var(--radius);
    border-left: 3px solid var(--accent-blue);
    margin-bottom: 16px;
}

.results-params {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.param-tag {
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 14px;
    font-weight: 600;
    border: 1px solid;
}

.param-tag.origin {
    background: rgba(63, 185, 80, 0.12);
    color: var(--accent-green);
    border-color: rgba(63, 185, 80, 0.25);
}

.param-tag.destination {
    background: rgba(188, 140, 255, 0.12);
    color: var(--accent-purple);
    border-color: rgba(188, 140, 255, 0.25);
}

.param-tag.date {
    background: rgba(210, 153, 34, 0.12);
    color: var(--accent-yellow);
    border-color: rgba(210, 153, 34, 0.25);
}

.param-tag.equipment {
    background: rgba(88, 166, 255, 0.12);
    color: var(--accent-blue);
    border-color: rgba(88, 166, 255, 0.25);
}

.param-tag.weight {
    background: rgba(240, 136, 62, 0.12);
    color: var(--accent-orange);
    border-color: rgba(240, 136, 62, 0.25);
}

.param-tag.rate {
    background: rgba(63, 185, 80, 0.12);
    color: var(--accent-green);
    border-color: rgba(63, 185, 80, 0.25);
}

.param-tag.refrigerated {
    background: rgba(88, 166, 255, 0.12);
    color: #79c0ff;
    border-color: rgba(88, 166, 255, 0.25);
}

.param-tag.generic {
    background: rgba(139, 148, 158, 0.12);
    color: var(--text-secondary);
    border-color: rgba(139, 148, 158, 0.25);
}

/* --- Results Table --- */

.results-table-wrap {
    overflow-x: auto;
    margin-bottom: 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.results-table th {
    text-align: left;
    padding: 10px 14px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 10px;
    border-bottom: 2px solid var(--border);
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    transition: color 0.2s;
}

.results-table th:hover {
    color: var(--accent-blue);
}

.results-table th.sorted-asc::after {
    content: ' \25B2';
    font-size: 9px;
}

.results-table th.sorted-desc::after {
    content: ' \25BC';
    font-size: 9px;
}

.results-table td {
    padding: 9px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    white-space: nowrap;
}

.results-table tbody tr:nth-child(even) td {
    background: rgba(22, 27, 34, 0.5);
}

.results-table tbody tr:hover td {
    background: rgba(88, 166, 255, 0.06);
}

.results-table .col-numeric {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    text-align: right;
    font-size: 12px;
}

.results-table .rate-good {
    color: var(--accent-green);
}

.results-table .rate-mid {
    color: var(--accent-yellow);
}

.results-table .rate-high {
    color: var(--accent-orange);
}

/* --- SQL Display --- */

.sql-details {
    margin-top: 8px;
    margin-bottom: 12px;
}

.sql-details summary {
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: 600;
    padding: 6px 0;
    user-select: none;
    outline: none;
}

.sql-details summary:hover {
    color: var(--text-primary);
}

.sql-display {
    display: block;
    margin-top: 8px;
    padding: 14px 18px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 12px;
    color: var(--accent-blue);
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-all;
    overflow-x: auto;
}

.results-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text-secondary);
    padding-top: 8px;
}

.row-count-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    background: rgba(88, 166, 255, 0.12);
    color: var(--accent-blue);
}

/* --- Text Input Section --- */

.text-input-section {
    width: 100%;
    max-width: 700px;
    margin-top: 24px;
}

.text-input-row {
    display: flex;
    gap: 8px;
}

.text-input {
    flex: 1;
    padding: 12px 18px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.text-input:focus {
    border-color: var(--accent-blue);
}

.text-input::placeholder {
    color: var(--text-muted);
}

.submit-btn {
    padding: 12px 24px;
    border-radius: var(--radius);
    border: none;
    background: var(--accent-blue);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.submit-btn:hover:not(:disabled) {
    background: #4a96ed;
}

.submit-btn:disabled {
    opacity: 0.5;
    cursor: wait;
}

/* --- Suggestions Section --- */

.suggestions-section {
    width: 100%;
    max-width: 900px;
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.suggestions-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
    display: block;
}

.suggestions-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.suggestion-pill {
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.suggestion-pill:hover {
    border-color: var(--accent-blue);
    color: var(--text-primary);
    background: rgba(88, 166, 255, 0.06);
}

/* --- History Sidebar --- */

.history-sidebar {
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    padding: 20px;
    overflow-y: auto;
    max-height: calc(100vh - 60px);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.sidebar-header h2 {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.clear-btn {
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.clear-btn:hover {
    border-color: var(--accent-red);
    color: var(--accent-red);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    padding: 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.history-item:hover,
.history-item.active {
    border-color: var(--accent-blue);
}

.history-item .history-text {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
    line-height: 1.4;
    margin-bottom: 6px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.history-item .history-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: var(--text-muted);
}

.history-item .history-count {
    font-weight: 700;
    color: var(--accent-blue);
}

.empty-state {
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
    padding: 32px 12px;
    line-height: 1.6;
}

/* --- Unsupported banner --- */

.unsupported-banner {
    background: rgba(210, 153, 34, 0.12);
    border: 1px solid rgba(210, 153, 34, 0.3);
    color: var(--accent-yellow);
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 13px;
    text-align: center;
    margin-bottom: 16px;
}

/* --- Error display --- */

.error-msg {
    color: var(--accent-red);
    font-size: 14px;
    padding: 12px 16px;
    background: rgba(248, 81, 73, 0.08);
    border-radius: 8px;
    border-left: 3px solid var(--accent-red);
}

/* --- Processing state --- */

.processing-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    color: var(--accent-yellow);
    font-size: 14px;
    font-weight: 500;
}

.processing-dots::after {
    content: '';
    animation: dots 1.4s steps(4, end) infinite;
}

@keyframes dots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}

/* --- Responsive --- */

@media (max-width: 900px) {
    main {
        grid-template-columns: 1fr;
    }

    .history-sidebar {
        border-left: none;
        border-top: 1px solid var(--border);
        max-height: 300px;
    }

    .content-area {
        padding: 20px 16px;
    }

    .mic-section {
        padding: 24px 0 16px;
    }

    .mic-btn {
        width: 96px;
        height: 96px;
    }

    .mic-btn svg {
        width: 40px;
        height: 40px;
    }

    .suggestions-pills {
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 8px;
    }

    .results-section {
        max-width: 100%;
    }
}

/* --- Scrollbar Styling --- */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
