/* Theme variables and overrides for light, dark, and auto modes */

/* Default (light) */
body,
body[data-theme="light"] {
    background-color: #f3f4f6; /* gray-100 */
    color: #111827; /* gray-900 */
}

/* Common utility overrides for light */
body[data-theme="light"] .bg-white { background-color: #ffffff !important; }
body[data-theme="light"] .bg-gray-50 { background-color: #f9fafb !important; }
body[data-theme="light"] .bg-gray-100 { background-color: #f3f4f6 !important; }
body[data-theme="light"] .text-gray-800 { color: #1f2937 !important; }
body[data-theme="light"] .text-gray-700 { color: #374151 !important; }
body[data-theme="light"] .text-gray-600 { color: #4b5563 !important; }
body[data-theme="light"] .text-gray-500 { color: #6b7280 !important; }
body[data-theme="light"] .border-gray-200 { border-color: #e5e7eb !important; }
body[data-theme="light"] .border-gray-300 { border-color: #d1d5db !important; }

/* Dark theme */
body[data-theme="dark"] {
    background-color: #0f172a !important; /* slate-900 */
    color: #e5e7eb !important; /* gray-200 */
}

/* Panels and cards */
body[data-theme="dark"] .bg-white,
body[data-theme="dark"] .bg-gray-50 {
    background-color: #111827 !important; /* gray-900 */
}

/* Subtle backgrounds */
body[data-theme="dark"] .bg-gray-100 { background-color: #0f172a !important; }

/* Text colors - ВАЖНО: всегда делаем текст видимым */
body[data-theme="dark"] .text-gray-800 { color: #e5e7eb !important; }
body[data-theme="dark"] .text-gray-900 { color: #e5e7eb !important; }
body[data-theme="dark"] .text-black { color: #e5e7eb !important; }
body[data-theme="dark"] .text-gray-700 { color: #e5e7eb !important; }
body[data-theme="dark"] .text-gray-600 { color: #d1d5db !important; }
body[data-theme="dark"] .text-gray-500 { color: #cbd5e1 !important; }
body[data-theme="dark"] .text-gray-400 { color: #94a3b8 !important; }

/* Table text - ВАЖНО: делаем текст в таблицах всегда видимым */
body[data-theme="dark"] table { color: #e5e7eb !important; }
body[data-theme="dark"] table td { color: #e5e7eb !important; }
body[data-theme="dark"] table th { color: #cbd5e1 !important; }
body[data-theme="dark"] .text-gray-900 { color: #e5e7eb !important; }

/* Headers */
body[data-theme="dark"] h1 { color: #e5e7eb !important; }
body[data-theme="dark"] h2 { color: #e5e7eb !important; }
body[data-theme="dark"] h3 { color: #e5e7eb !important; }
body[data-theme="dark"] h4 { color: #e5e7eb !important; }
body[data-theme="dark"] p { color: #e5e7eb !important; }

/* Borders */
body[data-theme="dark"] .border-gray-200 { border-color: #1f2937 !important; }
body[data-theme="dark"] .border-gray-300 { border-color: #374151 !important; }

/* Inputs */
body[data-theme="dark"] input,
body[data-theme="dark"] select,
body[data-theme="dark"] textarea {
    background-color: #0b1220 !important; /* dark input */
    color: #e5e7eb !important;
    border-color: #374151 !important;
}

/* Tables */
body[data-theme="dark"] thead { background-color: #0b1220 !important; }
body[data-theme="dark"] tbody tr:hover { background-color: rgba(148, 163, 184, 0.08) !important; }

/* Badges */
body[data-theme="dark"] .status-badge.status-pending { background-color: #1f2937 !important; color: #e5e7eb !important; }
body[data-theme="dark"] .status-badge.status-in_transit { background-color: #1e3a8a !important; color: #bfdbfe !important; }
body[data-theme="dark"] .status-badge.status-delivered { background-color: #064e3b !important; color: #bbf7d0 !important; }
body[data-theme="dark"] .status-badge.status-delayed { background-color: #7f1d1d !important; color: #fee2e2 !important; }
body[data-theme="dark"] .status-badge.status-on_warehouse { background-color: #78350f !important; color: #fef3c7 !important; }
body[data-theme="dark"] .status-badge.status-cancelled { background-color: #7f1d1d !important; color: #fee2e2 !important; }

/* Auto theme mirrors system preference when data-theme=auto */
body[data-theme="auto"] {
    background-color: #f3f4f6;
    color: #111827;
}
@media (prefers-color-scheme: dark) {
    body[data-theme="auto"] {
        background-color: #0f172a; /* slate-900 */
        color: #e5e7eb; /* light text */
    }
    body[data-theme="auto"] .bg-white { background-color: #0b1220 !important; }
    body[data-theme="auto"] .bg-gray-50 { background-color: #0f172a !important; }
    body[data-theme="auto"] .bg-gray-100 { background-color: #111827 !important; }
    body[data-theme="auto"] .text-gray-800, 
    body[data-theme="auto"] .text-gray-900,
    body[data-theme="auto"] .text-black { color: #e5e7eb !important; }
    body[data-theme="auto"] .border-gray-200 { border-color: #1f2937 !important; }
    body[data-theme="auto"] .divide-gray-200 > :not([hidden]) ~ :not([hidden]) { border-color: #1f2937 !important; }
    body[data-theme="auto"] .status-pending { background-color: #1f2937; color: #e5e7eb; }
    body[data-theme="auto"] .status-in_transit { background-color: #1e293b; color: #c7d2fe; }
    body[data-theme="auto"] .status-delivered { background-color: #064e3b; color: #d1fae5; }
    body[data-theme="auto"] .status-delayed { background-color: #7f1d1d; color: #fee2e2; }
    body[data-theme="auto"] .status-on_warehouse { background-color: #78350f; color: #fef3c7; }
    body[data-theme="auto"] .status-cancelled { background-color: #7f1d1d; color: #fee2e2; }
    /* Lavender sidebar/buttons in auto-dark */
    body[data-theme="auto"] .bg-blue-600 { background-color: #4c3c78 !important; }
    body[data-theme="auto"] .hover\:bg-blue-700:hover { background-color: #3e3163 !important; }
    
    /* Table text in auto-dark mode */
    body[data-theme="auto"] table { color: #e5e7eb !important; }
    body[data-theme="auto"] table td { color: #e5e7eb !important; }
    body[data-theme="auto"] table th { color: #cbd5e1 !important; }
    body[data-theme="auto"] .text-gray-900 { color: #e5e7eb !important; }
}

/* Lavender sidebar/buttons in dark mode */
body[data-theme="dark"] .bg-blue-600 { background-color: #4c3c78 !important; }
body[data-theme="dark"] .bg-blue-700 { background-color: #3e3163 !important; }
body[data-theme="dark"] .hover\:bg-blue-700:hover { background-color: #3e3163 !important; }

/* Sticky sidebar */
@media (min-width: 768px) {
    #sidebar { position: sticky; top: 0; height: 100vh; z-index: 10; }
    main { min-height: 100vh; z-index: 1; }
}

/* Ensure advanced filter panel is above content */
#advanced-filter-panel { position: relative; z-index: 30; }

/* Status badges */
.status-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    text-align: center;
}

.status-pending {
    background-color: #f3f4f6;
    color: #374151;
}

.status-in_transit {
    background-color: #dbeafe;
    color: #1e40af;
}

.status-delivered {
    background-color: #d1fae5;
    color: #065f46;
}

.status-delayed {
    background-color: #fee2e2;
    color: #991b1b;
}

.status-on_warehouse {
    background-color: #fef3c7;
    color: #92400e;
}

.status-cancelled {
    background-color: #fee2e2;
    color: #991b1b;
}