/* Appearance settings (ported from the INApp framework, FW.V5): the Appearance dialog puts its choices on <html> as data-*
   attributes (AppearanceRules.Attributes) and this file reads them. Mode, accent and High contrast are not here: they are the
   theme (InfenceThemes, the data-infence-theme / data-infence-mode attributes and the MudBlazor palette).

   Every option works by overriding the design tokens of infence-shell.css (density, radius, drawer width) or by one small rule, so a
   page needs no markup for any of it. The shipped defaults (comfortable, 14px, rounded, full width, full sidebar, striped rows,
   sticky headers, normal motion and targets) set nothing here: they are the shell's own look. Link this file after
   infence-shell.css and infence-components.css. */

/* ===== Accent: buttons and highlights ========================================================= */
/* Filled buttons and highlights take the accent as --accent-fill with --accent-ink on top. Light mode: a saturated colour with white
   text (the same colour reads as link text on white). Dark mode: a brighter shade of the hue with a very dark ink, so a button stands
   out from the dark card. The values mirror AppearanceRules.AccentFillHex / AccentInkHex (pinned by AppearanceTests); the default is
   the blue. High contrast keeps its own solid colours. */
:root {
    --accent-fill: #2563EB;
    --accent-ink: #FFFFFF;
    --accent-soft: color-mix(in srgb, var(--accent-fill) 12%, transparent);
    --accent-soft-hover: color-mix(in srgb, var(--accent-fill) 18%, transparent);
}

:root[data-infence-mode="dark"] {
    --accent-fill: #60A5FA;
    --accent-ink: #0B1B33;
    --accent-soft: color-mix(in srgb, var(--accent-fill) 16%, transparent);
    --accent-soft-hover: color-mix(in srgb, var(--accent-fill) 24%, transparent);
}

:root[data-infence-theme="contrast"] {
    --accent-soft: rgba(var(--mud-palette-primary-rgb), var(--tint-strong));
    --accent-soft-hover: rgba(var(--mud-palette-primary-rgb), .18);
}

html[data-accent="teal"]   { --accent-fill: #0F766E; --accent-ink: #FFFFFF; }
html[data-accent="indigo"] { --accent-fill: #4F46E5; --accent-ink: #FFFFFF; }
html[data-accent="green"]  { --accent-fill: #15803D; --accent-ink: #FFFFFF; }
html[data-accent="rose"]   { --accent-fill: #E11D48; --accent-ink: #FFFFFF; }

:root[data-infence-mode="dark"][data-accent="teal"]   { --accent-fill: #2DD4BF; --accent-ink: #052E2B; }
:root[data-infence-mode="dark"][data-accent="indigo"] { --accent-fill: #818CF8; --accent-ink: #14123D; }
:root[data-infence-mode="dark"][data-accent="green"]  { --accent-fill: #4ADE80; --accent-ink: #052E16; }
:root[data-infence-mode="dark"][data-accent="rose"]   { --accent-fill: #FB7185; --accent-ink: #4C0519; }

:root:not([data-infence-theme="contrast"]) .mud-button-filled.mud-button-filled-primary:not(.mud-button-disabled) {
    background-color: var(--accent-fill);
    color: var(--accent-ink);
}

:root:not([data-infence-theme="contrast"]) .mud-button-filled.mud-button-filled-primary:not(.mud-button-disabled):hover {
    background-color: color-mix(in srgb, var(--accent-fill) 86%, #000);
}

/* ===== Layout density ======================================================================== */
/* The tokens the shell sizes rows, controls, gutters and bars from. `html[...]` outranks the `:root` block that declares them. */
html[data-density="compact"] {
    --control-h: 36px;
    --control-h-compact: 32px;
    --row-pad-y: 6px;
    --row-pad-x: 12px;
    --pad-tight: 8px;
    --pad-base: 12px;
    --pad-roomy: 20px;
    --gap: 12px;
    --shell-bar-h: 50px;
    --nav-item-h: 34px;
}

html[data-density="dense"] {
    --control-h: 32px;
    --control-h-compact: 28px;
    --row-pad-y: 3px;
    --row-pad-x: 10px;
    --pad-tight: 6px;
    --pad-base: 8px;
    --pad-roomy: 16px;
    --gap: 8px;
    --shell-bar-h: 44px;
    --nav-item-h: 30px;
}

/* MudBlazor sizes a dense outlined input from its slot padding (10.5px: a 38.8px field). */
html[data-density="compact"] .mud-input-slot.mud-input-root-outlined.mud-input-root-margin-dense {
    padding-top: 8.5px;
    padding-bottom: 8.5px;
}

html[data-density="dense"] .mud-input-slot.mud-input-root-outlined.mud-input-root-margin-dense {
    padding-top: 6.5px;
    padding-bottom: 6.5px;
}

html[data-density="dense"] .mud-chip.mud-chip-size-small { height: 20px; }
html[data-density="dense"] .mud-button-root:not(.mud-icon-button) { padding-top: 3px; padding-bottom: 3px; }

/* ===== Text size ============================================================================= */
/* Every type size in the stylesheets and the MudBlazor theme is in rem, so the root size scales them all. */
html[data-text="small"] { font-size: 90%; }
html[data-text="large"] { font-size: 112.5%; }

/* ===== Font ================================================================================== */
/* Inter (the default) is self-hosted and set by the theme; System swaps every MudBlazor type style to the device's own UI font.
   Only fonts that need no download are offered, because the console has to work offline (no CDN, see infence-shell.css). */
html[data-font="system"] {
    --mud-typography-default-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mud-typography-h1-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mud-typography-h2-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mud-typography-h3-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mud-typography-h4-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mud-typography-h5-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mud-typography-h6-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mud-typography-subtitle1-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mud-typography-subtitle2-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mud-typography-body1-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mud-typography-body2-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mud-typography-button-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mud-typography-caption-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mud-typography-overline-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ===== Corners =============================================================================== */
/* The radius scale of infence-shell.css, plus MudBlazor's own default radius. Fully round shapes (999px) stay round
   except chips, which follow the corners too. */
html[data-corners="soft"] {
    --radius-xs: 2px;
    --radius-sm: 3px;
    --radius-md: 4px;
    --radius-lg: 6px;
    --radius-xl: 8px;
    --mud-default-borderradius: 4px;
}

html[data-corners="sharp"] {
    --radius-xs: 0;
    --radius-sm: 0;
    --radius-md: 0;
    --radius-lg: 0;
    --radius-xl: 0;
    --mud-default-borderradius: 0;
}

html[data-corners="soft"] .mud-chip.mud-chip-size-small { border-radius: 4px; }
html[data-corners="sharp"] .mud-chip.mud-chip-size-small { border-radius: 0; }

/* ===== Page width ============================================================================ */
/* Centered: ordinary pages stop at a comfortable reading width. Full-screen pages (the Live map, Devices, Fuel, Device health)
   fill the window by design and ignore it. */
html[data-width="centered"] .infence-page:not(:has(> .livemap, > .devices-page, > .fill-bleed)) {
    width: 100%;
    max-width: 1440px;
    margin-inline: auto;
}

/* ===== Sidebar ================================================================================ */
/* MudBlazor sizes the drawer, and the content beside it, from this variable. */
html[data-sidebar="narrow"] { --mud-drawer-width-left: 200px; }

/* A folded sidebar leaves the sheet with the canvas inset on its left, as on the other three sides, and the page header
   clears the "show sidebar" button that sits in the corner (as it does for the phone toggle in PageHeader.razor.css). */
@media (min-width: 960px) {
    .infence-shell .mud-drawer.mud-drawer--closed ~ .mud-main-content { padding-left: 8px; }
    .infence-shell .mud-drawer.mud-drawer--closed ~ .mud-main-content .cockpit__lead { padding-left: 44px; }
}

/* ===== Tables ================================================================================ */
/* The shell stripes every table (Striped="true" on the markup); this switches it off, leaving the hover wash. */
html[data-stripes="off"] .mud-table-striped .mud-table-body .mud-table-row:not(:hover) {
    background-color: transparent;
}

/* Headers scroll with the rows instead of staying put. */
html[data-sticky="off"] .mud-table-container .mud-table-head .mud-table-cell,
html[data-sticky="off"] .surface-panel--fill .mud-table-container .mud-table-head .mud-table-cell {
    position: static !important;
}

/* ===== Accessibility ========================================================================= */
/* Reduce motion: the same collapse as the prefers-reduced-motion rule in infence-shell.css, for people who ask for it here. */
html[data-motion="reduced"] *,
html[data-motion="reduced"] *::before,
html[data-motion="reduced"] *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
}

/* Large targets: 44px, the size of a thumb. */
html[data-targets="large"] {
    --control-h: 44px;
    --control-h-compact: 44px;
    --nav-item-h: 44px;
    --row-pad-y: 12px;
}

html[data-targets="large"] .mud-button-root,
html[data-targets="large"] .mud-icon-button,
html[data-targets="large"] .mud-menu-item,
html[data-targets="large"] .mud-list-item,
html[data-targets="large"] .nav__item,
html[data-targets="large"] .ap-seg-item,
html[data-targets="large"] .ap-swatch { min-height: 44px; }

html[data-targets="large"] .mud-icon-button { min-width: 44px; }
html[data-targets="large"] .mud-input-slot.mud-input-root-outlined.mud-input-root-margin-dense { padding-top: 12px; padding-bottom: 12px; }
html[data-targets="large"] :where(.mud-checkbox, .mud-switch) { min-height: 44px; }

/* ===== The Appearance dialog ================================================================== */
.ap-groups { display: flex; flex-direction: column; gap: 22px; }
.ap-group { display: flex; flex-direction: column; gap: 14px; }

.ap-group-title {
    font-size: .6875rem;
    font-weight: 650;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--mud-palette-text-secondary);
    padding-bottom: 4px;
    border-bottom: 1px solid var(--edge, var(--mud-palette-lines-default));
}

.ap-opt { display: flex; flex-direction: column; gap: 6px; }
.ap-opt-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.ap-opt-label { font-size: .875rem; font-weight: 600; }
.ap-opt-hint { font-size: .75rem; color: var(--mud-palette-text-secondary); }

/* Choices as a segmented control (a radio group): one is on. */
.ap-seg {
    display: inline-flex;
    align-self: flex-start;
    max-width: 100%;
    flex-wrap: wrap;
    border: 1px solid var(--mud-palette-lines-inputs, var(--mud-palette-lines-default));
    border-radius: var(--radius-md, 8px);
    overflow: hidden;
    background: var(--mud-palette-surface);
}

.ap-seg-item {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--mud-palette-text-primary);
    font: inherit;
    font-size: .8125rem;
    padding: 6px 14px;
    cursor: pointer;
    border-right: 1px solid var(--mud-palette-lines-default);
}

.ap-seg-item:last-child { border-right: 0; }
.ap-seg-item:hover:not(.ap-on) { background: var(--mud-palette-action-default-hover); }
.ap-seg-item:focus-visible { outline: 2px solid var(--mud-palette-primary); outline-offset: -2px; }

.ap-seg-item.ap-on {
    background: var(--accent-fill);
    color: var(--accent-ink);
    font-weight: 600;
}

/* Accent colours: a swatch each, the chosen one ringed. */
.ap-swatches { display: flex; gap: 10px; flex-wrap: wrap; }

.ap-swatch {
    appearance: none;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 2px solid transparent;
    background: var(--sw);
    cursor: pointer;
    display: grid;
    place-items: center;
    color: #fff;
    padding: 0;
    box-shadow: inset 0 0 0 2px var(--mud-palette-surface);
}

.ap-swatch.ap-on { border-color: var(--mud-palette-text-primary); }
.ap-swatch:focus-visible { outline: 2px solid var(--mud-palette-primary); outline-offset: 2px; }
.ap-swatch .mud-icon-root { font-size: 18px; }

.ap-switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ap-switch-text { display: flex; flex-direction: column; min-width: 0; }

@media (prefers-reduced-motion: reduce) {
    .ap-seg-item { transition: none; }
}
