/* ============================================================
   OptionCycle — Kite-inspired light theme
   ============================================================ */
:root {
  --bg:           #f4f5f7;        /* page bg */
  --surface:      #ffffff;        /* cards */
  --surface-2:    #f7f8fa;        /* sub-cards / inset panels */
  --surface-hover:#f1f3f6;
  --border:       #e6e8ec;
  --border-2:     #d6dae0;

  --text:         #1c1f23;
  --text-soft:    #5b6370;
  --muted:        #8a91a0;

  --accent:       #387ed1;        /* kite blue */
  --accent-2:     #2563b3;
  --accent-soft:  rgba(56, 126, 209, 0.08);

  --green:        #1ea355;
  --green-soft:   rgba(30, 163, 85, 0.10);
  --red:          #e0463c;
  --red-soft:     rgba(224, 70, 60, 0.10);
  --amber:        #d9892b;
  --amber-soft:   rgba(217, 137, 43, 0.10);

  --shadow-sm:    0 1px 2px rgba(15, 23, 42, 0.05), 0 1px 1px rgba(15, 23, 42, 0.03);
  --shadow:       0 2px 8px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg:    0 8px 28px rgba(15, 23, 42, 0.10), 0 2px 6px rgba(15, 23, 42, 0.05);
  --radius:       9px;
  --radius-lg:    14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* legacy dark-mode artefacts no-op'd */
.bg-orb { display: none; }

/* ─── Topbar ──────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 28px;
  height: 60px;                 /* explicit so tab-bar can sit flush beneath */
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  text-decoration: none;
  color: inherit;
  user-select: none;
}
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #387ed1 0%, #5b8def 50%, #8d4cff 100%);
  display: grid; place-items: center;
  box-shadow: 0 6px 18px rgba(56, 126, 209, 0.35),
              inset 0 1px 0 rgba(255,255,255,0.25);
  transition: transform 0.12s, box-shadow 0.12s;
}
.brand:hover .brand-mark {
  transform: rotate(-4deg) scale(1.04);
  box-shadow: 0 8px 22px rgba(56, 126, 209, 0.45),
              inset 0 1px 0 rgba(255,255,255,0.3);
}

.brand-wordmark {
  font-family: "Inter", sans-serif;
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.025em;
  line-height: 1;
  display: flex;
  align-items: baseline;
}
.wm-option { color: var(--text); }
.wm-cycle  {
  background: linear-gradient(90deg, var(--accent), #8d4cff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

@media (max-width: 720px) {
  .brand-wordmark { font-size: 17px; }
}

.topbar-right { display: flex; align-items: center; gap: 14px; }

/* Market status badge */
.market-status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 999px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: var(--text-soft);
  user-select: none;
}
.market-status .ms-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
}
.market-status-open { background: var(--green-soft); border-color: rgba(30,163,85,0.5); color: var(--green); }
.market-status-open .ms-dot { background: var(--green); animation: pulse-dot 1.4s ease-in-out infinite; }
.market-status-closed { background: var(--red-soft); border-color: rgba(224,70,60,0.4); color: var(--red); }
.market-status-closed .ms-dot { background: var(--red); }

/* Expiry auto-monitor pill (global topbar indicator) */
.monitor-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  user-select: none;
  cursor: default;
}
.monitor-pill .mp-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); display: inline-block;
}
/* running = green + pulsing */
.monitor-pill.running {
  background: var(--green-soft); border: 1px solid rgba(30,163,85,0.5); color: var(--green);
}
.monitor-pill.running .mp-dot { background: var(--green); animation: pulse-dot 1.4s ease-in-out infinite; }
/* alert = positions live but monitor NOT running */
.monitor-pill.alert {
  background: var(--red-soft); border: 1px solid rgba(224,70,60,0.5); color: var(--red);
}
.monitor-pill.alert .mp-dot { background: var(--red); }

/* Positions chip — same height/border-radius as user-chip for uniformity. */
.positions-chip {
  display: inline-flex; align-items: center; gap: 12px;
  padding: 0 18px;
  background: var(--surface-2);
  border: 1.5px solid var(--border-2);
  font-family: inherit;
  cursor: pointer;
  color: var(--text);
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
  line-height: 1;
}
.positions-chip:hover { background: var(--surface-hover); }
.positions-chip .pos-label {
  font-size: 10.5px; color: var(--muted); letter-spacing: 0.7px;
  text-transform: uppercase; font-weight: 600;
}
.positions-chip .pos-value {
  font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums;
  color: var(--text); letter-spacing: -0.01em;
}
.positions-chip .pos-count {
  font-size: 11.5px;
  color: var(--muted);
  padding-left: 10px;
  border-left: 1px solid var(--border-2);
  font-weight: 500;
}
.positions-chip.pos {
  background: var(--green-soft);
  border-color: rgba(30,163,85,0.5);
  box-shadow: 0 1px 6px rgba(30,163,85,0.15);
}
.positions-chip.pos .pos-value { color: var(--green); }
.positions-chip.pos .pos-count { border-left-color: rgba(30,163,85,0.3); }
.positions-chip.neg {
  background: var(--red-soft);
  border-color: rgba(224,70,60,0.5);
  box-shadow: 0 1px 6px rgba(224,70,60,0.15);
}
.positions-chip.neg .pos-value { color: var(--red); }
.positions-chip.neg .pos-count { border-left-color: rgba(224,70,60,0.3); }

/* Both topbar chips share the same height & rounding for a uniform look. */
.user-chip, .positions-chip {
  height: 44px;
  box-sizing: border-box;
  border-radius: 999px;
}

.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 14px 4px 4px;
  background: var(--surface-2);
  border: 1.5px solid var(--border-2);
  transition: background 0.12s, border-color 0.12s;
}
.user-chip:hover { background: var(--surface-hover); }
.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent);
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
  color: white;
  letter-spacing: 0.3px;
}
.user-name { font-size: 14px;  font-weight: 600; line-height: 1.2; color: var(--text); }
.user-id   { font-size: 11.5px; color: var(--muted); line-height: 1.2; }
.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-soft);
  width: 26px; height: 26px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.12s;
  display: grid; place-items: center;
}
.ghost-btn:hover { background: var(--red-soft); color: var(--red); border-color: var(--red); }

/* ─── Tab bar (centered pill group) ───────────────────── */
/* ─── Sidebar navigation ──────────────────────────────────
   Fixed vertical sidebar below the 60px topbar. On phones it
   collapses to a horizontal bottom bar (see responsive block). */
:root { --sidebar-w: 212px; }

.tab-bar {
  position: fixed;
  top: 60px;                    /* sits below the 60px topbar */
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 4;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
}
.tab-bar-inner {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 10px;
}
.tab {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 9px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-soft);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
  letter-spacing: -0.005em;
  position: relative;
}
.tab svg {
  width: 18px; height: 18px;
  flex-shrink: 0;
  opacity: 0.75;
  fill: currentColor;
}
.tab .tab-label { line-height: 1; }
.tab:hover { color: var(--text); background: var(--surface-hover); }
.tab.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.tab.active svg { opacity: 1; }
/* accent rail on the active item */
.tab.active::before {
  content: "";
  position: absolute;
  left: 0; top: 18%; bottom: 18%;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

/* Tabs size to their content. Sticky footer activates only when content
   actually overflows the viewport — no phantom scrolling on short pages. */
.tab-panel { display: none; flex-direction: column; gap: 16px; }
.tab-panel.active {
  display: flex;
  animation: tab-fade-in 0.16s ease-out;
}
@keyframes tab-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Long tables inside any card scroll within themselves rather than
   stretching the page indefinitely. Empty tables stay compact because
   the .empty placeholder is a single small row. */
.card > .table-wrap {
  max-height: 56vh;
  overflow: auto;
}

.section-h4 {
  margin: 22px 0 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  font-weight: 500;
}

/* ─── Container ───────────────────────────────────────── */
.container {
  max-width: 1180px;
  margin: 0 auto;                  /* logged-out: centered (no sidebar) */
  padding: 24px 32px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
/* When the sidebar is visible (logged in), shift content right to clear it.
   :has() lets us key off sidebar visibility with zero JS changes. */
body:has(#tab-bar:not(.hidden)) .container {
  margin-left: var(--sidebar-w);
  margin-right: 0;
}

/* ─── Cards ───────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.card h1 { margin: 0 0 6px; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.card h2 { margin: 0; font-size: 14px; font-weight: 600; color: var(--text); letter-spacing: -0.005em; }

.muted     { color: var(--text-soft); font-size: 12.5px; margin: 0 0 16px; }
.fineprint { color: var(--muted); font-size: 11px; margin: 12px 0 0; }

/* Auto-login status / error remark on the auth card */
.auth-msg { font-size: 13px; margin: 4px 0 14px; min-height: 18px; color: var(--muted); }
.auth-msg.err { color: var(--danger, #d23b3b); font-weight: 600; }

/* Auto-login toggle + editable settings */
.autologin-box {
  border: 1px solid var(--border, #e3e6ea);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 6px 0 16px;
  text-align: left;
}
.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 14px; font-weight: 600; cursor: pointer; gap: 12px;
}
/* iOS-style toggle switch (semantically a checkbox, visually a slider) */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--border, #cfd4da); border-radius: 999px; transition: background .18s ease;
}
.switch .slider::before {
  content: ""; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform .18s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.switch input:checked + .slider { background: var(--accent, #2c6e49); }
.switch input:checked + .slider::before { transform: translateX(20px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent, #2c6e49); outline-offset: 2px; }
.autologin-settings { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.autologin-settings.hidden { display: none; }
.al-field {
  display: flex; flex-direction: column; gap: 3px;
  font-size: 12px; color: var(--muted);
}
.al-field input {
  padding: 8px 10px; border: 1px solid var(--border, #e3e6ea);
  border-radius: 8px; font-size: 13px; color: var(--text, #1a1a1a);
  background: var(--surface, #fff);
}
.autologin-actions { display: flex; gap: 8px; margin-top: 6px; }
.autologin-actions button { flex: 1; }
.fineprint.warn { color: var(--danger, #d23b3b); }

/* ─── Auth card ───────────────────────────────────────── */
.auth-card {
  max-width: 420px;
  margin: 60px auto 0;
  text-align: center;
  padding: 32px 28px;
}

/* ─── Buttons ─────────────────────────────────────────── */
.primary-btn, .secondary-btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid transparent;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
  white-space: nowrap;
}
.primary-btn {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.primary-btn:hover { background: var(--accent-2); border-color: var(--accent-2); }
.primary-btn.big   { padding: 12px 22px; font-size: 13.5px; margin-top: 8px; }
.kite-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: white;
}

.secondary-btn {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-2);
}
.secondary-btn:hover { background: var(--surface-hover); border-color: var(--muted); }

.primary-btn.danger-btn {
  background: var(--red);
  border-color: var(--red);
}
.primary-btn.danger-btn:hover {
  background: #c03830;
  border-color: #c03830;
}

button:disabled { opacity: 0.55; cursor: not-allowed; }

/* ─── Stat cards (Holdings summary) ───────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 15px 17px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}
.stat-card:hover {
  box-shadow: var(--shadow);
  border-color: var(--border-2);
  transform: translateY(-1px);
}
.stat-label { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.stat-value { font-size: 18px; font-weight: 600; margin-top: 4px; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; color: var(--text); }
.stat-sub   { font-size: 11px; color: var(--text-soft); margin-top: 2px; font-variant-numeric: tabular-nums; }
.pos { color: var(--green) !important; }
.neg { color: var(--red)   !important; }

/* ─── Tables ──────────────────────────────────────────── */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table.holdings {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.holdings th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.5px;
  background: var(--surface-2);
  position: sticky; top: 0;
}
table.holdings th:first-child { border-top-left-radius: var(--radius); }
table.holdings th:last-child  { border-top-right-radius: var(--radius); }
table.holdings td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
/* zebra striping for scan-ability on dense tables */
table.holdings tbody tr:nth-child(even) td { background: var(--surface-2); }
table.holdings tr:last-child td { border-bottom: 0; }
table.holdings tbody tr { transition: background 0.1s; }
table.holdings tbody tr:hover td { background: var(--accent-soft); }
table.holdings .num { text-align: right; }
table.holdings .sym { font-weight: 500; color: var(--text); }
table.holdings .ex-chip {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  font-size: 10px;
  color: var(--text-soft);
  letter-spacing: 0.3px;
  font-weight: 500;
}
.empty { text-align: center; color: var(--muted); padding: 24px !important; }

.ex-chip.pos  { color: var(--green); border-color: rgba(30, 163, 85, 0.35); background: var(--green-soft); }
.ex-chip.neg  { color: var(--red);   border-color: rgba(224, 70, 60, 0.35); background: var(--red-soft);   }
.ex-chip.warn { color: var(--amber); border-color: rgba(217, 137, 43, 0.40); background: var(--amber-soft); }

.muted-cell { color: var(--text-soft); font-size: 11.5px; }

/* ─── Collapsible card (Holdings) ─────────────────────── */
details.collapsible { padding: 0; overflow: hidden; }
details.collapsible > summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 20px;
  margin: 0;
  user-select: none;
  background: var(--surface);
  transition: background 0.12s;
  display: flex; align-items: center; justify-content: space-between;
}
details.collapsible > summary:hover { background: var(--surface-hover); }
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible .chev {
  display: inline-block;
  transition: transform 0.18s ease;
  color: var(--muted);
  font-size: 11px;
  margin-left: 4px;
}
details.collapsible[open] .chev { transform: rotate(180deg); }
details.collapsible .collapsible-body {
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border);
}

/* ─── Chain summary + grid ────────────────────────────── */
.chain-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 14px;
  padding: 12px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.chain-stat .stat-value { font-size: 16px; }
.chain-stat .stat-value.accent { color: var(--accent); }

.chain-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.chain-col {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.chain-col-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 8px;
}

/* ─── Chain controls (auto pill + updated label) ──────── */
.chain-controls { display: flex; align-items: center; gap: 8px; }
.btn-row        { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.updated-pill {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.3px;
}
.auto-pill {
  background: var(--surface);
  color: var(--text-soft);
  border: 1px solid var(--border-2);
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.12s;
  letter-spacing: 0.2px;
}
.auto-pill:hover { background: var(--surface-hover); }
.auto-pill.on {
  background: var(--green-soft);
  color: var(--green);
  border-color: rgba(30, 163, 85, 0.4);
}

/* ─── Algo card extras ────────────────────────────────── */
.warn-banner {
  background: var(--amber-soft);
  border: 1px solid rgba(217, 137, 43, 0.35);
  color: #855413;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  line-height: 1.5;
  margin-bottom: 14px;
}
.warn-banner b { color: #6a3f0a; }

.run-detail {
  margin-top: 16px;
  padding: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.run-detail-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 6px;
}
.run-detail h3 { margin: 0; font-size: 13px; font-weight: 600; color: var(--text); }
.run-detail h4 {
  margin: 14px 0 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  font-weight: 500;
}
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--accent-soft); }

/* ─── Daily limit ─────────────────────────────────────── */
.dl-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
}
.dl-row {
  display: flex; align-items: center; gap: 18px;
  flex-wrap: wrap;
}
.dl-cell { flex: 1 1 130px; min-width: 0; }
.dl-label {
  color: var(--muted);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
}
.dl-value {
  font-size: 16px;
  font-weight: 600;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.dl-bar {
  height: 5px;
  background: var(--surface-hover);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 10px;
}
.dl-bar-fill {
  height: 100%;
  background: var(--green);
  width: 0;
  transition: width 0.3s ease, background 0.2s ease;
}
.dl-bar-fill.warn   { background: var(--amber); }
.dl-bar-fill.danger { background: var(--red); }

/* ─── Kill switches ───────────────────────────────────── */
.kill-row {
  display: flex; gap: 10px;
  margin: 0 0 16px;
  flex-wrap: wrap;
}
.ks-btn {
  flex: 1 1 220px;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  border: 1px solid;
  transition: all 0.12s;
  letter-spacing: 0.2px;
}
.ks-amber {
  background: var(--amber-soft);
  color: #855413;
  border-color: rgba(217, 137, 43, 0.55);
}
.ks-amber:hover { background: rgba(217, 137, 43, 0.18); }
.ks-red {
  background: var(--red);
  color: white;
  border-color: var(--red);
}
.ks-red:hover { background: #b03830; border-color: #b03830; }

.kill-banner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  background: var(--red-soft);
  border: 1.5px solid var(--red);
  color: #8a2820;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 14px;
  animation: kill-pulse 2.5s ease-in-out infinite;
}
.kill-banner b { color: var(--red); font-weight: 700; }
@keyframes kill-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(224, 70, 60, 0.0); }
  50%      { box-shadow: 0 0 0 4px rgba(224, 70, 60, 0.15); }
}

/* ─── Raw output ──────────────────────────────────────── */
.raw summary {
  cursor: pointer;
  list-style: none;
  color: var(--text-soft);
  font-size: 12.5px;
  user-select: none;
  font-weight: 500;
}
.raw summary::-webkit-details-marker { display: none; }
.raw summary::before { content: "▸ "; transition: transform 0.15s; display: inline-block; }
.raw[open] summary::before { transform: rotate(90deg); }
.raw pre {
  margin: 12px 0 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11px;
  color: var(--text);
  max-height: 240px;       /* tighter so the footer doesn't dominate the viewport */
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Raw API response: stick to the bottom of the viewport while on the tab.
   Collapsed by default → tiny strip; expanded → ~240px scrollable pre. */
.tab-panel > .raw {
  position: sticky;
  bottom: 0;
  z-index: 3;
  margin-top: auto;        /* push to the bottom in the flex layout */
  background: var(--surface);
  box-shadow: 0 -6px 14px rgba(15, 23, 42, 0.05);
  border-radius: var(--radius-lg);
  padding: 12px 18px;      /* compact strip when collapsed */
}
.tab-panel > .raw[open] {
  padding-bottom: 16px;
}

/* ─── Margin strip + lot picker (Expiry tab) ──────────── */
.margin-strip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.margin-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}
.m-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.m-label {
  color: var(--muted);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 600;
}
.m-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.m-card.lot-card { background: var(--accent-soft); border-color: rgba(56,126,209,0.4); }
.lot-controls {
  display: flex; align-items: center; gap: 10px;
  margin-top: 2px;
}
.lot-btn {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--surface);
  border: 1.5px solid var(--border-2);
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
  display: grid; place-items: center;
  line-height: 1;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
}
.lot-btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.lot-btn:active { transform: scale(0.93); }
.lot-count {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 22px;
  text-align: center;
}
.m-note {
  margin-top: 14px;
  font-size: 11.5px;
  text-align: center;
}

/* Submit button row — aligned under the CE + PE cards (cols 4-5 of margin-row) */
.lot-submit-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-top: 8px;                     /* tighter — flush with cards above */
}
.lot-submit-cell {
  grid-column: 4 / span 2;             /* spans CE + PE columns */
  display: flex; flex-direction: column;
  align-items: stretch; gap: 4px;
}
.lot-submit-btn {
  width: 100%;
  min-height: 44px;
  padding: 11px 18px;
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: 0.2px;
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(56, 126, 209, 0.18);
  display: inline-flex;
  align-items: center;
  justify-content: center;             /* CENTER the "Submit" label */
  text-align: center;
}
.lot-submit-btn:hover {
  box-shadow: 0 4px 12px rgba(56, 126, 209, 0.28);
}
.lot-submit-cell .muted-cell {
  font-size: 11px;
  text-align: center;
}

@media (max-width: 980px) {
  .lot-submit-row { grid-template-columns: 1fr; }
  .lot-submit-cell { grid-column: 1; }
}

/* Total-quantity line inside each CE/PE lot card */
.qty-line {
  margin-top: 8px;
  padding: 6px 10px;
  background: var(--accent-soft);
  border: 1px solid rgba(56,126,209,0.4);
  border-radius: 7px;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px;
}
.qty-label {
  color: var(--muted);
  font-size: 10.5px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-weight: 600;
}
.qty-value {
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 14px;
}

/* Mini contract preview under each CE/PE lot picker */
.mini-pick {
  margin-top: 8px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 7px;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px;
  gap: 8px;
}
.mini-pick-sym {
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mini-pick-ltp {
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12.5px;
}

@media (max-width: 980px) {
  .margin-row { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 640px) {
  .margin-row { grid-template-columns: repeat(2, 1fr); }
}

/* ─── Expiry banner (prominent date) ──────────────────── */
.expiry-banner {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 0 0 18px;
}
.expiry-card {
  background: linear-gradient(135deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.expiry-card::before {
  content: "";
  position: absolute;
  top: 0; right: 0;
  width: 80px; height: 80px;
  background: radial-gradient(circle at top right, var(--accent-soft), transparent 70%);
  pointer-events: none;
}
.exp-card-label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 500;
  position: relative;
}
.exp-card-date {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  margin-top: 4px;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  position: relative;
}
.exp-card-meta {
  font-size: 12.5px;
  color: var(--text-soft);
  margin-top: 4px;
  position: relative;
}
.exp-days {
  font-weight: 600;
  color: var(--text);
}
.expiry-card.expiry-today {
  background: linear-gradient(135deg, var(--green-soft), var(--surface-2));
  border-color: var(--green);
  box-shadow: 0 0 0 1px var(--green);
}
.expiry-card.expiry-today .exp-card-date { color: var(--green); }
.expiry-card.expiry-today .exp-days       { color: var(--green); }

.expiry-card.expiry-soon { border-color: var(--amber); }
.expiry-card.expiry-soon .exp-days { color: var(--amber); }

/* Nearest (leftmost) expiry gets a soft green tint - per user spec */
.expiry-card.expiry-nearest {
  background: linear-gradient(135deg, rgba(30,163,85,0.12), rgba(30,163,85,0.04));
}
.expiry-card.expiry-nearest .exp-card-date { color: var(--green); }

/* All cards are now clickable; show pointer + selected outline */
button.expiry-card {
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
  width: 100%;
}
.expiry-card.selected {
  box-shadow: 0 0 0 2px var(--accent);
  border-color: var(--accent);
}
.expiry-card.selected.expiry-nearest {
  box-shadow: 0 0 0 2px var(--green);
  border-color: var(--green);
}

.accent-text { color: var(--accent); font-weight: 600; }

@media (max-width: 800px) {
  .expiry-banner { grid-template-columns: 1fr; }
}

/* ─── Expiry snapshot ─────────────────────────────────── */
.snap-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 22px 0 10px;
}
.snap-head .section-h4 { margin: 0; }

.cand-grid {
  display: grid;
  grid-template-columns: 1fr;   /* NIFTY stacked above SENSEX so tables get full width */
  gap: 14px;
}
.cand-col {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  min-width: 0;
  overflow: hidden;             /* contain children */
}
.cand-head {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text);
}
.cand-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;   /* CE | PE side-by-side within an index */
  gap: 12px;
  min-width: 0;
}
.cand-side { min-width: 0; }
.cand-side .chain-col-head { font-size: 11px; }
.cand-side .table-wrap { max-height: 280px; overflow-y: auto; overflow-x: hidden; }
.cand-side table.holdings { table-layout: fixed; }
.cand-side table.holdings th { font-size: 9.5px; padding: 6px 8px; }
.cand-side table.holdings td { padding: 6px 8px; font-size: 12px; }
.cand-side table.holdings td.sym {
  max-width: 0;                   /* with table-layout:fixed this lets td shrink */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 720px) {
  .cand-pair { grid-template-columns: 1fr; }    /* CE & PE stack on mobile */
}

/* ─── Patterns tab (chart panel) ──────────────────────── */
.pat-summary { margin: 6px 0 16px; }

.vwap-legend {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  font-size: 11.5px; padding: 8px 12px;
  background: var(--surface-2); border-radius: 8px;
  border: 1px solid var(--border);
  margin: 0 0 10px;
}

/* Chart toolbar: zoom controls + inline legend in one clean row */
.chart-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 6px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 0 0 10px;
}
.chart-zoom-controls { display: flex; gap: 4px; }
.chart-tool-btn {
  width: 30px; height: 30px;
  border: 1px solid var(--border-2);
  background: var(--surface);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px; font-weight: 700;
  color: var(--text-soft);
  display: grid; place-items: center;
  font-family: inherit;
  transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.08s;
  line-height: 1;
}
.chart-tool-btn:hover  { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chart-tool-btn:active { transform: scale(0.94); }

.chart-legend {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 11.5px;
  color: var(--text-soft);
}
.chart-legend .legend-sep { color: var(--muted); }

/* ─── Cycle Backtest form (Patterns tab) ──────────────── */
.bt-form {
  display: flex; align-items: flex-end;
  flex-wrap: wrap;
  gap: 10px 14px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
}
.bt-form .inline-label {
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  font-weight: 600;
}
.bt-form input[type="number"],
.bt-form input[type="date"] {
  padding: 6px 8px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.bt-form input[type="number"] { width: 84px; }
.bt-form input[type="date"]   { width: 140px; }
.bt-form #bt-run-btn          { margin-top: 14px; }   /* aligns with the labelled inputs */

/* ─── Realtime status banner (modular — see app/realtime.py) ─── */
.rt-banner {
  display: flex; align-items: center; justify-content: center;
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.6px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 14px;
}
.rt-banner.running {
  background: var(--green-soft);
  border-color: rgba(30, 163, 85, 0.4);
  color: var(--green);
}
.rt-banner.running::before {
  content: "●";
  margin-right: 8px;
  animation: pulse-dot 1.4s ease-in-out infinite;
}
.rt-banner.stopped {
  background: var(--surface-2);
  color: var(--muted);
}
#rt-form #rt-start-btn, #rt-form #rt-stop-btn { margin-top: 14px; }

/* ─── Expiry auto-monitor status banner ───────────────── */
.exp-monitor-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px;
  margin-bottom: 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.exp-monitor-banner .emb-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.exp-monitor-banner.running {
  background: var(--green-soft);
  border-color: rgba(30, 163, 85, 0.4);
  color: var(--green);
}
.exp-monitor-banner.running .emb-dot {
  background: var(--green);
  animation: pulse-dot 1.4s ease-in-out infinite;
}
.exp-monitor-banner.stopped { background: var(--surface-2); color: var(--muted); }
.exp-monitor-banner #exp-monitor-stop-btn {
  margin-left: auto;
  flex-shrink: 0;
}
.exp-monitor-banner #exp-monitor-stop-btn:hover {
  background: var(--red-soft); color: var(--red); border-color: var(--red);
}

@media (max-width: 720px) {
  .bt-form                       { gap: 8px 10px; padding: 10px; }
  .bt-form input[type="number"]  { width: 70px; }
  .bt-form input[type="date"]    { width: 130px; }
}
@media (max-width: 480px) {
  .bt-form .inline-label         { flex: 1 1 calc(50% - 8px); }   /* 2-up on phones */
  .bt-form input[type="number"],
  .bt-form input[type="date"]    { width: 100%; }
  .bt-form #bt-run-btn           { width: 100%; margin-top: 4px; }
}
@media (max-width: 480px) {
  .chart-tool-btn        { width: 32px; height: 32px; }   /* slightly bigger tap target */
  .chart-toolbar         { padding: 6px 8px; gap: 8px; }
  .chart-legend          { font-size: 11px; gap: 6px; }
}
.legend-line {
  display: inline-block; width: 22px; height: 3px;
  vertical-align: middle; border-radius: 2px;
}
.legend-line.center { background: #1e3a5f; }
.legend-line.s1     { background: linear-gradient(90deg, rgba(56,126,209,0.55) 60%, transparent 60%); background-size: 6px 100%; }
.legend-line.s2     { background: linear-gradient(90deg, rgba(217,137,43,0.65) 60%, transparent 60%); background-size: 6px 100%; }
.legend-line.s3     { background: linear-gradient(90deg, rgba(224,70,60,0.7)   60%, transparent 60%); background-size: 6px 100%; }

/* Setup-backtest stat grid */
.setup-grid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px;
}
.setup-cell {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.setup-cell .m-value { font-size: 18px; }
@media (max-width: 1000px) {
  .setup-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 600px) {
  .setup-grid { grid-template-columns: repeat(2, 1fr); }
}
.pat-chart-wrap {
  position: relative;
  width: 100%;
  min-height: 600px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.pat-chart { width: 100%; height: 600px; }
.pat-chart-empty {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
}

/* Floating zoom controls overlaid on the chart - positioned at bottom-right to not hide data */
.pat-chart-zoom {
  position: absolute;
  bottom: 12px; right: 12px;
  display: flex; flex-direction: column;
  gap: 4px;
  z-index: 10;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(4px);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}
.pat-chart-zoom button {
  width: 30px; height: 30px;
  border: 0;
  background: transparent;
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  display: grid; place-items: center;
  font-family: inherit;
  transition: background 0.12s;
  line-height: 1;
}
.pat-chart-zoom button:hover { background: var(--accent-soft); color: var(--accent); }
.pat-chart-zoom button:active { transform: scale(0.95); }

/* ─── Reports / Config / Scheduler ────────────────────── */
.inline-label {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-soft);
}
.inline-label input[type="date"],
.inline-label select {
  padding: 6px 8px;
  font-size: 12px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
}

.cfg-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 28px;
}
.cfg-row {
  display: flex; flex-direction: column; gap: 6px;
}
.cfg-row label { font-size: 13px; font-weight: 500; }
.cfg-key { font-size: 11px; margin-top: 2px; }
.cfg-range { color: var(--muted); margin-left: 6px; }
.cfg-row input {
  padding: 8px 10px;
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 800px) {
  .cfg-form { grid-template-columns: 1fr; }
}

/* Modal */
.modal {
  position: fixed; inset: 0;
  background: rgba(20, 25, 35, 0.45);
  display: grid; place-items: center;
  z-index: 20;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  width: min(560px, 92vw);
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.form-row {
  display: grid;
  grid-template-columns: 130px 1fr;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.form-row label { font-size: 12.5px; color: var(--text-soft); font-weight: 500; }
.form-row input[type="text"],
.form-row select {
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
}
.form-row input[type="checkbox"] {
  width: 16px; height: 16px;
}

.job-run, .job-edit, .job-del {
  padding: 4px 9px !important;
  font-size: 11px !important;
  margin-left: 4px;
}

/* Per-row Exit button inside the positions modal */
.pos-exit-btn {
  background: var(--red-soft);
  border: 1px solid rgba(224, 70, 60, 0.45);
  color: var(--red);
  padding: 5px 14px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.3px;
  transition: all 0.12s;
  font-family: inherit;
}
.pos-exit-btn:hover  { background: var(--red); color: white; border-color: var(--red); }
.pos-exit-btn:disabled { opacity: 0.55; cursor: not-allowed; background: var(--surface-2); color: var(--muted); border-color: var(--border); }

/* Closed-today positions in the positions modal — greyed out, like Zerodha */
.pos-section-row td {
  background: var(--surface-2) !important;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 5px 10px !important;
}
.pos-closed-row td { opacity: 0.55; }
.pos-closed-row .sym { font-weight: 500; }
.pos-closed-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--muted);
  text-transform: uppercase;
}

/* Positions modal P&L breakdown row */
#positions-modal-pnl {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 16px;
  font-weight: 500;
  margin-left: 8px;
}
.pnl-cell {
  display: inline-flex;
  flex-direction: column;
  line-height: 1.2;
  font-size: 13px;
}
.pnl-cell-lbl {
  font-size: 9.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.pnl-cell b { font-variant-numeric: tabular-nums; }

/* Positions modal "updating" indicator — fixed width so the layout doesn't shift */
.modal-status {
  display: inline-flex;
  align-items: center;
  min-width: 150px;             /* reserve enough width for "Updated HH:MM:SS" + dot */
  justify-content: flex-end;
}
/* The dot is ALWAYS present in the layout (invisible when idle) so the
   neighbouring buttons never jump when it appears. */
.modal-status .updated-pill::before {
  content: "●";
  display: inline-block;
  width: 9px;
  margin-right: 5px;
  color: transparent;           /* hidden by default */
}
.modal-status.loading .updated-pill::before {
  color: var(--accent);
  animation: pulse-dot 1s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 0.35; }
  50%      { opacity: 1; }
}

/* Big P&L banner under the positions modal title */
.positions-pnl-banner {
  text-align: center;
  padding: 16px 12px;
  margin: -2px 0 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.positions-pnl-lbl {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: var(--muted);
  text-transform: uppercase;
}
.positions-pnl-val {
  margin-top: 4px;
  font-size: 36px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--text);
}
.positions-pnl-val.pos { color: var(--green); }
.positions-pnl-val.neg { color: var(--red); }

/* ─── Toast ───────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 12.5px;
  color: var(--text);
  box-shadow: var(--shadow);
  z-index: 10;
  animation: toast-in 0.18s ease-out;
}
.toast.ok   { border-color: rgba(30, 163, 85, 0.4); background: var(--green-soft); color: #166c39; }
.toast.err  { border-color: rgba(224, 70, 60, 0.4); background: var(--red-soft); color: #8a2820; }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(6px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ─── Spinner ─────────────────────────────────────────── */
.spinning { display: inline-block; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Command palette (Cmd/Ctrl-K) ────────────────────── */
.cmdk-overlay {
  position: fixed; inset: 0;
  background: rgba(20, 25, 35, 0.45);
  backdrop-filter: blur(2px);
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 12vh;
  z-index: 200;
}
.cmdk-panel {
  width: min(540px, 92vw);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: cmdk-in 0.12s ease-out;
}
@keyframes cmdk-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.cmdk-input {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 16px 18px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: transparent;
  outline: none;
}
.cmdk-input::placeholder { color: var(--muted); }
.cmdk-list {
  list-style: none; margin: 0; padding: 6px;
  max-height: 50vh; overflow-y: auto;
}
.cmdk-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-soft);
}
.cmdk-item.active, .cmdk-item:hover {
  background: var(--accent-soft);
  color: var(--accent);
}
.cmdk-hint {
  display: flex; gap: 14px;
  padding: 9px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
}
.cmdk-hint kbd {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 4px;
  padding: 1px 5px;
  margin-right: 2px;
}

/* ─── Raw API Response (Fixed Bottom) ──────────────────── */
.card.raw {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: auto;
  max-height: 200px;
  border-radius: 0;
  border-top: 1px solid var(--border);
  border-bottom: none;
  border-left: none;
  border-right: none;
  overflow: auto;
  background: var(--surface);
  z-index: 3;                    /* below sidebar (z-index 4) so it clears it */
  margin: 0;
}
/* Clear the sidebar when logged in (mirror of .container offset) */
body:has(#tab-bar:not(.hidden)) .card.raw { left: var(--sidebar-w); }

/* Add padding to page to prevent content from going under the fixed footer */
main.container {
  padding-bottom: 220px;
}

/* ─── Responsive ──────────────────────────────────────────
   Three tiers, mobile-first friendly. Pure CSS — no layout
   or behaviour change above 1024px.

   1024px  — small laptop / tablet landscape
    720px  — tablet portrait / large phone
    480px  — phone portrait
   ────────────────────────────────────────────────────────── */

/* ── Small laptop / tablet landscape ── */
@media (max-width: 1024px) {
  .container       { padding: 20px 18px 14px; }
  .topbar          { padding: 8px 18px; }
  .summary-grid    { grid-template-columns: repeat(2, 1fr); }
  .pat-chart       { height: 480px; }
}

/* ── Tablet portrait / large phone ── */
@media (max-width: 720px) {
  /* Sidebar → fixed bottom bar (icons over labels, horizontally scrollable) */
  .tab-bar {
    top: auto; bottom: 0; left: 0; right: 0;
    width: auto; height: 60px;
    border-right: none;
    border-top: 1px solid var(--border);
    overflow-x: auto; overflow-y: hidden;
    box-shadow: 0 -2px 10px rgba(15, 23, 42, 0.05);
  }
  .tab-bar-inner {
    flex-direction: row;
    gap: 2px;
    padding: 6px 8px;
    height: 100%;
    align-items: stretch;
    min-width: max-content;
  }
  .tab {
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    padding: 6px 12px;
    font-size: 10px;
    border-radius: 8px;
  }
  .tab .tab-label { font-size: 9.5px; }
  .tab svg { width: 19px; height: 19px; }
  .tab.active::before {       /* move accent rail to the top edge on bottom bar */
    left: 18%; right: 18%; top: 0; bottom: auto;
    width: auto; height: 3px;
    border-radius: 0 0 3px 3px;
  }
  /* content no longer offset by a left sidebar */
  body:has(#tab-bar:not(.hidden)) .container { margin-left: 0; }
  body:has(#tab-bar:not(.hidden)) .card.raw  { left: 0; bottom: 60px; }

  /* layout */
  .container       { padding: 14px 14px 12px; }
  main.container   { padding-bottom: 180px; }
  .topbar          {
    padding: 8px 14px;
    height: auto;
    min-height: 60px;
    flex-wrap: wrap;
    gap: 8px;
    row-gap: 6px;
  }
  .topbar-right    { gap: 8px; flex-wrap: wrap; }
  .card            { padding: 16px 14px; }
  .card h1         { font-size: 17px; }
  .card-head       { gap: 8px; }

  /* grids stack down */
  .summary-grid    { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .chain-summary   { grid-template-columns: repeat(2, 1fr); gap: 10px; padding: 10px 12px; }
  .chain-grid      { grid-template-columns: 1fr; }
  .setup-grid      { grid-template-columns: repeat(2, 1fr); }
  .cfg-form        { grid-template-columns: 1fr; }

  /* stat cards a touch tighter */
  .stat-card       { padding: 12px 12px; }
  .stat-value      { font-size: 16px; }

  /* margin strip (Expiry tab) — Final Margin spans full width
     so we get clean rows: Total|Required, Final, CE|PE */
  .margin-row              { grid-template-columns: 1fr 1fr; gap: 10px; }
  .margin-row .m-card:nth-child(3) { grid-column: 1 / -1; }
  .m-card                  { padding: 10px 12px; }
  .m-value                 { font-size: 16px; }
  .lot-btn                 { width: 28px; height: 28px; font-size: 15px; }
  .lot-count               { font-size: 16px; }
  .lot-controls            { gap: 8px; }
  .qty-line                { padding: 5px 9px; }
  .qty-value               { font-size: 13px; }
  .mini-pick               { padding: 5px 9px; }

  /* topbar chips — keep all visible, just compact */
  .market-status   { padding: 5px 9px; font-size: 10.5px; }
  .positions-chip  { padding: 4px 8px; }
  .user-chip       { padding: 4px 6px; gap: 6px; }
  .avatar          { width: 30px; height: 30px; font-size: 12px; }

  /* form rows: stack label above input so they don't squish */
  .form-row        { grid-template-columns: 1fr; gap: 4px; margin-bottom: 12px; }

  /* modal scales to viewport */
  .modal-card      { width: 96vw; padding: 16px; max-height: 90vh; overflow-y: auto; }

  /* chart down */
  .pat-chart       { height: 380px; }
  .positions-pnl-val { font-size: 28px; }

  /* fixed footer card smaller so it doesn't eat the screen */
  .card.raw        { max-height: 160px; }
}

/* ── Phone portrait ── */
@media (max-width: 480px) {
  /* no horizontal page scroll (long values still scroll inside .table-wrap) */
  html, body       { overflow-x: hidden; }

  /* layout */
  .container       { padding: 10px 10px 10px; }
  main.container   { padding-bottom: 160px; }
  .topbar          { padding: 8px 10px; gap: 6px; min-height: 56px; }
  .brand           { gap: 8px; }
  .brand-mark      { width: 32px; height: 32px; }
  .brand-wordmark  { font-size: 15px; }
  .topbar-right    { gap: 6px; }

  /* chip labels collapse — chips still tap-able with their value/icon */
  .market-status .ms-label  { display: none; }
  .market-status            { padding: 5px 7px; }
  .positions-chip .pos-label,
  .positions-chip .pos-count { display: none; }
  .user-name, .user-id      { display: none; }
  .user-chip                { padding: 4px 4px; }

  /* cards */
  .card            { padding: 14px 12px; border-radius: 10px; }
  .card h1         { font-size: 16px; }
  .card h2         { font-size: 13px; }

  /* grids */
  .summary-grid    { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .chain-summary   { grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 10px 12px; }
  .setup-grid      { grid-template-columns: repeat(2, 1fr); }

  /* stat values — smaller so big currency strings don't overflow */
  .stat-value      { font-size: 14px; }
  .stat-card       { padding: 10px 10px; }

  /* margin strip — Final Margin AND the two lot cards each take a full row.
     Eliminates the height-mismatch and number-overflow seen on phone.
     Result: row1 Total|Required, row2 Final, row3 CE Lots, row4 PE Lots. */
  .margin-strip                       { padding: 10px 10px; }
  .margin-row                         { grid-template-columns: 1fr 1fr; gap: 8px; }
  .margin-row .m-card:nth-child(3)    { grid-column: 1 / -1; }
  .margin-row .lot-card               { grid-column: 1 / -1; }
  .m-card                             { padding: 10px 10px; gap: 3px; }
  .m-label                            { font-size: 9.5px; letter-spacing: 0.4px; }
  .m-value                            { font-size: 14px; overflow-wrap: anywhere; }
  .lot-btn                            { width: 26px; height: 26px; font-size: 14px; }
  .lot-count                          { font-size: 15px; min-width: 18px; }
  .lot-controls                       { gap: 6px; }
  .qty-line                           { padding: 4px 8px; font-size: 11px; }
  .qty-label                          { font-size: 9.5px; }
  .qty-value                          { font-size: 12px; }
  .mini-pick                          { padding: 4px 8px; font-size: 11px; }
  .mini-pick-ltp                      { font-size: 11.5px; }

  /* expiry banner / cards */
  .expiry-card                        { padding: 12px 12px; }

  /* daily-limit strip — same overflow risk with currency values */
  .dl-row                             { gap: 10px; }
  .dl-value                           { font-size: 14px; overflow-wrap: anywhere; }

  /* tables — denser so more columns fit before horizontal scroll kicks in */
  table.holdings th { padding: 7px 6px; font-size: 9.5px; }
  table.holdings td { padding: 8px 6px; font-size: 12px; }

  /* chart */
  .pat-chart       { height: 300px; }

  /* P&L banner */
  .positions-pnl-val { font-size: 24px; }

  /* tabs — bigger tap target than the existing 720px rule */
  .tab             { padding: 10px 12px; font-size: 12px; }

  /* buttons — bigger tap target */
  .primary-btn, .secondary-btn { padding: 10px 14px; font-size: 12.5px; }
  .primary-btn.big { padding: 12px 20px; font-size: 13.5px; }

  /* auth card centred but full width */
  .auth-card       { margin: 24px auto 0; padding: 24px 18px; }

  /* fixed footer card smaller still */
  .card.raw        { max-height: 140px; }

  /* details/collapsible — tighter so it doesn't dominate */
  details.collapsible > summary       { padding: 12px 14px; }
  details.collapsible .collapsible-body { padding: 12px 14px 14px; }
}
