:root {
  --bg: #0D1014; --panel: #161B22; --panel-2: #1E242C; --line: #262D36; --line-2: #2F3742;
  --text: #E8ECF1; --muted: #9AA4B2; --soft: #C3CBD6;
  --up: #3DD68C; --down: #FFA24C; --info: #9ECBFF; --info-bg: #13233A; --warn-bg: #3A2614; --warn: #FFC48A;
  --danger: #FF6B6B;
  --sans: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); -webkit-text-size-adjust: 100%; }
body { min-height: 100dvh; }
[hidden] { display: none !important; }
h1 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
h2 { margin: 4px 0 6px; font-size: 18px; font-weight: 600; }
h3 { margin: 0; font-size: 15px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; line-height: 1.45; }
.row { display: flex; align-items: center; gap: 12px; }
.between { justify-content: space-between; }
.gap { gap: 8px; }
.grow { flex: 1; }
.mono { font-family: var(--mono); }

.btn { min-height: 44px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--panel-2);
  color: var(--text); font: 600 14px var(--sans); display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--up); color: var(--bg); border-color: transparent; }
.btn.light { background: var(--text); color: var(--bg); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.kill { background: transparent; color: var(--down); border: 1.5px solid var(--down); }
.btn.kill.paused { color: var(--bg); background: var(--down); }
.btn.danger { background: var(--danger); color: var(--bg); border-color: transparent; }

.top { padding: calc(14px + env(safe-area-inset-top)) 16px 8px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.status { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 500;
  background: var(--panel-2); color: var(--soft); }
.pill.ok { color: var(--up); }
.pill.paused { color: var(--down); background: var(--warn-bg); }
.pill.live { color: var(--bg); background: var(--danger); font-weight: 600; }
.pill.dry { color: var(--info); background: var(--info-bg); }
.banner { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--info-bg); color: var(--info); font-size: 13px; line-height: 1.45; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }

main { padding: 4px 16px calc(96px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
.totals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 6px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; }
.stat span { font-size: 11px; color: var(--muted); }
.stat strong { font: 600 16px var(--mono); }
.bar { margin: 12px 0; }
.empty { color: var(--muted); text-align: center; padding: 40px 12px; line-height: 1.5; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.card.hot { border-color: #2F6B4F; }
.card.risk { border-color: #6B4423; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.card-head .sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.clock { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; background: var(--panel-2); font: 600 14px var(--mono); white-space: nowrap; }
.clock.late { background: var(--warn-bg); color: var(--warn); }
.value-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.big { font: 600 36px/1 var(--mono); }
.big.up { color: var(--up); } .big.down { color: var(--down); }
.outlook { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.outlook > div { background: var(--panel-2); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.outlook span { font-size: 11px; color: var(--muted); }
.outlook b { font: 600 15px var(--mono); }
.outlook b.up { color: var(--up); } .outlook b.down { color: var(--down); }
.outlook small { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.value-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
.value-sub b { font-family: var(--mono); color: var(--text); font-weight: 500; }
.legs { display: grid; grid-template-columns: 18px max-content minmax(0, 1fr) auto; align-items: center; gap: 6px 8px; font-size: 13px; }
.leg { display: contents; }
.leg .coin { font-weight: 600; }
.leg .target { color: var(--muted); font: 12px var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leg .prob { font-family: var(--mono); }
.leg .prob.up { color: var(--up); } .leg .prob.down { color: var(--down); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 5px 10px; border-radius: 999px; background: var(--panel-2); color: var(--soft); font-size: 12px; }
.chip.armed { background: var(--info-bg); color: var(--info); font-weight: 500; }
.chip.armed.stop { background: var(--warn-bg); color: var(--warn); }
.chip.state { background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.actions { display: flex; gap: 8px; }
.actions .sell { flex: 1; }
.icon-btn { width: 48px; padding: 0; }
.sample-tag { font-size: 11px; color: var(--info); background: var(--info-bg); padding: 2px 7px; border-radius: 999px; margin-left: 6px; vertical-align: 2px; font-weight: 500; }

.rules { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.rule { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.rule-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.field input { min-height: 44px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--bg); color: var(--text); padding: 0 12px; font: 500 16px var(--mono); width: 100%; }
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line-2); transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; background: var(--text); transition: transform .15s; }
.switch input:checked + span { background: var(--up); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--info); outline-offset: 2px; }
.switch input:disabled + span { opacity: 0.4; }

.events { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-direction: column; gap: 8px; }
.events li { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 13px; line-height: 1.45; }
.events time { color: var(--muted); font: 12px var(--mono); }
.kind { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-right: 6px; }
.kind.sold { color: var(--up); } .kind.dry-run { color: var(--info); } .kind.skipped { color: var(--down); } .kind.held { color: var(--warn); } .kind.control { color: var(--warn); }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px;
  background: #11151B; border-top: 1px solid var(--line); padding: 6px 8px calc(8px + env(safe-area-inset-bottom)); z-index: 5; }
.tabs button { min-height: 56px; background: none; border: none; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font: 500 12px var(--sans); cursor: pointer; }
.tabs button.on { color: var(--text); font-weight: 600; }

.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin-bottom: 8px; }
.login-card label { font-size: 13px; color: var(--muted); }
.login-card input { min-height: 48px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--panel); color: var(--text); padding: 0 14px; font-size: 16px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 0; }

.sheet { border: 1px solid var(--line-2); border-radius: 16px; background: var(--panel); color: var(--text); padding: 18px; width: min(92vw, 420px); }
.sheet::backdrop { background: rgba(0, 0, 0, 0.6); }
.sheet form { display: flex; flex-direction: column; gap: 12px; }
.sheet p { margin: 0; line-height: 1.5; }

.toasts { position: fixed; left: 12px; right: 12px; top: calc(12px + env(safe-area-inset-top)); display: flex; flex-direction: column; gap: 8px; z-index: 20; pointer-events: none; }
.toast { margin: 0 auto; max-width: 480px; width: 100%; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 12px; padding: 10px 14px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.toast.sold { border-color: #2F6B4F; } .toast.skipped { border-color: #6B4423; } .toast.held { border-color: #6B5A23; }

/* flash alerts: a combo crossing the profit level (green) or fading from its peak (amber) */
@keyframes flash-profit { 0%, 100% { box-shadow: 0 0 0 0 rgba(61, 214, 140, 0); border-color: #2F6B4F; }
  50% { box-shadow: 0 0 0 4px rgba(61, 214, 140, 0.55), 0 0 28px rgba(61, 214, 140, 0.35); border-color: #3DD68C; background: #15261E; } }
@keyframes flash-fade { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 162, 76, 0); border-color: #6B4423; }
  50% { box-shadow: 0 0 0 4px rgba(255, 162, 76, 0.55), 0 0 28px rgba(255, 162, 76, 0.35); border-color: #FFA24C; background: #2A1E14; } }
.card.flash-profit { animation: flash-profit 0.9s ease-in-out 8; }
.card.flash-fade { animation: flash-fade 0.9s ease-in-out 8; }
.alert-tag { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; margin-left: 6px; vertical-align: 2px; }
.alert-tag.profit { background: #15261E; color: var(--up); }
.alert-tag.fade { background: var(--warn-bg); color: var(--warn); }
@media (prefers-reduced-motion: reduce) {
  .card.flash-profit, .card.flash-fade { animation: none; border-width: 2px; }
  .card.flash-profit { border-color: var(--up); } .card.flash-fade { border-color: var(--down); }
}
.settings-group { display: flex; flex-direction: column; gap: 12px; }
.settings-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.accuracy { font: 500 22px var(--mono); }

.seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; background: var(--bg); border: 1px solid var(--line-2); border-radius: 12px; padding: 4px; }
.seg button { min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--soft); font: 600 14px var(--sans); cursor: pointer; }
.seg button[aria-checked="true"] { background: var(--panel-2); color: var(--text); }
.seg button[data-mode="live"][aria-checked="true"] { background: var(--danger); color: var(--bg); }
.seg button[data-mode="test"][aria-checked="true"] { background: var(--info-bg); color: var(--info); }
.seg.small button { min-height: 36px; font-size: 13px; }
.auto-status { font-size: 13px; color: var(--soft); line-height: 1.45; }
.toggles { display: flex; flex-wrap: wrap; gap: 6px; }
.toggles label { position: relative; }
.toggles input { position: absolute; opacity: 0; inset: 0; cursor: pointer; margin: 0; }
.toggles span { display: inline-flex; min-height: 36px; align-items: center; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line-2);
  color: var(--soft); font: 500 13px var(--sans); }
.toggles input:checked + span { background: var(--info-bg); color: var(--info); border-color: transparent; }
.toggles input:focus-visible + span { outline: 2px solid var(--info); outline-offset: 2px; }
.auto-tag { font-size: 11px; color: var(--bg); background: var(--info); padding: 2px 7px; border-radius: 999px; margin-left: 6px; vertical-align: 2px; font-weight: 600; }
.kind.bought { color: var(--up); } .kind.test-buy { color: var(--info); } .kind.buy-skipped { color: var(--muted); }
.toast.bought { border-color: #2F6B4F; } .toast.test-buy { border-color: #23466B; }
.live-dot { color: var(--up); font-weight: 600; }
.tune-latest { display: flex; flex-direction: column; gap: 8px; }
.tune-latest .btn { min-height: 40px; margin-top: 8px; display: flex; width: 100%; }
.tune-history li { padding: 8px 10px; }
.kind.tuned { color: var(--info); } .toast.tuned { border-color: #23466B; }

/* live ticks: a brief green/orange wash when the value moves */
@keyframes tick-up { from { background: rgba(61, 214, 140, .28); } to { background: transparent; } }
@keyframes tick-down { from { background: rgba(255, 162, 76, .28); } to { background: transparent; } }
.big.tick-up { animation: tick-up .45s ease-out; border-radius: 6px; }
.big.tick-down { animation: tick-down .45s ease-out; border-radius: 6px; }
@media (prefers-reduced-motion: reduce) { .big.tick-up, .big.tick-down { animation: none; } }

/* ---------------------------------------------------------------- wide screens (laptops, desktops)
   Phones keep the layout above untouched. 760px+: two columns of cards and settings. 1100px+: a sidebar,
   a KPI strip and a results rail beside the live cards. */
.wide-only { display: none !important; }
.col-first { margin-top: 20px; }
.link { background: none; border: 0; padding: 0; color: var(--info); font: 500 13px var(--sans); cursor: pointer; }
.link:hover { text-decoration: underline; }

@media (hover: hover) {
  .btn:not(:disabled):hover { filter: brightness(1.12); }
  .btn.ghost:not(:disabled):hover, .btn.kill:not(.paused):hover { background: var(--panel-2); filter: none; }
  .tabs button:hover { color: var(--text); }
  .events li { transition: border-color .15s; }
}

@media (min-width: 760px) {
  main { max-width: 1180px; padding-left: 24px; padding-right: 24px; }
  .top { padding-left: 24px; padding-right: 24px; }
  #cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; align-items: start; }
  #cards .card { margin-bottom: 0; }
  .cols:not([hidden]) { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 28px; align-items: start; }
  .cols .col-first { margin-top: 4px; }
  .toasts { left: auto; right: 20px; width: 400px; }
  .sheet { width: min(92vw, 480px); }
}

@media (min-width: 1100px) {
  :root { --side: 232px; }
  .wide-only { display: revert !important; }
  .narrow-only { display: none !important; }
  body { min-height: 100vh; }

  /* sidebar: the tab bar becomes a left rail */
  .tabs { top: 0; right: auto; bottom: 0; width: var(--side); display: flex; flex-direction: column; gap: 2px;
    padding: 20px 12px; border-top: 0; border-right: 1px solid var(--line); background: #0F1318; }
  .tabs .brand { display: flex !important; align-items: center; gap: 10px; padding: 4px 12px 22px; font-weight: 600; font-size: 17px; color: var(--text); }
  .tabs button { flex-direction: row; justify-content: flex-start; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: 10px; font-size: 14px; }
  .tabs button.on { background: var(--panel-2); }
  .tabs button.on svg { color: var(--up); }
  .tabs .tv-link { margin-top: auto; display: flex !important; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
    color: var(--muted); font-size: 13px; text-decoration: none; }
  .tabs .tv-link:hover { color: var(--text); background: var(--panel-2); }
  .tabs .tv-link[hidden] { display: none !important; }

  /* top bar beside the sidebar */
  .top { margin-left: var(--side); padding: 18px 32px 12px; border-bottom: 1px solid var(--line); }
  .top h1 { font-size: 22px; }
  .top .row.between { align-items: center; }
  .top > .row > div { display: flex; align-items: center; gap: 14px; }
  .status { margin-top: 0; }
  main { margin-left: var(--side); max-width: none; padding: 22px 32px 40px; }

  /* KPI strip */
  .kpis { display: grid !important; grid-template-columns: 1.4fr repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
  .kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
  .kpi > span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
  .kpi strong { font: 600 22px var(--mono); white-space: nowrap; }
  .kpi-main strong { font-size: 30px; }
  .kpi small { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .kpi strong.up { color: var(--up); } .kpi strong.down { color: var(--down); }
  .meter { height: 5px; border-radius: 999px; background: var(--panel-2); overflow: hidden; margin: 2px 0 2px; }
  .meter i { display: block; height: 100%; width: 0; background: var(--info); border-radius: 999px; transition: width .3s; }

  /* live: cards beside a results rail */
  .live-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 22px; align-items: start; }
  .bar { margin: 0 0 12px; }
  #cards { grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); }
  .rail { display: flex !important; flex-direction: column; gap: 12px; position: sticky; top: 86px; }
  .panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
  .panel-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
  .chart { height: 170px; }
  .days { height: 120px; }
  .chart svg, .days svg { display: block; width: 100%; height: 100%; overflow: visible; }
  .axis { fill: var(--muted); font: 11px var(--mono); }
  .mini-events { list-style: none; margin: 0; padding: 0; }
  .mini-events li { padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; color: var(--soft); line-height: 1.4;
    display: grid; grid-template-columns: 56px 1fr; gap: 6px; }
  .mini-events li:first-child { border-top: 0; padding-top: 2px; }
  .mini-events time { color: var(--muted); font: 12px var(--mono); padding-top: 1px; }
  .mini-events .kind { display: block; margin: 0 0 1px; }

  /* settings pages: two roomy columns */
  .cols:not([hidden]) { gap: 32px; max-width: 1240px; }
  #tab-history { max-width: 860px; }

  .toasts { top: 18px; }
}

@media (min-width: 1500px) {
  .live-grid { grid-template-columns: minmax(0, 1fr) 380px; }
  .chart { height: 200px; }
}
