/* Coreflows Premium Design System */

:root {
    --cf-bg: #0B0C14;
    --cf-surface: #161822;
    --cf-surface-2: #1F212E;
    --cf-primary: #4F46E5;
    --cf-primary-glow: rgba(79, 70, 229, 0.4);
    --cf-text: #F9FAFB;
    --cf-text-muted: #9CA3AF;
    --cf-border: rgba(255, 255, 255, 0.08);
    --cf-gradient: linear-gradient(135deg, #4F46E5 0%, #7C3AED 100%);
    --cf-sidebar-width: 280px;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--cf-bg);
    color: var(--cf-text);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4,
h5,
h6,
.navbar-brand {
    font-family: 'Outfit', sans-serif;
}

/* Glassmorphism */
.glass-card {
    background: rgba(22, 24, 34, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--cf-border);
    border-radius: 1.25rem;
}

/* Sidebar Styling - Inspired by user screenshot */
.sidebar {
    width: var(--cf-sidebar-width);
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    background-color: var(--cf-surface);
    border-right: 1px solid var(--cf-border);
    padding: 1.5rem 1rem;
    z-index: 1050;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-nav .nav-link {
    color: var(--cf-text-muted);
    padding: 0.875rem 1.25rem;
    border-radius: 12px;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.2s ease;
    font-weight: 500;
}

.sidebar-nav .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--cf-text);
}

.sidebar-nav .nav-link.active {
    background-color: rgba(79, 70, 229, 0.15);
    color: var(--cf-primary);
    position: relative;
    /* Pill style indicator handled via background or a separate border-left if desired */
}

/* Main Content Wrapper - No sidebar margin */
.main-wrapper {
    min-height: 100vh;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* App Header Navigation */
.app-header {
    background: var(--cf-surface);
    border-bottom: 1px solid var(--cf-border);
    z-index: 1030;
}

.navigation {
    min-height: 56px;
}

/* Breadcrumb Navigation */
.breadcrumb-nav .breadcrumb {
    background: transparent;
    padding: 0;
    margin: 0;
    align-items: center;
}

.breadcrumb-nav .breadcrumb-item {
    color: var(--cf-text-muted);
    font-size: 0.925rem;
    font-weight: 500;
    list-style: none;
}

.breadcrumb-nav .breadcrumb-item a {
    color: var(--cf-text-muted);
    text-decoration: none;
    transition: color 0.2s ease;
}

.breadcrumb-nav .breadcrumb-item a:hover {
    color: var(--cf-primary);
}

.breadcrumb-nav .breadcrumb-item.active {
    color: var(--cf-text);
}

.breadcrumb-nav .breadcrumb-item+.breadcrumb-item::before {
    content: "/";
    color: var(--cf-text-muted);
    padding: 0 0.75rem;
    font-weight: 300;
}

.breadcrumb-nav .breadcrumb-item .bi-house-door-fill {
    font-size: 1rem;
}

/* Navbar Dashboard */
.dashboard-navbar {
    background: rgba(11, 12, 20, 0.8);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--cf-border);
    padding: 1rem 1.5rem;
}

/* Stat Cards */
.cf-stat-card {
    background: var(--cf-surface);
    border: 1px solid var(--cf-border);
    border-radius: 1.5rem;
    padding: 1.5rem;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.cf-stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    border-color: var(--cf-primary);
}

.stat-icon-wrapper {
    width: 48px;
    height: 48px;
    border-radius: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 1rem;
}

/* Buttons */
.btn-premium {
    background: var(--cf-gradient);
    border: none;
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 0.75rem;
    font-weight: 600;
    transition: all 0.3s ease;
}

.btn-premium:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px var(--cf-primary-glow);
    color: white;
    opacity: 0.9;
}

/* Theme Toggle */
.theme-toggle-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid var(--cf-border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--cf-text);
    background: transparent;
    transition: all 0.2s ease;
}

.theme-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* Responsive Sidebar Toggle */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1040;
    display: none;
}

@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
        box-shadow: 10px 0 40px rgba(0, 0, 0, 0.5);
    }

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

    .sidebar-overlay.show {
        display: block;
    }
}

/* Landing Page Specifics */
.hero-gradient {
    background: radial-gradient(circle at top right, rgba(79, 70, 229, 0.15) 0%, transparent 50%),
        radial-gradient(circle at bottom left, rgba(124, 58, 237, 0.1) 0%, transparent 40%);
}

.text-gradient {
    background: var(--cf-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Tables */
.cf-table {
    background: var(--cf-surface);
    border-radius: 1.25rem;
    overflow: hidden;
    border: 1px solid var(--cf-border);
}

.cf-table thead th {
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid var(--cf-border);
    color: var(--cf-text-muted);
    font-weight: 500;
    font-size: 0.875rem;
    padding: 1rem 1.5rem;
}

.cf-table tbody td {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--cf-border);
    vertical-align: middle;
}

.cf-table tbody tr:last-child td {
    border-bottom: none;
}

/* User Avatar */
.cf-avatar {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: var(--cf-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

/* Three dots & Context Menu */
.btn-action-dots {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    color: var(--cf-text-muted);
    transition: all 0.2s;
}

.btn-action-dots:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--cf-text);
}

.context-menu {
    position: fixed;
    z-index: 10000;
    min-width: 180px;
    background: rgba(30, 32, 44, 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 0.5rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    display: none;
}

.context-menu-item {
    padding: 0.6rem 0.8rem;
    border-radius: 8px;
    color: var(--cf-text);
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    transition: all 0.1s;
}

.context-menu-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.context-menu-item.text-danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

.context-menu-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.08);
    margin: 0.4rem 0.2rem;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade-in {
    animation: fadeIn 0.4s ease-out forwards;
}

.badge-premium {
    padding: 0.4em 0.8em;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.75rem;
}

/* Impersonation Banner */
/* Impersonation Banner */
.impersonation-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 50px;
    z-index: 9999;
    background: linear-gradient(135deg, #F59E0B 0%, #EF4444 100%);
    color: white;
    font-size: 0.875rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

body.has-impersonation-banner .app-header {
    top: 50px;
}

body.has-impersonation-banner .main-wrapper {
    padding-top: 50px;
}

body.has-impersonation-banner .dashboard-navbar {
    top: 50px;
}

/* BG Surface Utility */
.bg-surface {
    background-color: var(--cf-surface) !important;
}

/* Pulse animation for status indicators */
.pulse-dot {
    width: 8px;
    height: 8px;
    background: currentColor;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.5;
        transform: scale(1.2);
    }
}

/* X-Small text utility */
.x-small {
    font-size: 0.75rem;
}

/* Light Mode */
[data-bs-theme="light"] {
    --cf-bg: #F9FAFB;
    --cf-surface: #FFFFFF;
    --cf-surface-2: #F3F4F6;
    --cf-text: #111827;
    --cf-text-muted: #6B7280;
    --cf-border: rgba(0, 0, 0, 0.1);
}

[data-bs-theme="light"] body {
    background-color: var(--cf-bg);
    color: var(--cf-text);
}

[data-bs-theme="light"] .app-header {
    background-color: var(--cf-surface);
    border-bottom-color: var(--cf-border);
}

[data-bs-theme="light"] .dashboard-navbar {
    background: rgba(255, 255, 255, 0.9);
    border-bottom-color: var(--cf-border);
}

[data-bs-theme="light"] .dashboard-navbar .text-white {
    color: var(--cf-text) !important;
}

[data-bs-theme="light"] .glass-card {
    background: rgba(255, 255, 255, 0.8);
    border-color: var(--cf-border);
}

[data-bs-theme="light"] .cf-stat-card,
[data-bs-theme="light"] .cf-table {
    background: var(--cf-surface);
    border-color: var(--cf-border);
}

[data-bs-theme="light"] .navigation .nav-link {
    color: var(--cf-text-muted);
}

[data-bs-theme="light"] .navigation .nav-link:hover {
    color: var(--cf-text);
    background-color: rgba(0, 0, 0, 0.05);
}

[data-bs-theme="light"] .dropdown-menu {
    background: var(--cf-surface) !important;
    border-color: var(--cf-border);
}

[data-bs-theme="light"] .context-menu {
    background: rgba(255, 255, 255, 0.95);
    border-color: var(--cf-border);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

[data-bs-theme="light"] .context-menu-item {
    color: var(--cf-text);
}

[data-bs-theme="light"] .context-menu-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

[data-bs-theme="light"] .context-menu-divider {
    background: rgba(0, 0, 0, 0.1);

    [data-bs-theme="light"] .form-control,
    [data-bs-theme="light"] .form-select {
        background-color: #f1f5f9;
        border-color: rgba(0, 0, 0, 0.1);
        color: var(--cf-text);
    }

    [data-bs-theme="light"] .form-control::placeholder {
        color: #94a3b8;
    }

    [data-bs-theme="light"] .form-control:focus,
    [data-bs-theme="light"] .form-select:focus {
        background-color: #fff;
        color: var(--cf-text);
        border-color: var(--cf-primary);
    }

    [data-bs-theme="light"] .text-white,
    [data-bs-theme="light"] .modal-title,
    [data-bs-theme="light"] h1,
    [data-bs-theme="light"] h2,
    [data-bs-theme="light"] h3,
    [data-bs-theme="light"] h4,
    [data-bs-theme="light"] h5,
    [data-bs-theme="light"] h6 {
        color: var(--cf-text) !important;
    }

    [data-bs-theme="light"] .text-secondary {
        color: #475569 !important;
        /* Darker secondary text for light mode */
    }

    [data-bs-theme="light"] .form-label {
        color: #334155 !important;
    }

    [data-bs-theme="light"] .btn-outline-secondary {
        border-color: rgba(0, 0, 0, 0.2);
        color: #334155;
    }

    [data-bs-theme="light"] .btn-outline-secondary:hover {
        background-color: #f1f5f9;
        color: var(--cf-text);
    }

    [data-bs-theme="light"] .btn-close {
        filter: none;
    }

    [data-bs-theme="light"] .btn-premium {
        color: #fff !important;
        /* Keep white on premium buttons */
    }

    /* Fix for dark-themed elements that should stay dark in light mode if needed */
    [data-bs-theme="light"] .bg-gradient-dark .text-white {
        color: #fff !important;
    }

    /* AI Prompt Bar - Fixed at bottom */
    .ai-prompt-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(var(--cf-surface-rgb), 0.95);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-top: 1px solid rgba(255, 255, 255, 0.05);
        padding: 0.75rem 1rem;
        z-index: 1030;
    }

    .ai-prompt-bar .input-group {
        max-width: 800px;
        margin: 0 auto;
    }

    .ai-prompt-bar .input-group-text {
        background: transparent;
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-right: none;
        color: var(--cf-primary);
    }

    .ai-prompt-bar input {
        background: rgba(0, 0, 0, 0.2);
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-left: none;
        color: var(--cf-text);
        padding: 0.75rem 1rem;
    }

    .ai-prompt-bar input::placeholder {
        color: var(--cf-text-muted);
    }

    .ai-prompt-bar input:focus {
        background: rgba(0, 0, 0, 0.3);
        box-shadow: none;
        border-color: rgba(var(--cf-primary-rgb), 0.3);
    }

    /* Adjust main content when AI bar is present */
    body.has-ai-bar main {
        padding-bottom: 80px !important;
    }

    [data-bs-theme="light"] .ai-prompt-bar {
        background: rgba(255, 255, 255, 0.95);
        border-top-color: rgba(0, 0, 0, 0.1);
    }

    [data-bs-theme="light"] .ai-prompt-bar .input-group-text {
        border-color: rgba(0, 0, 0, 0.1);
    }

    [data-bs-theme="light"] .ai-prompt-bar input {
        background: rgba(0, 0, 0, 0.05);
        border-color: rgba(0, 0, 0, 0.1);
    }

    /* AI Chat Messages */
    .ai-chat-messages {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    .ai-message {
        max-width: 85%;
        padding: 0.75rem 1rem;
        border-radius: 1rem;
        font-size: 0.9rem;
        line-height: 1.5;
    }

    .ai-message.user {
        align-self: flex-end;
        background: var(--cf-primary);
        color: white;
        border-bottom-right-radius: 0.25rem;
    }

    .ai-message.assistant {
        align-self: flex-start;
        background: rgba(255, 255, 255, 0.1);
        color: var(--cf-text);
        border-bottom-left-radius: 0.25rem;
    }

    .ai-message.ai-welcome {
        align-self: center;
        max-width: 100%;
        background: transparent;
    }

    .ai-message .typing-indicator {
        display: flex;
        gap: 0.25rem;
        padding: 0.5rem 0;
    }

    .ai-message .typing-indicator span {
        width: 8px;
        height: 8px;
        background: var(--cf-primary);
        border-radius: 50%;
        animation: typing 1.4s infinite both;
    }

    .ai-message .typing-indicator span:nth-child(2) {
        animation-delay: 0.2s;
    }

    .ai-message .typing-indicator span:nth-child(3) {
        animation-delay: 0.4s;
    }

    @keyframes typing {

        0%,
        60%,
        100% {
            transform: translateY(0);
            opacity: 0.4;
        }

        30% {
            transform: translateY(-4px);
            opacity: 1;
        }
    }

    /* AI Actions */
    .ai-actions .btn {
        min-width: 90px;
    }

    [data-bs-theme="light"] .ai-message.assistant {
        background: rgba(0, 0, 0, 0.05);
    }

    /* Advanced Interaction Styles */
    /* Selected Row */
    .cf-table tbody tr.selected {
        background-color: rgba(79, 70, 229, 0.15) !important;
        border-left: 3px solid var(--cf-primary);
    }

    [data-bs-theme="light"] .cf-table tbody tr.selected {
        background-color: rgba(79, 70, 229, 0.1) !important;
    }

    /* Keyboard Focus */
    .cf-table tbody tr:focus {
        outline: 2px solid var(--cf-primary);
        outline-offset: -2px;
    }

    /* Context Menu & Submenus */
    .context-menu-item {
        position: relative;
        display: flex;
        align-items: center;
        width: 100%;
        padding: 0.5rem 1rem;
        clear: both;
        font-weight: 400;
        color: var(--cf-text);
        text-align: inherit;
        text-decoration: none;
        white-space: nowrap;
        background-color: transparent;
        border: 0;
        cursor: pointer;
    }

    .context-submenu {
        position: absolute;
        left: 100%;
        top: -0.5rem;
        min-width: 180px;
        background: rgba(30, 32, 44, 0.95);
        backdrop-filter: blur(12px);
        border: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: 8px;
        padding: 0.5rem;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
        display: none;
        margin-left: -5px;
        /* Overlap slightly to ensure hover persistence */
        padding-left: 5px;
        /* Compensate content */
    }

    [data-bs-theme="light"] .context-submenu {
        background: rgba(255, 255, 255, 0.98);
        border-color: rgba(0, 0, 0, 0.1);
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    }

    .context-menu-item:hover>.context-submenu {
        display: block;
    }

    /* Color Picker */
    .color-picker-grid {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 0.5rem;
        padding: 0.25rem;
    }

    .color-swatch {
        width: 20px;
        height: 20px;
        border-radius: 50%;
        cursor: pointer;
        border: 2px solid transparent;
        transition: transform 0.2s;
    }

    .color-swatch:hover {
        transform: scale(1.2);
        box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
    }

    /* Custom Tooltip */
    .cf-tooltip {
        position: fixed;
        z-index: 10001;
        background: rgba(22, 24, 34, 0.95);
        backdrop-filter: blur(8px);
        border: 1px solid rgba(255, 255, 255, 0.1);
        color: #F9FAFB;
        padding: 0.75rem 1rem;
        border-radius: 0.5rem;
        font-size: 0.825rem;
        pointer-events: none;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
        max-width: 250px;
        opacity: 0;
        transition: opacity 0.2s ease;
        transform: translate(-50%, -100%);
        margin-top: -10px;
    }

    [data-bs-theme="light"] .cf-tooltip {
        background: rgba(255, 255, 255, 0.95);
        color: #111827;
        border-color: rgba(0, 0, 0, 0.1);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }

    .cf-tooltip-header {
        font-weight: 600;
        margin-bottom: 0.25rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        padding-bottom: 0.25rem;
        color: var(--cf-primary);
    }

    [data-bs-theme="light"] .cf-tooltip-header {
        border-bottom-color: rgba(0, 0, 0, 0.1);
    }

    .cf-tooltip-row {
        display: flex;
        justify-content: space-between;
        gap: 1rem;
        margin-bottom: 0.125rem;
    }

    .cf-tooltip-row label {
        color: var(--cf-text-muted);
    }