/*
 * The client app's pages (frontend/views). The palette — colours, dark mode, the brand's accent (--brand-accent…, set on
 * <html> by the layout) — is the shared design tokens' .tb-theme-client (common/assets/widgets/tokens.css, TokensAsset);
 * this file uses its variables only. The settings form, the preview, the markets picker and the stop-to-target bar have
 * their own shared styles (common/web/shared).
 */
* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.top h1 { margin: 0; font-size: 18px; }
.top .brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.top .logo { height: 28px; width: auto; max-width: 120px; object-fit: contain; }
.top-actions { display: flex; gap: 16px; }

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

h2 { font-size: 17px; margin: 24px 0 8px; }
h2:first-child { margin-top: 0; }
h3 { font-size: 15px; margin: 20px 0 8px; }
.card > h3:first-child { margin-top: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 12px;
}

.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--danger); font-size: 14px; margin: 8px 0 0; }
.notice { text-align: center; padding: 48px 16px; }

label { display: block; font-weight: 600; margin-bottom: 6px; }

input[type="password"], input[type="text"], input[type="email"] {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

button {
  font: inherit;
  font-weight: 600;
  min-height: 44px;
  padding: 10px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
}

button:disabled { opacity: .55; cursor: default; }
button.secondary { background: transparent; color: var(--accent-text); border: 1px solid var(--line); }
button.danger { background: var(--danger); color: var(--on-danger); }
button.link { background: none; color: var(--accent-text); min-height: 0; padding: 4px 0; }
button.block { width: 100%; margin-top: 12px; }

.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.row button { flex: 1 1 auto; }

.head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.head strong { font-size: 16px; }

.badge {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid currentColor;
  white-space: nowrap;
}

.state-running { color: var(--ok); }
.state-waiting { color: var(--muted); }
.state-paused { color: var(--warn); }
.state-problem { color: var(--danger); }
.state-stopped { color: var(--muted); }

.figures { display: flex; justify-content: space-between; margin-top: 8px; font-size: 14px; }
.gain { color: var(--ok); }
.loss { color: var(--danger); }

ul.positions { list-style: none; margin: 6px 0 0; padding: 0; font-size: 14px; }
ul.positions li { padding: 2px 0; }

.preset {
  display: block;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 8px;
  font-weight: normal;
  cursor: pointer;
}

.preset:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.preset input { margin-right: 8px; }
.preset strong { font-size: 16px; }
.preset p { margin: 4px 0 0 24px; }

.check { display: flex; gap: 8px; align-items: flex-start; font-weight: normal; margin-top: 12px; }
.check input { margin-top: 4px; }

dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  max-width: min(420px, calc(100vw - 32px));
  padding: 16px;
}

dialog::backdrop { background: rgba(0, 0, 0, .4); }
.presets { border: 0; margin: 0; padding: 0; }
.presets legend { margin-bottom: 8px; }

.markets { border: 0; margin: 12px 0 0; padding: 0; }
.markets legend { margin-bottom: 4px; }
.markets input[type="search"] { width: 100%; font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); }
.picked-count { display: block; margin: 6px 0; }
.market-group { border-top: 1px solid var(--line); padding: 6px 0; }
.market-group summary, .stopped-robots summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.market { display: flex; gap: 8px; align-items: center; font-weight: normal; padding: 6px 0; margin: 0; }
.market[hidden], .market-group[hidden] { display: none; }
.stopped-robots { margin-top: 8px; }

/* The robot view */
.back { margin-bottom: 8px; }
.open-robot { display: block; margin: 4px 0; }
.now { font-size: 17px; margin: 10px 0 4px; }
.position .figures { margin-top: 4px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.curve { display: block; width: 100%; height: 80px; margin-top: 12px; }
.curve-zero { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.curve-line { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; }
.gain-stroke { stroke: var(--ok); }
.loss-stroke { stroke: var(--danger); }
ul.feed { list-style: none; margin: 0; padding: 0; }
ul.feed li { display: flex; flex-direction: column; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; overflow-wrap: anywhere; }
.feed-time { font-size: 12px; }
/* The stop-to-target bar: public/shared/position-bar.css. */

/* While a live block's or the preview's refreshes fail: the shared widgets' line under it, the page kept as it was. */
.tb-lost { margin: 8px 0; color: var(--warn); font-size: 14px; }
.tb-lost[hidden] { display: none; }

/* ---- Launch a robot: the shared settings form (../shared/settings-form.css) inside the app */
.launch .start .presets { display: grid; gap: 8px; }
.launch .start-option { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--card); }
.launch .start-option.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.launch .start-option p { margin: 4px 0 8px; }
.launch .saved-starts { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.launch .saved-start .row { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px 12px; }
.launch .in-effect { font-size: 14px; }
.launch h3 { font-size: 16px; margin: 20px 0 8px; }
.launch .launch-robot, .launch .settings-box { margin-top: 12px; }
.launch .name-ask { display: grid; gap: 8px; padding: 12px; margin-top: 12px; }
.launch .live-warning { margin-top: 12px; }
.launch .form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.launch .launch-status .error { margin-top: 12px; }

/* ---- The robot's own settings, read-only, in the live view */
details.settings { margin-top: 16px; padding: 12px 16px; }
details.settings > summary { cursor: pointer; font-weight: 600; }
.robot-settings .profile-group h4 { margin: 12px 0 4px; }
/* The Robot section at phone width: one column, as the panel's narrow layout gives it. */
.tb-settings.launch .launch-robot .field { grid-template-columns: minmax(0, 1fr); gap: 4px; }
.tb-settings.launch .launch-robot .field > span:empty { display: none; }
.tb-settings.launch .launch-robot .field > * { grid-column: 1; min-width: 0; }
.tb-settings.launch .launch-robot .field input[type=number] { max-width: 12rem; }

/* Accounts: sign in, register, the profile. */
.account-form input + label { margin-top: 12px; }
.account-form label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; font-size: 14px; margin-top: 12px; }
.account-form label.check input { margin-top: 3px; flex: none; }
.account-form.small button[type="submit"] { margin-top: 12px; }
.links { display: flex; flex-wrap: wrap; gap: 4px 20px; margin: 12px 0 0; }
.notice-line { color: var(--ok); font-size: 14px; margin: 0 0 12px; }
button.link.danger { color: var(--danger); background: none; }
.card.token code { font-size: 13px; overflow-wrap: anywhere; }

/* The landing page: what a signed-out visitor sees. Mobile first; wider from 768px. */
body.landing-page main { max-width: 1040px; padding: 0 16px 24px; }
.landing-page .hero { padding: 40px 0 32px; }
.landing-page .kicker { color: var(--accent-text); font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; margin: 0 0 12px; }
.landing-page .hero-title { font-size: clamp(28px, 7vw, 46px); line-height: 1.12; letter-spacing: -.02em; margin: 0 0 16px; max-width: 22ch; }
.landing-page .hero-text { font-size: 18px; color: var(--muted); max-width: 60ch; margin: 0; }
.landing-page .hero-note { margin: 14px 0 0; }
.landing-page .cta { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 24px; }
.landing-page .cta .button { min-height: 48px; padding: 12px 22px; font-size: 16px; flex: 1 1 100%; }
.landing-page .band { padding: 36px 0; border-top: 1px solid var(--line); }
.landing-page .band > h2 { font-size: 24px; letter-spacing: -.01em; margin: 0 0 16px; }
.landing-page .section-intro { margin: -6px 0 16px; }
.landing-page h3 { margin: 0 0 6px; }

.landing-page .steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.landing-page .steps li { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.landing-page .steps p { margin: 0; color: var(--muted); }
.landing-page .step-n { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent); font-weight: 700; font-size: 14px; margin-bottom: 10px; }

.landing-page .strategy-grid { display: grid; gap: 12px; }
.landing-page .strategy { margin: 0; }
.landing-page .strategy p { margin: 0 0 8px; }
.landing-page .strategy .fit { font-size: 14px; color: var(--muted); }
.landing-page .strategy .fit strong { color: var(--text); font-weight: 600; }

.landing-page .control-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; align-items: start; }
/* Grid items may shrink below their content (the demo bar's drawing): nothing pushes the page sideways. */
.landing-page .control-grid > *, .landing-page .steps > *, .landing-page .strategy-grid > * { min-width: 0; }
.landing-page .control-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.landing-page .control-list li { display: grid; gap: 2px; padding-left: 16px; border-left: 3px solid var(--accent); }
.landing-page .control-list span { color: var(--muted); font-size: 15px; }
.landing-page .demo { margin: 0; position: relative; }
.landing-page .demo .card { margin-bottom: 8px; }
.landing-page .demo-badge { position: absolute; top: -10px; right: 12px; z-index: 1; background: var(--warn); color: var(--on-warn); }
.landing-page .demo figcaption { font-size: 13px; }

.landing-page .faq-item { border-bottom: 1px solid var(--line); }
.landing-page .faq-item summary { cursor: pointer; font-weight: 600; padding: 14px 0; list-style-position: inside; }
.landing-page .faq-item p { margin: 0 0 14px; color: var(--muted); max-width: 70ch; }

.landing-page .band.risk { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--warn); border-radius: 12px; padding: 20px; margin-top: 12px; }
.landing-page .risk > h2 { font-size: 18px; margin-bottom: 8px; }
.landing-page .risk p { margin: 0; }
.landing-page .closing { border-top: 0; padding: 24px 0 8px; }
.landing-page .closing .cta { margin-top: 0; }
.landing-page .landing-footer { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; padding: 20px 0 8px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 14px; }
.landing-page .landing-footer a { color: var(--accent-text); }

@media (min-width: 560px) {
  .landing-page .cta .button { flex: 0 0 auto; }
}

@media (min-width: 768px) {
  .landing-page .hero { padding: 72px 0 48px; }
  .landing-page .band { padding: 48px 0; }
  .landing-page .steps, .landing-page .strategy-grid { grid-template-columns: repeat(3, 1fr); }
  .landing-page .control-grid { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 32px; }
  .landing-page .band.risk { padding: 24px 28px; }
}

/* ---- Links that act as buttons (a page is a link now, not a script's screen) */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-weight: 600;
  min-height: 44px;
  padding: 10px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  text-decoration: none;
  cursor: pointer;
}
.button.secondary { background: transparent; color: var(--accent-text); border: 1px solid var(--line); }
.button.block { display: flex; width: 100%; margin-top: 12px; }
a.link, a.back { color: var(--accent-text); text-decoration: none; font-weight: 600; }
a.back { display: inline-block; margin-bottom: 8px; padding: 4px 0; }
.top-actions { align-items: center; }
.top-actions a.link { padding: 4px 0; }
form.inline { display: inline; margin: 0; }
.row form.stop-form { display: flex; flex: 1 1 auto; }
.row form.stop-form button { flex: 1 1 auto; }

/* Enter in a field presses this one; nobody sees it. */
.default-submit { position: absolute; width: 1px; height: 1px; padding: 0; min-height: 0; overflow: hidden; clip: rect(0 0 0 0); border: 0; }

/* The notice cards' buttons sit under their text. */
.notice .button { margin-top: 8px; }

/* ---- The markets picker, drawn by the server (the shared picker styles): checkboxes the script filters and shows */
.picker-input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.picker-option { cursor: pointer; }
.picker-option label.picker-name { display: inline-flex; align-items: center; gap: 8px; font-weight: inherit; margin: 0; cursor: pointer; }
.picker-option:not(.is-chosen) .picker-check { visibility: hidden; }
.picker-chip[hidden], .picker-option[hidden], .picker-group[hidden], .picker-list[hidden], .picker-empty[hidden] { display: none; }

/* ---- A live launch: the last question before real money */
.launch .confirm-live { margin-top: 12px; border-color: var(--danger); }
.launch .confirm-live p { margin: 0; font-weight: 600; }

/* ---- The robot's settings, read-only */
.robot-settings .kv { width: 100%; }

/* Hidden means hidden, whatever display a row's own class gives it (the form's grid rows, check lines). */
.tb-settings.launch [hidden], .launch-units [hidden], .account-form [hidden] { display: none !important; }

/* The launch preview in the old order: the summary and the risk line, then the filters and the table (the currency
   note is in the head, under "For a balance of" in this column). The Pjax container (.tb-preview) keeps its parts out
   of the filters' way in the markup, so its own box is dropped and the card body orders them. */
.launch-preview > .card-body { display: flex; flex-direction: column; }
.launch-preview .tb-preview { display: contents; }
.launch-preview .preview-filters { order: 1; }
.launch-preview .preview-table { order: 2; }
.launch-preview .tb-lost { order: 3; }

/* "Open live view" is a link now: the old button.link's padding, so the card keeps its spacing. */
a.open-robot { padding: 4px 0; }

/* A posting form's CSRF field comes before its heading: the heading still starts the card, as a first child did. */
input[type=hidden]:first-child + h2, .card > input[type=hidden]:first-child + h3 { margin-top: 0; }
/* The links under a form are links now: the old button.link's padding, so the row keeps its height. */
.links a.link { display: inline-block; padding: 4px 0; }
/* The launch page's back link as the old one read: it sat inside the settings form, whose controls inherit the text's
   colour, weight and size (settings-form.css .tb-settings button). */
a.back:has(+ form.tb-settings.launch) { color: inherit; font-weight: 400; font-size: 14px; }

/* ---- Contrast (WCAG 2.1 AA): the settings form's own rules (settings-form.css) give its buttons the text's colour and its
   chips the raw accent; in the client app a filled button carries the ink chosen for the accent, chips the readable accent. */
.tb-theme-client .tb-settings { --accent-ink: var(--accent-text); }
.tb-theme-client .tb-settings button.primary { background: var(--accent); color: var(--on-accent); }
.tb-theme-client .tb-settings button.danger { background: var(--danger); color: var(--on-danger); }

/* ---- Accessibility (WCAG 2.1 AA) */

/* "Skip to content": the first stop of the keyboard, out of sight until it has the focus. */
.skip-link {
  position: absolute;
  left: 16px;
  top: -100px;
  z-index: 100;
  padding: 10px 16px;
  background: var(--card);
  color: var(--accent-text);
  border: 2px solid var(--accent);
  border-radius: 8px;
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus { top: 8px; }
main:focus { outline: none; }

/* Where the focus is, on everything that takes it (the browser's ring is not drawn on every control the same way). */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible,
[tabindex]:not([tabindex="-1"]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* A field's own error, under it (the account forms). */
.field-error { color: var(--danger); font-size: 14px; margin: 6px 0 0; }
input[aria-invalid="true"] { border-color: var(--danger); }

/* The error pages: their title over the words, the way back under them. */
.error-page h2 { margin: 0 0 8px; }
.error-page .button { margin: 8px 4px 0; }

/* ---- Phone width: every tap target at least 44 px high (WCAG 2.5.5), the text as it is. */
@media (max-width: 600px) {
  .top-actions a.link, .top-actions button.link, a.back, .links a.link, a.open-robot, .landing-page .landing-footer a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }
  /* A summary keeps its disclosure triangle (display: list-item): taller by its padding. */
  details.settings > summary, .stopped-robots > summary, .market-group > summary { padding-top: 10px; padding-bottom: 10px; }
  .account-form label.check { min-height: 44px; align-items: center; }
  .account-form label.check input { margin-top: 0; }
  .tb-theme-client .tb-settings select, .tb-theme-client .tb-settings input[type=number], .tb-theme-client .tb-settings input[type=text],
  .tb-theme-client .tb-settings input[type=search], .tb-theme-client .picker-field input[type=text] { min-height: 44px; }
  .tb-theme-client .tb-settings input[type=range] { min-height: 44px; }
  /* A native select keeps its own height whatever min-height says; the menulist-button look takes one, arrow and all. */
  .tb-theme-client .tb-settings select { -webkit-appearance: menulist-button; appearance: menulist-button; height: 44px; }
  /* A checkbox row: the box at 24 px (WCAG 2.5.8), its row's label a full-height target for it too. */
  .tb-theme-client .tb-settings .field-choice input[type=checkbox] { width: 24px; height: 24px; margin: 10px 0; }
  .tb-theme-client .tb-settings .setting.is-choice > label { display: flex; align-items: center; min-height: 44px; }
  .tb-theme-client .tb-settings .hint label, .tb-theme-client .tb-settings .field-choice label { display: inline-flex; align-items: center; min-height: 44px; min-width: 44px; }
  .bar-legend .legend-item { min-height: 44px; }
  button.link { display: inline-flex; align-items: center; min-height: 44px; }
}
