/* =====================================================================
   Redesign Preview — modern UI prototype.
   All selectors are scoped under `.km2` so this CSS cannot bleed into
   the existing dashboard. Safe to ship alongside the production styles.
   ===================================================================== */

.km2 {
  /* Design tokens — Linear/Vercel-inspired modern dark */
  --km2-bg:            #0b0d12;
  --km2-surface:       #12151c;
  --km2-surface-2:     #1a1f29;
  --km2-surface-hover: #222938;
  --km2-border:        #242a36;
  --km2-border-strong: #323a4b;
  --km2-text:          #e6e9ef;
  --km2-text-muted:    #8a94a6;
  --km2-text-faint:    #5a6272;
  --km2-accent:        #6ea8ff;
  --km2-accent-soft:   rgba(110, 168, 255, 0.12);

  --km2-green:         #3fb950;
  --km2-green-dim:     #2a8a3c;
  --km2-green-bg:      rgba(63, 185, 80, 0.14);
  --km2-red:           #f85149;
  --km2-red-dim:       #b5382e;
  --km2-red-bg:        rgba(248, 81, 73, 0.14);
  --km2-amber:         #e3b341;
  --km2-amber-bg:      rgba(227, 179, 65, 0.14);

  --km2-radius:        10px;
  --km2-radius-sm:     6px;
  --km2-shadow:        0 1px 2px rgba(0,0,0,0.25), 0 8px 24px rgba(0,0,0,0.35);

  font-family: 'Inter', -apple-system, 'Segoe UI', sans-serif;
  font-feature-settings: 'cv11', 'ss01', 'ss03';
  font-variant-numeric: tabular-nums lining-nums;
  color: var(--km2-text);
  padding: 24px;

  /* Size: ~50% viewport width, ~600px tall with internal scroll.
     The real dashboard has 42 widgets — this redesign is meant to coexist
     alongside others, not dominate the viewport. Card chrome stays visually
     "floating" instead of taking the whole page. See the .km2-card-body
     rule below for the internal scroll behavior. */
  max-width: 50vw;
  min-width: 640px;      /* Don't crunch below usable width on narrow screens */
  margin: 0;             /* Left-aligned, not centered */
}

/* When the surrounding viewport is narrower than 1280px (≈13" MBP),
   let the card take the full width — 50vw would be too cramped. */
@media (max-width: 1279px) {
  .km2 {
    max-width: 100%;
  }
}

/* ---------- Banner ---------- */
.km2-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  margin-bottom: 20px;
  background: linear-gradient(135deg, rgba(110,168,255,0.08), rgba(110,168,255,0.02));
  border: 1px solid var(--km2-border);
  border-radius: var(--km2-radius);
  font-size: 12px;
  color: var(--km2-text-muted);
}
.km2-banner strong { color: var(--km2-text); font-weight: 600; }
.km2-banner-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--km2-accent);
  background: var(--km2-accent-soft);
  border-radius: 999px;
}

/* ---------- Card ---------- */
.km2-card {
  background: var(--km2-surface);
  border: 1px solid var(--km2-border);
  border-radius: var(--km2-radius);
  box-shadow: var(--km2-shadow);
  overflow: hidden;
  /* Card sized to ~600px. Header + column-header stay sticky at the top;
     the group rows scroll inside. Preserves generous row spacing while
     keeping the card a reasonable visual weight in the viewport. */
  max-height: 600px;
  display: flex;
  flex-direction: column;
}

/* Sticky header + column header stay visible while the rows scroll. */
.km2-card > .km2-card-header,
.km2-card > .km2-colhead {
  flex: 0 0 auto;
}

/* Row groups become the scrollable region. */
.km2-card > div:nth-of-type(3) {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
}

/* Footer stays pinned at the bottom (outside the scroll area). */
.km2-card > .km2-footer {
  flex: 0 0 auto;
}

/* Custom scrollbar for the card body — matches the design language. */
.km2-card > div:nth-of-type(3)::-webkit-scrollbar {
  width: 8px;
}
.km2-card > div:nth-of-type(3)::-webkit-scrollbar-track {
  background: transparent;
}
.km2-card > div:nth-of-type(3)::-webkit-scrollbar-thumb {
  background: var(--km2-border-strong);
  border-radius: 4px;
}
.km2-card > div:nth-of-type(3)::-webkit-scrollbar-thumb:hover {
  background: var(--km2-text-faint);
}

.km2-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--km2-border);
  background: linear-gradient(180deg, rgba(255,255,255,0.015), transparent);
}
.km2-card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--km2-text);
  letter-spacing: -0.2px;
}
.km2-card-subtitle {
  font-size: 12px;
  color: var(--km2-text-muted);
  margin-top: 2px;
  font-weight: 400;
}
.km2-card-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.km2-btn {
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--km2-text-muted);
  background: transparent;
  border: 1px solid var(--km2-border-strong);
  border-radius: var(--km2-radius-sm);
  padding: 6px 12px;
  cursor: pointer;
  transition: all 120ms ease;
}
.km2-btn:hover {
  color: var(--km2-text);
  background: var(--km2-surface-hover);
  border-color: var(--km2-text-faint);
}
.km2-btn-primary {
  color: var(--km2-accent);
  border-color: var(--km2-accent);
  background: var(--km2-accent-soft);
}
.km2-btn-primary:hover {
  background: rgba(110,168,255,0.22);
  color: var(--km2-text);
}

/* ---------- Column headers ---------- */
.km2-colhead {
  display: grid;
  grid-template-columns: 180px repeat(5, 1fr);
  gap: 8px;
  padding: 14px 20px 10px;
  border-bottom: 1px solid var(--km2-border);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--km2-text-muted);
}
.km2-colhead > div { text-align: center; }
.km2-colhead > div:first-child { text-align: left; }
.km2-colhead a {
  color: var(--km2-text-muted);
  text-decoration: none;
  transition: color 120ms ease;
}
.km2-colhead a:hover { color: var(--km2-accent); }

/* ---------- Group / section labels ---------- */
.km2-group {
  padding: 8px 0;
}
.km2-group-label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--km2-text-faint);
}
.km2-group-label::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 10px;
  background: var(--km2-accent);
  border-radius: 2px;
  opacity: 0.6;
}
.km2-group-label-momentum::before { background: var(--km2-accent); }
.km2-group-label-trend::before    { background: var(--km2-amber); }
.km2-group-label-breadth::before  { background: var(--km2-green); }
.km2-group-label-info::before     { background: var(--km2-text-faint); }

/* ---------- Rows ---------- */
.km2-row {
  display: grid;
  grid-template-columns: 180px repeat(5, 1fr);
  gap: 8px;
  align-items: center;
  padding: 8px 20px;
  border-bottom: 1px solid transparent;
  transition: background-color 120ms ease;
}
.km2-row:hover { background: var(--km2-surface-2); }
.km2-row-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--km2-text);
  letter-spacing: -0.1px;
}

/* ---------- Metric cell (one per index) ---------- */
.km2-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 10px;
  border-radius: var(--km2-radius-sm);
  background: var(--km2-surface-2);
  border: 1px solid var(--km2-border);
  text-decoration: none;
  transition: all 120ms ease;
  overflow: hidden;
  min-height: 42px;
}
.km2-cell:hover {
  border-color: var(--km2-border-strong);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.km2-cell-pct {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.3px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  z-index: 1;
}
.km2-cell-counts {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 500;
  color: var(--km2-text-muted);
  font-variant-numeric: tabular-nums;
  z-index: 1;
}
.km2-cell-counts .up   { color: var(--km2-green); }
.km2-cell-counts .down { color: var(--km2-red); }

/* Background fill bar — scales with pct value */
.km2-cell-bar {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
}

/* Tone variants: colour hinting based on % bullishness */
.km2-cell--bull-strong { background: var(--km2-green-bg); border-color: rgba(63,185,80,0.35); }
.km2-cell--bull-strong .km2-cell-pct { color: var(--km2-green); }
.km2-cell--bull        { background: rgba(63,185,80,0.06); }
.km2-cell--bull        .km2-cell-pct { color: var(--km2-green); }
.km2-cell--neutral     { }
.km2-cell--neutral     .km2-cell-pct { color: var(--km2-text); }
.km2-cell--bear        { background: rgba(248,81,73,0.06); }
.km2-cell--bear        .km2-cell-pct { color: var(--km2-red); }
.km2-cell--bear-strong { background: var(--km2-red-bg); border-color: rgba(248,81,73,0.35); }
.km2-cell--bear-strong .km2-cell-pct { color: var(--km2-red); }

.km2-cell--info { background: transparent; border-style: dashed; }
.km2-cell--info .km2-cell-pct { font-size: 13px; color: var(--km2-text-muted); }
.km2-cell--empty { opacity: 0.3; }

/* ---------- Footer legend ---------- */
.km2-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--km2-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--km2-text-muted);
}
.km2-legend { display: flex; gap: 16px; align-items: center; }
.km2-legend-chip {
  display: inline-flex; align-items: center; gap: 6px;
}
.km2-legend-chip::before {
  content: ''; width: 10px; height: 10px; border-radius: 2px;
}
.km2-legend-chip.bull::before { background: var(--km2-green); }
.km2-legend-chip.neutral::before { background: var(--km2-text-faint); }
.km2-legend-chip.bear::before { background: var(--km2-red); }

/* ---------- Focus drawer (placeholder for future expansion) ---------- */
.km2-drawer-hint {
  padding: 14px 20px;
  font-size: 12px;
  color: var(--km2-text-faint);
  text-align: center;
  font-style: italic;
}
