/* ===== CSS Variables ===== */
:root {
    --primary: #4f46e5;
    --primary-light: #6366f1;
    --primary-dark: #3730a3;
    --primary-50: #eef2ff;
    --primary-100: #e0e7ff;
    --primary-200: #c7d2fe;
    --surface: #ffffff;
    --surface-50: #f8fafc;
    --surface-100: #f1f5f9;
    --surface-200: #e2e8f0;
    --surface-300: #cbd5e1;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --sidebar-width: 320px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --radius: 10px;
    --radius-sm: 6px;
    --transition: 0.2s ease;
}

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--surface-50);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    z-index: 10;
}

.sidebar-header {
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border-light);
}

.logo-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-title svg {
    color: var(--primary);
    flex-shrink: 0;
}

.logo-title h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

.subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 1px;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.sidebar-content::-webkit-scrollbar {
    width: 4px;
}

.sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: var(--surface-300);
    border-radius: 4px;
}

/* ===== Config Sections ===== */
.config-section {
    padding: 0 16px;
    margin-bottom: 4px;
}

.section-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 4px;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    transition: color var(--transition);
}

.section-toggle:hover {
    color: var(--primary);
}

.section-icon {
    display: flex;
    align-items: center;
    color: var(--primary);
}

.chevron {
    margin-left: auto;
    transition: transform var(--transition);
}

.section-toggle.collapsed .chevron {
    transform: rotate(-90deg);
}

.section-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.section-body.open {
    max-height: 600px;
}

.section-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    padding: 10px 4px 8px;
}

.section-label svg {
    color: var(--primary);
}

/* ===== Inputs ===== */
.input-row {
    display: flex;
    gap: 10px;
    margin-bottom: 14px;
}

.input-group {
    flex: 1;
}

.input-group label {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.input-group input[type="number"] {
    width: 100%;
    padding: 8px 10px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--surface);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

.input-group input[type="number"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-100);
}

/* ===== Sliders ===== */
.slider-group {
    margin-bottom: 14px;
}

.slider-group label {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: linear-gradient(to right, var(--primary), var(--primary-light));
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    border: 3px solid white;
    box-shadow: var(--shadow-md);
    cursor: pointer;
    transition: transform var(--transition);
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    border: 3px solid white;
    box-shadow: var(--shadow-md);
    cursor: pointer;
}

/* ===== Checkboxes ===== */
.checkbox-group {
    margin-bottom: 8px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    padding: 4px 0;
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    display: none;
}

.checkbox-custom {
    width: 18px;
    height: 18px;
    border: 2px solid var(--surface-300);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
    position: relative;
}

.checkbox-label input[type="checkbox"]:checked+.checkbox-custom {
    background: var(--primary);
    border-color: var(--primary);
}

.checkbox-label input[type="checkbox"]:checked+.checkbox-custom::after {
    content: '';
    width: 5px;
    height: 9px;
    border: 2px solid white;
    border-top: none;
    border-left: none;
    transform: rotate(45deg) translate(-1px, -1px);
    position: absolute;
}

.checkbox-label svg {
    color: var(--text-muted);
}

/* ===== Textarea ===== */
textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    color: var(--text-primary);
    resize: vertical;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
    min-height: 80px;
}

textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-100);
}

textarea::placeholder {
    color: var(--text-muted);
    font-size: 12px;
}

/* ===== Buttons ===== */
.button-row {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-outline {
    background: var(--surface);
    color: var(--text-primary);
    border: 1.5px solid var(--border);
    flex: 1;
}

.btn-outline:hover {
    background: var(--surface-50);
    border-color: var(--surface-300);
}

.btn-ai {
    background: var(--primary-50);
    color: var(--primary);
    border: 1.5px solid var(--primary-200);
    flex: 1;
}

.btn-ai:hover {
    background: var(--primary-100);
}

.btn-primary {
    width: 100%;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    padding: 12px 16px;
    font-size: 14px;
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 6px 16px rgba(79, 70, 229, 0.4);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    width: 100%;
    background: var(--surface);
    color: var(--primary);
    border: 1.5px solid var(--primary-200);
    padding: 10px 16px;
    font-size: 13px;
    border-radius: var(--radius);
}

.btn-secondary:hover {
    background: var(--primary-50);
}

/* ===== Code List ===== */
.list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 4px;
}

.btn-clear {
    display: flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    color: #ef4444;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background var(--transition);
}

.btn-clear:hover {
    background: #fef2f2;
}

.code-list {
    max-height: 180px;
    overflow-y: auto;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    background: var(--surface-50);
}

.code-list::-webkit-scrollbar {
    width: 4px;
}

.code-list::-webkit-scrollbar-thumb {
    background: var(--surface-300);
    border-radius: 4px;
}

.code-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-light);
    transition: background var(--transition);
}

.code-item:last-child {
    border-bottom: none;
}

.code-item:hover {
    background: var(--surface-100);
}

.code-item .remove-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    transition: all var(--transition);
}

.code-item .remove-btn:hover {
    color: #ef4444;
    background: #fef2f2;
}

/* ===== Sidebar Footer ===== */
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.paper-info {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    height: 100vh;
    overflow-y: auto;
    padding: 24px;
    background: var(--surface-100);
}

.labels-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: center;
    align-content: flex-start;
    min-height: 100%;
}

/* ===== Empty State ===== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 60vh;
    text-align: center;
    color: var(--text-muted);
    width: 100%;
}

.empty-state h2 {
    font-size: 20px;
    font-weight: 600;
    margin-top: 16px;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 14px;
    margin-top: 6px;
    max-width: 280px;
}

/* ===== Label Card ===== */
.label-card {
    background: white;
    border-radius: 4px;
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    transition: box-shadow var(--transition);
}

.label-card:hover {
    box-shadow: var(--shadow-lg);
}

.label-card.with-border {
    border: 2.5px solid #1e293b;
    border-radius: 6px;
}

/* Label Header (logo + UBICACIÓN) */
.label-header {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px 2px;
    border-bottom: 1px solid #e2e8f0;
}

/* Sidebar Logo */
.sidebar-logo {
    height: 32px;
    width: auto;
    object-fit: contain;
}

.label-logo {
    /* Height is set via inline style for customization */
    width: auto;
    object-fit: contain;
    /* Default fallback */
    height: 24px;
}

.label-ubicacion {
    font-size: 12px;
    font-weight: 700;
    color: #4f6d94;
    letter-spacing: 1px;
    text-transform: uppercase;
}

/* Label Body */
.label-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
    width: 100%;
}

.label-code {
    font-weight: 800;
    color: #1e293b;
    letter-spacing: 1px;
    line-height: 1.1;
    text-align: center;
    word-break: break-all;
}

.label-barcode {
    width: 90%;
    margin-top: 2px;
}

.label-barcode svg {
    width: 100%;
    height: auto;
}

/* ===== Print Styles ===== */
@media print {
    body {
        background: white;
        overflow: visible;
    }

    .sidebar {
        display: none !important;
    }

    .main-content {
        padding: 0;
        height: auto;
        overflow: visible;
        width: 100%;
    }

    .labels-grid {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        justify-content: flex-start;
        padding: 10px;
    }

    .empty-state {
        display: none !important;
    }

    .label-card {
        box-shadow: none !important;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .label-card.with-border {
        border: 2px solid #000 !important;
    }

    .label-card:hover {
        box-shadow: none !important;
    }

    @page {
        size: letter;
        margin: 0.5in;
    }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    body {
        flex-direction: column;
        overflow: auto;
    }

    .sidebar {
        width: 100%;
        min-width: 100%;
        height: auto;
        max-height: 50vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .main-content {
        height: auto;
        min-height: 50vh;
    }
}

/* ===== Animations ===== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.label-card {
    animation: fadeIn 0.3s ease forwards;
}

/* ===== Toast Notification ===== */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--text-primary);
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 100;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}