/* ─── PRECISION TRADING TERMINAL ─────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --bg: #0a0e14;
  --panel: #11161f;
  --border: rgba(255,255,255,.06);
  --text: #c9d1d9;
  --muted: #6e7681;
  --green: #3fb950;
  --red: #f85149;
  --amber: #d29922;
  --accent: #58a6ff;
  --shadow: 0 1px 8px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  background-image: radial-gradient(ellipse 80% 40% at 50% 0%, rgba(88,166,255,.07) 0%, transparent 70%);
  background-attachment: fixed;
  color: var(--text);
  font: 14px/1.5 'IBM Plex Sans', system-ui, sans-serif;
  font-weight: 400;
}

/* ─── NAV ─────────────────────────────────────────────────────────────────── */

nav {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: rgba(10,14,20,.85);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.nav-top {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 10px 18px 6px;
}

.nav-top a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
}

.nav-top a:hover { color: var(--accent); }

/* ─── TABS ────────────────────────────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: 6px;
  padding: 0 18px 8px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  -webkit-mask-image: linear-gradient(90deg, black 92%, transparent);
  mask-image: linear-gradient(90deg, black 92%, transparent);
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
  min-height: 36px;
  text-decoration: none;
  font-weight: 500;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  transition: color .15s, border-color .15s, background .15s;
}

.tab:hover {
  color: var(--text);
  border-color: rgba(255,255,255,.15);
}

.tab.active {
  background: rgba(88,166,255,.15);
  color: var(--accent);
  border-color: rgba(88,166,255,.25);
}

/* ─── BRAND ───────────────────────────────────────────────────────────────── */

.brand {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  letter-spacing: 3px;
  color: var(--green);
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.brand::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .4; transform: scale(.8); }
}

/* ─── ET CLOCK ────────────────────────────────────────────────────────────── */

.etclock {
  font-family: 'JetBrains Mono', monospace;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .5px;
  white-space: nowrap;
}
.etclock.premarket  { color: var(--amber); }
.etclock.open       { color: var(--green); }
.etclock.afterhours { color: var(--red); }
.etclock.overnight  { color: var(--muted); }

/* ─── LAYOUT ──────────────────────────────────────────────────────────────── */

.spacer { flex: 1; }
.muted { color: var(--muted); }
.nav-disabled { color: var(--muted); }

main {
  padding: clamp(10px, 3vw, 24px);
  max-width: 1200px;
  margin: 0 auto;
}

/* Page-load stagger — cards/sections fade up */
@media (prefers-reduced-motion: no-preference) {
  main > * {
    animation: rise .35s ease both;
  }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── CARDS ───────────────────────────────────────────────────────────────── */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.card {
  background: var(--panel);
  border-radius: 10px;
  padding: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.card h3 {
  margin: 0 0 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  font-weight: 500;
}

/* Big metric numbers — monospace, tabular */
.big {
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(20px, 5vw, 26px);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

/* Plain colored metrics; tinted pill reserved for status values (.pill) */
.pos { color: var(--green); }
.neg { color: var(--red); }
.amber { color: var(--amber); }

.big.pill {
  display: inline-block;
  padding: 2px 12px;
  border-radius: 6px;
  font-size: 18px;
  letter-spacing: 1px;
}
.big.pill.pos   { background: rgba(63,185,80,.12); }
.big.pill.neg   { background: rgba(248,81,73,.12); }
.big.pill.amber { background: rgba(210,153,34,.12); }

/* Compact stat tiles on the Live page */
.stat-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.stat { display: flex; flex-direction: column; gap: 3px; min-height: 86px; }
.stat .muted { font-size: 12px; }
.symline { font-size: 12px; margin-top: 3px; display: flex; gap: 6px; align-items: baseline; white-space: nowrap; min-width: 0; }
.symline .pos { font-weight: 500; }
.symline .muted { overflow: hidden; text-overflow: ellipsis; }

/* Equity chart 2:1 with strategy card; stacks on mobile */
.split-wide { grid-template-columns: 2fr 1fr; }

/* Section headings between cards and tables */
main h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  font-weight: 500;
  margin: 20px 0 8px;
}

/* ─── TABLES ──────────────────────────────────────────────────────────────── */

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border-radius: 10px;
  border: 1px solid var(--border);
  overflow: hidden;
}

th, td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

td:last-child, th:last-child { border-right: none; }

th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 500;
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 1;
}

tbody tr:hover { background: rgba(255,255,255,.03); }

tr.rowlink { cursor: pointer; }

/* Mono for price/numeric table cells */
td.num,
td:has(.pos), td:has(.neg), td:has(.amber) {
  font-family: 'JetBrains Mono', monospace;
  font-variant-numeric: tabular-nums;
}

/* ─── LOGS ────────────────────────────────────────────────────────────────── */

table, td, th { font-size: 13px; }      /* one size everywhere — no odd column */

.logs-table td { vertical-align: top; }

.logmsg details summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}
.logmsg details summary::-webkit-details-marker { display: none; }
.logmsg details summary::after {
  content: '▸';
  color: var(--muted);
  font-size: 10px;
  transition: transform .15s ease;
}
.logmsg details[open] summary::after { transform: rotate(90deg); }
.logmsg details summary:hover { color: var(--accent); }

.logmsg pre {
  margin: 8px 0 2px;
  padding: 10px 12px;
  background: #0b0f16;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: 12px/1.5 'JetBrains Mono', monospace;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 720px;
  overflow-x: auto;
}

/* ─── BANNERS ─────────────────────────────────────────────────────────────── */

.banner {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
}

.banner.error {
  background: rgba(248,81,73,.12);
  color: var(--red);
  border-color: rgba(248,81,73,.25);
}

/* ─── BUTTONS ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-block;
  background: var(--accent);
  color: #0a0e14;
  padding: 8px 18px;
  border-radius: 7px;
  text-decoration: none;
  font-weight: 600;
  border: none;
  cursor: pointer;
  font-size: 14px;
  transition: filter .15s ease;
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
}

.btn:hover  { filter: brightness(1.15); }
.btn:active { filter: brightness(.9); transform: translateY(1px); }
.btn.danger { background: var(--red); color: #fff; }

/* State toggles: green when on, muted when off (danger reserved for destructive) */
.btn.ok  { background: rgba(63,185,80,.15);  color: var(--green); border: 1px solid rgba(63,185,80,.3); }
.btn.dim { background: rgba(255,255,255,.06); color: var(--muted); border: 1px solid var(--border); }
.btn.danger:hover { filter: brightness(1.15); }

/* ─── FORMS ───────────────────────────────────────────────────────────────── */

form.inline { display: inline; }

input, select {
  background: #0b0d10;
  color: var(--text);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 7px;
  padding: 7px 10px;
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  font-size: 14px;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(88,166,255,.15);
}

/* ─── LOGIN ───────────────────────────────────────────────────────────────── */

.login-box {
  max-width: 360px;
  margin: 80px auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ─── MOBILE ≤640px ───────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .nav-top { padding: 8px 12px 4px; }
  .tabs { padding: 0 12px 8px; }

  main { padding: 10px; }

  body { padding-bottom: env(safe-area-inset-bottom); }

  .cards { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .split-wide { grid-template-columns: 1fr; }

  form { flex-wrap: wrap; }
  form.inline { flex-wrap: nowrap; }   /* table-cell value+set pairs stay on one line */

  form:not(.inline) .btn,
  form:not(.inline) button {
    width: 100%;
  }

  input, select { font-size: 16px; }

  .btn, button { min-height: 44px; }

  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    font-size: 13px;
  }

  /* Polled fragments: the scroll container must survive the htmx swap, or the
     horizontal scroll position resets every refresh. The wrapper (outside the
     swap target's content) scrolls; the table inside it must not. */
  .tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tablewrap table { display: table; overflow-x: visible; }

  table td:first-child,
  table th:first-child {
    position: sticky;
    left: 0;
    background: var(--panel);
  }

  #eqplot, #chart {
    min-height: 160px;
    max-height: 320px;
  }
}

@media (max-width: 380px) {
  .cards { grid-template-columns: 1fr 1fr; }
}

/* Dropdown nav menus — position:fixed to escape overflow:auto on .tabs */
.tab-dropdown { display: inline-block; }
.tab-dropdown .tab { cursor: pointer; user-select: none; }
.dropdown-menu {
  display: none; position: fixed; z-index: 9999;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 4px; min-width: 130px; padding: 4px 0;
}
.dropdown-menu a {
  display: block; padding: 6px 14px; color: var(--text);
  text-decoration: none; font-size: 13px; white-space: nowrap;
}
.dropdown-menu a:hover { background: rgba(255,255,255,0.06); }
.dropdown-menu a.active { color: var(--accent); }

/* ─── GRIDSTACK ─────────────────────────────────────────────────────────────── */

.grid-stack { user-select: none; }
.grid-stack-placeholder > .placeholder-content {
  background: rgba(88,166,255,.07);
  border: 1px dashed rgba(88,166,255,.3);
  border-radius: 10px;
}
/* Cards inside gridstack items fill the item height */
.grid-stack-item-content > .card {
  height: 100%;
  overflow: auto;
  box-sizing: border-box;
}
/* HTMX fragments may inject a card directly into item-content */
.grid-stack-item-content > div > .card,
.grid-stack-item-content .card:first-child {
  min-height: 0;
}

/* ─── TABLE COL RESIZE ───────────────────────────────────────────────────────── */

th { position: relative; }
.col-rz {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 5px;
  cursor: col-resize;
  user-select: none;
  z-index: 2;
  border-radius: 0 2px 2px 0;
}
.col-rz:hover, .col-rz-active { background: rgba(88,166,255,.45); }

/* ─── TABLE SORT INDICATORS ──────────────────────────────────────────────────── */

th[data-sort-dir="asc"]::after  { content: ' ↑'; color: var(--accent); font-size: 10px; }
th[data-sort-dir="desc"]::after { content: ' ↓'; color: var(--accent); font-size: 10px; }

/* ─── LAYOUT EDIT FAB ────────────────────────────────────────────────────────── */

/* Resize handles hidden by default; shown only in edit mode */
.grid-stack-item > .ui-resizable-handle { display: none !important; }
.gs-editing .grid-stack-item > .ui-resizable-handle { display: block !important; }

/* Dashed outline on the grid container while editing */
.gs-editing { outline: 1px dashed rgba(88,166,255,.18); outline-offset: 2px; border-radius: 10px; }

#gs-fab {
  position: fixed;
  bottom: max(20px, env(safe-area-inset-bottom, 20px));
  right: 20px;
  display: flex;
  gap: 8px;
  z-index: 1001;
}
