/* ========================================
   GLOBAL STYLES & VARIABLES
   ======================================== */

:root {
    --primary: #3498db;
    --secondary: #2c3e50;
    --success: #27ae60;
    --warning: #f39c12;
    --danger: #e74c3c;
    --light: #ecf0f1;
    --dark: #2c3e50;
    --gray: #95a5a6;
    --border-radius: 8px;
    --transition: all 0.3s ease;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
}

body.dark-mode {
    --light: #1a1a1a;
    --dark: #ecf0f1;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--light);
    color: var(--dark);
    transition: var(--transition);
}

body.large-font {
    font-size: 18px;
}

/* ========================================
   HEADER
   ======================================== */

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    padding: 20px;
    box-shadow: var(--shadow);
}

.header-content {
    display: flex;
    align-items: center;
    gap: 15px;
}

.header-logo {
    height: 25px;
    width: auto;
    object-fit: contain;
    margin-right: 10px;
    display: inline-block;
}

.header-content h1 {
    font-size: 28px;
    margin-bottom: 0;
    display: inline-block;
    vertical-align: middle;
}

.header-logo + h1 {
    margin-left: 0;
}

.header-content .subtitle {
    font-size: 14px;
    opacity: 0.9;
    margin-top: 5px;
}

.btn-settings {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 16px;
    transition: var(--transition);
}

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

/* ========================================
   MAIN CONTENT LAYOUT
   ======================================== */

.main-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    padding: 20px;
    overflow: hidden;
}

/* Tab Navigation */
.tab-navigation {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--light);
}

.tab-btn {
    padding: 12px 20px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-weight: 600;
    color: var(--gray);
    transition: var(--transition);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-btn:hover {
    color: var(--secondary);
}

/* Tab Content */
.tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
}

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

.tab-content.active .panel-scanner,
.tab-content.active .panel-history {
    flex: 1;
}

.panel {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 20px;
    overflow-y: auto;
    transition: var(--transition);
}

body.dark-mode .panel {
    background: #2d2d2d;
    box-shadow: var(--shadow);
}
.panel-scanner {
    flex: 1;
}

.panel-history {
    flex: 1;
}

.panel-settings {
    flex: 1;
    max-width: 800px;
}

/* ========================================
   SECTIONS
   ======================================== */

section h2 {
    margin-bottom: 20px;
    font-size: 20px;
    color: var(--secondary);
}

body.dark-mode section h2 {
    color: var(--light);
}

.section-help {
    font-size: 13px;
    color: var(--gray);
    margin-bottom: 15px;
}

/* ========================================
   CSV STATUS & INPUT
   ======================================== */

.csv-status {
    background: #fff3cd;
    border: 2px solid #ffc107;
    border-radius: var(--border-radius);
    padding: 15px;
    margin-bottom: 20px;
    text-align: center;
}

.csv-status.loaded {
    background: #d4edda;
    border-color: #28a745;
}

.status-text {
    font-weight: bold;
    margin-bottom: 5px;
}

.status-help {
    font-size: 12px;
    color: #666;
}

.csv-status.loaded .status-help {
    display: none;
}

.input-group {
    margin-bottom: 20px;
}

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

body.dark-mode .input-group label {
    color: var(--light);
}

.scan-input {
    width: 100%;
    padding: 14px;
    border: 2px solid #e0e0e0;
    border-radius: var(--border-radius);
    font-size: 16px;
    transition: var(--transition);
    font-weight: 600;
}

.scan-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.scan-input:disabled {
    background: #f5f5f5;
    color: #999;
    cursor: not-allowed;
}

.input-help {
    font-size: 12px;
    color: var(--gray);
    margin-top: 8px;
}

/* ========================================
   ITEM DISPLAY
   ======================================== */

.item-display {
    background: #f8f9fa;
    border-radius: var(--border-radius);
    border: 2px solid #e0e0e0;
    padding: 20px;
    margin: 20px 0;
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

body.dark-mode .item-display {
    background: #3d3d3d;
    border-color: #555;
}

.placeholder {
    text-align: center;
    color: var(--gray);
}

.item-display.active {
    background: #f0f7ff;
    border-color: var(--primary);
}

body.dark-mode .item-display.active {
    background: #1a3a4a;
}

.item-content {
    width: 100%;
}

.item-name {
    font-size: 22px;
    font-weight: bold;
    color: var(--primary);
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--primary);
}

.item-field {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #e0e0e0;
    font-size: 14px;
}

body.dark-mode .item-field {
    border-bottom-color: #555;
}

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

.field-label {
    font-weight: 600;
    color: var(--secondary);
}

body.dark-mode .field-label {
    color: #ccc;
}

.field-value {
    color: var(--gray);
    text-align: right;
    flex: 1;
    margin-left: 20px;
    word-break: break-word;
}

/* ========================================
   BUTTONS
   ======================================== */

.button-group {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.button-group-top {
    margin-top: 0;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.button-group-top .btn {
    flex: 1;
    min-width: 120px;
}

.button-group-vertical {
    flex-direction: column;
}

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    flex: 1;
    text-align: center;
}

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

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #2980b9;
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background: var(--secondary);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #1a252f;
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: #229954;
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-warning {
    background: var(--warning);
    color: white;
}

.btn-warning:hover:not(:disabled) {
    background: #e67e22;
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-close {
    background: transparent;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--gray);
    transition: var(--transition);
    padding: 0;
    width: 30px;
    height: 30px;
}

.btn-close:hover {
    color: var(--dark);
}

/* ========================================
   STATUS MESSAGE
   ======================================== */

.status-message {
    margin-top: 15px;
    padding: 12px;
    border-radius: var(--border-radius);
    font-size: 14px;
    text-align: center;
    display: none;
}

.status-message.show {
    display: block;
}

.status-message.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.status-message.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.status-message.warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
}

/* ========================================
   HISTORY SECTION
   ======================================== */

.history-stats {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: var(--border-radius);
}

body.dark-mode .history-stats {
    background: #3d3d3d;
}

.stat-item {
    flex: 1;
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 12px;
    color: var(--gray);
    margin-bottom: 5px;
}

.stat-value {
    display: block;
    font-size: 24px;
    font-weight: bold;
    color: var(--primary);
}

.history-list {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid #e0e0e0;
    border-radius: var(--border-radius);
    padding: 10px;
    margin-bottom: 20px;
}

body.dark-mode .history-list {
    border-color: #555;
}

.empty-message {
    text-align: center;
    color: var(--gray);
    padding: 30px 10px;
    font-size: 14px;
}

.history-item {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: var(--border-radius);
    padding: 12px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    transition: var(--transition);
}

body.dark-mode .history-item {
    background: #2d2d2d;
    border-color: #555;
}

.history-item:hover {
    background: #f0f7ff;
    border-color: var(--primary);
}

body.dark-mode .history-item:hover {
    background: #3a3a3a;
}

.history-item-code {
    font-weight: bold;
    color: var(--primary);
}

.history-item-name {
    display: block;
    color: var(--gray);
    font-size: 12px;
    margin-top: 3px;
}

.history-item-time {
    color: var(--gray);
    font-size: 12px;
    white-space: nowrap;
}

.history-item-remove {
    background: transparent;
    border: none;
    color: var(--danger);
    cursor: pointer;
    padding: 0;
    margin-left: 10px;
    font-size: 16px;
    transition: var(--transition);
}

.history-item-remove:hover {
    color: #c0392b;
}

/* ========================================
   MODAL
   ======================================== */

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideIn 0.3s ease;
}

.camera-result {
    margin-top: 12px;
    display: flex;
    gap: 8px;
    align-items: center;
    font-weight: 600;
}

.camera-result-value {
    font-family: 'Menlo', 'Courier New', monospace;
    color: var(--primary);
}

body.dark-mode .modal-content {
    background: #2d2d2d;
}

@keyframes slideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

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

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

body.dark-mode .modal-header {
    border-bottom-color: #555;
}

.modal-header h2 {
    margin: 0;
    font-size: 20px;
    color: var(--secondary);
}

body.dark-mode .modal-header h2 {
    color: var(--light);
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

body.dark-mode .modal-footer {
    border-top-color: #555;
}

/* ========================================
   SETTINGS
   ======================================== */

.settings-section {
    margin-bottom: 25px;
}

.settings-section h3 {
    font-size: 16px;
    color: var(--secondary);
    margin-bottom: 10px;
}

body.dark-mode .settings-section h3 {
    color: var(--light);
}

.info-box {
    background: #d4edda;
    border: 1px solid #c3e6cb;
    border-radius: var(--border-radius);
    padding: 15px;
    margin-bottom: 15px;
    font-size: 13px;
}

.info-box p {
    margin: 5px 0;
}

.info-box.hidden {
    display: none;
}

.file-input {
    display: block;
    width: 100%;
    padding: 10px;
    border: 2px dashed #3498db;
    border-radius: var(--border-radius);
    background: #f0f7ff;
    cursor: pointer;
    margin: 15px 0;
    font-size: 14px;
}

body.dark-mode .file-input {
    background: #1a3a4a;
}

.file-input::-webkit-file-upload-button {
    padding: 8px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    margin-right: 10px;
}

.error-text {
    color: var(--danger);
    font-size: 13px;
    margin-top: 8px;
    display: none;
}

.error-text.show {
    display: block;
}

.success-text {
    color: var(--success);
    font-size: 13px;
    margin-top: 8px;
    display: none;
}

.success-text.show {
    display: block;
}

.cache-stats {
    background: #f8f9fa;
    border-radius: var(--border-radius);
    padding: 15px;
    margin-bottom: 15px;
    font-size: 14px;
}

body.dark-mode .cache-stats {
    background: #3d3d3d;
}

.cache-stats p {
    margin: 8px 0;
}

.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.checkbox {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 14px;
}

.checkbox input {
    margin-right: 10px;
    cursor: pointer;
    width: 18px;
    height: 18px;
}

.info-text {
    background: #f0f7ff;
    border: 1px solid #b3d9ff;
    border-radius: var(--border-radius);
    padding: 15px;
    font-size: 13px;
}

body.dark-mode .info-text {
    background: #1a3a4a;
    border-color: #555;
}

.info-text p {
    margin: 8px 0;
}

.info-text .small {
    font-size: 12px;
    color: var(--gray);
}

.divider {
    border: none;
    border-top: 1px solid #e0e0e0;
    margin: 20px 0;
}

body.dark-mode .divider {
    border-top-color: #555;
}

/* ========================================
   EXPORT OPTIONS
   ======================================== */

.export-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 15px;
}

.export-option {
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: var(--border-radius);
    padding: 15px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 15px;
    text-align: left;
}

body.dark-mode .export-option {
    background: #3d3d3d;
    border-color: #555;
}

.export-option:hover {
    border-color: var(--primary);
    background: #f0f7ff;
}

body.dark-mode .export-option:hover {
    background: #1a3a4a;
}

.export-icon {
    font-size: 24px;
}

.export-text {
    font-weight: 600;
    color: var(--secondary);
    font-size: 15px;
}

body.dark-mode .export-text {
    color: var(--light);
}

.export-desc {
    font-size: 12px;
    color: var(--gray);
    display: block;
    width: 100%;
}

/* ========================================
   NOTIFICATION
   ======================================== */

.notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--success);
    color: white;
    padding: 15px 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    animation: slideInUp 0.3s ease;
    display: none;
}

.notification.show {
    display: block;
}

@keyframes slideInUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.notification.error {
    background: var(--danger);
}

.notification.warning {
    background: var(--warning);
}

.notification.info {
    background: var(--primary);
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 1024px) {
    .main-content {
        flex-direction: column;
    }

    .panel-history {
        width: 100%;
    }
}

@media (max-width: 768px) {
    .header {
        flex-direction: column;
        text-align: center;
    }

    .header-content h1 {
        font-size: 22px;
    }

    .main-content {
        padding: 10px;
        gap: 10px;
    }

    .panel {
        padding: 15px;
    }

    .history-list {
        max-height: 250px;
    }
}

@media (max-width: 480px) {
    .header-content h1 {
        font-size: 18px;
    }

    .header-content .subtitle {
        display: none;
    }

    .item-field {
        flex-direction: column;
    }

    .history-item-time {
        margin-top: 5px;
    }

    .button-group {
        flex-direction: column;
    }

    .button-group-top {
        flex-direction: row;
    }

    /* Keep history buttons horizontal */
    .history-section .button-group {
        flex-direction: row;
    }

    .modal-content {
        width: 95%;
    }
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
    .header,
    .btn-settings,
    .button-group {
        display: none;
    }

    .main-content {
        flex-direction: column;
    }

    .panel {
        box-shadow: none;
        page-break-inside: avoid;
    }
}

/* ========================================
   CAMERA SCANNER
   ======================================== */

.scan-input-group {
    display: flex;
    gap: 10px;
}

.scan-input-group input {
    flex: 1;
}

.scan-input-group .btn {
    padding: 10px 16px;
    font-size: 14px;
    white-space: nowrap;
}

.camera-video {
    width: 100%;
    max-width: 100%;
    height: 300px;
    border-radius: var(--border-radius);
    object-fit: cover;
    background: #000;
}

#cameraStatus {
    text-align: center;
    margin-top: 15px;
    padding: 10px;
    border-radius: var(--border-radius);
    background: rgba(52, 152, 219, 0.1);
    color: var(--primary);
    font-size: 14px;
}

#cameraStatus.error {
    background: rgba(231, 76, 60, 0.1);
    color: var(--danger);
}

#cameraStatus.success {
    background: rgba(39, 174, 96, 0.1);
    color: var(--success);
}

.camera-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    justify-content: center;
}

.camera-actions .btn {
    flex: 1;
    max-width: 300px;
}

/* ========================================
   DEBUG PANEL
   ======================================== */

.debug-show-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 8px 12px;
    background: var(--secondary);
    color: var(--light);
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 12px;
    z-index: 999;
    box-shadow: var(--shadow-lg);
}

.debug-show-btn.hidden {
    display: none;
}

.debug-show-btn:active {
    transform: scale(0.95);
}

.debug-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 90vw;
    max-width: 500px;
    max-height: 50vh;
    background: var(--secondary);
    border: 1px solid var(--gray);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    color: var(--light);
    font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
    font-size: 11px;
}

.debug-panel.hidden {
    display: none;
}

/* Hide debug when disabled in settings */
.debug-disabled .debug-panel,
.debug-disabled .debug-show-btn {
    display: none !important;
}

.debug-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.2);
}

.debug-title {
    flex: 1;
    font-weight: bold;
    font-size: 12px;
}

.debug-toggle-btn,
.debug-clear-btn {
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--light);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
}

.debug-toggle-btn:active,
.debug-clear-btn:active {
    background: rgba(255, 255, 255, 0.2);
}

.debug-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.debug-message {
    padding: 4px;
    background: rgba(0, 0, 0, 0.1);
    border-left: 2px solid var(--primary);
    word-break: break-word;
    line-height: 1.4;
}

.debug-message.empty {
    color: var(--gray);
    border-left-color: var(--gray);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
}

.debug-message.error {
    border-left-color: var(--danger);
    color: #ff6b6b;
}

.debug-message.success {
    border-left-color: var(--success);
    color: #51cf66;
}

.debug-message.warning {
    border-left-color: var(--warning);
    color: #ffd43b;
}


