/*
 * Fitting the Performance, Research, Optimizer, Bots and New bot pages to
 * the window (owner's request, 2026-10-17: "everything at our fingertips
 * or a mouse click"). Builds on css/fit.css: section tabs, boxed tables
 * and side-by-side columns.
 */

/* Performance: the heading and its two tabs share one line. */
.perf-head { display: flex; align-items: flex-end; gap: var(--space-2) var(--space-5); flex-wrap: wrap; margin-bottom: var(--space-3); }
.perf-head .page-tabs { margin-bottom: 0; flex: 0 1 auto; }

/* Report card: the graded bots in a box, what to do first beside them on a wide screen. */
.rc-cards { padding: 2px; }
@media (min-width: 1101px) {
  .rc-cols > .rc-first { order: 2; }
  .rc-cols.rc-one { grid-template-columns: minmax(0, 1fr); }
}
/* Kept to the window (fitToWindow, wide screens only): the boxes take its height, not the window's less a guess. */
@media (min-width: 1101px) and (min-height: 640px) {
  .fit .rc-cards, .fit .rc-first { max-height: none; }
}

/* Each page's boxed tables, as tall as the window less what sits above and
   below them there, so the page itself stops at the window's foot. */
@media (min-width: 1101px) and (min-height: 640px) {
  #an-tabs .fit-table { max-height: max(260px, calc(100dvh - 400px)); }
  #bots-list.fit-table { max-height: max(300px, calc(100dvh - 140px)); }
  #sb-sources .fit-table, #sb-recent .fit-table { max-height: max(260px, calc(100dvh - 380px)); }
  #kn-rows .fit-table { max-height: max(260px, calc(100dvh - 420px)); }
}
@media (max-width: 1100px) {
  /* Above the cards on a narrow screen, a short box of its own. */
  .rc-first { max-height: none; }
}

/* Optimizer: the page uses the width, and a tab's own label stands for its heading. */
.opt-page { max-width: none; }
[data-opt-tabs] > .opt-section { margin-top: 0; }
[data-opt-tabs] > .opt-section > .opt-h2 {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* Bots: a search and two filters above the list, as on the dashboard. */
.bots-filter { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; margin-bottom: var(--space-3); }
.bots-filter input[type="search"] { flex: 1 1 220px; min-width: 0; max-width: 360px; height: 36px; padding: 0 10px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); background: var(--color-surface); color: var(--color-text); font: inherit; font-size: 0.875rem; }
.bots-filter input[type="search"]:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 1px; }
.bots-filter-group { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.bots-count { margin-left: auto; font-size: 0.8rem; color: var(--color-text-muted); white-space: nowrap; }
#bots-tabs .ai-usage-panel { margin-top: 0; }
/* The rows a little tighter than a reading table: more bots in the box. */
.fit-bots .rtable td { padding-top: 6px; padding-bottom: 6px; }
/* One line a bot on a wide screen: an amount broken over two lines doubled every row. */
@media (min-width: 640px) {
  .fit-bots .rtable td, .fit-bots .rtable th { white-space: nowrap; padding-left: 8px; padding-right: 8px; }
  /* The name, the kind and the pair wrap, so the figures keep one line each and every column fits. */
  .fit-bots .rtable td[data-primary], .fit-bots .rtable td[data-label="Strategy"], .fit-bots .rtable td[data-label="Pair"] { white-space: normal; }
  .fit-bots .rtable td[data-primary] { min-width: 120px; overflow-wrap: anywhere; }
  /* What the profit was made on breaks over two lines only when the table is short of room. */
  .fit-bots .rtable [data-invested] { white-space: normal !important; }
}
/* A paper bot ready to promote (owner's request, 2026-11-01): a light green row. */
.fit-bots .rtable tr.is-promotable td { background: var(--color-promote-bg); }
.fit-bots .rtable tr.is-promotable:hover td { background: var(--color-promote-bg-hover); }
/* A bot not running (owner's request, 2026-11-01): a light red row. */
.fit-bots .rtable tr.is-not-running td { background: var(--color-stopped-bg); }
.fit-bots .rtable tr.is-not-running:hover td { background: var(--color-stopped-bg-hover); }
/* A figure's second line (the sells, the free capital) small and muted. */
.fit-bots .bots-sub { font-size: 0.7rem; color: var(--color-text-muted); white-space: nowrap; }
.fit-bots .bots-mode { white-space: nowrap; }
.fit-bots .bots-mode .mode-pill { font-size: 0.65rem !important; padding: 0 6px !important; vertical-align: 1px; }
/* Delete as a bin: square, in the danger colour. */
.fit-bots .bots-delete { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; color: var(--color-danger); }
@media (max-width: 768px) {
  .bots-filter input[type="search"] { flex-basis: 100%; max-width: none; height: 44px; }
  .bots-filter button.toggle-btn { min-height: 44px; }
  .bots-count { margin-left: 0; }
}
/* Too narrow for every column (the table needs about 1040px; a 1280px
   window gives it 1128): each bot is a card, its figures several to a line,
   each name above its value. It goes by the list's own width, not the
   window's, so the sidebar opening or closing cannot cut a column off. */
.fit-bots { container: bots / inline-size; }
@container bots (max-width: 1039.98px) {
  .fit-bots .rtable thead { display: none; }
  .fit-bots .rtable, .fit-bots .rtable tbody { display: block; width: 100%; min-width: 0 !important; }
  .fit-bots .rtable tr {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
    gap: 6px 12px;
    padding: var(--space-3);
    margin-bottom: var(--space-3);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
  }
  .fit-bots .rtable tr:hover td { background: none; }
  /* A paper bot ready to promote (owner's request, 2026-11-01): the whole card green, its cells clear. */
  .fit-bots .rtable tr.is-promotable { background: var(--color-promote-bg); border-color: var(--color-promote-border); }
  .fit-bots .rtable tr.is-promotable td, .fit-bots .rtable tr.is-promotable:hover td { background: none; }
  .fit-bots .rtable tr.is-not-running { background: var(--color-stopped-bg); border-color: var(--color-stopped-border); }
  .fit-bots .rtable tr.is-not-running td, .fit-bots .rtable tr.is-not-running:hover td { background: none; }
  .fit-bots .rtable td {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
    gap: 0;
    min-width: 0;
    padding: 2px 0 !important;
    border: none !important;
    text-align: left !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
  }
  .fit-bots .rtable td::before { content: attr(data-label); color: var(--color-text-muted); font-size: 0.68rem; font-weight: 400; }
  .fit-bots .rtable td[data-empty] { display: none; }
  /* The name across two columns, on the card's first line with Delete at its end. */
  .fit-bots .rtable td[data-primary] { grid-column: span 2; align-self: center; font-size: 0.95rem; }
  .fit-bots .rtable td[data-primary]::before { content: none; }
  .fit-bots .rtable td:last-child { order: 0 !important; grid-column: -2 / -1; align-items: flex-end; }
  .fit-bots .rtable td:last-child::before { content: none; }
  /* "Invested of total" wants two columns; Take home the whole line. */
  .fit-bots .rtable td[data-label="Capital"] { grid-column: span 2; }
  .fit-bots .rtable td[data-label="Take home"] { grid-column: 1 / -1; }
  .fit-bots .rtable td .text-mono, .fit-bots .bots-sub, .fit-bots .rtable [data-invested] { white-space: normal !important; }
}

/* New bot: the strategy's groups in two columns on a wide screen. */
@media (min-width: 1280px) {
  .create-config-groups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); align-items: start; }
}
/* Create and Cancel stay at the foot of the window while the form scrolls. */
.create-bar {
  grid-column: 1 / -1; position: sticky; bottom: 0; z-index: 5;
  padding: var(--space-3) var(--space-4); margin: 0 calc(-1 * var(--space-2));
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md);
  box-shadow: 0 -6px 16px rgba(0, 0, 0, 0.18);
}
.create-bar-note { font-size: 0.78rem; color: var(--color-text-muted); }
.create-bar-btn:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
@media (max-width: 768px) {
  /* Above the phone's bottom bar, not behind it. */
  .create-bar { bottom: calc(62px + env(safe-area-inset-bottom)); margin: 0; padding: var(--space-2) var(--space-3); }
  .create-bar-btn { min-height: 44px; }
  .create-bar-note { display: none; }
}
