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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    -webkit-user-select: none;
    user-select: none;
}

.container {
    max-width: 100%;
    padding: 10px;
    min-height: 100vh;
}

/* Header */
.header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 15px 20px;
    border-radius: 15px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 8px 32px rgba(31, 38, 135, 0.37);
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #2d3748;
}

.header h1 i {
    color: #667eea;
    margin-right: 8px;
}

/* API Status */
.api-status {
    display: flex;
    align-items: center;
}

.status-online {
    color: #48bb78;
    font-weight: 600;
}

.status-offline {
    color: #f56565;
    font-weight: 600;
}

.status-online i,
.status-offline i {
    font-size: 0.8rem;
    margin-right: 5px;
}

/* Navigation Tabs */
.tabs {
    display: flex;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 15px;
    padding: 5px;
    margin-bottom: 20px;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 16px rgba(31, 38, 135, 0.2);
}

.tab-btn {
    flex: 1;
    padding: 12px 16px;
    background: transparent;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 0.9rem;
    color: #718096;
}

.tab-btn.active {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.tab-btn i {
    font-size: 1.2rem;
}

/* Tab Content */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Cards */
.card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 25px;
    box-shadow: 0 8px 32px rgba(31, 38, 135, 0.37);
    margin-bottom: 20px;
}

.card h2 {
    font-size: 1.3rem;
    margin-bottom: 20px;
    color: #2d3748;
    display: flex;
    align-items: center;
    gap: 10px;
}

.card h2 i {
    color: #667eea;
}

/* Upload Area */
.upload-area {
    border: 3px dashed #cbd5e0;
    border-radius: 15px;
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 20px;
    position: relative;
    -webkit-tap-highlight-color: rgba(102, 126, 234, 0.2);
    touch-action: manipulation;
}

.upload-area:hover,
.upload-area.dragover,
.upload-area:active {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.1);
}

.upload-area i {
    font-size: 3rem;
    color: #a0aec0;
    margin-bottom: 15px;
}

.upload-area p {
    color: #718096;
    font-size: 1rem;
    margin: 0;
}

#image-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}

/* Preview Area */
.preview-area {
    text-align: center;
    margin-bottom: 20px;
}

#preview-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    margin-bottom: 15px;
}

/* Controls */
.controls {
    margin-bottom: 20px;
}

.controls label {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
    color: #4a5568;
}

#confidence-slider {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: #e2e8f0;
    outline: none;
    margin-bottom: 20px;
    -webkit-appearance: none;
}

#confidence-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-warning {
    width: 100%;
    padding: 15px;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 10px;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.btn-primary:disabled {
    background: #cbd5e0;
    color: #a0aec0;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-secondary {
    background: #f7fafc;
    color: #4a5568;
    border: 2px solid #e2e8f0;
}

.btn-secondary:hover:not(:disabled) {
    background: #edf2f7;
    border-color: #cbd5e0;
}

.btn-warning {
    background: linear-gradient(135deg, #ed8936, #dd6b20);
    color: white;
    box-shadow: 0 4px 15px rgba(237, 137, 54, 0.4);
}

.btn-warning:hover:not(:disabled) {
    transform: translateY(-2px);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-bottom: 20px;
}

.stat-card {
    background: rgba(255, 255, 255, 0.8);
    padding: 20px;
    border-radius: 15px;
    text-align: center;
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    position: relative;
}

.stat-card.highlight {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
}

.stat-card.highlight-in {
    background: linear-gradient(135deg, #48bb78, #38a169);
    color: white;
}

.stat-card.highlight-out {
    background: linear-gradient(135deg, #ed8936, #dd6b20);
    color: white;
}

.stat-card.secondary {
    background: rgba(237, 242, 247, 0.8);
    border: 2px solid rgba(203, 213, 224, 0.5);
}

.stat-icon {
    font-size: 1.5rem;
    margin-bottom: 10px;
    opacity: 0.9;
}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 5px;
}

.stat-label {
    font-size: 0.9rem;
    opacity: 0.8;
}

/* Camera Controls */
.camera-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
}

.camera-controls .btn-warning {
    grid-column: span 2;
}

#request-permission {
    grid-column: span 2;
    background: linear-gradient(135deg, #48bb78, #38a169);
}

#request-permission:hover {
    background: linear-gradient(135deg, #38a169, #2f855a);
    transform: translateY(-2px);
}

/* Video Container */
.video-container {
    position: relative;
    background: #000;
    border-radius: 15px;
    overflow: hidden;
    margin-bottom: 20px;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#camera-stream {
    width: 100%;
    height: auto;
    max-height: 400px;
    object-fit: cover;
}

/* Live Stats Section Titles */
.live-stats h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: #2d3748;
    margin: 25px 0 15px 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 10px;
    border-bottom: 2px solid rgba(102, 126, 234, 0.2);
}

.live-stats h3:first-of-type {
    margin-top: 0;
}

.live-stats h3 i {
    color: #667eea;
    font-size: 1rem;
}

/* Objects by Class */
.objects-by-class,
.live-classes {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.class-item {
    background: rgba(102, 126, 234, 0.1);
    color: #667eea;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    border: 2px solid rgba(102, 126, 234, 0.2);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.class-name {
    flex: 1;
    text-transform: capitalize;
}

.class-count {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.count-detail {
    font-size: 0.75rem;
    color: #667eea;
    opacity: 0.8;
}

.count-total {
    font-size: 0.85rem;
    font-weight: 700;
    color: #764ba2;
}

.class-count {
    background: rgba(102, 126, 234, 0.2);
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.85rem;
}

.no-detections {
    color: #718096;
    font-style: italic;
    text-align: center;
    padding: 20px;
    width: 100%;
}

/* Connection Status */
.connection-status {
    text-align: center;
    padding: 12px;
    border-radius: 10px;
    font-weight: 600;
    background: #f7fafc;
    color: #718096;
    border: 2px solid #e2e8f0;
}

.connection-status.connected {
    background: rgba(72, 187, 120, 0.1);
    color: #48bb78;
    border-color: rgba(72, 187, 120, 0.3);
}

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

.loading-overlay.show {
    display: flex;
}

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

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

.loading-overlay p {
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 15px 25px;
    border-radius: 25px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    z-index: 1001;
    transition: transform 0.3s ease;
    backdrop-filter: blur(10px);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

.toast i {
    font-size: 1.2rem;
}

/* Responsive Design */
@media (max-width: 480px) {
    .container {
        padding: 5px;
    }

    .card {
        padding: 20px;
    }

    .header {
        padding: 12px 15px;
    }

    .header h1 {
        font-size: 1.3rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .camera-controls {
        grid-template-columns: 1fr;
    }

    .camera-controls .btn-warning {
        grid-column: span 1;
    }

    .upload-area {
        padding: 30px 15px;
    }

    .upload-area i {
        font-size: 2.5rem;
    }

    .stat-number {
        font-size: 1.5rem;
    }

    .live-stats h3 {
        font-size: 1rem;
        margin: 20px 0 10px 0;
    }

    .class-item {
        font-size: 0.85rem;
        padding: 6px 12px;
    }
}

/* Landscape Mode */
@media (orientation: landscape) and (max-height: 600px) {
    #camera-stream {
        max-height: 250px;
    }
    
    .video-container {
        min-height: 150px;
    }
}

/* Dark Theme Support */
@media (prefers-color-scheme: dark) {
    .card {
        background: rgba(45, 55, 72, 0.95);
        color: #f7fafc;
    }
    
    .card h2 {
        color: #f7fafc;
    }
    
    .upload-area {
        border-color: #4a5568;
        color: #a0aec0;
    }
    
    .upload-area:hover {
        border-color: #667eea;
    }
}