/* ============================================================
   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);
}

/* --- 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;
}

.mud-input-outlined-border {
    border-radius: var(--cb-input-radius, 6px) !important;
}

/* Global input sizing — 3 tiers via font-size + padding (Material approach).
   NO fixed height — size comes from content naturally.
   Step 8px: S ≈ 32px (Dense), M ≈ 40px (default), L ≈ 48px (auth-card).
   Explicit horizontal padding (14px) for consistent text alignment across tiers.
   !important needed to beat MudBlazor's internal .mud-input-slot rules. */
.mud-input-control .mud-input-slot {
    font-size: .875rem !important;
    font-weight: 400 !important;
    padding: 9px 14px !important;
}

/* When start adornment (icon) exists, reduce left padding on the input slot
   to avoid excessive icon-to-text gap (adornment already has margin-right: 8px).
   Values scale with tier: S=2px, M=4px, L=6px */
.mud-input-adornment-start + .mud-input-slot {
    padding-left: 4px !important;
}

.mud-input-control-margin-dense .mud-input-adornment-start + .mud-input-slot {
    padding-left: 2px !important;
}

.cb-input-lg .mud-input-adornment-start + .mud-input-slot,
.cb-auth-card .mud-input-adornment-start + .mud-input-slot {
    padding-left: 6px !important;
}

/* Dense inputs = Small (~32px) — use Margin="Margin.Dense" on MudTextField */
.mud-input-control-margin-dense .mud-input-slot {
    font-size: .8rem !important;
    padding: 5px 14px !important;
}

/* Dense — set radius variable, both bg + border inherit it */
.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 (~48px) — use .cb-input-lg on any container --- */

/* Large tier — radius + sizing via class (reusable outside auth card).
   Set variable AND explicit overrides to ensure cascade works
   regardless of DOM depth between container and input. */
.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;
    border-width: 1.5px !important;
}

.cb-input-lg .mud-input-control:not(.mud-input-control-focused) .mud-input-outlined-border,
.cb-auth-card .mud-input-control:not(.mud-input-control-focused) .mud-input-outlined-border {
    border-color: var(--cb-border);
}

.cb-input-lg .mud-input-control:not(.mud-input-control-focused):hover .mud-input-outlined-border,
.cb-auth-card .mud-input-control:not(.mud-input-control-focused):hover .mud-input-outlined-border {
    border-color: var(--mud-palette-primary) !important;
    transition: border-color .15s;
}

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

/* NOTE: Do NOT override floating label transform — breaks MudBlazor animation.
   Use Placeholder (not Label) on inputs with custom padding, or CbTextField
   which renders external label above the input. */

/* 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-textfield-start-icon svg {
    width: 18px;
    height: 18px;
}

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

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

.cb-textfield-input {
    position: relative;
}

.cb-textfield-start-icon {
    position: absolute;
    left: 14px;
    top: 10px;
    width: 18px;
    height: 18px;
    color: var(--cb-text-3);
    z-index: 1;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cb-textfield-start-icon svg {
    width: 18px;
    height: 18px;
}

.cb-textfield .cb-has-start-icon .mud-input-slot {
    padding-left: 42px !important;
}

/* 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);
}

/* --- 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;
}
