/* Vision-UI inspired dark glassmorphic theme for Polymarket dashboard.
   Additive: existing pages not opting into .vision-* classes are unaffected.
   Load order: Dash auto-includes every file in /assets, alphabetical. */

:root {
  --vision-bg: #0b1035;
  --vision-bg-2: #050826;
  --vision-card-bg: rgba(19, 27, 63, 0.55);
  --vision-card-border: rgba(255, 255, 255, 0.08);
  --vision-card-hover: rgba(255, 255, 255, 0.14);
  --vision-accent-cyan: #01b5d9;
  --vision-accent-violet: #7551ff;
  --vision-accent-pink: #ff4d97;
  --vision-green: #01b574;
  --vision-red: #e31a1a;
  --vision-text: #e9ecef;
  --vision-muted: #a0aec0;
  --vision-stat-label: #a0aec0;
}

/* ── Page background (only on pages opting in via .vision-page) ── */
.vision-page {
  background: radial-gradient(ellipse at top left, #1a1f4d 0%, var(--vision-bg) 45%, var(--vision-bg-2) 100%) fixed;
  min-height: 100vh;
  color: var(--vision-text);
}

/* ── Glassmorphic card ── */
.vision-card {
  background: var(--vision-card-bg);
  border: 1px solid var(--vision-card-border);
  border-radius: 16px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 4px 24px -8px rgba(0, 0, 0, 0.5);
  transition: border-color 160ms ease, transform 160ms ease;
}
.vision-card:hover {
  border-color: var(--vision-card-hover);
}
.vision-card-pad {
  padding: 18px 22px;
}

/* ── Pinned stats strip ── */
.vision-pin {
  position: sticky;
  top: 0;
  z-index: 900;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  padding: 14px 20px;
  background: rgba(11, 16, 53, 0.75);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--vision-card-border);
}
.vision-stat {
  padding: 14px 18px;
  background: var(--vision-card-bg);
  border: 1px solid var(--vision-card-border);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.vision-stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--vision-stat-label);
  font-weight: 600;
}
.vision-stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  line-height: 1.15;
}
.vision-stat-sub {
  font-size: 0.7rem;
  color: var(--vision-muted);
}
.vision-stat-value.pos { color: var(--vision-green); }
.vision-stat-value.neg { color: var(--vision-red); }
.vision-stat-value.info { color: var(--vision-accent-cyan); }

/* Responsive: collapse to 2 cols on narrow screens */
@media (max-width: 720px) {
  .vision-pin { grid-template-columns: repeat(2, 1fr); }
}

/* ── Health badge inside pinned strip ── */
.vision-health-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
  box-shadow: 0 0 10px currentColor;
}
.vision-health-Healthy { color: var(--vision-green); }
.vision-health-Slow    { color: #f5a524; }
.vision-health-Offline { color: var(--vision-red); }
.vision-health-Unknown { color: var(--vision-muted); }

/* ── Tabs ── */
.vision-tabs {
  display: flex;
  gap: 8px;
  padding: 16px 20px 0 20px;
  border: none !important;
  flex-wrap: wrap;
}
.vision-tabs .nav-item .nav-link,
.vision-tabs .nav-link {
  background: rgba(255, 255, 255, 0.04) !important;
  border: 1px solid var(--vision-card-border) !important;
  border-radius: 999px !important;
  color: var(--vision-muted) !important;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.78rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 8px 18px !important;
  transition: all 180ms ease;
}
.vision-tabs .nav-link:hover {
  color: var(--vision-text) !important;
  border-color: var(--vision-card-hover) !important;
}
.vision-tabs .nav-link.active {
  background: linear-gradient(135deg, var(--vision-accent-violet) 0%, var(--vision-accent-cyan) 100%) !important;
  color: #fff !important;
  border-color: transparent !important;
  box-shadow: 0 4px 16px -4px rgba(117, 81, 255, 0.55);
}

.vision-tab-content {
  padding: 16px 20px 24px 20px;
}

/* ── Section headers inside tabs ── */
.vision-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--vision-text);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.vision-section-title::before {
  content: "";
  display: inline-block;
  width: 3px;
  height: 14px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--vision-accent-violet) 0%, var(--vision-accent-cyan) 100%);
}

/* ── Buttons (keep bootstrap variants intact; only soften outline) ── */
.vision-btn-group .btn-outline-secondary {
  border-color: var(--vision-card-border) !important;
  color: var(--vision-muted) !important;
  border-radius: 999px !important;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.5px;
}
.vision-btn-group .btn-outline-secondary:hover,
.vision-btn-group .btn-outline-secondary.active {
  background: linear-gradient(135deg, var(--vision-accent-violet) 0%, var(--vision-accent-cyan) 100%) !important;
  border-color: transparent !important;
  color: #fff !important;
}

/* ── Tables inside cards ── */
.vision-card table {
  color: var(--vision-text);
}
.vision-card th {
  color: var(--vision-muted) !important;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 1px solid var(--vision-card-border) !important;
}
.vision-card td {
  border-top: 1px solid rgba(255, 255, 255, 0.04) !important;
  font-size: 0.82rem;
}

/* ── Data table (dense monospace, mobile-scrollable wrapper) ── */
.vision-table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.vision-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  margin: 0;
}
.vision-table th {
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.02);
}
.vision-table td {
  padding: 8px 10px;
  white-space: nowrap;
  color: var(--vision-text);
}
.vision-table tbody tr {
  transition: background 140ms ease;
}
.vision-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.04);
}
.vision-table tr.vision-table-total td {
  border-top: 1px solid var(--vision-card-border) !important;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.02);
}
.vision-table td.pos { color: var(--vision-green); font-weight: 600; }
.vision-table td.neg { color: var(--vision-red);   font-weight: 600; }
.vision-table td.muted { color: var(--vision-muted); }
.vision-table td.num { font-variant-numeric: tabular-nums; }

/* ── Navbar (global) ── */
.vision-navbar {
  background: rgba(11, 16, 53, 0.85) !important;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--vision-card-border);
  box-shadow: 0 2px 16px -4px rgba(0, 0, 0, 0.4);
  padding: 10px 16px;
}
.vision-navbar .navbar-brand {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, var(--vision-accent-cyan) 0%, var(--vision-accent-violet) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.vision-navbar .nav-link {
  color: var(--vision-muted) !important;
  font-size: 0.82rem;
  letter-spacing: 0.5px;
  padding: 6px 14px !important;
  border-radius: 999px;
  transition: color 150ms ease, background 150ms ease;
}
.vision-navbar .nav-link:hover {
  color: var(--vision-text) !important;
  background: rgba(255, 255, 255, 0.04);
}
.vision-navbar .nav-link.active {
  color: #fff !important;
  background: rgba(117, 81, 255, 0.18);
}
.vision-navbar .badge {
  border-radius: 999px;
  padding: 6px 12px !important;
  font-weight: 600;
  letter-spacing: 0.6px;
}
.vision-navbar .btn-outline-light {
  border-radius: 999px !important;
  border-color: var(--vision-card-border) !important;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
  padding: 4px 14px !important;
}
.vision-navbar .btn-outline-light:hover {
  background: rgba(255, 255, 255, 0.08) !important;
  border-color: var(--vision-card-hover) !important;
}
.vision-navbar .text-muted {
  color: var(--vision-muted) !important;
}

/* ── Floating bottom ticker bar ── */
.vision-ticker-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  z-index: 1030;
  background: rgba(11, 16, 53, 0.82);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--vision-card-border);
  box-shadow: 0 -4px 20px -6px rgba(0, 0, 0, 0.45);
  padding: 10px 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
.vision-ticker-item {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--vision-card-border);
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.8rem;
  transition: border-color 160ms ease, background 160ms ease;
}
.vision-ticker-item:hover {
  border-color: var(--vision-card-hover);
  background: rgba(255, 255, 255, 0.06);
}
.vision-ticker-label {
  color: var(--vision-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 0.68rem;
  font-weight: 600;
}
.vision-ticker-value {
  color: var(--vision-accent-cyan);
  font-weight: 700;
}

/* ── Scrollbars ── */
.vision-scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.vision-scroll::-webkit-scrollbar-track { background: transparent; }
.vision-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}
.vision-scroll::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); }

/* ──────────────────────────────────────────────────────────────────────────
   m8 dashboard responsive grids + mobile fixes
   These classes replace inline gridTemplateColumns dicts in m8_page.py so
   media queries can take over below 720px / 480px. Desktop behavior is
   preserved; only narrow viewports change.
   ────────────────────────────────────────────────────────────────────────── */

/* KPI row: 6 cols desktop → 3 tablet → 2 mobile.
   The original inline style was `repeat(6, 1fr)` which produced
   60px-wide cells on iPhone — unreadable. */
.m8-grid-kpi {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
@media (max-width: 1024px) {
  .m8-grid-kpi { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 720px) {
  .m8-grid-kpi { grid-template-columns: repeat(2, 1fr); gap: 8px; }
}

/* Open Trades + Active Windows row — 2:1 desktop, single column mobile.
   The row-floor / min-height hack was removed once the layout was changed
   to put the card wrappers in the static layout (m8_page.py). With the
   card frames permanent, there's nothing to collapse during a callback
   re-render, so a fixed row height isn't needed. */
.m8-grid-2col-21 {
  display: grid;
  grid-template-columns: 2fr 1fr;
  align-items: start;
  gap: 18px;
}
@media (max-width: 900px) {
  .m8-grid-2col-21 {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

/* Recent Trades + Signal Eval row — 1:1 desktop, single column mobile.
   Two 7+col tables side-by-side at 375px is unrenderable. */
.m8-grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
@media (max-width: 900px) {
  .m8-grid-2col { grid-template-columns: 1fr; gap: 12px; }
}

/* Crypto + regime card grid — 4 cols desktop → 2 tablet → 2 mobile.
   8 stat cards × 4-col fits desktop nicely; on phone we drop to 2 so
   each cell stays >150px wide and the value font (22px) is legible. */
.m8-grid-crypto {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
@media (max-width: 1024px) {
  .m8-grid-crypto { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .m8-grid-crypto { gap: 8px; }
}

/* Wide table mobile horizontal-scroll wrapper.
   Recent Trades has 9 columns and Signal Eval has 6; collapsing to a
   card-stack would lose the at-a-glance comparison the operator scans
   for. Horizontal scroll keeps the grid intact and is a familiar mobile
   pattern. The min-width forces the table not to compress its cells.
   The existing `.vision-table-wrap` already does this for Vision tables;
   `.m8-table-wrap` is the equivalent for m8_page.py's `_table()` helper. */
.m8-table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.m8-table-wrap > table {
  min-width: 720px;  /* keeps columns readable; pan to see the rest */
}

/* m8 page wrapper — adds bottom padding so the fixed bottom dock doesn't
   overlap the last row of content. 80px > 64px ticker height + breathing
   room on mobile (where the dock wraps to two lines). */
.m8-page-pad {
  max-width: 1680px;
  margin: 0 auto;
  padding: 22px 28px 80px;
}
@media (max-width: 720px) {
  .m8-page-pad { padding: 14px 12px 120px; }
}

/* Header flex row — wrap onto two lines on mobile so the trading
   button doesn't push off-screen. */
.m8-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 28px;
  flex-wrap: wrap;
  gap: 8px;
}
@media (max-width: 720px) {
  .m8-header { padding: 12px 14px; }
  .m8-header > div { flex-wrap: wrap; }
}

/* Active-window mini chart — make the dcc.Graph respect parent width
   and bump the height up a touch on mobile so the y-axis labels and the
   yes/no lines aren't squashed. Combined with `responsive=True` on the
   Graph, the chart re-renders when the viewport changes. */
.m8-window-chart .js-plotly-plot,
.m8-window-chart .plot-container {
  width: 100% !important;
}
@media (max-width: 720px) {
  .m8-window-chart .js-plotly-plot,
  .m8-window-chart .plot-container,
  .m8-window-chart .svg-container {
    height: 200px !important;
    min-height: 200px !important;
  }
}

/* P&L chart container — slightly shorter on mobile to claw back vertical
   space for the cards below. */
@media (max-width: 720px) {
  .m8-pnl-chart .js-plotly-plot,
  .m8-pnl-chart .plot-container,
  .m8-pnl-chart .svg-container {
    height: 200px !important;
    min-height: 200px !important;
  }
}

/* Plotly's absolute-positioned SVG containers can paint outside the
   parent during the brief reflow that happens when `data-dash-is-loading`
   toggles on a sibling component. Containment + overflow:hidden keeps
   each chart's render strictly inside its declared box. Verified
   2026-04-30: without this, Active Windows mini-charts visually
   overlapped the P&L chart above on every refresh tick. */
.m8-pnl-chart,
.m8-window-chart {
  overflow: hidden;
  position: relative;
  contain: layout size;
}

/* Bottom dock — desktop is a single row left/right. Mobile: stack the
   two halves, smaller font, tighter padding. The dock is positioned
   `fixed` from inline styles in m8_page.py; we only override layout
   here, not position. */
@media (max-width: 720px) {
  .m8-dock {
    padding: 6px 12px !important;
    font-size: 11px !important;
    flex-wrap: wrap !important;
    gap: 4px 12px;
  }
  .m8-dock > div {
    flex-wrap: wrap !important;
    gap: 6px 10px !important;
    width: 100%;
    justify-content: flex-start !important;
  }
}
