/* ==========================================================================
   KZV Client Portal - application styles.

   Colours are never written as hex literals here. Everything resolves through the
   --mud-palette-* variables that MudBlazor generates from ClientZoneTheme, so switching
   the active palette (e.g. enabling dark mode) needs no changes in this file.

   Two brand colours have no MudBlazor slot of their own and are declared below as
   --cz-accent / --cz-accent-dark. Accent is the logo gold: it reaches only 2.7:1 against
   white, so it is used for surfaces, rules and underlines - never for text or icons.
   ========================================================================== */

:root {
    --cz-accent: #F7BB0E;
    --cz-accent-dark: #87650A;
    --cz-accent-wash: rgba(247, 187, 14, 0.10);
    --cz-accent-wash-strong: rgba(247, 187, 14, 0.18);

    --cz-radius-card: 12px;
    --cz-header-height: 68px;
    --cz-content-max: 1400px;

    /* Height of the Admin View bar. Declared here because two rules depend on it staying in step:
       the bar's own height, and the offset that keeps the sticky app bar below it. */
    --cz-admin-view-height: 36px;

    /* Gap between stacked cards. Matches MudGrid Spacing="3" (12px), which is what the pages built
       on MudGrid already use - so a .cz-stack page and a MudGrid page space identically. */
    --cz-gap: 12px;
}

/* Vertical page stack for pages that are a plain column of blocks. MudGrid would work too, but its
   negative margins collapse against sibling margins and produce a different first gap. */
.cz-stack {
    display: flex;
    flex-direction: column;
    gap: var(--cz-gap);
}

html, body {
    font-family: Inter, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--mud-palette-background);
}

/* Digits line up in a column wherever numbers are compared vertically - money totals,
   serial numbers, invoice numbers, counts. */
.mud-table,
.cz-tabular {
    font-variant-numeric: tabular-nums;
    font-feature-settings: 'tnum' 1;
}

/* ==========================================================================
   Application shell - top navigation, no drawer
   ========================================================================== */

/* Full-height column so the footer settles at the bottom of short pages instead of
   floating mid-screen. */
.mud-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* MudBlazor offsets main content by the app bar height unconditionally, which only makes sense
   for a fixed app bar. Ours sits in the flow (sticky), so that offset is dead space. */
.mud-layout > .mud-main-content {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    padding-top: 0;
}

.cz-appbar {
    position: sticky;
    top: 0;
    z-index: 1101;
    border-bottom: 1px solid var(--mud-palette-lines-default);
    box-shadow: none;
}

/* ==========================================================================
   Admin View bar - ServiceWeb users only, never rendered for a customer.

   Gold as a *surface* with near-black text, which is the one way the logo gold is usable:
   at 2.7:1 on white it cannot legally carry text, but dark text on top of it is fine.
   ========================================================================== */

.cz-admin-view-bar {
    position: sticky;
    top: 0;
    z-index: 1102;
    height: var(--cz-admin-view-height);
    background-color: var(--cz-accent);
    color: var(--mud-palette-text-primary);
    font-size: 0.8125rem;
}

/* The bar precedes the app bar in the document, so the app bar has to stick *below* it -
   otherwise it slides underneath and loses its top edge on every scroll. */
.cz-admin-view-bar ~ .mud-layout .cz-appbar {
    top: var(--cz-admin-view-height);
}

.cz-admin-view-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 100%;
    width: 100%;
    max-width: var(--cz-content-max);
    margin: 0 auto;
    padding: 0 24px;
}

.cz-admin-view-label {
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.cz-admin-view-customer {
    font-weight: 600;
}

.cz-admin-view-sep {
    opacity: 0.55;
}

.cz-admin-view-spacer {
    flex: 1 1 auto;
}

.cz-admin-view-exit {
    border: 1px solid var(--mud-palette-text-primary);
    border-radius: 4px;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: 600;
    padding: 2px 12px;
    cursor: pointer;
}

.cz-admin-view-exit:hover {
    background-color: var(--cz-accent-wash-strong);
}

/* The header carries its own two-row layout (brand row, then nav row), so the toolbar
   must stop imposing MudBlazor's fixed single-row height. */
.cz-appbar .mud-toolbar {
    height: auto;
    min-height: var(--cz-header-height);
    padding: 0;
}

.cz-appbar-inner {
    width: 100%;
    max-width: var(--cz-content-max);
    margin: 0 auto;
    padding: 0 24px;
}

.cz-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: inherit;
}

.cz-brand-mark {
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    object-fit: contain;
}

.cz-brand-name {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: -0.015em;
    color: var(--mud-palette-primary);
    white-space: nowrap;
}

.cz-nav {
    display: flex;
    align-items: stretch;
    gap: 4px;
}

.cz-nav-link {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px 12px;
    border-radius: 8px 8px 0 0;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    color: var(--mud-palette-text-secondary);
    transition: color 0.15s ease, background-color 0.15s ease;
}

.cz-nav-link:hover {
    color: var(--mud-palette-text-primary);
    background-color: var(--mud-palette-gray-lighter);
}

.cz-nav-link.active {
    color: var(--mud-palette-primary);
    font-weight: 600;
}

/* The amber signature: a solid rule under the active destination. Rendered on a
   pseudo-element so it overlaps the app bar's bottom border rather than shifting it. */
.cz-nav-link.active::after {
    content: '';
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: -1px;
    height: 3px;
    border-radius: 3px 3px 0 0;
    background-color: var(--cz-accent);
}

.cz-nav-icon {
    font-size: 1.125rem;
}

/* Mobile: the nav row collapses into a sheet behind the hamburger. */
.cz-nav-mobile-toggle {
    display: none;
}

@media (max-width: 899px) {
    .cz-appbar-inner {
        padding: 0 12px;
    }

    .cz-nav-desktop {
        display: none;
    }

    .cz-nav-mobile-toggle {
        display: inline-flex;
    }

    .cz-brand-name {
        font-size: 0.95rem;
    }
}

.cz-user-email {
    font-size: 0.8125rem;
    color: var(--mud-palette-text-secondary);
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ==========================================================================
   Page content
   ========================================================================== */

.cz-page {
    flex: 1 1 auto;
    width: 100%;
    max-width: var(--cz-content-max);
    margin: 0 auto;
    padding: 26px 20px 40px;
    box-sizing: border-box;
}

@media (max-width: 899px) {
    .cz-page {
        padding: 18px 12px 28px;
    }
}

/* A page heading with the amber rule beneath it. Controls are not placed here - see PageHeading.razor. */
.cz-page-head {
    margin-bottom: 20px;
}

.cz-page-title {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--mud-palette-text-primary);
    margin: 0;
}

.cz-rule {
    width: 40px;
    height: 3px;
    border-radius: 2px;
    background-color: var(--cz-accent);
    margin-top: 8px;
}

.cz-page-subtitle {
    margin-top: 10px;
    font-size: 0.875rem;
    color: var(--mud-palette-text-secondary);
}

/* ==========================================================================
   Dashboard - greeting, stat tiles, call to action
   ========================================================================== */

/* No bottom margin: the enclosing .cz-stack owns the spacing. */
.cz-hero {
    margin-bottom: 0;
}

.cz-hero-greeting {
    font-size: 0.8125rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--mud-palette-text-secondary);
}

.cz-hero-name {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 2px;
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--mud-palette-text-primary);
}

.cz-hero-legal {
    font-size: 1rem;
    font-weight: 400;
    color: var(--mud-palette-text-secondary);
}

.cz-hero-description {
    margin-top: 6px;
    font-size: 0.875rem;
    color: var(--mud-palette-text-secondary);
}

.cz-stat-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--cz-gap);
}

@media (max-width: 1099px) {
    .cz-stat-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 599px) {
    .cz-stat-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

.cz-stat-tile {
    position: relative;
    padding: 18px 20px;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: var(--cz-radius-card);
    background-color: var(--mud-palette-surface);
}

.cz-stat-icon {
    position: absolute;
    top: 16px;
    right: 16px;
    color: var(--mud-palette-primary);
    opacity: 0.35;
}

.cz-stat-value {
    font-size: 1.75rem;
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    color: var(--mud-palette-text-primary);
}

.cz-stat-label {
    margin-top: 2px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--mud-palette-text-secondary);
}

.cz-stat-hint {
    margin-top: 2px;
    font-size: 0.75rem;
    color: var(--mud-palette-text-disabled);
}

/* The one place amber does more than accent a line: the dashboard's call to action. */
.cz-attention {
    padding: 18px 20px;
    border: 1px solid var(--mud-palette-lines-default);
    border-left: 4px solid var(--cz-accent);
    border-radius: var(--cz-radius-card);
    background-color: var(--cz-accent-wash);
}

.cz-attention-head {
    display: flex;
    align-items: center;
    gap: 8px;
}

.cz-attention-icon {
    color: var(--cz-accent-dark);
}

.cz-attention-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--mud-palette-text-primary);
}

.cz-attention-list {
    margin: 14px 0 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cz-attention-item {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 4px 12px;
    padding-top: 8px;
    border-top: 1px solid var(--cz-accent-wash-strong);
    font-size: 0.875rem;
}

.cz-attention-number {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--mud-palette-text-primary);
}

.cz-attention-name {
    color: var(--mud-palette-text-secondary);
}

.cz-attention-meta {
    font-size: 0.8125rem;
    color: var(--mud-palette-text-secondary);
    white-space: nowrap;
}

.cz-attention-expired {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--cz-accent-dark);
    white-space: nowrap;
}

.cz-attention-more {
    margin-top: 10px;
    font-size: 0.8125rem;
    color: var(--mud-palette-text-secondary);
}

/* ==========================================================================
   Surfaces - flat, hairline-bordered, roomy
   ========================================================================== */

/* Doubled class beats MudBlazor's .mud-elevation-* box-shadow without !important. */
.mud-paper.mud-card {
    box-shadow: none;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: var(--cz-radius-card);
    background-color: var(--mud-palette-surface);
}

.mud-card > .mud-card-header {
    padding: 20px 24px 4px;
}

/* MudBlazor right-aligns header actions only indirectly, by letting .mud-card-header-content grow.
   A card whose title lives in the page heading has no content element, so its actions would drift
   left - which is how the offers filter and the dashboard's device filter ended up on opposite
   sides. Pushing the actions over explicitly makes alignment independent of whether a title exists.
   Both properties are needed: MudBlazor sets margin-inline-start, which would otherwise win. */
.mud-card > .mud-card-header > .mud-card-header-actions {
    margin-left: auto;
    margin-inline-start: auto;
}

.mud-card > .mud-card-content {
    padding: 16px 24px 24px;
}

/* Things that genuinely float keep their shadow. */
.mud-dialog,
.mud-popover {
    border-radius: var(--cz-radius-card);
}

/* ==========================================================================
   Data tables - hairline rows, no header fill, small-caps labels
   ========================================================================== */

.mud-table .mud-table-head .mud-table-cell {
    background-color: transparent;
    border-bottom: 1px solid var(--mud-palette-lines-default);
    padding-top: 10px;
    padding-bottom: 10px;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--mud-palette-text-secondary);
}

.mud-table .mud-table-body .mud-table-cell {
    padding-top: 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--mud-palette-table-lines);
}

/* A cell holding a control gives up its vertical padding, so the row keeps the height a plain text row sets
   (a 20px line plus the padding above, 48px - the organization units table) instead of adding the padding to
   a button's touch target. Every control used in a row is 48px or less, so it fits without growing the row;
   content that is genuinely taller, like two lines of row actions, still is. Phones are left alone: below
   MudTable's default breakpoint each cell is its own labelled line, which needs its padding. */
@media (min-width: 600px) {
    .mud-table .mud-table-body .mud-table-cell:has(.mud-button-root, .mud-chip) {
        padding-top: 0;
        padding-bottom: 0;
        vertical-align: middle;
    }
}

/* Last row sits flush against the card padding instead of drawing a dangling rule. */
.mud-table .mud-table-body .mud-table-row:last-child .mud-table-cell {
    border-bottom: none;
}

/* Row actions laid out two-per-line rather than in one long strip. Four labelled buttons in a
   single row push the offers table past the card and force a horizontal scrollbar; the rows are
   already tall enough (item chips, multi-line totals) to absorb the second line for free. */
/* max-content columns, and deliberately no width on the items themselves. The table cell is
   shrink-wrapped (width:1% in the markup) so its width is indefinite; a percentage width on a
   grid item resolved against an indefinite column contributes nothing to intrinsic sizing, which
   collapses the columns and stacks the buttons on top of each other. Sizing the columns to their
   content instead needs no widths at all - grid items stretch to their column by default. */
.cz-row-actions {
    display: grid;
    grid-template-columns: repeat(2, max-content);
    gap: 2px 4px;
    justify-content: start;
}

.cz-row-actions .mud-button-root {
    justify-content: flex-start;
    white-space: nowrap;
}

/* ==========================================================================
   Standalone message pages (not found, error)
   ========================================================================== */

.cz-message-page {
    max-width: 480px;
    margin: 64px auto;
    text-align: center;
}

.cz-message-icon {
    color: var(--mud-palette-primary);
    opacity: 0.4;
}

.cz-message-title {
    margin: 12px 0 8px;
    font-size: 1.375rem;
    font-weight: 600;
    letter-spacing: -0.015em;
    color: var(--mud-palette-text-primary);
}

.cz-message-text {
    margin: 0 0 24px;
    font-size: 0.9375rem;
    color: var(--mud-palette-text-secondary);
}

.cz-message-reference {
    margin: -8px 0 24px;
    font-size: 0.8125rem;
    color: var(--mud-palette-text-disabled);
}

.cz-message-reference code {
    font-size: 0.75rem;
    word-break: break-all;
}

/* ==========================================================================
   Footer
   ========================================================================== */

.cz-footer {
    border-top: 1px solid var(--mud-palette-lines-default);
    background-color: var(--mud-palette-surface);
    margin-top: auto;
}

.cz-footer-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    width: 100%;
    max-width: var(--cz-content-max);
    margin: 0 auto;
    padding: 20px 24px;
    font-size: 0.8125rem;
    color: var(--mud-palette-text-secondary);
}

.cz-footer-mark {
    width: 26px;
    height: 26px;
    object-fit: contain;
    opacity: 0.85;
}

/* ==========================================================================
   Anonymous pages (login / activate / forgot / reset)

   These render as static SSR so the browser can POST to /api/account/*, which rules out
   MudBlazor inputs - hence the hand-rolled controls below.
   ========================================================================== */

.cz-auth {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 32px 16px;
    box-sizing: border-box;
    background:
        radial-gradient(1100px 520px at 50% -8%, var(--cz-accent-wash), transparent 70%),
        var(--mud-palette-background);
}

.cz-auth-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-bottom: 24px;
}

.cz-auth-mark {
    width: 64px;
    height: 64px;
    object-fit: contain;
}

.cz-auth-name {
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.015em;
    color: var(--mud-palette-primary);
}

.cz-auth-card {
    width: 100%;
    max-width: 400px;
    box-sizing: border-box;
    padding: 32px;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: var(--cz-radius-card);
    background-color: var(--mud-palette-surface);
}

.cz-auth-title {
    margin: 0 0 4px;
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--mud-palette-text-primary);
}

.cz-auth-title-only {
    margin-bottom: 20px;
}

.cz-auth-subtitle {
    margin: 0 0 24px;
    font-size: 0.875rem;
    color: var(--mud-palette-text-secondary);
}

.cz-auth-foot {
    margin-top: 20px;
    text-align: center;
}

.cz-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--mud-palette-text-primary);
}

.cz-input {
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--mud-palette-lines-inputs);
    border-radius: 8px;
    background-color: var(--mud-palette-surface);
    color: var(--mud-palette-text-primary);
    font-family: inherit;
    font-size: 0.9375rem;
    box-sizing: border-box;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.cz-input:focus {
    outline: none;
    border-color: var(--mud-palette-primary);
    box-shadow: 0 0 0 3px rgba(38, 60, 123, 0.14);
}

.cz-btn {
    width: 100%;
    padding: 0.7rem 0.75rem;
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.cz-btn:hover {
    background: var(--mud-palette-primary-darken);
}

.cz-btn:focus-visible {
    outline: 3px solid rgba(38, 60, 123, 0.35);
    outline-offset: 2px;
}

.cz-link {
    color: var(--mud-palette-primary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
}

.cz-link:hover {
    text-decoration: underline;
}

/* ==========================================================================
   Segmented filter (grid-header toggles) - SegmentedFilter.razor
   ========================================================================== */

.cz-segmented {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    background: var(--mud-palette-background-grey);
    border-radius: 9999px;
}

.cz-segmented-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: none;
    background: transparent;
    border-radius: 9999px;
    padding: 5px 13px;
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
    color: var(--mud-palette-text-secondary);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.cz-segmented-item:hover {
    color: var(--mud-palette-text-primary);
    background: var(--mud-palette-gray-lighter);
}

.cz-segmented-item-active,
.cz-segmented-item-active:hover {
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
}

.cz-segmented-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9999px;
    background: rgba(0, 0, 0, 0.08);
    font-size: 0.6875rem;
    font-weight: 700;
    line-height: 1;
}

.cz-segmented-item-active .cz-segmented-count {
    background: rgba(255, 255, 255, 0.25);
}

/* ==========================================================================
   Form validation (EditForm) and the Blazor error boundary
   ========================================================================== */

.invalid {
    outline: 1px solid var(--mud-palette-error);
}

.validation-message {
    color: var(--mud-palette-error);
    font-size: 0.8125rem;
}

.blazor-error-boundary {
    padding: 16px 20px;
    border-radius: var(--cz-radius-card);
    background: var(--mud-palette-error);
    color: #fff;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}
