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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #1a1a2e;
    color: #ffffff;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-content {
    text-align: center;
    padding: 2rem;
}

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

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-content h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.loading-content p {
    font-size: 0.9rem;
    opacity: 0.8;
}

/* Error Screen */
.error-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #1a1a2e;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9998;
}

.error-content {
    text-align: center;
    padding: 2rem;
    max-width: 400px;
}

.error-icon {
    font-size: 4rem;
    display: block;
    margin-bottom: 1rem;
}

.error-content h2 {
    margin-bottom: 1rem;
    color: #ff6b6b;
}

.error-content p {
    margin-bottom: 1.5rem;
    opacity: 0.8;
    line-height: 1.6;
}

/* Main App */
.app {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Camera Container */
.camera-container {
    position: relative;
    flex: 1;
    width: 100%;
    overflow: hidden;
    background: #000;
}

#video {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scaleX(-1);
    min-width: 100%;
    min-height: 100%;
    width: auto;
    height: auto;
    object-fit: cover;
}

#video.rear-camera {
    transform: translate(-50%, -50%) scaleX(1);
}

#canvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
}

.fps-counter {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.6);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: bold;
    font-family: monospace;
    backdrop-filter: blur(10px);
    z-index: 10;
}

.face-indicator {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.6);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: bold;
    backdrop-filter: blur(10px);
    z-index: 10;
    transition: background 0.3s ease;
}

.face-indicator.detected {
    background: rgba(76, 175, 80, 0.6);
}

.face-indicator.not-detected {
    background: rgba(255, 107, 107, 0.6);
}

/* Controls */
.controls {
    background: linear-gradient(to top, #1a1a2e 0%, rgba(26, 26, 46, 0.95) 100%);
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    max-height: 50vh;
    overflow-y: auto;
}

/* Filter Selector */
.filter-selector h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    opacity: 0.8;
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.filter-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid transparent;
    border-radius: 12px;
    padding: 0.75rem 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    min-height: 80px;
}

.filter-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.filter-btn.active {
    background: rgba(102, 126, 234, 0.3);
    border-color: #667eea;
}

.filter-icon {
    font-size: 1.8rem;
}

.filter-name {
    font-size: 0.75rem;
    color: #ffffff;
    text-align: center;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    justify-content: center;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 25px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-width: 48px;
    min-height: 48px;
    position: relative;
}

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

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

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

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    backdrop-filter: blur(10px);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
}

.btn-large {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    flex: 1;
}

.btn-danger {
    background: #ff6b6b;
    color: white;
}

.btn-danger:hover {
    background: #ff5252;
}

.badge {
    background: #ff6b6b;
    color: white;
    border-radius: 10px;
    padding: 0.15rem 0.5rem;
    font-size: 0.75rem;
    font-weight: bold;
    min-width: 20px;
    text-align: center;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: #1a1a2e;
    border-radius: 20px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.btn-close {
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s ease;
}

.btn-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

.modal-body {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: center;
}

/* Gallery */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
}

.empty-gallery {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem 1rem;
    opacity: 0.6;
}

.empty-icon {
    font-size: 4rem;
    display: block;
    margin-bottom: 1rem;
}

.empty-gallery p {
    margin-bottom: 0.5rem;
}

.empty-gallery .small {
    font-size: 0.85rem;
    opacity: 0.7;
}

.gallery-item {
    position: relative;
    aspect-ratio: 3 / 4;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.gallery-item:hover {
    transform: scale(1.05);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-item-actions {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.7), transparent);
}

.gallery-item-btn {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: background 0.3s ease;
}

.gallery-item-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.gallery-item-date {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.5rem;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent);
    font-size: 0.7rem;
    text-align: center;
}

/* No Camera Desktop Message */
.no-camera-desktop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(26, 26, 46, 0.95);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
}

.no-camera-content {
    text-align: center;
    padding: 2rem;
    max-width: 500px;
}

.no-camera-content h2 {
    font-size: 1.8rem;
    margin-bottom: 1rem;
}

.no-camera-content p {
    margin-bottom: 1rem;
    opacity: 0.9;
    line-height: 1.6;
}

.qr-placeholder {
    background: rgba(255, 255, 255, 0.1);
    padding: 1.5rem;
    border-radius: 12px;
    margin: 1.5rem 0;
}

.mobile-url {
    font-family: monospace;
    font-size: 0.9rem;
    color: #667eea;
    word-break: break-all;
}

.hint {
    font-size: 0.85rem;
    opacity: 0.6;
    font-style: italic;
}

/* Footer */
.app-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.75rem 1rem;
    background: rgba(26, 26, 46, 0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    font-size: 0.9rem;
    z-index: 100;
}

.footer-link {
    color: #ffffff;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    transition: color 0.3s ease;
}

.footer-link:hover {
    color: #667eea;
}

.footer-divider {
    opacity: 0.3;
}

/* Adjust app to account for footer */
.app {
    padding-bottom: 45px;
}

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

/* Responsive Design */
@media (max-width: 768px) {
    .filter-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 769px) {
    .app {
        flex-direction: row;
    }
    
    .camera-container {
        width: 70%;
    }
    
    .controls {
        width: 30%;
        max-height: 100vh;
        border-top: none;
        border-left: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .filter-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
    .btn-large {
        width: 100%;
    }
}

/* Touch Improvements */
@media (hover: none) {
    .filter-btn:hover,
    .btn:hover,
    .gallery-item:hover {
        transform: none;
    }
    
    .filter-btn:active {
        transform: scale(0.95);
    }
    
    .btn:active {
        transform: scale(0.98);
    }
}

/* Landscape Mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .controls {
        max-height: 40vh;
    }
    
    .filter-grid {
        grid-template-columns: repeat(8, 1fr);
    }
}
