/* ═══════════════════════════════════════════════════
   DEXTER MORGAN TRADE — "Signal Noir" Terminal UI
   Dense, information-rich trading dashboard.
   Inspired by Bloomberg Terminal × dYdX × Bybit Pro.
   ═══════════════════════════════════════════════════ */

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

/* ── Tokens ────────────────────────────────────── */
:root {
  /* Zinc scale — true dark, not navy */
  --z-950: #09090b;
  --z-900: #18181b;
  --z-850: #1f1f23;
  --z-800: #27272a;
  --z-700: #3f3f46;
  --z-600: #52525b;
  --z-500: #71717a;
  --z-400: #a1a1aa;
  --z-300: #d4d4d8;
  --z-200: #e4e4e7;
  --z-100: #f4f4f5;

  /* Signal colors */
  --long:      #22c55e;
  --long-dim:  rgba(34,197,94,0.12);
  --long-mid:  rgba(34,197,94,0.25);
  --short:     #f43f5e;
  --short-dim: rgba(244,63,94,0.12);
  --short-mid: rgba(244,63,94,0.25);
  --warn:      #f59e0b;
  --warn-dim:  rgba(245,158,11,0.12);
  --info:      #3b82f6;

  /* Typography */
  --mono: 'Geist Mono', 'SF Mono', 'Cascadia Code', monospace;

  /* Spacing scale */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;

  /* Radii */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 8px;
}

/* ── Kill Pico defaults ───────────────────────── */
html[data-theme="dark"] {
  --pico-background-color: var(--z-950);
  --pico-card-background-color: var(--z-900);
  --pico-card-border-color: var(--z-800);
  --pico-color: var(--z-200);
  --pico-muted-color: var(--z-500);
  --pico-muted-border-color: var(--z-800);
  --pico-primary: var(--long);
  --pico-font-family: var(--mono);
  --pico-font-size: 13px;
  --pico-line-height: 1.5;
  --pico-border-radius: var(--r-md);
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  background: var(--z-950);
  color: var(--z-300);
  font-family: var(--mono);
  margin: 0;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Navigation ───────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-5);
  background: var(--z-950);
  border-bottom: 1px solid var(--z-800);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: var(--sp-4);
}

/* Accent line under nav */
.topbar::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg,
    transparent 5%,
    rgba(0,255,65,0.25) 50%,
    transparent 95%
  );
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  text-decoration: none;
  flex-shrink: 0;
}

.topbar-brand .mark {
  font-weight: 700;
  font-size: 14px;
  color: var(--z-100);
  letter-spacing: 0.08em;
}

.topbar-brand .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #00ff41;
  box-shadow: 0 0 8px #00ff4180;
  animation: blink 3s ease-in-out infinite;
}

@keyframes blink {
  0%,100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}

.topbar-nav::-webkit-scrollbar { display: none; }

.topbar-nav a {
  padding: var(--sp-1) var(--sp-3);
  font-size: 12px;
  font-weight: 500;
  color: var(--z-500);
  text-decoration: none;
  border-radius: var(--r-sm);
  white-space: nowrap;
  transition: color 0.15s, background 0.15s;
}

.topbar-nav a:hover {
  color: var(--z-300);
  background: var(--z-850);
}

.topbar-nav a[aria-current="page"],
.topbar-nav a.active {
  color: #00ff41;
  background: rgba(0,255,65,0.08);
}

.topbar-nav .sep {
  width: 1px;
  height: 16px;
  background: var(--z-800);
  margin: 0 var(--sp-1);
  flex-shrink: 0;
}

/* ── Theme Switcher ──────────────────────────── */
.theme-switcher {
  display: flex;
  align-items: center;
  gap: 1px;
}

.theme-btn {
  font-size: 9px !important;
  font-weight: 600 !important;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 5px !important;
  color: var(--z-600) !important;
  border-radius: 2px;
  opacity: 0.6;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}

.theme-btn:hover {
  opacity: 1;
  color: var(--z-300) !important;
  background: var(--z-850) !important;
}

.theme-btn.active {
  opacity: 1;
  color: #00ff41 !important;
  background: rgba(0,255,65,0.08) !important;
}

/* ── Layout ───────────────────────────────────── */
.shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--sp-5);
}

.page-hdr {
  margin-bottom: var(--sp-5);
}

.page-hdr h1 {
  font-size: 15px;
  font-weight: 700;
  color: var(--z-100);
  margin: 0 0 2px;
  letter-spacing: 0.02em;
}

.page-hdr .sub {
  font-size: 11px;
  color: var(--z-500);
  letter-spacing: 0.04em;
}

/* ── Panel (replaces article/card) ────────────── */
.panel {
  background: var(--z-900);
  border: 1px solid var(--z-800);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--z-800);
}

.panel-head .label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--z-500);
}

.panel-head .tag {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: var(--r-sm);
  font-weight: 600;
}

.panel-body {
  padding: var(--sp-4);
}

/* override Pico article styling completely */
article {
  all: unset;
  display: block;
}

/* ── Grid ─────────────────────────────────────── */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4);
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--sp-4);
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-4);
}

.grid-dash {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  gap: var(--sp-4);
}

/* ── Stat / Metric ────────────────────────────── */
.stat {
  padding: var(--sp-4);
}

.stat-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--z-500);
  margin-bottom: var(--sp-1);
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--z-100);
  line-height: 1.1;
  letter-spacing: -0.5px;
}

.stat-value.lg {
  font-size: 32px;
  letter-spacing: -1px;
}

.stat-value.sm {
  font-size: 18px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--z-850);
  font-size: 12px;
}

.stat-row:last-child {
  border-bottom: none;
}

.stat-row .k {
  color: var(--z-500);
}

.stat-row .v {
  color: var(--z-200);
  font-weight: 500;
}

/* ── Colors ───────────────────────────────────── */
.c-long { color: var(--long) !important; }
.c-short { color: var(--short) !important; }
.c-warn { color: var(--warn) !important; }

.glow-long { text-shadow: 0 0 20px var(--long-dim), 0 0 40px rgba(34,197,94,0.06); }
.glow-short { text-shadow: 0 0 20px var(--short-dim), 0 0 40px rgba(244,63,94,0.06); }

/* ── Bias chips ───────────────────────────────── */
.bias-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-2);
}

.bias-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-3) var(--sp-2);
  border-radius: var(--r-md);
  background: var(--z-850);
  border: 1px solid transparent;
  transition: border-color 0.2s;
  cursor: default;
}

.bias-chip:hover {
  border-color: var(--z-700);
}

.bias-chip .sym {
  font-size: 11px;
  font-weight: 700;
  color: var(--z-300);
  letter-spacing: 0.04em;
}

.bias-chip .badge {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: 3px;
}

.badge-bull {
  background: var(--long-dim);
  color: var(--long);
  border: 1px solid var(--long-mid);
}

.badge-bear {
  background: var(--short-dim);
  color: var(--short);
  border: 1px solid var(--short-mid);
}

.badge-neut {
  background: rgba(113,113,122,0.12);
  color: var(--z-500);
  border: 1px solid var(--z-700);
}

.bias-chip .conf {
  font-size: 10px;
  color: var(--z-500);
}

/* ── Progress bar ─────────────────────────────── */
.bar-track {
  height: 3px;
  border-radius: 2px;
  background: var(--z-800);
  overflow: hidden;
  margin: var(--sp-2) 0;
}

.bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.6s cubic-bezier(0.23,1,0.32,1);
}

.bar-fill.ok { background: var(--long); }
.bar-fill.mid { background: var(--warn); }
.bar-fill.bad { background: var(--short); }

/* ── Tables ───────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

thead th {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--z-500);
  padding: var(--sp-3) var(--sp-3);
  text-align: right;
  border-bottom: 1px solid var(--z-800);
  background: var(--z-850);
}

thead th:first-child { text-align: left; }

tbody td {
  padding: var(--sp-2) var(--sp-3);
  color: var(--z-300);
  text-align: right;
  border-bottom: 1px solid var(--z-850);
  font-weight: 500;
}

tbody td:first-child {
  text-align: left;
  color: var(--z-400);
  font-weight: 400;
}

tbody tr:hover {
  background: var(--z-850);
}

tbody tr:last-child td {
  border-bottom: none;
}

/* ── Buttons ──────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: var(--r-md);
  border: 1px solid var(--z-700);
  background: var(--z-850);
  color: var(--z-300);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn:hover {
  background: var(--z-800);
  color: var(--z-100);
  border-color: var(--z-500);
}

/* Terminal link — visible, no border, just brighter text */
.term-link {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--z-400);
  text-decoration: none;
  transition: color 0.15s;
  border-bottom: 1px solid transparent;
  padding-bottom: 1px;
}
.term-link:hover {
  color: var(--z-100);
  border-bottom-color: var(--z-500);
}

.btn-primary {
  background: var(--long);
  color: var(--z-950);
  border-color: var(--long);
}

.btn-primary:hover {
  filter: brightness(1.1);
  color: var(--z-950);
}

.btn-danger {
  background: var(--short-dim);
  color: var(--short);
  border-color: rgba(244,63,94,0.3);
}

.btn-danger:hover {
  background: var(--short-mid);
}

.btn-block { width: 100%; }

/* ── Inputs ───────────────────────────────────── */
input, textarea, select {
  background: var(--z-850) !important;
  border: 1px solid var(--z-700) !important;
  color: var(--z-200) !important;
  font-family: var(--mono) !important;
  font-size: 13px !important;
  border-radius: var(--r-md) !important;
  padding: var(--sp-3) var(--sp-4) !important;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--z-500) !important;
  outline: 2px solid rgba(113,113,122,0.2) !important;
  outline-offset: 1px;
  box-shadow: none !important;
}

input::placeholder {
  color: var(--z-600) !important;
}

/* ── Chart ────────────────────────────────────── */
#chart-container {
  width: 100%;
  height: 380px;
  border-radius: var(--r-lg);
  background: var(--z-900);
  border: 1px solid var(--z-800);
}

/* ── Log lines ────────────────────────────────── */
.log-line {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--z-850);
  font-size: 12px;
  align-items: baseline;
}

.log-line:last-child { border-bottom: none; }

.log-line .ts {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--z-600);
  width: 130px;
}

.log-line .act {
  font-weight: 600;
  flex-shrink: 0;
  width: 80px;
}

.log-line .msg {
  color: var(--z-400);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── HTMX ─────────────────────────────────────── */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { display: inline-block; }

/* ── Scrollbar ────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--z-700); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--z-600); }

/* ── Table responsive ─────────────────────────── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Login ─────────────────────────────────────── */
.login-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--z-950);
  position: relative;
}

.login-shell::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(255,255,255,0.008) 2px,
    rgba(255,255,255,0.008) 4px
  );
  pointer-events: none;
}

.login-card {
  width: 340px;
  background: var(--z-900);
  border: 1px solid var(--z-800);
  border-radius: var(--r-lg);
  padding: var(--sp-8);
  position: relative;
  z-index: 1;
}

.login-card .brand {
  text-align: center;
  margin-bottom: var(--sp-6);
}

.login-card .brand .name {
  font-size: 20px;
  font-weight: 700;
  color: var(--z-100);
  letter-spacing: 0.1em;
}

.login-card .brand .desc {
  font-size: 10px;
  color: var(--z-600);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: var(--sp-1);
}

.login-card .err {
  font-size: 12px;
  color: var(--short);
  text-align: center;
  margin-bottom: var(--sp-4);
}

.login-card button {
  width: 100%;
  background: var(--z-800);
  border: 1px solid var(--z-700);
  color: var(--z-200);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: var(--sp-3);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: all 0.15s;
}

.login-card button:hover {
  background: var(--z-700);
  color: var(--z-100);
}

/* ── Responsive ───────────────────────────────── */
@media (max-width: 900px) {
  .grid-dash { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .topbar-nav a { font-size: 11px; padding: var(--sp-1) var(--sp-2); }
  .topbar-nav .sep { display: none; }
}

@media (max-width: 600px) {
  .shell { padding: var(--sp-3); }
  .bias-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 20px; }
  .stat-value.lg { font-size: 26px; }
  .topbar {
    padding: var(--sp-2) var(--sp-3);
    flex-wrap: nowrap;
  }
  .topbar-nav {
    gap: 1px;
    -ms-overflow-style: none;
  }
  .topbar-nav a {
    font-size: 10px;
    padding: 3px 6px;
  }
  .topbar-brand .mark { font-size: 12px; }
  .page-hdr h1 { font-size: 13px; }
  .page-hdr .sub { font-size: 10px; }
  #chart-container { height: 260px; }

  /* Tables scroll horizontally on mobile */
  table { font-size: 11px; }
  thead th, tbody td { padding: var(--sp-1) var(--sp-2); }

  /* Tabs wrap on mobile */
  [role="tablist"] { width: 100%; }
  [role="tab"] { flex: 1; text-align: center; font-size: 10px; padding: var(--sp-2) var(--sp-2); }
}

/* ── Tabs (kill Pico blue buttons) ────────────── */
[role="tablist"] {
  display: flex;
  gap: 2px;
  background: var(--z-900);
  border: 1px solid var(--z-800);
  border-radius: var(--r-md);
  padding: 2px;
  margin-bottom: var(--sp-4);
  width: fit-content;
}

[role="tab"] {
  all: unset;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--z-500);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: all 0.15s;
}

[role="tab"]:hover {
  color: var(--z-300);
  background: var(--z-850);
}

[role="tab"][aria-selected="true"] {
  color: var(--z-100);
  background: var(--z-800);
}

/* ── Kill ALL Pico button defaults ────────────── */
button:not(.btn):not([role="tab"]) {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  background: var(--z-850);
  border: 1px solid var(--z-700);
  color: var(--z-300);
  border-radius: var(--r-md);
  padding: var(--sp-2) var(--sp-4);
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

button:not(.btn):not([role="tab"]):hover {
  background: var(--z-800);
  color: var(--z-100);
  border-color: var(--z-600);
}

/* ── Pico overrides (kill remaining defaults) ── */
nav { all: unset; }
footer { all: unset; }
[role="button"] { all: unset; }
a[role="button"].outline.secondary { all: unset; }

/* ── Hgroup override ─────────────────────────── */
hgroup {
  margin-bottom: var(--sp-5);
}
hgroup h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--z-100);
  margin: 0 0 2px;
}
hgroup p {
  font-size: 11px;
  color: var(--z-500);
  margin: 0;
}

/* ── Badge overrides (for logs etc) ──────────── */
.badge-bullish, .badge-neutral, .badge-bearish {
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: 3px;
  display: inline-block;
}
.badge-bullish { background: var(--long-dim); color: var(--long); }
.badge-bearish { background: var(--short-dim); color: var(--short); }
.badge-neutral { background: rgba(113,113,122,0.12); color: var(--z-500); }

/* ── Details/summary override ────────────────── */
details summary {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--z-400);
  cursor: pointer;
  padding: var(--sp-1) 0;
}
details summary:hover { color: var(--z-200); }

details .full-reasoning {
  font-size: 12px;
  white-space: pre-wrap;
  background: var(--z-850);
  padding: var(--sp-3);
  border-radius: var(--r-md);
  margin-top: var(--sp-2);
  max-height: 300px;
  overflow-y: auto;
  color: var(--z-400);
  border: 1px solid var(--z-800);
}
