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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f3f4f6;
    color: #1f2937;
    line-height: 1.6;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
}

/* Header */
.header {
    background: linear-gradient(135deg, #1e3a8a, #3b82f6);
    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;
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.status-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    font-size: 0.875rem;
    flex-wrap: wrap;
}

.connection-status {
    background: rgba(255, 255, 255, 0.2);
    padding: 0.25rem 0.5rem;
    border-radius: 0.5rem;
    backdrop-filter: blur(10px);
}

.pending-count {
    background: #f59e0b;
    padding: 0.25rem 0.5rem;
    border-radius: 0.5rem;
    font-weight: 500;
}

/* Main Layout */
.main {
    max-width: 480px;
    margin: 0 auto;
    padding: 1rem;
    min-height: calc(100vh - 120px);
}

.screen {
    display: none;
}

.screen.active {
    display: block;
}

/* Cards */
.card {
    background: white;
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    margin-bottom: 1rem;
}

.card h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: #1e3a8a;
}

.card p {
    color: #6b7280;
    margin-bottom: 1.5rem;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #374151;
    font-size: 0.875rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #d1d5db;
    border-radius: 0.5rem;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: white;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 48px;
    gap: 0.5rem;
    text-align: center;
    line-height: 1.2;
}

.btn-primary {
    background: #3b82f6;
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
    transform: translateY(-1px);
}

.btn-secondary {
    background: #6b7280;
    color: white;
}

.btn-secondary:hover {
    background: #4b5563;
}

.btn-success {
    background: #10b981;
    color: white;
}

.btn-success:hover {
    background: #059669;
}

.btn-camera {
    background: #8b5cf6;
    color: white;
    width: 100%;
    margin-bottom: 0.5rem;
}

.btn-camera:hover {
    background: #7c3aed;
}

.btn-large {
    padding: 1rem 2rem;
    font-size: 1.125rem;
    width: 100%;
    margin-bottom: 0.75rem;
}

/* Form Actions */
.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.form-actions .btn {
    flex: 1;
    min-width: 120px;
}

/* GPS Info */
.gps-info {
    padding: 0.75rem;
    background: #f3f4f6;
    border-radius: 0.5rem;
    border: 2px dashed #d1d5db;
    text-align: center;
    color: #6b7280;
    font-size: 0.875rem;
}

.gps-info.success {
    background: #ecfdf5;
    border-color: #10b981;
    color: #059669;
}

.gps-info.error {
    background: #fef2f2;
    border-color: #ef4444;
    color: #dc2626;
}

/* Photo Preview */
.photo-preview {
    margin-top: 0.5rem;
}

.photo-preview img {
    width: 100%;
    max-width: 200px;
    border-radius: 0.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.photo-preview .remove-photo {
    display: block;
    margin-top: 0.5rem;
    color: #ef4444;
    font-size: 0.875rem;
    text-decoration: underline;
    cursor: pointer;
}

/* Product Counter */
.product-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.product-counter {
    background: #dbeafe;
    color: #1e40af;
    padding: 0.5rem 1rem;
    border-radius: 1rem;
    font-size: 0.875rem;
    font-weight: 500;
}

/* Products List */
.products-list {
    margin-top: 2rem;
    margin-bottom: 2rem;
}

.product-item {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 0.75rem;
}

.product-item h4 {
    color: #1e3a8a;
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.product-details {
    font-size: 0.875rem;
    color: #6b7280;
    line-height: 1.4;
}

.product-price {
    font-weight: 600;
    color: #059669;
    margin-top: 0.5rem;
}

/* Visit Actions */
.visit-actions {
    border-top: 1px solid #e5e7eb;
    padding-top: 1.5rem;
    margin-top: 1.5rem;
}

.visit-actions .btn {
    margin-bottom: 0.75rem;
}

/* History */
.history-list {
    max-height: 60vh;
    overflow-y: auto;
}

.history-item {
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 0.75rem;
    background: #fafafa;
}

.history-item h4 {
    color: #1e3a8a;
    margin-bottom: 0.5rem;
}

.history-meta {
    font-size: 0.875rem;
    color: #6b7280;
    margin-bottom: 0.5rem;
}

.history-products {
    font-size: 0.875rem;
    color: #374151;
}

.no-data {
    text-align: center;
    color: #9ca3af;
    font-style: italic;
    padding: 2rem;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

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

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f4f6;
    border-top: 4px solid #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

.loading-overlay p {
    color: white;
    font-size: 1.125rem;
    font-weight: 500;
}

/* Success Animation */
.success-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(16, 185, 129, 0.95);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    z-index: 1001;
}

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

.success-animation {
    width: 80px;
    height: 80px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: #059669;
    margin-bottom: 1rem;
    animation: successPulse 0.6s ease-out;
}

@keyframes successPulse {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
        opacity: 1;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.success-overlay p {
    color: white;
    font-size: 1.25rem;
    font-weight: 600;
    text-align: center;
}

/* Camera Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1002;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 1rem;
    padding: 1rem;
    max-width: 90vw;
    max-height: 90vh;
    overflow: hidden;
}

#cameraVideo {
    width: 100%;
    max-width: 300px;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
}

.camera-controls {
    display: flex;
    gap: 0.75rem;
}

.camera-controls .btn {
    flex: 1;
}

/* Responsive Design */
@media (max-width: 480px) {
    .main {
        padding: 0.75rem;
    }
    
    .card {
        padding: 1rem;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .form-actions .btn {
        width: 100%;
    }
    
    .product-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .product-counter {
        align-self: stretch;
        text-align: center;
    }
}

/* Dark mode support for cameras */
@media (prefers-color-scheme: dark) {
    .modal-content {
        background: #1f2937;
        color: white;
    }
}

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

/* High contrast mode */
@media (prefers-contrast: high) {
    .btn {
        border: 2px solid currentColor;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        border-width: 2px;
    }
}

/* Focus visible for better accessibility */
.btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}
/* GPS Toggle Switch */
.gps-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
}
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
    flex-shrink: 0;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc;
    transition: .3s;
    border-radius: 28px;
}
.toggle-slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}
input:checked + .toggle-slider {
    background-color: #10b981;
}
input:checked + .toggle-slider:before {
    transform: translateX(24px);
}
#gpsToggleLabel {
    font-size: 0.9em;
    color: #555;
}
