/* =========================================================
   System Zarządzania Farbami — Ciemny motyw
   ========================================================= */

/* --- Reset & Base ---------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --color-primary:   #3b82f6;
    --color-primary-d: #2563eb;
    --color-danger:    #ef4444;
    --color-danger-d:  #b91c1c;
    --color-success:   #22c55e;
    --color-warning:   #f59e0b;
    --color-bg:        #0f172a;
    --color-surface:   #1e293b;
    --color-surface2:  #273449;
    --color-border:    #334155;
    --color-text:      #e2e8f0;
    --color-muted:     #94a3b8;
    --radius:          0.5rem;
    --shadow:          0 2px 8px rgba(0,0,0,.4);
}

html { font-size: 16px; }

body {
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Layout ---------------------------------------------- */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
    flex: 1;
}

/* --- Navbar ---------------------------------------------- */
.navbar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    height: 3.5rem;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--color-text);
    text-decoration: none;
    white-space: nowrap;
}
.navbar-brand:hover { text-decoration: none; color: var(--color-primary); }

.nav-links {
    display: flex;
    list-style: none;
    gap: 0.25rem;
    flex: 1;
}

.nav-links a {
    display: block;
    padding: 0.4rem 0.85rem;
    border-radius: var(--radius);
    color: var(--color-muted);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: background .15s, color .15s;
}
.nav-links a:hover, .nav-links a.active {
    background: rgba(59,130,246,.15);
    color: var(--color-primary);
    text-decoration: none;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
    color: var(--color-muted);
    white-space: nowrap;
}

/* --- Buttons --------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    background: var(--color-surface2);
    color: var(--color-text);
    transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: #334155; text-decoration: none; }

.btn-primary { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.btn-primary:hover { background: var(--color-primary-d); border-color: var(--color-primary-d); color: #fff; }

.btn-outline { background: transparent; border-color: var(--color-border); color: var(--color-muted); }
.btn-outline:hover { background: var(--color-surface2); color: var(--color-text); }

.btn-danger { background: var(--color-danger); color: #fff; border-color: var(--color-danger); }
.btn-danger:hover { background: var(--color-danger-d); color: #fff; }

.btn-sm { padding: 0.25rem 0.65rem; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; }

/* --- Alerts ---------------------------------------------- */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
    border: 1px solid transparent;
}
.alert ul { padding-left: 1.2rem; }

.alert-error   { background: rgba(239,68,68,.15);  border-color: #ef4444; color: #fca5a5; }
.alert-success { background: rgba(34,197,94,.12);  border-color: #22c55e; color: #86efac; }
.alert-info    { background: rgba(59,130,246,.12); border-color: #3b82f6; color: #93c5fd; }

/* --- Page header ----------------------------------------- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}
.page-header h1 { font-size: 1.5rem; }

/* --- Stats grid ------------------------------------------ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: var(--shadow);
}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-primary);
    line-height: 1;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--color-muted);
    margin-top: 0.35rem;
    text-align: center;
}

/* --- Recent section -------------------------------------- */
.recent-section { margin-top: 1rem; }
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}
.section-header h2 { font-size: 1.1rem; }

/* --- Data table ------------------------------------------ */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    font-size: 0.875rem;
}
.data-table th, .data-table td {
    text-align: left;
    padding: 0.65rem 0.85rem;
    border-bottom: 1px solid var(--color-border);
}
.data-table th { background: var(--color-surface2); font-weight: 600; color: var(--color-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.data-table th.sortable { user-select: none; white-space: nowrap; }
.data-table th.sortable:hover { color: var(--color-text); }
.data-table th.sort-asc,
.data-table th.sort-desc { color: var(--color-primary); }
.data-table th .sort-icon { font-style: normal; opacity: .7; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--color-surface2); }

.actions { white-space: nowrap; display: flex; gap: 0.4rem; align-items: center; }

/* --- Colour swatch --------------------------------------- */
.color-swatch {
    display: inline-block;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 4px;
    border: 1px solid rgba(255,255,255,.15);
    vertical-align: middle;
    flex-shrink: 0;
}

.large-swatch {
    width: 100%;
    max-width: 180px;
    height: 180px;
    border-radius: var(--radius);
    border: 1px solid rgba(255,255,255,.15);
    margin-bottom: 0.5rem;
}
.swatch-label { font-family: monospace; font-size: 0.9rem; color: var(--color-muted); }

/* --- Detail page ----------------------------------------- */
.detail-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2rem;
    margin-bottom: 1.5rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}
.detail-table { border-collapse: collapse; font-size: 0.9rem; }
.detail-table th, .detail-table td { padding: 0.45rem 0.75rem; border-bottom: 1px solid var(--color-border); vertical-align: top; }
.detail-table tr:last-child th, .detail-table tr:last-child td { border-bottom: none; }
.detail-table th { color: var(--color-muted); text-align: right; font-weight: 500; width: 140px; }

/* --- Forms ----------------------------------------------- */
.form-group { display: flex; flex-direction: column; gap: 0.35rem; }
.form-group label { font-size: 0.85rem; font-weight: 500; color: var(--color-muted); }

.form-group input,
.form-group select,
.form-group textarea {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: inherit;
    background: var(--color-surface2);
    color: var(--color-text);
    transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,.2);
}
.form-group select option { background: var(--color-surface2); }

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1rem; }

.paint-form {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    max-width: 800px;
}

.form-actions { display: flex; gap: 0.75rem; margin-top: 1.25rem; }

.color-input-group { display: flex; gap: 0.5rem; align-items: center; }
.color-input-group input[type="color"] { width: 2.5rem; height: 2.5rem; padding: 0.15rem; border-radius: 4px; cursor: pointer; }
.color-input-group input[type="text"] { flex: 1; font-family: monospace; }

/* --- Filter bar ------------------------------------------ */
.filter-bar {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
    align-items: center;
}
.filter-bar input, .filter-bar select {
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    background: var(--color-surface);
    color: var(--color-text);
}
.filter-bar input { flex: 1; min-width: 200px; }
.filter-bar select option { background: var(--color-surface); }

/* --- Pagination ------------------------------------------ */
.pagination { display: flex; gap: 0.35rem; margin-top: 1rem; flex-wrap: wrap; }
.pagination a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    height: 2rem;
    padding: 0 0.4rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    color: var(--color-text);
    text-decoration: none;
    background: var(--color-surface);
}
.pagination a:hover { background: var(--color-surface2); text-decoration: none; }
.pagination a.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* --- Auth page ------------------------------------------- */
.auth-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.auth-title { font-size: 1.75rem; margin-bottom: 1.5rem; }
.auth-form {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.auth-form h2 { font-size: 1.25rem; margin-bottom: 0.25rem; }

/* --- Badges ---------------------------------------------- */
.badge { display: inline-block; padding: 0.2rem 0.5rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge-primary { background: rgba(59,130,246,.2); color: #93c5fd; }
.badge-default { background: var(--color-surface2); color: var(--color-muted); }

/* --- Collapsible form ------------------------------------ */
.collapsible-form {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
    overflow: hidden;
}
.collapsible-form summary {
    padding: 0.75rem 1rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    list-style: none;
    color: var(--color-primary);
}
.collapsible-form summary::-webkit-details-marker { display: none; }
.collapsible-form .paint-form {
    border: none;
    border-top: 1px solid var(--color-border);
    border-radius: 0;
    box-shadow: none;
}

/* --- Error pages ----------------------------------------- */
.error-page { text-align: center; padding: 4rem 1rem; }
.error-page h1 { font-size: 6rem; font-weight: 900; color: var(--color-border); line-height: 1; }
.error-page p { color: var(--color-muted); margin: 1rem 0 1.5rem; }

/* --- Footer ---------------------------------------------- */
.site-footer {
    text-align: center;
    padding: 1rem;
    font-size: 0.8rem;
    color: var(--color-muted);
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
}

/* --- Misc ------------------------------------------------ */
.empty-state { color: var(--color-muted); font-style: italic; margin: 1.5rem 0; }
.inline-form { display: inline; }

/* =========================================================
   SZAFA Z FARBAMI
   ========================================================= */
.cabinet-config {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}
.cabinet-config h2 { margin-bottom: 0.9rem; color: var(--color-muted); text-transform: uppercase; letter-spacing: .05em; font-size: .78rem; }
.cabinet-config .form-row { margin-bottom: 0; }

/* Cabinet page two-panel layout */
.cabinet-page {
    display: flex;
    gap: 1.25rem;
    align-items: flex-start;
}
.cabinet-page-main {
    flex: 1;
    min-width: 0;
    overflow-x: auto;
}
.cabinet-paint-sidebar {
    width: 200px;
    flex-shrink: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 120px);
    position: sticky;
    top: 1rem;
}
.cabinet-sidebar-hd {
    padding: .5rem .75rem;
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--color-muted);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}
.cabinet-sidebar-search {
    margin: .5rem .75rem;
    padding: .3rem .5rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface2);
    color: var(--color-text);
    font-size: .8rem;
    flex-shrink: 0;
}
.cabinet-sidebar-list {
    overflow-y: auto;
    flex: 1;
    padding: 0 .5rem .5rem;
}
.sidebar-paint-chip {
    display: flex;
    align-items: center;
    gap: .45rem;
    padding: .3rem .4rem;
    border-radius: 5px;
    cursor: grab;
    font-size: .75rem;
    user-select: none;
    border: 1px solid transparent;
}
.sidebar-paint-chip:hover { background: var(--color-surface2); }
.sidebar-paint-chip:active { cursor: grabbing; }
.sidebar-paint-chip.dragging { opacity: .4; }
.sidebar-chip-swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    flex-shrink: 0;
    border: 1px solid rgba(255,255,255,.15);
}
.sidebar-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cabinet-slot.drag-over {
    border-color: var(--color-primary) !important;
    opacity: 1 !important;
    transform: translateY(-3px);
    box-shadow: 0 0 0 2px var(--color-primary);
}

.cabinets-wrapper {
    display: grid;
    grid-template-columns: repeat(2, max-content);
    justify-content: start;
    gap: 1.5rem;
}

.cabinet-unit {
    background: var(--color-surface);
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    flex-shrink: 0;
}
.cabinet-unit-title {
    background: var(--color-surface2);
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-muted);
    border-bottom: 1px solid var(--color-border);
    text-align: center;
    border-radius: var(--radius) var(--radius) 0 0;
}

.cabinet-shelf {
    display: flex;
    gap: 4px;
    padding: 4px 8px;
    border-bottom: 1px solid var(--color-border);
    align-items: center;
}
.cabinet-shelf:last-child { border-bottom: none; }
.shelf-label {
    width: 1.4rem;
    font-size: 0.7rem;
    color: var(--color-muted);
    text-align: right;
    flex-shrink: 0;
}

.cabinet-slot {
    width: 54px;
    height: 76px;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,.1);
    cursor: pointer;
    position: relative;
    transition: transform .12s, box-shadow .12s;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: var(--color-surface2);
}
.cabinet-slot:hover { transform: translateY(-3px); box-shadow: 0 6px 18px rgba(0,0,0,.55); z-index: 2; border-color: var(--color-primary); }
.cabinet-slot.filled { border-color: rgba(255,255,255,.2); }
.slot-img {
    width: 100%;
    height: calc(100% - 18px);
    object-fit: contain;
    display: block;
    padding: 2px;
}
.slot-color {
    width: 100%;
    height: calc(100% - 18px);
    flex-shrink: 0;
}
.cabinet-slot .slot-label {
    font-size: 0.42rem;
    color: rgba(255,255,255,.9);
    background: rgba(0,0,0,.6);
    width: 100%;
    text-align: center;
    padding: 2px 2px;
    line-height: 1.3;
    word-break: break-all;
    position: absolute;
    bottom: 0;
    left: 0;
}
.cabinet-slot .slot-plus {
    font-size: 1.1rem;
    color: rgba(255,255,255,.25);
    line-height: 1;
}
.cabinet-slot.empty-slot { border-style: dashed; opacity: .45; }
.cabinet-slot.empty-slot:hover { opacity: 1; }

/* Paint picker modal */
.paint-picker-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.paint-picker-overlay.open { display: flex; }
.paint-picker-modal {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem;
    width: 480px;
    max-width: 95vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.paint-picker-modal h3 { font-size: 1rem; }
.paint-picker-search {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface2);
    color: var(--color-text);
    font-size: 0.9rem;
    width: 100%;
}
.paint-picker-list {
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-height: 200px;
}
.paint-picker-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.5rem 0.65rem;
    border-radius: var(--radius);
    cursor: pointer;
    border: 1px solid transparent;
    transition: background .1s;
}
.paint-picker-item:hover { background: var(--color-surface2); border-color: var(--color-border); }
.paint-picker-item .swatch { width: 28px; height: 28px; border-radius: 4px; border: 1px solid rgba(255,255,255,.15); flex-shrink: 0; }
.paint-picker-item .pname { font-size: 0.85rem; font-weight: 500; }
.paint-picker-item .pbrand { font-size: 0.75rem; color: var(--color-muted); }
.paint-picker-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }

/* --- Stock quick-change control -------------------------- */
.stock-control {
    display: flex;
    align-items: center;
    gap: .35rem;
}
.stock-btn {
    width: 1.6rem;
    height: 1.6rem;
    border-radius: 4px;
    border: 1px solid var(--color-border);
    background: var(--color-surface2);
    color: var(--color-text);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .12s;
    flex-shrink: 0;
}
.stock-btn:hover { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.stock-val {
    min-width: 1.8rem;
    text-align: center;
    font-weight: 600;
    font-size: .9rem;
    transition: color .3s;
}
@keyframes stockFlash { 0%,100%{color:var(--color-text)} 50%{color:var(--color-success)} }
.stock-flash { animation: stockFlash .5s ease; }

/* --- Can level badges ----------------------------------- */
.can-level-badge {
    display: inline-block;
    padding: .2rem .55rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: .03em;
    text-transform: uppercase;
}
.level-high  { background: #d4edda; color: #1a5c2a; }
.level-mid   { background: #fff3cd; color: #7c5800; }
.level-low   { background: #f8d7da; color: #7c1a20; }
.can-level-toggle:hover { filter: brightness(.88); transition: filter .15s; }

/* --- Print styles --------------------------------------- */
.print-only { display: none; }

/* =========================================================
   PRINT — kompaktowy layout 3-kolumnowy
   ========================================================= */

/* Ukryj na ekranie */
.print-grid { display: none; }

@page {
    size: A4 portrait;
    margin: 10mm 8mm;
}

@media print {
    /* Reset kolorów */
    :root {
        --color-bg:      #fff;
        --color-surface: #fff;
        --color-text:    #000;
    }

    /* Ukryj całą resztę strony */
    .navbar, .page-header, .filter-bar, .site-footer,
    .no-print, #paintsTable, .alert, .empty-state { display: none !important; }

    body { background: #fff; color: #000; }
    .container { padding: 0; max-width: 100%; }

    /* Pokaż siatkę druku */
    .print-grid {
        display: block !important;
    }

    .print-title {
        font-size: 12pt;
        font-weight: 700;
        margin: 0 0 3mm;
        border-bottom: 1.5pt solid #000;
        padding-bottom: 1.5mm;
    }

    .print-group {
        margin-bottom: 3mm;
    }

    .print-group-hd {
        font-size: 8pt;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: .04em;
        background: #eee;
        padding: .8mm 1.5mm;
        margin-bottom: 1mm;
        border-left: 2pt solid #000;
    }

    /* 3 kolumny CSS */
    .print-cols {
        columns: 3;
        column-gap: 4mm;
        orphans: 1; widows: 1;
    }

    .print-row {
        display: flex;
        align-items: baseline;
        font-size: 7.5pt;
        line-height: 1;
        padding: .7mm 0;
        border-bottom: .4pt solid #ddd;
        break-inside: avoid;
        column-break-inside: avoid;
        gap: 1mm;
    }
    .pr-zero { color: #aaa; }

    .pr-code {
        font-weight: 700;
        min-width: 26pt;
        flex-shrink: 0;
    }
    .pr-color {
        flex: 1;
        font-size: 7pt;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        color: #333;
    }
    .pr-zero .pr-color { color: #aaa; }
    .pr-qty {
        font-weight: 700;
        min-width: 10pt;
        text-align: right;
        flex-shrink: 0;
    }
    .pr-zero .pr-qty::after { content: ''; }
}

/* =========================================================
   DOSTAWA MODAL
   ========================================================= */
.delivery-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.delivery-overlay.open { display: flex; }

.delivery-modal {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    width: 640px;
    max-width: 98vw;
    height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 64px rgba(0,0,0,.6);
    overflow: hidden;
}

#deliveryForm {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.delivery-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}
.delivery-modal-header h2 { font-size: 1.05rem; }
.delivery-close {
    background: none;
    border: none;
    color: var(--color-muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: .25rem .4rem;
    border-radius: 4px;
    line-height: 1;
}
.delivery-close:hover { background: var(--color-surface2); color: var(--color-text); }

.delivery-meta {
    display: flex;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
    flex-wrap: wrap;
}
.delivery-meta .form-group { margin: 0; }

.delivery-search-wrap {
    padding: .6rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}
.delivery-search {
    width: 100%;
    padding: .45rem .75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface2);
    color: var(--color-text);
    font-size: .9rem;
}

/* quick-add panel fields */
.ap-field {
    width: 100%;
    padding: .3rem .5rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: .82rem;
}

body.modal-open { overflow: hidden; }

.delivery-paint-list {
    overflow-y: scroll;
    flex: 1;
    padding: .4rem .75rem;
    overscroll-behavior: contain;
}

.delivery-paint-row {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .45rem .5rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background .1s;
    user-select: none;
}
.delivery-paint-row:hover { background: var(--color-surface2); }
.delivery-paint-row input[type="checkbox"] { width: 1rem; height: 1rem; flex-shrink: 0; cursor: pointer; accent-color: var(--color-primary); }
.delivery-paint-name { font-size: .875rem; font-weight: 500; flex: 1; }
.delivery-paint-brand { font-size: .78rem; color: var(--color-muted); white-space: nowrap; }

.delivery-qty-wrap { display: flex; align-items: center; gap: .3rem; flex-shrink: 0; }
.delivery-qty {
    width: 4rem;
    padding: .25rem .4rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background: var(--color-surface2);
    color: var(--color-text);
    font-size: .875rem;
    text-align: center;
}
.delivery-qty:focus { border-color: var(--color-primary); outline: none; }
.delivery-qty-label { font-size: .78rem; color: var(--color-muted); }

.delivery-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .85rem 1.25rem;
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
    gap: 1rem;
    flex-wrap: wrap;
}
.delivery-summary { font-size: .875rem; color: var(--color-muted); }

.delivery-history {
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
    max-height: 220px;
    overflow-y: auto;
}
.delivery-history summary {
    padding: .65rem 1.25rem;
    cursor: pointer;
    font-size: .85rem;
    color: var(--color-muted);
    list-style: none;
    user-select: none;
}
.delivery-history summary::-webkit-details-marker { display: none; }
.delivery-history summary:hover { color: var(--color-text); }
.delivery-history .data-table { font-size: .8rem; margin: 0 1rem .75rem; width: calc(100% - 2rem); }

/* Image upload preview */
.image-preview-wrap {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: .5rem;
}
.image-preview {
    width: 80px;
    height: 80px;
    object-fit: contain;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    background: var(--color-surface2);
    padding: 4px;
}
.checkbox-label {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .85rem;
    color: var(--color-muted);
    cursor: pointer;
}
.form-group input[type="file"] {
    padding: .35rem;
    cursor: pointer;
}

/* --- Responsive ------------------------------------------ */
@media (max-width: 640px) {
    .detail-grid { grid-template-columns: 1fr; }
    .navbar { gap: 0.75rem; }
    .nav-links a { padding: 0.4rem 0.5rem; font-size: 0.8rem; }
    .form-row { grid-template-columns: 1fr; }
    .cabinets-wrapper { gap: 1rem; }
}
