/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #151520;
    --bg-tertiary: #1e1e2e;
    --accent-cyan: #00d4ff;
    --accent-purple: #a855f7;
    --accent-green: #10b981;
    --text-primary: #ffffff;
    --text-secondary: #a0a0b0;
    --text-muted: #6b6b7a;
    --border-color: #2a2a3a;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

/* Header Styles */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}

.title {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: fadeIn 0.5s ease-in;
}

.pulse-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent-cyan);
    animation: pulse 2s infinite;
    box-shadow: 0 0 10px var(--accent-cyan);
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.2); }
}

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

.connection-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-tertiary);
    border-radius: 20px;
    border: 1px solid var(--border-color);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.status-dot.connected {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
    animation: pulse 2s infinite;
}

.status-dot.disconnected {
    background: var(--error);
    box-shadow: 0 0 8px var(--error);
}

.status-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Main Content */
.main-content {
    display: grid;
    grid-template-columns: 1fr 350px;
    gap: 2rem;
    margin-bottom: 2rem;
}

/* Visualizer Section */
.visualizer-section {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    position: relative;
}

.visualizer-section.recording {
    border-color: var(--accent-purple);
    box-shadow: 0 4px 30px rgba(168, 85, 247, 0.3);
}

.visualizer-container {
    margin-bottom: 1.5rem;
}

.waveform {
    width: 100%;
    height: 150px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    margin-bottom: 1rem;
    padding: 1rem;
}

.spectrogram-container {
    width: 100%;
    height: 200px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 1rem;
}

.spectrogram {
    width: 100%;
    height: 100%;
}

.audio-meter {
    margin-top: 1rem;
}

.meter-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.meter-bar-container {
    position: relative;
    width: 100%;
    height: 30px;
    background: var(--bg-tertiary);
    border-radius: 15px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.meter-bar {
    width: 100%;
    height: 100%;
    position: relative;
}

.meter-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-green), var(--accent-cyan));
    width: 0%;
    transition: width 0.1s ease, background 0.3s ease, box-shadow 0.3s ease;
    border-radius: 15px;
}

.threshold-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--accent-purple);
    box-shadow: 0 0 8px var(--accent-purple);
    transition: left 0.2s ease, background 0.3s ease, box-shadow 0.3s ease;
    border-radius: 1px;
}

@keyframes thresholdPulse {
    0%, 100% {
        opacity: 1;
        transform: scaleY(1);
    }
    50% {
        opacity: 0.8;
        transform: scaleY(1.05);
    }
}

.visualizer-section.listening {
    animation: none;
}

/* Control Panel */
.control-panel {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-label {
    font-size: 0.95rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.control-select {
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.control-select:hover {
    border-color: var(--accent-cyan);
}

.control-select:focus {
    outline: none;
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.1);
}

.control-textarea {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    resize: vertical;
    min-height: 80px;
    transition: all 0.3s ease;
}

.control-textarea:hover {
    border-color: var(--accent-cyan);
}

.control-textarea:focus {
    outline: none;
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.1);
}

.control-hint {
    display: block;
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
}

.control-slider {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: var(--bg-tertiary);
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
}

.control-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-cyan);
    cursor: pointer;
    box-shadow: 0 0 10px var(--accent-cyan);
    transition: all 0.3s ease;
}

.control-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 15px var(--accent-cyan);
}

.control-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-cyan);
    cursor: pointer;
    border: none;
    box-shadow: 0 0 10px var(--accent-cyan);
    transition: all 0.3s ease;
}

.control-slider::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 15px var(--accent-cyan);
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.btn {
    padding: 1rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: var(--text-primary);
}

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

.btn-record {
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
    box-shadow: 0 4px 15px rgba(0, 212, 255, 0.3);
}

.btn-record:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 212, 255, 0.4);
}

.btn-record.recording {
    animation: recordingPulse 1.5s infinite;
}

@keyframes recordingPulse {
    0%, 100% { box-shadow: 0 4px 15px rgba(0, 212, 255, 0.3); }
    50% { box-shadow: 0 4px 25px rgba(0, 212, 255, 0.6); }
}

.btn-stop {
    background: var(--error);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.btn-stop:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}

.btn-clear {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
}

.btn-clear:hover {
    background: var(--bg-primary);
    border-color: var(--accent-purple);
}

.btn-icon {
    font-size: 1.2rem;
}

/* Results Section */
.results-section {
    grid-column: 1 / -1;
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.section-title {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.results-container {
    max-height: 400px;
    overflow-y: auto;
    border-radius: 8px;
}

.results-container::-webkit-scrollbar {
    width: 8px;
}

.results-container::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.results-container::-webkit-scrollbar-thumb {
    background: var(--accent-cyan);
    border-radius: 4px;
}

.results-container::-webkit-scrollbar-thumb:hover {
    background: var(--accent-purple);
}

.results-table {
    width: 100%;
    border-collapse: collapse;
}

.results-table thead {
    background: var(--bg-tertiary);
    position: sticky;
    top: 0;
    z-index: 10;
}

.results-table th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-color);
}

.results-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.results-table tbody tr {
    transition: background 0.2s ease;
}

.results-table tbody tr:hover {
    background: var(--bg-tertiary);
}

.results-table tbody tr.empty-row td {
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
    padding: 2rem;
}

.confidence-bar {
    display: inline-block;
    width: 100px;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    margin-left: 0.5rem;
    vertical-align: middle;
}

.confidence-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-green), var(--accent-cyan));
    transition: width 0.3s ease;
}

.model-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--accent-purple);
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--accent-purple);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.audio-cell {
    text-align: center;
    padding: 0.5rem 1rem;
}

.result-audio-player {
    width: 100%;
    max-width: 200px;
    height: 32px;
    outline: none;
}

.result-audio-player::-webkit-media-controls-panel {
    background-color: var(--bg-tertiary);
}

.result-audio-player::-webkit-media-controls-play-button,
.result-audio-player::-webkit-media-controls-timeline,
.result-audio-player::-webkit-media-controls-current-time-display,
.result-audio-player::-webkit-media-controls-time-remaining-display {
    filter: invert(1);
}

.no-audio {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.9rem;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }
    
    .container {
        padding: 1rem;
    }
    
    .title {
        font-size: 2rem;
    }
}

@media (max-width: 768px) {
    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .button-group {
        flex-direction: row;
    }

    .btn {
        flex: 1;
    }
}

/* Toggle Switch Styles (Phase A A/B Testing) */
.toggle-switch-container {
    margin-top: 0.5rem;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 30px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-tertiary);
    transition: .4s;
    border-radius: 30px;
    border: 2px solid var(--border-color);
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: var(--text-muted);
    transition: .4s;
    border-radius: 50%;
}

input:checked + .toggle-slider {
    background-color: var(--accent-green);
    border-color: var(--accent-green);
}

input:checked + .toggle-slider:before {
    transform: translateX(30px);
    background-color: white;
}

.toggle-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.toggle-label-left {
    color: var(--text-muted);
}

.toggle-label-right {
    color: var(--accent-green);
    font-weight: 500;
}

.toggle-label-text {
    margin-right: 0.5rem;
}

.toggle-mode-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background-color: var(--accent-green);
    color: white;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Mode and Method Badges in Results Table */
.mode-badge,
.method-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
    text-transform: capitalize;
}

.mode-badge {
    min-width: 70px;
    text-align: center;
}

.method-badge {
    min-width: 90px;
    text-align: center;
    white-space: nowrap;
}
