/* Auxilia.Security.Blazor — Sidebar layout structure and the shared light/dark theme.
   Reference in App.razor <head>, after Bootstrap and before the app's own stylesheet:
     <link rel="stylesheet" href="_content/Auxilia.Security.Blazor/css/auxilia-layout.css" />

   Both top rows use Bootstrap's theme tokens, so their text stays ≥ 10:1 in light and dark. Re-check
   WCAG AA contrast (≥ 4.5:1 for normal text) if they're changed.
 */

/* Shared height token — both top rows reference this so they stay in sync.
   --bs-table-dark-bg isn't a real Bootstrap variable - it's Auxilia's own token, used for sticky
   header cells, including Auxilia.Components' IndexPage, which need a solid background. */
:root {
    --auxilia-top-row-height: 3.5rem;
    --auxilia-sidebar-width: 250px;
    --bs-table-dark-bg: #1a1a2e;
}

/* Logo card: rounded surface behind logo images. The tone is fixed (ApprovalPageOptions.LogoCardTheme)
   and deliberately ignores data-bs-theme so a logo has the same contrast on every page. */
.auxilia-logo-card {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: fit-content;
    max-width: 100%;
    padding: 0.35rem;
    border-radius: 12px;
    flex-shrink: 0;
}

.auxilia-logo-card--light {
    background: #ffffff;
    border: 1px solid rgba(15, 23, 42, 0.1);
    box-shadow: 0 6px 20px rgba(15, 23, 42, 0.15);
    color-scheme: light;
}

.auxilia-logo-card--dark {
    background: #1a1a2e;
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
}

.page {
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Keeps its full width while it's hidden, so it moves as one piece and its text doesn't rewrap. */
.sidebar {
    width: var(--auxilia-sidebar-width);
    overflow-y: auto;
    background-color: #1a1a2e;
    transition: margin-left 0.2s ease-in-out, transform 0.2s ease-in-out;
}

/* Hidden as well as moved off-screen, so its links can't take keyboard focus. The delay lets the
   slide finish first. */
body.sidebar-collapsed .sidebar {
    visibility: hidden;
    transition: margin-left 0.2s ease-in-out, transform 0.2s ease-in-out, visibility 0s linear 0.2s;
}

/* The sidebar toggle in TopBar.razor is the only control for the nav, so a host NavMenu's .collapse
   class and hamburger button must not hide it a second time. */
.sidebar .nav-scrollable {
    display: block !important;
}

.sidebar .navbar-toggler {
    display: none;
}

/* Bootstrap's sticky layer. Anything lower traps the account menu beneath the page's sticky table
   headers, while modals still sit above it. */
.top-row {
    position: sticky;
    top: 0;
    z-index: 1020;
    background-color: var(--bs-tertiary-bg);
    border-bottom: 1px solid var(--bs-border-color);
    justify-content: flex-end;
    height: var(--auxilia-top-row-height);
    display: flex;
    align-items: center;
    color: var(--bs-body-color);
}

/* For a host NavMenu that puts its own top row inside the sidebar. */
.sidebar .top-row {
    justify-content: space-between;
}

/* :not(.btn) leaves real buttons, such as LoginDisplay's Sign In link, with their own colours. */
.top-row a:not(.btn), .top-row .btn-link {
    white-space: nowrap;
    margin-left: 1.5rem;
    text-decoration: none;
    color: var(--bs-body-color);
}

.top-row a:not(.btn):hover, .top-row .btn-link:hover {
    text-decoration: underline;
    color: var(--bs-body-color);
}

.sidebar-toggle-btn, .theme-toggle-btn {
    flex-shrink: 0;
}

article {
    padding-top: 1.5rem;
}

/* Phones have no room to push the page aside, so the sidebar slides over it as a drawer. It sits
   just below the top row's layer so the logo and toggle stay above it. */
@media (max-width: 640px) {
    .sidebar {
        position: fixed;
        top: var(--auxilia-top-row-height);
        bottom: 0;
        left: 0;
        z-index: 1019;
    }

    body.sidebar-collapsed .sidebar {
        transform: translateX(-100%);
    }
}

@media (min-width: 641px) {
    .page-body {
        display: flex;
    }

    .sidebar {
        flex-shrink: 0;
        height: calc(100vh - var(--auxilia-top-row-height));
        position: sticky;
        top: var(--auxilia-top-row-height);
    }

    main {
        flex: 1;
        min-width: 0;
    }

    .top-row.auth a:first-child {
        flex: 1;
        text-align: right;
        width: 0;
    }

    .main > div {
        padding-left: 2rem !important;
        padding-right: 1.5rem !important;
    }

    /* Collapsed via the sidebar toggle button in TopBar.razor, which toggles this class on <body>
       (see sidebar-layout.js, window.auxiliaLayout.sidebar) rather than an element inside the
       layout, so both library-owned markup and consuming-app CSS can react to the same state.
       The negative margin slides it off the left edge, and the page widens to fill the gap. */
    body.sidebar-collapsed .sidebar {
        margin-left: calc(-1 * var(--auxilia-sidebar-width));
    }
}

/* ---------------------------------------------------------------------------------------------
   Shared light/dark theme. Everything below applies to library pages and consuming apps alike, so
   an app's own stylesheet shouldn't need to re-declare any of it.
   --------------------------------------------------------------------------------------------- */

/* Paints Bootstrap's near-black table header in the sidebar's colour, so "black" headers match the
   side nav instead of being a slightly different black. */
.table-dark {
    --bs-table-bg: var(--bs-table-dark-bg);
}

/* Bootstrap's own theme colours fall short of WCAG AA (4.5:1) on some surfaces: yellow and cyan on
   white in light mode, and blue, green, red and grey on the dark body in dark mode. The
   *-text-emphasis tokens are Bootstrap's readable equivalents, and differ per theme. Warning icons
   keep the bright yellow because they're decorative and sit beside their own label. */
.text-warning:not(i) {
    color: var(--bs-warning-text-emphasis) !important;
}

.btn.btn-outline-warning {
    --bs-btn-color: var(--bs-warning-text-emphasis);
}

.btn.btn-outline-info {
    --bs-btn-color: var(--bs-info-text-emphasis);
}

[data-bs-theme="dark"] .text-primary {
    color: var(--bs-primary-text-emphasis) !important;
}

[data-bs-theme="dark"] .text-success {
    color: var(--bs-success-text-emphasis) !important;
}

[data-bs-theme="dark"] .text-danger {
    color: var(--bs-danger-text-emphasis) !important;
}

[data-bs-theme="dark"] .text-secondary {
    color: var(--bs-secondary-color) !important;
}

[data-bs-theme="dark"] .btn-outline-primary {
    --bs-btn-color: var(--bs-primary-text-emphasis);
}

[data-bs-theme="dark"] .btn-outline-success {
    --bs-btn-color: var(--bs-success-text-emphasis);
}

[data-bs-theme="dark"] .btn-outline-danger {
    --bs-btn-color: var(--bs-danger-text-emphasis);
}

/* Bootstrap keeps its grey outline button's light-theme colour in dark mode, which is too dim to
   read on the dark surfaces. */
[data-bs-theme="dark"] .btn-outline-secondary {
    --bs-btn-color: var(--bs-body-color);
    --bs-btn-border-color: var(--bs-gray-500);
    --bs-btn-hover-color: var(--bs-gray-900);
    --bs-btn-hover-bg: var(--bs-gray-300);
    --bs-btn-hover-border-color: var(--bs-gray-300);
    --bs-btn-active-color: var(--bs-gray-900);
    --bs-btn-active-bg: var(--bs-gray-300);
    --bs-btn-active-border-color: var(--bs-gray-300);
    --bs-btn-disabled-color: var(--bs-gray-600);
    --bs-btn-disabled-border-color: var(--bs-gray-600);
}

/* Bootstrap's "Color modes" docs call out .bg-light, .bg-white, .text-bg-light and the .table-{color}
   row variants as fixed, light-only colours. Left alone, any filter bar, card header, badge or
   table row using one renders as a stark white box against the dark theme. These rules repaint
   them with Bootstrap's own dark tokens. */
[data-bs-theme="dark"] .bg-light,
[data-bs-theme="dark"] .bg-white,
[data-bs-theme="dark"] .text-bg-light {
    background-color: var(--bs-tertiary-bg) !important;
    color: var(--bs-body-color) !important;
}

/* Dark badges vanish against dark cards and table rows. */
[data-bs-theme="dark"] .badge.bg-dark,
[data-bs-theme="dark"] .badge.text-bg-dark {
    color: var(--bs-body-color) !important;
    background-color: var(--bs-gray-700) !important;
}

/* Deliberately not a blanket "[data-bs-theme=dark] .text-dark { color: ... }" rule: .text-dark is
   also paired with .bg-warning/.bg-info badges and the yellow approval headers to guarantee readable
   dark text on backgrounds that stay bright in both themes. The .bg-light pairing above already
   sets its own text colour, so no separate rule is needed for it. */

[data-bs-theme="dark"] .table-light {
    --bs-table-bg: var(--bs-tertiary-bg);
    --bs-table-color: var(--bs-body-color);
    --bs-table-border-color: var(--bs-border-color);
    --bs-table-striped-bg: var(--bs-secondary-bg);
    --bs-table-striped-color: var(--bs-body-color);
    --bs-table-active-bg: var(--bs-secondary-bg);
    --bs-table-active-color: var(--bs-body-color);
    --bs-table-hover-bg: var(--bs-secondary-bg);
    --bs-table-hover-color: var(--bs-body-color);
}

/* Striped and plain rows share one background: these are group-header rows, so a different shade
   per odd/even position would make groups in the same table look unrelated. */
[data-bs-theme="dark"] .table-secondary {
    --bs-table-bg: var(--bs-secondary-bg);
    --bs-table-color: var(--bs-body-color);
    --bs-table-border-color: var(--bs-border-color);
    --bs-table-striped-bg: var(--bs-secondary-bg);
    --bs-table-striped-color: var(--bs-body-color);
    --bs-table-active-bg: var(--bs-tertiary-bg);
    --bs-table-active-color: var(--bs-body-color);
    --bs-table-hover-bg: var(--bs-tertiary-bg);
    --bs-table-hover-color: var(--bs-body-color);
}

/* There's no generic "--bs-{color}-bg" token to vary the striped/active/hover shade the way
   --bs-secondary-bg does above, so each state reuses the same subtle background. */
[data-bs-theme="dark"] .table-primary {
    --auxilia-row-bg: var(--bs-primary-bg-subtle);
    --auxilia-row-color: var(--bs-primary-text-emphasis);
}

[data-bs-theme="dark"] .table-success {
    --auxilia-row-bg: var(--bs-success-bg-subtle);
    --auxilia-row-color: var(--bs-success-text-emphasis);
}

[data-bs-theme="dark"] .table-warning {
    --auxilia-row-bg: var(--bs-warning-bg-subtle);
    --auxilia-row-color: var(--bs-warning-text-emphasis);
}

[data-bs-theme="dark"] .table-danger {
    --auxilia-row-bg: var(--bs-danger-bg-subtle);
    --auxilia-row-color: var(--bs-danger-text-emphasis);
}

[data-bs-theme="dark"] .table-info {
    --auxilia-row-bg: var(--bs-info-bg-subtle);
    --auxilia-row-color: var(--bs-info-text-emphasis);
}

[data-bs-theme="dark"] .table-primary,
[data-bs-theme="dark"] .table-success,
[data-bs-theme="dark"] .table-warning,
[data-bs-theme="dark"] .table-danger,
[data-bs-theme="dark"] .table-info {
    --bs-table-bg: var(--auxilia-row-bg);
    --bs-table-color: var(--auxilia-row-color);
    --bs-table-border-color: var(--bs-border-color);
    --bs-table-striped-bg: var(--auxilia-row-bg);
    --bs-table-striped-color: var(--auxilia-row-color);
    --bs-table-active-bg: var(--auxilia-row-bg);
    --bs-table-active-color: var(--auxilia-row-color);
    --bs-table-hover-bg: var(--auxilia-row-bg);
    --bs-table-hover-color: var(--auxilia-row-color);
}
