/* =====================================================================
   Colour tokens — the single place for colours that CSS needs directly.
   Brand tokens (--tp-brand-charcoal, --tp-brand-teal, --tp-dark-background,
   --tp-white) are emitted by Components/App.razor from Theme/AppTheme.cs —
   change them there. <html data-theme> is set by js/theme.js.
   Prefer var(--mud-palette-*) for anything the MudBlazor palette covers
   (text-secondary, lines-default, primary, ...), and these for the rest.
   ===================================================================== */
:root {
    /* Nav chrome (app bar + drawer) — light in light mode, charcoal in dark mode */
    --tp-nav-bg: var(--tp-white);
    --tp-nav-text: var(--tp-brand-charcoal);
    --tp-nav-text-muted: rgba(0, 0, 0, 0.60);
    --tp-nav-icon: rgba(0, 0, 0, 0.54);
    --tp-nav-scrollbar: rgba(0, 0, 0, 0.20);
    --tp-nav-divider: rgba(0, 0, 0, 0.10);
    --tp-nav-card-bg: rgba(0, 0, 0, 0.03);
    --tp-nav-card-border: rgba(0, 0, 0, 0.08);

    /* Report semantics (light) */
    --tp-amount-positive: #388e3c;
    --tp-amount-negative: #c62828;
    --tp-accent: #1a237e;
    --tp-accent-bg: #e8eaf6;
    --tp-total-row-bg: #f5f5f5;
    --tp-highlight-row-bg: #f9fbe7;
}

html[data-theme="dark"] {
    color-scheme: dark;

    --tp-nav-bg: var(--tp-brand-charcoal);
    --tp-nav-text: #fff;
    --tp-nav-text-muted: rgba(255, 255, 255, 0.65);
    --tp-nav-icon: rgba(255, 255, 255, 0.70);
    --tp-nav-scrollbar: rgba(255, 255, 255, 0.22);
    --tp-nav-divider: rgba(255, 255, 255, 0.08);
    --tp-nav-card-bg: rgba(255, 255, 255, 0.06);
    --tp-nav-card-border: rgba(255, 255, 255, 0.10);

    --tp-amount-positive: #81c784;
    --tp-amount-negative: #ef9a9a;
    --tp-accent: #9fa8da;
    --tp-accent-bg: rgba(159, 168, 218, 0.14);
    --tp-total-row-bg: rgba(255, 255, 255, 0.06);
    --tp-highlight-row-bg: rgba(220, 231, 117, 0.10);
}

/* Paint the dark background before Blazor connects (MudBlazor's own vars arrive later) */
html[data-theme="dark"],
html[data-theme="dark"] body {
    background-color: var(--tp-dark-background);
}

/* Separate the app bar / nav from same-coloured page surfaces (white on white, charcoal on charcoal) */
.mud-appbar {
    border-bottom: 1px solid var(--tp-nav-divider);
}

/* App bar EN/ع switcher: fixed box so the filled (selected) button and the Arabic glyph's taller line
   box don't make one button bigger than the other */
.tp-lang-btn.mud-button-root {
    height: 28px;
    min-width: 40px;
    padding: 0 10px;
    line-height: 1;
}

/* Teal outline around the whole group; the selected (filled) button fills it edge to edge.
   Brand token, not a palette slot: teal is Secondary in AppTheme.Main but Primary in AppTheme.Auth */
.tp-lang-switch.mud-button-group-root {
    border: 1px solid var(--tp-brand-teal);
    border-radius: var(--mud-default-borderradius);
    overflow: hidden;
}

.tp-lang-switch .tp-lang-btn.mud-button-root {
    border: none;
    border-radius: 0;
}

/* Swap artwork per mode: <img class="tp-light-only"> / <img class="tp-dark-only"> */
html[data-theme="dark"] .tp-light-only,
html:not([data-theme="dark"]) .tp-dark-only {
    display: none !important;
}

.loading-progress {
    position: absolute;
    width: 80px;
    height: 80px;
    left: 50%;
    top: 50%;
    margin-left: -40px;
    margin-top: -40px;
}
    .loading-progress circle {
        fill: none;
        stroke: var(--tp-brand-teal);
        stroke-width: 4;
        stroke-dasharray: 250.6, 251.2;
        stroke-dashoffset: 0;
        animation: progress-animation 2s linear infinite;
    }
@keyframes progress-animation {
    to {
        stroke-dashoffset: -251.2;
    }
}
.loading-progress-text {
    position: absolute;
    width: 100%;
    top: 50%;
    left: 0;
    text-align: center;
    font-size: 18px;
    color: var(--tp-brand-teal);
    margin-top: 60px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
#app {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--tp-dark-background);
}
.bg-dark {
    background-color: var(--tp-brand-charcoal) !important;
}
.bg-white {
    background-color: var(--tp-white) !important;
}
.empty-layout-main {
    background-color: var(--mud-palette-background);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 !important;
}

/* Icons that point somewhere (arrows, send, play, login/logout) do not mirror by themselves in right-to-left */
html[dir="rtl"] .rtl-flip {
    transform: scaleX(-1);
}

/* MudBlazor puts the utility class justify-end on an alert's icon+message row when right-to-left, but flex-end is already
   the physical LEFT in an RTL row, so the icon and text ended up at the far left of the alert instead of the start edge */
html[dir="rtl"] .mud-alert-position.justify-end {
    justify-content: flex-start !important;
}

/* A tab's count badge is placed with a physical left offset, so in right-to-left it grew back over the tab label instead of
   into the space after it; mirror it to the physical right offset */
html[dir="rtl"] .mud-tab-badge .mud-badge.mud-badge-top.right {
    inset: auto calc(100% - 4px) calc(100% - 4px) auto;
}

/* MudTabs 9.2 has no PanelClass (the analyzer flags it), so panel content sat flush against the card edge; pad the
   panel via a class on the MudTabs instead. */
.tp-tabs-padded > .mud-tabs-panels > .mud-tab-panel {
    padding: 16px;
}

/* Same, for card-less tabs that only want space under the tab bar (was PanelClass="pt-3"). */
.tp-tabs-top-padded > .mud-tabs-panels > .mud-tab-panel {
    padding-top: 12px;
}

/* Phone widths (below MudBlazor's Sm breakpoint): dialogs keep to the screen. Some dialogs set a min-width of 520-680px on
   the MudDialog and the rest leave 32px margins each side, so on a phone they ran off the screen. Here every dialog is at
   most the screen less an 8px gutter, with tighter padding; wide content (line tables) scrolls inside the dialog content.
   All but the small (ExtraSmall) confirm dialogs take that full width, as the min-width ones would otherwise shrink-wrap. */
@media (max-width: 599.98px) {
    .mud-dialog-container .mud-dialog:not(.mud-dialog-fullscreen) {
        min-width: 0 !important;
        max-width: calc(100% - 16px) !important;
    }

    .mud-dialog-container .mud-dialog:not(.mud-dialog-fullscreen):not(.mud-dialog-width-xs) {
        width: calc(100% - 16px);
    }

    .mud-dialog .mud-dialog-title {
        padding: 12px 16px;
    }

    .mud-dialog .mud-dialog-content {
        padding: 8px 12px;
    }

    .mud-dialog .mud-dialog-actions {
        flex-wrap: wrap;
    }

    /* Title bars with a button (e.g. "+ New Contact") squeezed both into mid-word breaks; stack the button below the title */
    .mud-dialog .mud-dialog-title > .d-flex.flex-row.justify-space-between {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 8px;
    }

    .mud-dialog .mud-dialog-title .mud-button-root {
        white-space: nowrap;
    }

    /* Simple tables' 16-24px cell padding pushed the last column (e.g. role permission Delete) out of view */
    .mud-dialog .mud-simple-table table * tr > td,
    .mud-dialog .mud-simple-table table * tr > th {
        padding: 6px 8px;
    }
}

/* Line-item tables in the create/edit dialogs (invoice, return, PO, goods receipt, transfer) use table-layout: fixed with
   percentage columns, so in a narrow dialog the columns crushed until headers overlapped and fields were unusable. Below
   this width the table scrolls sideways inside its overflow-x: auto wrapper instead; desktop dialogs are wider anyway. */
.tp-line-table {
    min-width: 760px;
}

/* Phone widths: page headers (h4 title, or h4 + chip as on Users, with a "+ New ..." button beside it) wrapped the title onto two lines
   and squeezed the button; stack the button below the title instead, as in the dialogs above. */
@media (max-width: 599.98px) {
    .mud-main-content .d-flex.flex-row.justify-space-between:has(> .mud-typography-h4, > .d-flex > .mud-typography-h4) {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px;
    }
}

/* Hidden on screen, still read by screen readers */
.tp-visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ===== /set-password (same composition as /login) ===== */
.tp-setpw {
    width: min(420px, 100%);
}

.tp-setpw-full {
    width: 100%;
}

.tp-setpw-status {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 2rem 0;
}

.tp-setpw-email {
    font-weight: 600;
    overflow-wrap: anywhere;
}

.tp-setpw-rules {
    list-style: none;
    margin: 0 0 1rem;
    padding: 0;
    display: grid;
    gap: 6px;
    color: var(--mud-palette-text-secondary);
    font-size: 0.875rem;
}

.tp-setpw-rules li {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tp-setpw-rules li.is-met {
    color: var(--mud-palette-success);
}

.tp-setpw-done {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-bottom: 1rem;
}

.tp-setpw-done .mud-icon-root {
    font-size: 3rem;
}
