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

:root {
    --primary-color: #4a90e2;
    --success-color: #4caf50;
    --error-color: #f44336;
    --warning-color: #ff9800;
    --bg-color: #f5f5f5;
    --surface-color: #ffffff;
    --text-primary: #212121;
    --text-secondary: #757575;
    --border-color: #e0e0e0;
    --shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 8px rgba(0, 0, 0, 0.15);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header Styles */
.header {
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
    z-index: 100;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    font-size: 24px;
}

.app-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.status-indicator {
    font-size: 14px;
    color: var(--text-secondary);
}

.status-text {
    padding: 4px 8px;
    border-radius: 4px;
    background-color: var(--bg-color);
}

.status-text.offline {
    background-color: var(--warning-color);
    color: white;
}

.settings-button {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.settings-button:hover {
    background-color: var(--bg-color);
}

.settings-button:active {
    background-color: var(--border-color);
}

/* Main Content Layout */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* Camera Container */
.camera-container {
    flex: 1;
    position: relative;
    background-color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 30vh;
    max-height: 40vh;
}

#videoElement {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background-color: #000;
}

/* QuaggaJS video element styling - when Quagga creates its own video */
#cameraContainer video {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
    position: absolute;
    top: 0;
    left: 0;
}

/* Hide QuaggaJS canvas overlays */
#cameraContainer canvas.drawingBuffer {
    display: none !important;
}

#canvasElement {
    display: none;
}

.scan-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Scanning frame - visual guide */
.scan-frame {
    width: 70%;
    max-width: 400px;
    aspect-ratio: 1.5;
    border: 3px solid rgba(255, 255, 255, 0.8);
    border-radius: 8px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    position: relative;
    pointer-events: none;
}

.scan-frame::before,
.scan-frame::after {
    content: '';
    position: absolute;
    width: 30px;
    height: 30px;
    border: 3px solid var(--primary-color);
}

.scan-frame::before {
    top: -3px;
    left: -3px;
    border-right: none;
    border-bottom: none;
}

.scan-frame::after {
    bottom: -3px;
    right: -3px;
    border-left: none;
    border-top: none;
}

.scan-frame-label {
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    color: white;
    font-size: 14px;
    font-weight: 600;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    white-space: nowrap;
}

.feedback-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    opacity: 0;
}

.feedback-overlay.success {
    background-color: rgba(76, 175, 80, 0.3);
    opacity: 1;
}

.feedback-overlay.error {
    background-color: rgba(244, 67, 54, 0.3);
    opacity: 1;
}

.camera-status {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    text-align: center;
    background-color: rgba(0, 0, 0, 0.7);
    padding: 16px 24px;
    border-radius: 8px;
    z-index: 10;
}

.camera-status.error {
    background-color: rgba(244, 67, 54, 0.9);
}

/* Product List Panel */
.list-panel {
    width: 100%;
    max-width: 40%;
    min-width: 300px;
    background-color: var(--surface-color);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    z-index: 1;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), 
                max-width 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                top 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                left 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                right 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                bottom 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Expanded state for mobile */
.list-panel.expanded {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    max-width: 100%;
    width: 100%;
    z-index: 1000;
    border-left: none;
    transform: translateY(0);
}

.list-panel.expanded ~ .camera-container {
    display: none;
}

.list-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.list-header h2 {
    font-size: 18px;
    font-weight: 600;
    flex: 1;
}

.collapse-button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 36px;
    transition: background-color 0.2s, opacity 0.3s ease;
    opacity: 1;
}

.collapse-button:hover {
    background-color: #357abd;
}

.collapse-button:active {
    background-color: #2a5f8f;
}

.collapse-button span {
    font-size: 16px;
}

.list-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
}

.empty-state {
    padding: 48px 24px;
    text-align: center;
    color: var(--text-secondary);
}

.empty-hint {
    font-size: 14px;
    margin-top: 8px;
}

.product-table {
    width: 100%;
    border-collapse: collapse;
}

.product-table thead {
    position: sticky;
    top: 0;
    background-color: var(--surface-color);
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.product-table th {
    padding: 12px 8px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    border-bottom: 2px solid var(--border-color);
}

.product-table th:first-child {
    padding-left: 16px;
}

.product-table th:last-child {
    padding-right: 16px;
}

.product-table td {
    padding: 12px 8px;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
}

.product-table td:first-child {
    padding-left: 16px;
}

.product-table td:last-child {
    padding-right: 16px;
}

.product-table tbody tr:hover {
    background-color: var(--bg-color);
}

.product-table tbody tr.highlight {
    background-color: rgba(76, 175, 80, 0.1);
    transition: background-color 0.5s;
}

.product-code {
    font-family: 'Courier New', monospace;
    font-size: 13px;
    word-break: break-all;
}

.quantity-input {
    width: 80px;
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
    text-align: right;
    font-family: inherit;
}

.quantity-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2);
}

.quantity-input.invalid {
    border-color: var(--error-color);
}

.quantity-warning {
    font-size: 11px;
    color: var(--error-color);
    margin-top: 4px;
    display: none;
}

.quantity-warning.show {
    display: block;
    animation: fadeIn 0.2s;
}

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

.last-scanned {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    min-width: 140px;
}

.delete-button {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    color: var(--error-color);
    transition: background-color 0.2s;
}

.delete-button:hover {
    background-color: var(--bg-color);
}

.delete-button:active {
    background-color: var(--border-color);
}

.list-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-color);
    flex-shrink: 0;
}

.summary-stats {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    color: var(--text-secondary);
}

.summary-stats strong {
    color: var(--text-primary);
    font-weight: 600;
}

.submit-section {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.submit-button {
    width: 100%;
    padding: 16px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
    transition: background-color 0.2s, opacity 0.2s;
}

.submit-button:hover:not(:disabled) {
    background-color: #357abd;
}

.submit-button:active:not(:disabled) {
    background-color: #2a5f8f;
}

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

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
}

.modal-content {
    background-color: var(--surface-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    padding: 4px 8px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    color: var(--text-secondary);
    transition: background-color 0.2s;
}

.modal-close:hover {
    background-color: var(--bg-color);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    flex-shrink: 0;
}

.setting-group {
    margin-bottom: 24px;
}

.setting-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.setting-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
}

.setting-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2);
}

.radio-group {
    display: flex;
    gap: 16px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: normal;
}

.radio-label input[type="radio"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.toggle-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
}

.toggle-switch {
    position: relative;
    width: 50px;
    height: 26px;
    appearance: none;
    background-color: #ccc;
    border-radius: 13px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.toggle-switch:checked {
    background-color: var(--primary-color);
}

.toggle-switch::before {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background-color: white;
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch:checked::before {
    transform: translateX(24px);
}

.submission-summary {
    margin-bottom: 20px;
}

.submission-summary p {
    margin-bottom: 8px;
    font-size: 16px;
}

.submission-preview {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 12px;
}

.preview-item {
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
}

.preview-item:last-child {
    border-bottom: none;
}

.preview-more {
    text-align: center;
    padding: 12px;
    color: var(--text-secondary);
    font-size: 14px;
}

.button-primary {
    padding: 10px 20px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
    transition: background-color 0.2s;
}

.button-primary:hover {
    background-color: #357abd;
}

.button-secondary {
    padding: 10px 20px;
    background-color: var(--bg-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
    transition: background-color 0.2s;
}

.button-secondary:hover {
    background-color: var(--border-color);
}

.message-modal {
    max-width: 400px;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    color: white;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

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

.loading-overlay p {
    font-size: 16px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }

    .list-panel {
        max-width: 100%;
        min-width: 100%;
        max-height: 50vh;
        border-left: none;
        border-top: 2px solid var(--border-color);
        transform: translateY(0);
    }

    .list-panel.expanded {
        max-height: 100vh;
        border-top: none;
        transform: translateY(0);
    }

    .camera-container {
        max-height: 50vh;
        min-height: 30vh;
        transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1), 
                    transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .list-panel.expanded ~ .camera-container {
        opacity: 0;
        transform: translateY(-20px);
        pointer-events: none;
    }

    .list-header {
        cursor: grab;
        user-select: none;
        -webkit-user-select: none;
        position: relative;
        padding-right: 60px; /* Make room for arrow when button is hidden */
    }

    .list-panel.expanded .list-header {
        padding-right: 16px; /* Normal padding when button is visible */
    }

    .list-header::after {
        content: '⬆️';
        position: absolute;
        right: 16px;
        top: 50%;
        transform: translateY(-50%);
        font-size: 20px;
        transition: opacity 0.3s ease, transform 0.3s ease;
        pointer-events: none;
    }

    .list-panel.expanded .list-header::after {
        opacity: 0; /* Hide arrow when expanded */
        transform: translateY(-50%) rotate(180deg);
    }

    .list-header:active {
        cursor: grabbing;
    }

    .collapse-button {
        transition: opacity 0.3s ease, transform 0.3s ease;
    }

    .list-panel:not(.expanded) .collapse-button {
        display: none !important;
    }
}

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

