/* ============================================
   TRADEUPX — PREMIUM DARK ANALYTICS
   Tokens
   ============================================ */
:root {
  /* Layered surfaces (4 levels) */
  --bg-app: #080d14;
  --bg-sidebar: #0e151f;
  --bg-card: #111923;
  --bg-row: #141d28;
  --bg-row-hover: #18222f;
  --bg-row-active: #1c2737;
  --bg-input: #0a1019;
  --bg-elevated: #1a2433;

  /* Borders */
  --border: rgba(148, 163, 184, 0.12);
  --border-strong: rgba(148, 163, 184, 0.20);
  --border-bright: rgba(148, 163, 184, 0.32);

  /* Text */
  --text-primary: #e6ebf2;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-faint: #475569;

  /* Accent — Amber, used SPARINGLY */
  --amber: #f4b942;
  --amber-soft: #d99c2b;
  --amber-tint: rgba(244, 185, 66, 0.10);
  --amber-tint-strong: rgba(244, 185, 66, 0.18);
  --amber-border: rgba(244, 185, 66, 0.28);

  /* Status — calm, not garish */
  --green: #4ade80;
  --green-deep: #22c55e;
  --green-tint: rgba(74, 222, 128, 0.10);
  --green-border: rgba(74, 222, 128, 0.25);

  --red: #f87171;
  --red-tint: rgba(248, 113, 113, 0.10);
  --red-border: rgba(248, 113, 113, 0.25);

  --blue: #60a5fa;
  --blue-tint: rgba(96, 165, 250, 0.10);
  --blue-border: rgba(96, 165, 250, 0.25);

  /* Type */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

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

  /* Layout */
  --header-h: 52px;
  --sidebar-w: 320px;
  --toolbar-h: 56px;

  /* Focus */
  --focus: 0 0 0 2px var(--bg-app), 0 0 0 4px var(--amber);
}

/* ============================================
   RESET
   ============================================ */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  font-feature-settings: 'cv11', 'ss01';
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
button:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: var(--focus);
  border-radius: var(--r-md);
}

input, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

/* tabular numbers everywhere they matter */
.num, .tabular { font-variant-numeric: tabular-nums; }

::selection { background: var(--amber-tint-strong); color: var(--text-primary); }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.12); border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, 0.22); background-clip: padding-box; border: 2px solid transparent; }

/* ============================================
   APP SHELL
   ============================================ */
.app-header {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--header-h);
  background:
    linear-gradient(180deg, rgba(244,185,66,0.035), transparent 70%),
    var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
}

.header-left { display: flex; align-items: center; gap: 16px; }
.header-right { display: flex; align-items: center; gap: 8px; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.2px;
  color: var(--text-primary);
}
.brand-logo {
  width: 30px;
  height: 30px;
  display: block;
  border-radius: 8px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08), 0 6px 16px rgba(0,0,0,0.22);
}
.brand-mark { display: none; }
.brand-name {
  display: inline-flex;
  align-items: baseline;
  gap: 1px;
  font-size: 15px;
  font-weight: 750;
}
.brand-x { color: var(--amber); }
.brand-sub {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 400;
  border-left: 1px solid var(--border);
  padding-left: 12px;
  margin-left: 4px;
}

.hamburger {
  display: none;
  width: 32px; height: 32px;
  align-items: center; justify-content: center;
  border-radius: var(--r-md);
  color: var(--text-secondary);
}
.hamburger:hover { background: var(--bg-row); color: var(--text-primary); }
.hamburger svg { width: 18px; height: 18px; }

.status-dot {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px;
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--bg-card);
}
.status-dot .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.18);
}
.status-dot.partial .dot { background: var(--amber); box-shadow: 0 0 0 2px rgba(244, 185, 66, 0.18); }
.status-dot.low .dot { background: var(--red); box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.18); }

.icon-btn {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-md);
  color: var(--text-secondary);
  border: 1px solid transparent;
}
.icon-btn:hover { background: var(--bg-row); color: var(--text-primary); border-color: var(--border); }
.icon-btn svg { width: 16px; height: 16px; }

.app-shell {
  position: fixed;
  top: var(--header-h); left: 0; right: 0; bottom: 0;
  display: flex;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  height: 100%;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 14px 100px;
  display: flex; flex-direction: column; gap: 14px;
}

.sb-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 4px 4px;
}
.sb-header h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  font-weight: 600;
  margin: 0;
}
.sb-clear {
  font-size: 11px;
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: var(--r-sm);
}
.sb-clear:hover { color: var(--amber); background: var(--amber-tint); }

/* ============================================
   MAIN
   ============================================ */
.main {
  flex: 1;
  height: 100%;
  overflow-y: auto;
  display: flex; flex-direction: column;
}
.main-inner {
  padding: 18px 24px 32px;
  max-width: 1500px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
  display: flex; flex-direction: column;
  gap: 14px;
}

/* ============================================
   RESULTS HEADER (title + confidence)
   ============================================ */
.results-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.rh-left { display: flex; flex-direction: column; gap: 4px; }
.rh-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--text-primary);
  display: inline-flex; align-items: baseline; gap: 10px;
}
.rh-count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0;
}
.rh-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.confidence {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 10px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--bg-card);
  font-size: 11.5px;
  color: var(--text-secondary);
  position: relative;
}
.confidence .conf-label { color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.6px; font-size: 10.5px; font-weight: 600; }
.confidence .conf-val { color: var(--text-primary); font-weight: 500; }
.confidence .conf-led {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green);
}
.confidence.partial .conf-led { background: var(--amber); }
.confidence.low .conf-led { background: var(--red); }
.confidence .info {
  width: 14px; height: 14px;
  border-radius: 50%;
  display: inline-grid; place-items: center;
  font-size: 10px;
  color: var(--text-muted);
  cursor: help;
  border: 1px solid var(--border-strong);
  font-family: var(--font-mono);
}
.confidence .tooltip {
  position: absolute;
  top: calc(100% + 6px); right: 0;
  width: 260px;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  font-size: 11.5px;
  color: var(--text-secondary);
  line-height: 1.45;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  opacity: 0; pointer-events: none;
  transition: opacity 120ms ease;
  z-index: 20;
}
.confidence:hover .tooltip { opacity: 1; }

/* ============================================
   FOOTER
   ============================================ */
.app-footer {
  margin-top: auto;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  display: flex; justify-content: space-between; align-items: center;
  gap: 16px;
}
.app-footer nav {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.app-footer a { color: var(--text-secondary); }
.app-footer a:hover { color: var(--text-secondary); }

body.legal-page {
  min-height: 100%;
  overflow: auto;
  background:
    radial-gradient(circle at top left, rgba(244, 185, 66, 0.07), transparent 320px),
    var(--bg-app);
}
.legal-wrap {
  width: min(900px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0;
}
.legal-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 800;
}
.legal-brand span span { color: var(--amber); }
.legal-card {
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--bg-card);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.24);
}
.legal-eyebrow {
  margin: 0 0 8px;
  color: var(--amber);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}
.legal-card h1 {
  margin: 0 0 22px;
  font-size: clamp(28px, 4vw, 40px);
  letter-spacing: -0.02em;
}
.legal-card article {
  padding: 18px 0;
  border-top: 1px solid var(--border);
}
.legal-card h2 {
  margin: 0 0 6px;
  font-size: 15px;
}
.legal-card p {
  margin: 0;
  color: var(--text-secondary);
  line-height: 1.7;
}
.legal-note {
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}
.legal-nav {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 18px;
  color: var(--text-secondary);
  font-size: 12px;
}
.legal-nav a:hover { color: var(--amber); }

/* ============================================
   MOBILE
   ============================================ */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: var(--header-h) 0 0 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 40;
  opacity: 0;
  transition: opacity 180ms;
}
.sidebar-backdrop.open { display: block; opacity: 1; }

@media (max-width: 880px) {
  .hamburger { display: inline-flex; }
  .brand-sub { display: none; }
  .sidebar {
    position: fixed;
    top: var(--header-h); left: 0; bottom: 0;
    width: 320px;
    transform: translateX(-100%);
    transition: transform 220ms cubic-bezier(0.32, 0.72, 0, 1);
    z-index: 50;
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.4);
  }
  .sidebar.open { transform: translateX(0); }
  .main-inner { padding: 14px 16px 28px; }
}
