/* ── Global Typography ───────────────────────────────────────── */
html, body {
    font-family: 'Poppins', 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--mud-palette-background, var(--v-bg-light));
    color: var(--mud-palette-text-primary, var(--v-dark));
}

h1, h2, .mud-typography-h1, .mud-typography-h2 {
    font-family: 'Poppins', sans-serif;
    font-weight: 300;
}

h3, h4, h5, h6,
.mud-typography-h3,
.mud-typography-h4,
.mud-typography-h5,
.mud-typography-h6 {
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
}

/* ── App Shell ───────────────────────────────────────────────── */
#app {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ── App Bar ─────────────────────────────────────────────────── */
.mud-appbar {
    background-color: var(--v-deep-blue) !important;
}

/* ── Side Nav — override Bootstrap's a { text-decoration: underline }.
   MudNavLink renders as <a class="mud-nav-link">, outside the scoped CSS
   component subtree, so this must live in the global stylesheet. ────── */
a.mud-nav-link,
a.mud-nav-link:hover,
a.mud-nav-link:focus {
    text-decoration: none;
}

/* ── User Menu — must be global: ActivatorContent and popover both render outside
   the component's scoped CSS subtree, so scoped selectors never match. ────────── */
.user-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px 8px 8px;
    border-radius: 25px;
    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
    height: 46px;
    color: #ffffff;
    margin-left: 8px;
    min-width: 200px;
}

.user-pill:hover {
    background: rgba(255, 255, 255, 0.18);
}

.user-initials {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #ffffff;
    color: var(--v-deep-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    flex-shrink: 0;
}

.user-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
}

@media (max-width: 600px) {
    .user-name { display: none; }
}

.user-menu-popover {
    min-width: 200px;
    color: var(--mud-palette-text-primary);
}

.user-menu-roles {
    display: block;
    padding: 8px 16px;
    font-size: 12px;
    color: var(--mud-palette-text-secondary);
}

/* ── AI Usage Date Pickers — must be global: MudDatePicker popovers are
   portalled outside the page's scoped CSS subtree. ───────────────────── */
.ai-usage-date-picker {
    width: 176px;
    flex: 0 0 176px;
}

.mud-picker-popover {
    width: min(310px, calc(100vw - 32px)) !important;
    max-width: calc(100vw - 32px);
}

.mud-picker-popover .mud-picker-paper,
.mud-picker-popover .mud-picker-container {
    width: 100%;
}

/* ── Users Status Dot — must be global: MudTooltip renders ChildContent as a
   render fragment, so scoped CSS from Users.razor.css is not stamped here. ── */
.users-status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex: 0 0 8px;
}

.users-status-dot--active {
    background: #00c853;
}

.users-status-dot--pre-provisioned {
    background: #2196f3;
}

/* ── Menu Button ──────────────────────────────────────────────── */
.mud-menu .mud-button {
    text-transform: capitalize;
}

/* ── App Loading ─────────────────────────────────────────────── */
.app-loading-page {
    position: fixed;
    inset: 0;
    z-index: 2000;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 32px;
    background: var(--v-deep-blue);
}

.app-loading-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.app-loading-title {
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
    font-size: 1.75rem;
    color: #ffffff;
    letter-spacing: 0.01em;
    line-height: 1.2;
    margin: 0;
}

.app-loading-subtitle {
    font-size: 0.75rem;
    color: var(--v-green);
    letter-spacing: 0.12em;
    line-height: 1.3;
    text-transform: uppercase;
    text-align: center;
    margin: 0;
}

.loading-progress {
    position: relative;
    display: block;
    width: 4rem;
    height: 4rem;
    margin: 0;
}

.loading-progress circle {
    fill: none;
    stroke: var(--v-green);
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--v-bg-pale);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    font-family: 'Poppins', sans-serif;
    text-align: center;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.72);
    min-height: 1.5rem;
}

.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Loading");
}


/* ── Error Overlay — must be global: ErrorBoundary renders ErrorContent as a
   render fragment outside the normal component subtree, so scoped CSS from
   ErrorOverlay.razor.css is never stamped on those elements. ──────────────── */
.error-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(1, 48, 62, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
}

.error-modal {
    background: #1D1D21;
    border-radius: 8px;
    padding: 32px;
    max-width: 480px;
    width: 90%;
    box-shadow: 0 24px 64px rgba(0,0,0,0.6);
    border-top: 3px solid #00DBA6;
}

.error-title {
    color: #ffffff;
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 16px;
}

.error-body {
    color: rgba(255,255,255,0.7);
    font-size: 0.875rem;
    line-height: 1.5;
    margin: 0 0 24px;
}

.error-actions {
    display: flex;
    justify-content: flex-end;
}

/* ── Login Page — must be global: RemoteAuthenticatorView renders slot content
   (LogOutSucceeded, LoggingIn, etc.) as render fragments, so scoped CSS from
   Login.razor.css is never stamped on those elements. ────────────────────── */
.login-page {
    height: 100vh;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-panel {
    display: grid;
    grid-template-columns: 55% 45%;
    width: 100%;
    max-width: 860px;
    height: 560px;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 32px 80px rgba(0, 0, 0, 0.5);
    background-color: var(--v-deep-blue);
}

.login-form-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 64px 48px;
    position: relative;
}

.login-form-col::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 3px;
    background: var(--v-green);
}

.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    margin-bottom: 48px;
}

.login-brand-title {
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
    font-size: 1.75rem;
    color: #ffffff;
    letter-spacing: 0.01em;
    margin: 0;
}

.login-brand-sub {
    font-size: 0.75rem;
    color: var(--v-green);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin: 0;
}

.login-form-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
    max-width: 320px;
}

.login-form-prompt {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.6);
    text-align: center;
    margin: 0;
}

.login-separator {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    color: rgba(255, 255, 255, 0.2);
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.login-separator::before,
.login-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: rgba(255, 255, 255, 0.12);
}

.login-hero-col {
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--v-emerald);
}

.login-hero-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: 40% top;
    display: block;
}

@media (max-width: 768px) {
    .login-panel { grid-template-columns: 1fr; max-width: 420px; height: auto; }
    .login-hero-col { display: none; }
    .login-form-col { padding: 48px 32px; }
}

/* ── Health Check JSON Block — global because it renders inside MudDialog,
   which is portalled outside the component's scoped CSS subtree. ──────── */
.json-block {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.75rem;
    background: var(--mud-palette-background-grey, #f5f5f5);
    border: 1px solid var(--mud-palette-divider, #e0e0e0);
    border-radius: 4px;
    padding: 8px 12px;
    margin: 0;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 300px;
    overflow-y: auto;
}

/* ── DataGrid Header ─────────────────────────────────────────── */
.mud-table-root .mud-table-head .mud-table-cell {
    font-weight: 600;
}

/* ── Utility ─────────────────────────────────────────────────── */
.cursor-pointer {
    cursor: pointer;
}

/* ── ApexCharts — adapt axis labels and legend text to the active theme ─────
   ApexCharts bakes text colors into inline SVG attributes; these overrides
   make the axis labels and legend readable in both light and dark mode without
   touching data-label fills (which are explicitly set per-chart). ─────────── */
.apexcharts-yaxis-label tspan,
.apexcharts-xaxis-label tspan {
    fill: var(--mud-palette-text-secondary) !important;
}

.apexcharts-legend-text {
    color: var(--mud-palette-text-secondary) !important;
}

/* ── ApexCharts Tooltip — dark mode compatibility ────────────────────────────
   ApexCharts tooltips are absolutely positioned overlays injected into the DOM
   outside any component subtree; scoped CSS never reaches them. The default
   white background is jarring in dark mode — use MudBlazor palette tokens so
   the tooltip follows the active theme automatically. ───────────────────────── */
.apexcharts-tooltip {
    background: var(--mud-palette-surface) !important;
    border-color: var(--mud-palette-divider) !important;
    color: var(--mud-palette-text-primary) !important;
    box-shadow: var(--mud-elevation-4) !important;
}

.apexcharts-tooltip-title {
    background: var(--mud-palette-background-grey) !important;
    border-bottom-color: var(--mud-palette-divider) !important;
    color: var(--mud-palette-text-primary) !important;
}

.apexcharts-tooltip-text {
    color: var(--mud-palette-text-primary) !important;
}

/* Zendesk deep-link count numbers — no underline, theme-aware blue */
a.zd-count-link,
a.zd-count-link:hover {
    text-decoration: none !important;
}

a.zd-count-link {
    color: var(--mud-palette-primary) !important;
}

a.zd-count-link:hover {
    color: var(--mud-palette-primary-darken) !important;
}

/* ── Runtime CSS Variable Stubs ─────────────────────────────────
   Design-time declarations so the IDE can resolve var() references.
   These are overridden at runtime and have no effect on the app.
   MudBlazor vars: injected by MudThemeProvider into a <style> tag.
   Blazor vars:    set by the Blazor WASM loading progress script.
   ────────────────────────────────────────────────────────────── */
:root {
    /* MudBlazor */
    --mud-appbar-height:            64px;

    /* Blazor WASM loading */
    --blazor-load-percentage:       0%;
    --blazor-load-percentage-text:  "Loading";
}

/* ── Scraper Backlog filter dropdowns — must be global: MudMenu renders its popover
   outside the component's scoped CSS subtree, so selectors in
   BacklogFilterMenu.razor.css would never match. ─────────────────────── */
.backlog-filter-popover {
    max-height: 380px;
    overflow-y: auto;
}

.backlog-filter-pop {
    width: 356px;
    max-width: calc(100vw - 28px);
    padding: 5px;
}

.backlog-filter-pop__head {
    padding: 8px 9px 7px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--mud-palette-lines-default);
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--v-med-grey);
}

.backlog-filter-pop__section {
    padding: 10px 9px 4px;
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--v-teal);
}

.backlog-filter-pop__empty {
    padding: 20px 9px;
    text-align: center;
    font-size: 13px;
    color: var(--v-gray);
}

.backlog-filter-pop__option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 9px;
    border-radius: 2px;
    cursor: pointer;
    font-size: 13px;
}

.backlog-filter-pop__option:hover {
    background: var(--v-bg-pale);
}

.backlog-filter-pop__option input {
    accent-color: var(--v-green-regular);
    flex: none;
    cursor: pointer;
}

.backlog-filter-pop__option input:disabled {
    cursor: default;
}

.backlog-filter-pop__option:focus-within {
    outline: 2px solid var(--v-teal);
    outline-offset: -2px;
}

/* A selected value the server no longer returns still renders, greyed, so the operator can always
   untick the thing constraining their results. */
.backlog-filter-pop__option--zero .backlog-filter-pop__name,
.backlog-filter-pop__option--zero .backlog-filter-pop__count {
    color: var(--v-med-grey);
}

.backlog-filter-pop__name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.backlog-filter-pop__bar {
    flex: none;
    width: 64px;
    height: 6px;
    border-radius: 1px;
    background: var(--v-light-grey);
    overflow: hidden;
}

.backlog-filter-pop__bar > span {
    display: block;
    height: 100%;
    background: var(--v-green-regular);
}

.backlog-filter-pop__count {
    flex: none;
    min-width: 46px;
    text-align: right;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    color: var(--v-gray);
}

/* ── Scraper Backlog age-bar tooltip — must be global: MudTooltip portals its content
   to the body, outside the component's scoped CSS subtree. The bucket colours are
   redeclared here for the same reason — the portalled node is not a descendant of
   .backlog-console, so it cannot inherit that element's custom properties. ─────── */
.backlog-age-tip {
    --backlog-age-0: #35BC98;
    --backlog-age-1: #C9A227;
    --backlog-age-2: #D05B57;
    --backlog-age-3: #B3313F;

    min-width: 208px;
    text-align: left;
    font-size: 12px;
    line-height: 1.5;
}

.backlog-age-tip__head {
    font-size: 10px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    opacity: 0.7;
    padding-bottom: 5px;
    margin-bottom: 5px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.backlog-age-tip__row {
    display: grid;
    grid-template-columns: 10px 1fr auto 40px;
    align-items: center;
    gap: 8px;
    padding: 1px 0;
}

/* An empty bucket is still listed: "none in the last hour" is information, and a row
   silently missing reads as a rendering fault. */
.backlog-age-tip__row--zero {
    opacity: 0.45;
}

.backlog-age-tip__swatch {
    width: 9px;
    height: 9px;
    border-radius: 1px;
    display: inline-block;
}

.backlog-age-tip__swatch[data-bucket="0"] { background: var(--backlog-age-0); }
.backlog-age-tip__swatch[data-bucket="1"] { background: var(--backlog-age-1); }
.backlog-age-tip__swatch[data-bucket="2"] { background: var(--backlog-age-2); }
.backlog-age-tip__swatch[data-bucket="3"] { background: var(--backlog-age-3); }

.backlog-age-tip__count,
.backlog-age-tip__share {
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.backlog-age-tip__share {
    opacity: 0.7;
}

.backlog-age-tip__total {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-top: 5px;
    padding-top: 5px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
