/* CSS Variables for theming */
:root {
    --app-bg: #f8f9fa;
    --sidebar-bg: #1f242b;
    --sidebar-border: rgba(255, 255, 255, 0.08);
    --sidebar-text: rgba(255, 255, 255, 0.72);
    --sidebar-text-strong: rgba(255, 255, 255, 0.92);
    --sidebar-hover-bg: rgba(255, 255, 255, 0.12);
    --sidebar-active-bg: rgba(13, 110, 253, 0.18);
    --sidebar-active-border: rgba(13, 110, 253, 0.55);
    --topbar-bg: #ffffff;
    --backdrop-bg: rgba(0, 0, 0, 0.5);
    --chart-stripe-1: #e9ecef;
    --chart-stripe-2: #f8f9fa;
    --chart-text: #adb5bd;
    --tile-bg: #ffffff;
    --tile-border: rgba(0, 0, 0, 0.1);
    --tile-shadow: 0 2px 16px rgba(0, 0, 0, 0.06);
    --input-bg: #f8f9fa;
}

/* Accessibility: Prevent sticky header from obscuring focused content */
html {
    scroll-padding-top: 70px;
}

:focus-visible {
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
    scroll-margin-top: 70px;
}

/* Skip navigation link for keyboard users */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #0d6efd;
    color: white;
    padding: 8px 16px;
    z-index: 10000;
    text-decoration: none;
    border-radius: 0 0 4px 0;
}

.skip-link:focus {
    top: 0;
}

/* Dark mode overrides */
[data-bs-theme="dark"] {
    --app-bg: #212529;
    --sidebar-bg: #000000;
    --sidebar-hover-bg: rgba(255, 255, 255, 0.12);
    --sidebar-active-bg: rgba(13, 110, 253, 0.18);
    --sidebar-active-border: rgba(13, 110, 253, 0.55);
    --topbar-bg: #212529;
    --backdrop-bg: rgba(0, 0, 0, 0.7);
    --chart-stripe-1: #343a40;
    --chart-stripe-2: #495057;
    --chart-text: #6c757d;
    --tile-bg: #2b3035;
    --tile-border: rgba(255, 255, 255, 0.15);
    --tile-shadow: 0 2px 16px rgba(0, 0, 0, 0.3);
    --input-bg: #1a1d20;
}

.app-shell {
    min-height: 100vh;
    background-color: var(--app-bg);
}

/* Form input controls with subtle background for better visual hierarchy */
.form-control,
.form-select,
textarea.form-control {
    background-color: var(--input-bg) !important;
}

.form-control:focus,
.form-select:focus,
textarea.form-control:focus {
    background-color: var(--input-bg) !important;
}

.app-sidebar {
/*    width: 260px;
    min-width: 260px;*/
    min-height: 100vh;
    position: sticky;
    top: 0;
    align-self: flex-start;
    z-index: 1040;
    flex: 0 0 260px;
    background-color: var(--sidebar-bg) !important;
    overflow-y: auto;
    max-height: 100vh;
}

.app-sidebar-header {
    min-height: 64px;
    display: flex;
    align-items: center;
}

.app-sidebar-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    display: none; /* Hidden on desktop */
}

.app-sidebar .nav-link {
    color: var(--sidebar-text);
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    padding: 10px 12px;
    border-radius: 10px;
    margin: 4px 20px 4px 10px;
    border: 1px solid transparent;
    display: flex;
    align-items: center;
    gap: 10px;
    user-select: none;
    text-decoration: none;
}

.app-sidebar .nav-link:hover,
.app-sidebar .nav-link:focus {
    color: var(--sidebar-text-strong);
    background-color: var(--sidebar-hover-bg);
    text-decoration: none;
}

.app-sidebar .nav-link.active {
    color: var(--sidebar-text-strong);
    background-color: var(--sidebar-active-bg);
    border: 1px solid var(--sidebar-active-border);
}

.app-topbar {
    height: 64px;
    min-height: 64px;
    background-color: var(--topbar-bg) !important;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.app-main {
    min-width: 0;
}

.app-content {
    background-color: var(--app-bg);
}

.mobile-menu-toggle {
    border: none;
    background: transparent;
    padding: 0.5rem;
    cursor: pointer;
    display: none;
}

.mobile-menu-toggle:hover {
    opacity: 0.7;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--backdrop-bg);
    z-index: 1030;
}

@media (max-width: 575.98px) {
    .app-topbar {
        padding: 0.75rem 1rem;
    }

    .app-content {
        padding: 1rem 0.5rem !important;
    }
}

/* Fix for Bootstrap cards with rounded corners - allows dropdowns to overflow */
.card {
    overflow: hidden;
    border-radius: 0.5rem;
}

/* Only clip overflow for card images/media to maintain rounded corners */
.card-img,
.card-img-top,
.card-img-bottom {
    overflow: hidden;
}

/* Table header styling for better contrast in dark mode */
[data-bs-theme="dark"] .table thead {
    background-color: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

[data-bs-theme="dark"] .table thead th {
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

@media (max-width: 991.98px) {
    .app-sidebar {
        position: fixed;
        top: 0;
        left: -260px;
        width: 260px;
        min-height: 100vh;
        transition: left 0.3s ease;
        z-index: 1040;
    }

    .app-sidebar.show {
        left: 0;
    }

    .app-sidebar-footer {
        display: block; /* Show on mobile only */
        padding-bottom: 1.5rem !important;
    }

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

    .mobile-menu-toggle {
        display: block;
    }

    .app-topbar {
        position: sticky;
        top: 0;
        z-index: 1020;
    }
}

/* Hierarchical Navigation Styles */
.nav-section {
    color: rgba(255, 255, 255, 0.45);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 12px 12px 6px;
    user-select: none;
}

.app-sidebar .nav-link.toggle {
    justify-content: space-between;
}

.app-sidebar .nav-link.toggle .left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.app-sidebar .nav-link.toggle .text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-sidebar .nav-link.toggle .chev {
    opacity: 0.7;
    transition: transform 0.18s ease;
    font-size: 12px;
}

.app-sidebar .nav-link.toggle[aria-expanded="true"] .chev {
    transform: rotate(180deg);
}

.nav-sub {
    margin: 4px 20px 8px 10px;
    padding-left: 10px;
    border-left: 1px solid var(--sidebar-border);
}

.nav-sub .nav-link {
    margin: 4px 0;
    padding: 8px 10px;
    border-radius: 9px;
    font-size: 13px;
    color: var(--sidebar-text);
    border: 1px solid transparent;
}

.nav-sub .nav-link:hover {
    color: var(--sidebar-text-strong);
    background-color: var(--sidebar-hover-bg);
}

.nav-sub .nav-link.active {
    border: 1px solid var(--sidebar-active-border);
    background-color: var(--sidebar-active-bg);
    color: var(--sidebar-text-strong);
}

.divider {
    margin: 10px 14px;
    border-top: 1px solid var(--sidebar-border);
}

.grow {
    flex: 1;
}

.org {
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
}

.org .badge-dot {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: rgba(13, 110, 253, 0.18);
    border: 1px solid rgba(13, 110, 253, 0.35);
    display: grid;
    place-items: center;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 600;
    font-size: 12px;
    flex-shrink: 0;
}

.org .text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
