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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #0b0e11;
    color: #eaecef;
    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;
}

h1 {
    text-align: center;
    margin-bottom: 24px;
    font-size: 20px;
    color: #f0b90b;
}

.card {
    background: #1e2329;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 16px;
}

.card h2 {
    font-size: 16px;
    margin-bottom: 16px;
    color: #f0b90b;
}

/* Toggle switch for trading mode */
.mode-toggle {
    display: flex;
    background: #2b3139;
    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: #848e9c;
}

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

.mode-toggle input[type="radio"]:checked + label {
    background: #f0b90b;
    color: #0b0e11;
}

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

.form-group > label {
    display: block;
    font-size: 12px;
    color: #848e9c;
    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"],
select {
    width: 100%;
    padding: 10px 12px;
    background: #2b3139;
    border: 1px solid #3c4043;
    border-radius: 6px;
    color: #eaecef;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

input:focus, select:focus {
    border-color: #f0b90b;
}

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

.info-row .info-label {
    color: #848e9c;
}

.info-row .info-value {
    color: #eaecef;
    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: #848e9c;
}

.chevron {
    font-size: 12px;
    color: #848e9c;
    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: #f0b90b;
    width: 16px;
    height: 16px;
}

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

.sub-fields .form-group {
    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: #f0b90b;
    color: #0b0e11;
    border: 0;
    border-radius: 6px;
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.btn-secondary {
    background: #2b3139;
    color: #eaecef;
    border: 1px solid #3c4043;
}

.btn-connect {
    background: #02c076;
    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: #02c076;
}

.status-dot.red {
    background: #f6465d;
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #3c4043;
    border-top-color: #f0b90b;
    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: #2b3139;
    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 #02c076;
    color: #4caf72;
}

.result-box.error {
    border-left: 3px solid #f6465d;
    color: #ff7676;
}

/* Divider */
.divider {
    height: 1px;
    background: #2b3139;
    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: #f0b90b;
}

.hidden {
    display: none !important;
}

/* Profit display */
.profit-display {
    font-size: 14px;
    color: #02c076;
    font-weight: 500;
    padding: 8px 0;
}

/* TP/SL mode selector */
.tpsl-mode-selector {
    display: flex;
    background: #2b3139;
    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: #848e9c;
    transition: background 0.2s;
}

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

.tpsl-mode-selector input[type="radio"]:checked + label {
    background: #3c4043;
    color: #eaecef;
}

/* 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: #848e9c;
    text-decoration: none;
    padding: 6px 12px;
    border: 1px solid #2b3139;
    border-radius: 6px;
    transition: color 0.2s, border-color 0.2s;
}

.help-link:hover {
    color: #f0b90b;
    border-color: #f0b90b;
}

/* 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: #848e9c;
    text-decoration: none;
    margin-bottom: 12px;
}

.help-back:hover {
    color: #f0b90b;
}

.help-content {
    background: #1e2329;
    border-radius: 12px;
    padding: 32px 36px;
    font-size: 14px;
    line-height: 1.65;
    color: #eaecef;
}

.help-content h1,
.help-content h2,
.help-content h3 {
    color: #f0b90b;
    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 #2b3139; padding-bottom: 6px; }
.help-content h3 { font-size: 15px; color: #eaecef; }

.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: #f0b90b;
    font-weight: 600;
}

.help-content code {
    background: #2b3139;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    color: #f0b90b;
}

.help-content pre {
    background: #0b0e11;
    border: 1px solid #2b3139;
    border-radius: 6px;
    padding: 12px;
    overflow-x: auto;
    margin-bottom: 14px;
}

.help-content pre code {
    background: transparent;
    padding: 0;
    color: #eaecef;
}

.help-content a {
    color: #f0b90b;
    text-decoration: none;
}

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

.help-content blockquote {
    border-left: 3px solid #f0b90b;
    padding: 8px 14px;
    margin: 14px 0;
    background: #2b3139;
    border-radius: 0 6px 6px 0;
    color: #b7bdc6;
}

.help-content hr {
    border: none;
    border-top: 1px solid #2b3139;
    margin: 24px 0;
}

.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 #2b3139;
    text-align: left;
}

.help-content th {
    color: #f0b90b;
    font-weight: 600;
    background: #2b3139;
}

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

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

.bots-header h1 {
    margin: 0;
    margin-right: auto;        /* push the pill + controls to the right edge */
    text-align: left;
    font-size: 22px;
}

.bots-header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Wider bots bar → space the controls out a touch more. */
.bots-page .bots-header-controls { gap: 14px; }

/* Hamburger toggle — only shown on mobile (see the @media block). */
.nav-burger {
    display: none;
    background: transparent;
    border: 0;
    color: #eaecef;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 8px;
}

.network-pill {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    background: #2b3139;
    color: #848e9c;
}

.network-pill.testnet { background: #2b3a4d; color: #4fa8ff; }
.network-pill.mainnet { background: #3d2326; color: #ff7676; }

.btn-link {
    background: transparent;
    border: 0;
    color: #848e9c;
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
    padding: 4px 8px;
}

.btn-link:hover { color: #f0b90b; }

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

.btn-secondary {
    background: #2b3139;
    color: #eaecef;
    border: 0;
    border-radius: 6px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 13px;
}

.btn-secondary:hover { background: #3a4350; }

/* 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: #848e9c;
}

.bots-summary-value {
    font-size: 22px;
    font-weight: 600;
    color: #eaecef;
}

.bots-summary-value.profit-pos { color: #4caf72; }
.bots-summary-value.profit-neg { color: #ff7676; }

.bots-summary-spot {
    font-size: 13px;
    color: #848e9c;
}

.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: #848e9c;
    padding: 8px 12px;
    font-size: 14px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}

.filter-btn.active { color: #f0b90b; border-bottom-color: #f0b90b; }

.filter-btn .count {
    margin-left: 4px;
    background: #2b3139;
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 11px;
    color: #eaecef;
}

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

.bot-card {
    background: #1e2329;
    border-radius: 12px;
    padding: 16px;
    cursor: pointer;
    transition: background 0.15s;
}

.bot-card:hover { background: #242a32; }

.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: #1d3a2c; color: #4caf72; }
.state-pill.inactive { background: #2b3139; color: #848e9c; }
.state-pill.failed   { background: #3d2326; color: #ff7676; }
.state-pill.unknown  { background: #2b3139; color: #848e9c; }
.state-pill.total    { background: #1d2b3d; color: #4fa8ff; }

/* ── 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 #4fa8ff 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 #4fa8ff;
}
.bot-card--total:hover { background: #1e2329; }

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

.bot-card-row .label { color: #848e9c; }
.bot-card-row .value { color: #eaecef; }
.value.profit-pos { color: #4caf72; }
.value.profit-neg { color: #ff7676; }

/* Colour key for the "24h / total" pairs (matched profit + matched count):
   24h figure blue, all-time figure green. */
.dual-24h { color: #4fa8ff; }
.dual-total { color: #4caf72; }

/* Grid range: green when the mark is inside [lower, upper], red when outside. */
.value.range-in { color: #4caf72; }
.value.range-out { color: #ff7676; }

/* "↕ 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: #4fa8ff;
    background: #1d2b3d;
    vertical-align: middle;
}

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

.btn-stop {
    flex: 1;
    background: #3d2326;
    color: #ff7676;
    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: #1d3a2c; color: #4caf72; }
.cushion-badge.cushion-warn  { background: #3a2e12; color: #c9a227; }
.cushion-badge.cushion-danger { background: #3d2326; color: #ff7676; }
.cushion-badge.cushion-stale { background: #2b3139; color: #848e9c; }
/* Guardian degraded (#5): REST reads failing — not protecting. */
.cushion-badge.cushion-degraded { background: #3d2326; color: #ff9b6b; }
/* Variable-speed "slowdown" (amber) + suppressed-levels (blue) — running cards. */
.cushion-badge.vspeed-badge { background: #3a2e12; color: #e8b339; }
.cushion-badge.suppressed-badge { background: #2b3a4d; color: #4fa8ff; }

/* 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: #eaecef; }
.bwc-perp {
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    background: #2b3139;
    color: #848e9c;
}
.bwc-status { display: flex; align-items: center; gap: 6px; flex: none; }
.bwc-chevron { color: #848e9c; 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: #2b3139;
    color: #d0d4dc;
}
.bwc-risk {
    padding: 2px 7px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
}
.bwc-risk-low   { background: #1d3a2c; color: #4caf72; }
.bwc-risk-med   { background: #3a2e12; color: #c9a227; }
.bwc-risk-high  { background: #3d2326; color: #ff7676; }
.bwc-risk-stale { background: #2b3139; color: #848e9c; }

.bwc-created { color: #848e9c; font-size: 12px; margin: 2px 0 8px; }

.bwc-banner {
    background: #3a2e12;
    color: #c9a227;
    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: #848e9c; font-size: 11px; }
.bwc-value { color: #eaecef; font-size: 13px; font-weight: 500; }
.bwc-value.bwc-pos, .bwc-value.range-in { color: #4caf72; }
.bwc-value.bwc-neg, .bwc-value.range-out { color: #ff7676; }

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

/* ── Settings: Appearance (card design) ─────────────────────────────── */
.appearance-options { display: flex; gap: 16px; margin: 10px 0; }
.appearance-option { display: flex; align-items: center; gap: 6px; cursor: pointer; }

/* 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: #1d3a2c; color: #4caf72; }
#save-error  { background: #3d2326; color: #ff7676; }

/* ── 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: #3a2e12;
    color: #c9a227;
    border-left-color: #c9a227;
}

.exit-watch-row--filled {
    background: #1d3a2c;
    color: #4caf72;
    border-left-color: #4caf72;
}

.exit-watch-row--verify {
    background: #3d2326;
    color: #ff7676;
    border-left-color: #f6465d;
}

.exit-watch-row--informational {
    background: #2b3139;
    color: #848e9c;
    border-left-color: #848e9c;
}

.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 / Convert /
   Transfer button stack on the right; the transition 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-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: #3a4350; color: #f0b90b; }

#headroom-timeline {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #2b3139;
}

/* 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: #eaecef;
    font-variant-numeric: tabular-nums;
}

.equity-change { font-size: 13px; font-weight: 600; }
.equity-change.profit-pos { color: #4caf72; }
.equity-change.profit-neg { color: #ff7676; }
.equity-change-flat { color: #848e9c; }

.equity-chev {
    color: #848e9c;
    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: #4caf72; }
.equity-row-val.profit-neg { color: #ff7676; }

.equity-row-label { color: #b7bdc6; }

.equity-row-total {
    margin-top: 4px;
    padding-top: 10px;
    border-top: 1px solid #2b313a;
    font-size: 14px;
}

.equity-row-total .equity-row-label { color: #eaecef; font-weight: 600; }

.equity-coverage-warn {
    margin-top: 10px;
    font-size: 12px;
    color: #ff7676;
}

.headroom-timeline-empty {
    color: #848e9c;
    font-size: 13px;
    margin: 6px 0 0;
}

.headroom-timeline-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 5px 0;
    border-bottom: 1px solid #2b3139;
    font-size: 13px;
}

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

.headroom-timeline-ts {
    color: #848e9c;
    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: #ff7676; }
.headroom-level-ok    { color: #4caf72; }

.headroom-timeline-free {
    color: #eaecef;
}

.empty-state {
    text-align: center;
    color: #848e9c;
    padding: 32px;
}

.hidden { display: none !important; }

.ws-status {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: #3d2326;
    color: #ff7676;
    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: #848e9c; 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: #eaecef;
    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: #848e9c;
    background: #2b3139;
}

.badge.badge-long { background: #1d3a2c; color: #4caf72; }
.badge.badge-short { background: #3d2326; color: #ff7676; }

.bot-detail-meta { color: #848e9c; font-size: 12px; }

/* Variable-speed-down: N grid levels intentionally suppressed (recovery-pending).
   Amber-warn, matching the cushion-warn / log-dot-warn palette (CSP-safe class). */
.suppressed-banner {
    display: inline-block;
    margin-top: 8px;
    padding: 4px 9px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    background: #3a2e12;
    color: #c9a227;
}

.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 #2b3139;
}

.tab-btn {
    background: transparent;
    border: 0;
    color: #848e9c;
    /* 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: #f0b90b; border-bottom-color: #f0b90b; }

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

.kv-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #2b3139;
    font-size: 14px;
}

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

.kv-row > span:first-child { color: #848e9c; }
.kv-value { color: #eaecef; font-weight: 500; }

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

.details-subhead {
    font-size: 14px;
    font-weight: 600;
    color: #eaecef;
    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: #848e9c;
}
.vspeed-input { width: 72px; }
.vspeed-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: #eaecef;
}
/* Lock reason shown when a slowdown is engaged (edits idle-only). */
.vspeed-lock {
    margin-top: 8px;
    font-size: 12px;
    color: #e8b339;
}

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

.orders-grid .order-side { color: #848e9c; }
.orders-grid .order-side.buy { color: #4caf72; }
.orders-grid .order-side.sell { color: #ff7676; }
/* 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: #4a9eff; }
.orders-grid .order-side.skip-sell { color: #e8a13a; }
/* 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: #848e9c; }
.orders-grid .orders-skip-note { grid-column: 1 / -1; }

/* ── 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: #848e9c; }
.matched-stat-val { color: #eaecef; font-weight: 500; }
.matched-pos { color: #4caf72; }
.matched-neg { color: #ff7676; }
.matched-grid-pill {
    display: inline-block;
    margin-top: 10px;
    padding: 4px 10px;
    background: #2b3139;
    border-radius: 6px;
    font-size: 12px;
    color: #b7bdc6;
}
.matched-note {
    margin-top: 10px;
    font-size: 11px;
    line-height: 1.5;
    color: #848e9c;
}

.matched-list { display: flex; flex-direction: column; }
.matched-row { border-bottom: 1px solid #2b3139; }
.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: #eaecef; font-size: 13px; font-weight: 500; }
.matched-rung { color: #848e9c; font-weight: 400; margin-left: 6px; }
/* R14: a lot with no placed paired sell (exit-pending) — amber-warn label. */
.matched-exit-pending { color: #f0b90b; font-weight: 500; }
/* 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: #2b3139;
    border-radius: 4px;
    font-size: 11px;
    text-transform: capitalize;
    color: #b7bdc6;
}
/* 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: #16313a;
    border-radius: 4px;
    font-size: 11px;
    color: #5ec8d8;
}
.matched-chev { color: #848e9c; 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: #848e9c; }
.md-col { color: #eaecef; }
.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: #848e9c; 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: #f6465d; }

/* ── 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: #848e9c;
    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: #848e9c;
    flex: 1 1 140px;
}
.log-field input { width: 100%; }
.log-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.log-chip {
    background: #2b3139;
    border: 1px solid #3c4043;
    color: #848e9c;
    padding: 5px 10px;
    font-size: 12px;
    border-radius: 14px;
    cursor: pointer;
    white-space: nowrap;
}
.log-chip.active { color: #0b0e11; background: #f0b90b; border-color: #f0b90b; }
.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: #848e9c;
    padding: 10px 2px 4px;
    border-bottom: 1px solid #2b3139;
    position: sticky;
    top: 0;
    background: #1e2329;
}
.log-row { border-bottom: 1px solid #2b3139; }
.log-row:last-child { border-bottom: 0; }
.log-row-head {
    width: 100%;
    background: none;
    border: 0;
    color: #eaecef;
    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: #848e9c; }
.log-dot-buy { background: #4caf72; }
.log-dot-sell { background: #ff7676; }
.log-dot-warn { background: #f0b90b; }
.log-dot-bad { background: #f6465d; }
.log-dot-info { background: #5a8dee; }
.log-time { color: #848e9c; 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: #b7bdc6;
}
.log-chev { flex: 0 0 auto; color: #848e9c; 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: #848e9c; }
.log-kv-val { color: #eaecef; 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: #1e2329;
    border-radius: 12px;
    padding: 24px;
    width: calc(100% - 32px);
    max-width: 400px;
}

.modal h2 { font-size: 18px; margin-bottom: 12px; color: #f0b90b; }
.modal p { font-size: 13px; color: #eaecef; 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: #2b3139;
    border: 1px solid #3a4350;
    color: #eaecef;
    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 #2b3139;
}
.recon-bot:last-child { border-bottom: none; margin-bottom: 4px; }
.recon-confirm { margin-top: 8px; }
.recon-btn { margin-top: 4px; }
.stale-warn { color: #f0b90b; font-size: 13px; margin-top: 8px; line-height: 1.5; }
.recon-done { color: #02c076; font-size: 13px; margin-top: 8px; }

.modal-list { margin: 8px 0 12px 24px; font-size: 13px; color: #eaecef; }
.modal-subhead { font-size: 12px; font-weight: 600; color: #848e9c; margin: 4px 0; text-transform: uppercase; letter-spacing: .3px; }
.modal-note { font-size: 13px; color: #848e9c; margin: 8px 0 12px; font-style: italic; }

/* Stop-bot wind-down chooser (4 radio modes + maker-offset / type-to-confirm). */
.stop-modes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 4px; }
.stop-mode {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px;
    border: 1px solid #3a4350;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}
.stop-mode input[type=radio] { margin-top: 3px; }
.stop-bps-row, .stop-confirm-row { margin-top: 12px; }
.stop-bps-row label { display: block; font-size: 12px; color: #848e9c; margin-bottom: 4px; }
.stop-bps-row input[type=number] {
    width: 120px;
    background: #2b3139;
    border: 1px solid #3a4350;
    color: #eaecef;
    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: #848e9c;
}
.convert-asset-pick select,
.convert-asset-pick input[type=number] {
    background: #2b3139;
    border: 1px solid #3a4350;
    color: #eaecef;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 14px;
}
.convert-to {
    font-size: 13px;
    color: #848e9c;
    padding-bottom: 8px;
}
.convert-to strong { color: #eaecef; }
.convert-quote {
    border: 1px solid #3a4350;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 12px;
}
.convert-quote p { margin-bottom: 6px; }
.convert-countdown { color: #f0b90b; font-weight: 600; }
.convert-warn {
    border: 1px solid #f6465d;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 12px;
    font-size: 13px;
    color: #f6465d;
    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: #848e9c;
}
.transfer-asset-pick select,
.transfer-asset-pick input[type=number] {
    background: #2b3139;
    border: 1px solid #3a4350;
    color: #eaecef;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 14px;
}
.transfer-warn {
    border: 1px solid #f6465d;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 12px;
    font-size: 13px;
    color: #f6465d;
    line-height: 1.5;
}

/* Open Positions modals (Close + TP/SL) — Stage 6. Classes only (CSP). */
.modal select {
    width: 100%;
    background: #2b3139;
    border: 1px solid #3a4350;
    color: #eaecef;
    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 #2b3139;
}
.pos-modal-row:last-child { border-bottom: none; }
.pos-modal-row .label { color: #848e9c; }
.pos-modal-row .value { color: #eaecef; text-align: right; }
.pos-modal-leg {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}
.pos-modal-leg .label { font-size: 12px; color: #848e9c; }
.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: #2b3139;
    color: #eaecef;
    border: 1px solid #3a4350;
    border-left: 3px solid #02c076;   /* 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: #f6465d; }

/* 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(6, 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 ───────────────────────────────────────── */

/*
 * Eight cells per row, each cell rendered as an anchor so the whole row
 * is keyboard-navigable + right-click "open in new tab"-able. Grid layout
 * stays in one shared track so columns align across runs even when one
 * cell wraps.
 */
.history-grid {
    display: grid;
    grid-template-columns:
        auto                  /* compare checkbox */
        auto                  /* started */
        auto                  /* symbol */
        auto                  /* range */
        auto                  /* grids */
        auto                  /* invest */
        auto                  /* span */
        auto                  /* status */
        1fr                   /* matched p&l */
        auto;                 /* download icon */
    gap: 6px 14px;
    font-size: 13px;
    align-items: center;
}

.history-download {
    color: #848e9c;
    text-decoration: none;
    font-size: 16px;
    padding: 0 4px;
}

.history-download:hover { color: #f0b90b; }

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

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

.history-row-link {
    color: #eaecef;
    text-decoration: none;
    padding: 2px 0;
    border-bottom: 1px solid transparent;
}

.history-row-link:hover {
    border-bottom-color: #2b3139;
}

.compare-cb-cell {
    display: flex;
    justify-content: center;
}

.compare-cb-cell input[type="checkbox"] {
    accent-color: #f0b90b;
    cursor: pointer;
}

/* Sticky action bar — only visible when 1+ runs are checkbox-selected. */
.compare-bar {
    position: sticky;
    bottom: 16px;
    margin-top: 16px;
    background: #1e2329;
    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;
}

/* ── 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: #1d3a2c;
    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: #2b3139;
    padding: 1px 4px;
    border-radius: 3px;
}

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

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

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

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

.imported-badge {
    background: #2b3a4d;
    color: #4fa8ff;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.notes-textarea {
    width: 100%;
    background: #0b0e11;
    color: #eaecef;
    border: 1px solid #2b3139;
    border-radius: 6px;
    padding: 8px;
    font-family: inherit;
    font-size: 13px;
    resize: vertical;
}

.notes-textarea:focus {
    outline: none;
    border-color: #f0b90b;
}

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

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

.guardian-stale-note {
    font-size: 12px;
    color: #c9a227;
    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 #2b3139;
    font-size: 12px;
    align-items: start;
}

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

.guardian-action-kind {
    font-weight: 600;
    color: #eaecef;
}

.guardian-action-amount {
    color: #4caf72;
    font-weight: 500;
}

.guardian-action-detail { color: #848e9c; }

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

.guardian-settings-key { color: #848e9c; padding: 4px 0; }
.guardian-settings-val { color: #eaecef; font-weight: 500; padding: 4px 0; text-align: right; }

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

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

.login-container {
    width: 100%;
    max-width: 380px;
    margin: auto;
    background: #1e2329;
    border-radius: 12px;
    padding: 32px 24px;
}

.login-title {
    text-align: center;
    font-size: 24px;
    color: #f0b90b;
    margin-bottom: 4px;
}

.login-subtitle {
    text-align: center;
    color: #848e9c;
    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: #f0b90b;
    cursor: pointer;
}
.form-check label {
    color: #848e9c;
    font-size: 13px;
    cursor: pointer;
}

.error-banner {
    background: #3d2326;
    color: #ff7676;
    border-left: 3px solid #cf304a;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 16px;
}

/* ──────────────────────────────────────────────────────────────────────────
   Mobile header (phones incl. iPhone 16 Pro Max, 430px logical width).
   Compact: one short row — title + network pill + a hamburger. The actions
   collapse behind the burger and drop down on demand, so the always-visible
   header is a single ~44px row instead of a multi-line stack. Desktop layout
   and markup order are unchanged (the burger is display:none above 480px).
   ────────────────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .bots-header {
        flex-wrap: wrap;                 /* the dropdown wraps onto its own line */
        align-items: center;
        gap: 10px;
        margin-bottom: 16px;
        padding-bottom: 12px;
        border-bottom: 1px solid #1e242c;
    }
    .network-pill { padding: 6px 12px; font-size: 11px; }

    .nav-burger {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        border-radius: 9px;
        background: #1b212b;
        font-size: 20px;
    }
    .nav-burger:active { transform: scale(0.95); }

    /* The control cluster becomes a dropdown: hidden until toggled, then a
       full-width column on its own line below the bar. */
    .bots-header-controls {
        display: none;
        flex-basis: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        margin-top: 2px;
    }
    .bots-header-controls.open { display: flex; }

    /* Menu items: full-width, comfortable 46px tap targets. */
    #bots-menu #create-bot-link,
    #bots-menu #switch-network-btn,
    #bots-menu #restart-all-btn,
    #bots-menu .btn-link,
    #closed-positions-menu #create-bot-link,
    #closed-positions-menu .btn-link {
        box-sizing: border-box;
        width: 100%;
        min-height: 46px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0 16px;
        border-radius: 9px;
        font-size: 15px;
    }
    #bots-menu .btn-link,
    #closed-positions-menu .btn-link { background: #1b212b; color: #c2cad6; }
    #bots-menu .btn-link:hover,
    #bots-menu .btn-link:active,
    #closed-positions-menu .btn-link:hover,
    #closed-positions-menu .btn-link:active { background: #232a35; color: #f0b90b; }
    #bots-menu #logout-form,
    #closed-positions-menu #logout-form { display: flex; margin: 0; }
    #bots-menu #settings-link::after,
    #closed-positions-menu #settings-link::after { content: " Settings"; }   /* label the ⚙ in the menu */
    #bots-menu a:active,
    #bots-menu button:active,
    #closed-positions-menu a:active,
    #closed-positions-menu button:active { transform: scale(0.98); }

    /* Reclaim horizontal room on phones so the fleet-stat currency values
       (e.g. "22534.04 USDT", "+2508.38 USD") stay on ONE line instead of
       wrapping the asset suffix onto a second. Trims the outer page gutter +
       the summary-card padding + the 2-up column gap, and shaves the stat
       value to 19px — together these fit five-figure values down to a 375px
       viewport (verified headless 375/393/430/440). Other top cards inherit
       the tighter padding; their full-width values don't wrap, so only the
       2-up fleet-stat values get the smaller font. */
    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: #848e9c; }
.notify-row { padding: 10px 0; border-top: 1px solid #2b3139; }
.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: #848e9c; font-size: 13px; }
.notify-critical { border-left: 3px solid #f0b90b; padding-left: 9px; }
.notify-warn { margin: 4px 0 0 26px; color: #f0b90b; font-size: 13px; }
.notify-banner { margin-top: 12px; padding: 10px 12px; border-radius: 6px; }
.notify-banner.ok { background: #1d3a2c; color: #4caf72; }
.notify-banner.err { background: #3d2326; color: #ff7676; }

/* 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: #eaecef; 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: #2b3a4d; color: #4fa8ff; }
.pos-banner-hedge { background: #3a2e12; color: #c9a227; }
.pos-banner-error { background: #3d2326; color: #ff7676; }

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

.pos-card {
    background: #1e2329;
    border-radius: 12px;
    padding: 16px;
}

.pos-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}
.pos-symbol { font-size: 16px; font-weight: 600; color: #eaecef; }
.pos-perp {
    font-size: 11px;
    font-weight: 600;
    color: #848e9c;
    background: #2b3139;
    border-radius: 6px;
    padding: 1px 6px;
}
.pos-margin-mode { font-size: 12px; color: #848e9c; }

.pos-pnl-row {
    display: flex;
    gap: 24px;
    margin-bottom: 12px;
}
.pos-pnl-block { display: flex; flex-direction: column; gap: 2px; }
.pos-label { color: #848e9c; 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: #4caf72; }
.pos-pnl.profit-neg, .pos-roi.profit-neg { color: #ff7676; }

.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: #848e9c; }
.pos-row .value { color: #eaecef; }

.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: #2b3139; color: #d0d4dc; }
.pos-badge-hint { background: #3a2e12; color: #c9a227; }

.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: #848e9c;
}
.pos-countdown { color: #848e9c; }
.pos-updated { color: #848e9c; }
.pos-stale {
    padding: 1px 8px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
    background: #3a2e12;
    color: #c9a227;
}
.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: #848e9c; }
.closed-pos-select,
.closed-pos-filter {
    background: #1b212b;
    border: 1px solid #2b3139;
    color: #eaecef;
    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: #848e9c; }
.closed-pos-summary { margin: 0 0 12px; font-size: 13px; color: #c2cad6; }

/* 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: #1b212b;
    border: 1px solid #232a35;
    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: #2ebd85; color: #0b0e11;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700;
}
.cpc-sym { font-weight: 700; color: #eaecef; font-size: 15px; }
.cpc-pill { padding: 2px 7px; border-radius: 5px; font-size: 11px; background: #2b3139; color: #b7bdc6; }
.cpc-pill.cpc-long { color: #4caf72; }
.cpc-pill.cpc-short { color: #ff7676; }
.cpc-pill.cpc-merged { color: #f0b90b; }   /* folded-from-N-rounds accent */
.cpc-closed { color: #848e9c; 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: #848e9c; font-size: 12px; }
.cpc-val { color: #eaecef; font-size: 14px; font-variant-numeric: tabular-nums; }
.cpc-val.profit-pos { color: #4caf72; }   /* profit green */
.cpc-val.profit-neg { color: #ff7676; }   /* loss red */
.cpc-partial {
    margin-left: 6px; padding: 1px 6px; border-radius: 7px;
    font-size: 10px; background: #3a2e12; color: #c9a227;
}

.cpc-foot {
    margin-top: 12px; padding-top: 10px; border-top: 1px solid #232a35;
    display: flex; flex-direction: column; gap: 4px;
}
.cpc-foot-row { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; }
.cpc-ts { color: #b7bdc6; 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-tables { display: flex; flex-direction: column; gap: 16px; }
.mobile-table-wrap { width: 100%; min-width: 0; }

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

.mobile-col-bot   { width: 17%; }
.mobile-col-total { width: 14%; }
.mobile-col-match { width: 27%; }
.mobile-col-unm   { width: 14%; }
.mobile-col-24h   { width: 28%; }

.mobile-table td, .mobile-table th {
    padding: 7px 4px;
    border-bottom: 1px solid #1a2029;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mobile-num { text-align: right; }
.mobile-bot-cell { text-align: left; white-space: normal; }

/* 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: #848e9c;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    position: sticky;
    top: 0;
    background: #0b0e11;
    z-index: 1;
}

/* Fleet totals row: heavier, tinted, with the TOTAL label in the accent blue. */
.mobile-row-total td {
    font-weight: 700;
    color: #cbd2dc;
    background: #11161d;
    border-bottom: 1px solid #2a3340;
}
.mobile-row-total .mobile-bot-cell { color: #4fa8ff; letter-spacing: 0.03em; }

.mobile-bot-row { cursor: pointer; }
.mobile-bot-row:active { background: #161b22; }

.mobile-bot-name {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
    color: #eaecef;
}
.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; }

/* PnL colours (reuse the fleet green/red) — only Total + Unmatched are tinted. */
.mobile-num.profit-pos { color: #4caf72; }
.mobile-num.profit-neg { color: #ff7676; }

/* 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: #c2cad6; }
.mobile-dual-sub { color: #7d8794; font-size: 11px; }
.mobile-row-total .mobile-dual-sub { display: block; line-height: 1.2; }

/* 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 { position: static; }
}
