/* ============================================================
   Crypto Agent — trader workstation aesthetic
   Dark canvas, amber/cyan accents, mono numerics throughout.
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&family=DM+Sans:wght@400;500;700&display=swap');

:root {
  /* Surfaces */
  --bg:           #07090d;
  --bg-elev:      #11151d;
  --bg-elev-2:    #161b27;
  --bg-elev-3:    #1c2231;
  --line:         #232a3a;
  --line-soft:    #1a1f2c;
  --line-strong:  #2c3447;

  /* Type */
  --text:         #e6e9ef;
  --text-dim:     #8a93a6;
  --text-faint:   #4e5566;
  --text-quiet:   #383e4d;

  /* Accents */
  --accent:       #f5a524;     /* amber — primary */
  --accent-soft:  rgba(245,165,36,.12);
  --accent-2:     #38bdf8;     /* cyan — secondary */
  --accent-2-soft:rgba(56,189,248,.12);
  --good:         #34d399;
  --good-soft:    rgba(52,211,153,.12);
  --bad:          #f87171;
  --bad-soft:     rgba(248,113,113,.12);
  --warn:         #fbbf24;
  --warn-soft:    rgba(251,191,36,.10);

  /* Type families */
  --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  --sans: 'DM Sans', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  font-size: 14px;
  background:
    radial-gradient(1400px 700px at 85% -15%, rgba(245,165,36,.05), transparent 60%),
    radial-gradient(1100px 500px at -10% 18%, rgba(56,189,248,.04), transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
.link-muted { color: var(--text-dim); }
.link-muted:hover { color: var(--text); }
small { color: var(--text-dim); }
.mono { font-family: var(--mono); }
.muted { color: var(--text-faint); }

/* ============================================================
   LOGIN
   ============================================================ */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.login-card h1 { margin: 16px 0 24px; font-size: 22px; letter-spacing: 0.5px; }
.login-card label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--text-dim); }
.login-card input { width: 100%; }
.login-card button { width: 100%; margin-top: 6px; }
.login-card .hint { color: var(--text-faint); font-size: 12px; margin-top: 18px; text-align: center; }
.error {
  color: var(--bad);
  background: var(--bad-soft);
  padding: 10px 12px; border-radius: 8px;
  border: 1px solid rgba(248,113,113,.2);
  font-size: 13px; margin-bottom: 12px;
}

/* ============================================================
   BRAND + TOPBAR
   ============================================================ */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { color: var(--accent); font-size: 18px; line-height: 1; }
.brand-name {
  font-family: var(--mono); font-weight: 700;
  letter-spacing: 2.5px; font-size: 13px;
}

.app-body { padding: 0; }
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(7,9,13,.92);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 10;
}
.topbar nav { display: flex; gap: 4px; justify-content: center; }
.nav-link {
  font-family: var(--mono); font-size: 12px; letter-spacing: 1.5px;
  padding: 7px 14px; border-radius: 8px; color: var(--text-dim);
  text-transform: uppercase;
}
.nav-link:hover { color: var(--text); background: var(--bg-elev); text-decoration: none; }
.nav-link.active {
  color: var(--accent);
  background: var(--accent-soft);
}
.user-box { display: flex; gap: 14px; justify-content: flex-end; align-items: center; font-size: 13px; }
.user-name { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }

/* Mobile hamburger — hidden on desktop so the 3-col topbar grid is intact. */
.nav-toggle {
  display: none;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  color: var(--text);
  width: 38px; height: 38px;
  border-radius: 8px;
  font-size: 18px; line-height: 1;
  cursor: pointer;
}

/* ============================================================
   LAYOUT  — sidebar + content
   ============================================================ */
.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: calc(100vh - 56px);
}

/* ---- Sidebar -------------------------------------------- */
.sidebar {
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  background: linear-gradient(180deg, var(--bg-elev) 0%, var(--bg) 100%);
}
.sidebar h2 {
  font-family: var(--mono); font-size: 11px; letter-spacing: 2px;
  color: var(--text-faint); text-transform: uppercase;
  margin: 0 8px 14px;
}
.agent-list { list-style: none; padding: 0; margin: 0; }
.agent-list li { margin-bottom: 2px; }
.agent-list li a {
  display: flex; gap: 10px; align-items: center;
  padding: 10px 12px; border-radius: 8px; color: var(--text);
  border: 1px solid transparent;
  transition: all .12s ease;
}
.agent-list li a:hover {
  background: var(--bg-elev-2);
  text-decoration: none;
}
.agent-list li.is-active a {
  background: var(--bg-elev-2);
  border-color: var(--line-strong);
  border-left: 2px solid var(--accent);
  padding-left: 11px;
}
.agent-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.agent-name {
  font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.agent-sub {
  font-family: var(--mono); font-size: 11px;
  color: var(--text-faint);
  display: flex; align-items: center; gap: 6px;
}
.agent-sub .dot-sep { color: var(--text-quiet); }
.agent-mode { text-transform: uppercase; letter-spacing: 1px; font-size: 10px; }
.agent-mode.mode-demo { color: var(--text-faint); }
.agent-mode.mode-live { color: var(--accent); }
.agent-list .empty {
  color: var(--text-faint); font-size: 13px; padding: 14px 10px;
}

/* Status dots in sidebar */
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-faint); flex-shrink: 0;
}
.dot-running {
  background: var(--good);
  box-shadow: 0 0 0 3px rgba(52,211,153,.15);
  animation: pulse 2.4s ease-in-out infinite;
}
.dot-paused  { background: var(--warn); }
.dot-stopped { background: var(--text-quiet); }
/* "Action" dots — used for sidebar entries that aren't agents (e.g. the
   "New grid agent" and "How grids work" entries on the grid page). */
.dot-action {
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--text-faint);
  width: 14px; height: 14px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
  margin: -3px 0;
}
.sidebar-divider {
  height: 1px; background: var(--line-soft);
  margin: 14px 0 10px;
}
.sidebar-actions .agent-name { color: var(--text-dim); font-weight: normal; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(52,211,153,.15); }
  50%      { box-shadow: 0 0 0 5px rgba(52,211,153,.05); }
}

/* ---- Content area --------------------------------------- */
.content {
  padding: 22px 28px 40px;
  min-width: 0;
  display: flex; flex-direction: column; gap: 18px;
}
.content.single { max-width: 1100px; margin: 0 auto; width: 100%; }
.placeholder {
  color: var(--text-dim); padding: 80px 20px; text-align: center;
  font-size: 14px;
}

/* ============================================================
   AGENT HEADER (above the dashboard)
   ============================================================ */
.agent-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 24px; flex-wrap: wrap;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.agent-title { flex: 1 1 460px; min-width: 0; }
.agent-title-row {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 12px;
}
.agent-title-row h1 {
  margin: 0; font-size: 26px; font-weight: 700;
  letter-spacing: -0.5px;
}
.agent-meta-row {
  display: flex; gap: 22px; flex-wrap: wrap;
  font-size: 12px;
}
.meta-item { display: flex; flex-direction: column; gap: 2px; }
.meta-k {
  font-family: var(--mono); font-size: 10px; letter-spacing: 1.5px;
  color: var(--text-faint); text-transform: uppercase;
}
.meta-v { font-size: 13px; color: var(--text); }

/* ---- Status / mode pills (in header) -------------------- */
.status-pill, .mode-pill {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-family: var(--mono); font-size: 10px;
  letter-spacing: 1.5px; text-transform: uppercase;
  font-weight: 500;
}
.status-running {
  background: var(--good-soft); color: var(--good);
  border: 1px solid rgba(52,211,153,.3);
}
.status-paused {
  background: var(--warn-soft); color: var(--warn);
  border: 1px solid rgba(251,191,36,.3);
}
.status-stopped {
  background: rgba(138,147,166,.08); color: var(--text-dim);
  border: 1px solid var(--line);
}
.mode-pill.mode-demo {
  background: rgba(138,147,166,.08); color: var(--text-dim);
  border: 1px solid var(--line);
}
.mode-pill.mode-live {
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid rgba(245,165,36,.3);
}

/* ---- Pill (table) -------------------------------------- */
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-family: var(--mono); font-size: 10px; letter-spacing: 1px;
  background: var(--bg-elev-2); color: var(--text-dim);
  text-transform: uppercase; border: 1px solid var(--line-soft);
}

/* ---- Controls (start / pause / stop / mode / tick) ----- */
.controls {
  display: flex; gap: 8px; align-items: center;
  flex-wrap: wrap;
  flex: 0 0 auto;
}
.controls button {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 13px;
  font-size: 12px; letter-spacing: .5px;
}
.controls .ctrl-ico { font-size: 10px; line-height: 1; }
.controls .ctrl-go {
  background: var(--good-soft); color: var(--good);
  border-color: rgba(52,211,153,.3);
}
.controls .ctrl-go:not(:disabled):hover { background: rgba(52,211,153,.2); }
.controls .ctrl-pause {
  background: var(--warn-soft); color: var(--warn);
  border-color: rgba(251,191,36,.3);
}
.controls .ctrl-stop {
  background: var(--bad-soft); color: var(--bad);
  border-color: rgba(248,113,113,.3);
}
.controls .ctrl-mode {
  background: var(--accent-2-soft); color: var(--accent-2);
  border-color: rgba(56,189,248,.3);
  font-family: var(--mono); letter-spacing: 1px; text-transform: uppercase;
}
.controls .ctrl-tick {
  background: var(--bg-elev-2); color: var(--text-dim);
}

/* ============================================================
   KPI STRIP — 6 stat tiles in a row
   ============================================================ */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
}
.kpi {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 2px;
  position: relative; overflow: hidden;
}
.kpi::before {
  content: ''; position: absolute; inset: 0 auto auto 0;
  width: 2px; height: 100%;
  background: linear-gradient(180deg, var(--accent), transparent);
  opacity: .5;
}
.kpi-k {
  font-family: var(--mono); font-size: 10px; letter-spacing: 2px;
  color: var(--text-faint); text-transform: uppercase;
}
.kpi-v {
  font-size: 22px; font-weight: 500; letter-spacing: -0.5px;
  color: var(--text);
  margin-top: 4px;
}
.kpi-v.pnl-pos { color: var(--good); }
.kpi-v.pnl-neg { color: var(--bad);  }
.kpi-d {
  font-size: 11px; color: var(--text-faint);
  margin-top: 2px;
}
.kpi-d.pnl-pos { color: var(--good); }
.kpi-d.pnl-neg { color: var(--bad);  }

/* ============================================================
   GRID ROWS — two flexible row layouts
   ============================================================ */
.grid-row {
  display: grid; gap: 14px;
}
.grid-2-1 { grid-template-columns: 2fr 1fr; }
.grid-1-1 { grid-template-columns: 1fr 1fr; }

/* ============================================================
   CARD
   ============================================================ */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px 18px;
  min-width: 0;
  display: flex; flex-direction: column;
}
.card-tall { min-height: 360px; }
.card-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line-soft);
}
.card-head h3 {
  font-family: var(--mono); font-size: 10px; letter-spacing: 2.5px;
  color: var(--text-dim); text-transform: uppercase;
  margin: 0; font-weight: 600;
}
.card-meta {
  font-size: 10px; color: var(--text-faint); letter-spacing: 1px;
}

/* ---- Chart wrappers ------------------------------------- */
.chart-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 280px;
}
.chart-wrap-sm { min-height: 220px; }
.chart-wrap canvas { width: 100% !important; height: 100% !important; }

/* ============================================================
   PATTERN LIST
   ============================================================ */
.pattern-list {
  display: flex; flex-direction: column; gap: 6px;
  flex: 1 1 auto;
  max-height: 420px; overflow-y: auto;
  margin: -4px -4px;   /* allow scrollbar to sit at the edge */
  padding: 4px;
}
.pat-row {
  display: grid;
  grid-template-columns: 1fr 50px;
  gap: 4px 12px;
  align-items: center;
  padding: 9px 10px;
  border-radius: 8px;
  background: var(--bg-elev-2);
  border: 1px solid transparent;
  transition: border-color .15s ease;
}
.pat-row:hover { border-color: var(--line-strong); }
.pat-name { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.pat-name strong {
  font-size: 12px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pat-name small {
  font-family: var(--mono); font-size: 10px; letter-spacing: .5px;
}
.pat-conf {
  font-family: var(--mono);
  font-size: 14px; font-weight: 700;
  text-align: right;
}
.pat-bar {
  grid-column: 1 / -1;
  height: 4px;
  background: var(--bg);
  border-radius: 2px;
  overflow: hidden;
}
.pat-bar > div { height: 100%; transition: width .3s ease; }
.empty-state {
  color: var(--text-faint); font-size: 13px;
  padding: 30px 12px; text-align: center;
  font-style: italic;
}

/* ============================================================
   BUTTONS & INPUTS
   ============================================================ */
button, .btn {
  font-family: var(--sans); font-size: 13px; font-weight: 500;
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--line);
  padding: 9px 14px; border-radius: 8px; cursor: pointer;
  transition: all .15s ease;
}
button:hover { background: var(--bg-elev-3); border-color: var(--line-strong); }
button:disabled { opacity: .35; cursor: not-allowed; }
.btn-primary {
  background: var(--accent); color: #1a1300;
  border-color: var(--accent); font-weight: 700;
}
.btn-primary:hover { background: #ffb733; border-color: #ffb733; }
.btn-danger {
  background: var(--bad-soft); color: var(--bad);
  border-color: rgba(248,113,113,.3);
}

input, select, textarea {
  font-family: var(--mono); font-size: 13px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
fieldset {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px 6px;
  margin: 0 0 14px;
}
fieldset legend {
  font-family: var(--mono); font-size: 10px; letter-spacing: 2px;
  color: var(--text-dim); text-transform: uppercase;
  padding: 0 8px;
}

/* ---- Forms ---------------------------------------------- */
.grid-form { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.grid-form label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12px; color: var(--text-dim);
}
.grid-form label small { margin-top: 2px; font-size: 11px; }
.grid-form button { grid-column: span 2; justify-self: start; }
.row-form { display: flex; flex-direction: column; gap: 14px; align-items: stretch; }
.row-form fieldset > label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12px; color: var(--text-dim);
  margin-bottom: 10px;
}

/* ============================================================
   TABLES
   ============================================================ */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td {
  padding: 9px 8px; text-align: left;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}
.data-table th {
  font-family: var(--mono); font-size: 10px; letter-spacing: 1.5px;
  color: var(--text-faint); text-transform: uppercase;
  font-weight: 500;
  background: var(--bg-elev-2);
  position: sticky; top: 0;
}
.data-table td { font-family: var(--mono); font-size: 12px; }
.data-table tr:hover td { background: rgba(255,255,255,.02); }
.data-table td:first-child, .data-table th:first-child { padding-left: 4px; }
.dir-long  { color: var(--good); font-weight: 600; }
.dir-short { color: var(--bad);  font-weight: 600; }
.pnl-pos   { color: var(--good); }
.pnl-neg   { color: var(--bad);  }

/* ============================================================
   LOG
   ============================================================ */
.logbox {
  font-family: var(--mono); font-size: 12px; line-height: 1.7;
  background: var(--bg); color: var(--text-dim);
  border: 1px solid var(--line-soft); border-radius: 8px;
  padding: 12px 14px;
  max-height: 620px; min-height: 320px; overflow-y: auto;
  margin: 0; white-space: pre-wrap;
  flex: 1 1 auto;
}
.log-error { color: var(--bad); }
.log-warn  { color: var(--warn); }
.log-info  { color: var(--text-dim); }

.code {
  font-family: var(--mono); font-size: 12px; background: var(--bg);
  padding: 12px 14px; border-radius: 8px; border: 1px solid var(--line);
  overflow-x: auto;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1280px) {
  .kpi-strip { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 1024px) {
  .grid-2-1, .grid-1-1 { grid-template-columns: 1fr; }
  .agent-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .controls { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
}

/* ============================================================
   MOBILE  (≤ 760px)
   ============================================================ */
@media (max-width: 760px) {
  /* --- Topbar becomes a flex bar: brand | (spacer) | toggle, with the
         nav and user-box dropping into a collapsible drawer. --- */
  .topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    gap: 10px;
  }
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; order: 3; }
  .brand { order: 1; }

  /* Nav drawer: hidden by default, expands full-width below the bar when open */
  .topbar nav {
    order: 4;
    display: none;
    flex-direction: column;
    width: 100%;
    gap: 2px;
    padding-top: 8px;
    border-top: 1px solid var(--line-soft);
    margin-top: 6px;
  }
  .topbar nav.is-open { display: flex; }
  .nav-link {
    padding: 12px 10px;
    font-size: 13px;
    border-radius: 8px;
  }

  /* User box: keep the status chip + sign-out visible on the top row,
     wrapping under the brand if needed. */
  .user-box {
    order: 2;
    gap: 10px;
    flex: 1 1 auto;
    justify-content: flex-end;
    min-width: 0;
    flex-wrap: wrap;
  }
  .user-name { display: none; }          /* save space; name is in Profile */
  .status-chip { font-size: 10px; padding: 4px 9px; }
  .status-chip-label { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* --- Layout / content --- */
  .content { padding: 16px 12px 28px; }
  .content.single { padding-left: 12px; padding-right: 12px; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); padding: 14px 12px; }

  /* --- KPI strip: 2 across on phones --- */
  .kpi-strip { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .kpi { padding: 12px 12px; }
  .kpi-v { font-size: 18px; }

  /* --- Grids stack --- */
  .grid-2-1, .grid-1-1, .grid-row { grid-template-columns: 1fr; }

  /* --- Cards --- */
  .card { padding: 14px; }
  .card-tall { min-height: auto; }
  .chart-wrap { min-height: 260px; }

  /* --- Headings / titles --- */
  .agent-title-row h1 { font-size: 19px; }
  .agent-header .agent-meta { flex-wrap: wrap; gap: 10px 16px; }

  /* --- Controls (Start/Pause/Stop/Tick) wrap and grow --- */
  .controls { gap: 8px; }
  .controls button, .controls .ctrl-tick, .controls .ctrl-go {
    flex: 1 1 auto; min-width: 90px; text-align: center;
  }

  /* --- Tables scroll horizontally instead of squashing --- */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .data-table { min-width: 560px; }

  /* --- Forms go single-column --- */
  .grid-form { grid-template-columns: 1fr; }
  .grid-form label.full { grid-column: auto; }
  .row-form fieldset { min-width: 0; }

  /* --- Tabs (agents page) scroll horizontally --- */
  .tab-bar { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
  .tab { white-space: nowrap; padding: 12px 14px; }

  /* --- Pattern detail + help modals go (nearly) full screen --- */
  .modal-backdrop { padding: 8px; }
  .modal-card { max-height: 94vh; }
  .modal-kpis { grid-template-columns: repeat(3, 1fr); }
  .modal-kpi { padding: 9px 10px; }
  .modal-kpi-v { font-size: 13px; }
  .modal-chart-wrap { min-height: 300px; }
  .modal-head { padding: 14px 16px 12px; }
  .modal-head h2 { font-size: 16px; }

  /* --- Logs page controls wrap --- */
  .logs-controls { width: 100%; }
  .logs-controls select { min-width: 0; flex: 1 1 140px; }
  .log-row { grid-template-columns: 1fr; gap: 2px; padding: 8px 12px; }
  .log-row .log-ts { font-size: 10px; }

  /* --- Pattern grid (agent form) single column --- */
  .pattern-grid { grid-template-columns: 1fr; }

  /* --- Login card full-width padding --- */
  .login-card { margin: 16px; padding: 28px 22px; }

  /* iOS zooms the viewport when a focused input has font-size < 16px.
     Bump form controls to 16px on mobile to prevent that jarring zoom. */
  input, select, textarea { font-size: 16px; }
}

/* ============================================================
   SMALL PHONES  (≤ 420px) — drop KPI strip to 1 wide-ish col pair
   ============================================================ */
@media (max-width: 420px) {
  .modal-kpis { grid-template-columns: repeat(2, 1fr); }
  .brand-name { font-size: 13px; }
  .kpi-v { font-size: 16px; }
}

/* Stacked form used on the profile page */
.stack-form label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--text-dim); }
.stack-form input { width: 100%; }
.stack-form .btn-primary { margin-top: 4px; }
.success {
  color: var(--good);
  background: var(--good-soft);
  border: 1px solid rgba(52,211,153,.3);
  padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 14px;
}

/* ============================================================
   STATUS CHIP — worker liveness pill in the topbar
   ============================================================ */
.status-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 12px; border-radius: 999px;
  font-family: var(--mono); font-size: 11px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text-dim);
  letter-spacing: .3px;
  white-space: nowrap;
}
.status-chip-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-faint); flex-shrink: 0;
}
.status-chip.is-alive { color: var(--good); border-color: rgba(52,211,153,.3); background: var(--good-soft); }
.status-chip.is-alive .status-chip-dot { background: var(--good); box-shadow: 0 0 0 3px rgba(52,211,153,.15); animation: pulse 2.4s ease-in-out infinite; }
.status-chip.is-stale { color: var(--bad);  border-color: rgba(248,113,113,.3); background: var(--bad-soft); }
.status-chip.is-stale .status-chip-dot { background: var(--bad); }
.status-chip.is-idle  { color: var(--text-dim); }
.status-chip.is-idle  .status-chip-dot { background: var(--text-faint); }

/* ============================================================
   TIMEFRAME SWITCHER (over the price chart)
   ============================================================ */
.tf-switcher {
  display: inline-flex; gap: 2px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px;
}
.tf-btn {
  font-family: var(--mono); font-size: 11px; font-weight: 500;
  color: var(--text-dim);
  background: transparent;
  border: none;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  letter-spacing: .5px;
  transition: all .12s ease;
}
.tf-btn:hover { color: var(--text); background: var(--bg-elev-2); }
.tf-btn.is-active {
  color: var(--accent);
  background: var(--accent-soft);
}

/* The chart-wrap holds the lightweight-charts canvas; needs explicit
   positioning so the chart fills it. */
.chart-wrap { position: relative; flex: 1 1 auto; min-height: 320px; }
.chart-wrap-sm { min-height: 220px; }

/* ============================================================
   TABS (agents page)
   ============================================================ */
.tab-bar {
  display: flex; gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
}
.tab {
  font-family: var(--mono); font-size: 11px; letter-spacing: 1.5px;
  color: var(--text-dim); text-transform: uppercase;
  background: transparent;
  border: none;
  padding: 12px 18px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all .12s ease;
  display: inline-flex; align-items: center; gap: 8px;
}
.tab:hover { color: var(--text); background: rgba(255,255,255,0.02); }
.tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.tab-count {
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  color: var(--text-faint);
  letter-spacing: 0;
}
.tab.is-active .tab-count { background: var(--accent-soft); color: var(--accent); }

.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

/* Form helper: full-width spans both columns of grid-form */
.grid-form label.full { grid-column: span 2; }

/* H4 inside the help card */
.tab-panel h4 {
  font-family: var(--mono); font-size: 11px; letter-spacing: 2px;
  color: var(--text-dim); text-transform: uppercase;
  margin: 18px 0 8px;
}

/* ============================================================
   LOGS PAGE
   ============================================================ */
.logs-header {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 18px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.logs-controls {
  display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
}
.logs-controls label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--text-dim);
}
.logs-controls .ctrl-label {
  font-family: var(--mono); font-size: 10px; letter-spacing: 1.5px;
  color: var(--text-faint); text-transform: uppercase;
}
.logs-controls select {
  width: auto; min-width: 160px;
}
.logs-controls .ctrl-checkbox {
  flex-direction: row; align-items: center; gap: 8px;
  padding-bottom: 9px;
  font-size: 12px; color: var(--text);
}
.logs-controls .ctrl-checkbox input { width: auto; }

.log-stream {
  font-family: var(--mono); font-size: 12px;
  background: var(--bg);
  max-height: 70vh; overflow-y: auto;
  padding: 4px 0;
  border-radius: 12px;
}
.log-row {
  display: grid;
  grid-template-columns: 130px 50px 200px 1fr;
  gap: 10px;
  padding: 5px 16px;
  border-bottom: 1px solid var(--line-soft);
  line-height: 1.5;
  align-items: baseline;
}
.log-row:hover { background: rgba(255,255,255,0.02); }
.log-ts    { color: var(--text-faint); font-size: 11px; white-space: nowrap; }
.log-lvl   { color: var(--text-dim);   font-size: 10px; letter-spacing: 1px; }
.log-agent { color: var(--text);       font-size: 11px; }
.log-agent em { color: var(--text-faint); font-style: normal; font-size: 10px; }
.log-msg   { color: var(--text-dim); white-space: pre-wrap; word-break: break-word; }
.log-row.log-info  .log-lvl { color: var(--accent-2); }
.log-row.log-warn  { background: rgba(251,191,36,0.03); }
.log-row.log-warn  .log-lvl, .log-row.log-warn  .log-msg { color: var(--warn); }
.log-row.log-error { background: rgba(248,113,113,0.03); }
.log-row.log-error .log-lvl, .log-row.log-error .log-msg { color: var(--bad); }

/* ============================================================
   PATTERN GRID & CHECK TILES (create/edit agent form)
   ============================================================ */
.pattern-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
  margin: 10px 0 14px;
}
.check-tile {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-elev-2);
  cursor: pointer;
  transition: all .12s ease;
  font-size: 13px; color: var(--text-dim);
  font-family: var(--sans);
}
.check-tile input[type=checkbox] {
  width: auto; margin: 0;
}
.check-tile:hover { border-color: var(--line-strong); color: var(--text); }
.check-tile input[type=checkbox]:checked + span { color: var(--text); }
.check-tile:has(input:checked) {
  background: var(--accent-soft);
  border-color: rgba(245,165,36,.3);
  color: var(--accent);
}
.pattern-actions {
  display: flex; gap: 8px; margin-bottom: 8px;
}

/* The scale-in toggle row */
.check-row {
  display: flex !important; flex-direction: row !important;
  align-items: flex-start; gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-elev-2);
}
.check-row input[type=checkbox] {
  width: auto; margin: 4px 0 0;
}
.check-row strong { color: var(--text); }
.check-row small { display: block; margin-top: 6px; color: var(--text-dim); }

/* Edit button on the agent rows */
.btn-edit {
  display: inline-block;
  padding: 6px 12px;
  font-size: 12px;
  background: var(--accent-2-soft);
  color: var(--accent-2);
  border: 1px solid rgba(56,189,248,.3);
  border-radius: 6px;
  text-decoration: none;
  margin-right: 6px;
}
.btn-edit:hover { background: rgba(56,189,248,.2); text-decoration: none; }

/* ============================================================
   FUTURES ACCOUNT BLOCKS (balances page)
   ============================================================ */
.futures-account {
  margin-bottom: 16px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-elev-2);
}
.futures-account:last-child { margin-bottom: 0; }
.futures-account-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line-soft);
}
.futures-account-name {
  font-family: var(--mono); font-size: 13px;
  text-transform: uppercase; letter-spacing: 1.5px;
  color: var(--text);
}
.futures-account-usd {
  font-size: 18px; font-weight: 500;
  color: var(--text);
}
.futures-account-meta {
  display: flex; gap: 18px; flex-wrap: wrap;
  font-size: 12px;
  margin: 6px 0 4px;
}
.futures-account-meta .meta-k {
  font-family: var(--mono); font-size: 10px; letter-spacing: 1.2px;
  color: var(--text-faint); text-transform: uppercase;
  margin-right: 6px;
}

/* ============================================================
   PATTERN DETAIL MODAL
   ============================================================ */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 24px;
  animation: modal-fade-in .12s ease-out;
}
.modal-backdrop[hidden] { display: none; }
@keyframes modal-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  width: 100%;
  max-width: 1100px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 30px 60px rgba(0,0,0,0.5);
}

.modal-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--line-soft);
  gap: 16px;
}
.modal-head h2 {
  margin: 0 0 4px;
  font-size: 18px; font-weight: 600;
  color: var(--text);
}
.modal-head .meta {
  margin: 0;
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 1px;
}
.modal-close {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-dim);
  width: 32px; height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--bg-elev-2); color: var(--text); }

.modal-kpis {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 1px;
  background: var(--line-soft);
  padding: 1px 0;
}
.modal-kpi {
  background: var(--bg-elev);
  padding: 12px 14px;
  text-align: left;
}
.modal-kpi-k {
  font-family: var(--mono); font-size: 10px;
  text-transform: uppercase; letter-spacing: 1.5px;
  color: var(--text-faint);
  margin-bottom: 4px;
}
.modal-kpi-v {
  font-family: var(--mono); font-size: 15px;
  color: var(--text);
}

.modal-chart-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 380px;
  background: var(--bg);
}
.modal-loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  background: var(--bg);
  pointer-events: none;
}

.modal-legend {
  display: flex; flex-wrap: wrap; gap: 14px;
  padding: 12px 22px;
  border-top: 1px solid var(--line-soft);
  font-family: var(--mono); font-size: 11px;
  color: var(--text-dim);
  background: var(--bg-elev);
}
.legend-item {
  display: inline-flex; align-items: center; gap: 6px;
  letter-spacing: .5px;
}
.legend-swatch {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 2px;
}
.modal-note {
  padding: 14px 22px;
  font-size: 12px;
  color: var(--warn);
  background: rgba(251,191,36,0.05);
  border-bottom: 1px solid var(--line-soft);
}

/* Make .pat-row clickable and obvious. */
.pat-row {
  cursor: pointer;
  transition: background .12s ease;
}
.pat-row:hover {
  background: rgba(255,255,255,0.025);
}
.pat-row:focus {
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}

/* ============================================================
   HELP ICON + HELP MODAL
   ============================================================ */
.help-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px;
  margin-left: 8px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--bg-elev-2);
  color: var(--text-faint);
  font-size: 10px; font-weight: 600;
  font-family: var(--mono);
  cursor: pointer;
  transition: all .12s ease;
  vertical-align: middle;
  line-height: 1;
}
.help-icon:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.help-card { max-width: 720px; }
.help-body {
  padding: 4px 24px 24px;
  overflow-y: auto;
  max-height: 75vh;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.6;
}
.help-body section + section { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line-soft); }
.help-body h3 {
  margin: 14px 0 8px;
  font-size: 14px;
  color: var(--text);
  font-family: var(--sans);
  font-weight: 600;
}
.help-body p { margin: 0 0 10px; }
.help-body ul { margin: 0 0 10px; padding-left: 22px; }
.help-body li { margin: 4px 0; }
.help-body .meta {
  font-size: 12px;
  color: var(--text-faint);
  font-style: italic;
}
.help-body strong { color: var(--text); font-weight: 600; }
.help-body em { color: var(--accent); font-style: normal; }
