/**
 * Unified Modal System CSS
 *
 * Features:
 * - Consistent z-index hierarchy
 * - Multiple size variants
 * - Smooth animations
 * - Responsive design
 * - Accessibility support
 */

/* =================================================================
   Z-INDEX HIERARCHY (Global Constants)
   ================================================================= */

:root {
    --z-sidebar: 1000;
    --z-header: 2000;
    --z-dropdown: 5000;
    --z-modal-base: 10000;
    --z-modal-overlay: 10000;
    --z-modal-content: 10001;
    --z-toast: 15000;
    --z-tooltip: 20000;
}

/* =================================================================
   MODAL "WALL" (Mobile-only solid background)
   ================================================================= */

/* Mobile: hide everything except modal when modal is open */
@media (max-width: 768px) {
    body.modal-open-mobile > *:not(.modal-overlay):not(.custom-dropdown-menu) {
        display: none !important;
    }

    body.modal-open-mobile {
        background: #ffffff !important;
    }

    body.modal-open-mobile.dark-mode,
    body.dark-mode.modal-open-mobile {
        background: #242424 !important;
    }
}

/* =================================================================
   MODAL OVERLAY (Backdrop)
   ================================================================= */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal-overlay);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    padding: 20px;
    overflow-y: auto;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* =================================================================
   MODAL CONTAINER
   ================================================================= */

.modal-container {
    background: white;
    border-radius: .25rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    position: relative;
    z-index: var(--z-modal-content);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    transform: scale(0.9) translateY(-20px);
    transition: transform 0.3s ease;
    width: 100%;
    margin: auto;
}

.modal-overlay.active .modal-container {
    transform: scale(1) translateY(0);
}

/* =================================================================
   MODAL SIZES
   ================================================================= */

.modal-small {
    max-width: 400px;
}

.modal-medium {
    max-width: 600px;
}

.modal-large {
    max-width: 700px;
}

.modal-xlarge {
    max-width: 1000px;
}

.modal-full {
    max-width: 95%;
    max-height: 95vh;
}

/* =================================================================
   MODAL CONTENT STRUCTURE
   ================================================================= */

.modal-content {
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    overflow: hidden;
}

/* Modal Header */
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .5rem 1.75rem;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #1f2937;
    font-family: var(--font-main);
    margin: 0;
    line-height: 1.4;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: #6b7280;
    cursor: pointer;
    padding: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background-color 0.2s, color 0.2s;
    flex-shrink: 0;
}

.modal-close:hover {
    color: #1f2937;
}

.modal-close:active {
    background-color: #e5e7eb;
}

/* Modal Body */
.modal-body {
    padding: 1rem 1.175rem;
    overflow-y: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Modal Footer */
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 1rem 1.75rem;
    border-top: 1px solid rgba(0, 0, 0, 0.125);
    flex-shrink: 0;
}

/* =================================================================
   MODAL FORMS
   ================================================================= */

.modal-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

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

.modal-form-group {
    display: flex;
    flex-direction: column;
    gap: 0.0625rem;
}

.modal-form-group label {
    font-weight: 600;
    color: #374151;
    font-size: 0.875rem;
    font-family: var(--font-main);
    margin-left: 1.25rem;
}

.modal-form-group input,
.modal-form-group select,
.modal-form-group textarea {
    padding: 0.25rem 0.5rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.875rem;
    color: #1f2937;
    font-family: var(--font-main);
    transition: border-color 0.2s, box-shadow 0.2s;
    background: white;
}

.modal-form-group input::placeholder,
.modal-form-group textarea::placeholder {
    color: rgba(0, 0, 0, 0.4);
    font-weight: 400;
}

.modal-form-group input:focus,
.modal-form-group select:focus,
.modal-form-group textarea:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.modal-form-group textarea {
    resize: vertical;
    min-height: 6.25rem;
    font-family: var(--font-main);
}

.modal-form-group input[type="checkbox"],
.modal-form-group input[type="radio"] {
    width: auto;
    margin-right: 0.5rem;
}

/* Form validation states */
.modal-form-group input.error,
.modal-form-group select.error,
.modal-form-group textarea.error {
    border-color: #ef4444;
}

.modal-form-group input.success,
.modal-form-group select.success,
.modal-form-group textarea.success {
    border-color: #10b981;
}

.modal-form-error {
    color: #ef4444;
    font-size: 0.8125rem;
    margin-top: 0.25rem;
}

.modal-form-help {
    color: #6b7280;
    font-size: 0.8125rem;
    margin-top: 0.25rem;
}

/* =================================================================
   FORM SECTIONS
   ================================================================= */

.form-section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(0, 0, 0, 0.125);
}

.form-section-title {
    font-size: 1rem;
    font-weight: 600;
    color: #1f2937;
    margin: 0 0 1rem 0;
    font-family: var(--font-main);
}

/* =================================================================
   COMPONENT ROWS (for Final Products and similar)
   ================================================================= */

.component-row {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr) auto;
    gap: 0.5rem;
    align-items: end;
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.component-row:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.component-row .modal-form-group {
    margin-top: 0 !important;
}

.component-row .modal-form-group label {
    font-size: 0.75rem;
    padding-left: 0rem !important;
}

.component-row select,
.component-row input {
    font-size: 0.85rem;
    min-width: 0;
    width: 100%;
}

.btn-remove-component {
    background: rgba(231, 76, 60, 0.35);
    color: #c0392b;
    border: 1px solid rgba(231, 76, 60, 0.1);
    border-radius: .25rem;
    padding: .25rem .8rem !important;
    font-size: 1.3rem;
    font-weight: 400;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.btn-remove-component:hover {
    background: rgba(231, 76, 60, 0.25);
    border-color: rgba(231, 76, 60, 0.5);
}

.btn-add-component {
    background: rgba(52, 152, 219, 0.25);
    color: #2980b9;
    border: 1px solid rgba(52, 152, 219, 0.1);
    border-radius: .25rem;
    padding: .3rem 1rem;
    font: var(--font-main);
    font-size: .85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    width: fit-content;
    margin-top: 0.5rem;
    margin-left: auto;
    display: block;
    margin-right: .5rem;
}

.btn-add-component:hover {
    background: rgba(52, 152, 219, 0.25);
    border-color: rgba(52, 152, 219, 0.5);
}

#components-container,
#edit-components-container {
    border-radius: .25rem;
    padding: .5rem;
    background: rgba(0, 0, 0, 0.02);
    margin-top: 0.5rem;
    margin-bottom: 0.125rem;
    overflow: hidden;
}

/* =================================================================
   MODAL BUTTONS
   ================================================================= */

.modal-footer .btn,
.modal-footer button {
    padding: 0.25rem 1rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 600;
    font-family: var(--font-main);
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary {
    background: #3b82f6;
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

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

.btn-secondary:hover {
    background: #4b5563;
}

.btn-success {
    background: #10b981;
    color: white;
}

.btn-success:hover {
    background: #059669;
}

.btn-danger {
    background: #ef4444;
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-cancel,
.btn-outline {
    background: transparent;
    color: #6b7280;
    border: 1px solid #d1d5db;
}

.btn-cancel:hover,
.btn-outline:hover {
    background: #f9fafb;
    border-color: #9ca3af;
    color: #374151;
}

.btn:disabled,
button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* =================================================================
   SIDEBAR BLUR EFFECT
   ================================================================= */

.sidebar.modal-blur {
    filter: blur(3px);
    pointer-events: none;
    transition: filter 0.3s ease;
}

.hamburger.hidden {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

/* =================================================================
   RESPONSIVE DESIGN
   ================================================================= */

@media (max-width: 768px) {
    .modal-overlay {
        /* wall handles the solid background on mobile */
        background: transparent !important;
        backdrop-filter: none;
        padding: 0;
    }

    .modal-container {
        max-height: 100vh;
        height: 100vh;
        max-width: 100%;
        border-radius: 0;
        margin: 0;
    }

    .modal-content {
        height: 100vh;
    }

    .modal-small,
    .modal-medium,
    .modal-large,
    .modal-xlarge {
        max-width: 100%;
        max-height: 100vh;
        height: 100vh;
        border-radius: 0;
    }

    .modal-header {
        padding: 1rem;
        justify-content: center;
        text-align: center;
        position: relative;
    }

    .modal-title {
        font-size: 18px;
        text-align: center;
        flex: 1;
    }

    .modal-close {
        position: absolute;
        right: 20px;
        top: 50%;
        transform: translateY(-50%);
    }

    .modal-body {
        padding: 20px;
    }

    .modal-footer {
        padding: 16px 20px;
        flex-direction: column-reverse;
    }

    .modal-footer .btn,
    .modal-footer button {
        width: 100%;
    }

    .modal-form-row {
        flex-direction: column;
        gap: 20px;
    }

    .modal-content {
        margin-top: 2rem;
    }

    .modal-form-group label,
    .form-group label {
        font-size: 1rem !important;
    }
}

@media (max-width: 480px) {
    .modal-overlay {
        padding: 0;
    }

    .modal-container {
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
    }

    .modal-header {
        padding: 0rem;
        justify-content: center;
        text-align: center;
        position: relative;
    }

    .modal-title {
        font-size: 18px;
        text-align: center;
        flex: 1;
    }

    .modal-close {
        position: absolute;
        right: 20px;
        top: 50%;
        transform: translateY(-50%);
    }

    .modal-body {
        padding: 1rem 1rem 0rem 1rem;
        flex: 1;
        overflow-y: auto;
    }

    .modal-footer {
        padding: 16px 20px 0rem 20px;
    }
    

    .modal-form-group label,
    .form-group label {
        font-size: 1.125rem !important;
    }

    .modal-form-group input,
    .modal-form-group select,
    .modal-form-group textarea,
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 1rem !important;
    }

    .btn-remove-component {
        width: 100%;
        padding: 0.75rem 1rem !important;
        font-size: 1rem !important;
        border-radius: 0.25rem;
        margin-top: 0.25rem;
    }

    .btn-add-component {
        padding: 0.75rem 1rem;
        font-size: 1rem;
        width: 87%;
        margin: 0 auto;
        margin-top: 0.75rem;
    }

    #components-container,
    #edit-components-container {
        padding: 0.75rem;
        margin-top: 0.75rem;
        margin-bottom: 0.75rem;
        width: 87%;
        margin: 0 auto;
    }

    .component-row {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        margin-bottom: 1rem;
        padding-bottom: 1rem;
        border-bottom: 2px solid rgba(0, 0, 0, 0.1);
    }

    .component-row:last-child {
        margin-bottom: 0.5rem;
    }

    .component-row .modal-form-group {
        width: 100%;
        margin-bottom: 0 !important;
    }

    .component-row .modal-form-group label {
        font-size: 1rem !important;
        padding-left: 0.75rem !important;
        font-weight: 600;
    }

    .component-row select,
    .component-row input {
        font-size: 1rem !important;
        padding: 0.65rem 0.75rem !important;
        width: 100%;
        min-width: 0;
    }
}

/* =================================================================
   ACCESSIBILITY
   ================================================================= */

.modal-overlay[aria-modal="true"] {
    isolation: isolate;
}

.modal-close:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .modal-overlay,
    .modal-container {
        transition: none;
    }
}

/* =================================================================
   VIEW MODE (Read-only) STYLES
   ================================================================= */

/* Disabled/readonly inputs for view mode */
.modal-form-group input:disabled,
.modal-form-group select:disabled,
.modal-form-group textarea:disabled {
    background: rgba(0, 0, 0, 0.03);
    cursor: default;
    opacity: 0.9;
}

/* Stock input coloring for view mode */
.modal-form-group input.stock-input.low {
    color: #e74c3c;
    background-color: rgba(231, 76, 60, 0.1);
    border-color: rgba(231, 76, 60, 0.3);
}

.modal-form-group input.stock-input.okay {
    color: #b8860b;
    background-color: rgba(241, 196, 15, 0.1);
    border-color: rgba(241, 196, 15, 0.3);
}

.modal-form-group input.stock-input.normal,
.modal-form-group input.stock-input.good {
    color: rgb(45, 128, 48);
    background-color: rgba(76, 175, 80, 0.1);
    border-color: rgba(76, 175, 80, 0.3);
}

/* Components view container for final products */
.components-view-container {
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 0.25rem;
    padding: 0.75rem;
    margin-top: 0.5rem;
}

.component-view-item {
    padding: 0.4rem 0.5rem;
    font-size: 0.875rem;
    color: #1f2937;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

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

.component-view-item .component-qty {
    color: rgba(0, 0, 0, 0.5);
    font-weight: 500;
}

/* =================================================================
   SUGGESTIONS SECTION (AI/Analytics)
   ================================================================= */

.suggestions-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.suggestion-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem;
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 0.5rem;
    transition: all 0.2s ease;
}

.suggestion-item:hover {
    background: rgba(0, 0, 0, 0.04);
}

.suggestion-item.critical {
    background: rgba(231, 76, 60, 0.08);
    border-color: rgba(231, 76, 60, 0.25);
}

.suggestion-item.warning {
    background: rgba(241, 196, 15, 0.08);
    border-color: rgba(241, 196, 15, 0.25);
}

.suggestion-item.good {
    background: rgba(76, 175, 80, 0.08);
    border-color: rgba(76, 175, 80, 0.25);
}

.suggestion-item.insight {
    background: rgba(59, 130, 246, 0.06);
    border-color: rgba(59, 130, 246, 0.2);
}

.suggestion-item.action {
    background: rgba(139, 92, 246, 0.06);
    border-color: rgba(139, 92, 246, 0.2);
}

.suggestion-item.velocity {
    background: rgba(16, 185, 129, 0.06);
    border-color: rgba(16, 185, 129, 0.2);
}

.suggestion-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 0.375rem;
    color: #6b7280;
}

.suggestion-item.critical .suggestion-icon {
    background: rgba(231, 76, 60, 0.15);
    color: #e74c3c;
}

.suggestion-item.warning .suggestion-icon {
    background: rgba(241, 196, 15, 0.15);
    color: #d4a600;
}

.suggestion-item.good .suggestion-icon {
    background: rgba(76, 175, 80, 0.15);
    color: #4caf50;
}

.suggestion-item.insight .suggestion-icon {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
}

.suggestion-item.action .suggestion-icon {
    background: rgba(139, 92, 246, 0.15);
    color: #8b5cf6;
}

.suggestion-item.velocity .suggestion-icon {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
}

.suggestion-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.suggestion-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(0, 0, 0, 0.5);
}

.suggestion-value {
    font-size: 0.875rem;
    color: #1f2937;
    line-height: 1.4;
}

.suggestion-item.critical .suggestion-value {
    color: #c0392b;
    font-weight: 600;
}

.suggestion-item.warning .suggestion-value {
    color: #b8860b;
    font-weight: 500;
}

/* Suggestion Badges */
.suggestion-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.suggestion-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.3rem 0.6rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-radius: 0.25rem;
    background: rgba(0, 0, 0, 0.05);
    color: #6b7280;
}

.suggestion-badge.critical {
    background: rgba(231, 76, 60, 0.15);
    color: #c0392b;
}

.suggestion-badge.high {
    background: rgba(230, 126, 34, 0.15);
    color: #d35400;
}

.suggestion-badge.medium {
    background: rgba(241, 196, 15, 0.15);
    color: #b8860b;
}

.suggestion-badge.fast {
    background: rgba(231, 76, 60, 0.15);
    color: #c0392b;
}

.suggestion-badge.slow {
    background: rgba(149, 165, 166, 0.2);
    color: #7f8c8d;
}

.suggestion-badge.dead {
    background: rgba(52, 73, 94, 0.15);
    color: #34495e;
}

.suggestion-badge.seasonal {
    background: rgba(155, 89, 182, 0.15);
    color: #8e44ad;
}

.suggestion-badge.sporadic {
    background: rgba(52, 152, 219, 0.15);
    color: #2980b9;
}

.suggestion-badge.regular {
    background: rgba(76, 175, 80, 0.15);
    color: #27ae60;
}

/* =================================================================
   UTILITY CLASSES
   ================================================================= */

.modal-scrollable-body {
    max-height: 60vh;
    overflow-y: auto;
}

.modal-no-padding .modal-body {
    padding: 0;
}

.modal-center-content .modal-body {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.modal-loading {
    pointer-events: none;
    opacity: 0.6;
}

.modal-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 4px solid #f3f4f6;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: modal-spin 0.8s linear infinite;
}

@keyframes modal-spin {
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* =================================================================
   DARK MODE SUPPORT
   ================================================================= */

body.dark-mode .modal-overlay {
    background: rgba(0, 0, 0, 0.7);
}

body.dark-mode .modal-container {
    background: #242424;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

body.dark-mode .modal-header,
body.dark-mode .modal-footer {
    border-color: #374151;
}

body.dark-mode .modal-title {
    color: #f9fafb;
}

body.dark-mode .modal-close {
    color: #9ca3af;
}

body.dark-mode .modal-close:hover {
    background-color: #374151;
    color: #f9fafb;
}

body.dark-mode .modal-close:active {
    background-color: #4b5563;
}

body.dark-mode .modal-form-group label {
    color: #e5e7eb;
}

body.dark-mode .modal-form-group input,
body.dark-mode .modal-form-group select,
body.dark-mode .modal-form-group textarea {
    background: #181818;
    border-color: #36404e;
    color: #f9fafb;
}

body.dark-mode .modal-form-group input::placeholder,
body.dark-mode .modal-form-group textarea::placeholder {
    color: #6b7280;
}

body.dark-mode .modal-form-group input::placeholder,
body.dark-mode .modal-form-group textarea::placeholder {
    color: #6b7280;
}

body.dark-mode .modal-form-group input:focus,
body.dark-mode .modal-form-group select:focus,
body.dark-mode .modal-form-group textarea:focus {
    border-color: #3b82f6;
    background: #374151;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

body.dark-mode .modal-form-group input:hover,
body.dark-mode .modal-form-group select:hover,
body.dark-mode .modal-form-group textarea:hover {
    border-color: #6b7280;
}

body.dark-mode .modal-form-help {
    color: #9ca3af;
}

body.dark-mode .modal-form-error {
    color: #f87171;
}

body.dark-mode .btn-cancel,
body.dark-mode .btn-outline {
    color: #d1d5db;
    border-color: #4b5563;
    background: transparent;
}

body.dark-mode .btn-cancel:hover,
body.dark-mode .btn-outline:hover {
    background: #374151;
    border-color: #6b7280;
    color: #f9fafb;
}

body.dark-mode .btn-secondary {
    background: #4b5563;
}

body.dark-mode .btn-secondary:hover {
    background: #6b7280;
}

body.dark-mode .modal-body::-webkit-scrollbar-track {
    background: #374151;
}

body.dark-mode .modal-body::-webkit-scrollbar-thumb {
    background: #6b7280;
}

body.dark-mode .modal-body::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

body.dark-mode .modal-loading::after {
    border-color: #4b5563;
    border-top-color: #3b82f6;
}

body.dark-mode .component-row {
    border-bottom-color: rgba(255, 255, 255, 0.08);
}

body.dark-mode #components-container,
body.dark-mode #edit-components-container {
    border-color: rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.02);
}

body.dark-mode .btn-remove-component {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.4);
}

body.dark-mode .btn-remove-component:hover {
    background: rgba(239, 68, 68, 0.3);
    border-color: rgba(239, 68, 68, 0.6);
}

body.dark-mode .btn-add-component {
    background: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
    border-color: rgba(59, 130, 246, 0.4);
}

body.dark-mode .btn-add-component:hover {
    background: rgba(59, 130, 246, 0.3);
    border-color: rgba(59, 130, 246, 0.6);
}

/* View Mode Dark Mode */
body.dark-mode .modal-form-group input:disabled,
body.dark-mode .modal-form-group select:disabled,
body.dark-mode .modal-form-group textarea:disabled {
    background: rgba(255, 255, 255, 0.03);
    color: rgba(255, 255, 255, 0.8);
}

body.dark-mode .modal-form-group input.stock-input.low {
    color: #ff6b6b;
    background-color: rgba(255, 107, 107, 0.15);
    border-color: rgba(255, 107, 107, 0.4);
}

body.dark-mode .modal-form-group input.stock-input.okay {
    color: #ffd54f;
    background-color: rgba(255, 193, 7, 0.15);
    border-color: rgba(255, 193, 7, 0.4);
}

body.dark-mode .modal-form-group input.stock-input.normal,
body.dark-mode .modal-form-group input.stock-input.good {
    color: rgb(150, 230, 160);
    background-color: rgba(100, 200, 120, 0.15);
    border-color: rgba(100, 200, 120, 0.4);
}

body.dark-mode .components-view-container {
    background: rgba(255, 255, 255, 0.02);
    border-color: rgba(255, 255, 255, 0.08);
}

body.dark-mode .component-view-item {
    color: #f9fafb;
    border-bottom-color: rgba(255, 255, 255, 0.05);
}

body.dark-mode .component-view-item .component-qty {
    color: rgba(255, 255, 255, 0.5);
}

/* Suggestions Dark Mode */
body.dark-mode .suggestions-container {
    color: #f9fafb;
}

body.dark-mode .suggestion-item {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.08);
}

body.dark-mode .suggestion-item:hover {
    background: rgba(255, 255, 255, 0.06);
}

body.dark-mode .suggestion-item.critical {
    background: rgba(255, 107, 107, 0.12);
    border-color: rgba(255, 107, 107, 0.3);
}

body.dark-mode .suggestion-item.warning {
    background: rgba(255, 193, 7, 0.12);
    border-color: rgba(255, 193, 7, 0.3);
}

body.dark-mode .suggestion-item.good {
    background: rgba(100, 200, 120, 0.12);
    border-color: rgba(100, 200, 120, 0.3);
}

body.dark-mode .suggestion-item.insight {
    background: rgba(96, 165, 250, 0.1);
    border-color: rgba(96, 165, 250, 0.25);
}

body.dark-mode .suggestion-item.action {
    background: rgba(167, 139, 250, 0.1);
    border-color: rgba(167, 139, 250, 0.25);
}

body.dark-mode .suggestion-item.velocity {
    background: rgba(52, 211, 153, 0.1);
    border-color: rgba(52, 211, 153, 0.25);
}

body.dark-mode .suggestion-icon {
    background: rgba(255, 255, 255, 0.08);
    color: #9ca3af;
}

body.dark-mode .suggestion-item.critical .suggestion-icon {
    background: rgba(255, 107, 107, 0.2);
    color: #ff6b6b;
}

body.dark-mode .suggestion-item.warning .suggestion-icon {
    background: rgba(255, 193, 7, 0.2);
    color: #ffc107;
}

body.dark-mode .suggestion-item.good .suggestion-icon {
    background: rgba(100, 200, 120, 0.2);
    color: #64c878;
}

body.dark-mode .suggestion-item.insight .suggestion-icon {
    background: rgba(96, 165, 250, 0.2);
    color: #60a5fa;
}

body.dark-mode .suggestion-item.action .suggestion-icon {
    background: rgba(167, 139, 250, 0.2);
    color: #a78bfa;
}

body.dark-mode .suggestion-item.velocity .suggestion-icon {
    background: rgba(52, 211, 153, 0.2);
    color: #34d399;
}

body.dark-mode .suggestion-label {
    color: rgba(255, 255, 255, 0.5);
}

body.dark-mode .suggestion-value {
    color: #f3f4f6;
}

body.dark-mode .suggestion-item.critical .suggestion-value {
    color: #ff8a8a;
}

body.dark-mode .suggestion-item.warning .suggestion-value {
    color: #ffd54f;
}

body.dark-mode .suggestion-badge {
    background: rgba(255, 255, 255, 0.08);
    color: #9ca3af;
}

body.dark-mode .suggestion-badge.critical {
    background: rgba(255, 107, 107, 0.2);
    color: #ff8a8a;
}

body.dark-mode .suggestion-badge.high {
    background: rgba(251, 146, 60, 0.2);
    color: #fb923c;
}

body.dark-mode .suggestion-badge.medium {
    background: rgba(255, 193, 7, 0.2);
    color: #ffd54f;
}

body.dark-mode .suggestion-badge.fast {
    background: rgba(255, 107, 107, 0.2);
    color: #ff8a8a;
}

body.dark-mode .suggestion-badge.slow {
    background: rgba(156, 163, 175, 0.2);
    color: #9ca3af;
}

body.dark-mode .suggestion-badge.dead {
    background: rgba(107, 114, 128, 0.25);
    color: #9ca3af;
}

body.dark-mode .suggestion-badge.seasonal {
    background: rgba(192, 132, 252, 0.2);
    color: #c084fc;
}

body.dark-mode .suggestion-badge.sporadic {
    background: rgba(96, 165, 250, 0.2);
    color: #60a5fa;
}

body.dark-mode .suggestion-badge.regular {
    background: rgba(100, 200, 120, 0.2);
    color: #64c878;
}

/* =================================================================
   SCOPED UNIVERSAL MODAL OVERRIDES
   Prevent page-level .modal-* CSS from breaking the unified modal.
   ================================================================= */

.modal-overlay[data-modal-id] {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal-overlay);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
}

.modal-overlay[data-modal-id].active {
    opacity: 1;
    visibility: visible;
}

.modal-overlay[data-modal-id] .modal-container {
    background: white;
    border-radius: .25rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    position: relative;
    z-index: var(--z-modal-content);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    transform: scale(0.9) translateY(-20px);
    transition: transform 0.3s ease;
    width: 100%;
    margin: auto;
}

.modal-overlay[data-modal-id].active .modal-container {
    transform: scale(1) translateY(0);
}

.modal-overlay[data-modal-id] .modal-container.modal-small { max-width: 400px; }
.modal-overlay[data-modal-id] .modal-container.modal-medium { max-width: 600px; }
.modal-overlay[data-modal-id] .modal-container.modal-large { max-width: 700px; }
.modal-overlay[data-modal-id] .modal-container.modal-xlarge { max-width: 1000px; }
.modal-overlay[data-modal-id] .modal-container.modal-full { max-width: 95%; max-height: 95vh; }

.modal-overlay[data-modal-id] .modal-content {
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    overflow: hidden;
    width: 100%;
    max-width: none;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
}

.modal-overlay[data-modal-id] .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .5rem 1.75rem;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.modal-overlay[data-modal-id] .modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #1f2937;
    font-family: var(--font-main);
    margin: 0;
    line-height: 1.4;
}

.modal-overlay[data-modal-id] .modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: #6b7280;
    cursor: pointer;
    padding: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background-color 0.2s, color 0.2s;
    flex-shrink: 0;
}

.modal-overlay[data-modal-id] .modal-body {
    padding: 1rem 1.175rem;
    overflow-y: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

.modal-overlay[data-modal-id] .modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 1rem 1.75rem;
    border-top: 1px solid rgba(0, 0, 0, 0.125);
    flex-shrink: 0;
}

body.dark-mode .modal-overlay[data-modal-id] {
    background: rgba(0, 0, 0, 0.7);
}

body.dark-mode .modal-overlay[data-modal-id] .modal-container {
    background: #242424;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

body.dark-mode .modal-overlay[data-modal-id] .modal-header,
body.dark-mode .modal-overlay[data-modal-id] .modal-footer {
    border-color: #374151;
}

body.dark-mode .modal-overlay[data-modal-id] .modal-title {
    color: #f9fafb;
}

body.dark-mode .modal-overlay[data-modal-id] .modal-close {
    color: #9ca3af;
}

@media (max-width: 768px) {
    .modal-overlay[data-modal-id] {
        background: transparent !important;
        backdrop-filter: none;
        padding: 0;
    }

    .modal-overlay[data-modal-id] .modal-container {
        max-height: 100vh;
        height: 100vh;
        max-width: 100%;
        border-radius: 0;
        margin: 0;
    }

    .modal-overlay[data-modal-id] .modal-content {
        height: 100vh;
        margin-top: 2rem;
    }

    .modal-overlay[data-modal-id] .modal-container.modal-small,
    .modal-overlay[data-modal-id] .modal-container.modal-medium,
    .modal-overlay[data-modal-id] .modal-container.modal-large,
    .modal-overlay[data-modal-id] .modal-container.modal-xlarge {
        max-width: 100%;
        max-height: 100vh;
        height: 100vh;
        border-radius: 0;
    }

    .modal-overlay[data-modal-id] .modal-header {
        padding: 1rem;
        justify-content: center;
        text-align: center;
        position: relative;
    }

    .modal-overlay[data-modal-id] .modal-close {
        position: absolute;
        right: 20px;
        top: 50%;
        transform: translateY(-50%);
    }

    .modal-overlay[data-modal-id] .modal-body {
        padding: 20px;
    }

    .modal-overlay[data-modal-id] .modal-footer {
        padding: 16px 20px;
        flex-direction: column-reverse;
    }

    .modal-overlay[data-modal-id] .modal-footer .btn,
    .modal-overlay[data-modal-id] .modal-footer button {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .modal-overlay[data-modal-id] .modal-container {
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
    }

    .modal-overlay[data-modal-id] .modal-header {
        padding: 0rem;
        justify-content: center;
        text-align: center;
        position: relative;
    }

    .modal-overlay[data-modal-id] .modal-body {
        padding: 1rem 1rem 0rem 1rem;
        flex: 1;
        overflow-y: auto;
    }

    .modal-overlay[data-modal-id] .modal-footer {
        padding: 16px 20px 0rem 20px;
    }
}
