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

:root {
    --primary: #059669;
    --primary-dark: #047857;
    --secondary: #64748B;
    --success: #10B981;
    --danger: #EF4444;
    --warning: #F59E0B;
    --bg: #F8FAFC;
    --card-bg: #FFFFFF;
    --text: #1E293B;
    --text-light: #64748B;
    --border: #E2E8F0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
}

.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background: var(--primary);
    color: white;
    padding: 1rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 700;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

.header-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
}

.header-btn:active {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0.95);
}

.header-btn.active {
    background: rgba(255, 255, 255, 0.35);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.badge {
    position: absolute;
    top: -0.25rem;
    right: -0.25rem;
    background: var(--danger);
    color: white;
    font-size: 0.75rem;
    padding: 0.125rem 0.375rem;
    border-radius: 1rem;
    font-weight: 700;
    min-width: 1.25rem;
    text-align: center;
}

/* Mode Indicator */
.mode-indicator {
    max-width: 500px;
    margin: 0 auto 1rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: var(--shadow);
    animation: slideDown 0.3s;
}

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

.mode-icon {
    font-size: 1.5rem;
}

.mode-text {
    font-weight: 600;
    font-size: 0.95rem;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 1.25rem;
}

/* Scanner Section */
.scanner-section {
    max-width: 500px;
    margin: 0 auto;
}

.scan-area {
    position: relative;
    width: 100%;
    height: 300px;
    background: #000;
    border-radius: 1rem;
    overflow: hidden;
    box-shadow: var(--shadow);
    margin-bottom: 1.25rem;
}

#video {
    width: 100%;
    height: 100%;
}

#video canvas,
#video video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
}

/* Placeholder cuando no está escaneando */
.scan-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.placeholder-icon {
    font-size: 4rem;
    opacity: 0.5;
}

.placeholder-text {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.95rem;
    text-align: center;
    padding: 0 1rem;
}

.scan-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to bottom, 
        rgba(0,0,0,0.3) 0%, 
        transparent 30%, 
        transparent 70%, 
        rgba(0,0,0,0.3) 100%);
    pointer-events: none;
}

.scan-line {
    position: absolute;
    top: 50%;
    left: 10%;
    right: 10%;
    height: 2px;
    background: var(--success);
    box-shadow: 0 0 10px var(--success);
    animation: scan 2s ease-in-out infinite;
}

@keyframes scan {
    0%, 100% { transform: translateY(-50px); opacity: 0; }
    50% { transform: translateY(50px); opacity: 1; }
}

.controls {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.btn {
    flex: 1;
    padding: 1rem;
    border: none;
    border-radius: 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--shadow);
}

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

.btn-primary:active {
    background: var(--primary-dark);
    transform: translateY(1px);
}

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

.btn-secondary:active {
    background: #475569;
    transform: translateY(1px);
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* Search Box */
.search-box {
    display: flex;
    gap: 0.75rem;
    background: var(--card-bg);
    padding: 0.75rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
}

#searchInput {
    flex: 1;
    padding: 0.75rem;
    border: 2px solid var(--border);
    border-radius: 0.5rem;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

#searchInput:focus {
    border-color: var(--primary);
}

.btn-search {
    padding: 0.75rem 1.25rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-size: 1.25rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-search:active {
    background: var(--primary-dark);
    transform: scale(0.95);
}

/* Product Result */
.product-result {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    z-index: 200;
    animation: fadeIn 0.2s;
}

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

.product-card {
    background: var(--card-bg);
    border-radius: 1.25rem;
    padding: 2rem 1.5rem;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
    position: relative;
    animation: slideUp 0.3s;
}

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

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 2rem;
    height: 2rem;
    border: none;
    background: var(--border);
    border-radius: 50%;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    transition: all 0.2s;
}

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

.product-info {
    margin-bottom: 1.5rem;
}

.product-info h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text);
}

.product-code {
    color: var(--text-light);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.product-price {
    display: flex;
    align-items: baseline;
    margin-bottom: 1rem;
}

.currency {
    font-size: 1.5rem;
    color: var(--text-light);
    margin-right: 0.25rem;
}

#productPrice {
    font-size: 3rem;
    font-weight: 700;
    color: var(--success);
}

.product-stock {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    background: var(--bg);
    border-radius: 0.75rem;
    margin-bottom: 0.75rem;
}

.stock-label {
    color: var(--text-light);
    font-size: 0.875rem;
}

.stock-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.stock-unit {
    color: var(--text-light);
    font-size: 0.875rem;
}

.product-location {
    color: var(--text-light);
    font-size: 0.875rem;
    padding: 0.75rem;
    background: var(--bg);
    border-radius: 0.5rem;
}

/* Stock Loading Panel Specific Styles */
.load-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.load-icon {
    font-size: 2rem;
}

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

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.form-input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border);
    border-radius: 0.5rem;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.form-input:focus {
    border-color: var(--primary);
}

.form-input::placeholder {
    color: var(--text-light);
}

.stock-current {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--bg);
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
}

.stock-label-small {
    color: var(--text-light);
    font-size: 0.875rem;
}

.stock-current-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
}

.quantity-input-section {
    margin-bottom: 1.5rem;
}

.quantity-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.75rem;
}

.quantity-controls {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.qty-btn {
    width: 3rem;
    height: 3rem;
    border: 2px solid var(--primary);
    background: white;
    color: var(--primary);
    border-radius: 0.75rem;
    font-size: 1.5rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qty-btn:active {
    background: var(--primary);
    color: white;
    transform: scale(0.95);
}

.quantity-input {
    flex: 1;
    height: 3rem;
    text-align: center;
    font-size: 1.5rem;
    font-weight: 700;
    border: 2px solid var(--border);
    border-radius: 0.75rem;
    outline: none;
    transition: border-color 0.2s;
}

.quantity-input:focus {
    border-color: var(--primary);
}

.new-stock-preview {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    background: linear-gradient(135deg, var(--success) 0%, #059669 100%);
    color: white;
    border-radius: 0.75rem;
    margin-bottom: 1rem;
}

.preview-label {
    font-size: 0.875rem;
    opacity: 0.9;
}

.preview-value {
    font-size: 1.75rem;
    font-weight: 700;
}

.load-actions {
    display: flex;
    gap: 0.75rem;
}

.load-actions .btn {
    flex: 1;
}

/* History Panel */
.history-panel {
    position: fixed;
    top: 0;
    right: -100%;
    bottom: 0;
    width: 100%;
    max-width: 400px;
    background: var(--card-bg);
    box-shadow: -4px 0 10px rgba(0, 0, 0, 0.1);
    transition: right 0.3s;
    z-index: 300;
    overflow-y: auto;
}

.history-panel.active {
    right: 0;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

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

.history-actions {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.history-list {
    padding: 1.25rem;
}

.empty-state {
    text-align: center;
    color: var(--text-light);
    padding: 3rem 1rem;
}

.history-item {
    background: var(--bg);
    padding: 1rem;
    border-radius: 0.75rem;
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.history-item:active {
    background: var(--border);
    transform: scale(0.98);
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 0.5rem;
}

.history-item h3 {
    font-size: 1rem;
    color: var(--text);
    margin-bottom: 0.25rem;
}

.history-item-code {
    font-size: 0.75rem;
    color: var(--text-light);
}

.history-item-time {
    font-size: 0.75rem;
    color: var(--text-light);
}

.history-item-details {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
}

.history-item-price {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--success);
}

.history-item-stock {
    font-size: 0.875rem;
    color: var(--text-light);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 0.75rem;
    font-weight: 600;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 400;
    max-width: 90%;
    text-align: center;
}

.toast.show {
    opacity: 1;
}

.toast.success {
    background: var(--success);
}

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

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

/* History Tabs */
.history-tabs {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding: 1rem 1.25rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 4rem; /* Ajusta según la altura del header del historial */
    z-index: 5;
}

.history-tab {
    flex-shrink: 0;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-light);
    border-radius: 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.history-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.history-tab:active {
    transform: scale(0.95);
}

/* History Items by Type */
.history-item-consult {
    border-left: 4px solid var(--primary);
}

.history-item-load {
    border-left: 4px solid var(--success);
}

.history-item-discount {
    border-left: 4px solid var(--warning);
}

/* Tab Content */
#historyTabContent {
    padding: 0 1.25rem 1.25rem;
}

/* Responsive History Tabs */
@media (max-width: 480px) {
    .history-tabs {
        top: 3.5rem;
        padding: 0.75rem;
    }
    
    .history-tab {
        font-size: 0.7rem;
        padding: 0.4rem 0.6rem;
    }
}

/* Responsive */
@media (max-width: 480px) {
    .header h1 {
        font-size: 1.1rem;
    }
    
    .header-btn {
        font-size: 0.75rem;
        padding: 0.4rem 0.75rem;
    }
    
    #productPrice {
        font-size: 2.5rem;
    }
    
    .history-panel {
        max-width: 100%;
    }

    .mode-text {
        font-size: 0.85rem;
    }
}