  :root {
    --bg: #0d0d0d;
    --surface: #161616;
    --surface2: #1e1e1e;
    --border: #2a2a2a;
    --text: #e0e0e0;
    --muted: #888;
    --green: #22c55e;
    --yellow: #eab308;
    --blue: #3b82f6;
    --red: #ef4444;
    --orange: #f97316;
    --accent: #6366f1;
    --profit: #22c55e;
    --loss: #ef4444;
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
    min-height: 100vh;
  }

  /* Engine state stripe */
  #engine-stripe {
    position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 200;
    background: #2a2a2a;
    transition: background 0.4s;
  }
  #engine-stripe.running { background: var(--green); }
  #engine-stripe.stopped { background: var(--red); }

  /* Layout */
  .topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 20px;
    margin-top: 3px;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    position: sticky;
    top: 3px;
    z-index: 100;
  }
  .topbar h1 { font-size: 16px; font-weight: 600; letter-spacing: 0.5px; }
  .app-version { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; margin-left: -10px; }
  .topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

  /* Engine chip in topbar */
  .engine-chip {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 600;
    letter-spacing: 0.4px; text-transform: uppercase; line-height: 1;
    border: 1px solid var(--border); background: var(--surface2); color: var(--muted);
    transition: background 0.3s, border-color 0.3s, color 0.3s;
  }
  .engine-chip .ec-dot {
    width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex-shrink: 0;
  }
  .engine-chip.running { color: var(--green); border-color: rgba(34,197,94,0.35); background: rgba(34,197,94,0.08); }
  .engine-chip.stopped { color: var(--red);   border-color: rgba(239,68,68,0.35);  background: rgba(239,68,68,0.07);  }

  /* Tabs */
  .tabs {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    display: flex;
    gap: 4px;
    position: sticky;
    top: 60px;
    z-index: 90;
    overflow-x: auto;
  }
  .tab {
    padding: 10px 18px;
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    letter-spacing: 0.3px;
  }
  .tab:hover { color: var(--text); }
  .tab.active { color: var(--accent); border-bottom-color: var(--accent); }

  .main { padding: 20px; display: grid; gap: 16px; max-width: 1400px; margin: 0 auto; }
  .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  .grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
  @media (max-width: 900px) {
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
  }

  .tab-pane { display: none; }
  .tab-pane.active { display: grid; gap: 16px; }

  /* Grid/flex items default to min-width:auto, which refuses to shrink below
     their content — so a wide table propagates its width up the tree and
     overflows the viewport, breaking the sticky header on horizontal scroll.
     min-width:0 lets each level shrink so the inner overflow-x:auto wrappers
     actually contain their tables. */
  .tab-pane, .grid-2, .grid-3 { min-width: 0; }
  .tab-pane > *, .grid-2 > *, .grid-3 > * { min-width: 0; }

  /* Cards */
  .card {
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
  }
  .card-title {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 12px;
  }
  .card-subtitle {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 12px;
  }

  /* Status badge */
  .badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1;   /* pill text sat low without it; the topbar centres each item, this centres the text inside the pill */
  }
  .badge::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
  }
  .badge-idle     { background: #1a2a1a; color: var(--green); }
  .badge-scanning { background: #1a2a1a; color: var(--green); }
  .badge-executing { background: #1a2a1a; color: var(--green); }
  .badge-transferring { background: #1a1a2a; color: var(--blue); }
  .badge-halted   { background: #2a1a1a; color: var(--red); }
  .badge-paused   { background: #2a2a1a; color: var(--yellow); }
  .badge-unknown  { background: #2a2a2a; color: var(--muted); }
  .badge-dry { background: #2a1a2a; color: var(--orange); font-size: 11px; }
  .badge-live { background: #1a2a1a; color: var(--green); font-size: 11px; }
  .badge-otc { background: #1a1a2a; color: var(--accent); font-size: 11px; }

  /* Exchange columns */
  .exchanges { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; }
  .exch-card { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; background: rgba(255,255,255,0.015); }
  .exch-name { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 10px; }
  .exch-row { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 5px; font-size: 13px; }
  .exch-row span:first-child { color: var(--muted); min-width: 38px; }
  .exch-row span:last-child { font-variant-numeric: tabular-nums; font-weight: 500; }
  .exch-row-zero span { color: var(--muted); font-weight: 400; }
  .holdings-summary { display: flex; gap: 30px; flex-wrap: wrap; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }
  .holdings-summary > div { display: flex; flex-direction: column; gap: 3px; }
  .hs-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); }
  .hs-val { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }

  /* Spread panel */
  .spread-big { font-size: 36px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: center; margin: 8px 0; }
  .spread-direction { text-align: center; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
  .depth-table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
  .depth-table th { color: var(--muted); text-align: right; padding: 2px 6px; font-weight: 500; border-bottom: 1px solid var(--border); }
  .depth-table th:first-child { text-align: left; }
  .depth-table td { padding: 3px 6px; text-align: right; }
  .depth-table td:first-child { text-align: left; color: var(--muted); font-size: 11px; }
  .depth-bid td:nth-child(2) { color: var(--green); }
  .depth-ask td:nth-child(2) { color: var(--red); }
  .depth-bar-cell { position: relative; }
  .depth-bar { position: absolute; top: 2px; bottom: 2px; right: 0; border-radius: 2px; opacity: 0.18; pointer-events: none; }
  .depth-bar-bid { background: var(--green); }
  .depth-bar-ask { background: var(--red); }

  /* Engine status display */
  .engine-status-block {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 14px;
    background: var(--surface2);
    border: 1px solid var(--border);
    transition: border-color 0.3s, background 0.3s;
  }
  .engine-status-block.running {
    background: rgba(34,197,94,0.06);
    border-color: rgba(34,197,94,0.3);
  }
  .engine-status-block.stopped {
    background: rgba(239,68,68,0.05);
    border-color: rgba(239,68,68,0.2);
  }
  .engine-pulse {
    position: relative;
    width: 12px; height: 12px; flex-shrink: 0;
  }
  .engine-pulse-dot {
    width: 12px; height: 12px; border-radius: 50%;
    background: var(--muted);
    transition: background 0.3s;
  }
  .engine-pulse-ring {
    position: absolute; inset: 0;
    border-radius: 50%;
    border: 2px solid transparent;
    opacity: 0;
  }
  .engine-status-block.running .engine-pulse-dot { background: var(--green); }
  .engine-status-block.running .engine-pulse-ring {
    border-color: var(--green);
    opacity: 1;
    animation: pulse-ring 1.8s ease-out infinite;
  }
  .engine-status-block.stopped .engine-pulse-dot { background: var(--red); }
  @keyframes pulse-ring {
    0%   { transform: scale(1);   opacity: 0.7; }
    100% { transform: scale(2.4); opacity: 0; }
  }
  .engine-status-text { flex: 1; min-width: 0; }
  .engine-status-label { font-size: 14px; font-weight: 600; }
  .engine-status-meta  { font-size: 12px; color: var(--muted); margin-top: 2px; }
  .dashboard-activity-card { padding: 0; overflow: hidden; }
  .dashboard-activity-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.55px;
    text-transform: uppercase;
  }
  .engine-activity-panel {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(255,255,255,0.015);
    margin-bottom: 8px;
    overflow: hidden;
  }
  .engine-activity-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 11px;
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-size: 10px;
    letter-spacing: 0.55px;
    text-transform: uppercase;
  }
  .engine-activity-current {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 11px;
  }
  .engine-activity-dot {
    width: 9px;
    height: 9px;
    margin-top: 4px;
    border-radius: 50%;
    flex: 0 0 auto;
    background: var(--muted);
    box-shadow: 0 0 0 3px rgba(148,163,184,0.10);
  }
  .engine-activity-dot.busy {
    background: var(--accent);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.14);
    animation: activity-pulse 1.4s ease-in-out infinite;
  }
  .engine-activity-dot.good { background: var(--green); box-shadow: 0 0 0 3px rgba(34,197,94,0.12); }
  .engine-activity-dot.warn { background: var(--yellow); box-shadow: 0 0 0 3px rgba(234,179,8,0.12); }
  .engine-activity-dot.bad  { background: var(--red); box-shadow: 0 0 0 3px rgba(239,68,68,0.12); }
  @keyframes activity-pulse {
    0%, 100% { opacity: 0.45; transform: scale(0.82); }
    50% { opacity: 1; transform: scale(1.08); }
  }
  .engine-activity-label { font-size: 13px; font-weight: 600; }
  .engine-activity-detail { color: var(--muted); font-size: 11px; margin-top: 2px; }
  .engine-activity-log {
    border-top: 1px solid var(--border);
    padding: 5px 11px 8px;
    max-height: 78px;
    overflow: auto;
  }
  .engine-activity-log-empty { color: var(--muted); font-size: 10px; padding-top: 3px; }
  .engine-activity-log-row {
    display: grid;
    grid-template-columns: 54px 1fr;
    gap: 8px;
    color: var(--muted);
    font-size: 10px;
    padding-top: 4px;
  }
  .engine-activity-log-row span:last-child { color: var(--text); }
  .safety-mode-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .readonly-badge {
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    font-size: 9px;
    letter-spacing: 0.45px;
    padding: 3px 7px;
    text-transform: uppercase;
  }
  .viewer-only { display: none; }
  .viewer-mode-hint { margin-top: 10px; }
  .btn-engine {
    padding: 8px 20px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: opacity 0.15s, transform 0.1s;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .btn-engine:hover { opacity: 0.85; }
  .btn-engine:active { transform: scale(0.97); }
  .btn-engine:disabled { opacity: 0.4; cursor: not-allowed; }
  .btn-engine.start { background: var(--green); color: #0a0a0a; }
  .btn-engine.stop  { background: var(--red);   color: #fff; }

  /* Controls */
  .btn {
    padding: 7px 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface2);
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s, border-color 0.15s;
  }
  .btn:hover { background: #2a2a2a; }
  .btn-green { border-color: var(--green); color: var(--green); }
  .btn-green:hover { background: rgba(34,197,94,0.1); }
  .btn-yellow { border-color: var(--yellow); color: var(--yellow); }
  .btn-yellow:hover { background: rgba(234,179,8,0.1); }
  .btn-red { border-color: var(--red); color: var(--red); }
  .btn-red:hover { background: rgba(239,68,68,0.1); }
  .btn:disabled { opacity: 0.4; cursor: not-allowed; }
  .controls-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }

  /* Toggle switch */
  .switch { position: relative; display: inline-block; width: 46px; height: 24px; }
  .switch input { opacity: 0; width: 0; height: 0; }
  .switch-slider {
    position: absolute; cursor: pointer; inset: 0;
    background: var(--surface2); border: 1px solid var(--border); border-radius: 24px;
    transition: 0.2s;
  }
  .switch-slider::before {
    position: absolute; content: "";
    height: 16px; width: 16px; left: 3px; top: 3px;
    background: var(--muted); border-radius: 50%; transition: 0.2s;
  }
  .switch input:checked + .switch-slider { border-color: var(--orange); background: rgba(249,115,22,0.15); }
  .switch input:checked + .switch-slider::before { transform: translateX(22px); background: var(--orange); }
  .switch-row { display: flex; align-items: center; gap: 12px; }

  /* Config rows */
  .config-row {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid #1a1a1a;
  }
  .config-row:last-child { border-bottom: none; }
  .config-row.modified { background: rgba(234,179,8,0.04); border-radius: 6px; padding: 10px 8px; margin: 0 -8px; }
  .config-label-col { flex: 1; min-width: 0; }
  .config-label { font-size: 13px; font-weight: 500; color: var(--text); }
  .config-desc  { font-size: 11px; color: var(--muted); margin-top: 2px; }
  .config-input-col { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
  .config-input {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 6px 10px;
    font-size: 13px;
    width: 110px;
    text-align: right;
    font-variant-numeric: tabular-nums;
  }
  .config-input:focus { outline: none; border-color: var(--accent); }
  /* Inline entry forms (BTC inventory deposits, settlement costs): label above
     its input, everything bottom-aligned on one row, wrapping on narrow screens.
     Visibility is toggled with the hidden attribute, never inline display, so
     the flex layout is never lost on re-render. */
  .entry-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-top: 12px; }
  .entry-form[hidden] { display: none; }
  .entry-field { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
  .entry-field-grow { flex: 1 1 180px; min-width: 160px; }
  .entry-input {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 6px 10px;
    font-size: 13px;
    height: 32px;
    box-sizing: border-box;
    width: 100%;
    font-variant-numeric: tabular-nums;
    color-scheme: dark;
  }
  .entry-input:focus { outline: none; border-color: var(--accent); }
  .entry-form .btn { height: 32px; }
  .config-input.modified { border-color: var(--yellow); box-shadow: 0 0 0 2px rgba(234,179,8,0.15); }
  .config-meta { font-size: 11px; color: var(--muted); text-align: right; line-height: 1.5; min-width: 80px; }
  .config-save-btn {
    padding: 5px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--muted);
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    transition: border-color 0.15s, color 0.15s;
  }
  .config-save-btn:hover { border-color: var(--accent); color: var(--accent); }
  .config-save-btn.saved { border-color: var(--green); color: var(--green); }
  .config-group-sep { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); padding: 8px 0 4px; margin-top: 4px; border-top: 1px solid var(--border); }
  .config-group-sep:first-child { border-top: none; margin-top: 0; padding-top: 0; }

  /* Trade table */
  .trade-table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
  .trade-table th {
    color: var(--muted); text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--border);
    font-weight: 500; font-size: 11px; text-transform: uppercase; cursor: pointer; white-space: nowrap; user-select: none;
  }
  .trade-table th:first-child { text-align: left; }
  .trade-table th:hover { color: var(--text); }
  .trade-table td { padding: 6px 8px; text-align: right; border-bottom: 1px solid #1a1a1a; white-space: nowrap; }
  .trade-table td:first-child { text-align: left; color: var(--muted); }
  .trade-table tbody tr:hover { background: rgba(255,255,255,0.02); }
  .trade-table tbody tr:last-child td { border-bottom: none; }
  .sort-icon { font-size: 10px; margin-left: 2px; }

  /* PnL summary boxes */
  .pnl-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
  @media (max-width: 700px) { .pnl-grid { grid-template-columns: 1fr 1fr; } }
  /* Five-tile rows — one row wide, or the fifth wraps alone under the others. */
  .pnl-grid.pnl-grid-5 { grid-template-columns: repeat(5, 1fr); }
  @media (max-width: 900px) { .pnl-grid.pnl-grid-5 { grid-template-columns: 1fr 1fr; } }
  /* The Inventory card: total owned, held, avg cost, deposit fees, mid, unrealized. */
  .pnl-grid.pnl-grid-6 { grid-template-columns: repeat(6, 1fr); }
  @media (max-width: 1100px) { .pnl-grid.pnl-grid-6 { grid-template-columns: repeat(3, 1fr); } }
  @media (max-width: 700px) { .pnl-grid.pnl-grid-6 { grid-template-columns: 1fr 1fr; } }
  /* The Inventory card with the initial (deposited) coins in front of the six above. */
  .pnl-grid.pnl-grid-7 { grid-template-columns: repeat(7, 1fr); }
  @media (max-width: 1300px) { .pnl-grid.pnl-grid-7 { grid-template-columns: repeat(4, 1fr); } }
  @media (max-width: 700px) { .pnl-grid.pnl-grid-7 { grid-template-columns: 1fr 1fr; } }
  .pnl-box { background: var(--surface2); border-radius: 6px; padding: 12px; text-align: center; }
  .pnl-box-label { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
  .pnl-box-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
  .pnl-section + .pnl-section { margin-top: 14px; }
  .pnl-section-title { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
  .pnl-section-note { font-size: 11px; font-weight: 400; color: var(--muted); margin-left: 6px; }
  /* Trades & P&L / Inventory layout (2026-10-06): tiles grouped under small
     headings, one compact filter toolbar, collapsible analysis cards, and the
     inventory ledger breakdown as a two-column list. Presentation only. */
  .pnl-group-title { font-size: 11px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); margin: 14px 0 6px; }
  .pnl-group-title:first-of-type { margin-top: 0; }
  .pnl-grid.pnl-grid-3 { grid-template-columns: 1.6fr 1fr 1fr; }
  .pnl-grid.pnl-grid-2 { grid-template-columns: repeat(2, 1fr); }
  .pnl-box-lg .pnl-box-value { font-size: 30px; }
  @media (max-width: 700px) {
    .pnl-grid.pnl-grid-3 { grid-template-columns: 1fr 1fr; }
    .pnl-grid.pnl-grid-3 .pnl-box-lg { grid-column: 1 / -1; }
  }
  .pnl-toolbar { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; justify-content: space-between; margin-bottom: 14px; }
  .pnl-toolbar-group { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
  .pnl-toolbar-group label { font-size: 12px; color: var(--muted); }
  .pnl-toolbar-group label input { margin-left: 4px; }
  .pnl-toolbar-note { font-size: 12px; color: var(--muted); }
  .table-wrap { overflow-x: auto; }
  .card-title-hint { font-size: 11px; font-weight: 400; color: var(--muted); margin-left: 6px; text-transform: none; letter-spacing: 0; }
  .pnl-adj-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
  .pnl-adj-actions { display: flex; gap: 8px; align-items: center; }
  details.card-collapsible > summary { cursor: pointer; list-style: none; margin-bottom: 0; }
  details.card-collapsible > summary::-webkit-details-marker { display: none; }
  details.card-collapsible > summary::before { content: "B8"; display: inline-block; margin-right: 6px; }
  details.card-collapsible[open] > summary::before { content: "BE"; }
  details.card-collapsible[open] > summary { margin-bottom: 12px; }
  .section-heading { font-size: 13px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); margin: 8px 0 -4px; padding-top: 12px; border-top: 1px solid var(--border); }
  .inv-actions { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-top: 10px; }
  .inv-breakdown { margin-top: 10px; max-width: 420px; font-size: 12px; }
  .inv-breakdown-title { font-size: 11px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
  .inv-breakdown-row { display: flex; justify-content: space-between; gap: 16px; padding: 2px 0; border-bottom: 1px solid var(--border); }
  .inv-breakdown-row:last-child { border-bottom: none; }
  .inv-breakdown-row span:first-child { color: var(--muted); }
  .inv-breakdown-row span:last-child { font-variant-numeric: tabular-nums; text-align: right; }

  /* Keep the unresolved-short recovery action compact inside its table cell. */
  .pending-short-recovery { display: grid; gap: 8px; }
  .pending-short-recovery:not(:empty) { margin-bottom: 12px; }
  .short-recovery-card { display: flex; align-items: center; justify-content: space-between;
    gap: 8px 20px; flex-wrap: wrap; padding: 10px 12px; border: 1px solid var(--yellow);
    border-radius: 6px; font-size: 12px; overflow-wrap: anywhere; }
  .hand-buyback-recovery { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; max-width: 240px; text-align: left; }
  .hand-buyback-title { color: var(--yellow); font-size: 11px; font-weight: 600; white-space: nowrap; }
  .hand-buyback-button { background: transparent; border: 1px solid var(--yellow); color: var(--yellow); border-radius: 4px; padding: 4px 7px; font-size: 11px; cursor: pointer; white-space: nowrap; }

  /* Misc */
  .refresh-indicator { font-size: 11px; color: var(--muted); }
  .auth-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 20px; font-size: 11px; background: var(--surface2); border: 1px solid var(--border); color: var(--muted); }
  .auth-chip.ok { color: var(--green); border-color: rgba(34,197,94,0.3); }
  .auth-chip.bad { color: var(--red); border-color: rgba(239,68,68,0.3); }
  .error-banner { background: rgba(239,68,68,0.1); border: 1px solid var(--red); border-radius: 6px; padding: 10px 14px; color: var(--red); margin-bottom: 12px; font-size: 13px; display: none; }
  .section-sep { border: none; border-top: 1px solid var(--border); margin: 4px 0 12px; }
  .imbalance-warn { color: var(--orange); font-size: 12px; margin-top: 6px; }
  .dir-box { background: rgba(255,255,255,0.03); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; flex: 1; min-width: 0; }
  .dir-box.opp { border-color: rgba(34,197,94,0.4); background: rgba(34,197,94,0.04); }
  .dir-box.nofill { opacity: 0.55; }
  .dir-box-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); margin-bottom: 8px; }
  .dir-row { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 3px; }
  .dir-row span:first-child { color: var(--muted); }
  .formula-block { background: rgba(0,0,0,0.25); border: 1px solid rgba(255,255,255,0.07); border-radius: 4px; padding: 8px 10px; margin-top: 10px; font-size: 11px; font-family: monospace; line-height: 1.7; }
  .formula-step { color: var(--muted); }
  .formula-step b { color: var(--text); font-weight: 500; }
  .formula-result { color: var(--text); font-weight: 600; }
  .pair-bal-row { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 3px; }
  .tag-dry { display: inline-block; background: rgba(249,115,22,0.15); color: var(--orange); border-radius: 3px; font-size: 10px; padding: 1px 5px; margin-left: 4px; vertical-align: middle; }
  .tag-blocked { display: inline-block; background: rgba(234,179,8,0.15); color: var(--yellow); border-radius: 3px; font-size: 10px; padding: 1px 5px; margin-left: 4px; vertical-align: middle; }
  .val-pos { color: var(--green); }
  .val-neg { color: var(--red); }
  .val-zero { color: var(--muted); }
  .val-warn { color: var(--yellow); }
  .intent-fill { width: 92px; }
  .cycle-time { font-size: 12px; color: var(--muted); }
  .no-data { color: var(--muted); font-size: 12px; text-align: center; padding: 24px 0; }
  .halt-reason { font-size: 12px; color: var(--red); margin-top: 4px; }
  .spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }
  .env-table { width: 100%; border-collapse: collapse; font-size: 13px; }
  .env-table td { padding: 4px 6px; vertical-align: middle; }
  .env-input {
    width: 100%; background: var(--surface2); color: var(--text);
    border: 1px solid var(--border); border-radius: 4px; padding: 4px 6px;
    font-family: Consolas, monospace; font-size: 12px;
  }
  /* Mask secret fields visually WITHOUT type="password", so Chromium never
     offers to save them as a login. Applied to text inputs. */
  .masked { -webkit-text-security: disc; text-security: disc; }
  /* Same "unsaved edit" cue as .config-input.modified, reused here for the
     Luno beneficiary picker's "Use this" — it never auto-saves. */
  .env-input.modified { border-color: var(--yellow); box-shadow: 0 0 0 2px rgba(234,179,8,0.15); }
  .key-cell { color: var(--muted); white-space: nowrap; font-family: Consolas, monospace; font-size: 12px; }
  .hint { font-size: 12px; color: var(--muted); }
  .hint.warn { color: var(--orange); }
  .section-group { display: grid; gap: 16px; }

  /* Portal adapter test pane */
  .ad-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  @media (max-width: 640px) { .ad-grid { grid-template-columns: 1fr; } }
  .ad-field-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
  .ad-row { border: 1px solid var(--border); border-radius: 6px; margin-bottom: 10px; overflow: hidden; }
  .ad-row:last-child { margin-bottom: 0; }
  .ad-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface2); flex-wrap: wrap; }
  .ad-method { font: 700 11px Consolas, monospace; padding: 2px 8px; border-radius: 4px; }
  .ad-method.get { background: rgba(59,130,246,0.15); color: var(--blue); }
  .ad-method.post { background: rgba(249,115,22,0.15); color: var(--orange); }
  .ad-path { font-size: 12px; color: var(--text); flex: 1; min-width: 150px; }
  .ad-pill { font: 700 11px Consolas, monospace; padding: 2px 9px; border-radius: 20px; border: 1px solid var(--border); color: var(--muted); }
  .ad-pill.ok  { background: rgba(34,197,94,0.12); color: var(--green); border-color: transparent; }
  .ad-pill.err { background: rgba(239,68,68,0.12); color: var(--red);   border-color: transparent; }
  .ad-body { border-top: 1px solid var(--border); }
  .ad-pre { margin: 0; padding: 12px; background: var(--bg); color: var(--text); font: 12px/1.5 Consolas, monospace; overflow-x: auto; white-space: pre; max-height: 340px; }
  .ad-pre.bad { color: var(--red); }
  .ad-metrics { width: 100%; border-collapse: collapse; font-size: 12px; }
  .ad-metrics td { padding: 6px 12px; border-bottom: 1px solid var(--border); font-family: Consolas, monospace; }
  .ad-metrics tr:last-child td { border-bottom: 0; }
  .ad-metrics td:first-child { color: var(--muted); width: 46%; }
  .ad-good { color: var(--green); } .ad-bad { color: var(--red); } .ad-flag { color: var(--orange); }

  /* ── Login gate ────────────────────────────────────────────────────────── */
  .login-overlay {
    position: fixed; inset: 0; z-index: 500;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg);
    padding: 20px;
  }
  .login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 28px;
    width: 100%; max-width: 360px;
  }
  .login-card h2 { font-size: 20px; margin-bottom: 4px; }
  .login-sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
  .login-card label {
    display: block; color: var(--muted); font-size: 12px; margin-bottom: 5px;
  }
  .login-card input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 14px;
    padding: 9px 10px;
    margin-bottom: 10px;
  }
  .login-card input:focus { outline: none; border-color: var(--accent); }
  .login-btn {
    width: 100%;
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 4px;
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    padding: 9px;
  }
  .login-btn:disabled { opacity: 0.6; cursor: default; }
  .login-error {
    background: rgba(239,68,68,0.12);
    border-radius: 4px;
    color: var(--red);
    font-size: 12px;
    margin-top: 14px;
    padding: 9px 10px;
  }

  /* ── Record settlement dialog (Inventory) ─────────────────────────────────
     Modelled on .login-overlay/.login-card — the only modal idiom this app
     already has — but semi-transparent (the dashboard stays visible, just
     dimmed) rather than opaque (the login gate replaces the whole page). */
  .rs-overlay {
    position: fixed; inset: 0; z-index: 600;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.55);
    padding: 20px;
  }
  .rs-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 24px;
    width: 100%; max-width: 560px;
    max-height: 90vh; overflow-y: auto;
  }
  .rs-card h2 { font-size: 18px; margin-bottom: 4px; }
  .rs-sub { color: var(--muted); font-size: 12px; margin-bottom: 16px; }
  .rs-section { border: 1px solid var(--border); border-radius: 6px; padding: 12px; margin-bottom: 12px; }
  /* A half already saved: dimmed, not hidden — the operator can still see
     what it said, just not edit it (fields are `disabled`, not removed). */
  .rs-section.rs-done { opacity: 0.7; }
  .rs-section-title {
    font-size: 13px; font-weight: 600; margin-bottom: 8px;
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
  }
  .rs-section input[type="text"] {
    width: 100%; background: var(--bg); border: 1px solid var(--border);
    border-radius: 4px; color: var(--text); font-size: 13px; padding: 7px 8px;
    margin-bottom: 8px; box-sizing: border-box;
  }
  .rs-section input:focus { outline: none; border-color: var(--accent); }
  .rs-b-row { display: flex; align-items: center; gap: 8px; font-size: 12px; padding: 3px 0; }
  .rs-error:empty { display: none; }
  .rs-error { color: var(--red); font-size: 12px; margin-top: 6px; }
  .rs-summary {
    font-size: 12px; color: var(--muted); margin: 10px 0; padding: 8px 10px;
    background: var(--bg); border-radius: 4px; border: 1px solid var(--border);
  }
  .rs-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }

  /* Viewer mode — presentation only. The server refuses a viewer's writes
     regardless of what is hidden here; this keeps the UI honest, not safe. */
  body.viewer-mode .operator-only { display: none !important; }
  /* Portal Operator role: the admin surface (credentials, service, exchange
     enablement, state reset) is hidden; the server refuses it regardless. */
  body.operator-mode .admin-only { display: none !important; }
  body.viewer-mode .viewer-only { display: inline-flex; }
  body.viewer-mode .viewer-mode-hint { display: block; }
  body.viewer-mode .safety-mode-card .switch { cursor: not-allowed; opacity: 0.6; }
  body.viewer-mode .safety-mode-card input:disabled + .switch-slider { cursor: not-allowed; }

  /* Sub-tab bars (Runtime Config + Settings): same look as the main .tabs
     nav - plain muted text, accent + 2px underline when active, one thin
     line under the whole bar. Wraps onto extra rows on a phone, so the page
     never scrolls sideways. */
  .subtab-bar {
    display: flex; flex-wrap: wrap; gap: 0 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 14px; max-width: 100%;
  }
  .subtab-bar .btn {
    padding: 9px 14px; background: transparent; border: none; border-radius: 0;
    border-bottom: 2px solid transparent; margin-bottom: -1px;
    color: var(--muted); font-size: 13px; font-weight: 500;
    letter-spacing: 0.3px; white-space: nowrap;
  }
  .subtab-bar .btn:hover { background: transparent; color: var(--text); }
  .subtab-bar .btn.active { color: var(--accent); border-bottom-color: var(--accent); }
  .subtab-dot {
    display: inline-block; width: 6px; height: 6px; border-radius: 50%;
    background: var(--green); margin-left: 6px; vertical-align: middle;
  }
