:root {
    --bg-color: #0f172a;
    --sidebar-bg: rgba(30, 41, 59, 0.8);
    --accent-color: #6366f1;
    --text-color: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --label-bg: #ffffff;
    --label-text: #000000;
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar Styling */
.sidebar {
    width: 350px;
    background: var(--sidebar-bg);
    backdrop-filter: blur(12px);
    border-right: 1px solid var(--border-color);
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    z-index: 10;
}

.sidebar header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(135deg, #818cf8, #c084fc);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar header p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.form-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.form-section h3 {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.input-group label {
    font-size: 0.8rem;
    font-weight: 500;
}

input[type="text"], select {
    background: #1e293b;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.6rem;
    color: white;
    font-size: 0.9rem;
    transition: all 0.2s;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

/* Pictograms */
.pictograms-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

.picto-item {
    aspect-ratio: 1;
    background: #1e293b;
    border: 1px solid var(--border-color);
    border-radius: 0.4rem;
    padding: 0.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.picto-item img {
    max-width: 100%;
    max-height: 100%;
    filter: grayscale(0.8);
    opacity: 0.5;
}

.picto-item.active {
    border-color: var(--accent-color);
    background: rgba(99, 102, 241, 0.1);
}

.picto-item.active img {
    filter: none;
    opacity: 1;
}

/* Tags (H & P Phrases) */
.tag-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.5rem;
}

/* Search results dropdown */
.search-container {
    position: relative;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #1e293b;
    border: 1px solid var(--border-color);
    border-radius: 0 0 8px 8px;
    max-height: 250px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

.search-results.hidden {
    display: none;
}

.search-item {
    padding: 10px 15px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s;
}

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

.search-item:hover {
    background: var(--accent-color);
}

.search-item .item-name {
    display: block;
    font-weight: 600;
}

.search-item .item-name small {
    font-weight: 400;
    color: var(--text-muted);
    margin-left: 0.5rem;
}

.search-item .item-ids {
    display: flex;
    gap: 1rem;
    margin-top: 2px;
}

.search-item .item-cas, .search-item .item-ce {
    display: inline-block;
    font-size: 0.7rem;
    opacity: 0.7;
    background: rgba(255, 255, 255, 0.05);
    padding: 1px 4px;
    border-radius: 3px;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.tag {
    background: #334155;
    color: white;
    padding: 0.2rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.tag .remove {
    cursor: pointer;
    font-weight: bold;
    opacity: 0.7;
}

.tag .remove:hover {
    opacity: 1;
}

/* Layout Selector */
.layout-selector {
    display: flex;
    gap: 0.4rem;
}

.layout-btn {
    flex: 1;
    padding: 0.5rem;
    background: #1e293b;
    border: 1px solid var(--border-color);
    border-radius: 0.4rem;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
}

.layout-btn.active {
    background: var(--accent-color);
    border-color: var(--accent-color);
}

.small {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Buttons */
.btn {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.btn-primary {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

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

.sidebar-footer {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding-top: 1.5rem;
}

.export-import-group {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.2rem;
}

.btn-small {
    flex: 1;
    padding: 0.4rem;
    font-size: 0.75rem;
    background: #475569;
}

/* Preview Area */
.preview-area {
    flex: 1;
    background: #1e293b;
    padding: 2rem;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
}

#print-grid {
    background: white;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    width: 210mm;
    min-height: 297mm;
    padding: 10mm;
    display: grid;
    gap: 5mm;
    align-content: start;
}

/* Dynamic Grid Layouts */
.grid-l1 { grid-template-columns: 1fr; }
.grid-l2 { grid-template-columns: 1fr; grid-template-rows: repeat(2, 1fr); height: 297mm; }
.grid-l4 { grid-template-columns: 1fr 1fr; grid-template-rows: repeat(2, 1fr); height: 297mm; }
.grid-l8 { grid-template-columns: 1fr 1fr; grid-template-rows: repeat(4, 1fr); height: 297mm; }
.grid-l12 { grid-template-columns: 1fr 1fr; grid-template-rows: repeat(6, 1fr); height: 297mm; }

/* Label Box Styling - THE ACTUAL TICKET */
.label-box {
    background: white;
    color: black;
    border: 1.5px solid black;
    padding: 2mm;
    display: flex;
    flex-direction: column;
    gap: 1.5mm;
    overflow: hidden;
    position: relative;
    font-family: 'Helvetica', 'Arial', sans-serif;
}

.label-section-header {
    text-align: center;
    border-bottom: 0.5px solid #eee;
    padding-bottom: 2mm;
    margin-bottom: 2mm;
}

.label-name {
    font-size: 1.6em;
    font-weight: 800;
    color: #0000FF; /* Pure Blue like ref */
    margin-bottom: 1mm;
    line-height: 1.2;
}

.label-formula {
    font-size: 1.2em;
    font-weight: 700;
    color: #000;
}

.label-tech-properties {
    font-size: 0.9em;
    font-weight: 500;
    color: #444;
    display: flex;
    justify-content: center;
    gap: 3mm;
    margin-top: 1mm;
}

.label-section-pictos {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2mm;
    padding: 1mm 0;
}

.label-pictos {
    display: flex;
    justify-content: center;
    gap: 2mm;
}

.label-pictos img {
    width: auto;
    transition: height 0.2s ease;
}

/* Base dynamic scaling logic */
.label-pictos[data-count="4"] { --picto-modifier: 0.85; }
.label-pictos[data-count="5"] { --picto-modifier: 0.75; }
.label-pictos[data-count="6"] { --picto-modifier: 0.65; }
.label-pictos[data-count="7"] { --picto-modifier: 0.55; }
.label-pictos[data-count="8"] { --picto-modifier: 0.5; }
.label-pictos[data-count="9"] { --picto-modifier: 0.45; }

.label-pictos {
    --picto-modifier: 1; /* Default multiplier */
}

.label-pictos img {
    height: calc(var(--base-height, 18mm) * var(--picto-modifier));
}


.label-section-signal {
    text-align: center;
    font-size: 1.25em;
    font-weight: 900;
    color: #FF0000; /* GHS Red */
    letter-spacing: 1px;
    margin: 1.5mm 0;
}

.label-section-phrases {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5mm;
    font-size: 0.75em;
    line-height: 1.15;
    overflow-y: hidden;
}

.label-h-container, .label-p-container {
    padding: 0.5mm 0;
    background: transparent;
}

.label-h-list, .label-p-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.label-section-footer {
    border-top: 1.5px solid black;
    padding-top: 1.5mm;
    padding-bottom: 0.5mm;
    font-size: 0.75em;
    display: flex;
    flex-direction: column;
    gap: 1mm;
}

.footer-ids {
    display: flex;
    justify-content: center;
    gap: 10mm;
    font-weight: 800;
}

.footer-custom {
    text-align: center;
    font-size: 0.85em;
    font-weight: 600;
    opacity: 0.8;
}

/* LAYOUT-SPECIFIC SCALING */

/* L1: Full Page */
.grid-l1 { --base-height: 50mm; }
.grid-l1 .label-name { font-size: 4rem; }
.grid-l1 .label-meta { font-size: 1.8rem; }
.grid-l1 .label-section-signal { font-size: 2.5rem; }
.grid-l1 .label-section-phrases { font-size: 1.4rem; gap: 4mm; }
.grid-l1 .label-section-footer { font-size: 1rem; }

/* L2: 2 par page */
.grid-l2 { --base-height: 40mm; }
.grid-l2 .label-name { font-size: 3rem; }
.grid-l2 .label-meta { font-size: 1.4rem; }
.grid-l2 .label-section-signal { font-size: 2rem; }
.grid-l2 .label-section-phrases { font-size: 1.1rem; }

/* L4: 4 par page */
.grid-l4 { --base-height: 35mm; }
.grid-l4 .label-name { font-size: 2.2rem; }
.grid-l4 .label-meta { font-size: 1.1rem; }
.grid-l4 .label-section-signal { font-size: 1.5rem; }
.grid-l4 .label-section-phrases { font-size: 0.95rem; }

/* L8: 8 par page */
.grid-l8 { --base-height: 20mm; }
.grid-l8 .label-name { font-size: 1.35rem; }
.grid-l8 .label-meta { font-size: 0.85rem; }
.grid-l8 .label-section-signal { font-size: 1.1rem; }
.grid-l8 .label-section-phrases { font-size: 0.75rem; }

/* L12: 12 par page (Small labels) */
.grid-l12 { --base-height: 12mm; }
.grid-l12 .label-name { font-size: 1rem; }
.grid-l12 .label-meta { font-size: 0.7rem; }
.grid-l12 .label-section-signal { font-size: 0.9rem; }
.grid-l12 .label-section-phrases { font-size: 0.6rem; }
.grid-l12 .label-section-footer { font-size: 0.5rem; }

/* Print Overrides */
@media print {
    @page {
        size: A4;
        margin: 0;
    }
    body { background: white; }
    .no-print { display: none !important; }
    .app-container { height: auto; display: block; }
    .preview-area { padding: 0; background: white; }
    #print-grid {
        box-shadow: none;
        width: 210mm;
        margin: 0;
        padding: 5mm; 
        gap: 2mm;
    }
}
