/* CSS Variables */
:root {
    --primary-color: #4a90d9;
    --primary-hover: #357abd;
    --secondary-color: #2ecc71;
    --danger-color: #e74c3c;
    --english-color: #3498db;
    --spanish-color: #e74c3c;
    --portuguese-color: #27ae60;
    --background-color: #f5f7fa;
    --card-background: #ffffff;
    --text-color: #333333;
    --text-muted: #666666;
    --border-color: #e0e0e0;
    --border-radius: 12px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    --transition: all 0.2s ease;
    --sidebar-width: 220px;
}

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

/* Full viewport layout */
html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
}

/* App Container - Full viewport */
.app-container {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Setup Panel - Centered */
.setup-panel {
    max-width: 400px;
    margin: auto;
    background: var(--card-background);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 32px;
}

.setup-panel h1 {
    font-size: 1.75rem;
    margin-bottom: 8px;
    text-align: center;
}

.setup-panel .subtitle {
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 32px;
}

.setup-panel .hint {
    color: var(--text-muted);
    font-size: 0.875rem;
    text-align: center;
    margin-top: 16px;
}

/* Form Elements */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-color);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px 16px;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--card-background);
    color: var(--text-color);
    transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Buttons */
.btn-primary {
    width: 100%;
    padding: 14px 24px;
    font-size: 1rem;
    font-weight: 600;
    color: white;
    background: var(--primary-color);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-primary:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Chat Panel - Full height */
.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Chat Layout - Sidebar + Main */
.chat-layout {
    display: flex;
    flex: 1;
    height: 100%;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--card-background);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.participant-count {
    background: var(--primary-color);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.participant-list {
    flex: 1;
    overflow-y: auto;
    list-style: none;
    padding: 8px;
}

.participant-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 4px;
    transition: var(--transition);
}

.participant-item:hover {
    background: var(--background-color);
}

.participant-item.self {
    background: rgba(74, 144, 217, 0.1);
}

.participant-item.speaking {
    background: rgba(231, 76, 60, 0.15);
}

.participant-item.speaking .participant-avatar {
    animation: speaking-pulse 1s infinite;
}

@keyframes speaking-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(231, 76, 60, 0);
    }
}

.participant-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    color: white;
}

.participant-avatar.en {
    background: var(--english-color);
}

.participant-avatar.es {
    background: var(--spanish-color);
}

.participant-avatar.pt {
    background: var(--portuguese-color);
}

.participant-info {
    flex: 1;
    min-width: 0;
}

.participant-name {
    font-weight: 500;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.participant-lang {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Chat Main Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: var(--card-background);
    border-bottom: 1px solid var(--border-color);
}

.chat-header h2 {
    font-size: 1.25rem;
}

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

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
}

.language-badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.language-badge.en {
    background: var(--english-color);
    color: white;
}

.language-badge.es {
    background: var(--spanish-color);
    color: white;
}

.language-badge.pt {
    background: var(--portuguese-color);
    color: white;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ccc;
}

.status-indicator.connected {
    background: var(--secondary-color);
}

.status-indicator.disconnected {
    background: var(--danger-color);
}

/* Message Feed - Flex grow */
.message-feed {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    background: var(--background-color);
}

.welcome-message {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 20px;
}

.welcome-message p {
    margin-bottom: 8px;
}

/* System Messages (join/leave) */
.system-message {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 8px 16px;
    margin: 12px 0;
}

/* Message Styles */
.message {
    margin-bottom: 16px;
    padding: 16px;
    background: var(--card-background);
    border-radius: var(--border-radius);
    border-left: 4px solid var(--primary-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.message.english {
    border-left-color: var(--english-color);
}

.message.spanish {
    border-left-color: var(--spanish-color);
}

.message.portuguese {
    border-left-color: var(--portuguese-color);
}

.message.realtime-transcript {
    border-left-color: var(--text-muted);
    opacity: 0.7;
    font-style: italic;
}

.message.speaking-pending {
    opacity: 0.6;
}

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

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

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 0.875rem;
}

.speaker {
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.speaker .lang-tag {
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.speaker .lang-tag.en {
    background: var(--english-color);
    color: white;
}

.speaker .lang-tag.es {
    background: var(--spanish-color);
    color: white;
}

.speaker .lang-tag.pt {
    background: var(--portuguese-color);
    color: white;
}

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

.message-original {
    font-size: 1rem;
    line-height: 1.5;
    margin-bottom: 8px;
}

.message-translated {
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--primary-color);
    padding-top: 8px;
    border-top: 1px dashed var(--border-color);
}

.translation-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 4px;
}

/* Translation-only mode: hide original text when a translation exists */
.translation-only .message:not(.speaking-pending) .message-original:has(~ .message-translated) {
    display: none;
}
.translation-only .message .message-translated {
    border-top: none;
    padding-top: 0;
}
.translation-only .message .translation-label {
    display: none;
}

/* Controls */
.controls {
    padding: 12px 20px;
    background: var(--card-background);
    border-top: 1px solid var(--border-color);
}

/* Input Row */
.input-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.text-input {
    flex: 1;
    padding: 10px 14px;
    font-size: 0.95rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--card-background);
    color: var(--text-color);
    transition: var(--transition);
    min-width: 0;
}

.text-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.text-input:disabled {
    background: #f0f0f0;
    cursor: not-allowed;
}

.send-btn {
    padding: 10px 14px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    background: var(--primary-hover);
}

.send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Push-to-Talk Button */
.ptt-button {
    padding: 10px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    color: white;
    background: var(--primary-color);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    flex-shrink: 0;
}

.ptt-button:hover:not(:disabled) {
    background: var(--primary-hover);
}

.ptt-button:active:not(:disabled),
.ptt-button.recording {
    background: var(--danger-color);
}

.ptt-button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.ptt-button.blocked {
    background: #95a5a6;
    cursor: not-allowed;
}

.ptt-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Recording Indicator */
.recording-indicator,
.processing-indicator {
    margin-top: 12px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.recording-indicator {
    color: var(--danger-color);
}

.processing-indicator {
    color: var(--primary-color);
}

.pulse {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--danger-color);
    animation: pulse 1s infinite;
}

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

/* Scrollbar Styling */
.message-feed::-webkit-scrollbar,
.participant-list::-webkit-scrollbar {
    width: 8px;
}

.message-feed::-webkit-scrollbar-track,
.participant-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.message-feed::-webkit-scrollbar-thumb,
.participant-list::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.message-feed::-webkit-scrollbar-thumb:hover,
.participant-list::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 180px;
        min-width: 180px;
    }
}

@media (max-width: 600px) {
    .chat-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        min-width: 100%;
        height: auto;
        max-height: 150px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .participant-list {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        padding: 8px;
    }

    .participant-item {
        flex: 0 0 auto;
        margin-bottom: 0;
    }

    .ptt-button .ptt-text {
        display: none;
    }

    .header-right {
        gap: 8px;
    }

    .toggle-label {
        display: none;
    }
}

/* ---- Presenter Mode ---- */

.presenter-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-color);
}

.presenter-toggle input[type="checkbox"] {
    display: none;
}

.toggle-slider {
    position: relative;
    width: 44px;
    height: 24px;
    background: #ccc;
    border-radius: 12px;
    transition: var(--transition);
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: var(--transition);
}

.presenter-toggle input:checked + .toggle-slider {
    background: var(--secondary-color);
}

.presenter-toggle input:checked + .toggle-slider::after {
    transform: translateX(20px);
}

.presenter-toggle input:disabled + .toggle-slider {
    opacity: 0.5;
    cursor: not-allowed;
}

/* VAD Indicator */
.vad-indicator {
    width: 100%;
    padding: 20px;
    border-radius: var(--border-radius);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    background: var(--secondary-color);
    position: relative;
    overflow: hidden;
    transition: background 0.3s ease;
}

.vad-indicator.vad-listening {
    background: var(--secondary-color);
}

.vad-indicator.vad-recording {
    background: var(--danger-color);
}

.vad-indicator.vad-blocked {
    background: #95a5a6;
}

.vad-indicator.vad-processing {
    background: var(--primary-color);
}

.vad-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.vad-text {
    font-size: 0.95rem;
}

/* Audio level bar */
.vad-level-bar {
    width: 80%;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 4px;
}

.vad-level-fill {
    height: 100%;
    width: 0%;
    background: white;
    border-radius: 2px;
    transition: width 0.05s linear;
}

/* Pulse ring animation */
.vad-pulse-ring {
    position: absolute;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.4);
    animation: vad-ring-pulse 2s infinite;
}

.vad-recording .vad-pulse-ring {
    border-color: rgba(255, 255, 255, 0.6);
    animation-duration: 1s;
}

@keyframes vad-ring-pulse {
    0% {
        transform: scale(0.8);
        opacity: 1;
    }
    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}
