/* App MudBlazor Layout & Structural Overrides */
/* Typography is controlled via DefaultTheme.cs */

h1:focus {
    outline: none;
}

/* Input label sizing and centering - inherit from theme typography */
.mud-input-control .mud-input-label {
    font-size: var(--mud-typography-body1-fontsize) !important;
}

.mud-input-label-outlined.mud-input-label-margin-dense {
    transform: translate(14px, 10px) scale(1);
}

/* Ensure input elements inherit the font size properly */
.mud-input-slot {
    font-size: inherit;
}

/* Global Button Normalization */
.mud-button:not(.mud-icon-button) {
    min-width: 80px;
}

/* Main content layout */
.mud-main-content {
    height: 100%;
    min-height: 100vh;
}

.centered-content-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    overflow-y: auto;
}

/* Tab bar compact height */
:root {
    --app-tab-font-size: var(--mud-typography-body2-fontsize, 0.8125rem);
    --app-tab-line-height: var(--mud-typography-body2-lineheight, 1.5);
    --app-tab-icon-size: 1.125rem;
}

.mud-tabs-tabbar {
    height: 40px;
}

.mud-tab {
    min-height: 40px;
    padding: 0 16px;
}

.mud-tab,
.mud-tab .mud-typography,
.mud-tab .mud-tab-text,
.mud-tab *:not(.mud-icon-root):not(svg) {
    font-size: var(--app-tab-font-size) !important;
    line-height: var(--app-tab-line-height) !important;
}

.mud-tab .mud-icon-root {
    font-size: var(--app-tab-icon-size) !important;
    height: var(--app-tab-icon-size);
    width: var(--app-tab-icon-size);
}

.mud-tab-icon-text {
    margin-bottom: 0;
    margin-right: 8px;
}

/* Border visibility - 1px borders for outlined elements */
.mud-input-outlined .mud-input-outlined-border {
    border-width: 1px;
}

.mud-divider,
.mud-table-outlined,
.mud-paper-outlined,
.mud-alert-outlined {
    border-width: 1px;
}

/* Navigation */
.side-menu .mud-nav-link {
    white-space: normal;
    margin: 0;
    padding-top: 8px;
    padding-bottom: 8px;
    padding-left: 16px;
    border-left: 3px solid transparent; /* Reserve space to prevent jump */
    transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out;
}

.side-menu .mud-nav-group-header {
    margin: 0;
    padding-top: 8px;
    padding-bottom: 8px;
    padding-left: 16px;
    border-left: 3px solid transparent;
    transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out;
}

/* Navigation Transitions */
.side-menu .mud-nav-link .mud-nav-link-text,
.side-menu .mud-nav-link .mud-nav-link-icon-default,
.side-menu .mud-nav-group-header .mud-nav-link-text,
.side-menu .mud-nav-group-header .mud-nav-link-icon-default {
    transition: transform 0.2s ease-in-out;
}

/* Only slide actual navigation links (pages) */
/* Actual pages in MudBlazor use the <a> tag for MudNavLink */
.side-menu a.mud-nav-link:hover:not(.mud-nav-link-disabled) .mud-nav-link-text,
.side-menu a.mud-nav-link:hover:not(.mud-nav-link-disabled) .mud-nav-link-icon-default,
.side-menu a.mud-nav-link.active:not(.mud-nav-link-disabled) .mud-nav-link-text,
.side-menu a.mud-nav-link.active:not(.mud-nav-link-disabled) .mud-nav-link-icon-default {
    transform: translateX(8px);
}

/* Ensure dropdown headers (which are divs, not <a> tags) NEVER slide */
.side-menu .mud-nav-group-header .mud-nav-link-text,
.side-menu .mud-nav-group-header .mud-nav-link-icon-default {
    transform: none !important;
}

.side-menu .mud-nav-link:hover:not(.mud-nav-link-disabled),
.side-menu .mud-nav-group-header:hover {
    background-color: rgba(var(--mud-palette-primary-rgb), 0.08);
}

.side-menu .mud-nav-link.active:not(.mud-nav-link-disabled) {
    background-color: rgba(var(--mud-palette-primary-rgb), 0.12);
    border-left-color: var(--mud-palette-primary);
}

.side-menu .mud-nav-link .mud-nav-link-icon-default, 
.side-menu .mud-nav-group-header .mud-nav-link-icon-default {
    margin-right: 8px;
}

.side-menu {
    border-right: 1px solid var(--mud-palette-divider);
}

/* DataGrid toolbar spacing */
.mud-table.mud-data-grid .mud-toolbar,
.mud-table.mud-data-grid .mud-table-toolbar {
    height: auto;
    padding: 1rem;
}

.mud-table.mud-data-grid .mud-table-pagination-toolbar {
    height: auto;
    padding: 0;
}

/* Key-value tables: fix column widths so short values don't get pushed far right */
.kv-table table { table-layout: fixed; }
.kv-table table td:first-child { width: 45%; }

/* Dialog styling */
.mud-dialog-container .mud-overlay {
    backdrop-filter: blur(2px);
}

.mud-dialog .mud-dialog-actions {
    padding: 16px 24px 20px;
    gap: 8px;
}

.mud-dialog .mud-dialog-content {
    padding: 20px 24px;
}

.mud-dialog .mud-dialog-title {
    padding: 20px 24px 8px;
}

/* User button */
.user-button {
    text-transform: none;
    background: rgba(var(--mud-palette-primary-rgb), 0.1);
}

/* Side menu chip sizing */
.side-menu .mud-chip.mud-chip-size-small {
    font-size: 0.625rem;
    height: 1.125rem;
}

/* Blazor error boundary */
.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5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    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

/* Drawer transition */
.mud-drawer {
    transition: width 0.2s ease-in-out;
}

/* Loading overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(var(--mud-palette-background-rgb), 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

/* User menu popover minimum width */
.user-menu-popover {
    min-width: 250px;
    overflow: hidden !important;
}

.user-menu-popover .mud-list {
    padding: 0 !important;
}

.user-menu-popover .mud-paper {
    overflow: hidden !important;
}

/* Notification menu popover fixed width */
.notification-popover {
    width: 350px;
}

.notification-popover .mud-list {
    width: 100%;
}

/* Mobile responsive */
@media (max-width: 600px) {
    .mud-table,
    .mud-data-grid {
        overflow-x: auto;
    }

    .mud-table-cell {
        white-space: nowrap;
    }

    .mud-container {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .mud-dialog-actions {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .mud-dialog-actions .mud-button {
        flex: 1 1 auto;
    }

    .mud-dialog {
        max-width: 100%;
        margin: 0.5rem;
    }

    .hide-on-mobile {
        display: none;
    }
}

    @media (max-width: 960px) {
        .mud-drawer-header {
            padding: 0.75rem;
        }

        .mud-chart {
            max-width: 100%;
            height: auto;
        }
    }

    @keyframes typing {
        0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
        30% { transform: translateY(-4px); opacity: 1; }
    }

    /* Blazor Server reconnection modal */
#components-reconnect-modal {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    background: transparent;
    border: none;
    padding: 0;
    margin: 0;
    z-index: 2147483647;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

#components-reconnect-modal[open] {
    display: flex;
    opacity: 1;
    pointer-events: auto;
}

#components-reconnect-modal::backdrop {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
}

.reconnect-panel {
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-lines-default);
    box-shadow: var(--mud-elevation-24);
    width: 90%;
    max-width: 340px;
    border-radius: 16px;
    padding: 40px 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    animation: reconnect-slideUp 0.3s ease-out;
}

.reconnect-icon-wrapper {
    position: relative;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
}

.reconnect-status-icon {
    width: 40px;
    height: 40px;
    color: var(--mud-palette-primary);
    z-index: 2;
}

.reconnect-pulse-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--mud-palette-primary);
    opacity: 0;
    animation: reconnect-ripple 2s infinite ease-out;
}

.reconnect-title {
    margin: 0 0 8px;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--mud-palette-text-primary);
}

.reconnect-desc {
    margin: 0;
    font-size: 0.95rem;
    color: var(--mud-palette-text-secondary);
    line-height: 1.5;
}

.reconnect-sub-text {
    font-size: 0.85rem;
    opacity: 0.8;
    margin-top: 4px;
    display: block;
}

.reconnect-progress-container {
    width: 100%;
    height: 4px;
    background: var(--mud-palette-lines-default);
    border-radius: 100px;
    overflow: hidden;
    margin-top: 32px;
}

.reconnect-progress-bar {
    width: 100%;
    height: 100%;
    background: var(--mud-palette-primary);
    animation: reconnect-indeterminate 1.5s infinite cubic-bezier(0.65, 0.815, 0.735, 0.395);
}

@keyframes reconnect-slideUp {
    from { transform: scale(0.95) translateY(10px); opacity: 0; }
    to { transform: scale(1) translateY(0); opacity: 1; }
}

@keyframes reconnect-ripple {
    0% { transform: scale(0.8); opacity: 0.5; border-width: 4px; }
    100% { transform: scale(1.4); opacity: 0; border-width: 0; }
}

@keyframes reconnect-indeterminate {
    0% { transform: translateX(-100%); }
    60% { transform: translateX(50%); }
    100% { transform: translateX(100%); }
}

/* ── Chart trade hover panel: floats top-right inside AppChart's
     chart container, shows stats for the trade the cursor is over.
     pointer-events:none so it never eats a click. ── */
.app-chart-hover {
    position: absolute;
    top: 8px;
    right: 12px;
    z-index: 5;
    padding: 6px 10px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.75);
    color: #eaeaf0;
    font-size: 0.78rem;
    line-height: 1.5;
    pointer-events: none;
    min-width: 180px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
.app-chart-hover__title { display: flex; align-items: center; gap: 6px; margin-bottom: 2px; }
.app-chart-hover__side {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    padding: 1px 5px;
    border-radius: 3px;
}
.app-chart-hover__side--long  { background: rgba(38, 166, 154, 0.25); color: #6fddd0; }
.app-chart-hover__side--short { background: rgba(239, 83, 80,  0.25); color: #f4928f; }
.app-chart-hover__label { opacity: 0.7; }
.app-chart-hover__k { opacity: 0.6; margin-right: 4px; }
.app-chart-hover__arrow { opacity: 0.5; margin: 0 4px; }
.app-chart-hover__pnl { font-weight: 600; }
.app-chart-hover__pnl--win  { color: #6fddd0; }
.app-chart-hover__pnl--loss { color: #f4928f; }
.app-chart-hover__dates { opacity: 0.6; font-size: 0.72rem; margin-top: 2px; }

/* ── Fullscreen: target the wrapper (toolbar + chart), flex the chart to fill
   the remaining height. autoSize on the LC side picks up the new dimensions
   via its ResizeObserver. Toolbar icons get bumped a notch for readability
   on a big screen — KISS, no media queries. ── */
.app-chart-wrapper:fullscreen {
    background: #1e1e2e;
    padding: 12px;
    height: 100vh;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}
.app-chart-wrapper:fullscreen .app-chart-container {
    flex: 1 1 auto;
    height: auto !important;
    min-height: 0;
}
.app-chart-wrapper:fullscreen .mud-button-root.mud-icon-button {
    padding: 8px;
}
.app-chart-wrapper:fullscreen .mud-icon-root {
    font-size: 1.35rem;
}

/* ── Metric label row: label + muted info icon.
     svg { display:block } is the only rule that actually centres the
     icon — SVGs sit on the text baseline by default (~2px high next
     to bold text); setting them to block takes them out of that flow
     and align-items:center does its job. ── */
.metric-label-row { display: inline-flex; align-items: center; gap: 4px; }
.metric-label-row svg { display: block; opacity: 0.6; }
.metric-label-row .icon-btn { cursor: pointer; }
.metric-label-row .icon-btn:hover svg { opacity: 0.95; }

/* Same baseline fix for standalone tooltip'd icons that sit inline with text
   (InfoHint next to a heading, a flag icon next to a name). Without display:block
   the SVG descender drops the icon below the text in an align-items:center row. */
.info-hint, .tip-icon { display: inline-flex; align-items: center; }
.info-hint svg, .tip-icon svg { display: block; }
.info-hint svg { opacity: 0.6; }
.info-hint .icon-btn { cursor: pointer; }
.info-hint .icon-btn:hover svg { opacity: 0.95; }

/* Advisory panels pair a full-width summary row + flags (flush to the panel padding)
   with a MudSimpleTable (cells carry their own padding). Zero the table's outer-edge
   padding so every row shares one clean left edge instead of the table looking indented. */
.flush-table td:first-child, .flush-table th:first-child { padding-left: 0; }
.flush-table td:last-child,  .flush-table th:last-child  { padding-right: 0; }

/* ── Markdown body in tooltip (.metric-tip) and dialog (.metric-explainer).
     Browser defaults for p/ul/li/strong/code look fine — we only cap width,
     tone the font, kill the outer first/last margins so the bubble isn't
     double-padded, and give blockquotes a left rule so the "Why in Rosetta"
     callout reads as a callout instead of just indented text. ── */
.metric-tip        { max-width: 360px; font-size: 0.82rem; line-height: 1.5; }
.metric-explainer  { font-size: 0.9rem;  line-height: 1.6; }
.metric-tip > :first-child, .metric-explainer > :first-child { margin-top: 0; }
.metric-tip > :last-child,  .metric-explainer > :last-child  { margin-bottom: 0; }
.metric-tip blockquote, .metric-explainer blockquote {
    margin: 0.6em 0 0;
    padding: 0.25em 0.75em;
    border-left: 3px solid rgba(255, 255, 255, 0.25);
    opacity: 0.92;
}

/* ── Markdown document rhythm (.markdown-body) — THE standard for long-form markdown surfaces:
     chat attachment previews, ML reports, any future viewer. Chat bubbles keep their own tighter
     rhythm (conversation, not documents); .metric-tip/.metric-explainer stay compact by design. ── */
.markdown-body { line-height: 1.65; }
.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child { margin-bottom: 0; }
.markdown-body p { margin: 10px 0; }
.markdown-body ul, .markdown-body ol { margin: 10px 0; padding-left: 1.8em; }
.markdown-body li { margin: 5px 0; }
.markdown-body li > p { margin: 4px 0; }

.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
    margin: 24px 0 10px;
    line-height: 1.3;
}

.markdown-body pre {
    margin: 12px 0;
    padding: 8px 12px;
    border-radius: 6px;
    overflow-x: auto;
    background: var(--mud-palette-background-gray);
}

.markdown-body code { font-family: var(--mud-typography-caption-family, monospace); }

.markdown-body blockquote {
    margin: 10px 0;
    padding: 4px 16px;
    border-left: 3px solid var(--mud-palette-lines-default);
    color: var(--mud-palette-text-secondary);
}

.markdown-body table { border-collapse: collapse; margin: 12px 0; }
.markdown-body th, .markdown-body td { padding: 6px 12px; border: 1px solid var(--mud-palette-lines-default); }

/* PFI report add-on: dense numeric tables — row rules instead of full borders, numbers right-aligned. */
.pfi-report table { width: 100%; }
.pfi-report th, .pfi-report td { border: none; border-bottom: 1px solid rgba(255, 255, 255, 0.1); padding: 0.4rem 0.75rem; white-space: nowrap; }
.pfi-report th { text-align: left; font-weight: 600; border-bottom: 2px solid rgba(255, 255, 255, 0.2); }
.pfi-report td:not(:first-child) { text-align: right; }
