/* 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: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    overflow-x: hidden;
    
}

.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    max-width: 100%;
    margin: 0 auto;
}

/* PWA Install Banner */
.pwa-banner {
    background: #ff6b35;
    color: white;
    padding: 12px 20px;
    text-align: center;
    border-radius: 8px 8px 0 0;
    margin-bottom: 0;
}

.pwa-banner-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 600px;
    margin: 0 auto;
}

.btn-install {
    background: white;
    color: #ff6b35;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-install:hover {
    background: #f0f0f0;
    transform: translateY(-1px);
}

/* Main Card Container */
.main-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    overflow: hidden;
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

/* Card Header */
.card-header {
    background: linear-gradient(135deg, #2196F3, #21CBF3);
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
}

.header-icon {
    font-size: 2rem;
    background: rgba(255,255,255,0.2);
    padding: 10px;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-text h1 {
    font-size: 1.5rem;
    margin: 0;
    font-weight: 600;
}

.header-text p {
    font-size: 0.9rem;
    margin: 5px 0 0 0;
    opacity: 0.9;
}

/* Camera Section */
.camera-section {
    padding: 20px;
}

.camera-preview {
    width: 105mm;   /* 210mm / 2 */
    height: 148.5mm;
    max-width: 100vw;
    max-height: 100vh;
    margin: 0 auto;
    background: #222;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0,0,0,0.2);
    aspect-ratio: 16/9;
    display: flex;
    align-items: center;
    justify-content: center;
}

.camera-preview video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Header Styles */
.app-header {
    background: linear-gradient(135deg, #2196F3, #21CBF3);
    color: white;
    padding: 1rem;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-header h1 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
    font-weight: 600;
}

.app-header p {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* GCN Section */
.gcn-section {
    margin-top: 20px;
}

.gcn-input {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
    position: relative;
}

.gcn-input input[type="text"] {
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    text-align: center;
    width: 100%;
    max-width: 300px;
    background-color: #f9f9f9;
    transition: all 0.3s ease;
}

.gcn-input input[type="text"]:focus {
    border-color: #2196F3;
    outline: none;
    background-color: white;
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.gcn-input input[type="text"]:not(:read-only) {
    border-color: #2196F3;
    background-color: white;
}

.gcn-input input[type="text"]:not(:read-only):focus {
    border-color: #2196F3;
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #666;
    font-size: 0.9rem;
    cursor: pointer;
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    display: none;
}

.checkmark {
    width: 20px;
    height: 20px;
    border: 2px solid #ddd;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    background: white;
}

.checkbox-label input[type="checkbox"]:checked + .checkmark {
    background: #2196F3;
    border-color: #2196F3;
}

.checkbox-label input[type="checkbox"]:checked + .checkmark::after {
    content: "✓";
    color: white;
    font-weight: bold;
    font-size: 12px;
}

/* Save button in GCN section */
.gcn-input .btn-save {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    margin-top: 0;
}

/* Ensure all buttons are perfectly round */
.btn, .btn-switch, .btn-capture, .btn-save, .btn-secondary {
    border-radius: 50% !important;
    aspect-ratio: 1;
    overflow: hidden;
}

.back-btn {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: white;
    text-decoration: none;
    font-size: 1.2rem;
    font-weight: bold;
    padding: 0.5rem;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
}

.back-btn:hover {
    background: rgba(255,255,255,0.3);
    color: white;
    text-decoration: none;
}

/* Main Content */
.app-main {
    flex: 1;
    padding: 1.5rem;
}

.welcome-card {
    background: white;
    border-radius: 15px;
    padding: 2rem;
    text-align: center;
    margin-bottom: 2rem;
    box-shadow: 0 5px 20px rgba(0,0,0,0.1);
}

.welcome-card h2 {
    color: #2196F3;
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

/* Action Buttons */
.action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 1rem 1.5rem;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    min-height: 60px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

.btn-primary {
    background: linear-gradient(135deg, #2196F3, #21CBF3);
    color: white;
    box-shadow: 0 4px 15px rgba(33, 150, 243, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(33, 150, 243, 0.4);
}

.btn-secondary {
    background: linear-gradient(135deg, #6c757d, #868e96);
    color: white;
    box-shadow: 0 4px 15px rgba(108, 117, 125, 0.3);
}

.btn-secondary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(108, 117, 125, 0.4);
}

.btn-large {
    font-size: 1.1rem;
    padding: 1.25rem 2rem;
}

.btn-capture {
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
    font-size: 1.2rem;
    padding: 1.5rem;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    box-shadow: 0 8px 25px rgba(76, 175, 80, 0.4);
    border: 4px solid rgba(255,255,255,0.3);
    transition: all 0.2s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn-capture:hover,
.btn-capture:active {
    transform: scale(1.05);
    box-shadow: 0 10px 30px rgba(76, 175, 80, 0.6);
    border-color: rgba(255,255,255,0.5);
}

.btn-capture:active {
    transform: scale(0.95);
}

/* Features Grid */
.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 2rem;
}

.feature-item {
    text-align: center;
    padding: 1.5rem 1rem;
    background: white;
    border-radius: 12px;
    box-shadow: 0 3px 15px rgba(0,0,0,0.1);
}

.feature-icon {
    font-size: 2rem;
    display: block;
    margin-bottom: 0.5rem;
}

.feature-item h3 {
    color: #2196F3;
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.feature-item p {
    color: #666;
    font-size: 0.85rem;
    line-height: 1.4;
}

/* Camera Controls */
.camera-controls {
    display: flex;
    gap: 20px;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    border-radius: 50%;
    font-size: 1.2rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    width: 50px;
    height: 50px;
    min-width: 50px;
    min-height: 50px;
    max-width: 50px;
    max-height: 50px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    gap: 0;
    flex-shrink: 0;
}

.btn-icon {
    font-size: 1.1rem;
}

.btn-switch {
    background: #6c757d;
    color: white;
    box-shadow: 0 2px 8px rgba(108, 117, 125, 0.3);
}

.btn-switch:hover {
    background: #5a6268;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(108, 117, 125, 0.4);
}

.btn-capture {
    background: #2196F3;
    color: white;
    box-shadow: 0 2px 8px rgba(33, 150, 243, 0.3);
    width: 50px;
    height: 50px;
    min-width: 50px;
    min-height: 50px;
    max-width: 50px;
    max-height: 50px;
    font-size: 1.4rem;
}

.btn-capture:hover {
    background: #1976D2;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.4);
}

.btn-save {
    background: #4CAF50;
    color: white;
    box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
    display: none; /* Initially hidden */
}

.btn-upload {
    background: #FF9800;
    color: white;
    box-shadow: 0 2px 8px rgba(255, 152, 0, 0.3);
    width: 50px;
    height: 50px;
    min-width: 50px;
    min-height: 50px;
    max-width: 50px;
    max-height: 50px;
    font-size: 1.4rem;
}

.btn-upload:hover {
    background: #F57C00;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 152, 0, 0.4);
}

.btn-save:hover {
    background: #45a049;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.4);
}

/* Ensure retake button is initially hidden */
#retakeBtn {
    display: none;
}

.btn-secondary {
    background: #6c757d;
    color: white;
    box-shadow: 0 2px 8px rgba(108, 117, 125, 0.3);
}

.btn-secondary:hover {
    background: #5a6268;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(108, 117, 125, 0.4);
}

.camera-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.capture-frame {
    width: 85%;
    height: 70%;
    position: relative;
    border: 3px solid rgba(255,255,255,0.9);
    border-radius: 16px;
    box-shadow: 0 0 20px rgba(255,255,255,0.3);
}

.corner {
    position: absolute;
    width: 24px;
    height: 24px;
    border: 4px solid #4CAF50;
}

.corner.top-left {
    top: -4px;
    left: -4px;
    border-right: none;
    border-bottom: none;
    border-radius: 8px 0 0 0;
}

.corner.top-right {
    top: -4px;
    right: -4px;
    border-left: none;
    border-bottom: none;
    border-radius: 0 8px 0 0;
}

.corner.bottom-left {
    bottom: -4px;
    left: -4px;
    border-right: none;
    border-top: none;
    border-radius: 0 0 0 8px;
}

.corner.bottom-right {
    bottom: -4px;
    right: -4px;
    border-left: none;
    border-top: none;
    border-radius: 0 0 8px 0;
}

.capture-controls {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 1.5rem;
    align-items: center;
    z-index: 10;
}

/* Preview Container */
#previewImage {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;  /* always fit inside */
    border-radius: 8px;
    margin-bottom: 20px;
}


#previewImage {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    margin-bottom: 20px;
    z-index: 100000;
    position: relative;
}

.preview-actions {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    z-index: 100000;
    position: relative;
}

/* Ensure preview container is always on top */
.preview-container * {
    z-index: 100000 !important;
    position: relative;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal-content {
    background: white;
    border-radius: 15px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    color: #2196F3;
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
    padding: 0.25rem;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    background: #f5f5f5;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid #eee;
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

/* Form Styles */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #333;
}

.form-control {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.form-control:focus {
    outline: none;
    border-color: #2196F3;
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.form-control:invalid {
    border-color: #f44336;
}

/* Gallery Styles */
.gallery-container {
    flex: 1;
    padding: 1rem;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
}

.gallery-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.3s ease;
    box-shadow: 0 3px 15px rgba(0,0,0,0.1);
}

.gallery-item:hover {
    transform: scale(1.05);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.gallery-item:hover .gallery-overlay {
    opacity: 1;
}

.view-icon {
    font-size: 2rem;
    color: white;
}

.empty-gallery {
    text-align: center;
    padding: 3rem 1rem;
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-gallery h3 {
    color: #666;
    margin-bottom: 0.5rem;
}

.empty-gallery p {
    color: #999;
    margin-bottom: 2rem;
}

/* Image Viewer */
.image-viewer {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 1rem;
}

.image-viewer-content {
    position: relative;
    max-width: 100%;
    max-height: 100%;
}

.image-viewer-content img {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 8px;
}

.image-info {
    text-align: center;
    color: white;
    margin-top: 1rem;
}

/* Loading Styles */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    color: white;
}

.loading-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-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Footer */
.app-footer {
    background: #f8f9fa;
    padding: 1rem;
    text-align: center;
    color: #666;
    font-size: 0.9rem;
}

/* Mobile-First Responsive Design */
@media (max-width: 768px) {
    .app-container {
        min-height: 100vh;
        height: 100vh;
    }
    
    .camera-container {
        height: 100vh;
        min-height: 100vh;
    }
    
    .camera-controls {
        top: 0.5rem;
        right: 0.5rem;
        padding: 0.75rem;
    }
    
    .camera-switch button {
        padding: 0.75rem;
        font-size: 0.9rem;
        min-height: 50px;
    }
    
    .capture-controls {
        bottom: 1.5rem;
        gap: 2rem;
    }
    
    .btn-capture {
        width: 100px;
        height: 100px;
        font-size: 1.4rem;
    }
    
    .btn-upload {
        width: 100px;
        height: 100px;
        font-size: 1.4rem;
    }
    
    .btn-secondary {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
        min-height: 50px;
    }
    
    .preview-container {
        padding: 1rem;
    }
    
    .preview-actions {
        gap: 1rem;
        margin-top: -1.5rem;
    }
    
    .preview-actions .btn {
        width: 50px;
        height: 50px;
        min-width: 50px;
        min-height: 50px;
        max-width: 50px;
        max-height: 50px;
        font-size: 1.2rem;
    }
}

@media (max-width: 480px) {
    .app-header {
        padding: 0.75rem;
    }
    
    .app-header h1 {
        font-size: 1.25rem;
    }
    
    .app-header p {
        font-size: 0.8rem;
    }
    
    .camera-controls {
        top: 0.25rem;
        right: 0.25rem;
        padding: 0.5rem;
    }
    
    .camera-switch button {
        padding: 0.5rem;
        font-size: 0.8rem;
        min-height: 45px;
    }
    
    #cameraStatus {
        font-size: 0.7rem;
    }
    
    .capture-frame {
        width: 90%;
        height: 65%;
    }
    
    .corner {
        width: 20px;
        height: 20px;
        border-width: 3px;
    }
    
    .capture-controls {
        bottom: 1rem;
        gap: 1.5rem;
    }
    
    .btn-capture {
        width: 85px;
        height: 85px;
        font-size: 1.2rem;
    }
    
    .btn-upload {
        width: 85px;
        height: 85px;
        font-size: 1.2rem;
    }
    
    .btn-secondary {
        padding: 0.6rem 0.8rem;
        font-size: 0.85rem;
        min-height: 45px;
    }
    
    .preview-actions .btn {
        width: 45px;
        height: 45px;
        min-width: 45px;
        min-height: 45px;
        max-width: 45px;
        max-height: 45px;
        font-size: 1.1rem;
    }
}

/* Landscape orientation for mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .camera-container {
        height: 100vh;
    }
    
    .capture-controls {
        bottom: 0.5rem;
    }
    
    .btn-capture {
        width: 70px;
        height: 70px;
        font-size: 1rem;
    }
    
    .btn-upload {
        width: 70px;
        height: 70px;
        font-size: 1rem;
    }
    
    .capture-frame {
        width: 80%;
        height: 80%;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .btn:hover {
        transform: none;
    }
    
    .btn:active {
        transform: scale(0.95);
        opacity: 0.8;
    }
    
    .btn-capture:active {
        transform: scale(0.9);
    }
}

/* PWA specific styles */
@media (display-mode: standalone) {
    .app-header {
        padding-top: calc(1rem + env(safe-area-inset-top));
    }
    
    .app-container {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    body {
        background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    }
    
    .app-container {
        background: #1a1a1a;
        color: #fff;
    }
    
    .welcome-card,
    .feature-item,
    .modal-content {
        background: #2d2d2d;
        color: #fff;
    }
    
    .form-control {
        background: #3d3d3d;
        border-color: #555;
        color: #fff;
    }
    
    .form-control:focus {
        border-color: #2196F3;
    }
}
