/* Modern SaaS Theme */
:root {
    /* Primary Palette - Trustworthy Blue/Indigo */
    --primary: #4f46e5;
    /* Indigo 600 */
    --primary-hover: #4338ca;
    /* Indigo 700 */
    --primary-light: #e0e7ff;
    /* Indigo 100 */

    /* Secondary/Accent */
    --secondary: #0ea5e9;
    /* Sky 500 */
    --accent: #f59e0b;
    /* Amber 500 */
    --danger: #ef4444;
    /* Red 500 */
    --success: #10b981;
    /* Emerald 500 */
    --warning: #f59e0b;
    /* Amber 500 */

    /* Neurtals */
    --bg-body: #f3f4f6;
    /* Gray 100 */
    --bg-surface: #ffffff;
    --text-main: #111827;
    /* Gray 900 */
    --text-muted: #6b7280;
    /* Gray 500 */
    --border-color: #e5e7eb;
    /* Gray 200 */

    /* Sidebar */
    --sidebar-bg: #1e1b4b;
    /* Indigo 950 */
    --sidebar-text: #9ca3af;
    /* Gray 400 */
    --sidebar-active: #ffffff;
    --sidebar-active-bg: rgba(255, 255, 255, 0.1);

    /* Dimensions */
    --sidebar-width: 260px;
    --header-height: 64px;
}

[data-theme="dark"] {
    --bg-body: #111827;
    /* Gray 900 */
    --bg-surface: #1f2937;
    /* Gray 800 */
    --text-main: #f9fafb;
    /* Gray 50 */
    --text-muted: #9ca3af;
    /* Gray 400 */
    --border-color: #374151;
    /* Gray 700 */

    /* Recalibrate colors for dark mode context if needed */
    --primary-light: #312e81;
    /* Indigo 900 */
}

/* Base */
body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* Bootstrap Utility Overrides for Theme Support */
.text-muted {
    color: var(--text-muted) !important;
}

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

.bg-white {
    background-color: var(--bg-surface) !important;
}

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

h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-main);
    font-weight: 600;
    letter-spacing: -0.025em;
}

/* Layout Grid */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.app-sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    transition: width 0.3s ease, transform 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    /* Hide horizontal overflow during transition */
    white-space: nowrap;
    /* Prevent text wrapping */
}

/* Collapsed State (Desktop) */
body.sidebar-collapsed .app-sidebar {
    width: 70px;
}

body.sidebar-collapsed .sidebar-brand span,
body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .nav-link span,
/* Assuming text is wrapped in span if not already, or we rely on flex behavior */
body.sidebar-collapsed .sidebar-content .mt-5 {
    display: none;
    opacity: 0;
}

/* Ensure icons are centered in collapsed mode */
body.sidebar-collapsed .nav-item .nav-link {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

body.sidebar-collapsed .nav-icon {
    margin-right: 0;
    font-size: 1.25rem;
}

body.sidebar-collapsed .app-main {
    margin-left: 70px;
}

/* Branding adjustments for collapsed state */
body.sidebar-collapsed .sidebar-brand {
    justify-content: center;
    padding: 0;
}

body.sidebar-collapsed .sidebar-brand .bi {
    margin-right: 0 !important;
}

.sidebar-brand {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    color: #fff;
    font-size: 1.25rem;
    font-weight: 700;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem 0;
}

.nav-label {
    padding: 0.75rem 1.5rem 0.5rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.4);
    white-space: nowrap;
}

.nav-item .nav-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    color: var(--sidebar-text);
    transition: all 0.2s;
    border-left: 3px solid transparent;
    white-space: nowrap;
    overflow: hidden;
}

.nav-item .nav-link:hover {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.05);
}

.nav-item .nav-link.active {
    color: #fff;
    background-color: var(--sidebar-active-bg);
    border-left-color: var(--secondary);
}

.nav-icon {
    min-width: 20px;
    /* Ensure icon has size */
    margin-right: 0.75rem;
    font-size: 1.1rem;
    opacity: 0.8;
    text-align: center;
}

/* Main Content Area */
.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* Prevent overflow */
    transition: margin-left 0.3s ease;
}

.sidebar-user-card {
    background-color: rgba(255, 255, 255, 0.1);
    color: white;
}

/* Header */
.app-header {
    height: var(--header-height);
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 40;
}

.header-left {
    display: flex;
    align-items: center;
}

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    margin-right: 1rem;
    display: block;
    /* Always show toggle button */
}

/* Cards */
.card-modern {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    transition: box-shadow 0.2s, background-color 0.3s ease, border-color 0.3s ease;
}

.card-modern:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.card-header-modern {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title-modern {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-main);
    margin: 0;
}

/* Status Badges */
.badge-modern {
    padding: 0.35em 0.65em;
    font-size: 0.75em;
    font-weight: 600;
    border-radius: 9999px;
}

.badge-success-soft {
    background-color: #d1fae5;
    color: #065f46;
}

.badge-warning-soft {
    background-color: #fef3c7;
    color: #92400e;
}

.badge-danger-soft {
    background-color: #fee2e2;
    color: #991b1b;
}

.badge-info-soft {
    background-color: #e0f2fe;
    color: #075985;
}

/* Buttons */
.btn-modern {
    border-radius: 0.5rem;
    padding: 0.5rem 1rem;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-primary-modern {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.btn-primary-modern:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

/* Mobile Responsiveness */
@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
    }

    .app-sidebar.show {
        transform: translateX(0);
    }

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

    .sidebar-toggle {
        display: block;
    }

    /* Overlay when sidebar is open */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 45;
    }

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

/* Sidebar Tooltip */
.sidebar-tooltip {
    position: fixed;
    background: #333;
    color: #fff;
    padding: 0.4rem 0.8rem;
    border-radius: 0.375rem;
    font-size: 0.8rem;
    font-weight: 500;
    z-index: 9999;
    pointer-events: none;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.15s ease-in-out;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    /* Arrow */
}

.sidebar-tooltip::before {
    content: '';
    position: absolute;
    left: -4px;
    top: 50%;
    transform: translateY(-50%);
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    border-right: 4px solid #333;
}

.sidebar-tooltip.show {
    opacity: 1;
}

/* Sidebar Toggle Chevron Rotation */
.nav-group-toggle .bi-chevron-down {
    transition: transform 0.3s ease;
}

.nav-group-toggle.collapsed .bi-chevron-down {
    transform: rotate(-90deg);
}

.nav-group-toggle:hover {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.05);
}

/* Dark Mode Table & Background Overrides */
[data-theme="dark"] .bg-light {
    background-color: rgba(255, 255, 255, 0.05) !important;
    color: var(--text-main) !important;
}

[data-theme="dark"] .table {
    --bs-table-color: var(--text-main);
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--border-color);
    --bs-table-hover-bg: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select {
    background-color: var(--bg-body);
    border-color: var(--border-color);
    color: var(--text-main);
}

[data-theme="dark"] .form-select option {
    background-color: var(--bg-surface);
    color: var(--text-main);
}