/* AI Layer Dashboard - Flowbite Pro Theme */

/* ============================================
   DARK MODE - CSS Custom Properties
   ============================================ */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --bg-card: #ffffff;
    --bg-hover: #f9fafb;
    --bg-input: #ffffff;
    --border-color: #e5e7eb;
    --border-light: #f3f4f6;
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-tertiary: #6b7280;
    --text-muted: #9ca3af;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

html.dark {
    --bg-primary: #111827;
    --bg-secondary: #1f2937;
    --bg-tertiary: #374151;
    --bg-card: #1f2937;
    --bg-hover: #374151;
    --bg-input: #374151;
    --border-color: #374151;
    --border-light: #1f2937;
    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --text-tertiary: #9ca3af;
    --text-muted: #6b7280;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3);
}

/* Apply dark mode to core layout elements */
html.dark body { background-color: var(--bg-primary); color: var(--text-primary); }
html.dark .bg-white { background-color: var(--bg-card) !important; }
html.dark .bg-gray-50, html.dark .bg-gray-100 { background-color: var(--bg-secondary) !important; }
html.dark .bg-gray-200 { background-color: var(--bg-tertiary) !important; }
html.dark .text-gray-900 { color: var(--text-primary) !important; }
html.dark .text-gray-800 { color: var(--text-primary) !important; }
html.dark .text-gray-700 { color: var(--text-secondary) !important; }
html.dark .text-gray-600 { color: var(--text-secondary) !important; }
html.dark .text-gray-500 { color: var(--text-tertiary) !important; }
html.dark .text-gray-400 { color: var(--text-muted) !important; }
html.dark .text-gray-300 { color: var(--text-muted) !important; }
html.dark .border-gray-200, html.dark .border-gray-300 { border-color: var(--border-color) !important; }
html.dark .border-gray-100 { border-color: var(--border-light) !important; }
html.dark .divide-gray-200 > :not([hidden]) ~ :not([hidden]),
html.dark .divide-gray-100 > :not([hidden]) ~ :not([hidden]) { border-color: var(--border-color) !important; }

/* Dark mode for specific components */
html.dark input, html.dark textarea, html.dark select {
    background-color: var(--bg-input) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}
html.dark input::placeholder, html.dark textarea::placeholder {
    color: var(--text-muted) !important;
}
html.dark table thead { background-color: var(--bg-secondary) !important; }
html.dark table thead th { color: var(--text-tertiary) !important; }
html.dark table tbody tr:hover { background-color: var(--bg-hover) !important; }
html.dark .shadow-sm, html.dark .shadow { box-shadow: var(--shadow-sm) !important; }
html.dark .shadow-md, html.dark .shadow-lg { box-shadow: var(--shadow-md) !important; }

/* Icon rail sidebar in dark mode */
html.dark #icon-rail { background-color: #1e1b4b !important; }
html.dark #sub-nav { background-color: var(--bg-secondary) !important; border-color: var(--border-color) !important; }
html.dark #sub-nav a:hover { background-color: var(--bg-hover) !important; }
html.dark #top-navbar { background-color: var(--bg-card) !important; border-color: var(--border-color) !important; }

/* Charts and specific elements */
html.dark .hover\:bg-gray-50:hover { background-color: var(--bg-hover) !important; }
html.dark .hover\:bg-gray-100:hover { background-color: var(--bg-tertiary) !important; }

/* Toast container in dark mode */
html.dark #toast-container > div { box-shadow: var(--shadow-md); }

/* Command palette dark mode */
html.dark #command-palette .bg-white { background-color: var(--bg-card) !important; }
html.dark #command-palette input { background-color: transparent !important; }
html.dark #command-palette kbd { background-color: var(--bg-tertiary) !important; color: var(--text-muted) !important; }

/* Skeleton loader in dark mode */
html.dark .animate-pulse .bg-gray-200 { background-color: var(--bg-tertiary) !important; }

/* ============================================
   ICON RAIL
   ============================================ */
.icon-rail-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 0.5rem;
    color: #6b7280; /* gray-500 */
    cursor: pointer;
    transition: all 0.15s ease;
    border: none;
    background: transparent;
    position: relative;
}
.icon-rail-btn svg {
    width: 24px;
    height: 24px;
}
.icon-rail-btn:hover {
    background-color: #f3f4f6; /* gray-100 */
    color: #4f46e5; /* primary-600 */
}
.icon-rail-btn.active {
    background-color: #eef2ff; /* primary-50 */
    color: #4f46e5; /* primary-600 */
}
.icon-rail-btn.active::before {
    content: '';
    position: absolute;
    left: -7px;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 0 2px 2px 0;
    background-color: #4f46e5; /* primary-600 */
}

/* ============================================
   SUB-NAV PANEL
   ============================================ */
.sub-nav-panel {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
}
.sub-nav-panel.open {
    transform: translateX(0);
}

/* Sub-nav link items */
.sub-nav-link {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151; /* gray-700 */
    border-radius: 0.5rem;
    transition: background-color 0.1s, color 0.1s;
    text-decoration: none;
    cursor: pointer;
}
.sub-nav-link:hover {
    background-color: #f3f4f6; /* gray-100 */
}
.sub-nav-link.active {
    background-color: #eef2ff; /* primary-50 */
    color: #4f46e5; /* primary-600 */
}
.sub-nav-link.active svg {
    color: #4f46e5; /* primary-600 */
}
.sub-nav-link svg {
    color: #9ca3af; /* gray-400 */
    transition: color 0.1s;
}
.sub-nav-link:hover svg {
    color: #4f46e5; /* primary-600 */
}

/* Keep old .nav-item styles for backward compat in sub-panel */
.nav-item.active {
    background-color: #eef2ff; /* primary-50 */
    color: #4f46e5; /* primary-600 */
}
.nav-item.active svg {
    color: #4f46e5; /* primary-600 */
}

/* ============================================
   MAIN CONTENT TRANSITIONS
   ============================================ */
#main-content.panel-open {
    margin-left: 17.5rem; /* w-14 (3.5rem) rail + w-56 (14rem) panel = 17.5rem */
}
#top-navbar.panel-open {
    left: 17.5rem;
}
#impersonation-banner.panel-open {
    left: 17.5rem;
}

/* ============================================
   STAT CARDS
   ============================================ */
.stat-card {
    transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

/* ============================================
   TOGGLE SWITCH (Flowbite-compatible)
   ============================================ */
.toggle-bg:after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 9999px;
    height: 1.25rem;
    width: 1.25rem;
    transition: all 0.15s ease-in-out;
}
input:checked + .toggle-bg:after {
    transform: translateX(100%);
    border-color: white;
}
input:checked + .toggle-bg {
    background-color: #4f46e5;
}

/* ============================================
   LOADING & ANIMATIONS
   ============================================ */
@keyframes spin {
    to { transform: rotate(360deg); }
}
.animate-spin {
    animation: spin 1s linear infinite;
}
@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}
.animate-pulse-dot {
    animation: pulse-dot 2s ease-in-out infinite;
}

/* ============================================
   SCROLLBAR STYLING
   ============================================ */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}
aside::-webkit-scrollbar {
    width: 4px;
}
aside::-webkit-scrollbar-thumb {
    background: #e5e7eb;
    border-radius: 2px;
}
.sub-nav-panel::-webkit-scrollbar {
    width: 4px;
}
.sub-nav-panel::-webkit-scrollbar-thumb {
    background: #e5e7eb;
    border-radius: 2px;
}

/* ============================================
   CONFIG TABS
   ============================================ */
.config-tab {
    transition: color 0.15s, border-color 0.15s;
}

/* ============================================
   TABLE ROWS
   ============================================ */
tbody tr {
    transition: background-color 0.1s;
}

/* ============================================
   MODAL
   ============================================ */
.modal-backdrop {
    backdrop-filter: blur(4px);
}

/* ============================================
   BADGES
   ============================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 9999px;
}
.badge-success { background-color: #d1fae5; color: #065f46; }
.badge-warning { background-color: #fef3c7; color: #92400e; }
.badge-danger { background-color: #fee2e2; color: #991b1b; }
.badge-info { background-color: #dbeafe; color: #1e40af; }

/* ============================================
   CARDS
   ============================================ */
.card {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
}

/* ============================================
   FORM FOCUS RINGS
   ============================================ */
input:focus, select:focus, textarea:focus {
    outline: none;
    --tw-ring-color: #6366f1;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
    border-color: #6366f1;
}

/* ============================================
   MOBILE RESPONSIVE SIDEBAR
   ============================================ */

/* Mobile overlay fade transition */
#mobile-overlay {
    transition: opacity 0.2s ease;
}

/* On mobile (<1024px), prevent panel-open from shifting content/navbar */
@media (max-width: 1023px) {
    #main-content.panel-open {
        margin-left: 0;
    }
    #top-navbar.panel-open {
        left: 0;
    }
    #impersonation-banner.panel-open {
        left: 0;
    }
}
