*, *::before, *::after { box-sizing: border-box; }

html, body {
    height: 100%;
    height: 100dvh;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

body {
    background: var(--mud-palette-background, #e9edf5);
    font-family: 'Plus Jakarta Sans', 'Montserrat', 'Segoe UI', sans-serif;
    color: var(--mud-palette-text-primary, #10224a);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

.mud-ripple::after { display: none !important; }

.mud-layout {
    display: flex;
    flex-direction: column;
}

.mud-main-content {
    flex: 1 1 0;
    min-height: 0;
    padding-top: 0;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
}

.app-topbar {
    box-shadow: 0 .08em .8em rgba(var(--connect-shadow-rgb), 0.1);
}

.app-topbar .mud-toolbar-appbar {
    height: var(--app-topbar-height);
}

:root {
    --app-topbar-height: 112px;
    --app-sim-banner-height: 40px;
    --app-content-inset-start: 0px;

    --connect-radius-md: 8px;
    --connect-radius-sm: 6px;
    --connect-radius-xs: 4px;

    /* Brand tints not covered by the MudBlazor palette */
    --connect-tint-faint: #f7fbff;
    --connect-tint: #e8f0ff;
    --connect-tint-strong: #dfeaff;
    --connect-surface-muted: #eef2f8;

    --connect-border: #e5e8ef;
    --connect-border-strong: #d2d8e4;

    --connect-error-surface: #fff1f1;
    --connect-error-surface-hover: #ffe4e4;

    --connect-frost-bg: rgba(255, 255, 255, 0.8);
    --connect-drawer-hover-bg: rgb(255 255 255 / 8%);
    --connect-drawer-edge: rgb(255 255 255 / 6%);

    --connect-shadow-rgb: 28, 63, 145;
    --connect-shadow-card: 0 1px 2px rgba(var(--connect-shadow-rgb), 0.06), 0 10px 24px rgba(var(--connect-shadow-rgb), 0.05);

    --connect-chip-info-bg: var(--connect-tint);
    --connect-chip-success-bg: #e4f7ed;
    --connect-chip-warning-bg: #fff1d6;
    --connect-chip-error-bg: #fdecea;
    --connect-chip-neutral-bg: var(--connect-surface-muted);
}

/* Banners are laid out above the app bar, and the clipped drawer hangs off --mud-appbar-height:
   grow it so the drawer and the main content start under whatever is stacked up there. */
.mud-layout.has-app-banner {
    --mud-appbar-height: calc(var(--app-topbar-height) + var(--app-sim-banner-height));
}

/* Degraded mode on top of a session banner (impersonation, role simulation). */
.mud-layout.has-app-banner-stack {
    --mud-appbar-height: calc(var(--app-topbar-height) + 2 * var(--app-sim-banner-height));
}

.app-sim-banner { flex-shrink: 0; }

.app-sim-banner > .mud-paper {
    height: var(--app-sim-banner-height);
    padding-top: 0 !important;
    padding-bottom: 0 !important;
}

.app-sim-banner > .mud-paper > * { height: 100%; }

/* Degraded mode (immodesk unreachable): same slot and height as the other banners. */
.app-degraded-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--app-sim-banner-height);
    padding: 0 20px;
    background: #92400e;
    color: #fff;
    font-size: 13px;
}

.app-degraded-banner .degraded-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Support impersonation banner: same slot and height as the role-simulation banner. */
.app-impersonation-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--app-sim-banner-height);
    padding: 0 20px;
    background: #b45309;
    color: #fff;
    font-size: 13px;
}

.app-impersonation-banner .impersonation-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-impersonation-banner .impersonation-stop-form {
    margin-left: auto;
    flex-shrink: 0;
}

.app-impersonation-banner .impersonation-stop {
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 6px;
    background: transparent;
    color: #fff;
    padding: 3px 12px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.app-impersonation-banner .impersonation-stop:hover {
    background: rgba(255, 255, 255, 0.12);
}

.app-sidebar {
    box-shadow: inset -1px 0 0 var(--connect-drawer-edge);
    overflow-x: clip;
}

.mud-drawer-open-persistent-left:not(.mud-drawer-open-persistent-right) .mud-main-content {
    margin-left: 0;
}

@media (min-width: 960px) {
    /* Icon-only navigation rail at every desktop size; html:root outweighs the theme's own :root. */
    html:root { --mud-drawer-width-left: 120px; }

    :root { --app-content-inset-start: var(--mud-drawer-width-left); }

    .mud-drawer-open-persistent-left:not(.mud-drawer-open-persistent-right) .mud-main-content {
        margin-left: var(--mud-drawer-width-left);
    }
}

.app-main {
    position: relative;
    /* Scope the page's stacking contexts so a page-level z-index never escapes over the shell
       (top bar, sidebar); the invoice drawer opts back above the bar via the :has rule below. */
    isolation: isolate;
    background:
        radial-gradient(58rem 40rem at 88% -6%, var(--connect-tint-strong) 0%, transparent 62%),
        radial-gradient(48rem 34rem at -8% 108%, var(--connect-tint-strong) 0%, transparent 55%),
        var(--mud-palette-primary-lighten);
    background-attachment: fixed;
    box-shadow: inset .05em .05em .05em rgba(var(--connect-shadow-rgb), 0.06);
}

/* Consulting an invoice must cover the whole shell: lift the isolated main region above the
   in-flow top bar (which carries --mud-zindex-appbar) while its temporary drawer is open. */
.app-main:has(.invoice-drawer.mud-drawer--open) {
    z-index: calc(var(--mud-zindex-appbar) + 1);
}

/* Not positioned on purpose: the Localisation page fills the content area with an absolute layer
   (.loc-full { inset: 0 }) that must resolve against .app-main, not this container. The gradient
   background lives on .app-main (isolated), so content needs no z-index of its own here. */
.app-main-content {
    width: 100%;
    max-width: 100%;
    padding-inline: 20px;
}

@media (min-width: 600px) {
    .app-main-content {
        padding-inline: 32px;
    }
}

@media (min-width: 1200px) {
    .app-main-content {
        max-width: 1120px;
        padding-inline: 40px;
    }
}

@media (min-width: 1536px) {
    .app-main-content {
        max-width: 1320px;
    }
}

/* Vertical breathing room between the top bar and the page content (shorter on laptop-height
   screens), carried by the page wrapper as on main. */
.app-page {
    padding-top: 32px;
    padding-bottom: 80px;
}

@media (min-width: 960px) {
    .app-page {
        padding-top: 80px;
    }
}

@media (min-width: 900px) and (max-width: 1599px) and (max-height: 950px) {
    .app-page {
        padding-top: 48px;
    }
}

.vh-100 { height: 100vh; height: 100dvh; }
.min-w-0 { min-width: 0; }
.min-h-0 { min-height: 0; }
.min-h-full { min-height: 100%; }

.text-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-nowrap { white-space: nowrap; }

.border-bottom-divider {
    border-bottom: 1px solid var(--mud-palette-divider);
}

.connect-card {
    border: 1px solid rgba(var(--mud-palette-primary-rgb), 0.08);
    border-radius: var(--connect-radius-md);
    background: var(--mud-palette-surface);
    box-shadow: var(--connect-shadow-card);
}

.connect-card-action {
    border-radius: var(--connect-radius-md);
    min-height: 48px;
    padding: 7px 22px;
    font-weight: 600;
}

.mud-input-control {
    --mud-default-borderradius: var(--connect-radius-md);
}

.mud-chip {
    font-weight: 700;
}

.mud-chip.mud-chip-size-small {
    height: 26px;
    padding: 0 10px;
}

.invoice-drawer {
    --mud-palette-drawer-background: var(--mud-palette-background-gray);
    --mud-palette-drawer-text: var(--mud-palette-text-primary);
}

.mud-chip.mud-chip-text { background-color: var(--connect-chip-neutral-bg); }
.mud-chip.mud-chip-text.mud-chip-color-info { background-color: var(--connect-chip-info-bg); }
.mud-chip.mud-chip-text.mud-chip-color-success { background-color: var(--connect-chip-success-bg); }
.mud-chip.mud-chip-text.mud-chip-color-warning { background-color: var(--connect-chip-warning-bg); }
.mud-chip.mud-chip-text.mud-chip-color-error { background-color: var(--connect-chip-error-bg); }

/* MudMenu popovers render outside their component subtree, so these styles cannot be isolated. */
.lease-menu-popover {
    max-height: min(320px, 40dvh);
    overflow-y: auto;
}

.building-menu-popover {
    width: min(400px, calc(100vw - 32px));
}

@media (max-width: 599px) {
    .building-menu-popover {
        left: 12px !important;
        width: calc(100vw - 24px);
        max-width: calc(100vw - 24px);
    }
}

.building-menu-popover.mud-popover-open {
    animation: building-menu-reveal 50ms steps(1, end) both;
}

@keyframes building-menu-reveal {
    from { opacity: 0; }
    to { opacity: 1; }
}

.user-menu-popover {
    min-width: 220px;
    max-width: 100%;
    overflow: hidden;
    border: 1px solid rgba(var(--mud-palette-primary-rgb), 0.12);
    border-radius: 6px;
    background: var(--mud-palette-surface);
    box-shadow: 0 12px 28px rgba(var(--connect-shadow-rgb), 0.12);
}

.user-menu-list {
    padding: 0;
}

.user-menu-list > .mud-divider {
    margin: 0 !important;
}

.user-menu-item {
    min-height: 42px;
    padding: 8px 16px;
    color: var(--mud-palette-text-primary);
    font-size: 14px;
    font-weight: 600;
}

.user-menu-item:hover {
    background: rgba(var(--mud-palette-primary-rgb), 0.06);
}

.user-menu-item .mud-list-item-icon {
    min-width: 34px;
    color: var(--mud-palette-text-secondary) !important;
}

.user-menu-item .mud-list-item-icon .mud-icon-root {
    font-size: 20px;
}


/* État d'un bail dans les sélecteurs : rendu hors du sous-arbre du composant (popover MudSelect),
   donc stylé globalement plutôt qu'en CSS isolé. */
.lease-state-chip {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: #92400e;
    background: var(--connect-chip-warning-bg, rgba(146, 64, 14, 0.12));
    vertical-align: middle;
}

/* Localisation (Mapbox) : le canevas, l'overlay de chargement, les marqueurs et les popups sont
   créés par wwwroot/js/locataire-map.js hors du sous-arbre Blazor, donc stylés globalement. */
.locataire-map-canvas {
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity 0.24s ease;
}

.locataire-map-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--mud-palette-background-grey, #eef2f8);
    transition: opacity 0.24s ease;
    z-index: 1;
}

.locataire-map-spinner {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 3px solid rgba(var(--mud-palette-primary-rgb), 0.2);
    border-top-color: var(--mud-palette-primary);
    animation: locataire-map-spin 0.8s linear infinite;
}

@keyframes locataire-map-spin {
    to { transform: rotate(360deg); }
}

.locataire-map-building {
    /* Mapbox writes an inline transform on this element for positioning, so the visual pin (with
       its own rotation) lives in a child that Mapbox never touches. */
    cursor: pointer;
}

.locataire-map-building-pin {
    width: 54px;
    height: 54px;
    display: grid;
    place-items: center;
    border-radius: 18px 18px 18px 4px;
    background: #071a44;
    color: #fff;
    box-shadow: 0 16px 34px rgba(7, 26, 68, 0.28);
}

/* The bubble sits square with its pointed corner at the bottom left; the icon stays upright. */
.locataire-map-building-pin svg {
    width: 27px;
    height: 27px;
    display: block;
    fill: currentColor;
}

.locataire-map-poi {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--poi-color, #607d8b);
    color: #fff;
    box-shadow: 0 8px 18px rgba(7, 26, 68, 0.18), inset 0 0 0 3px rgba(255, 255, 255, 0.75);
    cursor: pointer;
}

/* Inherited fill tints every glyph shape (path, circle, rect...) while the icons' own
   fill="none" guard shapes keep their attribute, which beats inheritance. */
.locataire-map-poi svg {
    width: 20px;
    height: 20px;
    display: block;
    fill: currentColor;
}

.locataire-map-popup {
    display: grid;
    gap: 2px;
    font-family: 'Plus Jakarta Sans', 'Segoe UI', sans-serif;
    padding: 2px 4px;
}

.locataire-map-popup strong {
    font-size: 13px;
    color: #10224a;
}

.locataire-map-popup-category {
    font-size: 12px;
    font-weight: 600;
    color: var(--mud-palette-text-secondary, #5a6b8c);
}

.locataire-map-popup-distance {
    font-size: 12px;
    color: var(--mud-palette-text-secondary, #5a6b8c);
}

.locataire-map-popup-walkscore {
    margin-top: 2px;
    font-size: 12px;
    font-weight: 800;
}
