/* ---- Theme tokens (IBM Carbon light / dark) ---- */
:root {
    --canvas: #ffffff;
    --surface-1: #f4f4f4;
    --surface-2: #e0e0e0;
    --ink: #161616;
    --ink-muted: #525252;
    --ink-subtle: #8c8c8c;
    --hairline: #e0e0e0;
    --hairline-strong: #161616;
    --ibm-blue: #0f62fe;
    --blue-hover: #0050e6;
    --blue-60: #0043ce;
    --blue-80: #002d9c;
    --blue-10: #edf5ff;
    --blue-20: #d0e2ff;
    --secondary: #0f62fe;
    --on-secondary: #ffffff;
    --success: #24a148;
    --success-dark: #198038;
    --success-light: #defbe6;
    --warning: #f1c21b;
    --warning-dark: #8e6a00;
    --warning-light: #fcf4d6;
    --danger: #da1e28;
    --danger-dark: #a2191f;
    --danger-light: #fff1f1;
    --info: #0f62fe;
    --focus-ring: #0f62fe;
    --modal-bg: #ffffff;
    --modal-border: #e0e0e0;
    --modal-shadow: rgba(0, 0, 0, 0.2);
    --page-bg: #f7f8fa;
    --sidebar-bg: #111827;
    --sidebar-border: #1f2937;
    --topbar-bg: #ffffff;
    --topbar-border: #d9dee7;
    --status-pill-border: #d9dee7;
    --status-pill-bg: #ffffff;
    --eyebrow: #6b7280;
    --nav-active-bg: #f4f4f4;
    --nav-active-ink: #161616;
}

:root.dark {
    --canvas: #161616;
    --surface-1: #262626;
    --surface-2: #393939;
    --ink: #f4f4f4;
    --ink-muted: #a8a8a8;
    --ink-subtle: #6f6f6f;
    --hairline: #393939;
    --hairline-strong: #f4f4f4;
    --ibm-blue: #78a9ff;
    --blue-hover: #a6c8ff;
    --blue-60: #4589ff;
    --blue-80: #0043ce;
    --blue-10: #001d6c;
    --blue-20: #002d9c;
    --secondary: #78a9ff;
    --on-secondary: #002d9c;
    --success: #42be65;
    --success-dark: #6fdc8c;
    --success-light: #044317;
    --warning: #f1c21b;
    --warning-dark: #f1c21b;
    --warning-light: #3a2a04;
    --danger: #fa4d56;
    --danger-dark: #ff8389;
    --danger-light: #3b1019;
    --info: #78a9ff;
    --focus-ring: #78a9ff;
    --modal-bg: #262626;
    --modal-border: #393939;
    --modal-shadow: rgba(0, 0, 0, 0.5);
    --page-bg: #161616;
    --sidebar-bg: #0d0d0d;
    --sidebar-border: #262626;
    --topbar-bg: #1a1a1a;
    --topbar-border: #393939;
    --status-pill-border: #393939;
    --status-pill-bg: #262626;
    --eyebrow: #a8a8a8;
    --nav-active-bg: #393939;
    --nav-active-ink: #f4f4f4;
}

.material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    display: inline-block;
    line-height: 1;
    text-transform: none;
    letter-spacing: normal;
    word-wrap: normal;
    white-space: nowrap;
    direction: ltr;
}

body {
    min-height: max(884px, 100dvh);
    font-family: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;
    letter-spacing: 0.16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Carbon focus ring — 2px IBM Blue outline on interactive elements */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: -2px;
}

.bento-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}
@media (max-width: 768px) {
    .bento-grid {
        grid-template-columns: 1fr;
    }
}

/* Blazor Specific Validation — Carbon semantic colors */
.valid.modified:not([type=checkbox]) {
    outline: 1px solid var(--success);
}

.invalid {
    outline: 1px solid var(--danger);
}

.validation-message {
    color: var(--danger);
    font-size: 12px;
    line-height: 1.33;
    letter-spacing: 0.32px;
    margin-top: 4px;
}

#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* ---------------------------------------------------------------------------
   Header popovers — notifications & help dropdowns. Driven by vanilla JS
   (App.razor) toggling `.open` on the `[data-popover]` wrapper, so they work
   inside the statically-rendered MainLayout without a Blazor circuit.
   Un-scoped: applies at all breakpoints.
   --------------------------------------------------------------------------- */
[data-popover-panel] {
    display: none;
}
html [data-popover].open [data-popover-panel] {
    display: block;
}

/* ---------------------------------------------------------------------------
   Mobile shell — drawer nav, backdrop, bottom bar, responsive tables.
   Everything here is scoped to phones (<= 767px). Desktop (md+) is untouched:
   the sidebar keeps its permanent `fixed left-0` position from MainLayout.
   --------------------------------------------------------------------------- */

/* Active state for the mobile bottom navigation (NavLink adds `.active`). */
.bottom-nav-link.active {
    color: var(--secondary);
}

/* Backdrop is hidden until the drawer is open. */
.nav-backdrop {
    display: none;
}

@media (max-width: 767px) {
    /* Off-canvas drawer: slide the sidebar out of view, animate it in on open. */
    .app-sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        will-change: transform;
        padding-bottom: env(safe-area-inset-bottom); /* drawer footer clears home indicator */
    }

    html.nav-open .app-sidebar {
        transform: translateX(0);
        box-shadow: 0 0 24px rgba(0, 0, 0, 0.24);
    }

    /* Show the backdrop and lock background scroll while the drawer is open. */
    html.nav-open .nav-backdrop {
        display: block;
    }

    html.nav-open,
    html.nav-open body {
        overflow: hidden;
    }

    /* Wide data tables that are NOT tagged for card layout scroll horizontally
       instead of breaking the viewport (safety net for the long tail of tables). */
    .work-canvas table:not(.responsive-table) {
        display: block;
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    /* Card layout: tables tagged `responsive-table` turn each row into a labelled
       card on phones. Add class="… responsive-table" to the <table> and
       data-label="Column" to each <td> (the first cell becomes the card title). */
    .responsive-table thead {
        display: none;
    }
    .responsive-table,
    .responsive-table tbody {
        display: block;
        width: 100%;
    }
    .responsive-table tr {
        display: block;
        padding: 12px 16px;
    }
    .responsive-table td {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 6px 0;
        text-align: right;
        white-space: normal;
        border: 0;
    }
    .responsive-table td::before {
        content: attr(data-label);
        margin-right: auto;
        text-align: left;
        font-size: 12px;
        font-weight: 600;
        letter-spacing: 0.02em;
        text-transform: uppercase;
        color: var(--ink-muted);
    }
    /* First cell becomes the card title: full width, no label. */
    .responsive-table td:first-child {
        display: block;
        text-align: left;
        padding: 0 0 8px;
        margin-bottom: 4px;
        border-bottom: 1px solid var(--hairline);
    }
    .responsive-table td:first-child::before {
        content: none;
    }
    /* Empty-state / spanning rows: no label, centred, no divider. */
    .responsive-table td[colspan] {
        display: block;
        text-align: center;
        border-bottom: 0;
        padding: 8px 0;
    }
    .responsive-table td[colspan]::before {
        content: none;
    }

    /* iOS: keep the fixed bottom nav above the home indicator / gesture area.
       Needs viewport-fit=cover (App.razor). env() is 0 on non-notched devices. */
    nav.bottom-nav {
        height: calc(4rem + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* iOS Safari auto-zooms the page when a focused control is < 16px. Force 16px on
       touch viewports so tapping a field/search box doesn't jolt the layout.
       !important to override Tailwind text-size utilities (e.g. text-body-sm = 14px). */
    input,
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* ---------------------------------------------------------------------------
   Touch targets — Apple HIG requires 44px minimum on touch viewports.
   Buttons and selects often use h-9/h-10 (36/40px); bump to 44px on mobile.
   Inputs are already handled by the 16px font-size rule above.
   --------------------------------------------------------------------------- */
@media (max-width: 767px) {
    button, select {
        min-height: 44px;
    }
}

/* ---------------------------------------------------------------------------
   Reduced motion — respect user's prefers-reduced-motion setting.
   Disables decorative animations while keeping essential state changes.
   --------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .global-loading-bar__track {
        animation: none;
        width: 100%;
        opacity: 0.7;
    }
    .btn-spinner {
        animation: none;
        border-right-color: currentColor;
        opacity: 0.5;
    }
    .btn-loading-active::after {
        animation: none !important;
        border-right-color: currentColor !important;
        opacity: 0.5 !important;
    }
    *,
    *::before,
    *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}

/* ---------------------------------------------------------------------------
   Global Loading Bar — appears at the very top of the page whenever any
   async operation is in-flight (driven by GlobalLoadingService).
   --------------------------------------------------------------------------- */

.global-loading-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 9999;
    pointer-events: none;
    overflow: hidden;
    background: transparent;
}

.global-loading-bar__track {
    height: 100%;
    width: 40%;
    background: linear-gradient(90deg, var(--ibm-blue) 0%, var(--blue-hover) 60%, var(--ibm-blue) 100%);
    background-size: 200% 100%;
    border-radius: 0 2px 2px 0;
    animation: loading-bar-slide 1.4s ease-in-out infinite;
}

@keyframes loading-bar-slide {
    0%   { transform: translateX(-100%); }
    60%  { transform: translateX(200%); }
    100% { transform: translateX(200%); }
}

/* ---------------------------------------------------------------------------
   BusyButton — spinner shown inside the button while its async task runs.
   --------------------------------------------------------------------------- */

.btn-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: btn-spin 0.65s linear infinite;
    margin-right: 6px;
    vertical-align: middle;
    flex-shrink: 0;
}

@keyframes btn-spin {
    to { transform: rotate(360deg); }
}

/* While loading, show a progress cursor on the whole page */
body.app-busy,
body.app-busy * {
    cursor: wait !important;
}

/* Block ALL interactive elements page-wide during busy (prevents double-submit) */
body.app-busy button,
body.app-busy a[href],
body.app-busy a.btn,
body.app-busy input[type="submit"],
body.app-busy input[type="button"],
body.app-busy [role="button"] {
    pointer-events: none !important;
}

/* CSS-driven loading bar at top of viewport (supplements Blazor LoadingBar for
   the 587 raw @onclick handlers that don't use BusyButton/GlobalLoadingService) */
body.app-busy::after {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 9999;
    pointer-events: none;
    overflow: hidden;
    background: linear-gradient(90deg, var(--ibm-blue) 0%, var(--blue-hover) 60%, var(--ibm-blue) 100%);
    background-size: 200% 100%;
    animation: loading-bar-slide 1.4s ease-in-out infinite;
}

/* Busy button — reduce opacity so it looks non-interactive */
.btn--loading {
    opacity: 0.7;
}

/* Click interceptor button loading styles */
.btn-loading-active {
    position: relative !important;
    pointer-events: none !important;
    opacity: 0.75 !important;
    color: transparent !important;
}

.btn-loading-active > * {
    opacity: 0 !important;
}

.btn-loading-active::after {
    content: "";
    position: absolute;
    top: 50% !important;
    left: 50% !important;
    width: 16px !important;
    height: 16px !important;
    margin-top: -8px !important;
    margin-left: -8px !important;
    border: 2px solid currentColor !important;
    border-right-color: transparent !important;
    border-radius: 50% !important;
    animation: btn-spin 0.65s linear infinite !important;
    opacity: 1 !important;
}

/* ---------------------------------------------------------------------------
   Skeleton screens — pulsing placeholder bars shown while data loads.
   --------------------------------------------------------------------------- */

.skeleton-bar {
    height: 12px;
    border-radius: 2px;
    background-color: var(--surface-2);
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-bar--sm { height: 10px; }

@keyframes skeleton-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.4; }
}

/* ---------------------------------------------------------------------------
   Page transition — subtle fade-in on the content area after navigation.
   --------------------------------------------------------------------------- */

@keyframes page-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.work-canvas {
    animation: page-fade-in 150ms ease-out;
}

/* ---------------------------------------------------------------------------
   Multi-Level Materiality — risk-band pills, classification chips, modal,
   SAD verdict, warning rows.
   --------------------------------------------------------------------------- */

/* Risk-band pills (FSA Materiality tab) */
.risk-band-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 2px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.32px;
    text-transform: uppercase;
}
.risk-band-low         { background: var(--success-light); color: #0e6027; }
.risk-band-moderate    { background: var(--warning-light); color: var(--warning-dark); }
.risk-band-high        { background: var(--danger-light);  color: var(--danger-dark); }
.risk-band-significant { background: #ffd7d9; color: #750e13; }
.risk-band-unrated     { background: var(--surface-1);     color: var(--ink-muted); }

/* Classification chips (Account Classification tab) */
.classification-chip {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 2px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.32px;
}
.classification-material       { background: #ffd7d9; color: #750e13; }
.classification-significant    { background: var(--danger-light);  color: var(--danger-dark); }
.classification-moderate       { background: var(--warning-light); color: var(--warning-dark); }
.classification-clearlytrivial { background: var(--surface-1);     color: var(--ink-muted); }

/* Warning highlight for untested material accounts */
.bg-warning-light { background-color: var(--warning-light); }

/* SAD verdict */
.sad-verdict { font-size: 13px; border-radius: 2px; }
.sad-verdict-ok     { background: var(--success-light); color: #0e6027; }
.sad-verdict-danger { background: #ffd7d9; color: #750e13; }

/* SAD per-FSA flag */
.sad-flag-ok          { color: var(--success-dark); font-weight: 600; }
.sad-flag-exceeds-pm  { color: var(--warning-dark); font-weight: 600; }
.sad-flag-material    { color: #750e13; font-weight: 600; }

/* Modal backdrop + panel */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 500;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 48px 16px;
    overflow-y: auto;
}
.modal-panel {
    background: var(--modal-bg);
    border: 1px solid var(--modal-border);
    padding: 24px;
    width: 100%;
    max-width: 640px;
    border-radius: 2px;
    box-shadow: 0 8px 24px var(--modal-shadow);
}
