/* Dark Mode & Layout Styles */
/* Uses Tailwind's dark: variant pattern with custom properties */

/* =============================================================================
   Sidebar Layout & Animation
   ============================================================================= */

/* Base sidebar styles */
#sidebar {
    width: 256px;
    transition: width 0.2s ease-in-out;
    background-color: #ffffff;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-right: 1px solid #e5e7eb;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
}

.dark #sidebar {
    background-color: #111827;
    border-color: #374151;
}

/* Collapsed sidebar state */
#sidebar.sidebar-collapsed {
    width: 72px;
}

#sidebar.sidebar-collapsed .sidebar-label {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

#sidebar.sidebar-collapsed .nav-section-title {
    opacity: 0;
    height: 0;
    margin: 0;
    padding: 0;
}

#sidebar.sidebar-collapsed .sidebar-header {
    justify-content: center;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    position: relative;
}

#sidebar.sidebar-collapsed .sidebar-header a {
    justify-content: center;
}

/* Logo switching for collapsed state */
.sidebar-collapsed-logo {
    display: none !important;
}

.sidebar-expanded-logo {
    display: block;
}

#sidebar.sidebar-collapsed .sidebar-collapsed-logo {
    display: flex !important;
}

#sidebar.sidebar-collapsed .sidebar-expanded-logo {
    display: none !important;
}

/* Position toggle button on the border line (expanded state) */
.sidebar-header {
    position: relative;
}

.sidebar-toggle {
    position: absolute !important;
    right: -12px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 50;
}

/* Keep toggle button on border when collapsed */
#sidebar.sidebar-collapsed .sidebar-toggle {
    right: -12px;
}

#sidebar.sidebar-collapsed .nav-item {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

#sidebar.sidebar-collapsed .sidebar-footer {
    justify-content: center;
    padding: 0.75rem 0.5rem;
}

/* Collapsed sidebar: hide expanded rows, show collapsed items */
#sidebar.sidebar-collapsed .sidebar-label-row {
    display: none;
}

#sidebar.sidebar-collapsed .sidebar-collapsed-item {
    display: flex !important;
}

/* Sidebar label transition */
.sidebar-label {
    transition: opacity 0.15s ease-in-out, width 0.15s ease-in-out;
}

/* Main content margin */
.main-content {
    margin-left: 256px;
    transition: margin-left 0.2s ease-in-out;
    min-height: 100vh;
}

.main-content.sidebar-collapsed-margin {
    margin-left: 72px;
}

/* Mobile sidebar styles */
@media (max-width: 1023px) {
    #sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        width: 280px;
        z-index: 50;
    }

    #sidebar.mobile-open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .main-content.sidebar-collapsed-margin {
        margin-left: 0;
    }
}

/* Mobile overlay */
#mobileOverlay {
    transition: opacity 0.2s ease-in-out;
    opacity: 0;
}

#mobileOverlay.opacity-100 {
    opacity: 1;
}

/* Navigation item hover tooltip for collapsed state */
#sidebar.sidebar-collapsed .nav-item {
    position: relative;
}

#sidebar.sidebar-collapsed .nav-item::after {
    content: attr(title);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    background-color: #1f2937;
    color: white;
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease-in-out;
    margin-left: 0.5rem;
    z-index: 100;
}

#sidebar.sidebar-collapsed .nav-item:hover::after {
    opacity: 1;
}

/* =============================================================================
   Base dark mode colors
   ============================================================================= */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f3f4f6;
    --bg-tertiary: #e5e7eb;
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;
    --border-color: #e5e7eb;
    --card-bg: #ffffff;
    --sidebar-bg: #ffffff;
    --header-bg: #ffffff;
    --input-bg: #ffffff;
    --hover-bg: #f9fafb;
    --active-bg: #eff6ff;
    --active-border: #2563eb;
    --active-text: #1d4ed8;
}

.dark {
    --bg-primary: #111827;
    --bg-secondary: #1f2937;
    --bg-tertiary: #374151;
    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --text-muted: #9ca3af;
    --border-color: #374151;
    --card-bg: #1f2937;
    --sidebar-bg: #111827;
    --header-bg: #1f2937;
    --input-bg: #374151;
    --hover-bg: #374151;
    --active-bg: #1e3a5f;
    --active-border: #3b82f6;
    --active-text: #60a5fa;
}

/* Dark mode overrides */
.dark body {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

/* Sidebar */
.dark aside {
    background-color: var(--sidebar-bg) !important;
    border-color: var(--border-color) !important;
}

.dark aside h1 {
    color: #60a5fa !important;
}

.dark .sidebar-item {
    color: var(--text-secondary) !important;
}

.dark .sidebar-item:hover {
    background-color: var(--hover-bg) !important;
    color: var(--text-primary) !important;
}

.dark .sidebar-item.bg-blue-50 {
    background-color: var(--active-bg) !important;
    color: var(--active-text) !important;
}

.dark nav h3 {
    color: var(--text-muted) !important;
}

/* Header */
.dark header {
    background-color: var(--header-bg) !important;
    border-color: var(--border-color) !important;
}

.dark header h2 {
    color: var(--text-primary) !important;
}

.dark header p {
    color: var(--text-secondary) !important;
}

/* Cards and panels */
.dark .bg-white {
    background-color: var(--card-bg) !important;
}

.dark .bg-gray-50 {
    background-color: var(--bg-tertiary) !important;
}

.dark .bg-gray-100 {
    background-color: var(--bg-secondary) !important;
}

/* Text colors */
.dark .text-gray-900 {
    color: var(--text-primary) !important;
}

.dark .text-gray-700 {
    color: var(--text-secondary) !important;
}

.dark .text-gray-600 {
    color: var(--text-secondary) !important;
}

.dark .text-gray-500 {
    color: var(--text-muted) !important;
}

.dark .text-gray-400 {
    color: var(--text-muted) !important;
}

/* Borders */
.dark .border-gray-200 {
    border-color: var(--border-color) !important;
}

.dark .border-gray-300 {
    border-color: var(--border-color) !important;
}

.dark .divide-gray-200 > * + * {
    border-color: var(--border-color) !important;
}

/* Form inputs */
.dark input,
.dark select,
.dark textarea {
    background-color: var(--input-bg) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

.dark input::placeholder,
.dark textarea::placeholder {
    color: var(--text-muted) !important;
}

.dark input:focus,
.dark select:focus,
.dark textarea:focus {
    border-color: #3b82f6 !important;
    outline: none;
}

/* Autofill styling for dark mode - override browser defaults */
.dark input:-webkit-autofill,
.dark input:-webkit-autofill:hover,
.dark input:-webkit-autofill:focus,
.dark input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 30px var(--input-bg) inset !important;
    -webkit-text-fill-color: var(--text-primary) !important;
    caret-color: var(--text-primary) !important;
    transition: background-color 5000s ease-in-out 0s;
}

/* Firefox autofill */
.dark input:autofill {
    background-color: var(--input-bg) !important;
    color: var(--text-primary) !important;
}

/* Tables */
.dark table {
    background-color: var(--card-bg) !important;
}

.dark thead {
    background-color: var(--bg-tertiary) !important;
}

.dark th {
    color: var(--text-muted) !important;
}

.dark tbody tr {
    background-color: var(--card-bg) !important;
}

.dark tbody tr:hover {
    background-color: var(--hover-bg) !important;
}

/* Modals */
.dark .bg-black {
    background-color: rgba(0, 0, 0, 0.7) !important;
}

/* Shadows - make them darker in dark mode */
.dark .shadow,
.dark .shadow-sm,
.dark .shadow-md,
.dark .shadow-lg,
.dark .shadow-xl {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.2) !important;
}

/* Status badges - preserve colors but adjust backgrounds */
.dark .bg-green-100 {
    background-color: rgba(34, 197, 94, 0.3) !important;
}

.dark .bg-yellow-100 {
    background-color: rgba(234, 179, 8, 0.3) !important;
}

.dark .bg-red-100 {
    background-color: rgba(239, 68, 68, 0.3) !important;
}

.dark .bg-blue-100 {
    background-color: rgba(59, 130, 246, 0.3) !important;
}

.dark .bg-orange-100 {
    background-color: rgba(249, 115, 22, 0.3) !important;
}

.dark .bg-purple-100 {
    background-color: rgba(168, 85, 247, 0.3) !important;
}

/* Text colors for status badges in dark mode - brighten for readability */
.dark .text-blue-700 {
    color: #60a5fa !important;
}

.dark .text-yellow-700 {
    color: #fbbf24 !important;
}

.dark .text-green-700 {
    color: #4ade80 !important;
}

.dark .text-purple-700 {
    color: #c084fc !important;
}

.dark .text-red-700 {
    color: #f87171 !important;
}

.dark .text-cyan-800,
.dark .text-teal-800 {
    color: #22d3ee !important;
}

.dark .text-amber-800 {
    color: #fbbf24 !important;
}

.dark .text-green-800 {
    color: #86efac !important;
}

.dark .text-blue-800 {
    color: #60a5fa !important;
}

.dark .text-yellow-800 {
    color: #fbbf24 !important;
}

.dark .text-red-800 {
    color: #f87171 !important;
}

.dark .text-purple-800 {
    color: #c084fc !important;
}

/* Border colors for status badges in dark mode */
.dark .border-blue-300 {
    border-color: rgba(59, 130, 246, 0.5) !important;
}

.dark .border-yellow-300 {
    border-color: rgba(234, 179, 8, 0.5) !important;
}

.dark .border-green-300 {
    border-color: rgba(34, 197, 94, 0.5) !important;
}

.dark .border-purple-300 {
    border-color: rgba(168, 85, 247, 0.5) !important;
}

.dark .border-red-300 {
    border-color: rgba(239, 68, 68, 0.5) !important;
}

.dark .bg-teal-100,
.dark .bg-cyan-100,
.dark .bg-emerald-100 {
    background-color: rgba(20, 184, 166, 0.25) !important;
}

.dark .bg-gray-100 {
    background-color: var(--bg-secondary) !important;
}

/* Tab buttons - Info/Orders style tabs */
.dark .tab-btn {
    background-color: transparent !important;
    border-color: var(--border-color) !important;
    color: #d1d5db !important; /* Brighter gray for inactive tabs */
}

.dark .tab-btn:hover {
    background-color: var(--hover-bg) !important;
    color: #f3f4f6 !important;
    border-color: #6b7280 !important;
}

.dark .tab-btn.active {
    background-color: transparent !important;
    border-color: var(--active-border) !important;
    color: var(--active-text) !important;
}

/* Override text-gray-500 specifically for tab buttons in dark mode */
.dark .tab-btn.text-gray-500 {
    color: #d1d5db !important;
}

.dark .tab-btn.text-gray-500:hover {
    color: #f3f4f6 !important;
}

/* Select dropdowns */
.dark select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%239ca3af' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e") !important;
    background-position: right 0.5rem center !important;
    background-repeat: no-repeat !important;
    background-size: 1.5em 1.5em !important;
    padding-right: 2.5rem !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
}

/* Fix icon container backgrounds */
.dark .bg-teal-100 {
    background-color: rgba(20, 184, 166, 0.25) !important;
}

.dark .text-teal-600 {
    color: #2dd4bf !important;
}

/* Gray/black status badges (like Delivered) */
.dark .bg-gray-800,
.dark .bg-gray-900 {
    background-color: #4b5563 !important;
}

.dark .text-gray-800 {
    color: #e5e7eb !important;
}

/* Draft status (yellow/amber) */
.dark .bg-amber-100 {
    background-color: rgba(245, 158, 11, 0.25) !important;
}

.dark .text-amber-800 {
    color: #fbbf24 !important;
}

/* Reset button styling */
.dark button[class*="bg-gray-700"],
.dark .bg-gray-700 {
    background-color: #374151 !important;
}

.dark button[class*="bg-gray-700"]:hover {
    background-color: #4b5563 !important;
}

/* Icon colors in dark mode */
.dark .text-gray-400 svg,
.dark svg.text-gray-400 {
    color: var(--text-muted) !important;
}

/* Hover states for buttons */
.dark .hover\:bg-gray-50:hover {
    background-color: var(--hover-bg) !important;
}

.dark .hover\:bg-gray-100:hover {
    background-color: var(--bg-tertiary) !important;
}

/* Inspection panel */
.dark .inspection-panel {
    background-color: var(--card-bg) !important;
    border-color: var(--border-color) !important;
}

/* Rounded full badges (pill badges) */
.dark .rounded-full.bg-gray-100 {
    background-color: var(--bg-tertiary) !important;
}

/* API status footer */
.dark #apiStatus {
    background-color: var(--sidebar-bg) !important;
    border-color: var(--border-color) !important;
}

/* Stats cards icon backgrounds */
.dark .rounded-full[class*="bg-"][class*="-100"] {
    opacity: 0.8;
}

/* Ring focus states */
.dark .focus\:ring-blue-500:focus {
    --tw-ring-color: #3b82f6;
}

/* Scrollbar styling for dark mode */
.dark ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.dark ::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

.dark ::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.dark ::-webkit-scrollbar-thumb:hover {
    background: #4b5563;
}
