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

:root {
  --bg: #09090b;
  --bg-subtle: #0c0c0f;
  --surface: #111114;
  --surface-hover: #18181b;
  --border: #27272a;
  --border-subtle: #1f1f23;
  --text: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-muted: rgba(99, 102, 241, 0.12);
  --accent-glow: rgba(99, 102, 241, 0.2);
  --success: #22c55e;
  --success-muted: rgba(34, 197, 94, 0.12);
  --danger: #ef4444;
  --danger-muted: rgba(239, 68, 68, 0.12);
  --warning: #eab308;
  --radius: 10px;
  --radius-lg: 14px;
  --font: "Inter", system-ui, sans-serif;
  --mono: "JetBrains Mono", Consolas, monospace;
  --topbar-h: 56px;
  --mobile-bar-h: 68px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(99, 102, 241, 0.08), transparent),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(139, 92, 246, 0.05), transparent);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Topbar ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(9, 9, 11, 0.8);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: grid;
  place-items: center;
  color: #fff;
}

.brand h1 {
  font-size: 0.9375rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.brand p {
  font-size: 0.6875rem;
  color: var(--text-muted);
}

/* ── Layout ── */
.layout {
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  padding: 1rem;
  padding-bottom: calc(var(--mobile-bar-h) + var(--safe-bottom) + 1rem);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 900px) {
  .layout {
    flex-direction: row;
    align-items: flex-start;
    gap: 1.25rem;
    padding: 1.25rem;
    padding-bottom: 1.25rem;
  }
}

/* ── Panel ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.panel-head {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(0, 0, 0, 0.15);
}

.panel-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.panel-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.panel-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.125rem;
}

.panel-body {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 900px) {
  .layout > .panel:first-child {
    width: 300px;
    flex-shrink: 0;
    position: sticky;
    top: calc(var(--topbar-h) + 1rem);
  }
}

.content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.content > .panel {
  flex: 1;
}

/* ── Form ── */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

@media (min-width: 900px) {
  .field-row {
    grid-template-columns: 1fr;
  }
}

.field-side {
  max-width: 100%;
}

.field-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.field-label-sm {
  font-size: 0.6875rem;
  color: var(--text-muted);
}

.field-hint {
  font-size: 0.6875rem;
  color: var(--text-muted);
}

.muted {
  font-weight: 400;
  color: var(--text-muted);
}

.input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.5625rem 0.75rem;
  font-size: 0.875rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-height: 40px;
}

.input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-mono {
  font-family: var(--mono);
  font-size: 0.8125rem;
}

select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2371717a' viewBox='0 0 16 16'%3E%3Cpath d='M4.5 6l3.5 3.5L11.5 6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.625rem center;
  padding-right: 2rem;
}

.custom-range {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin-top: 0.25rem;
}

/* ── Chips ── */
.chip-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.3125rem;
}

.chip {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-secondary);
  border-radius: var(--radius);
  padding: 0.4375rem 0.125rem;
  font-size: 0.75rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.12s ease;
  min-height: 34px;
}

.chip:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

.chip.active {
  background: var(--accent-muted);
  border-color: var(--accent);
  color: #c7d2fe;
}

.chip.full {
  grid-column: 1 / -1;
}

.time-preview {
  padding: 0.5rem 0.625rem;
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.6875rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s ease;
  min-height: 40px;
  padding: 0 1rem;
  white-space: nowrap;
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.btn-outline:hover {
  border-color: var(--text-muted);
  color: var(--text);
  background: var(--surface-hover);
}

.btn-sm {
  min-height: 34px;
  padding: 0 0.75rem;
  font-size: 0.8125rem;
}

.btn-block { width: 100%; }

.btn-desktop { display: none; }

@media (min-width: 900px) {
  .btn-desktop {
    display: inline-flex;
    width: 100%;
    margin-top: 0.25rem;
  }
}

.btn-icon {
  min-height: 34px;
  width: 34px;
  padding: 0;
}

/* ── Mobile bar ── */
.mobile-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  padding: 0.625rem 1rem;
  padding-bottom: calc(0.625rem + var(--safe-bottom));
  background: rgba(9, 9, 11, 0.92);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
}

@media (min-width: 900px) {
  .mobile-bar { display: none; }
}

/* ── Empty ── */
.panel-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 1.5rem;
  min-height: 280px;
}

.empty-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent-muted);
  color: var(--accent);
  display: grid;
  place-items: center;
  margin-bottom: 1rem;
}

.panel-empty h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.375rem;
}

.panel-empty p {
  font-size: 0.8125rem;
  color: var(--text-muted);
  max-width: 320px;
}

/* ── Alert ── */
.alert {
  padding: 0.625rem 0.875rem;
  border-radius: var(--radius);
  font-size: 0.8125rem;
}

.alert-error {
  background: var(--danger-muted);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: #fca5a5;
}

/* ── Stats ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

@media (min-width: 640px) {
  .stats-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

.stat-card {
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 0.625rem 0.75rem;
}

.stat-label {
  display: block;
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.125rem;
}

.stat-value {
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.stat-value.positive { color: var(--success); }
.stat-value.negative { color: var(--danger); }
.stat-value.estimated { color: var(--warning); }

/* ── Section ── */
.section-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.625rem;
  padding-top: 0.25rem;
}

.section-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.section-badge {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 0.0625rem 0.4375rem;
}

/* ── Slug list ── */
.slug-list {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.slug-card {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 0.625rem 0.75rem;
  transition: border-color 0.12s, background 0.12s;
}

.slug-card:hover {
  border-color: var(--border);
  background: var(--surface-hover);
}

@media (min-width: 768px) {
  .slug-card {
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 0.75rem;
  }
}

.slug-card-main {
  min-width: 0;
}

.slug-card-top {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  margin-bottom: 0.125rem;
}

.slug-name {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
  min-width: 0;
}

.slug-market-title {
  font-size: 0.8125rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.winner-tag {
  flex-shrink: 0;
  padding: 0.0625rem 0.4375rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  background: var(--accent-muted);
  color: #a5b4fc;
  line-height: 1.35;
}

.slug-card-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem 0.75rem;
}

@media (min-width: 768px) {
  .slug-card-stats {
    flex-wrap: nowrap;
    gap: 0.875rem;
    padding-left: 0.75rem;
    border-left: 1px solid var(--border-subtle);
  }
}

.slug-stat {
  display: inline-flex;
  align-items: baseline;
  gap: 0.25rem;
  white-space: nowrap;
}

.slug-stat-label {
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.slug-stat-value {
  font-size: 0.875rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.slug-stat-value.positive { color: var(--success); }
.slug-stat-value.negative { color: var(--danger); }
.slug-stat-value.estimated { color: var(--warning); }

.slug-card-action {
  display: flex;
  justify-content: flex-end;
}

@media (min-width: 768px) {
  .slug-card-action {
    justify-content: center;
  }
}

/* ── Table ── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  min-width: 640px;
}

.data-table th {
  text-align: left;
  padding: 0.625rem 0.875rem;
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.data-table td {
  padding: 0.5625rem 0.875rem;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

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

.data-table tbody tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.data-table .mono {
  font-family: var(--mono);
  font-size: 0.75rem;
}

.table-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0.625rem 0 0;
}

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 0.125rem 0.4375rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 700;
}

.badge-buy {
  background: var(--success-muted);
  color: var(--success);
}

.badge-sell {
  background: var(--danger-muted);
  color: var(--danger);
}

/* ── Spinner ── */
.spinner {
  display: inline-block;
  width: 0.875rem;
  height: 0.875rem;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

.hidden { display: none !important; }
