/* V4 Client Portal — Core Styles */
:root {
  --bg: #0e1117;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-hover: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8eaed;
  --text-muted: #9aa0a6;
  --accent: #8ab4f8;
  --accent-dim: rgba(138, 180, 248, 0.15);
  --sage: #81c995;
  --peach: #f6aea9;
  --sky: #8ab4f8;
  --lavender: #c58af9;
  --butter: #fdd663;
  --mint: #78d9a0;
  --good: #81c995;
  --bad: #f28b82;
  --radius: 12px;
  --radius-sm: 8px;
  --font: "IBM Plex Sans", -apple-system, sans-serif;
  --font-display: "Space Grotesk", sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.15;
  pointer-events: none;
  z-index: 0;
}
.orb-a {
  width: 500px;
  height: 500px;
  top: -10%;
  left: -5%;
  background: var(--accent);
}
.orb-b {
  width: 400px;
  height: 400px;
  bottom: -10%;
  right: -5%;
  background: var(--lavender);
}

.shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
  position: relative;
  z-index: 1;
}

/* Header */
.v4-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
}
.v4-header h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
}
.eyebrow {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

/* Market selector */
.market-selector {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}
.market-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  opacity: 0.5;
  transition: all 0.2s;
  line-height: 1;
}
.market-btn:hover {
  opacity: 0.8;
  border-color: var(--text-muted);
}
.market-btn.active {
  opacity: 1;
  border-color: var(--accent);
  background: var(--accent-dim);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}
.btn-primary {
  background: var(--accent);
  color: var(--bg);
}
.btn-primary:hover {
  filter: brightness(1.1);
}
.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  transition: all 0.2s;
}
.card:hover {
  background: var(--surface-hover);
}
.card.selected {
  border-color: var(--accent);
  background: var(--accent-dim);
}

/* Grid */
.grid {
  display: grid;
  gap: 1rem;
}
.grid-2 {
  grid-template-columns: repeat(2, 1fr);
}
.grid-3 {
  grid-template-columns: repeat(3, 1fr);
}
.grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

/* Thumbnails */
.thumb {
  width: 100%;
  aspect-ratio: 16/9;
  border-radius: var(--radius-sm);
  background-size: cover;
  background-position: center;
  background-color: var(--surface);
}
.thumb-sm {
  width: 80px;
  height: 45px;
  border-radius: 6px;
}

/* Chips / Pills */
.chip {
  display: inline-block;
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.chip.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.chip.removable {
  cursor: pointer;
}
.chip.removable::after {
  content: " ×";
}

/* Score bar */
.score-bar {
  height: 6px;
  background: var(--surface);
  border-radius: 3px;
  overflow: hidden;
}
.score-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.3s;
}

/* Section titles */
.section-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

/* Input */
.input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s;
}
.input:focus {
  border-color: var(--accent);
}
textarea.input {
  resize: vertical;
  min-height: 100px;
}

/* Loading */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Progress bar */
.progress-bar {
  height: 8px;
  background: var(--surface);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--lavender));
  border-radius: 4px;
}

/* Search bar */
.search-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}
.search-bar .input {
  flex: 1;
}

/* Selected bar (bottom) */
.selected-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(14, 17, 23, 0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 0.75rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
  transform: translateY(100%);
  transition: transform 0.3s;
}
.selected-bar.visible {
  transform: translateY(0);
}
.selected-pills {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  flex: 1;
}

/* Twin badges */
.twin-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.625rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0 2px;
}
.twin-badge.good {
  border-color: var(--good);
  color: var(--good);
}
.twin-badge.bad {
  border-color: var(--bad);
  color: var(--bad);
}

/* Results row */
.result-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
}
.result-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}
.result-row-summary {
  padding: 0.5rem 1rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.result-row-body {
  display: flex;
  gap: 1rem;
  padding: 1rem;
  overflow-x: auto;
}

/* Content rail */
.content-rail {
  display: flex;
  gap: 1rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  flex: 1;
}
.content-rail::-webkit-scrollbar {
  height: 4px;
}
.content-rail::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* Rail card */
.rail-card {
  flex: 0 0 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}
.rail-card:hover {
  background: var(--surface-hover);
}
.rail-card.selected {
  border-color: var(--accent);
}
.rail-card.deselected {
  opacity: 0.5;
}
.rail-card .thumb {
  margin-bottom: 0.5rem;
}
.rail-card .card-title {
  font-size: 0.8125rem;
  font-weight: 500;
  margin-bottom: 0.375rem;
  line-height: 1.3;
}
.rail-card .score-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.375rem;
}
.rail-card .score-value {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--accent);
  min-width: 24px;
}
.rail-card .why-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.375rem;
}
.rail-card .tag-row {
  display: flex;
  gap: 0.375rem;
  flex-wrap: wrap;
  margin-bottom: 0.375rem;
}
.rail-card .tag {
  font-size: 0.6875rem;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent);
}

/* Quote carousel */
.quote-box {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  margin-top: 0.375rem;
}
.quote-box .twin-badge {
  width: 28px;
  height: 28px;
  font-size: 0.625rem;
  flex-shrink: 0;
}
.quote-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
  flex: 1;
}
.quote-nav {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 0 0.25rem;
}
.quote-nav:hover {
  color: var(--text);
}

/* Checkbox */
.tile-check {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 2px solid var(--border);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.tile-check.checked {
  background: var(--accent);
  border-color: var(--accent);
}
.tile-check.checked::after {
  content: "✓";
  color: var(--bg);
  font-size: 0.75rem;
  font-weight: 700;
}

/* Toggle bar */
.toggle-bar {
  display: flex;
  gap: 0.25rem;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 0.25rem;
  margin-bottom: 1.5rem;
  width: fit-content;
}
.toggle-btn {
  padding: 0.375rem 1rem;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all 0.2s;
}
.toggle-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
}

/* Overview panel */
.overview-panel {
  padding: 1rem;
}
.overview-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}
.overview-metric {
  text-align: center;
}
.overview-metric .value {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--accent);
}
.overview-metric .label {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.topic-bar {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}
.topic-segment {
  height: 100%;
}
.topic-legend {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.topic-item {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.topic-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

/* Signal quality panel */
.signal-quality-panel {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
}
.signal-quality-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}
.signal-quality-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.signal-quality-label {
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 600;
}
.signal-quality-detail {
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 0.75rem;
}
.signal-bar-track {
  height: 8px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 4px;
  position: relative;
}
.signal-bar-iqr {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 4px;
  opacity: 0.45;
}
.signal-bar-median {
  position: absolute;
  top: -3px;
  width: 3px;
  height: 14px;
  border-radius: 1.5px;
  transform: translateX(-1px);
}
.signal-stats-toggle {
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  background: none;
  border: none;
  font-family: var(--font);
  padding: 0;
  margin-top: 0.5rem;
  display: inline-block;
}
.signal-stats-toggle:hover {
  color: var(--text);
}
.signal-stats-row {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.375rem;
  display: none;
}
.signal-stats-row.visible {
  display: block;
}

/* Three-column layout (strategy page) */
.three-col {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1.5rem;
}

/* Floating quotes animation */
.float-quote {
  position: absolute;
  animation: floatUp 8s ease-in-out infinite;
  opacity: 0.6;
}
@keyframes floatUp {
  0%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  50% {
    transform: translateY(-20px);
    opacity: 0.8;
  }
}

/* Creative card (in results) */
.creative-card {
  flex: 0 0 200px;
}
.creative-card .thumb {
  margin-bottom: 0.5rem;
}
.creative-card .card-title {
  font-size: 0.875rem;
  font-weight: 500;
}
.creative-label {
  font-size: 0.6875rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Auth overlay */
#auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-box {
  width: 340px;
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}
.auth-logo {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.5rem;
}
.auth-sub {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
}

/* Responsive */
@media (max-width: 900px) {
  .grid-3,
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
  .three-col {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 600px) {
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }
  .shell {
    padding: 1rem;
  }
}
