/* ==========================================================================
   1. VARIABLES & RESET
   ========================================================================== */
:root {
    --primary: #1e3a8a;
    --primary-light: #2563eb;
    --gray-bg: #f8fafc;
    --border: #cbd5e1;
    --text: #0f172a;
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 15px;
    background-color: var(--gray-bg);
    color: var(--text);
    line-height: 1.4;
    overflow-x: hidden;
}

/* ==========================================================================
   2. LAYOUT CONTAINERS & CARDS
   ========================================================================== */
.container {
    max-width: 1200px;
    margin: 0 auto;
    background: #ffffff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    width: 100%;
}

h1, h2, h3 {
    color: var(--primary);
    margin-top: 0;
    word-break: break-word;
}

.section-card {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 15px;
    margin-bottom: 20px;
    background: #ffffff;
}

    .section-card h2 {
        border-bottom: 2px solid var(--primary);
        padding-bottom: 5px;
        font-size: 1.2rem;
        margin-bottom: 15px;
    }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--primary);
    padding-bottom: 5px;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 8px;
}

    .section-header h2 {
        border-bottom: none;
        margin-bottom: 0;
    }

/* ==========================================================================
   3. FORM ELEMENTS & INPUTS
   ========================================================================== */
.form-group {
    display: flex;
    flex-direction: column;
}

    .form-group label {
        font-weight: 600;
        font-size: 0.875rem;
        color: #334155;
        margin-bottom: 6px;
    }

input[type="text"],
input[type="date"],
input[type="number"],
input[type="search"],
textarea,
select {
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.9rem;
    width: 100%;
    box-sizing: border-box;
}

textarea {
    resize: vertical;
    height: 120px;
}

.radio-group,
.radio-inline-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    padding-top: 4px;
}

    .radio-group label,
    .radio-inline-group label {
        font-weight: normal;
        font-size: 0.9rem;
        margin-bottom: 0;
        cursor: pointer;
    }

.optional {
    font-weight: normal;
    color: #64748b;
}

.mt-2 {
    margin-top: 8px;
}

/* ==========================================================================
   4. GRID LAYOUT SYSTEM
   ========================================================================== */
.grid {
    display: grid;
    gap: 16px;
    margin-bottom: 12px;
}

.grid-1 {
    grid-template-columns: 1fr;
}

.grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

/* ==========================================================================
   5. TABLES
   ========================================================================== */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 10px;
    width: 100%;
}

table.productSpecTable {
    width: 100%;
    border-collapse: collapse;
}

    table.productSpecTable th,
    table.productSpecTable td {
        border: 1px solid var(--border);
        padding: 8px;
        text-align: left;
        font-size: 0.85rem;
    }

th {
    background-color: #f1f5f9;
}

/* ==========================================================================
   6. BUTTONS & ACTIONS BAR
   ========================================================================== */
.btn {
    background-color: var(--primary);
    color: #ffffff;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

    .btn:hover {
        background-color: var(--primary-light);
    }

.btn-danger {
    background-color: #dc2626;
}

    .btn-danger:hover {
        background-color: #ef4444;
    }

.btn-secondary {
    background-color: #64748b;
}

.btn-success {
    background-color: #16a34a;
}

    .btn-success:hover {
        background-color: #22c55e;
    }

.btn-outline {
    background-color: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
}

.btn-sm {
    padding: 3px 8px;
    font-size: 0.8rem;
}

/* Floating & Sticky Action Bars */
.actions-bar,
.sticky-actions {
    position: sticky;
    bottom: 0;
    z-index: 1000;
    background: #ffffff;
    padding: 8px 12px;
    border-top: 1px solid #cbd5e1;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 6px 6px 0 0;
    margin-top: 16px;
    gap: 8px;
    flex-wrap: nowrap;
}

    .actions-bar > div,
    .sticky-actions > div {
        display: flex;
        align-items: center;
        gap: 6px;
    }

@supports (backdrop-filter: blur(8px)) {
    .actions-bar,
    .sticky-actions {
        background: rgba(255, 255, 255, 0.92);
        backdrop-filter: blur(8px);
    }
}

.header-actions {
    position: static;
    box-shadow: none;
    border-top: none;
    padding: 0;
    margin-top: 12px;
    margin-bottom: 12px;
}

.search-box {
    display: flex;
    gap: 8px;
    width: 100%;
    max-width: 400px;
}

#searchInput {
    width: 100%;
    max-width: 100%;
}

/* ==========================================================================
   7. FILE UPLOADS & PREVIEWS
   ========================================================================== */
.upload-zone {
    border: 2px dashed #cbd5e1;
    padding: 15px;
    border-radius: 6px;
    background: #fafafa;
    display: flex;
    align-items: center;
    gap: 12px;
}

.image-preview-zone {
    margin-top: 8px;
}

.preview-card {
    display: inline-flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #ffffff;
}

.img-thumbnail {
    max-width: 180px;
    max-height: 120px;
    object-fit: contain;
    border-radius: 4px;
    border: 1px solid #f1f5f9;
}

.preview-actions {
    display: flex;
    gap: 8px;
}

/* Deleted row highlighting */
tr.is-deleted,
tr.is-deleted td {
    background-color: #fef2f2 !important;
    color: #991b1b;
}

/* Notice label styling */
.list-notice-label {
    background-color: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e40af;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 0.875rem;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Validation */
.required-star {
    color: #dc2626;
    margin-left: 2px;
}

/* File upload controls */
.file-upload-container {
    background: #f8fafc;
    border: 1px dashed #cbd5e1;
    padding: 10px;
    border-radius: 4px;
    margin-top: 5px;
}

.file-list {
    list-style: none;
    padding: 0;
    margin: 8px 0 0 0;
}

    .file-list li {
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: #fff;
        border: 1px solid #e2e8f0;
        padding: 4px 8px;
        border-radius: 3px;
        margin-bottom: 4px;
        font-size: 0.85rem;
        word-break: break-all;
    }

tr.row-completed {
    background-color: #d4edda !important;
}

tr.row-incomplete {
    background-color: #fff3cd !important;
}

.tree-nut-container {
    margin-top: 8px;
    padding: 10px;
    border: 1px dashed #cbd5e1;
    background: #f8fafc;
    border-radius: 4px;
}

.tree-nut-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

#ingredientDeclaration {
    height: 150px;
}

#nutrientsTable tr, #microTable tr, #allergenMatrixTable tr, #ingredientsTable tr {
    scroll-margin-top: 120px; /* Adjust 60px to match the height of your #adminNavBar */
}

.geColumn {
    min-width: 90px;
}

.section-footer {
    border-top: 2px solid var(--primary);
}

#generalNotes {
    height: 200px;
}

/* ==========================================================================
   8. MEDIA QUERIES (RESPONSIVE DESIGN & MOBILE OPTIMIZATION)
   ========================================================================== */
@media (max-width: 900px) {
    .grid-3,
    .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }

    .tree-nut-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Small Mobile Breakpoint (360px - 600px) */
@media (max-width: 600px) {
    body {
        padding: 4px;
    }

    .container {
        padding: 8px;
        border-radius: 4px;
    }

    .section-card {
        padding: 10px;
        margin-bottom: 12px;
    }

    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }

    .tree-nut-grid {
        grid-template-columns: 1fr;
    }

    .actions-bar.sticky-actions,
    .sticky-actions {
        flex-direction: column;
        padding: 6px 8px;
        gap: 6px;
    }

        .actions-bar.sticky-actions > div,
        .sticky-actions > div {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 6px;
            width: 100%;
        }

            .sticky-actions > div:last-child {
                display: flex;
                flex-wrap: wrap;
            }

                .sticky-actions > div:last-child .btn {
                    flex: 1 1 auto;
                    min-width: 30%;
                }

    .btn {
        min-height: 38px;
        font-size: 0.825rem;
        padding: 4px 8px;
    }

    .btn-sm {
        min-height: 34px;
        width: 100%;
    }

    .search-box {
        flex-direction: column;
        max-width: 100%;
        width: 100%;
        margin-bottom: 0;
    }

        .search-box button {
            width: 100%;
        }

    .section-header,
    .section-card > div[style*="display: flex"] {
        flex-direction: column;
        align-items: stretch !important;
    }

        .section-header .btn,
        .section-card > div[style*="display: flex"] .btn {
            width: 100%;
            margin-top: 6px;
        }

    /* Transform HTML Tables into Mobile Card View */
    table.productSpecTable {
        border: 0;
        min-width: 100%;
        display: block;
    }

        table.productSpecTable thead {
            border: none;
            clip: rect(0 0 0 0);
            height: 1px;
            margin: -1px;
            overflow: hidden;
            padding: 0;
            position: absolute;
            width: 1px;
        }

        table.productSpecTable tbody {
            display: block;
            width: 100%;
        }

        table.productSpecTable tr {
            display: block;
            border: 1px solid var(--border);
            border-radius: 6px;
            margin-bottom: 12px;
            padding: 8px;
            background: #ffffff;
        }

        table.productSpecTable td {
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            align-items: stretch;
            font-size: 0.9rem;
            border: none;
            border-bottom: 1px solid #e2e8f0;
            padding: 8px 0;
            text-align: left !important;
            width: 100% !important;
        }

            table.productSpecTable td:last-child {
                border-bottom: 0;
            }

            table.productSpecTable td::before {
                content: attr(data-label);
                font-weight: 700;
                color: var(--primary);
                margin-bottom: 4px;
                text-transform: uppercase;
                font-size: 0.75rem;
            }

            .specActionsColumn,
            table.productSpecTable td.no-print {
                display: flex;
                flex-direction: row;
                gap: 6px;
                justify-content: flex-end;
            }

                .specActionsColumn .btn,
                table.productSpecTable td.no-print .btn {
                    width: auto;
                    flex: 1;
                }
}

@media (width > 1816px) {
    .section21 {
        position: fixed;
        right: 16px;
        top: 66px;
        width: 280px;
    }
}

/* ==========================================================================
   9. PRINT STYLESHEET
   ========================================================================== */
@media print {
    @page {
        margin: 0.5in;
        size: auto;
    }

    body {
        background: #ffffff;
        padding: 0;
        color: #000000;
    }

    .container {
        box-shadow: none;
        padding: 0;
        width: 100%;
        max-width: 100%;
    }

    .no-print,
    .btn,
    .actions-bar,
    .sticky-actions,
    #list-view {
        display: none !important;
    }

    #form-view {
        display: block !important;
    }

    /* Prevent sections from cutting off across page breaks */
    .section-card {
        border: none;
        padding: 0;
        margin-bottom: 20px;
        box-shadow: none;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    /* Form Fields & Auto-Expanding Text Areas */
    input[type="text"],
    input[type="number"],
    input[type="date"],
    textarea,
    select {
        border: none !important;
        border-bottom: 1px solid #000000 !important;
        background: transparent !important;
        box-shadow: none !important;
        outline: none !important;
        padding: 2px 0 !important;
        margin: 0 !important;
        appearance: none;
        -webkit-appearance: none;
        -moz-appearance: none;
        font-family: inherit;
        font-size: 0.9rem;
        width: 100% !important;
    }

        /* Split pseudo-selectors so individual browsers process them */
        input::placeholder,
        textarea::placeholder {
            color: transparent !important;
            -webkit-text-fill-color: transparent !important;
            opacity: 0 !important;
        }

        input::-webkit-input-placeholder,
        textarea::-webkit-input-placeholder {
            color: transparent !important;
            -webkit-text-fill-color: transparent !important;
            opacity: 0 !important;
        }

        input::-moz-placeholder,
        textarea::-moz-placeholder {
            color: transparent !important;
            opacity: 0 !important;
        }

        input:-ms-input-placeholder,
        textarea:-ms-input-placeholder {
            color: transparent !important;
            opacity: 0 !important;
        }

    textarea {
        height: auto !important;
        min-height: 1.5em !important;
        overflow: visible !important;
        white-space: pre-wrap !important;
        word-break: break-word !important;
        resize: none !important;
        field-sizing: content; /* Modern browser support for auto-expanding height */
    }

    select {
        background-image: none !important;
    }

    /* Radio & Checkbox Handling */
    input[type="radio"] {
        display: inline-block !important;
        appearance: auto;
        -webkit-appearance: auto;
    }

    .radio-group label,
    .radio-inline-group label {
        display: inline;
    }

    /* Table Printing */
    th, td {
        border: 1px solid #000000 !important;
    }

    /* Tree Nut & Checkbox Overrides */
    .tree-nut-container {
        display: block !important;
        margin-top: 5px;
        padding-left: 10px;
        border-left: 2px solid #ccc;
    }

        .tree-nut-container button,
        .custom-nuts-wrapper button {
            display: none !important;
        }

    .tree-nut-cb:not(:checked),
    .tree-nut-cb:not(:checked) + label,
    label:has(.tree-nut-cb:not(:checked)) {
        display: none !important;
    }

    label:has(.tree-nut-cb:checked) {
        display: inline-block !important;
        margin-right: 12px;
        font-weight: bold;
    }

    .tree-nut-cb:checked {
        appearance: none;
        -webkit-appearance: none;
        margin-right: 4px;
    }

        .tree-nut-cb:checked::before {
            content: "✓ ";
            font-weight: bold;
        }

    .tree-nut-custom {
        border: none !important;
        border-bottom: 1px solid #000 !important;
        background: transparent !important;
        padding: 0 !important;
        box-shadow: none !important;
    }

    #mayShipFrozen {
        appearance: none;
        -webkit-appearance: none;
        width: auto !important;
        height: auto !important;
        border: none !important;
    }

        #mayShipFrozen:checked::before {
            content: "✓ ";
            font-weight: bold;
            font-size: 1.1em;
        }

        #mayShipFrozen:not(:checked),
        label:has(#mayShipFrozen:not(:checked)) {
            display: none !important;
        }
}
