/* --- FONTS ---
   Self-hosted Roboto (Latin) + Cairo (Arabic). Fluent UI loads its own design-token
   CSS via its JS initializer; there are intentionally no Bootstrap overrides here. */
@font-face {
  font-family: "Roboto";
  src: url("/fonts/Roboto-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Cairo";
  src: url("/fonts/Cairo-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* Force a light color scheme — the app's surfaces are light. */
html {
  color-scheme: light;
}

[dir="rtl"] {
  font-family: "Cairo", sans-serif;
}

/* --- Surfaces ------------------------------------------------------------
   Every page card is a FluentCard. Its own defaults are --colorNeutralStroke1 and
   --borderRadiusMedium, but the shared DataGrid got here first and set the house
   surface from the Fluent v9 tokens (see DataGrid.razor.css) — so cards follow the
   grid rather than the other way round, and a card sitting above a grid matches it.

   No shadow: in this app elevation means "this layer floats above the page" — the
   grid's column popup and the reports menu both use --shadow16 for that — so a card
   at rest is flat and bordered. Cards pass Shadow="CardShadow.None" to override
   FluentCard's resting --shadow4.

   Before this, ~20 components hardcoded background/border/radius/padding inline,
   with four different greys and two radii, so a theme change moved some and not
   others. Nothing should set those four properties on a card again. */
fluent-card {
  border-color: var(--colorNeutralStroke2);
  border-radius: var(--borderRadiusLarge);
}

/* --- Navbar --------------------------------------------------------------
   Dark "terminal" theme. All colors flow from these tokens so the header,
   its dropdowns (nav submenus, culture + user menu) and active indicators
   stay in sync. Tokens live on the header so every descendant panel inherits
   them regardless of where it is portalled in the DOM. */
.erp-nav {
  /* Brand palette — deep navy surface, cyan accent. */
  --nav-bg: #121b2e;
  --nav-fg: #ffffff;
  --nav-fg-strong: #ffffff;
  --nav-fg-muted: rgba(255, 255, 255, 0.6);
  --nav-accent: #53abe0;
  --nav-panel-bg: #1a2740;
  --nav-panel-hover: #22335a;
  --nav-panel-active: rgba(83, 171, 224, 0.18);
  --nav-border: rgba(255, 255, 255, 0.08);

  display: flex;
  align-items: center;
  gap: 2px;
  height: 48px;
  /* Fixed-height bar inside the layout's flex column: never let a tall page's
     scrollable body squeeze the navbar below 48px (default flex-shrink is 1). */
  flex-shrink: 0;
  padding: 0 16px;
  background: var(--nav-bg);
  color: var(--nav-fg);
  border-bottom: 1px solid var(--nav-border);
  font-size: 0.9rem;
}
.erp-nav-brand,
.erp-nav-brand:hover,
.erp-nav-brand:focus,
.erp-nav-brand:active,
.erp-nav-brand:visited {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-inline-end: 12px;
  text-decoration: none;
  color: var(--nav-fg);
  font-weight: 700;
}
.erp-nav-brand img {
  height: 28px;
}
.erp-nav-brand .accent {
  color: var(--nav-accent);
}

/* A top-level nav entry (button or dropdown trigger) with an active underline. */
.erp-nav-item {
  position: relative;
  display: flex;
  align-items: center;
  height: 100%;
}
.erp-nav-item.is-active::after {
  content: "";
  position: absolute;
  inset-inline: 8px;
  bottom: 6px;
  height: 2px;
  border-radius: 2px;
  background: var(--nav-accent);
}
.erp-nav-disabled {
  opacity: 0.5;
  padding: 0 8px;
  font-size: 0.9rem;
}

/* --- Dropdown (nav submenus, culture + user menu) --- */
.erp-dd-wrap {
  position: relative;
  display: flex;
  align-items: center;
  height: 100%;
}
.erp-dd-backdrop {
  position: fixed;
  inset: 0;
  z-index: 900;
}
.erp-dd-panel {
  position: absolute;
  top: 100%;
  inset-inline-end: 0;
  margin-top: 6px;
  background: var(--nav-panel-bg);
  color: var(--nav-fg);
  border: 1px solid var(--nav-border);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
  border-radius: 8px;
  min-width: 200px;
  z-index: 1000;
  overflow: hidden;
  padding: 6px;
}
.erp-dd-item {
  padding: 8px 12px;
  cursor: pointer;
  white-space: nowrap;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 6px;
  color: var(--nav-fg);
  transition: background-color 0.12s ease, color 0.12s ease;
}
.erp-dd-item:hover {
  background: var(--nav-panel-hover);
}
.erp-dd-item.is-active {
  background: var(--nav-panel-active);
  color: var(--nav-fg-strong);
  font-weight: 600;
}
.erp-dd-separator {
  height: 1px;
  margin: 6px 4px;
  background: var(--nav-border);
}

/* --- Blazor error UI (standard template rule; hidden until an error occurs) --- */
#blazor-error-ui {
  background: lightyellow;
  bottom: 0;
  box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
  display: none;
  left: 0;
  padding: 0.6rem 1.25rem 0.7rem 1.25rem;
  position: fixed;
  width: 100%;
  z-index: 1000;
}

#blazor-error-ui .dismiss {
  cursor: pointer;
  position: absolute;
  right: 0.75rem;
  top: 0.5rem;
}

/* --- FluentField vertical rhythm (project-wide) ------------------------------
   FluentUI stamps every <fluent-field> with a margin utility class (`my-3-o` at
   the time of writing) worth 12px above and below. Every form here already owns
   its spacing — forms wrap each field in a div with margin-bottom, filters and
   dialogs use flex gaps — so that margin is only ever double-spacing, and inside
   a flex row it cannot even collapse: the container gap, the field margins and
   the next block's margin all stack. Drop it once, globally, and let each
   layout's gaps be the single source of rhythm.

   `!important` is required and deliberate: the library's declaration comes from
   a *class*, which outranks any selector on the element name, and keying this
   rule to `.my-3-o` instead would break silently the day that class is renamed.
   A field that genuinely needs its own margin should get it from its wrapper. */
fluent-field {
  margin-block: var(--spacingVerticalNone) !important;
}

/* --- FluentField control metrics (project-wide) -------------------------------
   A text field is the themed reference: its shadow CSS pins .root to 32px (Fluent's
   medium control height) and drives its border through tokens — sides in
   --colorNeutralStroke1, bottom in --colorNeutralStrokeAccessible, moving to the
   *Hover / *Pressed tokens on interaction. Leave it completely alone: a document
   rule on ::part(root) would outrank those state rules and freeze the accent.

   A dropdown is the one that breaks the scale: it declares no height at all, so it
   grows to 34px from its own padding, and its field fills the trailing message row
   that a text field leaves collapsed. Two px is enough to knock a mixed row out of
   alignment. Correct just the dropdown, on both counts. */
fluent-dropdown {
  /* 32px is a literal on purpose: the theme has no control-height token (the closest
     same-valued ones, --lineHeightBase600 and --spacingVerticalXXXXL, mean unrelated
     things and would drift if those ramps change). This mirrors the `height: 32px`
     that the text input's own shadow CSS declares, which is the real reference. */
  height: 32px;
}

/* A text field rests its bottom border on --colorNeutralStrokeAccessible, two shades
   darker than the --colorNeutralStroke1 that dropdowns and buttons ring themselves
   with, so one field in a row reads as heavier than its neighbours. Retune the token
   for form fields instead of overriding the component: the field inherits it down to
   the control, so nothing competes with the component's own rules — and because the
   hover and pressed states resolve their own *Hover / *Pressed tokens, the border
   still darkens on interaction. Scoped to fluent-field so accessible strokes
   elsewhere (icons, chrome) keep their contrast. */
fluent-field {
  --colorNeutralStrokeAccessible: var(--colorNeutralStroke1);
}

/* Only a dropdown's field renders this element, and only when there is no message
   to show — a real validation message still displays. */
fluent-field > fluent-text:empty {
  display: none;
}

/* --- Form validation: error state on invalid fields ---
   FluentUI marks an invalid field's wrapper with `.invalid` (and sets aria-invalid), and renders its
   own `fluent-validation-message`, but v5-rc does not colour the input itself. Highlight it here, once,
   globally. `::part(root)` is the component's public styling hook — not a shadow-DOM hack. */
fluent-field.invalid fluent-text-input::part(root),
fluent-field.invalid fluent-text-area::part(root),
fluent-field.invalid fluent-number-field::part(root),
fluent-field.invalid fluent-select::part(control),
fluent-field.invalid fluent-combobox::part(control) {
  border-color: var(--colorPaletteRedBorderActive);
  border-bottom-color: var(--colorPaletteRedBorderActive);
}


/* --- Dialog: prevent the page from shifting down when a dialog opens ---
   FluentDialogProvider is declared before the app content, and in v5-rc the <fluent-dialog> host
   renders `display:inline; position:static`, so its line-box sits in normal flow and pushes the whole
   app (incl. the nav) down by ~20px. Take the host out of flow; its modal + overlay are positioned
   independently (top layer), so appearance is unchanged. */
.fluent-dialog-provider > fluent-dialog {
  position: fixed;
}

/* Validation summary (FluentValidationSummary → ul.fluent-validation-errors) styled as a Fluent
   danger message-bar/alert. All colours are FluentUI design tokens; the text uses the same token as
   the inline field-error message (--colorPaletteRedForeground1). */
.fluent-validation-errors {
  margin: 0 0 12px;
  padding: 8px 12px;
  list-style: none;
  background: var(--colorStatusDangerBackground1);
  border: 1px solid var(--colorStatusDangerBorder1);
  border-radius: 4px;
  color: var(--colorPaletteRedForeground1);
}
.fluent-validation-errors .fluent-validation-message,
.fluent-validation-errors li {
  color: var(--colorPaletteRedForeground1);
}

/* --- FluentNav sidebar (Sidebar.razor) ---
   FluentNav auto-sizes its width to the longest label, which makes the rail jump between pages.
   Pin a fixed width, fill the available height, and scroll internally when the links overflow. */
.erp-sidebar {
  flex-shrink: 0;
  /* FluentNav sets its own (unstable) inline width, so pin ours with priority to stop the jump. */
  width: 260px !important;
  min-width: 260px !important;
  max-width: 260px !important;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  /* Offset the first/last item from the edges by the same 2px the flex row-gap puts between items, so
     the top/bottom spacing matches the inter-item rhythm. !important: FluentNav forces padding:0. */
  padding-block: 2px !important;
  /* Stand the rail off the (grey) body as a raised surface that MATCHES the DataGrid card: the same
     surface token (--colorNeutralBackground1) as .erp-grid, a crisp inline-end divider, and a light
     Fluent 2 elevation shadow (https://fluent2.microsoft.design/elevation) — --shadow2, the lightest
     level (no horizontal offset, so RTL-safe as-is). position+z-index lift the elevation above the
     scrolling content (a later flex sibling that would otherwise paint over it). !important because
     FluentNav's own host styles otherwise win — it forces the border-colour transparent (why the rail
     had no separation before). */
  background: var(--colorNeutralBackground1) !important;
  border-inline-end: 1px solid rgba(0, 0, 0, 0.12) !important;
  box-shadow: var(--shadow2);
  position: relative;
  z-index: 1;
}

/* FluentNav items render as solid grey tiles at rest in this theme, which read as boxes on the white
   rail. Make them transparent at rest so only the icon + label show, with subtle Fluent subtle-background
   hover / selected states (the active accent bar is a separate indicator and is left untouched).
   !important beats the theme's resting background on the anchor host. */
.erp-sidebar a.fluent-navitem {
  background-color: transparent !important;
}
.erp-sidebar a.fluent-navitem:hover {
  background-color: var(--colorSubtleBackgroundHover, #f5f5f5) !important;
}
.erp-sidebar a.fluent-navitem.active {
  background-color: var(--colorSubtleBackgroundSelected, #ebebeb) !important;
}

/* Collapsible category headers (nested nav, e.g. the Budget module) render as a separate
   `button.fluent-navcategoryitem` with the same resting grey fill — which reads as "selected" on the
   white rail. Give them the same transparent-at-rest + subtle-hover treatment as the leaf items. */
.erp-sidebar button.fluent-navcategoryitem {
  background-color: transparent !important;
}
.erp-sidebar button.fluent-navcategoryitem:hover {
  background-color: var(--colorSubtleBackgroundHover, #f5f5f5) !important;
}

/* --- Toolbar rows mixing FluentUI fields with buttons -----------------------------------------
   A `fluent-field` is a grid that reserves a label row and a message row around its control, so a
   bare field is 36px (text input) or 34px (dropdown) tall while a `fluent-button` is 32px. Centring
   them still leaves their top/bottom edges staggered by 2-4px, which reads as misalignment.

   Applied to a row whose labels are rendered separately (see the label/control grids in the report
   pages), this collapses every control to a uniform 32px box so all edges line up exactly. */
.fluent-row fluent-field {
  row-gap: 0;
}

.fluent-row fluent-field > [slot="message"] {
  margin: 0;
}

.fluent-row fluent-text-input,
.fluent-row fluent-dropdown {
  height: 32px;
}

/* A FluentSelect's Style parameter lands on its fluent-field wrapper, so the inner fluent-dropdown
   keeps the library default width:160px and overhangs any narrower track — visibly colliding with
   whatever follows it. Nothing settable from the component's own markup reaches this. */
.fluent-row fluent-dropdown,
.fluent-row fluent-text-input {
  width: 100%;
  min-width: 0;
}

/* Unsupported-browser gate, revealed by BrowserCompatibility. Plain old CSS on purpose -- no custom
   properties, no grid, no flex gap, no :has(). Every browser that reaches this could not load any
   of that. */
#erp-browser-compat {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2147483647;
  background: #ffffff;
  color: #1a1a1a;
  font-family: "Segoe UI", Tahoma, Arial, Helvetica, sans-serif;
  overflow: auto;
}

/* table-cell rather than flex or grid for the centring: it is bulletproof on every browser that
   can reach this page, and unlike a translate it still scrolls when the content is taller than a
   short landscape viewport. */
.erp-compat-wrap {
  display: table;
  width: 100%;
  height: 100%;
}

.erp-compat-cell {
  display: table-cell;
  vertical-align: middle;
  text-align: center;
  padding: 24px;
}

.erp-compat-inner {
  max-width: 470px;
  margin: 0 auto;
}

.erp-compat-inner h1 {
  margin: 0 0 10px 0;
  font-size: 20px;
  font-weight: 600;
}

.erp-compat-inner p {
  margin: 0 0 36px 0;
  color: #616161;
  font-size: 14px;
  line-height: 1.5;
}

.erp-compat-browsers {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0; /* kills the whitespace between inline-blocks */
}

.erp-compat-browsers li {
  display: inline-block;
  vertical-align: top;
  width: 25%;
}

.erp-compat-browsers a {
  display: block;
  padding: 10px 4px;
  text-decoration: none;
  color: inherit;
  border-radius: 6px;
}

.erp-compat-browsers a:hover {
  background: #f5f5f5;
}

.erp-compat-name {
  display: block;
  margin-top: 10px;
  font-size: 13px;
}

.erp-compat-ver {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: #9e9e9e;
}

@media (max-width: 420px) {
  .erp-compat-browsers li {
    width: 50%;
    margin-bottom: 8px;
  }
}
