/* RiskDesk global stylesheet.
   A style goes to the first step that fits: a MudBlazor parameter or RiskDeskTheme, a MudBlazor utility class,
   an app utility of this file, the component's .razor.css, then this file for what is global only.
   Traps of the dressing below:
   - RiskDeskTheme.LayoutProperties.AppbarHeight reads --app-header-height: the two-row app bar sets its own
     height, and the role simulation banner adds its height to it.
   - The button typography of the theme has no text transform: no rule repeats it.
   - MudBlazor's dark mode swaps its palette variables only: AppLayout puts .app-dark on its .app-theme wrapper,
     which redefines the --app-* colors below it. Popovers render outside that wrapper and keep the light values.
   Sections: tokens, base, shell, MudBlazor dressing, out-of-tree DOM, app utilities, mobile. */

/* ─── Tokens ────────────────────────────────────────────────── */
:root {
    --app-header-height: 128px;
    --app-sim-banner-height: 40px;

    /* Severity ramp of incidents and risks: Mineur, Modéré, Majeur/Élevé, Critique. Kept in sync with
       IncidentPdfTheme (Infrastructure) for the PDF export. */
    --app-severity-1: #758195;
    --app-severity-2: #B77A5A;
    --app-severity-3: #D24B3C;
    --app-severity-4: #A61E22;
    --app-severity-1-bg: #EEF0F3;
    --app-severity-2-bg: #F5ECE3;
    --app-severity-3-bg: #FBE2DE;
    --app-severity-4-bg: #F5DBDC;

    /* Alert banner of the incidents dashboard: a dark red apart from the theme, weighted like a critical alert,
       in both modes. */
    --app-alert-banner-bg: #4A1116;
    --app-alert-banner-text: #F5DBDC;

    /* Trend badges: light green for an improvement, light red for a degradation. */
    --app-trend-improvement: #6FCF97;
    --app-trend-degradation: #EB9694;

    /* Pointer under the criticality gauge. */
    --app-gauge-pointer: #4a4a4a;
}

/* Dark mode: the severity ramp lightened to read on the dark surface, its tints mixed into that surface. */
.app-dark {
    --app-severity-1: #9BA5B7;
    --app-severity-2: #D49B7B;
    --app-severity-3: #EC7462;
    --app-severity-4: #F06A6E;
    --app-severity-1-bg: color-mix(in srgb, var(--app-severity-1) 18%, var(--mud-palette-surface));
    --app-severity-2-bg: color-mix(in srgb, var(--app-severity-2) 18%, var(--mud-palette-surface));
    --app-severity-3-bg: color-mix(in srgb, var(--app-severity-3) 18%, var(--mud-palette-surface));
    --app-severity-4-bg: color-mix(in srgb, var(--app-severity-4) 18%, var(--mud-palette-surface));

    --app-gauge-pointer: #c5c7d4;
}

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

html, body {
    height: 100%;
    height: 100dvh;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: var(--mud-palette-background, #f0eee9);
}

/* ─── Shell ─────────────────────────────────────────────────── */
/* AppLayout's wrapper carries .app-dark only: it takes no box, so the layout is unchanged. */
.app-theme { display: contents; }

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

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

/* The app bar is in-flow with height:auto, so --mud-appbar-height only drives the top offset of the clipped
   drawer. Anything stacked above the app bar must be added to it, or the drawer slides under the header. */
.mud-layout.has-role-simulation {
    --mud-appbar-height: calc(var(--app-header-height) + var(--app-sim-banner-height));
}

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

/* !important beats the py-1 utility (padding-top/bottom: 4px !important) that Perial.Blazor's
   RoleSimulationBanner puts on its MudPaper. */
.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%; }

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

/* Two-row auto-height header. */
.app-header.mud-appbar {
    position: relative;
    height: auto;
    padding: 0;
    flex-shrink: 0;
    z-index: var(--mud-zindex-appbar);
}

.app-header .mud-toolbar,
.app-header .mud-toolbar-appbar {
    flex-direction: column;
    align-items: stretch;
    height: auto;
    min-height: auto;
}

.app-header-subtitle {
    opacity: 0.7;
}

/* Top navigation tabs. */
.nav-row {
    overflow-x: auto;
    scrollbar-width: thin;
}

.nav-tab.mud-button-root {
    border-radius: 0;
    min-width: auto;
    padding: 8px 16px;
    font-weight: 400;
    font-size: 0.8125rem;
    opacity: 0.7;
    white-space: nowrap;
    flex-shrink: 0;
    transition: opacity 0.2s, background-color 0.2s;
}

.nav-tab.mud-button-root .mud-icon-button-label,
.nav-tab.mud-button-root .mud-button-icon-start {
    font-size: 1.125rem;
    margin-right: 4px;
}

.nav-tab.mud-button-root:hover:not(:disabled) {
    opacity: 1;
    background-color: rgba(128, 128, 128, 0.12);
}

.nav-tab-active.mud-button-root {
    opacity: 1;
    font-weight: 500;
    box-shadow: inset 0 -3px 0 0 currentColor;
}

/* ─── MudBlazor dressing ────────────────────────────────────── */
/* Label of a control that is not a MudBlazor input (rich text editor, criticality selector, attachment
   list): the size and color of a filled outlined MudBlazor label (1rem scaled 0.75, text-secondary), so
   every label of a form reads the same. */
.app-field-label {
    display: block;
    font-size: 0.75rem;
    line-height: 1.5;
    color: var(--mud-palette-text-secondary);
}

/* ─── Out-of-tree DOM ───────────────────────────────────────── */
/* Snackbars, rendered by the snackbar provider: below the app bar. */
.mud-snackbar-location-top-left,
.mud-snackbar-location-top-center,
.mud-snackbar-location-top-right { top: 64px; }

/* Field help tooltips, rendered by the popover provider: wrapped text, left-aligned. !important beats the
   inline max-width: none that MudPopover writes on the tooltip. */
.riskdesk-field-help-tooltip {
    max-width: 260px !important;
    white-space: normal;
    text-align: left;
    line-height: 1.35;
}

/* Rich text editor: Quill renders its toolbar and container in JavaScript. */
.rte-field {
    display: flex;
    flex-direction: column;
}

.rte-editor {
    background: var(--mud-palette-surface);
    min-height: 120px;
}

.rte-field .ql-toolbar.ql-snow,
.rte-field .ql-container.ql-snow {
    border-color: var(--mud-palette-lines-inputs);
}

/* quill.snow.css sets Helvetica on the toolbar (the heading picker shows text) and Helvetica 13px on the
   content: both inherit the theme's font instead, at the size MudBlazor inputs use (font: inherit from body),
   so the editor reads like every other field of a form. */
.rte-field .ql-toolbar.ql-snow {
    border-top-left-radius: var(--mud-default-borderradius);
    border-top-right-radius: var(--mud-default-borderradius);
    font-family: inherit;
}

.rte-field .ql-container.ql-snow {
    border-bottom-left-radius: var(--mud-default-borderradius);
    border-bottom-right-radius: var(--mud-default-borderradius);
    font-family: inherit;
    font-size: inherit;
}

/* Quill's placeholder is italic and 60% black (unreadable in dark mode): upright and current color at 42%,
   like the placeholder of a MudBlazor input. */
.rte-field .ql-editor.ql-blank::before {
    font-style: normal;
    color: currentColor;
    opacity: 0.42;
}

/* Lets a .flex-grow-1 editor (e.g. Description du risque) stretch to match a sibling column's
   height — the .ql-container height:100% from quill.snow.css would otherwise fight the flex
   layout for space instead of filling what's left after the label and toolbar. */
.rte-field.flex-grow-1 .ql-container.ql-snow {
    flex: 1 1 auto;
    height: auto;
}

/* Rich text read-only rendering: HTML written by the editor, rendered as MarkupString. */
.rte-content {
    overflow-wrap: anywhere;
}

.rte-content p {
    margin: 0 0 0.5rem;
}

.rte-content p:last-child {
    margin-bottom: 0;
}

.rte-content ul,
.rte-content ol {
    margin: 0 0 0.5rem;
    padding-left: 1.5rem;
}

/* ─── App utilities ─────────────────────────────────────────── */
/* What MudBlazor 9 lacks. The text-align and font-weight utilities are !important like MudBlazor's own:
   they beat .mud-table-cell { text-align: start } and the font weight of the typography classes. */
.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; }
.text-pre-wrap { white-space: pre-wrap; }
.text-right { text-align: right !important; }
.text-center { text-align: center !important; }
.fw-300 { font-weight: 300 !important; }
.fw-700 { font-weight: 700 !important; }

/* Long text wraps on two lines at most (put the full text in a title attribute): a table cell shrinks instead of
   widening the table, so a page never scrolls horizontally. Goes on a block inside the cell, never on the cell. */
.text-clamp-2 {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    overflow-wrap: anywhere;
}

/* Width of the short "Code" field of the reference and risk forms. */
.app-code-field { max-width: 160px; }

/* ─── Mobile ────────────────────────────────────────────────── */
@media (max-width: 600px) {
    /* The side panels (Width="var(--app-side-drawer-width, …)") cover the whole screen on a phone. */
    .mud-drawer.mud-drawer-temporary { --app-side-drawer-width: 100vw; }

    .mud-snackbar { font-size: 0.8rem; padding: 6px 10px; min-width: 0; }
    .mud-snackbar-location-top-right { right: 8px; left: 8px; width: auto; }
}
