:root {
    color-scheme: dark;
    --page-bg: #0b0e11;
    --surface: #1e2329;
    --surface-alt: #1b212b;
    --surface-active: #161b22;
    --surface-control: #2b3139;
    --surface-hover: #3a4350;
    --surface-header: #252b32;
    --surface-raised-alt: #232a35;
    --divider-subtle: #1a1f27;
    --border-strong: #3c4043;
    --text-primary: #eaecef;
    --text-secondary: #b7bdc6;
    --text-secondary-strong: #c2cad6;
    --text-muted: #848e9c;
    --text-subtle: #5e6673;
    --accent: #f0b90b;
    --success-solid: #02c076;
    --success-text: #4caf72;
    --success-bg: #1d3a2c;
    --danger-solid: #f6465d;
    --danger-text: #ff7676;
    --danger-bg: #3d2326;
    --warning-text: #c9a227;
    --warning-soft-text: #e6c96d;
    --warning-bg: #3a2e12;
    --warning-border: #8b6d18;
    --orange-text: #e8a13a;
    --info-text: #4fa8ff;
    --info-bg: #2b3a4d;
    --info-bg-strong: #1d2b3d;
    --history-surface: #111827;
    --history-header: #1f2937;
    --history-sticky: #0f172a;
    --history-border: #374151;
    --history-muted: #9ca3af;
    --history-text: #d1d5db;
    --cyan-border: #0e7490;
    --cyan-text: #67e8f9;
    --yellow-text: #facc15;
    --purple-text: #c4b5fd;
    --blue-soft-text: #93c5fd;
    --orange-soft-text: #fdba74;
    --red-soft-text: #fca5a5;
    --green-soft-text: #86efac;
    --surface-deep-1: #11161c;
    --surface-deep-2: #0f1419;
    --surface-deep-3: #161a1e;
    --bug-text: #ff8b98;
    --feature-text: #73b9ff;
    --purple-solid: #a979ff;
    --disabled-text: #7d8590;
    --surface-hover-alt: #232a33;
    --border-alt: #3c4856;
    --purple-bg: #2f2440;
    --purple-soft-text: #c49dff;
    --success-soft-text: #6ed19a;
    --cancelled-bg: #30333a;
    --card-hover: #242a32;
    --degraded-text: #ff9b6b;
    --vspeed-text: #e8b339;
    --text-neutral: #d0d4dc;
    --border-dark: #2b313a;
    --buy-info-text: #4a9eff;
    --park-buy-text: #6d93b8;
    --park-sell-text: #c39a5a;
    --pager-hover: #363d47;
    --critical-bg: #3a1d24;
    --stale-bg: #3a3218;
    --cyan-bg: #16313a;
    --cyan-muted-text: #5ec8d8;
    --log-info: #5a8dee;
    --border-mid: #474d57;
    --binance-bg: #4a3c0a;
    --model-bg: #24384b;
    --model-text: #6bb5ff;
    --snapshot-bg: #343b45;
    --snapshot-text: #c5cbd3;
    --stress-bg: #5a4510;
    --stress-text: #f1d36b;
    --text-medium: #aeb4bd;
    --surface-row: #181c22;
    --surface-row-alt: #252a31;
    --accent-red-border: #cf304a;
    --mobile-border: #1e242c;
    --no-bot-bg: #2b2517;
    --no-bot-hover: #343019;
    --long-bg: #14301f;
    --short-bg: #3a1e20;
    --error-soft-text: #ff9d9d;
    --no-bot-border: #6e5714;
    --no-bot-text: #f0c94d;
    --success-alt: #2ebd85;
    --mobile-row-border: #1a2029;
    --mobile-header-text: #cbd2dc;
    --mobile-header-bg: #11161d;
    --mobile-header-border: #2a3340;
    --warning-border-2: #6d5513;
    --warning-bg-2: #2d260f;
    --warning-text-2: #e0bd58;
    --mobile2-card-bg: #18202a;
    --mobile2-source-0: #5eb7ff;
    --mobile2-source-1: #f0a85b;
    --mobile2-source-2: #65d69a;
    --mobile2-source-3: #c58cff;
    --mobile2-source-4: #ff7f96;
    --mobile2-source-5: #62d5df;
    --mobile2-source-6: #e2cf63;
    --mobile2-source-7: #a6b7ff;
    --danger-deep: #2d1b1b;
    --text-gray: #c7c9cc;
    --green-banner-bg: #2b4d27;
    --green-bright: #0ecb81;
    --history-modal-text: #f3f4f6;
    --history-warning-text: #fbbf24;
    --history-warning-border: #a16207;
    --history-danger-border: #b91c1c;
    --row-alt-tint: rgba(43, 49, 57, .35);
    --danger-row-tint: rgba(180, 58, 58, .15);
    --warning-row-tint: rgba(201, 162, 39, .12);
    --warning-cell-tint: rgba(105, 83, 20, .28);
    --danger-cell-tint: rgba(114, 37, 37, .45);
    --warning-cell-strong-tint: rgba(105, 83, 20, .35);
    --danger-unavailable-tint: rgba(114, 37, 37, .28);
}

:root[data-theme="light"] {
    color-scheme: light;
    --page-bg: #f3f6f9;
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --surface-active: #e3e9f0;
    --surface-control: #eef2f6;
    --surface-hover: #e2e8ef;
    --surface-header: #e8edf3;
    --surface-raised-alt: #e9eef4;
    --divider-subtle: #d8e0e8;
    --border-strong: #c7d0da;
    --text-primary: #18202b;
    --text-secondary: #374151;
    --text-secondary-strong: #334155;
    --text-muted: #596579;
    --text-subtle: #697586;
    --accent: #a06b00;
    --success-solid: #087a48;
    --success-text: #087a48;
    --success-bg: #e4f6ec;
    --danger-solid: #c21f3a;
    --danger-text: #b4233a;
    --danger-bg: #fee9ed;
    --warning-text: #8a6100;
    --warning-soft-text: #765000;
    --warning-bg: #fff4d6;
    --warning-border: #b78100;
    --orange-text: #a65100;
    --info-text: #1769aa;
    --info-bg: #e8f2fb;
    --info-bg-strong: #dcecf8;
    --history-surface: #f8fafc;
    --history-header: #e8edf3;
    --history-sticky: #f2f5f8;
    --history-border: #c7d0da;
    --history-muted: #596579;
    --history-text: #344054;
    --cyan-border: #08788a;
    --cyan-text: #08788a;
    --yellow-text: #8a6100;
    --purple-text: #6d44b8;
    --blue-soft-text: #1769aa;
    --orange-soft-text: #a65100;
    --red-soft-text: #b4233a;
    --green-soft-text: #087a48;
    --surface-deep-1: #f4f7fa;
    --surface-deep-2: #f7f9fb;
    --surface-deep-3: #edf1f5;
    --bug-text: #b4233a;
    --feature-text: #1769aa;
    --purple-solid: #6d44b8;
    --disabled-text: #697586;
    --surface-hover-alt: #e9eef4;
    --border-alt: #b8c3cf;
    --purple-bg: #efe8fb;
    --purple-soft-text: #6d44b8;
    --success-soft-text: #087a48;
    --cancelled-bg: #e8edf2;
    --card-hover: #f5f7f9;
    --degraded-text: #ad3e13;
    --vspeed-text: #8a6100;
    --text-neutral: #374151;
    --border-dark: #c7d0da;
    --buy-info-text: #1769aa;
    --park-buy-text: #326a96;
    --park-sell-text: #8a5517;
    --pager-hover: #e2e8ef;
    --critical-bg: #fee9ed;
    --stale-bg: #fff4d6;
    --cyan-bg: #e7f6f7;
    --cyan-muted-text: #08788a;
    --log-info: #245fb5;
    --border-mid: #aeb9c5;
    --binance-bg: #fff4d6;
    --model-bg: #e8f2fb;
    --model-text: #1769aa;
    --snapshot-bg: #edf1f5;
    --snapshot-text: #374151;
    --stress-bg: #f8e3aa;
    --stress-text: #765000;
    --text-medium: #4b5563;
    --surface-row: #f8fafc;
    --surface-row-alt: #eef2f6;
    --accent-red-border: #c21f3a;
    --mobile-border: #d8e0e8;
    --no-bot-bg: #fff9e9;
    --no-bot-hover: #fff3c8;
    --long-bg: #e4f6ec;
    --short-bg: #fee9ed;
    --error-soft-text: #b4233a;
    --no-bot-border: #b78100;
    --no-bot-text: #8a6100;
    --success-alt: #087a48;
    --mobile-row-border: #d8e0e8;
    --mobile-header-text: #374151;
    --mobile-header-bg: #f4f7fa;
    --mobile-header-border: #c7d0da;
    --warning-border-2: #b78100;
    --warning-bg-2: #fff4d6;
    --warning-text-2: #765000;
    --mobile2-card-bg: #f8fafc;
    --mobile2-source-0: #1769aa;
    --mobile2-source-1: #a65100;
    --mobile2-source-2: #087a48;
    --mobile2-source-3: #6d44b8;
    --mobile2-source-4: #b4233a;
    --mobile2-source-5: #08788a;
    --mobile2-source-6: #765000;
    --mobile2-source-7: #4758a8;
    --danger-deep: #fee9ed;
    --text-gray: #374151;
    --green-banner-bg: #e4f6ec;
    --green-bright: #087a48;
    --history-modal-text: #18202b;
    --history-warning-text: #8a6100;
    --history-warning-border: #a16207;
    --history-danger-border: #b91c1c;
    --row-alt-tint: rgba(89, 101, 121, .08);
    --danger-row-tint: rgba(194, 31, 58, .09);
    --warning-row-tint: rgba(160, 107, 0, .09);
    --warning-cell-tint: rgba(160, 107, 0, .12);
    --danger-cell-tint: rgba(194, 31, 58, .14);
    --warning-cell-strong-tint: rgba(160, 107, 0, .16);
    --danger-unavailable-tint: rgba(194, 31, 58, .10);
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme]) {
        color-scheme: light;
        --page-bg: #f3f6f9;
        --surface: #ffffff;
        --surface-alt: #f8fafc;
        --surface-active: #e3e9f0;
        --surface-control: #eef2f6;
        --surface-hover: #e2e8ef;
        --surface-header: #e8edf3;
        --surface-raised-alt: #e9eef4;
        --divider-subtle: #d8e0e8;
        --border-strong: #c7d0da;
        --text-primary: #18202b;
        --text-secondary: #374151;
        --text-secondary-strong: #334155;
        --text-muted: #596579;
        --text-subtle: #697586;
        --accent: #a06b00;
        --success-solid: #087a48;
        --success-text: #087a48;
        --success-bg: #e4f6ec;
        --danger-solid: #c21f3a;
        --danger-text: #b4233a;
        --danger-bg: #fee9ed;
        --warning-text: #8a6100;
        --warning-soft-text: #765000;
        --warning-bg: #fff4d6;
        --warning-border: #b78100;
        --orange-text: #a65100;
        --info-text: #1769aa;
        --info-bg: #e8f2fb;
        --info-bg-strong: #dcecf8;
        --history-surface: #f8fafc;
        --history-header: #e8edf3;
        --history-sticky: #f2f5f8;
        --history-border: #c7d0da;
        --history-muted: #596579;
        --history-text: #344054;
        --cyan-border: #08788a;
        --cyan-text: #08788a;
        --yellow-text: #8a6100;
        --purple-text: #6d44b8;
        --blue-soft-text: #1769aa;
        --orange-soft-text: #a65100;
        --red-soft-text: #b4233a;
        --green-soft-text: #087a48;
        --surface-deep-1: #f4f7fa;
        --surface-deep-2: #f7f9fb;
        --surface-deep-3: #edf1f5;
        --bug-text: #b4233a;
        --feature-text: #1769aa;
        --purple-solid: #6d44b8;
        --disabled-text: #697586;
        --surface-hover-alt: #e9eef4;
        --border-alt: #b8c3cf;
        --purple-bg: #efe8fb;
        --purple-soft-text: #6d44b8;
        --success-soft-text: #087a48;
        --cancelled-bg: #e8edf2;
        --card-hover: #f5f7f9;
        --degraded-text: #ad3e13;
        --vspeed-text: #8a6100;
        --text-neutral: #374151;
        --border-dark: #c7d0da;
        --buy-info-text: #1769aa;
        --park-buy-text: #326a96;
        --park-sell-text: #8a5517;
        --pager-hover: #e2e8ef;
        --critical-bg: #fee9ed;
        --stale-bg: #fff4d6;
        --cyan-bg: #e7f6f7;
        --cyan-muted-text: #08788a;
        --log-info: #245fb5;
        --border-mid: #aeb9c5;
        --binance-bg: #fff4d6;
        --model-bg: #e8f2fb;
        --model-text: #1769aa;
        --snapshot-bg: #edf1f5;
        --snapshot-text: #374151;
        --stress-bg: #f8e3aa;
        --stress-text: #765000;
        --text-medium: #4b5563;
        --surface-row: #f8fafc;
        --surface-row-alt: #eef2f6;
        --accent-red-border: #c21f3a;
        --mobile-border: #d8e0e8;
        --no-bot-bg: #fff9e9;
        --no-bot-hover: #fff3c8;
        --long-bg: #e4f6ec;
        --short-bg: #fee9ed;
        --error-soft-text: #b4233a;
        --no-bot-border: #b78100;
        --no-bot-text: #8a6100;
        --success-alt: #087a48;
        --mobile-row-border: #d8e0e8;
        --mobile-header-text: #374151;
        --mobile-header-bg: #f4f7fa;
        --mobile-header-border: #c7d0da;
        --warning-border-2: #b78100;
        --warning-bg-2: #fff4d6;
        --warning-text-2: #765000;
        --mobile2-card-bg: #f8fafc;
        --mobile2-source-0: #1769aa;
        --mobile2-source-1: #a65100;
        --mobile2-source-2: #087a48;
        --mobile2-source-3: #6d44b8;
        --mobile2-source-4: #b4233a;
        --mobile2-source-5: #08788a;
        --mobile2-source-6: #765000;
        --mobile2-source-7: #4758a8;
        --danger-deep: #fee9ed;
        --text-gray: #374151;
        --green-banner-bg: #e4f6ec;
        --green-bright: #087a48;
        --history-modal-text: #18202b;
        --history-warning-text: #8a6100;
        --history-warning-border: #a16207;
        --history-danger-border: #b91c1c;
        --row-alt-tint: rgba(89, 101, 121, .08);
        --danger-row-tint: rgba(194, 31, 58, .09);
        --warning-row-tint: rgba(160, 107, 0, .09);
        --warning-cell-tint: rgba(160, 107, 0, .12);
        --danger-cell-tint: rgba(194, 31, 58, .14);
        --warning-cell-strong-tint: rgba(160, 107, 0, .16);
        --danger-unavailable-tint: rgba(194, 31, 58, .10);
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--page-bg);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 20px;
}

.container {
    width: 100%;
    max-width: 480px;
}

/* Bots dashboard widens to use desktop/iPad space; every other page keeps the
   shared 480px column. Scoped via the .bots-page modifier on the container. */
.container.bots-page {
    max-width: 1280px;
}

/* The fleet margin view is intentionally wide: all risk columns remain present
   in one horizontally scrollable semantic table. */
.container.margin-page {
    max-width: none;
}

/* Profit-history fills tablet/desktop width so its wide multi-column table is not
   clipped inside the shared 480px column. Mobile (<768px) keeps the narrow column
   that drives the responsive single-metric table layout. */
@media (min-width: 768px) {
    .container.profit-history-page {
        max-width: none;
    }
}

h1 {
    text-align: center;
    margin-bottom: 24px;
    font-size: 20px;
    color: var(--accent);
}

.card {
    background: var(--surface);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 16px;
}

.card h2 {
    font-size: 16px;
    margin-bottom: 16px;
    color: var(--accent);
}

/* Toggle switch for trading mode */
.mode-toggle {
    display: flex;
    background: var(--surface-control);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 16px;
}

.mode-toggle label {
    flex: 1;
    text-align: center;
    padding: 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s, color 0.2s;
    color: var(--text-muted);
}

.mode-toggle input[type="radio"] {
    display: none;
}

.mode-toggle input[type="radio"]:checked + label {
    background: var(--accent);
    color: var(--page-bg);
}

/* Form rows */
.form-group {
    margin-bottom: 14px;
}

.form-group > label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.form-row {
    display: flex;
    gap: 10px;
}

.form-row .form-group {
    flex: 1;
    /* Flex items default to min-width:auto, which won't shrink a form control
       below its intrinsic (size-based) width — iOS Safari gives inputs a wide
       min, overflowing the row on narrow phones. Allow them to shrink. */
    min-width: 0;
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="date"],
input[type="datetime-local"],
select {
    width: 100%;
    padding: 10px 12px;
    background: var(--surface-control);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

input:focus, select:focus {
    border-color: var(--accent);
}

/* Inline input + select row */
.input-with-select {
    display: flex;
    gap: 8px;
}

.input-with-select input {
    flex: 1;
    min-width: 0;  /* shrink past intrinsic width so the fixed-width select
                      sibling can't push the row past the viewport (iOS h-scroll) */
}

.input-with-select select {
    /* 140px by default, but allowed to shrink (down to a readable floor) when
       the row is tight, so the input + select pair never overflows a narrow
       phone instead of the select hogging a fixed width. */
    flex: 0 1 140px;
    min-width: 96px;
}

/* Read-only info rows */
.info-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 13px;
    border-bottom: 1px solid var(--surface-control);
}

.info-row .info-label {
    color: var(--text-muted);
}

.info-row .info-value {
    color: var(--text-primary);
    font-weight: 500;
}

/* Collapsible section */
.collapsible-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 12px 0;
    user-select: none;
}

.collapsible-header h3 {
    font-size: 14px;
    color: var(--text-muted);
}

.chevron {
    font-size: 12px;
    color: var(--text-muted);
    transition: transform 0.3s;
}

.chevron.open {
    transform: rotate(180deg);
}

.collapsible-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.collapsible-content.open {
    max-height: 800px;
}

/* Checkbox rows */
.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 13px;
}

.checkbox-row input[type="checkbox"] {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
}

.sub-fields {
    margin-left: 24px;
    margin-bottom: 10px;
}

.sub-fields .form-group {
    margin-bottom: 8px;
}

/* Adaptive-stride create block.  All visibility/state changes use classes so
   the create page stays compatible with the style-src 'self' CSP. */
.adaptive-section {
    margin-bottom: 18px;
    padding: 16px;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: var(--surface-alt);
}

.adaptive-section h3 {
    margin: 0 0 6px;
    color: var(--accent);
    font-size: 15px;
}

.adaptive-intro {
    margin: 0 0 14px;
    line-height: 1.45;
}

.adaptive-validation {
    margin: 4px 0 12px;
    padding: 10px 12px;
    border-left: 3px solid var(--danger-solid);
    border-radius: 6px;
    background: var(--danger-bg);
    color: var(--danger-text);
    font-size: 12px;
    line-height: 1.45;
    white-space: pre-line;
}

.adaptive-preview {
    margin-top: 4px;
}

.adaptive-preview-heading {
    margin-bottom: 8px;
    color: var(--text-secondary-strong);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.adaptive-step-basis {
    margin: -2px 0 10px;
    font-size: 11px;
    line-height: 1.4;
}

.adaptive-regime-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.adaptive-regime-card {
    min-width: 0;
    padding: 11px;
    border: 1px solid var(--border-dark);
    border-radius: 8px;
    background: var(--surface-deep-1);
}

.adaptive-regime-title {
    display: flex;
    align-items: center;
    gap: 7px;
    color: var(--text-secondary-strong);
    font-size: 12px;
    font-weight: 600;
}

.adaptive-regime-code {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 5px;
    background: var(--surface-control);
    color: var(--accent);
    font-size: 11px;
}

.adaptive-regime-step {
    margin-top: 8px;
    color: var(--text-primary);
    font-size: 18px;
    font-weight: 650;
}

.adaptive-regime-meta {
    margin-top: 3px;
    color: var(--success-soft-text);
    font-size: 12px;
}

.adaptive-regime-rule,
.adaptive-regime-window {
    margin-top: 7px;
    color: var(--text-muted);
    font-size: 11px;
    line-height: 1.35;
}

.adaptive-regime-window {
    margin-top: 3px;
    color: var(--text-subtle);
}

.adaptive-preview-summary {
    margin-top: 8px;
}

.adaptive-preview-summary .info-row:last-child {
    border-bottom: 0;
}

#vspeed-section.is-locked input {
    cursor: not-allowed;
}

@media (max-width: 480px) {
    .adaptive-section {
        padding: 12px;
    }

    .adaptive-section .form-row,
    .adaptive-regime-grid {
        display: block;
    }

    .adaptive-regime-card {
        margin-bottom: 8px;
    }
}

/* Buttons */
.btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
    margin-bottom: 8px;
}

.btn:hover {
    opacity: 0.85;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    color: var(--page-bg);
    border: 0;
    border-radius: 6px;
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.btn-secondary {
    background: var(--surface-control);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
}

.btn-connect {
    background: var(--success-solid);
    color: #fff;
}

/* Status indicators */
.status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    margin-bottom: 12px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-dot.green {
    background: var(--success-solid);
}

.status-dot.red {
    background: var(--danger-solid);
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Result box */
.result-box {
    background: var(--surface-control);
    border-radius: 6px;
    padding: 12px;
    margin-top: 12px;
    font-size: 13px;
    white-space: pre-wrap;
    word-break: break-all;
}

.result-box.success {
    border-left: 3px solid var(--success-solid);
    color: var(--success-text);
}

.result-box.error {
    border-left: 3px solid var(--danger-solid);
    color: var(--danger-text);
}

/* Divider */
.divider {
    height: 1px;
    background: var(--surface-control);
    margin: 20px 0;
}

/* Radio group */
.radio-group {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
}

.radio-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: pointer;
}

.radio-group input[type="radio"] {
    accent-color: var(--accent);
}

.hidden {
    display: none !important;
}

/* Profit display */
.profit-display {
    font-size: 14px;
    color: var(--success-solid);
    font-weight: 500;
    padding: 8px 0;
}

/* TP/SL mode selector */
.tpsl-mode-selector {
    display: flex;
    background: var(--surface-control);
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 10px;
}

.tpsl-mode-selector label {
    flex: 1;
    text-align: center;
    padding: 8px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-muted);
    transition: background 0.2s;
}

.tpsl-mode-selector input[type="radio"] {
    display: none;
}

.tpsl-mode-selector input[type="radio"]:checked + label {
    background: var(--border-strong);
    color: var(--text-primary);
}

/* Page header with help link */
.page-header {
    position: relative;
    margin-bottom: 24px;
}

.page-header h1 {
    margin-bottom: 0;
}

.help-link {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    font-size: 13px;
    color: var(--text-muted);
    text-decoration: none;
    padding: 6px 12px;
    border: 1px solid var(--surface-control);
    border-radius: 6px;
    transition: color 0.2s, border-color 0.2s;
}

.help-link:hover {
    color: var(--accent);
    border-color: var(--accent);
}

/* Help page (/help) */
.help-container {
    width: 100%;
    max-width: 760px;
    padding: 0 8px;
}

.help-header {
    margin-bottom: 24px;
    text-align: center;
}

.help-back {
    display: inline-block;
    font-size: 13px;
    color: var(--text-muted);
    text-decoration: none;
    margin-bottom: 12px;
}

.help-back:hover {
    color: var(--accent);
}

.help-content {
    background: var(--surface);
    border-radius: 12px;
    padding: 32px 36px;
    font-size: 14px;
    line-height: 1.65;
    color: var(--text-primary);
}

.help-content h1,
.help-content h2,
.help-content h3 {
    color: var(--accent);
    margin-top: 28px;
    margin-bottom: 12px;
    line-height: 1.3;
}

.help-content h1 { font-size: 22px; margin-top: 0; }
.help-content h2 { font-size: 18px; border-bottom: 1px solid var(--surface-control); padding-bottom: 6px; }
.help-content h3 { font-size: 15px; color: var(--text-primary); }

.help-content p {
    margin-bottom: 14px;
}

.help-content ul,
.help-content ol {
    margin: 0 0 14px 22px;
}

.help-content li {
    margin-bottom: 6px;
}

.help-content strong {
    color: var(--accent);
    font-weight: 600;
}

.help-content code {
    background: var(--surface-control);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    color: var(--accent);
}

.help-content pre {
    background: var(--page-bg);
    border: 1px solid var(--surface-control);
    border-radius: 6px;
    padding: 12px;
    overflow-x: auto;
    margin-bottom: 14px;
}

.help-content pre code {
    background: transparent;
    padding: 0;
    color: var(--text-primary);
}

.help-content a {
    color: var(--accent);
    text-decoration: none;
}

.help-content a:hover {
    text-decoration: underline;
}

.help-content blockquote {
    border-left: 3px solid var(--accent);
    padding: 8px 14px;
    margin: 14px 0;
    background: var(--surface-control);
    border-radius: 0 6px 6px 0;
    color: var(--text-secondary);
}

.help-content hr {
    border: none;
    border-top: 1px solid var(--surface-control);
    margin: 24px 0;
}

/* Repository-backed operational-document page. */
.container.documents-page {
    max-width: 1080px;
    min-width: 0;
}

.documents-intro {
    margin: 18px 0 22px;
}

.documents-kicker {
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .09em;
    margin-bottom: 5px;
    text-transform: uppercase;
}

.documents-intro h2 {
    color: var(--text-primary);
    font-size: 24px;
    line-height: 1.25;
    margin: 0 0 7px;
}

.documents-intro > p:last-child {
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.5;
    margin: 0;
}

.document-groups {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.document-group {
    background: var(--surface-deep-1);
    border: 1px solid var(--surface-control);
    border-radius: 12px;
    overflow: hidden;
}

.document-group > summary {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 17px 19px;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.document-group > summary::-webkit-details-marker { display: none; }

.document-group > summary::after {
    content: "›";
    color: var(--text-muted);
    flex: 0 0 auto;
    font-size: 22px;
    line-height: 1;
    transform: rotate(90deg);
    transition: transform .15s ease;
}

.document-group[open] > summary::after { transform: rotate(-90deg); }

.document-group-heading {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.document-group-heading > span {
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 700;
}

.document-group-heading small {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 400;
    line-height: 1.4;
}

.document-group-count {
    min-width: 28px;
    margin-left: auto;
    padding: 3px 8px;
    background: var(--surface-control);
    border-radius: 999px;
    color: var(--text-secondary);
    font-size: 11px;
    text-align: center;
}

.document-group-content {
    padding: 12px;
    background: var(--surface-deep-2);
    border-top: 1px solid var(--surface-control);
}

.document-group-empty {
    color: var(--text-muted);
    font-size: 13px;
    margin: 4px;
}

.doc-summary-path {
    color: var(--text-muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11px;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.document-accordions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.doc-accordion {
    background: var(--surface-deep-3);
    border: 1px solid var(--surface-control);
    border-radius: 10px;
    overflow: hidden;
    scroll-margin-top: 16px;
}

.doc-accordion:target {
    border-color: var(--warning-border);
}

.doc-accordion > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 15px 17px;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.doc-accordion > summary::-webkit-details-marker {
    display: none;
}

.doc-accordion > summary::after {
    content: "›";
    color: var(--text-muted);
    flex: 0 0 auto;
    font-size: 20px;
    line-height: 1;
    transform: rotate(90deg);
    transition: transform .15s ease;
}

.doc-accordion[open] > summary::after {
    transform: rotate(-90deg);
}

.doc-accordion > summary time {
    color: var(--text-muted);
    font-size: 11px;
    margin-left: auto;
    white-space: nowrap;
}

.doc-summary-title {
    display: flex;
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    font-size: 14px;
    font-weight: 650;
    overflow-wrap: anywhere;
}

.doc-accordion > .help-content {
    background: var(--surface);
    border-radius: 0;
    border-top: 1px solid var(--surface-control);
    padding: 28px 32px;
}

.doc-accordion > .help-content table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
}

@media (max-width: 700px) {
    .doc-accordion > summary {
        align-items: flex-start;
        flex-wrap: wrap;
        gap: 7px;
    }

    .doc-accordion > summary time {
        margin-left: 0;
        order: 3;
        width: calc(100% - 32px);
    }

    .doc-accordion > summary::after {
        margin-left: auto;
    }
}

@media (max-width: 480px) {
    .documents-intro h2 { font-size: 20px; }

    .doc-accordion > .help-content {
        padding: 20px 16px;
    }

    .doc-accordion > summary,
    .document-group > summary {
        padding: 13px;
    }

    .document-group-content { padding: 8px; }
}

.help-content table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
    font-size: 13px;
}

.help-content th,
.help-content td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--surface-control);
    text-align: left;
}

.help-content th {
    color: var(--accent);
    font-weight: 600;
    background: var(--surface-control);
}

/* ── Bot console ─────────────────────────────────────────────────── */

.bots-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 10px;
    flex-wrap: wrap;
    position: relative;
}

.bots-header h1 {
    margin: 0;
    margin-right: auto;        /* push the menu toggle to the right edge */
    text-align: left;
    font-size: 22px;
    min-width: 0;
}

/* Hamburger toggle — always visible at all screen sizes. */
.nav-burger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--surface-alt);
    border: 0;
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
}
.nav-burger:active { transform: scale(0.95); }

/* Dropdown menu — hidden until burger is clicked. */
.bots-header-controls {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 200;
    flex-direction: column;
    gap: 2px;
    min-width: 200px;
    max-height: calc(100vh - 88px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 6px;
    background: var(--surface-active);
    border: 1px solid var(--surface-control);
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.bots-header-controls.open { display: flex; }

.nav-environment {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 38px;
    margin-bottom: 4px;
    padding: 0 12px 6px;
    border-bottom: 1px solid var(--surface-control);
}

.nav-environment-label {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

/* Dropdown items — full-width rows with comfortable tap targets. */
.bots-header-controls > a,
.bots-header-controls > button,
.bots-header-controls .btn-link {
    box-sizing: border-box;
    width: 100%;
    min-height: 40px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    border-radius: 7px;
    font-size: 14px;
    white-space: nowrap;
    text-align: left;
    justify-content: flex-start;
}
.bots-header-controls .btn-link { background: transparent; color: var(--text-secondary-strong); }
.bots-header-controls .btn-link:hover,
.bots-header-controls .btn-link:active { background: var(--surface-alt); color: var(--accent); }
.bots-header-controls .is-active { color: var(--accent); font-weight: 600; }
.bots-header-controls #logout-form { display: flex; margin: 0; }
.bots-header-controls a:active,
.bots-header-controls button:active { transform: scale(0.98); }

.network-pill {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    background: var(--surface-control);
    color: var(--text-muted);
}

.network-pill.testnet { background: var(--info-bg); color: var(--info-text); }
.network-pill.mainnet { background: var(--danger-bg); color: var(--danger-text); }
/* The shared nav hydrates this centrally; keep failed/slow loads unobtrusive. */
.network-pill:empty { display: none; }

.btn-link {
    background: transparent;
    border: 0;
    color: var(--text-muted);
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
    padding: 4px 8px;
}

.btn-link:hover { color: var(--accent); }

/* Active nav link — the current page's entry in the unified site-nav. */
.bots-header-controls .is-active { color: var(--accent); }
.bots-header-controls a.is-active { font-weight: 600; }

#logout-form { display: inline; margin: 0; padding: 0; }

.btn-secondary {
    background: var(--surface-control);
    color: var(--text-primary);
    border: 0;
    border-radius: 6px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 13px;
}

.btn-secondary:hover { background: var(--surface-hover); }

/* Top summary row: stacks on phone/iPad-portrait, goes 3-up on desktop (≥1040). */
.bots-top-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-bottom: 16px;
}
.bots-top-row > .card { margin-bottom: 0; }

.bots-summary-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 16px 20px;
}

.bots-summary-label {
    font-size: 12px;
    color: var(--text-muted);
}

.bots-summary-value {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-primary);
}

.bots-summary-value.profit-pos { color: var(--success-text); }
.bots-summary-value.profit-neg { color: var(--danger-text); }

.bots-summary-spot {
    font-size: 13px;
    color: var(--text-muted);
}

.bots-summary-actions {
    display: flex;
    gap: 8px;
}

.fleet-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 28px;   /* row-gap col-gap */
}

.fleet-stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.bots-filters {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    margin-bottom: 12px;
    padding-bottom: 4px;
}

.filter-btn {
    background: transparent;
    border: 0;
    color: var(--text-muted);
    padding: 8px 12px;
    font-size: 14px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}

.filter-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.filter-btn .count {
    margin-left: 4px;
    background: var(--surface-control);
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 11px;
    color: var(--text-primary);
}

.bots-list { display: grid; grid-template-columns: 1fr; gap: 12px; }

.bot-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    cursor: pointer;
    transition: background 0.15s;
}

.bot-card:hover { background: var(--card-hover); }

.bot-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.bot-card-symbol {
    font-size: 16px;
    font-weight: 600;
}

.state-pill {
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.state-pill.active   { background: var(--success-bg); color: var(--success-text); }
.state-pill.inactive { background: var(--surface-control); color: var(--text-muted); }
.state-pill.failed   { background: var(--danger-bg); color: var(--danger-text); }
.state-pill.unknown  { background: var(--surface-control); color: var(--text-muted); }
.state-pill.total    { background: var(--info-bg-strong); color: var(--info-text); }

/* ── Total summary card (inert roll-up; Stage 1) ──────────────────────
   A non-clickable card that sums the running/stopped fleet. Reuses the base
   .bot-card shell; a subtle blue left-accent (the existing var(--info-text) accent)
   distinguishes it, and it overrides the base card's clickable affordances
   (cursor + hover) since it isn't a link. CSP-safe — classes only. */
.bot-card--total {
    cursor: default;
    border-left: 3px solid var(--info-text);
}
.bot-card--total:hover { background: var(--surface); }

.bot-card-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    margin: 4px 0;
}

.bot-card-row .label { color: var(--text-muted); }
.bot-card-row .value { color: var(--text-primary); }
.legacy-backlog-line {
    display: flex;
    flex-direction: column;
    gap: 2px;
    border-left: 3px solid var(--warning-text);
    background: var(--warning-bg);
    border-radius: 6px;
    padding: 7px 9px;
    margin: 6px 0 9px;
    font-size: 12px;
}
.legacy-backlog-label { color: var(--text-primary); font-weight: 700; }
.legacy-backlog-value { color: var(--text-neutral); overflow-wrap: anywhere; }
.legacy-backlog-healthy {
    border-left-color: var(--success-text);
    background: var(--success-bg);
}
.legacy-backlog-unhealthy {
    border-left-color: var(--danger-text);
    background: var(--danger-bg);
}
.value.profit-pos { color: var(--success-text); }
.value.profit-neg { color: var(--danger-text); }

/* Colour key for the "24h / total" pairs (matched profit + matched count):
   24h figure blue, all-time figure green. */
.dual-24h { color: var(--info-text); }
.dual-total { color: var(--success-text); }

/* Grid range: green when the mark is inside [lower, upper], red when outside. */
.value.range-in { color: var(--success-text); }
.value.range-out { color: var(--danger-text); }

/* "↕ extended" pill on a card whose range has grown beyond its config bounds. */
.ext-badge {
    display: inline-block;
    margin-left: 4px;
    padding: 0 5px;
    font-size: 10px;
    font-weight: 600;
    line-height: 15px;
    border-radius: 4px;
    color: var(--info-text);
    background: var(--info-bg-strong);
    vertical-align: middle;
}

.bot-card-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.btn-stop {
    flex: 1;
    background: var(--danger-bg);
    color: var(--danger-text);
    border: 0;
    border-radius: 6px;
    padding: 8px;
    cursor: pointer;
    font-size: 13px;
}

/* ── Margin guardian card row ────────────────────────────────────── */

.bot-card-margin {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 6px 0 2px;
}

/* Cushion badge: green / amber / red / stale */
.cushion-badge {
    padding: 2px 7px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
}

.cushion-badge.cushion-ok    { background: var(--success-bg); color: var(--success-text); }
.cushion-badge.cushion-warn  { background: var(--warning-bg); color: var(--warning-text); }
.cushion-badge.cushion-danger { background: var(--danger-bg); color: var(--danger-text); }
.cushion-badge.cushion-stale { background: var(--surface-control); color: var(--text-muted); }
/* Guardian degraded (#5): REST reads failing — not protecting. */
.cushion-badge.cushion-degraded { background: var(--danger-bg); color: var(--degraded-text); }
/* Variable-speed "slowdown" (amber) + suppressed-levels (blue) — running cards. */
.adaptive-split-line {
    margin: .35rem 0;
    color: var(--muted);
    font-size: .78rem;
    line-height: 1.35;
}

.cushion-badge.vspeed-badge { background: var(--warning-bg); color: var(--vspeed-text); }
.cushion-badge.suppressed-badge { background: var(--info-bg); color: var(--info-text); }
/* Adaptive-stride regime badges: compact N/B/W/E on both card designs and the
   detail header. Fixed bots never render this element. */
.adaptive-regime-badge { font-weight: 700; }
.adaptive-regime-narrow { background: var(--success-bg); color: var(--success-text); }
.adaptive-regime-base { background: var(--info-bg); color: var(--info-text); }
.adaptive-regime-wide { background: var(--warning-bg); color: var(--warning-text); }
.adaptive-regime-emergency { background: var(--danger-bg); color: var(--danger-text); }
/* Suppressed-badge split numbers: green = below mark, red = above mark. Used in
   the fleet card + mobile "⏸ below / above" badge and the detail banner. */
.sup-below { color: var(--success-text); }
.sup-above { color: var(--danger-text); }

/* Guardian chip: small icon badge */
.guardian-chip {
    font-size: 13px;
    line-height: 1;
}

/* ── Binance-style bot card (operator-selectable on /settings) ──────────
   Reuses the base .bot-card shell (bg / radius / padding / hover); adds a
   richer header, a badge row, an out-of-range banner, and a 2-col stats
   grid. CSP-safe — classes only, no inline style= and no JS .style writes. */
.bot-card--binance .bwc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    gap: 8px;
}
.bwc-title { display: flex; align-items: center; gap: 6px; min-width: 0; }
.bwc-symbol { font-size: 16px; font-weight: 600; color: var(--text-primary); }
.bwc-perp {
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    background: var(--surface-control);
    color: var(--text-muted);
}
.bwc-status { display: flex; align-items: center; gap: 6px; flex: none; }
.bwc-chevron { color: var(--text-muted); font-size: 18px; line-height: 1; }

.bwc-badges {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin: 6px 0;
}
.bwc-badge {
    padding: 2px 7px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
    background: var(--surface-control);
    color: var(--text-neutral);
}
.bwc-risk {
    padding: 2px 7px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
}
.bwc-risk-low   { background: var(--success-bg); color: var(--success-text); }
.bwc-risk-med   { background: var(--warning-bg); color: var(--warning-text); }
.bwc-risk-high  { background: var(--danger-bg); color: var(--danger-text); }
.bwc-risk-stale { background: var(--surface-control); color: var(--text-muted); }

.bwc-created { color: var(--text-muted); font-size: 12px; margin: 2px 0 8px; }

.bwc-banner {
    background: var(--warning-bg);
    color: var(--warning-text);
    border-radius: 6px;
    padding: 7px 10px;
    font-size: 12px;
    margin-bottom: 10px;
}

.bwc-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 16px;
}
.bwc-cell { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.bwc-label { color: var(--text-muted); font-size: 11px; }
.bwc-value { color: var(--text-primary); font-size: 13px; font-weight: 500; }
.bwc-value.bwc-pos, .bwc-value.range-in { color: var(--success-text); }
.bwc-value.bwc-neg, .bwc-value.range-out { color: var(--danger-text); }
/* Fleet-card "open // total grids" thresholds: orange once either count passes
   150, red past 180 — a grid extended near the exchange's open-order ceiling. */
.bwc-value.grid-count-warn  { color: var(--orange-text); }
.bwc-value.grid-count-alert { color: var(--danger-text); }

.bwc-actions { display: flex; gap: 8px; margin-top: 12px; }
.bwc-action { flex: 1; }

/* ── Settings: Appearance (theme + card design) ─────────────────────── */
.appearance-section h3 { margin-bottom: 6px; font-size: 14px; color: var(--text-primary); }
.appearance-section-bordered {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--surface-control);
}
.appearance-options { display: flex; flex-wrap: wrap; gap: 10px 18px; margin: 10px 0; }
.appearance-option { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.appearance-option input { accent-color: var(--accent); }

/* Settings save / error banners — styled by id so settings.js only toggles
   .hidden (CSP-safe; no inline style= and no runtime .style writes). */
#save-banner, #save-error { padding: 10px 12px; border-radius: 6px; }
#save-banner { background: var(--success-bg); color: var(--success-text); }
#save-error  { background: var(--danger-bg); color: var(--danger-text); }

/* ── Exit-watch strip ────────────────────────────────────────────────
   A compact strip of dismissible pill rows at the top of /bots, one per
   stopped-bot exit episode. pending=amber, filled=green, verify=red,
   informational=muted. CSP-safe — classes only, no inline style. */
.exit-watch-strip {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}

.exit-watch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 7px 12px;
    border-radius: 8px;
    font-size: 13px;
    border-left: 3px solid transparent;
}

.exit-watch-msg {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.exit-watch-row--pending {
    background: var(--warning-bg);
    color: var(--warning-text);
    border-left-color: var(--warning-text);
}

.exit-watch-row--filled {
    background: var(--success-bg);
    color: var(--success-text);
    border-left-color: var(--success-text);
}

.exit-watch-row--verify {
    background: var(--danger-bg);
    color: var(--danger-text);
    border-left-color: var(--danger-solid);
}

.exit-watch-row--informational {
    background: var(--surface-control);
    color: var(--text-muted);
    border-left-color: var(--text-muted);
}

.exit-watch-dismiss {
    flex: none;
    background: none;
    border: none;
    color: inherit;
    opacity: 0.7;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0 4px;
}

.exit-watch-dismiss:hover { opacity: 1; }

/* ── Account headroom timeline ───────────────────────────────────── */

/* Headroom card: free-margin values on the left, a vertical History / Refill /
   Convert / Transfer button stack on the right; history expands full-width
   below (its top border shows only when expanded — the body carries it). */
.headroom-main {
    display: flex;
    align-items: flex-start;
    gap: 16px;
}
.headroom-values {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1 1 auto;
    min-width: 0;
}
.headroom-asset { display: block; }
.headroom-asset + .headroom-asset { margin-top: 10px; }
.headroom-free { display: block; }
.headroom-thresholds {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin-top: 2px;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 400;
    line-height: 1.4;
}
.headroom-fall {
    display: grid;
    grid-template-columns: minmax(72px, auto) minmax(48px, auto);
    gap: 2px 10px;
    margin-top: 9px;
    padding-top: 8px;
    border-top: 1px solid var(--surface-control);
    font-size: 11px;
}
.headroom-fall-row { display: contents; }
.headroom-fall-scope {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: subgrid;
    padding-top: 4px;
}
.headroom-fall-scope + .headroom-fall-scope {
    margin-top: 4px;
    border-top: 1px solid var(--surface-control);
}
.headroom-fall-scope-id {
    grid-column: 1 / -1;
    overflow-wrap: anywhere;
    color: var(--text-muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 9px;
}
.headroom-fall-label {
    color: var(--text-muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.headroom-fall-value {
    color: var(--text-primary);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-align: right;
}
.headroom-fall-warning {
    grid-column: 1 / -1;
    color: var(--warning-soft-text);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
}
.headroom-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 0 0 auto;
}
.headroom-actions .btn-secondary { white-space: nowrap; text-align: center; }
.headroom-actions .btn-secondary[aria-expanded="true"] { background: var(--surface-hover); color: var(--accent); }

#headroom-timeline {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--surface-control);
}

/* Account-value card — same accordion mechanics as the headroom timeline. */
.equity-card { padding: 16px 20px; }

.equity-toggle {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    color: inherit;
    font: inherit;
    text-align: left;
}

.equity-head {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.equity-value-line {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 10px;
}

.equity-value {
    font-size: 26px;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.equity-change { font-size: 13px; font-weight: 600; }
.equity-change.profit-pos { color: var(--success-text); }
.equity-change.profit-neg { color: var(--danger-text); }
.equity-change-flat { color: var(--text-muted); }

.equity-chev {
    color: var(--text-muted);
    font-size: 12px;
    transition: transform 0.15s;
    flex-shrink: 0;
    margin-top: 4px;
}

.equity-toggle[aria-expanded="true"] .equity-chev { transform: rotate(180deg); }

.equity-breakdown { margin-top: 14px; }

.equity-row {
    display: flex;
    align-items: baseline;
    gap: 12px;
    padding: 5px 0;
    font-size: 13px;
}

.equity-row-val {
    flex: 0 0 auto;
    min-width: 104px;
    text-align: right;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.equity-row-val.profit-pos { color: var(--success-text); }
.equity-row-val.profit-neg { color: var(--danger-text); }

.equity-row-label { color: var(--text-secondary); }

.equity-row-total {
    margin-top: 4px;
    padding-top: 10px;
    border-top: 1px solid var(--border-dark);
    font-size: 14px;
}

.equity-row-total .equity-row-label { color: var(--text-primary); font-weight: 600; }

.equity-summary-divider {
    margin: 12px 0 6px;
    border-top: 1px dashed var(--border-dark);
}

.equity-glossary-link {
    display: block;
    margin-top: 4px;
    font-size: 12px;
}

.equity-coverage-warn {
    margin-top: 10px;
    font-size: 12px;
    color: var(--danger-text);
}

.headroom-timeline-empty {
    color: var(--text-muted);
    font-size: 13px;
    margin: 6px 0 0;
}

.headroom-timeline-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 5px 0;
    border-bottom: 1px solid var(--surface-control);
    font-size: 13px;
}

.headroom-timeline-row:last-child { border-bottom: none; }

.headroom-timeline-ts {
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.headroom-timeline-level {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 11px;
    flex-shrink: 0;
}

.headroom-level-alert { color: var(--danger-text); }
.headroom-level-ok    { color: var(--success-text); }

.headroom-timeline-free {
    color: var(--text-primary);
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 32px;
}

.hidden { display: none !important; }

.ws-status {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--danger-bg);
    color: var(--danger-text);
    padding: 6px 14px;
    border-radius: 14px;
    font-size: 12px;
}

/* ── Bot detail ──────────────────────────────────────────────────── */

.bot-detail-back {
    margin-bottom: 12px;
    font-size: 13px;
}

.bot-detail-back a { color: var(--text-muted); text-decoration: none; }

.bot-detail-header {
    padding: 20px;
}

.bot-detail-title {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.bot-detail-title h1 {
    margin: 0;
    font-size: 22px;
    color: var(--text-primary);
    text-align: left;
}

.bot-detail-badges {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.badge {
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    color: var(--text-muted);
    background: var(--surface-control);
}

.badge.badge-long { background: var(--success-bg); color: var(--success-text); }
.badge.badge-short { background: var(--danger-bg); color: var(--danger-text); }

.bot-detail-meta { color: var(--text-muted); font-size: 12px; }

/* Current market price in the always-visible detail header (right-aligned via
   margin-left:auto in the flex .bot-detail-title row). Painted live by
   fillHeader on every WS snapshot/delta. */
.detail-mark {
    margin-left: auto;
    color: var(--text-primary);
    font-size: 16px;
    font-variant-numeric: tabular-nums;
}

/* Bot-detail slowdown and recovery states are separate: amber means the safety
   slowdown is active; blue means skipped levels remain to be recovered. */
.slowdown-banner,
.suppressed-banner {
    display: inline-block;
    margin-top: 8px;
    padding: 4px 9px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
}

.slowdown-banner {
    background: var(--warning-bg);
    color: var(--warning-text);
}

.suppressed-banner {
    background: var(--info-bg);
    color: var(--info-text);
}

.bot-detail-actions-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
}

.tab-bar {
    display: flex;
    gap: 4px;
    margin: 16px 0;
    overflow-x: auto;
    /* overflow-x:auto coerces overflow-y from visible to auto (CSS spec); with
       .tab-btn's margin-bottom:-1px the content is ~1px taller than the box and
       a spurious vertical scrollbar appears. Pin the y-axis to suppress it
       while keeping the narrow-viewport horizontal fallback. */
    overflow-y: hidden;
    border-bottom: 1px solid var(--surface-control);
}

.tab-btn {
    background: transparent;
    border: 0;
    color: var(--text-muted);
    /* Tightened so all six tabs fit a 440px (iPhone 16 Pro Max) viewport
       without the tab-bar scrolling horizontally. Vertical padding kept for
       the tap target. */
    padding: 10px 9px;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
}

.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-panel { margin-bottom: 16px; }

.kv-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--surface-control);
    font-size: 14px;
}

.kv-row:last-child { border-bottom: 0; }

.kv-row > span:first-child { color: var(--text-muted); }
.kv-value { color: var(--text-primary); font-weight: 500; }

#driver-diagnostics .diagnostic-object-row { align-items: flex-start; }
#driver-diagnostics .diagnostic-object {
    max-width: min(72ch, 70vw);
    overflow-wrap: anywhere;
    white-space: pre-wrap;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 12px;
}

.details-section { padding: 8px 20px; }

.details-subhead {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 8px 0;
}

.details-footer .kv-value {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 12px;
    word-break: break-all;
}

.tp-edit-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 8px;
}
.tp-input { width: 120px; }

/* ── Slowdown (variable-speed) live-edit row ─────────────────────────── */
.vspeed-edit-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    align-items: flex-end;
    margin-top: 8px;
}
.vspeed-field {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 11px;
    color: var(--text-muted);
}
.vspeed-input { width: 72px; }
.vspeed-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-primary);
}
/* Lock reason shown when a slowdown is engaged (edits idle-only). */
.vspeed-lock {
    margin-top: 8px;
    font-size: 12px;
    color: var(--vspeed-text);
}

/* ── Running adaptive-policy editor ─────────────────────────────────── */
.adaptive-preferences-card {
    border-color: color-mix(in srgb, var(--accent) 32%, var(--border-strong));
}
.adaptive-preferences-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}
.adaptive-pref-eligibility {
    flex: 0 0 auto;
    border-radius: 999px;
    padding: 4px 9px;
    background: var(--warning-bg);
    color: var(--vspeed-text);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .35px;
}
.adaptive-pref-eligibility.is-editable {
    background: var(--success-bg);
    color: var(--success-solid);
}
.adaptive-pref-status-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 12px;
}
.adaptive-pref-status-grid > div {
    min-width: 0;
    padding: 9px 10px;
    border: 1px solid var(--surface-hover);
    border-radius: 8px;
    background: var(--surface-control);
}
.adaptive-pref-status-grid span,
.adaptive-pref-digests > div > span:first-child {
    display: block;
    color: var(--text-muted);
    font-size: 11px;
    margin-bottom: 3px;
}
.adaptive-pref-status-grid strong {
    color: var(--text-primary);
    font-size: 13px;
    overflow-wrap: anywhere;
}
.adaptive-pref-digests {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--surface-hover);
    border-radius: 8px;
    margin-bottom: 12px;
}
.adaptive-pref-digests code {
    display: block;
    color: var(--text-secondary-strong);
    font-size: 11px;
    overflow-wrap: anywhere;
}
.adaptive-pref-notice,
.adaptive-pref-warning,
.adaptive-pref-recovery,
.adaptive-pref-outcome {
    border-radius: 8px;
    padding: 10px 12px;
    margin: 10px 0;
    font-size: 12px;
    line-height: 1.5;
}
.adaptive-pref-notice {
    background: var(--warning-bg);
    color: var(--vspeed-text);
}
.adaptive-pref-warning {
    border: 1px solid color-mix(in srgb, var(--danger-solid) 40%, transparent);
    background: color-mix(in srgb, var(--danger-solid) 10%, transparent);
    color: var(--text-primary);
}
.adaptive-pref-recovery {
    border: 1px solid var(--accent);
    background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.adaptive-pref-recovery h3 {
    margin: 0 0 8px;
    color: var(--accent);
    font-size: 14px;
}
.adaptive-pref-recovery-grid {
    display: grid;
    grid-template-columns: 140px minmax(0, 1fr);
    gap: 5px 10px;
}
.adaptive-pref-recovery-grid dt { color: var(--text-muted); }
.adaptive-pref-recovery-grid dd {
    margin: 0;
    overflow-wrap: anywhere;
}
.adaptive-pref-recovery-changes {
    margin: 8px 0 0 18px;
}
.adaptive-pref-fieldset {
    border: 0;
    padding: 0;
    margin: 16px 0 0;
}
.adaptive-pref-fieldset legend {
    width: 100%;
    padding: 12px 0 7px;
    border-top: 1px solid var(--surface-hover);
    color: var(--text-secondary-strong);
    font-size: 12px;
    font-weight: 700;
}
.adaptive-pref-fields {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}
.adaptive-pref-fields label {
    color: var(--text-muted);
    font-size: 11px;
}
.adaptive-pref-fields input {
    width: 100%;
    margin-top: 4px;
}
.adaptive-pref-fieldset:disabled {
    opacity: .68;
}
.adaptive-pref-readonly-note {
    margin-top: 12px;
    color: var(--text-muted);
    font-size: 12px;
}
.adaptive-pref-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 14px;
}
.adaptive-pref-outcome.is-success {
    background: var(--success-bg);
    color: var(--success-solid);
}
.adaptive-pref-outcome.is-rollback,
.adaptive-pref-outcome.is-pending {
    background: var(--warning-bg);
    color: var(--vspeed-text);
}
.adaptive-pref-outcome.is-failure {
    background: color-mix(in srgb, var(--danger-solid) 12%, transparent);
    color: var(--danger-text);
}
.adaptive-pref-modal {
    max-width: 720px;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
}
.adaptive-pref-review-table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0 14px;
    font-size: 12px;
}
.adaptive-pref-review-table th,
.adaptive-pref-review-table td {
    padding: 7px 8px;
    border-bottom: 1px solid var(--surface-hover);
    text-align: left;
    overflow-wrap: anywhere;
}
.adaptive-pref-review-table th {
    color: var(--text-muted);
    font-weight: 600;
}
.adaptive-pref-modal-warning {
    border-left: 3px solid var(--accent);
    padding-left: 10px;
}

@media (max-width: 700px) {
    .adaptive-preferences-head { display: block; }
    .adaptive-pref-eligibility {
        display: inline-block;
        margin-top: 8px;
    }
    .adaptive-pref-status-grid,
    .adaptive-pref-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .adaptive-pref-digests { grid-template-columns: 1fr; }
}

@media (max-width: 430px) {
    .adaptive-pref-status-grid,
    .adaptive-pref-fields { grid-template-columns: 1fr; }
    .adaptive-pref-recovery-grid { grid-template-columns: 1fr; }
}
/* Range-extension live-edit row (mirrors .vspeed-edit-row). */
.extend-edit-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    align-items: flex-end;
    margin-top: 8px;
}
.extend-field {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 11px;
    color: var(--text-muted);
}
.extend-toggle {
    flex-direction: row;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-primary);
}
.extend-input { width: 96px; }
/* Advisory warnings (freeze / exposure / liquidation) returned by the edit.
   pre-line so the JS newline-joined warnings render one per line. */
.extend-warnings {
    margin-top: 8px;
    font-size: 12px;
    color: var(--vspeed-text);
    line-height: 1.5;
    white-space: pre-line;
}

.orders-grid {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 4px 12px;
    font-size: 13px;
}

.orders-grid .order-side { color: var(--text-muted); }
.orders-grid .order-side.buy { color: var(--success-text); }
.orders-grid .order-side.sell { color: var(--danger-text); }
/* Variable-speed suppressed (intentionally-empty) grid slots, drawn inline in
   the ladder: a skipped buy (below mark) is blue, a skipped sell (at/above
   mark) is orange. */
.orders-grid .order-side.skip-buy { color: var(--buy-info-text); }
.orders-grid .order-side.skip-sell { color: var(--orange-text); }
/* Muted price-gap suffix (delta to the closest placed order below) + the
   span-all footnote for any suppressed level outside the config grid range. */
.orders-grid .order-gap { color: var(--text-muted); }
.orders-grid .orders-skip-note { grid-column: 1 / -1; }
/* Current market price, drawn as a full-width divider at its price position in
   the ladder (between the placed buys and sells). Neutral/bright so it reads
   distinctly from the green buys, red sells, blue/orange suppressed, and muted
   parked rows. */
.orders-grid .order-mark-row {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-primary);
    padding: 3px 0;
    border-top: 1px solid var(--surface-control);
    border-bottom: 1px solid var(--surface-control);
    font-variant-numeric: tabular-nums;
}
/* A placed order resting at a recovery-pending (suppressed-buy) level — the
   rung's own buy is still missing; this order is its paired exit. */
.orders-grid .order-recovery-tag { color: var(--orange-text); }

/* Windowed-grid PARKED (shelved, off-exchange) rungs, shown as collapsed
   one-line accordions at the price extremes (far-below-mark buys at the top,
   far-above-mark sells at the bottom). The summary row spans all three columns
   and is a keyboard/click button (role="button"); the caret ▸/▾ is in its text.
   Muted side tint so it reads as "off-exchange, will re-place" — distinct from
   both real orders (bright green/red) and the vspeed skip-* rows (bright
   blue/orange). */
.orders-grid .park-summary {
    grid-column: 1 / -1;
    cursor: pointer;
    color: var(--text-muted);
    user-select: none;
}
.orders-grid .park-summary.park-buy { color: var(--park-buy-text); }
.orders-grid .park-summary.park-sell { color: var(--park-sell-text); }
.orders-grid .park-summary:hover { color: var(--text-primary); }
.orders-grid .park-summary:focus-visible {
    outline: 1px solid var(--buy-info-text);
    outline-offset: 1px;
}
/* Expanded parked rungs: the side colour, muted (dimmer than the skip-* rows)
   to signal off-exchange. */
.orders-grid .order-side.park-buy { color: var(--park-buy-text); }
.orders-grid .order-side.park-sell { color: var(--park-sell-text); }

/* ── Matched-trade history (Binance-style History tab) ──────────────── */
.matched-stat-row {
    display: flex;
    justify-content: space-between;
    padding: 7px 0;
    font-size: 13px;
}
.matched-stat-row > span:first-child { color: var(--text-muted); }
.matched-stat-val { color: var(--text-primary); font-weight: 500; }
.matched-pos { color: var(--success-text); }
.matched-neg { color: var(--danger-text); }
.matched-grid-pill {
    display: inline-block;
    margin-top: 10px;
    padding: 4px 10px;
    background: var(--surface-control);
    border-radius: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}
.matched-note {
    margin-top: 10px;
    font-size: 11px;
    line-height: 1.5;
    color: var(--text-muted);
}
.backtest-prefill-warnings {
    margin-top: 12px;
    padding: 10px 12px;
    border: 1px solid var(--warning-border);
    border-radius: 8px;
    background: var(--warning-bg);
    color: var(--warning-soft-text);
    font-size: 12px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}
.backtest-prefill-warnings ul {
    margin: 4px 0 0;
    padding-left: 18px;
}
.backtest-prefill-warnings li + li {
    margin-top: 4px;
}

/* Adaptive-only History statistics. The entire card stays hidden for fixed
   bots; its body is an accessible, collapsed-by-default accordion. */
.adaptive-history-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border: 0;
    padding: 0;
    background: none;
    color: var(--text-primary);
    font: inherit;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}
.adaptive-history-chevron { color: var(--text-muted); }
.adaptive-history-body {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--surface-control);
}
.adaptive-history-current {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px;
    margin-bottom: 16px;
    font-size: 13px;
}
.adaptive-history-current .adaptive-regime-badge,
.adaptive-history-table .adaptive-regime-badge {
    display: inline-flex;
    min-width: 22px;
    min-height: 22px;
    align-items: center;
    justify-content: center;
    border-radius: 5px;
    padding: 2px 6px;
    font-size: 11px;
    line-height: 1;
}
.adaptive-history-economics { margin-bottom: 18px; }
.adaptive-history-economics h3 {
    margin: 0 0 3px;
    color: var(--text-primary);
    font-size: 13px;
}
.adaptive-history-economics-caption {
    margin: 0 0 8px;
    color: var(--text-muted);
    font-size: 11px;
    line-height: 1.5;
}
.adaptive-history-economics-unavailable {
    padding: 10px;
    border: 1px solid var(--surface-control);
    border-radius: 7px;
    color: var(--text-muted);
    font-size: 12px;
}
.adaptive-history-window + .adaptive-history-window { margin-top: 18px; }
.adaptive-history-window h3 {
    margin: 0 0 8px;
    color: var(--text-primary);
    font-size: 13px;
}
.adaptive-history-table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--surface-control);
    border-radius: 7px;
}
.adaptive-history-table {
    width: 100%;
    min-width: 690px;
    border-collapse: collapse;
    font-size: 12px;
}
.adaptive-history-table th,
.adaptive-history-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--surface-control);
    text-align: right;
    white-space: nowrap;
}
.adaptive-history-table th:first-child,
.adaptive-history-table td:first-child { text-align: left; }
.adaptive-history-table thead th {
    color: var(--text-muted);
    background: var(--surface-header);
    font-weight: 500;
}
.adaptive-history-table tbody th {
    color: var(--text-primary);
    font-weight: 500;
}
.adaptive-history-table tbody tr:last-child th,
.adaptive-history-table tbody tr:last-child td { border-bottom: 0; }
.adaptive-history-switches,
.adaptive-history-coverage,
.adaptive-history-note {
    color: var(--text-muted);
    font-size: 11px;
    line-height: 1.5;
}
.adaptive-history-switches { margin-top: 8px; }
.adaptive-history-switches strong { color: var(--text-primary); }
.adaptive-history-coverage { margin-top: 3px; }
.adaptive-history-note {
    margin-top: 14px;
    padding-top: 10px;
    border-top: 1px solid var(--surface-control);
}

/* History-tab pager (100 rows/page). Prev/Next re-slice the already-fetched
   timeline — the totals above are server-computed over all trades and never
   move between pages. */
.matched-pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 14px 0 4px;
    margin-top: 4px;
    border-top: 1px solid var(--surface-control);
}
.matched-pager-btn {
    background: var(--surface-control);
    border: 0;
    border-radius: 6px;
    padding: 6px 14px;
    color: var(--text-primary);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}
.matched-pager-btn:hover:not(:disabled) { background: var(--pager-hover); }
.matched-pager-btn:disabled { opacity: 0.4; cursor: default; }
.matched-pager-info { color: var(--text-muted); font-size: 12px; white-space: nowrap; }

.matched-list { display: flex; flex-direction: column; }
.matched-row { border-bottom: 1px solid var(--surface-control); }
.matched-row:last-child { border-bottom: 0; }
.matched-row-head {
    width: 100%;
    background: none;
    border: 0;
    padding: 12px 0;
    cursor: pointer;
    text-align: left;
    color: inherit;
    font: inherit;
}
.matched-row-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.matched-date { color: var(--text-primary); font-size: 13px; font-weight: 500; }
.matched-rung { color: var(--text-muted); font-weight: 400; margin-left: 6px; }
/* R14: a lot with no placed paired sell (exit-pending) — amber-warn label. */
.matched-exit-pending { color: var(--accent); font-weight: 500; }
.matched-exit-reason { white-space: normal; }
.matched-ownership-conflict {
  color: var(--danger-solid);
  white-space: normal;
}
.matched-inferred-pairing {
    color: var(--text-muted);
    font-size: 11px;
}
.matched-non-natural-exit,
.matched-sell-missing,
.matched-sell-stale {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}
.matched-non-natural-exit,
.matched-sell-missing { color: var(--danger-solid); background: var(--critical-bg); }
.matched-sell-stale { color: var(--accent); background: var(--stale-bg); }
/* R14: a closed non-grid reduction (flatten/rebalance/recovery/repair) — a muted
   labeled pill so it reads as a labeled closure, not a Matched grid pair. */
.matched-non-grid {
    display: inline-block;
    padding: 1px 6px;
    margin-right: 6px;
    background: var(--surface-control);
    border-radius: 4px;
    font-size: 11px;
    text-transform: capitalize;
    color: var(--text-secondary);
}
/* SPEC §2.9 (laddered open): a marketable grid buy that filled off-grid near the
   mark — a teal-tinted pill so it reads as an entry kind, distinct from the muted
   non-grid exit label. Display-only (the recorded buy_price/profit are honest). */
.matched-ladder-open {
    display: inline-block;
    padding: 1px 6px;
    margin-right: 6px;
    background: var(--cyan-bg);
    border-radius: 4px;
    font-size: 11px;
    color: var(--cyan-muted-text);
}
.matched-chev { color: var(--text-muted); transition: transform 0.15s; font-size: 12px; }
.matched-row.open .matched-chev { transform: rotate(180deg); }
.matched-row-mid {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
}
.matched-row-body { padding: 4px 0 12px; }
.matched-detail { display: flex; flex-direction: column; gap: 2px; }
.md-row {
    display: grid;
    grid-template-columns: 88px 1fr 1fr;
    gap: 8px;
    padding: 3px 0;
    font-size: 12px;
}
.md-label { color: var(--text-muted); }
.md-col { color: var(--text-primary); }
.md-row > .md-col:nth-child(2) { text-align: left; }
.md-row > .md-col:nth-child(3) { text-align: right; }
.md-head .md-col { font-weight: 600; }

.muted { color: var(--text-muted); font-size: 13px; }

/* Create-page price-band hints (live mark + min/max placeable price). The
   .band-warn modifier turns a hint red when the entered range edge falls
   outside the symbol's PERCENT_PRICE band (soft — never blocks create). */
.band-hint, .band-mark { margin-top: 4px; }
.band-warn { color: var(--danger-solid); }

/* ── Logs tab (chronological activity feed) ────────────────────────── */
/* Logs filter accordion — collapsed by default; the body (#log-filters-body)
   is hidden until the toggle is clicked. Mirrors the headroom-timeline
   accordion. The Refresh button lives in the header row so it stays visible
   while the filters are collapsed. No inline styles (CSP). */
.log-filters-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.log-filters-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    color: inherit;
    font: inherit;
    text-align: left;
}
.log-filters-chev {
    color: var(--text-muted);
    font-size: 12px;
    transition: transform 0.15s;
}
.log-filters-toggle[aria-expanded="true"] .log-filters-chev {
    transform: rotate(180deg);
}
#log-filters-body { margin-top: 10px; }
.log-filters-head .btn-link { white-space: nowrap; }

.log-controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.log-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--text-muted);
    flex: 1 1 140px;
}
.log-field input { width: 100%; }
.log-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.log-chip {
    background: var(--surface-control);
    border: 1px solid var(--border-strong);
    color: var(--text-muted);
    padding: 5px 10px;
    font-size: 12px;
    border-radius: 14px;
    cursor: pointer;
    white-space: nowrap;
}
.log-chip.active { color: var(--page-bg); background: var(--accent); border-color: var(--accent); }
.log-chip-all { font-weight: 600; }
.log-utc-note { margin-top: 10px; font-size: 11px; }

.log-list { display: flex; flex-direction: column; }
.log-day-sep {
    font-size: 11px;
    color: var(--text-muted);
    padding: 10px 2px 4px;
    border-bottom: 1px solid var(--surface-control);
    position: sticky;
    top: 0;
    background: var(--surface);
}
.log-row { border-bottom: 1px solid var(--surface-control); }
.log-row:last-child { border-bottom: 0; }
.log-row-head {
    width: 100%;
    background: none;
    border: 0;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 2px;
    text-align: left;
    font-size: 13px;
}
.log-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; background: var(--text-muted); }
.log-dot-buy { background: var(--success-text); }
.log-dot-sell { background: var(--danger-text); }
.log-dot-warn { background: var(--accent); }
.log-dot-bad { background: var(--danger-solid); }
.log-dot-info { background: var(--log-info); }
.log-time { color: var(--text-muted); flex: 0 0 auto; font-variant-numeric: tabular-nums; }
.log-label { flex: 0 0 auto; font-weight: 600; }
.log-summary {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-secondary);
}
.log-chev { flex: 0 0 auto; color: var(--text-muted); font-size: 12px; transition: transform 0.15s; }
.log-row.open .log-chev { transform: rotate(180deg); }
.log-row-body { padding: 2px 2px 12px; }
.log-row-body.hidden { display: none; }
.log-kv {
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 8px;
    padding: 2px 0;
    font-size: 12px;
}
.log-kv-label { color: var(--text-muted); }
.log-kv-val { color: var(--text-primary); word-break: break-all; }
.log-sentinel { height: 1px; }
.log-end { text-align: center; padding: 12px 0; font-size: 12px; }

/* ── Modal ──────────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.65);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
}

.modal {
    background: var(--surface);
    border-radius: 12px;
    padding: 24px;
    width: calc(100% - 32px);
    max-width: 400px;
}

.modal h2 { font-size: 18px; margin-bottom: 12px; color: var(--accent); }
.modal p { font-size: 13px; color: var(--text-primary); margin-bottom: 12px; line-height: 1.5; }
.modal .modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal input[type=text] {
    width: 100%;
    background: var(--surface-control);
    border: 1px solid var(--surface-hover);
    color: var(--text-primary);
    padding: 8px 10px;
    border-radius: 6px;
    margin: 8px 0;
}
/* Reconcile-stale-sibling modal (create-failure recovery). Wider + scrollable
   body since it can list several siblings' local-vs-exchange rows. */
.recon-modal { max-width: 520px; }
.recon-body { max-height: 60vh; overflow-y: auto; }
.recon-bot {
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--surface-control);
}
.recon-bot:last-child { border-bottom: none; margin-bottom: 4px; }
.recon-confirm { margin-top: 8px; }
.recon-btn { margin-top: 4px; }
.stale-warn { color: var(--accent); font-size: 13px; margin-top: 8px; line-height: 1.5; }
.recon-done { color: var(--success-solid); font-size: 13px; margin-top: 8px; }
.reconcile-change-list {
    margin: 6px 0 12px 20px;
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.6;
}
.reconcile-order-list { margin: 12px 0; }
.reconcile-order-row {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) 1fr 1fr;
    gap: 8px;
    padding: 5px 0;
    border-bottom: 1px solid var(--surface-control);
    color: var(--text-secondary-strong);
    font-size: 12px;
}
.reconcile-order-row code { overflow-wrap: anywhere; }
.reconcile-order-row span { text-align: right; }
.reconcile-diff { margin: 12px 0; font-size: 12px; }
.reconcile-diff-head,
.reconcile-diff-row {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) 1fr 1fr;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid var(--surface-control);
}
.reconcile-diff-head { color: var(--text-muted); font-weight: 600; }
.reconcile-diff-head span:not(:first-child),
.reconcile-diff-row span:not(:first-child) { text-align: right; }
.reconcile-diff-row.changed { color: var(--accent); }

@media (max-width: 560px) {
    .reconcile-order-row { grid-template-columns: 1fr; }
    .reconcile-order-row span { text-align: left; }
}

.modal-list { margin: 8px 0 12px 24px; font-size: 13px; color: var(--text-primary); }
.modal-subhead { font-size: 12px; font-weight: 600; color: var(--text-muted); margin: 4px 0; text-transform: uppercase; letter-spacing: .3px; }
.modal-note { font-size: 13px; color: var(--text-muted); margin: 8px 0 12px; font-style: italic; }

/* Stop-bot wind-down chooser (5 compact radio modes + explanations on demand). */
.stop-modes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 4px; }
.stop-mode {
    position: relative;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) 36px;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 6px 8px 6px 10px;
    border: 1px solid var(--surface-hover);
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}
.stop-mode:hover,
.stop-mode:focus-within { z-index: 2; }
.stop-mode input[type=radio] { margin: 0; }
.stop-mode-title {
    min-width: 0;
    cursor: pointer;
    line-height: 1.3;
}
.stop-mode-info {
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--text-muted);
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary-strong);
    cursor: help;
    font: 700 13px/1 system-ui, sans-serif;
}
.stop-mode-info:hover,
.stop-mode-info:focus-visible,
.stop-mode-info[aria-expanded="true"] {
    border-color: var(--accent);
    color: var(--accent);
    outline: none;
}
.stop-mode-info:focus-visible { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.stop-mode-tooltip {
    position: absolute;
    top: calc(100% - 2px);
    right: 8px;
    width: min(320px, calc(100vw - 64px));
    padding: 9px 10px;
    border: 1px solid var(--surface-hover);
    border-radius: 6px;
    background: var(--surface-control);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
    color: var(--text-primary);
    font-size: 12px;
    font-weight: 400;
    line-height: 1.45;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-2px);
    transition: opacity 0.12s ease, transform 0.12s ease, visibility 0.12s;
}
.stop-mode:nth-last-child(-n+2) .stop-mode-tooltip {
    top: auto;
    bottom: calc(100% - 2px);
    transform: translateY(2px);
}
.stop-mode-info:hover:not([data-tooltip-dismissed]) + .stop-mode-tooltip,
.stop-mode-info:focus-visible:not([data-tooltip-dismissed]) + .stop-mode-tooltip,
.stop-mode-info[aria-expanded="true"] + .stop-mode-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.stop-bps-row, .stop-confirm-row { margin-top: 12px; }
.stop-bps-row label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.stop-bps-row input[type=number] {
    width: 120px;
    background: var(--surface-control);
    border: 1px solid var(--surface-hover);
    color: var(--text-primary);
    padding: 8px 10px;
    border-radius: 6px;
}

/* Convert (USDT↔USDC) modal — FROM/TO picker, amount, quote echo + countdown. */
.convert-row {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    margin-bottom: 12px;
}
.convert-asset-pick {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--text-muted);
}
.convert-asset-pick select,
.convert-asset-pick input[type=number] {
    background: var(--surface-control);
    border: 1px solid var(--surface-hover);
    color: var(--text-primary);
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 14px;
}
.convert-to {
    font-size: 13px;
    color: var(--text-muted);
    padding-bottom: 8px;
}
.convert-to strong { color: var(--text-primary); }
.convert-quote {
    border: 1px solid var(--surface-hover);
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 12px;
}
.convert-quote p { margin-bottom: 6px; }
.convert-countdown { color: var(--accent); font-weight: 600; }
.convert-warn {
    border: 1px solid var(--danger-solid);
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--danger-solid);
    line-height: 1.5;
}

/* Transfer modal (Spot ⇄ Futures) — mirrors the .convert-* rules. CSP-safe. */
.transfer-row {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    margin-bottom: 12px;
}
.transfer-asset-pick {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--text-muted);
}
.transfer-asset-pick select,
.transfer-asset-pick input[type=number] {
    background: var(--surface-control);
    border: 1px solid var(--surface-hover);
    color: var(--text-primary);
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 14px;
}
.transfer-warn {
    border: 1px solid var(--danger-solid);
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--danger-solid);
    line-height: 1.5;
}

/* Manual cushion refill: compact, scrollable fleet table + replacing confirm. */
.refill-modal { max-width: 760px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.refill-table-scroll { overflow: auto; max-height: 58vh; border: 1px solid var(--surface-hover); border-radius: 6px; }
.refill-table { width: 100%; min-width: 650px; border-collapse: separate; border-spacing: 0; font-size: 12px; }
.refill-table th, .refill-table td { padding: 7px 8px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--surface-control); background: var(--surface); }
.refill-table thead th { position: sticky; top: 0; z-index: 2; color: var(--text-muted); background: var(--surface-header); }
.refill-table th:first-child { position: sticky; left: 0; z-index: 1; min-width: 108px; box-shadow: 1px 0 var(--surface-hover); }
.refill-table thead th:first-child { z-index: 3; background: var(--surface-header); }
.refill-table tbody tr:last-child th, .refill-table tbody tr:last-child td { border-bottom: 0; }
.refill-row-btn { padding: 5px 9px; font-size: 12px; }
.refill-footer { flex: 0 0 auto; }
.refill-confirm-body { overflow-y: auto; max-height: 58vh; }
.refill-asset-block { border: 1px solid var(--surface-hover); border-radius: 6px; padding: 12px; margin-bottom: 10px; }
.refill-asset-block dl { display: grid; grid-template-columns: minmax(110px, 1fr) auto; gap: 5px 12px; margin-top: 8px; font-size: 13px; }
.refill-asset-block dt { color: var(--text-muted); }
.refill-asset-block dd { margin: 0; text-align: right; }
.refill-allowed { color: var(--success-solid) !important; margin: 10px 0 0 !important; }
.refill-critical, .refill-error { color: var(--danger-solid) !important; }

@media (max-width: 600px) {
    .refill-modal { padding: 16px; width: calc(100% - 16px); }
    .refill-table-scroll, .refill-confirm-body { max-height: 65vh; }
}

/* Open Positions modals (Close + TP/SL) — Stage 6. Classes only (CSP). */
.modal select {
    width: 100%;
    background: var(--surface-control);
    border: 1px solid var(--surface-hover);
    color: var(--text-primary);
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 14px;
}
.pos-modal-rows, .pos-modal-tpsl { margin: 4px 0 4px; }
.pos-modal-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    padding: 6px 0;
    font-size: 13px;
    border-bottom: 1px solid var(--surface-control);
}
.pos-modal-row:last-child { border-bottom: none; }
.pos-modal-row .label { color: var(--text-muted); }
.pos-modal-row .value { color: var(--text-primary); text-align: right; }
.pos-modal-leg {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}
.pos-modal-leg .label { font-size: 12px; color: var(--text-muted); }
.pos-modal-leg-inputs {
    display: flex;
    gap: 8px;
    align-items: center;
}
.pos-modal-leg-inputs input[type=text] { flex: 1 1 auto; margin: 0; }
.pos-modal-source { flex: 0 0 92px; width: 92px; }

/* ── Toast (transient bottom-center notice; click or auto-dismiss) ──── */
.toast {
    position: fixed;
    left: 50%;
    /* Lift above the iOS home indicator / Safari bottom chrome so the toast
       isn't clipped on iPhone; env() resolves to 0 on desktop. */
    bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
    transform: translateX(-50%) translateY(12px);
    background: var(--surface-control);
    color: var(--text-primary);
    border: 1px solid var(--surface-hover);
    border-left: 3px solid var(--success-solid);   /* green accent — success */
    padding: 12px 18px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.4;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
    max-width: calc(100% - 32px);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 200;                     /* above .modal-overlay (100) */
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-error { border-left-color: var(--danger-solid); }

/* Inline loading spinner (e.g. a button mid-action) + disabled affordance. */
.spinner {
    display: inline-block;
    width: 13px;
    height: 13px;
    margin-right: 7px;
    vertical-align: -2px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.btn-primary:disabled, .btn-secondary:disabled { opacity: 0.65; cursor: progress; }

/* ── Backtest fills table ────────────────────────────────────────── */

.fills-grid {
    display: grid;
    grid-template-columns: repeat(9, auto);
    gap: 6px 12px;
    font-size: 13px;
}

.fills-pager {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
}

.fills-pager .page-label {
    padding: 6px 8px;
}

.run-status-spacer {
    margin-top: 8px;
}

/* ── Backtest history list ───────────────────────────────────────── */

.container.backtest-history-page {
    max-width: 1280px;
}

.history-grid {
    display: flex;
    flex-direction: column;
    min-width: 0;
    font-size: 13px;
}

.history-grid-header,
.history-run {
    display: grid;
    grid-template-columns:
        40px
        minmax(142px, 1.1fr)
        minmax(78px, .65fr)
        minmax(158px, 1.25fr)
        minmax(88px, .7fr)
        minmax(162px, 1.25fr)
        minmax(76px, .6fr)
        minmax(190px, 1.5fr)
        64px;
    column-gap: 14px;
    align-items: center;
}

.history-grid-header {
    padding: 0 8px 10px;
    border-bottom: 1px solid var(--surface-control);
    font-size: 12px;
}

.history-run {
    min-width: 0;
    padding: 11px 8px;
    border-bottom: 1px solid var(--surface-control);
    transition: background-color .15s ease;
}

.history-run:last-child {
    border-bottom: 0;
}

.history-run:hover,
.history-run:focus-within {
    background: var(--card-hover);
}

.history-cell {
    min-width: 0;
    overflow-wrap: anywhere;
}

.history-download {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 16px;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.history-download:hover,
.history-download:focus-visible {
    color: var(--accent);
    background: var(--surface-control);
    outline: none;
}

.history-download-cell {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 40px;
}

.imported-badge-mini {
    margin-right: 4px;
}

.history-row-link {
    color: var(--text-primary);
    text-decoration: none;
    padding: 5px 0;
    border-bottom: 1px solid transparent;
}

.history-row-link:hover {
    border-bottom-color: var(--surface-control);
}

.history-status {
    white-space: nowrap;
}

.compare-cb-cell {
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 40px;
    min-height: 40px;
}

.compare-cb-cell input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
}

.history-pagination {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

@media (max-width: 1199px) {
    .history-card {
        padding: 0;
        background: transparent;
    }

    .history-grid {
        gap: 12px;
    }

    .history-grid-header {
        display: none;
    }

    .history-run {
        grid-template-columns: 40px minmax(0, .85fr) minmax(0, 1.3fr) auto;
        grid-template-areas:
            "select symbol driver status"
            "select source driver actions"
            "select started period period"
            "select matched matched matched";
        gap: 8px 18px;
        padding: 16px;
        border: 1px solid var(--surface-control);
        border-radius: 12px;
        background: var(--surface);
    }

    .history-run:last-child {
        border-bottom: 1px solid var(--surface-control);
    }

    .compare-cb-cell { grid-area: select; align-self: stretch; }
    .history-started { grid-area: started; }
    .history-source { grid-area: source; }
    .history-driver { grid-area: driver; }
    .history-symbol { grid-area: symbol; }
    .history-span { grid-area: period; }
    .history-status { grid-area: status; }
    .history-matched { grid-area: matched; }
    .history-download-cell { grid-area: actions; }

    .history-cell[data-label]::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 3px;
        color: var(--text-muted);
        font-size: 10px;
        font-weight: 600;
        letter-spacing: .05em;
        line-height: 1.2;
        text-transform: uppercase;
    }

    .history-symbol {
        font-size: 15px;
        font-weight: 650;
    }

    .history-status::before,
    .history-download-cell::before {
        display: none !important;
    }

    .history-row-link {
        padding: 0;
        border-bottom: 0;
    }

    .history-row-link:hover {
        border-bottom-color: transparent;
    }

    .history-download-cell {
        justify-content: flex-end;
    }
}

@media (max-width: 640px) {
    .history-run {
        grid-template-columns: 44px minmax(0, 1fr) auto;
        grid-template-areas:
            "select symbol status"
            "select source actions"
            "driver driver driver"
            "started started started"
            "period period period"
            "matched matched matched";
        gap: 7px 10px;
        padding: 14px;
    }

    .history-driver,
    .history-started,
    .history-span,
    .history-matched {
        display: grid;
        grid-template-columns: 72px minmax(0, 1fr);
        gap: 8px;
        align-items: baseline;
    }

    .history-driver {
        margin-top: 4px;
        padding-top: 10px;
        border-top: 1px solid var(--surface-control);
    }

    .history-matched {
        padding-top: 8px;
        border-top: 1px solid var(--surface-control);
    }

    .history-driver::before,
    .history-started::before,
    .history-span::before,
    .history-matched::before {
        margin-bottom: 0 !important;
    }

    .history-source::before {
        display: inline !important;
        margin: 0 5px 0 0 !important;
    }

    .history-source {
        color: var(--text-secondary);
        font-size: 12px;
    }

    .history-status {
        align-self: start;
        padding-top: 1px;
    }

    .history-download-cell {
        min-width: 40px;
    }

    .history-pagination {
        flex-wrap: wrap;
    }

    .history-pagination .btn-link {
        min-height: 40px;
        display: inline-flex;
        align-items: center;
    }
}

/* Sticky action bar — only visible when 1+ runs are checkbox-selected. */
.compare-bar {
    position: sticky;
    bottom: 16px;
    margin-top: 16px;
    background: var(--surface);
    border-radius: 12px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.compare-bar .btn-primary.disabled {
    opacity: 0.5;
    pointer-events: none;
}

@media (max-width: 640px) {
    .compare-bar {
        bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        flex-wrap: wrap;
        gap: 10px;
        padding: 12px;
    }

    .compare-bar > .btn-link {
        flex-basis: 100%;
    }
}

/* ── Backtest compare ────────────────────────────────────────────── */

.compare-varies {
    margin-top: 6px;
}

.compare-grid {
    display: grid;
    grid-template-columns: auto auto auto auto auto auto;
    gap: 6px 16px;
    font-size: 13px;
    align-items: center;
}

.compare-best {
    background: var(--success-bg);
    border-radius: 4px;
    padding: 2px 6px;
}

.compare-swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    margin-right: 6px;
    vertical-align: middle;
}

.compare-warnings > div {
    margin-bottom: 4px;
}

.compare-warnings code {
    background: var(--surface-control);
    padding: 1px 4px;
    border-radius: 3px;
}

/* ── Backtest result page: notes + imported badge ──────────────── */

.container.backtest-result-page {
    max-width: 1280px;
}

#comparison-table {
    table-layout: fixed;
}

#fills-table {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
}

#comparison-table th,
#comparison-table td {
    overflow-wrap: anywhere;
    vertical-align: top;
}

#comparison-table th:nth-child(1) { width: 30%; }
#comparison-table th:nth-child(2) { width: 23%; }
#comparison-table th:nth-child(3) { width: 20%; }
#comparison-table th:nth-child(4) { width: 27%; }

.comparison-cell-value {
    min-width: 0;
}

.comparison-cell-value > .muted {
    margin-top: 3px;
    line-height: 1.35;
}

@media (max-width: 640px) {
    #comparison-card {
        padding: 16px;
    }

    #comparison-table {
        display: block;
        width: 100%;
        margin-top: 14px;
        margin-bottom: 0;
        font-size: 13px;
    }

    #comparison-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    #comparison-table tbody {
        display: grid;
        width: 100%;
        gap: 12px;
    }

    #comparison-table .comparison-row {
        display: block;
        min-width: 0;
        overflow: hidden;
        border: 1px solid var(--surface-control);
        border-radius: 10px;
        background: var(--surface-alt);
    }

    #comparison-table .comparison-row > .comparison-metric {
        display: block;
        width: 100%;
        padding: 11px 13px;
        border-bottom: 1px solid var(--surface-control);
        background: var(--surface-control);
        font-size: 14px;
        line-height: 1.35;
    }

    #comparison-table .comparison-value-cell {
        display: grid;
        grid-template-columns: minmax(88px, .75fr) minmax(0, 1.25fr);
        width: 100%;
        gap: 12px;
        align-items: start;
        padding: 10px 13px;
        border-bottom: 1px solid var(--surface-control);
        background: transparent;
    }

    #comparison-table .comparison-value-cell:last-child {
        border-bottom: 0;
    }

    #comparison-table .comparison-value-cell::before {
        content: attr(data-label);
        color: var(--text-muted);
        font-size: 10px;
        font-weight: 650;
        letter-spacing: .05em;
        line-height: 1.4;
        text-transform: uppercase;
    }

    #comparison-table .comparison-cell-value {
        min-width: 0;
        overflow-wrap: anywhere;
        line-height: 1.4;
    }
}

.result-header-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.result-meta {
    margin-top: 4px;
}

.result-actions {
    margin-top: 12px;
}

.imported-badge {
    background: var(--info-bg);
    color: var(--info-text);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.notes-textarea {
    width: 100%;
    background: var(--page-bg);
    color: var(--text-primary);
    border: 1px solid var(--surface-control);
    border-radius: 6px;
    padding: 8px;
    font-family: inherit;
    font-size: 13px;
    resize: vertical;
}

.notes-textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.notes-status {
    margin-top: 6px;
}

/* ── Guardian tab ────────────────────────────────────────────────── */

.guardian-stale-note {
    font-size: 12px;
    color: var(--warning-text);
    margin-top: 8px;
}

.guardian-actions-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.guardian-action-log {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.guardian-action-row {
    display: grid;
    grid-template-columns: auto auto 1fr auto;
    gap: 4px 10px;
    padding: 6px 0;
    border-bottom: 1px solid var(--surface-control);
    font-size: 12px;
    align-items: start;
}

.guardian-action-row:last-child { border-bottom: 0; }

.guardian-action-kind {
    font-weight: 600;
    color: var(--text-primary);
}

.guardian-action-amount {
    color: var(--success-text);
    font-weight: 500;
}

.guardian-action-detail { color: var(--text-muted); }

.guardian-settings-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 2px 12px;
    font-size: 13px;
}

.guardian-settings-key { color: var(--text-muted); padding: 4px 0; }
.guardian-settings-val { color: var(--text-primary); font-weight: 500; padding: 4px 0; text-align: right; }

.guardian-refresh-section { margin-top: 12px; }

.guardian-mode-control {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.guardian-mode-select {
    flex: 1;
    background: var(--surface-control);
    color: var(--text-primary);
    border: 1px solid var(--border-mid);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 13px;
}

.guardian-mode-save {
    white-space: nowrap;
}

.guardian-mode-warning {
    font-size: 12px;
    margin-top: 4px;
    margin-bottom: 8px;
}

.guardian-inactive-banner {
    background: var(--surface-control);
    color: var(--text-muted);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 12px;
    margin-bottom: 10px;
}

.guardian-config-error-banner {
    background: var(--warning-bg);
    color: var(--warning-text);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 12px;
    margin-bottom: 10px;
}

.guardian-adoption-banner {
    background: var(--info-bg);
    color: var(--info-text);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 12px;
    margin-top: 8px;
}

.guardian-warm-restart-row {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
    margin-top: 10px;
}

.guardian-warm-restart-row .btn-secondary {
    min-height: 38px;
}

.guardian-warm-restart-note {
    font-size: 11px;
    text-align: right;
}

.guardian-mode-help {
    font-size: 11px;
    margin-top: 2px;
    margin-bottom: 6px;
}

.guardian-projection-card.is-refreshing {
    opacity: .78;
}

.guardian-projection-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.guardian-projection-head .muted { font-size: 11px; }

.guardian-projection-warnings,
.guardian-projection-error {
    margin: 8px 0;
    padding: 8px 10px;
    border-radius: 6px;
    background: var(--warning-bg);
    color: var(--warning-soft-text);
    font-size: 12px;
}

.guardian-projection-cache-note {
    margin: 8px 0;
    padding: 8px 10px;
    border: 1px solid var(--warning-border);
    border-radius: 6px;
    background: var(--warning-bg);
    color: var(--warning-soft-text);
    font-size: 12px;
}

.guardian-projection-groups {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.guardian-projection-group {
    border-top: 1px solid var(--surface-control);
    padding-top: 8px;
}

.guardian-projection-group:first-child { border-top: 0; }

.guardian-projection-group-label {
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    margin-bottom: 2px;
}

.guardian-projection-row {
    display: grid;
    grid-template-columns: minmax(230px, 1fr) auto;
    column-gap: 12px;
    padding: 7px 8px;
    border-radius: 6px;
}

.guardian-projection-row:nth-child(even) { background: var(--row-alt-tint); }
.guardian-projection-row-danger { background: var(--danger-row-tint) !important; }
.guardian-projection-row-warning { background: var(--warning-row-tint) !important; }
.guardian-projection-row-cached {
    border-left: 3px solid var(--warning-text);
    background: var(--warning-cell-tint) !important;
}

.guardian-projection-label,
.guardian-projection-main {
    display: flex;
    align-items: center;
    gap: 7px;
}

.guardian-projection-main { justify-content: flex-end; }

.guardian-projection-value {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    text-align: right;
}

.guardian-projection-secondary {
    grid-column: 1 / -1;
    color: var(--text-muted);
    font-size: 11px;
    margin-top: 3px;
}

.projection-source {
    display: inline-flex;
    align-items: center;
    border-radius: 3px;
    padding: 1px 5px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .04em;
}

.projection-source-binance { background: var(--binance-bg); color: var(--accent); }
.projection-source-model { background: var(--model-bg); color: var(--model-text); }
.projection-source-snapshot { background: var(--snapshot-bg); color: var(--snapshot-text); }

.projection-cache-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 3px;
    padding: 1px 5px;
    background: var(--stress-bg);
    color: var(--stress-text);
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .04em;
}

.projection-info-button {
    width: 18px;
    height: 18px;
    padding: 0;
    border: 1px solid var(--text-subtle);
    border-radius: 50%;
    background: transparent;
    color: var(--text-medium);
    font: 600 11px/16px inherit;
    cursor: pointer;
}

.projection-info-button:hover,
.projection-info-button:focus-visible {
    border-color: var(--accent);
    color: var(--accent);
    outline: none;
}

.projection-info-popover {
    position: fixed;
    z-index: 1000;
    right: 20px;
    bottom: 20px;
    width: min(420px, calc(100vw - 32px));
    max-height: min(520px, calc(100vh - 40px));
    overflow: auto;
    padding: 16px;
    border: 1px solid var(--text-subtle);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text-primary);
    box-shadow: 0 14px 48px rgba(0, 0, 0, .55);
    font-size: 13px;
}

.projection-info-popover p { margin: 10px 0; line-height: 1.45; }
.projection-info-popover a { display: inline-block; margin-top: 12px; color: var(--info-text); }

.projection-info-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.projection-info-close {
    border: 0;
    background: transparent;
    color: var(--text-primary);
    font-size: 22px;
    cursor: pointer;
}

.projection-info-formula,
.projection-info-substitution {
    padding: 8px 10px;
    border-radius: 5px;
    background: var(--page-bg);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11px;
    overflow-wrap: anywhere;
}

.projection-info-substitution { margin-top: 7px; color: var(--text-secondary); }
.projection-cache-detail {
    margin-top: 9px;
    padding: 9px 10px;
    border: 1px solid var(--warning-border);
    border-radius: 5px;
    background: var(--warning-bg);
    color: var(--warning-soft-text);
    line-height: 1.4;
}
.guardian-projection-readme,
.margin-page > p a {
    display: inline-block;
    margin-top: 12px;
    color: var(--info-text);
    font-size: 12px;
}

@media (max-width: 640px) {
    .guardian-projection-row { grid-template-columns: 1fr; }
    .guardian-projection-main { justify-content: flex-start; margin-top: 3px; }
    .projection-info-popover { right: 16px; bottom: 16px; }
}

/* ── Fleet margin projection table ───────────────────────────────── */

.margin-page-intro {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 20px;
    margin: 18px 0 12px;
}

.margin-page-intro h2,
.margin-page-intro p { margin: 0; }
.margin-page-intro p { margin-top: 5px; }

.margin-resilience-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 12px;
}

.margin-resilience-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 34px;
    padding: 7px 10px;
    border: 1px solid var(--surface-hover);
    border-radius: 7px;
    background: var(--surface-row);
    color: var(--text-primary);
    cursor: pointer;
    font: inherit;
    font-size: 12px;
}

.margin-resilience-button:hover,
.margin-resilience-button:focus-visible {
    border-color: var(--accent);
    outline: none;
}

.margin-resilience-label { color: var(--text-medium); }
.margin-resilience-value {
    color: #fff;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.margin-resilience-warning {
    color: var(--warning-soft-text);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
}

.margin-page-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
}

.margin-filter-label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 11px;
}

.margin-filter-label input {
    width: 150px;
    min-height: 32px;
    padding: 5px 8px;
}

.margin-table-wrap {
    position: relative;
    max-width: 100%;
    /* Keep the header in view while the fleet rows scroll.  The vh fallback
       covers older Safari; dvh tracks the usable iPad viewport as browser
       chrome expands and collapses. */
    max-height: calc(100vh - 150px);
    max-height: calc(100dvh - 150px);
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    border: 1px solid var(--surface-control);
    border-radius: 8px;
}

.margin-table {
    width: 100%;
    min-width: 960px;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 11px;
}

.margin-table th,
.margin-table td {
    padding: 7px 6px;
    border-right: 1px solid var(--surface-control);
    border-bottom: 1px solid var(--surface-control);
    background: var(--surface-row);
    text-align: left;
    vertical-align: top;
}

.margin-table th {
    position: sticky;
    top: 0;
    z-index: 4;
    background: var(--surface-row-alt);
    color: var(--text-primary);
}

.margin-table tbody tr:last-child td { border-bottom: 0; }
.margin-table th:last-child,
.margin-table td:last-child { border-right: 0; }

.margin-col-bot { width: 66px; overflow-wrap: anywhere; }
.margin-col-symbol { width: 73px; overflow-wrap: anywhere; }
.margin-col-context { width: 70px; }
.margin-col-current-binance-liquidation { width: 88px; }
.margin-col-modeled-current-liquidation { width: 101px; }
.margin-col-effective-margin { width: 87px; }
.margin-col-no-refill-live-floor { width: 91px; }
.margin-col-no-refill-extension-floor { width: 91px; }
.margin-col-next-refill-price { width: 79px; }
.margin-col-refill-required { width: 82px; }
.margin-col-post-refill-extension-floor { width: 96px; }

.margin-table .margin-col-sticky { position: sticky; z-index: 3; }
.margin-table th.margin-col-sticky { z-index: 6; }
.margin-col-sticky-1 { left: 0; }
.margin-col-sticky-2 { left: 66px; }

.margin-table td.margin-col-sticky-1 > a {
    color: #fff;
}

.margin-header-label {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 5px;
    font-weight: 600;
    margin-bottom: 4px;
}

.margin-cell-button {
    display: flex;
    width: 100%;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
    font: inherit;
    font-variant-numeric: tabular-nums;
}

.margin-cell-primary {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    max-width: 100%;
}

.margin-inline-info {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border: 1px solid var(--text-subtle);
    border-radius: 50%;
    color: var(--text-medium);
    font-size: 9px;
    font-weight: 700;
    line-height: 12px;
}

.margin-cell-button:hover .margin-inline-info,
.margin-cell-button:focus-visible .margin-inline-info {
    border-color: var(--accent);
    color: var(--accent);
}

.margin-cell-button:hover > span:first-child,
.margin-cell-button:focus-visible > span:first-child { color: var(--accent); }
.margin-cell-button:focus-visible { outline: 1px solid var(--accent); outline-offset: 3px; }

.margin-cell-secondary {
    display: block;
    max-width: 220px;
    color: var(--text-muted);
    font-size: 10px;
    line-height: 1.25;
    white-space: normal;
}

.margin-cell-danger { background: var(--danger-cell-tint) !important; }
.margin-cell-warning { background: var(--warning-cell-strong-tint) !important; }
.margin-row-cached td {
    background: var(--warning-cell-tint);
    border-top: 1px solid var(--warning-border);
    border-bottom-color: var(--warning-border);
}
.margin-row-cached td:first-child { border-left: 3px solid var(--warning-text); }
.margin-row-unavailable td { background: var(--danger-unavailable-tint); }
.margin-refresh-summary {
    color: var(--warning-text);
    font-size: 11px;
    white-space: normal;
}

@media (max-width: 700px) {
    .margin-page-intro { align-items: flex-start; flex-direction: column; }
    .margin-page-actions {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
        white-space: normal;
    }
    .margin-col-sticky-2 { position: static !important; }
    .margin-table { min-width: 900px; }
}

/* futures-only elements: hidden when spot radio is checked */
#mode-spot:checked ~ .futures-only,
#mode-spot:checked ~ * .futures-only {
    display: none !important;
}

/* ── Login screen ────────────────────────────────────────────────── */

.login-container {
    width: 100%;
    max-width: 380px;
    margin: auto;
    background: var(--surface);
    border-radius: 12px;
    padding: 32px 24px;
}

.login-title {
    text-align: center;
    font-size: 24px;
    color: var(--accent);
    margin-bottom: 4px;
}

.login-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 24px;
}

.login-submit {
    width: 100%;
    margin-top: 8px;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
}
.form-check input[type="checkbox"] {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    accent-color: var(--accent);
    cursor: pointer;
}
.form-check label {
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
}

.error-banner {
    background: var(--danger-bg);
    color: var(--danger-text);
    border-left: 3px solid var(--accent-red-border);
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 16px;
}

/* ── Mobile: tighten page gutters + fleet-stat values on small phones. ───────
   The burger/dropdown are now always-on (not media-gated), so only the
   layout-density rules need a breakpoint. */
@media (max-width: 480px) {
    .bots-header {
        padding-bottom: 12px;
        border-bottom: 1px solid var(--mobile-border);
    }
    .network-pill { padding: 6px 12px; }
    .nav-burger { width: 44px; height: 44px; border-radius: 9px; font-size: 20px; }

    /* Reclaim horizontal room so fleet-stat currency values stay on one line. */
    body { padding: 14px; }
    .bots-summary-card { padding: 14px; }
    .fleet-stats { gap: 10px 14px; }
    .fleet-stat .bots-summary-value { font-size: 19px; }
}

/* ── Bots dashboard: responsive grid (desktop/iPad) ──────────────────────────
   Min-width rules so they never collide with the max-width:480px block above.
   768 → iPad portrait (2-up tab grid); 1040 → iPad landscape + MacBook (3-up).
   1040 cleanly splits every iPad's portrait width (≤1024) from landscape (≥1080). */
@media (min-width: 768px) {
    .bots-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    /* The roll-up spans the full row, and its own stat rows go 2-up so the wide
       card is half as tall (the header spans both columns). */
    .bot-card--total {
        grid-column: 1 / -1;
        display: grid;
        grid-template-columns: 1fr 1fr;
        column-gap: 28px;
        align-items: start;
    }
    .bot-card--total .bot-card-header { grid-column: 1 / -1; }
}
@media (min-width: 1040px) {
    .bots-page .bots-top-row { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: stretch; }
    .bots-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* Credentials banner row (create page) — replaces an inline style the CSP drops (L-3). */
.creds-banner-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ── Per-type notification toggles (Settings) ─────────────────────── */
.notify-network-tag { font-size: 13px; font-weight: normal; color: var(--text-muted); }
.notify-row { padding: 10px 0; border-top: 1px solid var(--surface-control); }
.notify-row:first-child { border-top: none; }
.notify-row > label { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.notify-desc { margin: 4px 0 0 26px; color: var(--text-muted); font-size: 13px; }
.notify-critical { border-left: 3px solid var(--accent); padding-left: 9px; }
.notify-warn { margin: 4px 0 0 26px; color: var(--accent); font-size: 13px; }
.notify-banner { margin-top: 12px; padding: 10px 12px; border-radius: 6px; }
.notify-banner.ok { background: var(--success-bg); color: var(--success-text); }
.notify-banner.err { background: var(--danger-bg); color: var(--danger-text); }

/* CSP: `style-src 'self'` silently drops inline style="" — these moved off the
   markup. Declarations match the former inline values exactly. */
#logout-form { display: inline; margin: 0; }
#margin_mode { background: transparent; border: none; color: var(--text-primary); font-size: 13px; text-align: right; }
.mt-8 { margin-top: 8px; }
.mb-8 { margin-bottom: 8px; }
.switch-network-list { margin: 8px 0 12px 24px; font-size: 13px; }

/* ── Open Positions page ────────────────────────────────────────────────
   The read-only /positions list. Reuses the dark theme tokens + mirrors the
   .bot-card / .bwc-* aesthetic; CSP-safe (classes only, no inline style=). */
.pos-banners { display: flex; flex-direction: column; gap: 8px; }
.pos-banner {
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 13px;
    margin-bottom: 8px;
}
.pos-banner-testnet { background: var(--info-bg); color: var(--info-text); }
.pos-banner-hedge { background: var(--warning-bg); color: var(--warning-text); }
.pos-banner-error { background: var(--danger-bg); color: var(--danger-text); }

.pos-list { display: flex; flex-direction: column; gap: 12px; }

.pos-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 0;                 /* padding moves to the summary/detail (whole row clickable) */
    overflow: hidden;
}

/* Positions with no running (state=active) bot on the symbol — flagged amber. */
.pos-card.pos-card-no-bot { background: var(--no-bot-bg); }
.pos-card.pos-card-no-bot .pos-summary:hover { background: var(--no-bot-hover); }
.pos-card.pos-detail-stale { box-shadow: inset 0 0 0 1px var(--warning-text); }
.pos-card.pos-detail-stale .pos-detail::before {
    content: "Stale detail";
    display: block;
    color: var(--warning-text);
    font-size: 11px;
    font-weight: 600;
    margin: 6px 0 2px;
}

.pos-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}
.pos-symbol { font-size: 16px; font-weight: 600; color: var(--text-primary); }
.pos-perp {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--surface-control);
    border-radius: 6px;
    padding: 1px 6px;
}
.pos-margin-mode { font-size: 12px; color: var(--text-muted); }

/* ── Lazy-load list: collapsed 2-line summary row (click to expand in place) ── */
.pos-summary {
    display: flex;
    flex-direction: column;
    gap: 3px;
    width: 100%;
    padding: 12px 16px;
    background: transparent;
    border: 0;
    color: var(--text-primary);
    cursor: pointer;
    text-align: left;
    font: inherit;
}
.pos-summary:hover { background: var(--surface-hover-alt); }
.pos-sum-top { display: flex; align-items: center; gap: 10px; }
.pos-sum-id { display: flex; align-items: center; gap: 8px; min-width: 0; }
.pos-sum-id .pos-symbol { font-size: 15px; }
.pos-side {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 1px 6px;
    border-radius: 6px;
}
.pos-side-long { background: var(--long-bg); color: var(--success-text); }
.pos-side-short { background: var(--short-bg); color: var(--danger-text); }
.pos-sum-pnl { margin-left: auto; font-weight: 600; font-size: 14px; }
.pos-sum-pnl.profit-pos { color: var(--success-text); }
.pos-sum-pnl.profit-neg { color: var(--danger-text); }
.pos-sum-sub { color: var(--text-muted); font-size: 12px; }
.pos-chevron { color: var(--text-muted); font-size: 12px; transition: transform 0.15s ease; }
.pos-card.expanded .pos-chevron { transform: rotate(90deg); }

.pos-sum-badges { padding: 0 16px 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.pos-sum-badges:empty { display: none; }

.pos-detail { padding: 6px 16px 16px; border-top: 1px solid var(--surface-control); }
.pos-detail-meta { color: var(--text-muted); font-size: 12px; margin: 8px 0 10px; }
.pos-detail-note { color: var(--text-muted); font-size: 13px; padding: 14px 0; }
.pos-detail-error { color: var(--error-soft-text); }

.pos-pnl-row {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    margin-bottom: 12px;
}
.pos-pnl-block { display: flex; flex-direction: column; gap: 2px; }
/* Total PNL sits in the card's upper-right corner (all-in economic P&L). */
.pos-total-block { margin-left: auto; text-align: right; }
.pos-label { color: var(--text-muted); font-size: 11px; }
.pos-pnl { font-size: 18px; font-weight: 600; }
.pos-roi { font-size: 18px; font-weight: 600; }
.pos-pnl.profit-pos, .pos-roi.profit-pos { color: var(--success-text); }
.pos-pnl.profit-neg, .pos-roi.profit-neg { color: var(--danger-text); }

.pos-rows { display: flex; flex-direction: column; }
.pos-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    margin: 4px 0;
}
.pos-row .label { color: var(--text-muted); }
.pos-row .value { color: var(--text-primary); }

.pos-badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; }
.pos-badge {
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
}
.pos-badge-managed { background: var(--surface-control); color: var(--text-neutral); }
.pos-badge-hint { background: var(--warning-bg); color: var(--warning-text); }
.pos-badge-stopped { background: var(--warning-bg); color: var(--accent); }

.pos-modal-warning {
    margin: 10px 0;
    padding: 9px 10px;
    border: 1px solid var(--no-bot-border);
    border-radius: 8px;
    background: var(--no-bot-bg);
    color: var(--no-bot-text);
    font-size: 13px;
    line-height: 1.45;
}

.pos-actions { display: flex; gap: 8px; margin-top: 12px; }
.pos-action { flex: 1; }

/* Live auto-refresh status bar (Stage 7): countdown + stale badge +
   last-updated + Refresh-now. CSP-safe — visibility via .hidden only. */
.pos-status {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 4px 0 12px;
    font-size: 12px;
    color: var(--text-muted);
}
.pos-countdown { color: var(--text-muted); }
.pos-updated { color: var(--text-muted); }
.pos-stale {
    padding: 1px 8px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
    background: var(--warning-bg);
    color: var(--warning-text);
}
.pos-refresh-now { margin-left: auto; }

/* ── Closed Positions page ──────────────────────────────────────────────
   Account-wide closed-round history. A CSS-grid table (the repo has no <table>
   styling); horizontal-scroll on narrow screens like the backtest tables.
   CSP-safe (classes only, no inline style=). */
.closed-pos-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin: 4px 0 12px;
}
.closed-pos-control { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); }
.closed-pos-select,
.closed-pos-filter {
    background: var(--surface-alt);
    border: 1px solid var(--surface-control);
    color: var(--text-primary);
    border-radius: 8px;
    padding: 7px 10px;
    font-size: 13px;
}
.closed-pos-filter { min-width: 160px; }
.closed-pos-refresh { margin-left: auto; }
.closed-pos-updated { margin: 0 0 4px; font-size: 12px; color: var(--text-muted); }
.closed-pos-summary { margin: 0 0 12px; font-size: 13px; color: var(--text-secondary-strong); }

/* Per-position cards, modelled on Binance's Position History → Closed card. */
.closed-pos-cards { display: flex; flex-direction: column; gap: 12px; }
.closed-pos-pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 14px;
}
.closed-pos-pager .page-label { padding: 6px 8px; }
.closed-pos-pager .btn-link:disabled { opacity: 0.4; cursor: default; }
.closed-pos-card {
    background: var(--surface-alt);
    border: 1px solid var(--surface-raised-alt);
    border-radius: 12px;
    padding: 14px 16px;
}
.cpc-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.cpc-head-left { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cpc-icon {
    width: 20px; height: 20px; border-radius: 6px;
    background: var(--success-alt); color: var(--page-bg);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700;
}
.cpc-sym { font-weight: 700; color: var(--text-primary); font-size: 15px; }
.cpc-pill { padding: 2px 7px; border-radius: 5px; font-size: 11px; background: var(--surface-control); color: var(--text-secondary); }
.cpc-pill.cpc-long { color: var(--success-text); }
.cpc-pill.cpc-short { color: var(--danger-text); }
.cpc-pill.cpc-merged { color: var(--accent); }   /* folded-from-N-rounds accent */
.cpc-closed { color: var(--text-muted); font-size: 13px; white-space: nowrap; }

.cpc-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px 16px; }
.cpc-stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cpc-stat.cpc-right { text-align: right; align-items: flex-end; }
.cpc-label { color: var(--text-muted); font-size: 12px; }
.cpc-val { color: var(--text-primary); font-size: 14px; font-variant-numeric: tabular-nums; }
.cpc-val.profit-pos { color: var(--success-text); }   /* profit green */
.cpc-val.profit-neg { color: var(--danger-text); }   /* loss red */
.cpc-partial {
    margin-left: 6px; padding: 1px 6px; border-radius: 7px;
    font-size: 10px; background: var(--warning-bg); color: var(--warning-text);
}

.cpc-foot {
    margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--surface-raised-alt);
    display: flex; flex-direction: column; gap: 4px;
}
.cpc-foot-row { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; }
.cpc-ts { color: var(--text-secondary); font-variant-numeric: tabular-nums; }

/* ──────────────────────────────────────────────────────────────────────────
   /mobile — dense fleet table (running bots). One 440px-wide table on phones;
   two side-by-side tables on >=768px (iPad/desktop). table-layout:fixed + clipped
   cells guarantee NO horizontal scroll at 440px. CSP-safe: classes only, no
   inline style=. PnL colours reuse the fleet green/red; badges reuse the
   .vspeed-badge / .suppressed-badge backgrounds (compound selector, higher
   specificity) while .mobile-badge shrinks the padding/font for the table.
   ────────────────────────────────────────────────────────────────────────── */
.container.mobile-page { max-width: 440px; }
.mobile-page .bots-header { margin-bottom: 6px; }

@media (max-width: 480px) {
    .mobile-page .bots-header { padding-bottom: 0; }
}

.mobile-summary {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: baseline;
    column-gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
    padding-bottom: 10px;
    white-space: nowrap;
}
.mobile-summary-bots { justify-self: start; }
.mobile-summary-fhr { justify-self: center; }
.mobile-summary-av { justify-self: end; }
.mobile-summary b { color: var(--text-primary); font-weight: 700; }
.mobile-summary-primary { padding-bottom: 6px; }
.mobile-summary-secondary {
    grid-template-columns: auto minmax(0, 1fr) auto;
    column-gap: 4px;
}
.mobile-summary-fall { justify-self: start; }
.mobile-summary-settled { justify-self: center; }
.mobile-summary-position { justify-self: end; }
.mobile-summary-av b.profit-pos { color: var(--success-text); }
.mobile-summary-av b.profit-neg { color: var(--danger-text); }
.mobile-refresh-spinner {
    display: inline-block;
    margin-right: 3px;
    transform-origin: center;
    animation: mobile-refresh-spin 0.8s linear infinite;
}
@keyframes mobile-refresh-spin { to { transform: rotate(360deg); } }

.mobile-refresh-track {
    height: 2px;
    margin-bottom: 6px;
    overflow: hidden;
    background: var(--surface-raised-alt);
}
.mobile-refresh-progress {
    width: 100%;
    height: 100%;
    background: var(--info-text);
    transform: scaleX(0);
    transform-origin: left center;
}
.mobile-refresh-progress.mobile-refresh-counting {
    animation: mobile-refresh-countdown 30s linear forwards;
}
@keyframes mobile-refresh-countdown {
    from { transform: scaleX(1); }
    to { transform: scaleX(0); }
}

@media (max-width: 360px) {
    .mobile-summary { column-gap: 4px; font-size: 11px; }
    .mobile-summary-secondary { column-gap: 2px; }
}

@media (max-width: 330px) {
    .mobile-summary { font-size: 10px; }
}

.mobile-tables { display: flex; flex-direction: column; gap: 16px; }
.mobile-table-wrap {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
}

.mobile-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
    font-size: 12px;
}

.mobile-col-bot   { width: 22%; }
.mobile-col-price { width: 13%; }
.mobile-col-total { width: 11%; }
.mobile-col-match { width: 21%; }
.mobile-col-unm   { width: 11%; }
.mobile-col-24h   { width: 22%; }
.mobile-col-cushion  { width: 15%; }
.mobile-col-position { width: 16%; }
.mobile-col-down     { width: 15%; }
.mobile-col-60m      { width: 18%; }
.mobile-col-take-profit { width: 15%; }
.mobile-col-fees-total  { width: 17%; }
.mobile-col-fees-24h    { width: 16%; }
.mobile-col-version     { width: 11ch; min-width: 11ch; }
.mobile-version {
    width: 11ch;
    max-width: 11ch;
    overflow: hidden;
    text-overflow: clip;
    white-space: nowrap;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.85em;
}
.mobile-col-grids-around  { width: 13%; }
.mobile-col-stop-drop      { width: 14%; }
.mobile-col-entry-position { width: 17%; }
.mobile-col-floor-position { width: 17%; }
.mobile-col-floor-pnl      { width: 16%; }
.mobile-col-open-qty       { width: 15%; }
.mobile-col-floor-qty      { width: 15%; }
.mobile-col-growth-pct     { width: 14%; }
.mobile-col-vspeed         { width: 12%; }
.mobile-col-extension-liq  { width: 15%; }
.mobile-col-extension-fall { width: 15%; }

/* The existing six-column selection remains exactly viewport-wide. Each
   additional selected column adds a bounded table-width increment inside the
   wrapper, so overflow scrolls the table—not the document. */
.mobile-table-extra-1 { min-width: 524px; }
.mobile-table-extra-2 { min-width: 608px; }
.mobile-table-extra-3 { min-width: 692px; }
.mobile-table-extra-4 { min-width: 776px; }
.mobile-table-extra-5 { min-width: 860px; }
.mobile-table-extra-6 { min-width: 944px; }
.mobile-table-extra-7 { min-width: 1028px; }
.mobile-table-extra-8 { min-width: 1112px; }
.mobile-table-extra-9 { min-width: 1196px; }
.mobile-table-extra-10 { min-width: 1280px; }
.mobile-table-extra-11 { min-width: 1364px; }
.mobile-table-extra-12 { min-width: 1448px; }
.mobile-table-extra-13 { min-width: 1532px; }
.mobile-table-extra-14 { min-width: 1616px; }
.mobile-table-extra-15 { min-width: 1700px; }
.mobile-table-extra-16 { min-width: 1784px; }
.mobile-table-extra-17 { min-width: 1868px; }
.mobile-table-extra-18 { min-width: 1952px; }
.mobile-table-extra-19 { min-width: 2036px; }

.mobile-estimate-warning {
    color: var(--warning, #b7791f);
    font-weight: 700;
}

.mobile-table td, .mobile-table th {
    padding: 4px 1px;
    border-bottom: 1px solid var(--mobile-row-border);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mobile-table td.mobile-version,
.mobile-table th.mobile-version {
    overflow: hidden;
    text-overflow: clip;
    white-space: nowrap;
}

.mobile-num { text-align: right; }
.mobile-price {
    color: var(--text-secondary-strong);
    font-size: 10px;
    text-overflow: clip;
}
.mobile-bot-cell {
    position: sticky;
    left: 0;
    z-index: 2;
    text-align: left;
    white-space: normal;
    background: var(--page-bg);
    box-shadow: 1px 0 0 var(--mobile-row-border);
}

/* Column labels: muted, uppercase, sticky to the top while the list scrolls
   (narrow only — the wide layout resets this to static). */
.mobile-labels th {
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    position: sticky;
    top: 0;
    background: var(--page-bg);
    z-index: 1;
}
.mobile-labels th.mobile-bot-cell { z-index: 4; }

/* Fleet totals row: heavier, tinted, with the TOTAL label in the accent blue. */
.mobile-row-total td {
    font-weight: 700;
    color: var(--mobile-header-text);
    background: var(--mobile-header-bg);
    border-bottom: 1px solid var(--mobile-header-border);
}
.mobile-row-total .mobile-bot-cell {
    z-index: 3;
    color: var(--info-text);
    letter-spacing: 0.03em;
    background: var(--mobile-header-bg);
}
/* Fleet Total/Unm sums are bold + can reach 5–6 digits; drop a point so they
   never ellipsize in the narrowed value columns (bot rows stay 12px). */
.mobile-row-total .mobile-num { font-size: 11px; }

.mobile-bot-row { cursor: pointer; }
.mobile-bot-row:active { background: var(--surface-active); }
.mobile-bot-row:active .mobile-bot-cell { background: var(--surface-active); }

.mobile-bot-identity {
    display: flex;
    align-items: center;
    gap: 2px;
    min-width: 0;
}
.mobile-bot-name {
    display: block;
    min-width: 6ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
    color: var(--text-primary);
}
.mobile-bot-name.mobile-range-catchup { color: var(--orange-text); }
.mobile-bot-name.mobile-range-out { color: var(--danger-text); }
.mobile-badges { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 3px; }
.mobile-badge { font-size: 10px; padding: 1px 5px; border-radius: 6px; font-weight: 600; }
.mobile-adaptive-regime-badge {
    flex: 0 0 auto;
    min-width: 14px;
    padding-right: 3px;
    padding-left: 3px;
    text-align: center;
}

/* PnL colours (reuse the fleet green/red) — only Total + Unmatched are tinted. */
.mobile-num.profit-pos { color: var(--success-text); }
.mobile-num.profit-neg { color: var(--danger-text); }
.mobile-vspeed-off { color: var(--text-muted); }

/* Matched / 24h cell: matched profit + a smaller, muted trade count ("/ N").
   Per-bot rows keep both on ONE line (counts are <=4 digits and fit the column).
   Only the TOTAL row — summed counts reach 5 digits — drops the count to a
   second line by making its `.mobile-dual-sub` a block. */
.mobile-dual-main { color: var(--text-secondary-strong); }
.mobile-dual-sub { color: var(--disabled-text); font-size: 11px; }
.mobile-row-total .mobile-dual-sub { display: block; line-height: 1.2; }

/* Persistent per-browser column selection, placed after all dashboard content. */
.mobile-column-config-host {
    margin-top: 24px;
    margin-bottom: 12px;
}

.mobile-column-config {
    border: 1px solid var(--border-dark);
    border-radius: 8px;
    background: var(--surface-alt);
}

.mobile-column-config > summary {
    padding: 10px 12px;
    color: var(--text-secondary-strong);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.mobile-column-form {
    padding: 2px 12px 12px;
    border-top: 1px solid var(--border-dark);
}

.mobile-column-groups {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 8px 0 10px;
}

.mobile-column-group,
.mobile-layout-group {
    min-width: 0;
    margin: 0;
    padding: 4px 8px 6px;
    border: 1px solid var(--border-dark);
    border-radius: 6px;
}

.mobile-column-group legend,
.mobile-layout-group legend {
    padding: 0 4px;
    color: var(--text-secondary-strong);
    font-size: 11px;
    font-weight: 700;
}

.mobile-column-group .mobile-column-choices {
    padding: 2px 0 0;
}

.mobile-layout-group {
    margin-bottom: 10px;
}

.mobile-layout-choices {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 12px;
}

.mobile-layout-choice {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 34px;
    color: var(--text-primary);
    font-size: 12px;
}

.mobile-layout-choice input {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    margin: 0;
}

.mobile-column-choices {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    padding: 6px 0 10px;
}

.mobile-column-choice {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 34px;
    color: var(--text-primary);
    font-size: 12px;
}

.mobile-column-choice input {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    margin: 0;
}

.mobile-column-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mobile-column-actions .btn-primary {
    min-height: 34px;
    padding: 6px 14px;
}

.mobile-column-status {
    color: var(--text-muted);
    font-size: 11px;
}

.mobile-refresh-control {
    margin-top: 10px;
}

.mobile-refresh-now {
    width: 100%;
    min-height: 44px;
}

.mobile-refresh-status {
    display: block;
    margin-top: 5px;
    color: var(--text-muted);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    line-height: 1.3;
    text-align: center;
}

/* iPad + desktop: two equal tables side by side; labels no longer sticky. */
@media (min-width: 768px) {
    .container.mobile-page { max-width: 1040px; }
    .mobile-tables { flex-direction: row; align-items: flex-start; }
    .mobile-tables .mobile-table-wrap { flex: 1 1 0; }
    .mobile-labels th:not(.mobile-bot-cell) { position: static; }
    .mobile-labels th.mobile-bot-cell { top: auto; }
    .mobile-column-choices { grid-template-columns: 1fr 1fr; column-gap: 18px; }
    .mobile-column-groups { grid-template-columns: 1fr 1fr; }
    .mobile-column-group .mobile-column-choices { grid-template-columns: 1fr; }
}

/* ── /mobile2 multi-server dashboard ────────────────────────────────────── */
body.mobile2-body {
    --mobile2-page-gutter: 20px;
    --mobile2-safe-inline-gutter: max(
        var(--mobile2-page-gutter),
        env(safe-area-inset-left, 0px),
        env(safe-area-inset-right, 0px)
    );
    padding-right: var(--mobile2-safe-inline-gutter);
    padding-left: var(--mobile2-safe-inline-gutter);
}

.container.mobile2-page {
    min-width: 0;
    padding-bottom: calc(112px + env(safe-area-inset-bottom, 0px));
}

.mobile2-page .mobile-refresh-control {
    position: fixed;
    right: 20px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    left: 20px;
    z-index: 30;
    width: auto;
    max-width: 440px;
    margin: 0 auto;
    padding: 8px;
    border: 1px solid var(--border-dark);
    border-radius: 8px;
    background: var(--page-bg);
    box-shadow: 0 4px 18px rgba(0, 0, 0, .28);
}

@media (max-width: 767px) {
    body.mobile2-body {
        --mobile2-page-gutter: 12px;
    }

    .mobile2-page .mobile-refresh-control {
        right: 0;
        bottom: 0;
        left: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        width: auto;
        max-width: none;
        margin: 0;
        padding: 8px var(--mobile2-safe-inline-gutter)
            calc(8px + env(safe-area-inset-bottom, 0px));
        border: 0;
        border-top: 1px solid var(--border-dark);
        border-radius: 0;
        box-shadow: 0 -4px 18px rgba(0, 0, 0, .28);
    }

    .mobile2-page .mobile-refresh-now,
    .mobile2-page .mobile-refresh-status {
        width: 100%;
        max-width: 440px;
        margin-right: auto;
        margin-left: auto;
    }
}

.mobile2-warning {
    margin: 0 0 12px;
    padding: 8px 10px;
    border: 1px solid var(--warning-border-2);
    border-radius: 6px;
    background: var(--warning-bg-2);
    color: var(--warning-text-2);
    font-size: 12px;
    line-height: 1.4;
}

.mobile2-block {
    margin-bottom: 24px;
    min-width: 0;
}

.mobile2-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
    margin-bottom: 8px;
}

.mobile2-heading h2 {
    min-width: 0;
    margin: 0;
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.35;
}

.mobile2-source-link,
.mobile2-source-link:visited {
    overflow-wrap: anywhere;
    text-decoration: none;
}

.mobile2-source-link:hover {
    text-decoration: underline;
}

.mobile2-status {
    flex: 0 0 auto;
    min-width: 8.5em;
    color: var(--text-muted);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: nowrap;
}

.mobile2-status-live { color: var(--success-text); }
.mobile2-status-stale { color: var(--orange-text); }
.mobile2-status-error { color: var(--danger-text); }
.mobile2-status-loading {
    color: var(--text-muted);
    text-align: center;
}
.mobile2-loading-emoji {
    display: inline-block;
    line-height: 1;
}

.mobile2-refresh-progress {
    animation: mobile-refresh-countdown 30s linear forwards;
}

.mobile2-total-table {
    width: 100%;
    min-width: 0;
}

.mobile2-sticky-labels {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
    background: var(--page-bg);
}

.mobile2-sticky-labels .mobile-table-wrap {
    background: var(--page-bg);
    scrollbar-width: none;
}

.mobile2-sticky-labels .mobile-table-wrap::-webkit-scrollbar {
    display: none;
}

.mobile2-sticky-labels .mobile-labels th {
    top: auto;
}

.mobile2-list-region {
    gap: 16px;
}

.mobile2-total-control {
    cursor: pointer;
    outline: none;
}

.mobile2-total-control:hover td,
.mobile2-total-control:active td {
    background: var(--mobile2-card-bg);
}
.mobile2-total-control:hover .mobile-bot-cell,
.mobile2-total-control:active .mobile-bot-cell {
    background: var(--mobile2-card-bg);
}

.mobile2-total-control:focus-visible td {
    box-shadow: inset 0 2px var(--info-text), inset 0 -2px var(--info-text);
}

.mobile2-total-control:focus-visible td:first-child {
    box-shadow: inset 2px 0 var(--info-text), inset 0 2px var(--info-text), inset 0 -2px var(--info-text);
}

.mobile2-total-control:focus-visible td:last-child {
    box-shadow: inset -2px 0 var(--info-text), inset 0 2px var(--info-text), inset 0 -2px var(--info-text);
}

.mobile2-disclosure {
    display: inline-block;
    margin-left: 2px;
    color: var(--disabled-text);
}

/* Keep the disclosure label compact inside the widened 22% Bot column so the
   numeric totals retain their full share of the fixed-width table. */
.mobile2-total-control .mobile-bot-cell {
    padding-left: 2px;
    padding-right: 0;
    overflow: visible;
    text-overflow: clip;
    font-size: 9px;
    letter-spacing: 0;
}

.mobile2-empty {
    flex: 1 1 100%;
    padding: 10px 0;
}

/* Fixed CSP-safe source palette. The same class is applied to a source URL
   and its combined-table rows, so the heading and 4px border cannot drift. */
.mobile2-color-0 { --mobile2-source-color: var(--mobile2-source-0); }
.mobile2-color-1 { --mobile2-source-color: var(--mobile2-source-1); }
.mobile2-color-2 { --mobile2-source-color: var(--mobile2-source-2); }
.mobile2-color-3 { --mobile2-source-color: var(--mobile2-source-3); }
.mobile2-color-4 { --mobile2-source-color: var(--mobile2-source-4); }
.mobile2-color-5 { --mobile2-source-color: var(--mobile2-source-5); }
.mobile2-color-6 { --mobile2-source-color: var(--mobile2-source-6); }
.mobile2-color-7 { --mobile2-source-color: var(--mobile2-source-7); }

.mobile2-source-link.mobile2-color-0,
.mobile2-source-link.mobile2-color-1,
.mobile2-source-link.mobile2-color-2,
.mobile2-source-link.mobile2-color-3,
.mobile2-source-link.mobile2-color-4,
.mobile2-source-link.mobile2-color-5,
.mobile2-source-link.mobile2-color-6,
.mobile2-source-link.mobile2-color-7,
.mobile2-source-link.mobile2-color-0:visited,
.mobile2-source-link.mobile2-color-1:visited,
.mobile2-source-link.mobile2-color-2:visited,
.mobile2-source-link.mobile2-color-3:visited,
.mobile2-source-link.mobile2-color-4:visited,
.mobile2-source-link.mobile2-color-5:visited,
.mobile2-source-link.mobile2-color-6:visited,
.mobile2-source-link.mobile2-color-7:visited {
    color: var(--mobile2-source-color);
}

.mobile2-combined-row.mobile2-color-0 td:first-child,
.mobile2-combined-row.mobile2-color-1 td:first-child,
.mobile2-combined-row.mobile2-color-2 td:first-child,
.mobile2-combined-row.mobile2-color-3 td:first-child,
.mobile2-combined-row.mobile2-color-4 td:first-child,
.mobile2-combined-row.mobile2-color-5 td:first-child,
.mobile2-combined-row.mobile2-color-6 td:first-child,
.mobile2-combined-row.mobile2-color-7 td:first-child {
    border-left: 4px solid var(--mobile2-source-color);
    padding-left: 2px;
}

@media (min-width: 768px) {
    .mobile2-total-table {
        width: calc((100% - 16px) / 2);
    }

    .mobile2-sticky-labels {
        flex-direction: row;
        align-items: flex-start;
    }

    .mobile2-sticky-labels .mobile-table-wrap {
        flex: 1 1 0;
    }
}

/* Mobile2 resolves Auto against the 768px media query in JavaScript, then
   applies one explicit class. Fixed choices therefore keep the same geometry
   at every viewport width. */
.mobile2-total-table.mobile2-layout-1 {
    width: 100%;
}

.mobile2-total-table.mobile2-layout-2 {
    width: calc((100% - 16px) / 2);
}

.mobile2-total-table.mobile2-layout-3 {
    width: calc((100% - 32px) / 3);
}

.mobile2-sticky-labels.mobile2-layout-1,
.mobile2-list-region.mobile2-layout-1 {
    flex-direction: column;
    align-items: stretch;
}

.mobile2-sticky-labels.mobile2-layout-2,
.mobile2-sticky-labels.mobile2-layout-3,
.mobile2-list-region.mobile2-layout-2,
.mobile2-list-region.mobile2-layout-3 {
    flex-direction: row;
    align-items: flex-start;
}

.mobile2-sticky-labels.mobile2-layout-1 .mobile-table-wrap,
.mobile2-list-region.mobile2-layout-1 .mobile-table-wrap {
    flex: 0 0 100%;
}

.mobile2-sticky-labels.mobile2-layout-2 .mobile-table-wrap,
.mobile2-list-region.mobile2-layout-2 .mobile-table-wrap {
    flex: 0 0 calc((100% - 16px) / 2);
}

.mobile2-sticky-labels.mobile2-layout-3 .mobile-table-wrap,
.mobile2-list-region.mobile2-layout-3 .mobile-table-wrap {
    flex: 0 0 calc((100% - 32px) / 3);
}

@media (max-width: 300px) {
    .mobile2-heading {
        align-items: flex-start;
        flex-direction: column;
        gap: 2px;
    }

    .mobile2-status {
        text-align: left;
    }
}

/* ── Profit History page (/history) ──────────────────────────────────────── */

.profit-history-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.profit-history-desc {
    color: var(--text-muted);
    font-size: 13px;
    flex: 1 1 auto;
}

.profit-history-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.profit-history-recalc-btn {
    font-size: 13px;
}

.profit-history-banner {
    margin-bottom: 8px;
    padding: 8px 12px;
    border-radius: 4px;
    background: var(--surface);
    color: var(--text-muted);
    font-size: 13px;
}

.profit-history-banner-error {
    background: var(--danger-deep);
    color: var(--danger-solid);
}

.profit-history-summary {
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

.ph-summary-item {
    display: block;
    line-height: 1.45;
}

.ph-summary-range {
    color: var(--text-subtle);
}

.ph-average-table-wrap {
    margin-top: 8px;
    width: 100%;
}

.ph-average-table {
    width: 100%;
    min-width: 0;
    table-layout: fixed;
    border-collapse: collapse;
    color: var(--text-muted);
    font-size: 12px;
}

.ph-average-table th,
.ph-average-table td {
    padding: 5px 10px;
    border-bottom: 1px solid var(--surface-control);
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.ph-average-table th:first-child {
    text-align: left;
    width: 46%;
    white-space: normal;
    overflow-wrap: break-word;
    line-height: 1.25;
}

.ph-average-table th:not(:first-child) {
    width: 27%;
    white-space: normal;
    line-height: 1.25;
}

.ph-average-table td {
    white-space: nowrap;
}

@media (max-width: 480px) {
    .ph-average-table {
        font-size: 11px;
    }

    .ph-average-table th,
    .ph-average-table td {
        padding: 5px 4px;
    }
}

.profit-history-table-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 3px 14px;
    margin-bottom: 6px;
    color: var(--text-subtle);
    font-size: 12px;
}

.ph-table-meta-collateral {
    color: var(--text-muted);
}

.profit-history-loading {
    padding: 24px 0;
    color: var(--text-muted);
    font-size: 14px;
}

.profit-history-empty {
    padding: 24px 0;
    color: var(--text-muted);
    font-size: 14px;
}

/* Scroll wrapper — horizontal scrollable for the dual-definition table. */
.profit-history-table-region {
    width: 100%;
}

.profit-history-scroll-wrap {
    overflow-x: auto;
    width: 100%;
}

.profit-history-table {
    min-width: 2220px;
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.profit-history-caption {
    text-align: left;
    color: var(--text-subtle);
    font-size: 12px;
    padding-bottom: 6px;
    caption-side: top;
}

/* Column widths */
.ph-col-date       { width: 104px; }
.ph-col-equity     { width: 120px; }
.ph-col-profit     { width: 120px; }
.ph-col-delta      { width: 100px; }
.ph-col-settled    { width: 120px; }
.ph-col-pending    { width: 120px; }
.ph-col-commission { width: 110px; }
.ph-col-capital    { width: 140px; }
.ph-col-discrepancy { width: 105px; }

/* Header cells */
.profit-history-table thead th {
    padding: 6px 8px;
    text-align: right;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 12px;
    border-bottom: 1px solid var(--surface-control);
    white-space: nowrap;
}

.ph-th-date {
    text-align: left;
    position: sticky;
    left: 0;
    background: var(--page-bg);
    z-index: 1;
    border-right: 1px solid var(--surface-control);
}

.ph-th-num {
    text-align: right;
}

.ph-th-primary {
    color: var(--text-gray);
    font-weight: 600;
}

.ph-th-quiet {
    color: var(--text-subtle);
}

/* Body cells */
.profit-history-table tbody td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--divider-subtle);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.ph-td-date {
    text-align: left;
    position: sticky;
    left: 0;
    background: var(--page-bg);
    z-index: 1;
    border-right: 1px solid var(--surface-control);
    font-size: 13px;
}

.ph-date-value {
    display: block;
}

.ph-date-badges {
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 0;
    margin-top: 2px;
}

.ph-date-badges:empty {
    display: none;
}

.ph-date-badges .ph-live-pill,
.ph-date-badges .ph-stale-warn,
.ph-date-badges .ph-issue-marker {
    margin-left: 0;
    margin-right: 0;
}

.ph-td-num {
    text-align: right;
}

.ph-td-change.profit-pos {
    color: var(--success-text);
}

.ph-td-change.profit-neg {
    color: var(--danger-text);
}

.ph-td-primary {
    font-weight: 600;
}

.ph-td-quiet {
    color: var(--text-muted);
}

/* Live / stale indicators */
.ph-live-pill {
    display: inline-block;
    background: var(--green-banner-bg);
    color: var(--green-bright);
    border-radius: 3px;
    padding: 0 4px;
    font-size: 10px;
    font-weight: 600;
    margin-right: 4px;
    vertical-align: middle;
}

.ph-stale-warn {
    display: inline-block;
    color: var(--danger-solid);
    font-size: 11px;
    margin-right: 4px;
}

/* Issue warning marker (focusable) */
.ph-issue-marker {
    cursor: help;
    color: var(--accent);
    font-size: 12px;
    margin-left: 4px;
    vertical-align: middle;
}

.ph-issue-msg {
    /* visually hidden but available to screen readers and aria-describedby */
}

/* Discrepancy description (visually hidden) */
.ph-discrepancy-note {
    /* visually hidden */
}

/* Screen-reader-only utility (also used above) */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Pagination — 40px minimum touch targets */
.profit-history-pagination {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
}

.profit-history-page-btn {
    min-height: 40px;
    padding: 8px 16px;
}

.profit-history-page-label {
    color: var(--text-muted);
    font-size: 13px;
}

/* Polite announcer (off-screen) */
.profit-history-announcer {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* Recalculate confirmation dialog */
.profit-history-dialog {
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--surface-control);
    border-radius: 6px;
    padding: 24px;
    max-width: 480px;
    width: 90%;
}

.profit-history-dialog::backdrop {
    background: rgba(0, 0, 0, 0.7);
}

.profit-history-dialog-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
}

.profit-history-dialog-body {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 20px;
    line-height: 1.5;
}

.profit-history-dialog-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* ── Closed pairing-history tables (/pairing-issues) ── */
.unpaired-table {
    min-width: 900px;
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

/* Column widths */
.up-col-bot    { width: 130px; }
.up-col-closed { width: 140px; }
.up-col-price  { width: 110px; }
.up-col-qty    { width: 100px; }
.up-col-pnl    { width: 110px; }
.up-col-cid    { width: 110px; }

/* Header cells */
.unpaired-table thead th {
    padding: 6px 8px;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 12px;
    border-bottom: 1px solid var(--surface-control);
    white-space: nowrap;
}

.up-th-bot {
    text-align: left;
    position: sticky;
    left: 0;
    background: var(--page-bg);
    z-index: 1;
    border-right: 1px solid var(--surface-control);
}

.up-th-num  { text-align: right; }
.up-th-cid  { text-align: left; padding-left: 16px; }

.up-th-primary {
    color: var(--text-gray);
    font-weight: 600;
}

/* Body cells */
.unpaired-table tbody td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--divider-subtle);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.up-td-bot {
    text-align: left;
    position: sticky;
    left: 0;
    background: var(--page-bg);
    z-index: 1;
    border-right: 1px solid var(--surface-control);
    font-weight: 600;
    font-size: 13px;
}

.up-td-num     { text-align: right; }
.up-td-primary { font-weight: 600; }

.up-td-cid {
    text-align: left;
    padding-left: 16px;
    font-family: monospace;
    font-size: 11px;
    color: var(--text-muted);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Pairing observability: History accordions + fleet page ── */
.pairing-issue-accordion {
    border-bottom: 1px solid var(--surface-control);
    padding: 8px 0;
}
.pairing-issue-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.pairing-issue-toggle {
    flex: 1;
    border: 0;
    background: none;
    color: var(--text-primary);
    padding: 6px 0;
    text-align: left;
    font: inherit;
    cursor: pointer;
}
.pairing-issue-chevron { display: inline-block; width: 1.2em; }
.pairing-issue-show-all { white-space: nowrap; }
.pairing-issue-body { padding: 2px 0 8px 18px; }
.pairing-issue-list { display: flex; flex-direction: column; }
.pairing-issue-row {
    border-bottom: 1px solid var(--divider-subtle);
    padding: 8px 0;
    color: var(--text-secondary);
    font-size: 12px;
    overflow-wrap: anywhere;
}
.pairing-issue-row:last-child { border-bottom: 0; }
.pairing-issue-primary { color: var(--text-primary); font-weight: 600; }
.pairing-issue-meta { color: var(--text-muted); margin-top: 3px; }
.pairing-issue-neutral { color: var(--text-muted); }
.pairing-issue-warning { color: var(--accent); }
.pairing-issue-danger { color: var(--danger-solid); }
.pairing-issue-section h2 { margin: 0; font-size: 16px; }
.pairing-issues-page .pairing-issue-toggle { width: 100%; }
.pairing-issues-page .pairing-issue-section { margin-top: 12px; }
.pairing-issues-page .pairing-history-body { padding: 2px 0 12px; }
