/* 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;
    color: #333;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header styles */
header {
    text-align: center;
    margin-bottom: 30px;
    color: white;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* Main content */
main {
    background: white;
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

/* Video container */
.video-container {
    position: relative;
    text-align: center;
    margin: 0 auto 20px auto;
    width: 100%;
    height: 406px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#input_video {
    width: 400px;
    height: 400px;
    border-radius: 50%;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
    display: block;
    border: 3px solid rgba(255, 255, 255, 0.1);
    position: relative;
}

#output_canvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.1);
}

/* Placeholder overlay for initial state */
.selfie-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 400px;
    height: 400px;
    border-radius: 50%;
    background-image: url('./take_selfie_placeholder.png');
    background-size: 110%;
    background-position: center;
    background-repeat: no-repeat;
    display: block;
    pointer-events: none;
    z-index: 10;
    border: 3px solid rgba(255, 255, 255, 0.1);
}

.selfie-placeholder.hidden {
    display: none;
}

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

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 25px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
    display: inline-block;
}

.btn-primary {
    background: rgba(45, 55, 72, 0.8) !important;
    color: white !important;
    backdrop-filter: blur(10px) !important;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(45, 55, 72, 0.4);
    background: rgba(45, 55, 72, 0.9);
}

.btn-secondary {
    background: linear-gradient(45deg, #f44336, #da190b);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(244, 67, 54, 0.4);
}

.btn-success {
    background: rgba(45, 55, 72, 0.8);
    color: white;
    backdrop-filter: blur(10px);
}

.btn-success:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(45, 55, 72, 0.4);
    background: rgba(45, 55, 72, 0.9);
}

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

/* Status */
.status {
    text-align: center;
    padding: 15px;
    margin-bottom: 30px;
    background: #f8f9fa;
    border-radius: 10px;
    border-left: 4px solid #007bff;
    font-weight: 500;
}

/* Features panel */
.features-panel {
    margin-bottom: 30px;
}

.features-panel h2 {
    text-align: center;
    margin-bottom: 25px;
    color: #333;
    font-size: 1.8rem;
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.feature-card {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border-radius: 15px;
    padding: 25px;
    text-align: center;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
}

.feature-card:hover {
    transform: translateY(-5px);
}

.feature-icon {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.feature-label {
    font-weight: 600;
    color: #666;
    margin-bottom: 10px;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.feature-value {
    font-size: 2rem;
    font-weight: bold;
    color: #007bff;
    margin-bottom: 5px;
    font-family: 'Courier New', monospace;
}

.feature-unit {
    font-size: 0.8rem;
    color: #999;
    text-transform: uppercase;
}

/* Emotion summary panel */
.emotion-summary {
    background: linear-gradient(135deg, #667eea, #764ba2);
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 30px;
    text-align: center;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    color: white;
}

.emotion-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin: 20px 0;
}

.emotion-card {
    background: rgba(255, 255, 255, 0.15);
    padding: 15px;
    border-radius: 10px;
    backdrop-filter: blur(10px);
    text-align: center;
    transition: transform 0.3s ease;
}

.emotion-card:hover {
    transform: translateY(-5px);
}

.emotion-icon {
    font-size: 2em;
    margin-bottom: 8px;
}

.emotion-label {
    font-size: 0.9em;
    opacity: 0.8;
    margin-bottom: 5px;
}

.emotion-value {
    font-size: 1.1em;
    font-weight: bold;
    color: #fff;
}

/* Wellness Coach Section */
.wellness-coach, .wellness-section {
    background: linear-gradient(135deg, #f093fb, #f5576c);
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 30px;
    text-align: center;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    color: white;
    display: block !important;
    visibility: visible !important;
}

.wellness-coach h2 {
    margin-bottom: 20px;
    color: white;
    font-size: 1.8rem;
}

.wellness-button, .wellness-btn {
    background: rgba(255, 255, 255, 0.2) !important;
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
    color: white !important;
    padding: 18px 40px !important;
    border-radius: 30px !important;
    font-size: 1.4rem !important;
    font-weight: bold !important;
    cursor: pointer;
    backdrop-filter: blur(10px) !important;
    transition: all 0.3s ease;
    margin-bottom: 25px;
    box-shadow: 0 6px 15px rgba(0,0,0,0.3) !important;
}

.wellness-button:hover:not(:disabled), .wellness-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

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

.wellness-feedback {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 20px;
    text-align: justify;
    backdrop-filter: blur(10px);
    min-height: 120px;
    display: block;
    line-height: 1.8;
}

.wellness-placeholder {
    color: rgba(255, 255, 255, 0.8);
    font-style: italic;
    text-align: center;
}

.wellness-content {
    line-height: 1.8;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 20px;
    text-align: justify;
    min-height: 60px;
    display: block;
}

.wellness-content h3 {
    margin-top: 0;
    margin-bottom: 10px;
    color: #fff;
}

.wellness-content p {
    margin-bottom: 15px;
}

.wellness-content ul {
    margin: 10px 0;
    padding-left: 20px;
}

.wellness-content li {
    margin-bottom: 8px;
}

.emotion-summary h2 {
    margin-bottom: 20px;
    color: #2e7d32;
    font-size: 1.8rem;
}

.emotion-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.current-emotion {
    font-size: 2.5rem;
    font-weight: bold;
    color: #1b5e20;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 25px;
    min-width: 200px;
}

.emotion-confidence {
    font-size: 1.1rem;
    color: #388e3c;
    font-weight: 500;
}

/* Debug panel */
.debug-panel {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
}

.debug-panel h3 {
    margin-bottom: 15px;
    color: #666;
    font-size: 1.2rem;
}

#debug_output {
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    line-height: 1.6;
    background: #fff;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #ddd;
    white-space: pre-wrap;
    max-height: 200px;
    overflow-y: auto;
}

/* Footer */
footer {
    text-align: center;
    margin-top: 30px;
    color: white;
    opacity: 0.8;
}

/* Responsive design */
@media (max-width: 768px) {
    .container {
        padding: 15px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }
    
    header h1 {
        font-size: 2rem;
        text-align: center;
    }
    
    main {
        padding: 20px;
        text-align: center;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    
    .features-grid {
        grid-template-columns: 1fr;
    }
    
    .controls {
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-align: center;
    }
    
    .btn {
        width: 200px;
        text-align: center !important;
        display: inline-block !important;
        background: rgba(45, 55, 72, 0.8) !important;
        color: white !important;
        backdrop-filter: blur(10px) !important;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.8rem;
    }
    
    .feature-card {
        padding: 20px;
    }
    
    .feature-value {
        font-size: 1.5rem;
    }
    
    .btn {
        background: rgba(45, 55, 72, 0.8) !important;
        color: white !important;
        backdrop-filter: blur(10px) !important;
    }
}

/* iPhone SE and small devices */
@media (max-width: 380px) {
    .video-container {
        transform: translateX(-50%);
        left: 50%;
        position: relative;
    }
    
    .btn {
        background: rgba(45, 55, 72, 0.8) !important;
        color: white !important;
        backdrop-filter: blur(10px) !important;
        width: 180px;
    }
}

/* iPhone 14 Pro and similar devices */
@media (max-width: 430px) and (min-width: 381px) {
    .btn {
        background: rgba(45, 55, 72, 0.8) !important;
        color: white !important;
        backdrop-filter: blur(10px) !important;
    }
}

/* Desktop and tablet specific */
@media (min-width: 769px) {
    .btn {
        background: rgba(45, 55, 72, 0.8) !important;
        color: white !important;
        backdrop-filter: blur(10px) !important;
    }
}

/* Universal button styling for all devices and states */
#mood_check_button, #take_selfie_button {
    background: rgba(45, 55, 72, 0.8) !important;
    color: white !important;
    backdrop-filter: blur(10px) !important;
    border: none !important;
    padding: 12px 24px !important;
    border-radius: 25px !important;
    font-size: 1rem !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    text-align: center !important;
    display: inline-block !important;
}

/* Hover states for all devices */
#mood_check_button:hover:not(:disabled),
#take_selfie_button:hover:not(:disabled) {
    background: rgba(45, 55, 72, 0.9) !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3) !important;
}

/* Disabled states for analyzing button */
#mood_check_button:disabled,
#take_selfie_button:disabled {
    background: rgba(45, 55, 72, 0.6) !important;
    cursor: not-allowed !important;
    transform: none !important;
}

/* Animation for loading states */
.loading {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

/* Error states */
.error {
    background: #ffebee !important;
    border-left-color: #f44336 !important;
    color: #c62828;
}

.success {
    background: #e8f5e8 !important;
    border-left-color: #4caf50 !important;
    color: #2e7d32;
}

/* Enterprise Analysis Styling */
.enterprise-badge {
    background: linear-gradient(45deg, #4CAF50, #45a049);
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: bold;
    margin-bottom: 15px;
    display: inline-block;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.emotion-detection-box {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.primary-emotion {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.emotion-name {
    font-size: 24px;
    font-weight: bold;
    text-transform: capitalize;
}

.confidence-score {
    font-size: 18px;
    background: rgba(255,255,255,0.2);
    padding: 5px 10px;
    border-radius: 15px;
}

.dataset-info {
    margin-bottom: 10px;
    opacity: 0.9;
}

.pattern-indicators {
    background: rgba(255,255,255,0.1);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
}

.measurement-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.measurement-item {
    background: white;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #ddd;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.2s;
}

.measurement-item:hover {
    transform: translateY(-2px);
}

.measurement-item.elevated {
    border-left-color: #ff9800;
    background: linear-gradient(to right, #fff3e0, #ffffff);
}

.measurement-item.high {
    border-left-color: #f44336;
    background: linear-gradient(to right, #ffebee, #ffffff);
}

.measurement-item.positive {
    border-left-color: #4caf50;
    background: linear-gradient(to right, #e8f5e8, #ffffff);
}

.measurement-item.negative {
    border-left-color: #2196f3;
    background: linear-gradient(to right, #e3f2fd, #ffffff);
}

.measurement-item.raised {
    border-left-color: #9c27b0;
    background: linear-gradient(to right, #f3e5f5, #ffffff);
}

.measurement-item.lowered {
    border-left-color: #607d8b;
    background: linear-gradient(to right, #eceff1, #ffffff);
}

.measurement-item.normal {
    border-left-color: #4caf50;
}

.measurement-item.low {
    border-left-color: #ff5722;
}

.measurement-item.relaxed {
    border-left-color: #009688;
}

.measurement-item.neutral {
    border-left-color: #795548;
}

.measurement-item .label {
    font-weight: bold;
    color: #333;
    display: block;
    margin-bottom: 5px;
}

.measurement-item .value {
    font-size: 18px;
    font-weight: bold;
    color: #2196f3;
    display: block;
    margin-bottom: 8px;
}

.measurement-item .interpretation {
    font-size: 12px;
    color: #666;
    line-height: 1.4;
}

.emotion-scores-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.emotion-score-item {
    background: white;
    padding: 12px;
    border-radius: 8px;
    border: 2px solid #e0e0e0;
    transition: all 0.3s;
}

.emotion-score-item.primary {
    border-color: #4caf50;
    background: linear-gradient(to right, #e8f5e8, #ffffff);
    transform: scale(1.02);
}

.emotion-label {
    font-weight: bold;
    color: #333;
    margin-bottom: 8px;
    text-transform: capitalize;
}

.confidence-bar {
    background: #f0f0f0;
    border-radius: 10px;
    height: 20px;
    position: relative;
    margin-bottom: 5px;
    overflow: hidden;
}

.confidence-fill {
    background: linear-gradient(90deg, #4caf50, #8bc34a);
    height: 100%;
    border-radius: 10px;
    transition: width 0.5s ease;
}

.confidence-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 12px;
    font-weight: bold;
    color: #333;
}

.dataset-size {
    font-size: 10px;
    color: #666;
    text-align: center;
}

/* Mobile-specific centering for camera and frame */
@media (max-width: 768px) {
    .container {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 15px;
    }
    
    main {
        width: 100%;
        max-width: 400px;
        text-align: center;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    
    .video-container {
        width: 350px;
        height: 356px;
        position: relative;
        display: flex;
        justify-content: center;
        align-items: center;
        margin: 20px auto;
    }
    
    #input_video {
        width: 350px;
        height: 350px;
        position: relative;
    }
    
    #output_canvas {
        width: 350px;
        height: 350px;
        position: absolute;
        top: 0;
        left: 0;
    }
    
    .selfie-placeholder {
        width: 350px;
        height: 350px;
        position: absolute;
        top: 0;
        left: 0;
    }
    
    .controls {
        width: 100%;
        justify-content: center;
        margin-top: 20px;
    }
}

/* iPhone SE and very small devices specific centering */
@media (max-width: 380px) {
    body {
        padding: 0;
    }
    
    .container {
        padding: 5px;
        max-width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }
    
    main {
        padding: 10px 5px;
        overflow-x: hidden;
        width: 100%;
        max-width: 380px;
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center;
    }
    
    .video-container {
        position: relative;
        width: 350px;
        height: 356px;
        margin: 20px auto;
        display: flex;
        justify-content: center;
        align-items: center;
        user-select: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        touch-action: none;
        pointer-events: none;
        -webkit-touch-callout: none;
        -webkit-tap-highlight-color: transparent;
    }
    
    #input_video {
        width: 350px;
        height: 350px;
        margin: 0;
        display: block;
        position: relative;
        user-select: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        -webkit-user-drag: none;
        -khtml-user-drag: none;
        -moz-user-drag: none;
        -o-user-drag: none;
        user-drag: none;
        touch-action: none;
        -webkit-touch-callout: none;
        -webkit-tap-highlight-color: transparent;
        pointer-events: none;
    }
    
    #output_canvas {
        width: 350px;
        height: 350px;
        position: absolute;
        top: 0;
        left: 0;
        margin: 0;
        pointer-events: none;
        user-select: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
    }
    
    .selfie-placeholder {
        width: 350px;
        height: 350px;
        position: absolute;
        top: 0;
        left: 0;
        margin: 0;
        pointer-events: none;
        user-select: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
    }
    
    .controls {
        width: 100%;
        max-width: 350px;
        margin: 20px auto 0;
        padding: 0 10px;
        box-sizing: border-box;
        pointer-events: auto;
        user-select: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    
    .btn {
        text-align: center !important;
        display: inline-block !important;
    }
}

/* Desktop text alignment overrides */
@media (min-width: 769px) {
    .wellness-feedback {
        text-align: justify !important;
    }
    
    .wellness-content {
        text-align: justify !important;
    }
    
    .wellness-placeholder {
        text-align: center !important;
    }
    
    .wellness-feedback-wide {
        text-align: justify !important;
        display: block !important;
        flex-direction: column !important;
    }
    
    #combined_feedback {
        text-align: justify !important;
        display: block !important;
        flex-direction: column !important;
    }
    
    /* Ensure instructional text is centered on desktop ONLY when showing placeholder */
    .wellness-section .wellness-feedback-wide:not(.has-content) {
        text-align: center !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
}

/* Universal layout fixes for all screen sizes */
.wellness-feedback-wide {
    text-align: justify !important;
    display: block !important;
    width: 100% !important;
    box-sizing: border-box !important;
    line-height: 1.8 !important;
    flex-direction: column !important;
}

#combined_feedback {
    text-align: justify !important;
    display: block !important;
    width: 100% !important;
    box-sizing: border-box !important;
    line-height: 1.8 !important;
    flex-direction: column !important;
}

/* Force paragraphs to stack vertically, never side-by-side */
#combined_feedback p, 
.wellness-feedback-wide p,
#combined_feedback > div,
.wellness-feedback-wide > div,
.feedback-section {
    display: block !important;
    width: 100% !important;
    margin-bottom: 20px !important;
    flex: none !important;
    clear: both !important;
}

/* Prevent any flex row behavior */
.wellness-section .wellness-feedback-wide {
    display: block !important;
    flex-direction: column !important;
}

.unified-feedback-container {
    display: block !important;
    flex-direction: column !important;
}

/* Absolutely prevent side-by-side text blocks */
#combined_feedback, 
#combined_feedback * {
    float: none !important;
    display: block !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

/* Override any conflicting flex or inline styles */
.ai-feedback, .feedback-section {
    display: block !important;
    width: 100% !important;
    margin: 0 0 30px 0 !important;
    padding: 0 !important;
    float: none !important;
    position: static !important;
}

/* Mobile-specific overrides */
@media (max-width: 768px) {
    .wellness-feedback {
        text-align: justify !important;
        display: block !important;
        width: 100% !important;
        line-height: 1.8 !important;
    }
    
    .wellness-content {
        text-align: justify !important;
        display: block !important;
        width: 100% !important;
        line-height: 1.8 !important;
    }
    
    .wellness-feedback-wide {
        text-align: justify !important;
        display: block !important;
        width: 100% !important;
        line-height: 1.8 !important;
    }
    
    #combined_feedback {
        text-align: justify !important;
        display: block !important;
        width: 100% !important;
        line-height: 1.8 !important;
    }
}

/* iPhone 14 Pro and medium phones specific centering */
@media (max-width: 430px) and (min-width: 390px) {
    .container {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        width: 100%;
        padding: 10px;
    }
    
    main {
        width: 100%;
        max-width: 390px;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    
    .video-container {
        position: relative;
        width: 350px;
        height: 356px;
        display: flex;
        justify-content: center;
        align-items: center;
        margin: 20px auto;
    }
    
    #input_video {
        width: 350px;
        height: 350px;
        position: relative;
    }
    
    #output_canvas,
    .selfie-placeholder {
        width: 350px;
        height: 350px;
        position: absolute;
        top: 0;
        left: 0;
    }
}
