:root {
    /* Color Palette */
    --p-primary: #4f46e5;
    --p-primary-hover: #4338ca;
    --p-secondary: #64748b;
    --p-accent: #0ea5e9;
    --p-success: #10b981;
    --p-warning: #f59e0b;
    --p-danger: #ef4444;
    
    --p-bg-body: #f8fafc;
    --p-bg-surface: #ffffff;
    --p-bg-sidebar: #0f172a;
    --p-bg-sidebar-hover: #1e293b;
    
    --p-text-main: #0f172a;
    --p-text-muted: #64748b;
    --p-border: #e2e8f0;
    
    /* Layout Tokens */
    --p-radius: 16px;
    --p-radius-sm: 8px;
    --p-shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --p-shadow: 0 4px 20px rgba(0,0,0,0.04);
    --p-shadow-hover: 0 10px 30px rgba(0,0,0,0.08);
}

.preload-transitions * {
    transition: none !important;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--p-bg-body);
    color: var(--p-text-main);
    letter-spacing: -0.01em;
}

/* Typography Overrides */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    color: var(--p-text-main);
}

/* Sidebar Customization */
.sidebar {
    background-color: var(--p-bg-sidebar);
    color: #f1f5f9;
    border-right: 1px solid rgba(255,255,255,0.05);
    width: 260px;
    flex-shrink: 0;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    overflow-y: auto;
    transition: all 0.3s ease;
    z-index: 1050;
}
.sidebar a {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    color: #94a3b8;
    text-decoration: none;
    border-radius: var(--p-radius-sm);
    transition: all 0.2s ease;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
}
.sidebar a:hover {
    color: #ffffff;
    background-color: var(--p-bg-sidebar-hover);
}
.sidebar a.active {
    color: #ffffff;
    background-color: var(--p-primary);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
}

/* Sidebar Collapsed State (Desktop) */
@media (min-width: 769px) {
    .sidebar.collapsed {
        width: 80px;
        overflow: visible !important;
    }
    .sidebar.collapsed .sidebar-text,
    .sidebar.collapsed .sidebar-header-text,
    .sidebar.collapsed .sidebar-profile {
        display: none !important;
    }
    .sidebar.collapsed a {
        justify-content: center;
        padding: 0.75rem 0;
        position: relative;
        overflow: visible; /* Override hidden to show tooltip */
    }
    .sidebar.collapsed a i {
        margin-right: 0 !important;
        font-size: 1.25rem;
        width: 100% !important;
        text-align: center;
    }
    
    /* Elegant Tooltip on Hover */
    .sidebar.collapsed a:hover .sidebar-text {
        display: block !important;
        position: absolute;
        left: 55px; /* Distance from the icon */
        top: 50%;
        background-color: var(--p-bg-sidebar-hover);
        border: 1px solid rgba(255,255,255,0.05);
        color: #ffffff;
        padding: 0.4rem 0.8rem;
        border-radius: var(--p-radius-sm);
        font-size: 0.85rem;
        font-weight: 500;
        white-space: nowrap;
        box-shadow: 0 4px 12px rgba(0,0,0,0.3);
        z-index: 1060;
        pointer-events: none;
        opacity: 0;
        transform: translateY(-50%) translateX(-5px);
        animation: tooltipFadeIn 0.2s forwards;
        animation-delay: 0.1s;
    }
    
    /* Tooltip Arrow */
    .sidebar.collapsed a:hover .sidebar-text::before {
        content: '';
        position: absolute;
        left: -5px;
        top: 50%;
        transform: translateY(-50%);
        border-width: 5px 5px 5px 0;
        border-style: solid;
        border-color: transparent var(--p-bg-sidebar-hover) transparent transparent;
    }
}

/* Sidebar Mobile State */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        height: 100%;
        transform: translateX(-100%);
    }
    .sidebar.show {
        transform: translateX(0);
        box-shadow: var(--p-shadow-hover);
    }
    /* Dim background overlay for mobile */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.5);
        z-index: 1040;
        display: none;
    }
    .sidebar-overlay.show {
        display: block;
    }
}

/* Cards */
.card {
    border: none;
    border-radius: var(--p-radius);
    box-shadow: var(--p-shadow);
    background-color: var(--p-bg-surface);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.card:hover {
    box-shadow: var(--p-shadow-hover);
}
.card-header {
    background-color: transparent;
    border-bottom: 1px solid var(--p-border);
    padding: 1.25rem 1.5rem;
}
.card-body {
    padding: 1.5rem;
}

/* Glassmorphic Navbar */
.navbar-top {
    background: rgba(255, 255, 255, 0.85) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: var(--p-shadow-sm);
    border-radius: var(--p-radius);
}

/* Buttons */
.btn {
    border-radius: var(--p-radius-sm);
    font-weight: 500;
    padding: 0.6rem 1.2rem;
    transition: all 0.2s ease;
}
.btn-primary {
    background-color: var(--p-primary);
    border-color: var(--p-primary);
}
.btn-primary:hover {
    background-color: var(--p-primary-hover);
    border-color: var(--p-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}
.btn-outline-secondary {
    border-color: var(--p-border);
    color: var(--p-text-muted);
}
.btn-outline-secondary:hover {
    background-color: #f8fafc;
    color: var(--p-text-main);
    border-color: #cbd5e1;
}

/* Tables */
.table {
    margin-bottom: 0;
    color: var(--p-text-main);
}
.table th {
    font-weight: 500;
    color: var(--p-text-muted);
    border-bottom: 2px solid var(--p-border);
    padding: 1rem;
    background-color: #f8fafc;
}
.table td {
    padding: 1rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--p-border);
}
.table tbody tr {
    transition: background-color 0.2s ease;
}
.table tbody tr:hover {
    background-color: #f1f5f9;
}

/* Form Controls */
.form-control, .form-select {
    border-radius: var(--p-radius-sm);
    border: 1px solid var(--p-border);
    padding: 0.6rem 1rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.form-control:focus, .form-select:focus {
    border-color: var(--p-primary);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
}
.form-label {
    font-weight: 500;
    color: var(--p-text-main);
    margin-bottom: 0.4rem;
}

/* Badges */
.badge {
    padding: 0.4em 0.8em;
    font-weight: 500;
    border-radius: 20px;
}
/* Soft Badge Colors */
.bg-primary { background-color: rgba(79, 70, 229, 0.1) !important; color: var(--p-primary) !important; }
.bg-success { background-color: rgba(16, 185, 129, 0.1) !important; color: var(--p-success) !important; }
.bg-warning { background-color: rgba(245, 158, 11, 0.1) !important; color: var(--p-warning) !important; }
.bg-danger { background-color: rgba(239, 68, 68, 0.1) !important; color: var(--p-danger) !important; }
.bg-secondary { background-color: rgba(100, 116, 139, 0.1) !important; color: var(--p-secondary) !important; }

/* Status specific overrides for custom colors */
.bg-orange { background-color: rgba(253, 126, 20, 0.1) !important; color: #fd7e14 !important; }
.bg-purple { background-color: rgba(111, 66, 193, 0.1) !important; color: #6f42c1 !important; }

/* Dropdown */
.dropdown-menu {
    border: none;
    box-shadow: var(--p-shadow-hover);
    border-radius: var(--p-radius-sm);
}
.dropdown-item:hover {
    background-color: #f1f5f9;
}

/* Activity Timeline */
.timeline-item {
    position: relative;
    padding-left: 2rem;
    margin-bottom: 1.5rem;
}
.timeline-item::before {
    content: '';
    position: absolute;
    left: 0.5rem;
    top: 0.25rem;
    bottom: -1.5rem;
    width: 2px;
    background-color: var(--p-border);
}
.timeline-item:last-child::before {
    display: none;
}
.timeline-icon {
    position: absolute;
    left: 0;
    top: 0;
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
    background-color: var(--p-primary);
    border: 3px solid white;
    box-shadow: 0 0 0 2px var(--p-primary);
}

/* Prevent scroll chaining on offcanvas */
.offcanvas, .offcanvas-body {
    overscroll-behavior: none;
}

/* Fix horizontal scrolling on mobile/iPad safely */
body {
    overflow-x: hidden;
}

.main-content {
    min-width: 0; /* allows flex item to shrink below content size if needed */
    margin-left: 260px; /* Offset for fixed sidebar */
    transition: margin-left 0.3s ease;
}

@media (min-width: 769px) {
    /* Offset for collapsed sidebar on desktop */
    .sidebar.collapsed ~ .main-content,
    body:has(.sidebar.collapsed) .main-content {
        margin-left: 80px;
    }
}

@media (max-width: 768px) {
    /* Reduce padding on mobile */
    .mobile-px-3 { padding-left: 1rem !important; padding-right: 1rem !important; }
    .mobile-py-2 { padding-top: 0.5rem !important; padding-bottom: 0.5rem !important; }
    
    .main-content {
        margin-left: 0; /* Remove offset on mobile */
    }
}

/* Tooltip Animation */
@keyframes tooltipFadeIn {
    0% { opacity: 0; transform: translateY(-50%) translateX(-5px); }
    100% { opacity: 1; transform: translateY(-50%) translateX(0); }
}

/* Fix overlapping dropdown arrow on native selects with auto or small widths */
select.form-select {
    padding-right: 2.5rem !important; /* Ensure enough space for the arrow */
}
select.form-select.w-auto, 
select.form-select[style*="width: auto"] {
    min-width: 150px;
}
select.form-select-sm[style*="width: auto"] {
    min-width: 130px;
}
.markdown-content p:last-child { margin-bottom: 0; }
.markdown-content ul, .markdown-content ol { margin-bottom: 0; padding-left: 1.5rem; }
.markdown-content li { margin-bottom: 0.25rem; }
