/* =================================================================
   Andex Hub — global stylesheet
   Self-hosted Inter + JetBrains Mono with system-font fallback.
   ================================================================= */

@font-face {
    font-family: 'Inter';
    font-weight: 400;
    font-style: normal;
    font-display: swap;
    src: url('/fonts/Inter-Regular.woff2') format('woff2');
}
@font-face {
    font-family: 'Inter';
    font-weight: 500;
    font-style: normal;
    font-display: swap;
    src: url('/fonts/Inter-Medium.woff2') format('woff2');
}
@font-face {
    font-family: 'Inter';
    font-weight: 600;
    font-style: normal;
    font-display: swap;
    src: url('/fonts/Inter-SemiBold.woff2') format('woff2');
}
@font-face {
    font-family: 'Inter';
    font-weight: 700;
    font-style: normal;
    font-display: swap;
    src: url('/fonts/Inter-Bold.woff2') format('woff2');
}
@font-face {
    font-family: 'JetBrains Mono';
    font-weight: 400;
    font-style: normal;
    font-display: swap;
    src: url('/fonts/JetBrainsMono-Regular.woff2') format('woff2');
}

html, body {
    margin: 0;
    padding: 0;
    font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

code, pre, kbd, samp {
    font-family: 'JetBrains Mono', 'Cascadia Code', Consolas, monospace;
}

/* Custom focus ring (WCAG AA, overrides browser default) */
*:focus-visible {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Selection color */
::selection {
    background-color: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
}

/* Scrollbars (subtle, themed) */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--mud-palette-lines-default) transparent;
}
*::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
*::-webkit-scrollbar-track {
    background: transparent;
}
*::-webkit-scrollbar-thumb {
    background-color: var(--mud-palette-lines-default);
    border-radius: 4px;
}
*::-webkit-scrollbar-thumb:hover {
    background-color: var(--mud-palette-text-disabled);
}

/* =================================================================
   Layout: 3-column structure (rail + secondary + main + optional right)
   ================================================================= */
.andex-app {
    display: grid;
    grid-template-columns: 72px auto 1fr;
    grid-template-rows: 56px 1fr;
    grid-template-areas:
        "rail topbar topbar"
        "rail secondary main";
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    background: var(--mud-palette-background);
    color: var(--mud-palette-text-primary);
}

.andex-app--has-right {
    grid-template-columns: 72px auto 1fr 280px;
    grid-template-areas:
        "rail topbar topbar topbar"
        "rail secondary main right";
}

.andex-app--no-secondary {
    grid-template-columns: 72px 1fr;
    grid-template-areas:
        "rail topbar"
        "rail main";
}
.andex-app--no-secondary.andex-app--has-right {
    grid-template-columns: 72px 1fr 280px;
    grid-template-areas:
        "rail topbar topbar"
        "rail main right";
}

.andex-rail {
    grid-area: rail;
    background: var(--mud-palette-drawer-background);
    color: var(--mud-palette-drawer-text);
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.andex-topbar {
    grid-area: topbar;
    background: var(--mud-palette-appbar-background);
    color: var(--mud-palette-appbar-text);
    border-bottom: 1px solid var(--mud-palette-divider);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    gap: 1rem;
    z-index: 10;
}

.andex-topbar-hamburger { display: none; }
.andex-topbar-search-icon { display: none; }
@media (max-width: 768px) {
    .andex-topbar { padding: 0 .25rem; gap: .25rem; }
    .andex-topbar-hamburger { display: inline-flex !important; }
    .andex-topbar-search { display: none !important; }
    .andex-topbar-search-icon { display: inline-flex !important; }
    .andex-topbar-desktop-only { display: none !important; }
    .andex-topbar-brand-name { display: none; }
    .andex-topbar-breadcrumb {
        max-width: 50vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: .85rem;
    }
}

.andex-secondary {
    grid-area: secondary;
    background: var(--mud-palette-surface);
    border-right: 1px solid var(--mud-palette-divider);
    overflow-y: auto;
    width: 320px;
}

.andex-main {
    grid-area: main;
    overflow-y: auto;
    padding: 1.5rem;
    background: var(--mud-palette-background);
}

/* Subtle per-module page tint — kicks in only when --module-accent is set
   on the .andex-app container by MainLayout. Mixes 4% of the accent into
   the page background, so it works for both light and dark themes. */
.andex-app[data-module] .andex-main {
    background: color-mix(in srgb, var(--module-accent, transparent) 4%, var(--mud-palette-background));
}

.andex-right {
    grid-area: right;
    background: var(--mud-palette-surface);
    border-left: 1px solid var(--mud-palette-divider);
    overflow-y: auto;
}

/* =================================================================
   Icon Rail
   ================================================================= */
.andex-rail-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 56px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    cursor: pointer;
}

.andex-rail-items {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 8px 0;
    gap: 2px;
    overflow-y: auto;
}

.andex-rail-footer {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 8px 0;
    gap: 2px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.andex-rail-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 4px;
    margin: 0 8px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--mud-palette-drawer-icon);
    text-decoration: none;
    position: relative;
    transition: background-color 120ms ease;
}
.andex-rail-item:hover {
    background-color: color-mix(in srgb, var(--module-accent, #FFFFFF) 8%, transparent);
    color: var(--mud-palette-drawer-text);
}
.andex-rail-item--active {
    background-color: color-mix(in srgb, var(--module-accent, #175DDC) 16%, transparent);
    color: #FFFFFF;
}
.andex-rail-item--active::before {
    content: "";
    position: absolute;
    left: -8px;
    top: 12px;
    bottom: 12px;
    width: 3px;
    background-color: var(--module-accent, var(--mud-palette-primary));
    border-radius: 0 2px 2px 0;
}
.andex-rail-item-icon {
    font-size: 22px;
    line-height: 1;
}
.andex-rail-item-label {
    font-size: 0.625rem;
    font-weight: 500;
    margin-top: 4px;
    letter-spacing: 0.02em;
}
.andex-rail-badge {
    position: absolute;
    top: 4px;
    right: 8px;
    background-color: var(--mud-palette-error);
    color: #FFFFFF;
    font-size: 0.625rem;
    font-weight: 600;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    padding: 0 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* =================================================================
   Top bar
   ================================================================= */
.andex-topbar-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
}
.andex-topbar-breadcrumb {
    color: var(--mud-palette-text-secondary);
    font-size: 0.875rem;
}
.andex-topbar-search {
    flex: 1;
    max-width: 600px;
    margin: 0 auto;
}
.andex-topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* =================================================================
   Login page (centered card on full-bleed background)
   ================================================================= */
.andex-login-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--mud-palette-background);
    padding: 1rem;
}
.andex-login-card {
    width: 100%;
    max-width: 400px;
    padding: 2rem;
    border-radius: 12px;
    background: var(--mud-palette-surface);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    border: 1px solid var(--mud-palette-divider);
}
.andex-login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
}
.andex-login-brand-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--mud-palette-text-primary);
}
.andex-login-subtitle {
    text-align: center;
    color: var(--mud-palette-text-secondary);
    font-size: 0.875rem;
    margin-bottom: 1.5rem;
}

.andex-login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.andex-form-field {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}
.andex-form-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--mud-palette-text-primary);
}
.andex-form-input {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--mud-palette-lines-inputs);
    border-radius: 4px;
    background: var(--mud-palette-surface);
    color: var(--mud-palette-text-primary);
    font-family: inherit;
    font-size: 0.875rem;
    transition: border-color 120ms ease, box-shadow 120ms ease;
    box-sizing: border-box;
}
.andex-form-input:focus {
    outline: none;
    border-color: var(--mud-palette-primary);
    box-shadow: 0 0 0 3px rgba(23, 93, 220, 0.15);
}
.andex-form-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--mud-palette-text-primary);
    cursor: pointer;
}
.andex-form-submit {
    width: 100%;
    padding: 0.75rem;
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
    border: none;
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 120ms ease;
    margin-top: 0.5rem;
}
.andex-form-submit:hover {
    background: var(--mud-palette-primary-darken);
}
.andex-form-submit:active {
    transform: translateY(1px);
}

/* =================================================================
   Mobile (responsive switch <= 768px)
   ================================================================= */
@media (max-width: 768px) {
    .andex-app,
    .andex-app--has-right,
    .andex-app--no-secondary,
    .andex-app--no-secondary.andex-app--has-right {
        grid-template-columns: 1fr;
        grid-template-rows: 56px 1fr 64px;
        grid-template-areas:
            "topbar"
            "main"
            "bottomnav";
    }
    .andex-rail,
    .andex-right {
        display: none;
    }

    /* Secondary pane becomes a slide-in drawer over main content. */
    .andex-secondary {
        position: fixed;
        top: 56px;
        bottom: 64px;
        left: 0;
        width: min(86vw, 340px);
        z-index: 900;
        box-shadow: 4px 0 16px rgba(0, 0, 0, 0.18);
        transform: translateX(-105%);
        transition: transform 0.18s ease-out;
    }
    .andex-secondary--open { transform: translateX(0); }
    .andex-secondary-close-bar {
        display: flex;
        justify-content: flex-end;
        padding: 4px 4px 0;
    }

    /* Backdrop scrim that catches taps to close the drawer. */
    .andex-drawer-scrim {
        position: fixed;
        top: 56px;
        bottom: 64px;
        left: 0;
        right: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 800;
    }

    /* Main content gets vertical padding back since splitters are stacked. */
    .andex-main { padding: 1rem; }

    /* Touch targets: ensure tappable controls are at least 40px. */
    .andex-main .mud-button-root { min-height: 40px; }
}

/* Hide the close button and scrim on desktop — only meaningful in drawer mode. */
@media (min-width: 769px) {
    .andex-secondary-close-bar { display: none; }
    .andex-drawer-scrim { display: none; }
}

/* IconRail re-skinned when embedded in the mobile drawer: full-width rows
   with icon + label side-by-side instead of the slim vertical icon strip. */
@media (max-width: 768px) {
    .andex-secondary--mobile .andex-rail {
        position: static;
        background: transparent;
        color: inherit;
        border-right: none;
        height: auto;
        display: block;
    }
    .andex-secondary--mobile .andex-rail-logo { display: none; }
    .andex-secondary--mobile .andex-rail-items {
        display: flex;
        flex-direction: column;
        padding: 4px 0;
    }
    .andex-secondary--mobile .andex-rail-item {
        flex-direction: row;
        justify-content: flex-start;
        gap: 14px;
        padding: 10px 16px;
        margin: 0;
        border-radius: 0;
        color: inherit;
    }
    .andex-secondary--mobile .andex-rail-item:hover { background: rgba(0,0,0,0.04); }
    .andex-secondary--mobile .andex-rail-item--active {
        background: rgba(23, 93, 220, 0.10);
        color: var(--mud-palette-primary);
    }
    .andex-secondary--mobile .andex-rail-item--active::before { display: none; }
    .andex-secondary--mobile .andex-rail-item-label {
        font-size: 0.95rem;
        font-weight: 500;
        margin-top: 0;
        letter-spacing: 0;
    }
    .andex-secondary--mobile .andex-rail-badge {
        position: static;
        margin-left: auto;
    }
    .andex-secondary--mobile .andex-rail-footer {
        display: flex;
        flex-direction: column;
        border-top: 1px solid var(--mud-palette-divider);
        padding: 4px 0;
        margin-top: 8px;
    }
}

/* Generic helper class — apply to any element that should disappear on mobile. */
@media (max-width: 768px) {
    .andex-mobile-hide { display: none !important; }
}

/* Mobile typography scale-down. MudBlazor uses rem units so reducing the root
   shrinks all body text consistently. Inputs stay at 16px so iOS Safari does
   NOT zoom in when a field is focused. */
@media (max-width: 768px) {
    html { font-size: 14px; }
    input, textarea, select,
    .mud-input-slot input,
    .mud-input-slot textarea { font-size: 16px !important; }
    .andex-main { padding: .75rem; }
}

/* Mobile: dialogs go full-screen so users can use the whole viewport. */
@media (max-width: 768px) {
    .mud-dialog-container.mud-dialog-center {
        align-items: stretch;
        justify-content: stretch;
    }
    .mud-dialog {
        max-width: 100vw !important;
        max-height: 100vh !important;
        margin: 0 !important;
        border-radius: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        display: flex !important;
        flex-direction: column;
    }
    .mud-dialog-content {
        flex: 1;
        overflow-y: auto;
        max-height: none !important;
    }
    .mud-dialog-actions { padding: .5rem .75rem; flex-wrap: wrap; }
}

.andex-bottomnav {
    grid-area: bottomnav;
    display: none;
    background: var(--mud-palette-surface);
    border-top: 1px solid var(--mud-palette-divider);
    z-index: 850;
}
@media (max-width: 768px) {
    .andex-bottomnav {
        display: flex;
        justify-content: space-around;
        align-items: stretch;
    }
}

.andex-bottomnav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: none;
    background: transparent;
    color: inherit;
    padding: 6px 4px;
    cursor: pointer;
    font: inherit;
    -webkit-tap-highlight-color: transparent;
}
.andex-bottomnav-btn.is-active { color: var(--mud-palette-primary); }
.andex-bottomnav-btn:focus-visible { outline: 2px solid var(--mud-palette-primary); outline-offset: -2px; }
.andex-bottomnav-icon-wrap { position: relative; line-height: 1; }
.andex-bottomnav-label { font-size: 0.7rem; line-height: 1; }
.andex-bottomnav-badge {
    position: absolute;
    top: -4px;
    right: -8px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--mud-palette-error);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* =================================================================
   Blazor error UI (server-rendered fallback)
   ================================================================= */
#blazor-error-ui {
    background: var(--mud-palette-error);
    color: white;
    bottom: 0;
    box-shadow: 0 -1px 4px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.75rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    font-weight: 500;
}
#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}
