html, body {
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

h1:focus {
    outline: none;
}

#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;
    }

.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

    .blazor-error-boundary::after {
        content: "An error has occurred."
    }


/* APP STYLES */

/* Overall Layout and Drawer */

body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    margin: 0;
}

div.appbar-top {
    position: relative;
    z-index: 2000;
    overflow: visible;
}

/* Top category nav menu (visible on wide screens; hidden under 960px).
   Selector must match or exceed the Telerik theme rule
   .k-appbar .k-appbar-section { display: inline-flex } (specificity 0,2,0)
   so we use .k-appbar .appbar-section-menu plus !important as fallback. */
.k-appbar .appbar-section-menu,
.appbar-section-menu {
    display: none !important;
    flex: 1 1 auto;
    min-width: 0;
    margin-left: 1em;
    overflow: visible;
}

@media (min-width: 960px) {
    .k-appbar .appbar-section-menu,
    .appbar-section-menu {
        display: inline-flex !important;
    }
}

.appbar-menu.k-menu {
    background: transparent;
    border: none;
    box-shadow: none;
    font-size: 0.95em;
}

.appbar-menu .k-menu-link {
    padding: 0.4em 0.75em;
    border-radius: 6px;
    color: inherit;
    transition: background-color 0.15s ease;
}

.appbar-menu .k-menu-link:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

.appbar-menu-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    color: inherit;
    text-decoration: none;
}

.appbar-menu-link.appbar-menu-link-active {
    font-weight: 600;
    color: var(--kendo-color-primary);
}

.appbar-menu-label {
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    color: inherit;
}

/* Popup dropdown styling: align with theme, room for descriptions on hover */
.k-menu-popup .k-menu-link {
    padding: 0.5em 0.9em;
}

.k-menu-popup .appbar-menu-link {
    min-width: 12em;
}

/* GTTA toast: keep the top-right TelerikNotification clear of the AppBar. */
.k-notification-container.gtta-toast {
    top: 70px !important;
    right: 16px !important;
    z-index: 20000;
}

.gtta-toast .k-notification {
    min-width: 280px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}

.appbar-top .k-appbar-section,
.appbar-top .k-appbar-spacer {
    overflow: visible;
}

.mainlayout-drawer {
    flex: 1 1 auto;
    align-items: stretch;
    overflow: hidden;
    min-height: 0;
    height: 100%;
}

/* AppBar menu toggle: substantial hit area, themed hover, focus ring */
.appbar-menu-btn.k-button {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 6px;
    transition: background-color 120ms ease-in-out, box-shadow 120ms ease-in-out;
}

.appbar-menu-btn.k-button:hover {
    background-color: var(--kendo-color-base-hover, rgba(255, 255, 255, 0.08));
}

.appbar-menu-btn.k-button:focus-visible {
    outline: 2px solid var(--kendo-color-primary);
    outline-offset: 2px;
}

/* Collapsed mini-drawer: hide all label/trailing content so only the icons
   show in the rail. Without this, the custom ItemTemplate keeps rendering
   text + info icons and they get clipped awkwardly at the ~50px rail width. */
.k-drawer-mini .drawer-item-text,
.k-drawer-mini .drawer-item-info,
.k-drawer-mini .drawer-section-header {
    display: none;
}

/* Mobile + narrow viewports (<960px): hide the collapsed mini-drawer rail.
   Below 960px the top TelerikMenu is hidden and the AppBar (brand + hamburger
   + user info) becomes the sole persistent nav. The drawer still slides in
   on hamburger toggle (DrawerExpanded), but does not leave a permanent
   left-side rail next to the top bar. This avoids the previous "two navs at
   once" effect at phone and small-tablet widths. Desktop (>=960px) is
   unchanged: TelerikMenu is the only nav and the drawer is not rendered. */
@media (max-width: 959px) {
    .mainlayout-drawer .k-drawer.k-drawer-mini {
        display: none;
    }
}

/* Center the lone icon left in each row when collapsed. */
.k-drawer-mini .drawer-item-row,
.k-drawer-mini .drawer-external-link {
    justify-content: center;
}

/* Tighten any item rows in mini mode so the icon sits centred on the rail. */
.k-drawer-mini .k-drawer-item {
    padding-left: 0;
    padding-right: 0;
    text-align: center;
}

.mainlayout-drawer .k-drawer-content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.mainlayout-drawer > .k-drawer {
    min-height: 0;
    height: 100%;
}

.mainlayout-drawer .k-drawer-wrapper {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

    .mainlayout-drawer .k-drawer-items {
        margin-top: 0.5em;
    }

.drawer-separator {
    border: none;
    border-top: 1px solid var(--kendo-color-border, rgba(255,255,255,0.1));
    margin: 0.4em 1em;
}

.drawer-section-header {
    display: flex;
    align-items: center;
    gap: 0.4em;
    font-size: 0.65em;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    opacity: 0.5;
    padding: 0.6em 0 0.2em;
    pointer-events: none;
}

.drawer-section-text {
    pointer-events: none;
}

.drawer-section-info {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    cursor: help;
    opacity: 0.6;
    transition: opacity 120ms ease-in-out;
    font-size: 1em;
}

.drawer-section-info:hover,
.drawer-section-info:focus-visible {
    opacity: 1;
    outline: none;
}

.drawer-item-text {
    margin-left: 0.5em;
}

.drawer-item-row {
    display: flex;
    align-items: center;
    width: 100%;
}

.drawer-external-link {
    display: flex;
    align-items: center;
    color: inherit;
    text-decoration: none;
    width: 100%;
}

.drawer-item-info {
    margin-left: auto;
    padding: 0 0.25em 0 0.5em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: help;
    opacity: 0;
    transition: opacity 120ms ease-in-out;
    font-size: 0.9em;
}

.drawer-item-row:hover .drawer-item-info,
.drawer-external-link:hover .drawer-item-info,
.drawer-item-info:hover,
.drawer-item-info:focus-visible {
    opacity: 0.7;
    outline: none;
}

.drawer-item-info:hover,
.drawer-item-info:focus-visible {
    opacity: 1;
}

.drawer-tooltip .k-tooltip-content {
    max-width: 320px;
    white-space: normal;
    line-height: 1.35;
}

/* Top AppBar */

.appbar-top > div {
    line-height: 2.4;
}

.app-brand {
    display: inline-flex;
    align-items: center;
    gap: .55em;
    padding: 4px 8px;
    margin: 0;
    border-radius: 6px;
    font-size: 1.2em;
    line-height: 1;
    color: inherit;
    text-decoration: none;
    transition: background-color .15s ease;
}

    .app-brand:hover,
    .app-brand:focus-visible {
        background-color: rgba(255, 255, 255, 0.06);
        color: inherit;
        text-decoration: none;
        outline: none;
    }

    .app-brand-mark {
        display: block;
        width: 28px;
        height: 28px;
        border-radius: 6px;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    }

    .app-brand-text {
        font-weight: 700;
        letter-spacing: .04em;
    }

/* Main Content */

main {
    padding: 0 2em 2em;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
}

main > .k-grid {
    flex: 1;
    min-height: 0;
    height: unset !important;
}

a {
    color: var(--kendo-color-on-app-surface);
}

    a:hover {
        color: var(--kendo-color-primary);
        text-decoration: none;
    }

h1, h2, h3 {
    margin: .67em 0 .3em;
    font-weight: normal;
}

h1 {
    font-size: 42px;
}

h2 {
    font-size: 32px;
}

h3 {
    font-size: 24px;
}

/* User Auth Display */

.user-info {
    display: flex;
    align-items: center;
    gap: 0.8em;
    margin-right: 1em;
}

.user-name {
    font-weight: 500;
    font-size: 0.9em;
    opacity: 0.85;
}

.logout-link,
.login-link {
    font-size: 0.85em;
    padding: 0.3em 0.8em;
    border-radius: 4px;
    border: 1px solid var(--kendo-color-border);
    text-decoration: none;
    color: inherit;
    transition: border-color 0.2s, background 0.2s;
}

.logout-link:hover,
.login-link:hover {
    border-color: var(--kendo-color-primary);
    background: rgba(150, 202, 79, 0.08);
    color: inherit;
}

/* Splitter Layout */

.mainlayout-splitter {
    flex: 1;
    overflow: hidden;
}

.mainlayout-splitter > .k-splitbar {
    z-index: 1;
}

/*
 * SplitterPane renders <main> directly inside .mainlayout-drawer-pane (no
 * .k-pane-content wrapper) when UseTopNav is true. Without flex on the pane
 * itself, <main>'s flex:1 + overflow-y:auto has no flex-parent context, so the
 * pane's overflow:hidden silently clips content that exceeds the viewport and
 * no scrollbar appears (Targets page bottom was unreachable). Same pattern as
 * .gtta-chat-pane below.
 */
.mainlayout-drawer-pane {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.mainlayout-drawer-pane > .k-pane-content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/*
 * When the chat pane is collapsed the drawer pane is the splitter's only
 * child. Telerik panes default to flex: 0 0 auto, so without this rule the
 * pane sizes to its content width instead of filling the splitter row, which
 * leaves ~280px of empty space on the right and pulls every centred page
 * (.dash, .tg-page) noticeably off-centre on a wide screen.
 */
.mainlayout-splitter > .k-pane.mainlayout-drawer-pane:only-child {
    flex: 1 1 auto;
}

/* GTTA AI Chat Pane */

/*
 * Telerik renders SplitterPane children directly inside the .gtta-chat-pane DIV
 * (no .k-pane-content wrapper), so flex layout must be set on the pane itself.
 * Without this, .gtta-chat-body's flex:1 has no flex parent and the chat body
 * grows to content size instead of being constrained to the pane height,
 * which makes the message-list scrollbar never appear under overflow.
 */
.gtta-chat-pane,
.gtta-chat-pane > .k-pane-content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--kendo-color-surface, #fff);
}

/* Shared page header treatment */

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1em;
    margin: 0.75em 0 1em;
    flex-wrap: wrap;
}

.page-header h1 {
    margin: 0;
    font-size: 1.8em;
}

.page-subtitle {
    margin: 0.25em 0 0;
    opacity: 0.8;
    font-size: 0.95em;
    max-width: 70ch;
}

/* Strategy parameter form (Components/Pages/Strategies/StrategyParameterForm.razor) */

.strategy-params-form {
    padding: 0.25em 0.25em 0.5em;
}

.strategy-params-head {
    margin-bottom: 0.75em;
}

.strategy-params-heading {
    margin: 0;
    font-size: 1.05em;
    font-weight: 600;
}

.strategy-params-sub {
    margin: 0.25em 0 0;
    opacity: 0.75;
    font-size: 0.9em;
}

.strategy-params-empty {
    margin: 0.5em 0 0;
    opacity: 0.7;
    font-size: 0.92em;
}

.strategy-params-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 0.75em;
    margin: 0.5em 0;
}

.param-card {
    border-radius: 6px;
    background: rgba(255,255,255,0.04);
    padding: 0.75em 0.85em;
    display: flex;
    flex-direction: column;
    gap: 0.4em;
}

.param-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5em;
}

.param-label {
    font-weight: 600;
    font-size: 0.95em;
}

.param-badge {
    font-size: 0.7em;
    padding: 0.1em 0.5em;
    border-radius: 999px;
    border: 1px solid currentColor;
    letter-spacing: 0.03em;
}

.param-badge-default {
    color: rgba(255,255,255,0.55);
}

.param-badge-custom {
    color: #4caf50;
}

.param-badge-unsaved {
    color: #ffb74d;
}

.param-help {
    margin: 0;
    font-size: 0.85em;
    opacity: 0.75;
    line-height: 1.35;
}

.param-editor {
    display: flex;
    align-items: center;
    gap: 0.5em;
    flex-wrap: wrap;
}

.param-unit {
    font-size: 0.85em;
    opacity: 0.6;
}

.strategy-params-actions {
    display: flex;
    gap: 0.5em;
    margin-top: 0.5em;
    flex-wrap: wrap;
}

.strategy-params-custom {
    margin-top: 1.25em;
    padding-top: 0.75em;
    border-top: 1px dashed rgba(255,255,255,0.1);
}

.strategy-params-custom h5 {
    margin: 0 0 0.25em;
    font-size: 0.95em;
}

.strategy-params-custom-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
    margin-top: 0.5em;
}

.strategy-params-custom-table th,
.strategy-params-custom-table td {
    padding: 0.35em 0.5em;
    text-align: left;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.strategy-params-custom-table th {
    opacity: 0.7;
    font-weight: 500;
}

/* Backtest chart tooltips */
.k-chart-tooltip,
.k-chart-tooltip.k-tooltip,
.k-animation-container .k-chart-tooltip,
.k-animation-container .k-tooltip.k-chart-tooltip {
    background: rgba(15, 23, 42, 0.96) !important;
    color: #f8fafc !important;
    border: 1px solid rgba(148, 163, 184, 0.45) !important;
    border-radius: 8px !important;
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.35) !important;
    opacity: 1 !important;
    backdrop-filter: blur(6px);
}

.k-chart-tooltip .k-tooltip-content,
.k-tooltip.k-chart-tooltip .k-tooltip-content {
    background: transparent !important;
    color: inherit !important;
    opacity: 1 !important;
}

.k-chart-tooltip strong,
.k-tooltip.k-chart-tooltip strong {
    color: #ffffff;
}

/* ============================================================
   MOBILE RESPONSIVE
   ============================================================ */

/* Reduce main content padding on phones */
@media (max-width: 640px) {
    main {
        padding: 0 0.75em 1.5em;
    }

    h1 {
        font-size: 1.6em;
    }

    h2 {
        font-size: 1.25em;
    }

    .page-header {
        gap: 0.5em;
        margin: 0.5em 0 0.75em;
    }

    .page-header h1 {
        font-size: 1.4em;
    }

    .page-subtitle {
        font-size: 0.85em;
    }
}

/* AppBar: keep it in a single row, allow wrapping only if needed */
@media (max-width: 959px) {
    div.appbar-top .k-appbar-section,
    div.appbar-top .k-appbar-spacer {
        overflow: hidden;
    }

    div.appbar-top {
        flex-wrap: wrap;
    }
}

/* AppBar: hide username on narrow screens, keep sign-out + chat */
@media (max-width: 600px) {
    .user-name {
        display: none;
    }

    .user-info {
        gap: 0.4em;
        margin-right: 0.4em;
    }

    .app-brand-text {
        display: none;
    }

    .app-brand {
        padding: 4px;
    }
}

/* AppBar hamburger section: don't let it add dead space on wide screens */
.appbar-section-menubtn {
    flex: 0 0 auto;
}

/* Grids: ensure they scroll horizontally rather than overflowing the page */
@media (max-width: 768px) {
    main > .k-grid {
        height: calc(100vh - 140px) !important;
    }
}

/* Grid toolbar: wrap on mobile so Add button + refresh don't clip */
@media (max-width: 640px) {
    .k-grid .k-toolbar,
    .k-grid .k-grid-toolbar {
        flex-wrap: wrap;
        gap: 0.4em;
    }
}

/* Chat pane: on mobile the splitter chat pane should overlay full-width */
@media (max-width: 768px) {
    .gtta-chat-pane {
        position: fixed !important;
        inset: 0 !important;
        z-index: 9000;
        width: 100% !important;
        max-width: 100% !important;
        flex: none !important;
    }

    .mainlayout-splitter > .k-splitbar {
        display: none;
    }
}

/* Market Monitor toolbar: wrap controls on narrow viewports */
@media (max-width: 768px) {
    .mm-toolbar {
        flex-wrap: wrap;
        gap: 0.4em;
    }

    .mm-toolbar-controls {
        flex-wrap: wrap;
        gap: 0.4em;
        width: 100%;
    }

    .mm-field {
        flex: 1 1 auto;
        min-width: 0;
    }

    .mm-field .k-dropdownlist {
        width: 100% !important;
    }
}

/* Responsive adjustments for strategy parameter form */
@media (max-width: 640px) {
    .strategy-params-grid {
        grid-template-columns: 1fr;
    }
}
