/* ============================================================
   CoreBIM — MudBlazor Component Overrides
   Target: MudBlazor 9.0.0
   ============================================================ */

/* --- Global font ---
   Font set ONCE here. MudBlazor CbTheme.Default also sets fontFamily
   via Typography.Default — both reinforce the same value.
   HTML form elements (input, textarea, select, button) do NOT inherit
   font-family by default — hence the explicit inherit rule below.
   DO NOT repeat font-family on individual components. */

html, body {
    font-family: 'Be Vietnam Pro', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

input, textarea, select, button {
    font-family: inherit;
}

/* --- AppBar --- */

.mud-appbar {
    height: var(--cb-appbar-h, clamp(48px, 2vw + 38px, 56px));
}

.mud-appbar .mud-toolbar {
    height: 100%;
    min-height: unset;
}

/* Admin AppBar — uniform with body */
.cb-admin-appbar {
    border-bottom: 1px solid var(--cb-border);
}

/* --- MudPaper — Tabler-style: same bg as body, visible border --- */

.mud-paper.mud-elevation-0 {
    border: 1px solid var(--cb-border);
}

/* --- MudLayout: fix scroll container ---
   MudLayout uses flex but doesn't set overflow on .mud-main-content.
   Force the layout to fill viewport and main content to scroll internally,
   so the sidebar stays fixed and custom scrollbar can attach to the container. */

.mud-layout {
    height: 100vh !important;
    height: 100dvh !important;
    overflow: hidden !important;
}

.mud-main-content {
    height: 100% !important;
    overflow-y: auto !important;
    box-sizing: border-box !important;
}

/* --- Sidebar (Drawer) --- ViewerApp-style: full-height, logo in header --- */

.mud-drawer {
    border-right: 1px solid var(--cb-border) !important;
}

.cb-sidebar .mud-drawer-content {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Sidebar header — logo + brand + theme toggle */
.cb-sidebar-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--cb-border);
    min-height: 56px;
}

.cb-sidebar-brand {
    font-weight: 700;
    letter-spacing: -.02em;
}

/* Sidebar footer — user info, pushed to bottom via flex */
.cb-sidebar-footer {
    border-top: 1px solid var(--cb-border);
}

/* Sidebar logout button — align text left */
.cb-sidebar-footer .mud-button-root {
    justify-content: flex-start;
}

/* Desktop floating hamburger — shown when sidebar is closed */
.cb-sidebar-toggle {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1100;
}

.mud-drawer--mini .mud-nav-link .mud-nav-link-text {
    display: none;
}

/* --- NavLink --- */

.mud-nav-link {
    border-radius: var(--cb-radius-md);
    margin: 2px 8px;
    transition: background .15s, color .15s;
    align-items: center;
}

/* Nav link icons — restore to 20px (global override shrinks to 18px) */
.mud-nav-link .mud-svg-icon {
    width: 20px !important;
    height: 20px !important;
}

.mud-nav-link:hover {
    background: var(--cb-hover-bg);
}

.mud-nav-link.active {
    background: rgba(0, 114, 181, .1);
    color: var(--cb-blue);
    position: relative;
}

.mud-nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 4px;
    bottom: 4px;
    width: 4px;
    border-radius: 2px;
    background: var(--cb-blue);
}

/* --- Button --- 3 sizes: S=32px, M=38px (default), L=44px */

.mud-button-root {
    border-radius: var(--cb-radius-md);
    font-weight: 600;
    text-transform: none;
    letter-spacing: .3px;
    height: 38px;
}

.mud-button-text-size-small,
.mud-button-outlined-size-small,
.mud-button-filled-size-small {
    height: 32px;
    font-size: .8125rem;
}

.mud-button-text-size-large,
.mud-button-outlined-size-large,
.mud-button-filled-size-large {
    height: 44px;
    font-size: .9375rem;
}

/* --- TextField --- */

/* Global input background — darker than card surface.
   --cb-input-radius keeps background + fieldset border-radius in sync.
   display:flex + align-items:center for vertical text centering. */
.mud-input.mud-input-outlined {
    background: var(--cb-input);
    border-radius: var(--cb-input-radius, 6px);
    overflow: hidden;
    display: flex;
    align-items: center;
}

/* Global outlined border — consistent across ALL inputs */
.mud-input-outlined-border {
    border-radius: var(--cb-input-radius, 6px) !important;
    border-width: 1.5px !important;
    border-color: var(--cb-border);
    transition: border-color .15s;
}

/* Hover: primary border (all outlined inputs) */
.mud-input-control:not(.mud-input-control-focused):hover .mud-input-outlined-border {
    border-color: var(--mud-palette-primary) !important;
}

/* Focus: primary border, same width (no box-shadow, no layout shift) */
.mud-input-control-focused .mud-input-outlined-border {
    border-width: 1.5px !important;
}

/* Input — VISUAL ONLY overrides.
   DO NOT override padding, height, or transform — MudBlazor manages
   padding ↔ label positioning internally. Any padding override breaks labels.
   Use Margin="Margin.Dense" on components for smaller inputs. */
.mud-input-control .mud-input-slot {
    font-size: .875rem !important;
}

.mud-input-control-margin-dense {
    --cb-input-radius: 4px;
}

/* --- Auth text utilities — single source of truth for text styles --- */

.cb-text-muted { color: var(--cb-text-3); }
.cb-text-faint { color: var(--cb-text-4); }
.cb-text-link  { color: var(--cb-blue); font-weight: 700; }
.cb-text-link-red { color: var(--cb-red); font-weight: 700; }
.cb-text-accent { color: var(--cb-blue); font-weight: 600; }
.cb-text-title { font-weight: 800; margin-bottom: 8px; }

/* --- Large input tier — Auth card uses Placeholder ONLY (no Label).
   DO NOT use .cb-auth-card with Label param on inputs. */
.cb-input-lg,
.cb-auth-card {
    --cb-input-radius: 8px;
}

.cb-input-lg .mud-input.mud-input-outlined,
.cb-auth-card .mud-input.mud-input-outlined {
    border-radius: 8px;
}

.cb-input-lg .mud-input-outlined-border,
.cb-auth-card .mud-input-outlined-border {
    border-radius: 8px !important;
}

.cb-input-lg .mud-input-slot,
.cb-auth-card .mud-input-slot {
    font-size: .9375rem !important;
    font-weight: 400 !important;
}

/* Auth card: custom padding is safe here — auth pages use Placeholder ONLY (no Label).
   DO NOT use Label param on inputs inside .cb-auth-card — it WILL break. */

/* Switch — vertical alignment fix.
   .mud-switch-base is position:absolute inside .mud-switch-span (38px).
   Thumb (20px) + padding (9px*2) = 38px → should be centered.
   Force the span container to center its content properly. */
.mud-switch-span {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
}

.mud-switch-base {
    top: 50% !important;
    transform: translateY(-50%) !important;
}

.mud-switch-base.mud-checked {
    transform: translateY(-50%) translateX(20px) !important;
}

/* Select (dropdown) — vertical centering via flex on the outlined container */
.mud-select .mud-input.mud-input-outlined {
    display: flex;
    align-items: center;
}

/* Global icon default color — plain icons + icon buttons inside adornments */
.mud-icon-default,
.mud-input-adornment-icon-button .mud-svg-icon {
    color: var(--cb-text-3) !important;
}

/* Global icon sizes — override MudBlazor defaults (24/24/32 → 16/18/24) */
.mud-icon-size-small  { width: 16px !important; height: 16px !important; }
.mud-icon-size-medium { width: 18px !important; height: 18px !important; }
.mud-icon-size-large  { width: 24px !important; height: 24px !important; }

/* Global icon button — base = medium/default (MudBlazor has NO medium-specific CSS rule) */
.mud-icon-button {
    box-sizing: border-box !important;
    width: 32px !important;
    height: 32px !important;
    padding: 7px !important;
}

/* Icon button size overrides — only S and L differ from base */
.mud-icon-button.mud-icon-button-size-small { width: 28px !important; height: 28px !important; padding: 6px !important; }
.mud-icon-button.mud-icon-button-size-large { width: 40px !important; height: 40px !important; padding: 8px !important; }

/* Force icon SVG size inside icon buttons — override TablerIcons width="24" attribute */
.mud-icon-button .mud-svg-icon                            { width: 18px !important; height: 18px !important; }
.mud-icon-button.mud-icon-button-size-small .mud-svg-icon { width: 16px !important; height: 16px !important; }
.mud-icon-button.mud-icon-button-size-large .mud-svg-icon { width: 24px !important; height: 24px !important; }

/* Neutralize MudBlazor negative margin on edge buttons — align with start icon (14px) */
.mud-icon-button-edge-end   { margin-right: -4px !important; }
.mud-icon-button-edge-start { margin-left: -4px !important; }

.cb-auth-card .mud-input-helper-text {
    font-size: 11px;
    color: var(--cb-text-4);
    margin-top: 4px;
}

/* CbTextField — external label wrapper */
.cb-textfield {
    margin-bottom: 18px;
}

/* CbTextField dual icon — wrapper takes over border/bg, inner MudTextField is borderless */
.cb-textfield-dual {
    display: flex;
    align-items: center;
    background: var(--cb-input);
    border: 1.5px solid var(--cb-border);
    border-radius: var(--cb-input-radius, 6px);
    overflow: hidden;
    transition: border-color .15s;
}

.cb-textfield-dual:focus-within {
    border-color: var(--mud-palette-primary);
}

.cb-textfield-dual:not(:focus-within):hover {
    border-color: var(--mud-palette-primary);
}

.cb-textfield-dual .cb-textfield-start-icon {
    flex-shrink: 0;
    margin-left: 12px;
    color: var(--cb-text-3);
}

/* Hide inner MudTextField border — wrapper provides all border/bg */
.cb-textfield-dual .mud-input-outlined-border {
    border: none !important;
}

.cb-textfield-dual .mud-input.mud-input-outlined {
    background: transparent;
}

.cb-textfield-dual .mud-input-control {
    margin-top: 0;
    margin-bottom: 0;
    flex: 1;
}

/* Dual mode helper text — rendered outside wrapper to avoid border enclosure */
.cb-helper-text {
    font-size: 11px;
    color: var(--cb-text-4);
    margin-top: 4px;
}

/* Auth card: larger dual wrapper */
.cb-auth-card .cb-textfield-dual {
    border-radius: 8px;
}

/* Auth static label — above input (JSX pattern) */
.cb-auth-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--cb-text-2);
    display: block;
    margin-bottom: 8px;
}

.cb-auth-label .req {
    color: var(--cb-red);
}

/* Auth primary button — match input height (Large = 44px) */
.cb-auth-card .mud-button-root {
    height: 44px;
    border-radius: 10px;
    font-size: .8125rem;
    font-weight: 600;
}

/* Auth Google button */
.cb-auth-card .cb-google-btn {
    border: 1.5px solid var(--cb-border);
    border-radius: 10px;
    height: 42px;
    font-size: .8125rem;
    font-weight: 500;
    color: var(--cb-text-1);
    text-transform: none;
    letter-spacing: 0;
    transition: border-color .15s, background .15s;
}

.cb-auth-card .cb-google-btn:hover {
    border-color: var(--cb-border-hover);
    background: var(--cb-hover-bg);
}


/* Auth OTP notification banner */
.cb-otp-notification {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--cb-green-bg);
    border: 1px solid var(--cb-green-border);
    border-radius: 10px;
    padding: 10px 14px;
    margin-bottom: 24px;
    font-size: 13px;
    color: var(--cb-text-2);
}

.cb-otp-notification .mud-svg-icon {
    flex-shrink: 0;
}

/* Success icon color — used in OTP notifications + verify success */
.cb-icon-success { color: var(--cb-green) !important; }

/* Success icon wrapper — verify success page */
.cb-success-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--cb-green-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}

/* Reusable spacing — standard bottom margin for sections */
.cb-section-bottom { margin-bottom: 28px; }

/* Password label row — flex between (label + forgot link) */
.cb-auth-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.cb-auth-label-row .cb-auth-label {
    margin-bottom: 0;
}

/* Submit button top margin (first button after last input without label row) */
.cb-btn-submit { margin-top: 10px; }

/* Last textfield before button — extra bottom margin */
.cb-textfield-last { margin-bottom: 24px; }

/* Auth subtitle (below title) */
.cb-auth-subtitle {
    margin-top: 6px;
    margin-bottom: 28px;
}

/* Auth divider — override spacing (replaces Bootstrap my-3) */
.cb-auth-divider { margin: 18px 0; }

/* Auth footer */
.cb-auth-footer { margin-top: 24px; }

/* Back header */
.cb-back-header {
    position: relative;
    margin-bottom: 16px;
}

.cb-back-header-btn {
    position: absolute;
    left: 0;
}

/* Auth readonly input */
.cb-input-readonly {
    opacity: .7;
}

/* Auth OTP countdown */
.cb-otp-countdown {
    text-align: center;
    padding: 8px 0;
    font-size: .8125rem;
    color: var(--cb-text-3);
}

.cb-otp-resend {
    border: 1.5px solid var(--cb-blue);
    border-radius: 10px;
    height: 42px;
    font-size: .8125rem;
    color: var(--cb-blue);
    font-weight: 600;
}

/* --- Table / DataGrid — 3 tiers: S (Dense), M (default), L (.cb-table-lg) ---
   S ≈ 36px row | M ≈ 44px row | L ≈ 52px row
   Small = Dense="true" on MudTable/MudDataGrid
   Large = Class="cb-table-lg" on MudTable/MudDataGrid
   Design ref: clean horizontal borders, no vertical borders, muted header,
   subtle zebra, action links in primary color. */

/* --- Global table base --- */

/* Remove default MudBlazor table shadow + border */
.mud-table {
    box-shadow: none !important;
    border: none !important;
    background: transparent !important;
}

/* Container — subtle border + rounded corners */
.mud-table .mud-table-container {
    border: 1px solid var(--cb-border);
    border-radius: var(--cb-radius-md);
    overflow: hidden;
}

/* Remove all vertical cell borders — horizontal only via row border-bottom */
.mud-table .mud-table-cell {
    border-bottom: 1px solid var(--cb-border) !important;
}

/* Last row — no bottom border (container border handles it) */
.mud-table .mud-table-body .mud-table-row:last-child .mud-table-cell {
    border-bottom: none !important;
}

/* Header — uppercase mono, muted text, clean bottom border */
.mud-table .mud-table-head .mud-table-cell {
    font-family: var(--cb-font-mono);
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--cb-text-3);
    background: transparent !important;
    border-bottom: 1px solid var(--cb-border) !important;
    padding: 10px 14px;
}

/* --- Medium (default) — row + cell --- */
.mud-table .mud-table-row {
    height: 44px;
}

.mud-table .mud-table-cell {
    padding: 8px 14px;
    font-size: .8125rem;
    vertical-align: middle;
}

/* Row hover — subtle highlight */
.mud-table .mud-table-row:hover {
    background: var(--cb-hover-bg) !important;
}

/* Striped — very subtle zebra */
.mud-table-striped .mud-table-row:nth-child(even) {
    background: var(--cb-zebra);
}

/* Action link inside table — primary color */
.mud-table .mud-table-cell a,
.mud-table .mud-table-cell .mud-button-text {
    color: var(--mud-palette-primary);
    font-weight: 600;
    font-size: .8125rem;
}

/* --- Small (Dense) — header --- */
.mud-table-dense .mud-table-head .mud-table-cell {
    font-size: .65rem;
    padding: 6px 10px;
}

/* Small — row + cell */
.mud-table-dense .mud-table-row {
    height: 36px;
}

.mud-table-dense .mud-table-cell {
    padding: 4px 10px;
    font-size: .75rem;
}

/* --- Large (.cb-table-lg) — header --- */
.cb-table-lg .mud-table-head .mud-table-cell {
    font-size: .75rem;
    padding: 12px 18px;
}

/* Large — row + cell */
.cb-table-lg .mud-table-row {
    height: 52px;
}

.cb-table-lg .mud-table-cell {
    padding: 12px 18px;
    font-size: .875rem;
}

/* --- Rich rows (avatar + multi-line) — auto height --- */
.cb-table-rich .mud-table-row {
    height: auto;
    min-height: 64px;
}

.cb-table-rich .mud-table-cell {
    padding: 12px 14px;
}

/* DataGrid footer/pager — clean border */
.mud-table .mud-table-pagination {
    border-top: 1px solid var(--cb-border);
}

/* DataGrid column header sort icon — smaller */
.mud-table .mud-table-head .mud-table-sort-label .mud-svg-icon {
    width: 14px !important;
    height: 14px !important;
}

/* --- Dialog --- */

.mud-dialog {
    border: 1px solid var(--cb-border);
    box-shadow: 0 4px 24px rgba(0,0,0,.12);
    border-radius: var(--cb-radius-lg);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.mud-dialog .mud-dialog-content {
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
}

/* --- Mobile-only utility — hidden on desktop, shown ≤960px --- */
.cb-mobile-only { display: none !important; }

/* --- Responsive ≤960px (tablet) --- */

@media (max-width: 960px) {
    .cb-mobile-only { display: inline-flex !important; }
}

/* --- Responsive ≤640px (phone) — tighter container + full screen card --- */

@media (max-width: 640px) {
    .mud-container {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }

    .cb-auth-layout {
        padding: 0;
        align-items: stretch;
    }

    .cb-auth-card,
    .mud-paper.cb-auth-card {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 0 !important;
        border: none !important;
        padding: 32px 20px !important;
        box-shadow: none !important;
        background: transparent !important;
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
    }

    .mud-nav-link {
        min-height: 48px;
    }
}

/* --- Touch devices --- */

@media (hover: none) and (pointer: coarse) {
    .mud-button-root {
        min-height: 44px;
    }

    .mud-nav-link {
        min-height: 48px;
    }
}

/* --- Auto-hide AppBar on mobile --- */

.mud-appbar.cb-appbar-hidden {
    transform: translateY(-100%);
    transition: transform .3s ease;
}

.mud-appbar.cb-appbar-visible {
    transform: translateY(0);
    transition: transform .3s ease;
}

/* ============================================================
   Reconnect Overlay — Blazor Server connection lost
   Bouncing dots (blue + purple + red) + logo text
   Shared across all Blazor Server apps (AuthPortal, LandingPage, Server.Auth)
   ============================================================ */
.cb-reconnect {
    display:none;
    position:fixed;inset:0;z-index:99999;
    align-items:center;justify-content:center;
}
.cb-reconnect.components-reconnect-show,
.cb-reconnect.components-reconnect-failed,
.cb-reconnect.components-reconnect-rejected { display:flex; }

.cb-reconnect__backdrop {
    position:absolute;inset:0;
    background:var(--mud-palette-background, var(--cb-land-bg, #F5F7FA));
    opacity:.45;
    -webkit-backdrop-filter:blur(16px);
    backdrop-filter:blur(16px);
}
.cb-reconnect__content {
    position:relative;
    display:flex;flex-direction:column;align-items:center;gap:24px;
    padding:40px;
}

/* Bouncing dots */
.cb-reconnect__dots {
    display:flex;gap:8px;align-items:center;height:64px;
}
.cb-reconnect__dot {
    width:11px;height:11px;border-radius:50%;
    animation:cb-bounce 1.4s ease-in-out infinite;
}
.cb-reconnect__dot--lg { width:16px;height:16px; }
.cb-reconnect__dot--blue { background:linear-gradient(135deg,#0080C0,#00A3F5); }
.cb-reconnect__dot--purple { background:linear-gradient(135deg,#8B5CF6,#A78BFA); }
.cb-reconnect__dot--red { background:linear-gradient(135deg,#BE1E2D,#E14B59); }

@keyframes cb-bounce {
    0%,80%,100% { transform:translateY(0); }
    40% { transform:translateY(-18px); }
}

/* Logo text */
.cb-reconnect__logo {
    height:20px;width:auto;
}

/* Text: hidden initially, fade in after 5s */
.cb-reconnect__text {
    display:flex;align-items:center;gap:10px;
    opacity:0;
    animation:cb-reconnect-fade-in .4s ease forwards;
    animation-delay:5s;
    color:var(--mud-palette-text-secondary, var(--cb-land-t3, #718096));
    font-family:'Be Vietnam Pro',sans-serif;
    font-size:13px;font-weight:500;
}
@keyframes cb-reconnect-fade-in { to { opacity:1; } }

/* Failed / Rejected state */
.cb-reconnect__failed {
    display:none;
    flex-direction:column;align-items:center;gap:12px;
    color:var(--mud-palette-text-secondary, var(--cb-land-t2, #4A5568));
    font-family:'Be Vietnam Pro',sans-serif;
    font-size:14px;font-weight:500;
}
.cb-reconnect.components-reconnect-failed .cb-reconnect__text,
.cb-reconnect.components-reconnect-rejected .cb-reconnect__text { display:none; }
.cb-reconnect.components-reconnect-failed .cb-reconnect__failed,
.cb-reconnect.components-reconnect-rejected .cb-reconnect__failed { display:flex; }
.cb-reconnect.components-reconnect-failed .cb-reconnect__dots,
.cb-reconnect.components-reconnect-rejected .cb-reconnect__dots { display:none; }

.cb-reconnect__btn {
    padding:8px 24px;
    border:1px solid var(--mud-palette-lines-default, var(--cb-land-bd, #E2E8F0));
    border-radius:8px;
    background:var(--mud-palette-surface, var(--cb-land-sf, #fff));
    color:var(--mud-palette-text-primary, var(--cb-land-t1, #1A202C));
    font-family:'Be Vietnam Pro',sans-serif;
    font-size:13px;font-weight:600;
    cursor:pointer;
    transition:all .2s ease;
}
.cb-reconnect__btn:hover {
    background:var(--blue, #0080C0);
    color:#fff;border-color:var(--blue, #0080C0);
}
