:root {
  --background: 210 20% 98%;
  --foreground: 222.2 47.4% 11.2%;
  --muted: 215 16.3% 46.9%;
  --card: 0 0% 100%;
  --card-foreground: 222.2 47.4% 11.2%;
  --border: 214.3 31.8% 91.4%;
  --input: 214.3 31.8% 91.4%;
  --primary: 221.2 83.2% 53.3%;
  --primary-foreground: 210 40% 98%;
  --secondary: 210 40% 96.1%;
  --secondary-foreground: 222.2 47.4% 11.2%;
  --destructive: 0 84.2% 60.2%;
  --radius: 0.75rem;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: hsl(var(--foreground));
  font-family: "Space Grotesk", sans-serif;
  background:
    radial-gradient(1300px 700px at 95% -10%, rgba(59, 130, 246, 0.15), transparent 55%),
    radial-gradient(1000px 500px at -10% -10%, rgba(14, 165, 233, 0.1), transparent 50%),
    hsl(var(--background));
}

.bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0.9));
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 1500px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 16px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.page-header {
  display: grid;
  gap: 6px;
}

.page-header p {
  margin: 0;
  color: hsl(var(--muted));
  font-size: clamp(0.92rem, 1.6vw, 1.08rem);
}

.brand-wordmark {
  width: min(100%, 760px);
  height: auto;
  display: block;
  filter: drop-shadow(0 12px 20px rgba(5, 22, 45, 0.08));
}

.card {
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.05);
}

.controls-card {
  padding: 12px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.card-head h2 {
  margin: 0;
  font-size: 1.03rem;
}

.subtle {
  margin: 4px 0 0;
  color: hsl(var(--muted));
  font-size: 0.84rem;
}

.card-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  border-radius: 999px;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  padding: 2px 8px;
  font-size: 0.73rem;
  font-family: "JetBrains Mono", monospace;
}

.badge.live {
  background: rgba(34, 197, 94, 0.12);
  color: #15803d;
  border-color: rgba(34, 197, 94, 0.3);
}

.badge.external {
  background: rgba(59, 130, 246, 0.12);
  color: #1d4ed8;
  border-color: rgba(59, 130, 246, 0.3);
}

.badge.simulated {
  background: rgba(249, 115, 22, 0.12);
  color: #c2410c;
  border-color: rgba(249, 115, 22, 0.3);
}

.badge.mock {
  background: rgba(217, 119, 6, 0.15);
  color: #92400e;
  border-color: rgba(217, 119, 6, 0.3);
}

.badge.error {
  background: rgba(220, 38, 38, 0.12);
  color: #b91c1c;
  border-color: rgba(220, 38, 38, 0.28);
}

.badge.loading {
  background: rgba(2, 132, 199, 0.12);
  color: #0369a1;
  border-color: rgba(2, 132, 199, 0.3);
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  align-items: end;
}

.controls-grid > label:not(.checkbox-label) {
  display: grid;
  grid-template-rows: 2.35em auto;
  align-items: start;
}

.multi-dropdown-label {
  position: relative;
}

.history-controls {
  margin-bottom: 12px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8rem;
  color: hsl(var(--muted));
}

.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  min-height: 42px;
  color: hsl(var(--foreground));
}

.input,
.select,
.button {
  font: inherit;
}

.input,
.select {
  width: 100%;
  border: 1px solid hsl(var(--input));
  border-radius: calc(var(--radius) - 4px);
  background: #fff;
  color: hsl(var(--foreground));
  padding: 9px 10px;
}

.multi-select-store {
  display: none;
}

.multi-dropdown {
  width: 100%;
  position: relative;
}

.multi-dropdown-summary {
  list-style: none;
  border: 1px solid hsl(var(--input));
  border-radius: calc(var(--radius) - 4px);
  background: #fff;
  color: hsl(var(--foreground));
  padding: 9px 10px;
  cursor: pointer;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.multi-dropdown-summary::-webkit-details-marker {
  display: none;
}

.multi-dropdown-summary::after {
  content: "▾";
  font-size: 0.8rem;
  color: hsl(var(--muted));
}

.multi-dropdown[open] .multi-dropdown-summary::after {
  content: "▴";
}

.multi-dropdown-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 4px);
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.14);
  padding: 8px;
  display: grid;
  gap: 8px;
}

.multi-dropdown-search {
  min-height: 36px;
  padding: 8px 9px;
}

.multi-dropdown-options {
  max-height: 240px;
  overflow: auto;
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  padding: 4px;
}

.multi-option {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  font-size: 0.82rem;
  color: hsl(var(--foreground));
  border-radius: 6px;
  cursor: pointer;
}

.multi-option input[type="checkbox"] {
  margin: 0;
  flex: 0 0 auto;
}

.multi-option span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.multi-option:hover {
  background: rgba(59, 130, 246, 0.08);
}

.multi-empty {
  padding: 8px;
  color: hsl(var(--muted));
  font-size: 0.8rem;
}

.tooltip-anchor {
  position: relative;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid hsl(var(--border));
  color: hsl(var(--muted));
  font-size: 0.72rem;
  cursor: help;
}

.tooltip-content {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  z-index: 40;
  width: min(320px, 70vw);
  display: none;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  padding: 8px;
  line-height: 1.35;
  font-size: 0.75rem;
}

.tooltip-anchor:hover .tooltip-content,
.tooltip-anchor:focus-within .tooltip-content {
  display: block;
}

.input:focus,
.select:focus,
.button:focus {
  outline: 2px solid rgba(59, 130, 246, 0.35);
  outline-offset: 1px;
}

.button {
  border-radius: calc(var(--radius) - 4px);
  border: 1px solid transparent;
  padding: 9px 12px;
  font-weight: 600;
  cursor: pointer;
  margin-top: auto;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button-primary {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}

.button-outline {
  background: #fff;
  border-color: hsl(var(--border));
  color: hsl(var(--foreground));
}

.controls-note {
  margin-top: 8px;
  color: hsl(var(--muted));
  font-size: 0.78rem;
}

.summary {
  border: 1px solid hsl(var(--border));
  background: rgba(241, 245, 249, 0.45);
  border-radius: calc(var(--radius) - 4px);
  padding: 10px;
  font-size: 0.86rem;
  line-height: 1.45;
  margin-bottom: 10px;
}

.summary ul {
  margin: 0;
  padding-left: 18px;
}

.summary li {
  margin-bottom: 4px;
}

.summary li:last-child {
  margin-bottom: 0;
}

.connection-note {
  font-size: 0.8rem;
  color: hsl(var(--muted));
  margin-top: 8px;
}

.table-wrap {
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 4px);
  overflow: auto;
  background: #fff;
}

.projection-card {
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 4px);
  background: rgba(241, 245, 249, 0.55);
  padding: 10px;
  margin-bottom: 10px;
}

.capacity-card {
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 4px);
  background: rgba(241, 245, 249, 0.55);
  padding: 10px;
  margin-top: 0;
}

.capacity-card h2 {
  margin: 0;
  font-size: 1.03rem;
}

.capacity-controls {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 8px;
}

.projection-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.projection-head h3 {
  margin: 0;
  font-size: 0.95rem;
}

.projection-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 8px;
}

.ct-controls {
  margin-bottom: 10px;
}

.ct-tables-grid {
  margin-bottom: 10px;
}

.ct-tables-grid table {
  min-width: 0;
}

.ct-chart-wrap canvas {
  min-height: 220px;
  max-height: 300px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1080px;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  font-size: 0.76rem;
  color: hsl(var(--muted));
  background: hsl(var(--secondary));
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid hsl(var(--border));
}

tbody td {
  padding: 8px;
  border-bottom: 1px solid hsl(var(--border));
  font-size: 0.84rem;
  white-space: nowrap;
}

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

#opportunitiesTableBody tr.skeleton-row {
  cursor: default;
}

#opportunitiesTableBody tr.skeleton-row:hover {
  background: transparent;
}

.skeleton-line {
  height: 11px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(226, 232, 240, 0.9) 20%, rgba(241, 245, 249, 1) 50%, rgba(226, 232, 240, 0.9) 80%);
  background-size: 220% 100%;
  animation: shimmer 1.15s linear infinite;
}

.loading-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.spinner {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid rgba(2, 132, 199, 0.25);
  border-top-color: #0284c7;
  animation: spin 0.9s linear infinite;
}

#opportunitiesTableBody tr {
  cursor: pointer;
}

#opportunitiesTableBody tr:hover {
  background: rgba(59, 130, 246, 0.08);
}

#opportunitiesTableBody tr.selected {
  background: rgba(59, 130, 246, 0.13);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.kpi-card {
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 4px);
  background: #fff;
  padding: 8px;
  display: grid;
  gap: 4px;
}

.kpi-card span {
  font-size: 0.72rem;
  color: hsl(var(--muted));
}

.kpi-card strong {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.95rem;
}

.chart-wrap {
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 4px);
  background: #fff;
  padding: 8px;
  margin-bottom: 10px;
}

.chart-wrap canvas {
  width: 100%;
  min-height: 280px;
  max-height: 360px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.one {
  grid-template-columns: 1fr;
}

.raw-hover {
  position: relative;
  border: 1px dashed hsl(var(--border));
  color: hsl(var(--muted));
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 0.72rem;
  font-family: "JetBrains Mono", monospace;
}

.raw-tooltip {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 40;
  display: none;
  width: min(760px, 90vw);
  max-height: 360px;
  overflow: auto;
  background: #0f172a;
  color: #dbeafe;
  border: 1px solid #1e293b;
  border-radius: 10px;
  padding: 10px;
  margin: 0;
  white-space: pre-wrap;
  font-size: 0.78rem;
  line-height: 1.4;
}

.raw-hover:hover .raw-tooltip,
.raw-hover:focus-within .raw-tooltip {
  display: block;
}

.outlier-yes {
  color: #b91c1c;
  font-weight: 600;
}

.outlier-no {
  color: #15803d;
}

.pass-yes {
  color: #15803d;
  font-weight: 600;
}

.pass-no {
  color: #b91c1c;
  font-weight: 600;
}

.venue-pill {
  border: 1px solid hsl(var(--border));
  border-radius: 999px;
  background: #fff;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-family: "JetBrains Mono", monospace;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -20% 0;
  }
}

@media (max-width: 1360px) {
  .controls-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 920px) {
  .grid.two {
    grid-template-columns: 1fr;
  }

  .controls-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .projection-controls {
    grid-template-columns: 1fr;
  }

  .capacity-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 12px;
  }

  .brand-wordmark {
    width: min(100%, 520px);
  }

  .controls-grid {
    grid-template-columns: 1fr;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .capacity-controls {
    grid-template-columns: 1fr;
  }
}
