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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333;
}

.container {
    background: rgba(34, 4, 35, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    width: 90%;
    max-width: 600px;
    overflow: hidden;
    position: relative;
}

/* Header Styles */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 30px;
    text-align: center;
    position: relative;
}

.header h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 10px;
}

.connection-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 14px;
}

.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ff4444;
    animation: pulse 2s infinite;
    transition: all 0.3s ease;
}

.status-indicator.connecting {
    background: #ffbb33;
}

.status-indicator.connected {
    background: #00C851;
}

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

/* Main Content */
.main-content {
    padding: 30px;
}

/* Speaking Indicators */
.speaking-indicators {
    display: flex;
    justify-content: space-around;
    margin-bottom: 30px;
}

.indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 20px;
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.8);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    position: relative;
}

.indicator i {
    font-size: 24px;
    color: #666;
    transition: all 0.3s ease;
}

.indicator.speaking i {
    color: #667eea;
    animation: bounce 0.5s infinite alternate;
}

.indicator.muted i {
    color: #ff4444;
}

.audio-level {
    width: 60px;
    height: 4px;
    background: #e0e0e0;
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

.audio-level::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: linear-gradient(90deg, #00C851, #ffbb33, #ff4444);
    border-radius: 2px;
    width: 0%;
    transition: width 0.1s ease;
}

.indicator.speaking .audio-level::after {
    animation: audioLevel 0.5s infinite alternate;
}

.indicator-label {
    font-size: 12px;
    color: #666;
    font-weight: 500;
}

@keyframes bounce {
    0% { transform: translateY(0); }
    100% { transform: translateY(-5px); }
}

@keyframes audioLevel {
    0% { width: 20%; }
    50% { width: 60%; }
    100% { width: 80%; }
}

/* Rive Animation Styles */
.rive-animation-container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 20px 0; /* Add some vertical spacing */
    min-height: 200px; /* Ensure it takes up some space */
    background: rgba(255, 255, 255, 0.9);
    border-radius: 15px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

#riveCanvas {
    width: 100% !important;
    height: auto !important;
    max-width: 300px; /* Adjust max-width as needed for optimal display */
    display: block; /* Remove extra space below canvas */
}

/* Transcription Area */
.transcription-area {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 30px;
    min-height: 200px;
    position: relative;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.transcription-message {
    margin-bottom: 12px;
    padding: 15px;
    border-radius: 10px;
    animation: fadeIn 0.5s ease;
    transition: all 0.3s ease;
    max-width: 85%;
}

.transcription-message.fadeOut {
    animation: fadeOut 0.5s ease forwards;
}

.user-message {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    margin-left: auto;
    margin-right: 0;
    border-bottom-right-radius: 5px;
    align-self: flex-end;
}

.agent-message {
    background: #f8f9fa;
    color: #333;
    margin-left: 0;
    margin-right: auto;
    border-bottom-left-radius: 5px;
    border-left: 4px solid #667eea;
    align-self: flex-start;
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.speaker-label {
    font-size: 12px;
    font-weight: 600;
    opacity: 0.8;
}

.message-text {
    font-size: 14px;
    line-height: 1.4;
}

.empty-state {
    text-align: center;
    color: #999;
    padding: 40px 20px;
}

.empty-state i {
    font-size: 48px;
    margin-bottom: 20px;
    color: #ddd;
}

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

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

/* Text Input Section */
.text-input-section {
    margin-bottom: 20px;
}

.input-container {
    display: flex;
    gap: 10px;
    align-items: center;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 25px;
    padding: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.input-container:focus-within {
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
    background: white;
}

#textInput {
    flex: 1;
    border: none;
    background: transparent;
    padding: 12px 16px;
    font-size: 14px;
    font-family: inherit;
    color: #333;
    outline: none;
    border-radius: 20px;
}

#textInput::placeholder {
    color: #999;
    font-style: italic;
}

#textInput:disabled {
    color: #666;
    background: rgba(0, 0, 0, 0.05);
    cursor: not-allowed;
}

#textInput:disabled::placeholder {
    color: #bbb;
}

.send-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.send-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.send-btn:active {
    transform: translateY(0);
}

.send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Controls */
.controls {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
}

.control-btn {
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 50%;
    background: white;
    color: #666;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.control-btn:active {
    transform: translateY(0);
}

.mic-btn.active {
    background: #00C851;
    color: white;
}

.mic-btn.muted {
    background: #ff4444;
    color: white;
}

.speaker-btn.muted {
    background: #ff4444;
    color: white;
}

.info-btn {
    background: #667eea;
    color: white;
}

.test-btn {
    background: #28a745;
    color: white;
}

/* Footer */
.footer {
    background: rgba(0, 0, 0, 0.05);
    padding: 15px 30px;
    text-align: center;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.room-info {
    font-size: 12px;
    color: #666;
}

.room-label {
    font-weight: 600;
    margin-right: 5px;
}

.room-id {
    font-family: monospace;
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 3px;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.loading-spinner {
    text-align: center;
    color: white;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1001;
}

.modal-content {
    background: white;
    border-radius: 15px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

.modal-header {
    background: #667eea;
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 20px;
    text-align: center;
    border-top: 1px solid #eee;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s ease;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5a6fd8;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        width: 95%;
        margin: 10px;
    }
    
    .header {
        padding: 15px 20px;
    }
    
    .header h1 {
        font-size: 20px;
    }
    
    .main-content {
        padding: 20px;
    }
    
    .speaking-indicators {
        flex-direction: column;
        gap: 15px;
    }
    
    .indicator {
        flex-direction: row;
        padding: 15px;
    }
    
    .text-input-section {
        margin-bottom: 15px;
    }
    
    .input-container {
        padding: 8px;
    }
    
    #textInput {
        padding: 12px 16px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .send-btn {
        width: 44px;  /* Larger touch target */
        height: 44px;
        font-size: 16px;
    }

    .controls {
        gap: 15px;
    }
    
    .control-btn {
        width: 56px;  /* Larger touch target */
        height: 56px;
        font-size: 22px;
    }
    
    .transcription-area {
        min-height: 150px;
        padding: 15px;
    }
    
    .user-message {
        margin-left: 10px;
    }
    
    .agent-message {
        margin-right: 10px;
    }
}

/* Portrait Phone Optimizations */
@media (max-width: 480px) and (orientation: portrait) {
    body {
        align-items: flex-start;
        padding: 0;
    }
    
    .container {
        width: 100%;
        min-height: 100vh;
        margin: 0;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }
    
    .header {
        padding: 15px 20px;
        flex-shrink: 0;
    }
    
    .header h1 {
        font-size: 22px;
        margin-bottom: 8px;
    }
    
    .main-content {
        padding: 20px;
        flex: 1;
        display: flex;
        flex-direction: column;
    }
    
    .speaking-indicators {
        margin-bottom: 20px;
        flex-shrink: 0;
    }
    
    .indicator {
        padding: 16px;
        gap: 12px;
        min-height: 60px;
    }
    
    .indicator i {
        font-size: 20px;
    }
    
    .indicator-label {
        font-size: 14px;
        font-weight: 600;
    }
    
    .transcription-area {
        flex: 1;
        min-height: 200px;
        margin-bottom: 20px;
        padding: 16px;
        display: flex;
        flex-direction: column;
        justify-content: flex-end;
    }
    
    .transcription-message {
        margin-bottom: 12px;
        padding: 16px;
        font-size: 15px;
        line-height: 1.5;
    }
    
    .message-text {
        font-size: 15px;
        line-height: 1.5;
    }
    
    .speaker-label {
        font-size: 13px;
        margin-bottom: 4px;
    }
    
    .text-input-section {
        margin-bottom: 20px;
        flex-shrink: 0;
    }
    
    .input-container {
        padding: 10px;
        border-radius: 30px;
    }
    
    #textInput {
        padding: 14px 18px;
        font-size: 16px;
        border-radius: 25px;
    }
    
    .send-btn {
        width: 48px;
        height: 48px;
        font-size: 18px;
    }
    
    .controls {
        gap: 20px;
        margin-bottom: 15px;
        flex-shrink: 0;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .control-btn {
        width: 60px;
        height: 60px;
        font-size: 24px;
        touch-action: manipulation; /* Prevents double-tap zoom */
    }
    
    .footer {
        padding: 12px 20px;
        flex-shrink: 0;
    }
}

/* Landscape or very small screens */
@media (max-width: 480px) and (orientation: landscape) {
    .container {
        width: 100%;
        margin: 0;
        border-radius: 0;
    }
    
    .header {
        padding: 8px 15px;
    }
    
    .header h1 {
        font-size: 18px;
        margin-bottom: 5px;
    }
    
    .main-content {
        padding: 15px;
    }
    
    .speaking-indicators {
        gap: 8px;
        margin-bottom: 15px;
    }
    
    .indicator {
        padding: 8px 12px;
        flex-direction: row;
        gap: 8px;
    }
    
    .transcription-area {
        min-height: 120px;
        padding: 12px;
        margin-bottom: 15px;
    }
    
    .controls {
        gap: 8px;
        margin-bottom: 10px;
    }
    
    .control-btn {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
    
    .input-container {
        padding: 6px;
    }
    
    #textInput {
        padding: 8px 12px;
        font-size: 14px;
    }
    
    .send-btn {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }
    
    .footer {
        padding: 8px 15px;
    }
}

/* Very small screens regardless of orientation */
@media (max-width: 320px) {
    .header h1 {
        font-size: 16px;
    }
    
    .main-content {
        padding: 12px;
    }
    
    .controls {
        gap: 6px;
    }
    
    .control-btn {
        width: 38px;
        height: 38px;
        font-size: 14px;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus styles for keyboard navigation */
.control-btn:focus,
.close-btn:focus,
.btn:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .container {
        background: white;
        border: 2px solid #333;
    }
    
    .header {
        background: #333;
        color: white;
    }
    
    .indicator {
        background: white;
        border: 1px solid #333;
    }
    
    .transcription-area {
        background: white;
        border: 1px solid #333;
    }
}