/* ============================================================
   Tokens & Custom Properties
   Premium Dark-Mode inspired by Linear & Vercel
   ============================================================ */
:root {
  --bg: #0A0A0C;
  --panel: #121215;
  --panel-raised: #18181C;
  --line: #222227;
  --line-soft: #1A1A1E;
  
  --text: #F4F4F5;
  --text-muted: #A1A1AA;
  --text-dim: #52525B;

  --accent: #3B82F6; /* Premium Amber/Blue Restrained Choice */
  --signal: #F59E0B; /* Amber — active / in-progress */
  --signal-dim: #271C0C;
  --confirmed: #10B981; /* Emerald — success */
  --danger: #EF4444;

  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  --radius: 8px;
  --radius-sm: 4px;
}

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

html { 
  color-scheme: dark; 
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13.5px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.mono { font-family: var(--font-mono); }

@media (prefers-reduced-motion: reduce) {
  * { 
    animation-duration: 0.01ms !important; 
    transition-duration: 0.01ms !important; 
  }
}

.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px 64px;
}

/* ============================================================
   Top Bar (Sticky & Polished)
   ============================================================ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 10, 12, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: auto;
}

.brand-mark {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text);
  box-shadow: 0 0 0 4px var(--line-soft);
}

.brand-name {
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: 0.2em;
  font-size: 12px;
}

.conn-state {
  display: flex; 
  align-items: center; 
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--panel);
  padding: 4px 10px;
  border-radius: 100px;
  border: 1px solid var(--line);
}

.conn-state .dot {
  width: 6px; 
  height: 6px; 
  border-radius: 50%;
  background: var(--text-dim);
}

.conn-state[data-state="online"] .dot { background: var(--confirmed); }
.conn-state[data-state="online"] .conn-label::after { content: "connected"; }
.conn-state[data-state="online"] .conn-label { font-size: 0; }
.conn-state[data-state="online"] .conn-label::after { font-size: 12px; }
.conn-state[data-state="offline"] .dot { background: var(--danger); }

.topbar-actions { display: flex; gap: 8px; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 12.5px;
  font-weight: 500;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all .15s ease;
}

.btn-ghost:hover { 
  border-color: var(--text-dim); 
  color: var(--text);
  background: var(--panel);
}

/* ============================================================
   Hero / Sweep Section
   ============================================================ */
.hero {
  padding: 32px 0 24px;
  border-bottom: 1px solid var(--line);
}

.hero-top-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 24px;
  margin-bottom: 20px;
}

.hero-readout { display: flex; flex-direction: column; }

.hero-count {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 52px;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.hero-sep { color: var(--text-dim); margin: 0 4px; }
#heroTarget { color: var(--text-muted); }

.hero-caption {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 12.5px;
}

.hero-sweep { margin-top: 12px; }

.sweep-track {
  position: relative;
  height: 2px;
  background: var(--line);
  border-radius: 1px;
  overflow: hidden;
}

.sweep-fill {
  position: absolute; 
  inset: 0 auto 0 0;
  width: 0%;
  background: var(--signal);
  border-radius: 1px;
  transition: width .5s ease;
}

.sweep-pulse {
  position: absolute; 
  top: 0; 
  bottom: 0; 
  left: 0;
  width: 120px;
  background: linear-gradient(90deg, transparent, rgba(245, 158, 11, 0.3), transparent);
  opacity: 0;
}

.sweep-pulse.active {
  opacity: 1;
  animation: sweep 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes sweep {
  0%   { transform: translateX(-120px); }
  100% { transform: translateX(1280px); }
}

.hero-meta {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}

.meta-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 8px 16px;
  border-radius: var(--radius);
  min-width: 120px;
}

.meta-label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.meta-value { 
  font-size: 13px; 
  font-weight: 500; 
  color: var(--text);
}

.meta-value.mono { font-family: var(--font-mono); }

/* ============================================================
   Workspace Grid Layout
   ============================================================ */
.workspace {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
  padding: 24px 0;
  align-items: start;
}

.sidebar-panels {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

.panel-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* Run Scan Controls */
.preset-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.preset {
  background: var(--panel-raised);
  border: 1px solid var(--line);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 8px 0;
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s ease;
}

.preset:hover { 
  border-color: var(--text-dim); 
  color: var(--text);
}

.preset.selected {
  border-color: var(--signal);
  background: var(--signal-dim);
  color: var(--signal);
}

.custom-row { margin-bottom: 12px; }

.custom-row input {
  width: 100%;
  background: var(--panel-raised);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  transition: all .15s ease;
}

.custom-row input:focus { 
  outline: none;
  border-color: var(--signal);
  box-shadow: 0 0 0 1px var(--signal);
}

.action-row { display: flex; gap: 8px; }

.btn-primary, .btn-danger {
  flex: 1;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 0;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s ease;
}

.btn-primary { 
  background: var(--text); 
  color: var(--bg); 
}

.btn-primary:hover:not(:disabled) { 
  background: transparent;
  border-color: var(--text);
  color: var(--text);
}

.btn-primary:disabled { 
  opacity: .2; 
  cursor: not-allowed; 
  background: var(--text);
}

.btn-danger { 
  background: transparent; 
  border: 1px solid var(--line); 
  color: var(--text-muted); 
}

.btn-danger:hover:not(:disabled) { 
  border-color: var(--danger); 
  color: var(--danger);
  background: rgba(239, 68, 68, 0.05);
}

.btn-danger:disabled { 
  opacity: .2; 
  cursor: not-allowed; 
}

/* Premium Stat Cards Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.metric-card {
  background: var(--panel-raised);
  border: 1px solid var(--line);
  padding: 12px;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric-card dt {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 500;
}

.metric-card dd {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

/* Providers Status Cards */
.provider-list { display: flex; flex-direction: column; gap: 8px; }

.provider-row {
  background: var(--panel-raised);
  border: 1px solid var(--line);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
}

.provider-row .p-name { display: flex; align-items: center; gap: 8px; }
.provider-row .p-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-dim); }
.provider-row.active .p-dot { background: var(--confirmed); box-shadow: 0 0 8px var(--confirmed); }
.provider-row.exhausted .p-dot { background: var(--danger); }
.provider-row .p-usage { font-family: var(--font-mono); color: var(--text-muted); font-size: 12px; }
.provider-row.exhausted { border-color: rgba(239, 68, 68, 0.15); }
.provider-row.exhausted .p-usage { color: var(--danger); }

/* ---- Live Log Terminal ---- */
.log-panel { 
  display: flex; 
  flex-direction: column; 
  height: 100%;
  min-height: 480px; 
}

.log-scroll {
  flex: 1;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.8;
  background: var(--panel-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
}

.log-empty { color: var(--text-dim); text-align: center; margin-top: 24px; }

.log-line {
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
  padding: 2px 0;
  border-bottom: 1px solid transparent;
}

.log-line .ts { color: var(--text-dim); margin-right: 10px; }
.log-line.level-ERROR { color: var(--danger); background: rgba(239, 68, 68, 0.03); }
.log-line.type-match { color: var(--confirmed); }

/* ============================================================
   Leads Data Table Block
   ============================================================ */
.leads-panel { margin-bottom: 40px; }

.leads-header {
  display: flex; 
  justify-content: space-between; 
  align-items: center;
  margin-bottom: 16px;
}

.leads-count { 
  font-family: var(--font-mono); 
  font-size: 11.5px; 
  color: var(--text-muted); 
  background: var(--panel-raised);
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.table-scroll { 
  overflow-x: auto; 
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-raised);
}

.leads-table { 
  width: 100%; 
  border-collapse: collapse; 
  font-size: 12.5px; 
  text-align: left;
}

.leads-table th {
  background: var(--panel);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  font-weight: 600;
}

.leads-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

.leads-table tr:last-child td { border-bottom: none; }
.leads-table tr:hover td { background: rgba(255, 255, 255, 0.01); }

.leads-table .id-cell, 
.leads-table .rating-cell { 
  font-family: var(--font-mono); 
  white-space: nowrap; 
}

.leads-table .rating-cell { color: var(--signal); font-weight: 500; }
.leads-table .title-cell a { color: var(--text); text-decoration: none; font-weight: 500; }
.leads-table .title-cell a:hover { color: var(--accent); }
.leads-table .sub-cell { color: var(--text-muted); font-family: var(--font-mono); white-space: nowrap; }
.leads-table .time-cell { color: var(--text-dim); font-family: var(--font-mono); white-space: nowrap; }
.empty-row td { color: var(--text-dim); text-align: center; padding: 48px 0; }

/* ============================================================
   Interactive Feedback Toast
   ============================================================ */
.toast {
  position: fixed;
  bottom: 24px; 
  left: 50%;
  transform: translate(-50%, 12px);
  background: var(--panel-raised);
  border: 1px solid var(--text-dim);
  color: var(--text);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ============================================================
   Mobile First Responsive Infrastructure
   ============================================================ */
@media (max-width: 920px) {
  .workspace { grid-template-columns: 1fr; gap: 20px; }
  .hero-top-row { flex-direction: column; align-items: flex-start; gap: 16px; }
  .hero-meta { width: 100%; display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .meta-item { min-width: 0; }
}

@media (max-width: 640px) {
  .app { padding: 0 16px 48px; }
  .hero-count { font-size: 40px; }
  
  /* Desktop Table to Mobile Responsive Layout Conversion */
  .table-scroll { border: none; background: transparent; }
  .leads-table, .leads-table thead, .leads-table tbody, .leads-table tr, .leads-table td { 
    display: block; 
    width: 100%; 
  }
  .leads-table thead { display: none; }
  .leads-table tr {
    background: var(--panel-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
  }
  .leads-table tr.empty-row { padding: 32px 16px; }
  .leads-table td {
    padding: 6px 0;
    border: none;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
  }
  .leads-table td::before {
    content: attr(data-label);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-dim);
    font-weight: 600;
    margin-right: 16px;
    flex-shrink: 0;
  }
  .leads-table .title-cell { flex-direction: column; gap: 4px; }
  .leads-table .title-cell::before { content: "Title"; }
  .leads-table .title-cell a { display: block; text-align: left; }
}


@media (max-width: 640px) {
  .app { 
    padding: 0 12px 48px; 
    overflow-x: hidden; /* Prevents outer structural leaks */
  }
  
  .hero-count { 
    font-size: 36px; 
  }

  .topbar {
    flex-wrap: wrap;
    gap: 12px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .btn-ghost {
    flex: 1;
    text-align: center;
    padding: 6px 4px;
    font-size: 11px;
  }
  
  /* Full Mobile Reset for Data Layouts */
  .table-scroll { 
    border: none; 
    background: transparent; 
    overflow-x: hidden;
  }
  
  .leads-table, 
  .leads-table thead, 
  .leads-table tbody, 
  .leads-table tr, 
  .leads-table td { 
    display: block; 
    width: 100% !important; 
    box-sizing: border-box;
  }
  
  .leads-table thead { 
    display: none; 
  }
  
  .leads-table tr {
    background: var(--panel-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 12px;
    word-break: break-word; /* Prevents overflow from ultra-long titles */
  }
  
  .leads-table tr.empty-row { 
    padding: 32px 12px; 
  }
  
  .leads-table td {
    padding: 6px 0;
    border: none;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
  }
  
  /* Forces the mobile cell layout logic */
  .leads-table td::before {
    content: attr(data-label);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-dim);
    font-weight: 600;
    flex-shrink: 0;
  }
  
  .leads-table .title-cell { 
    flex-direction: column; 
    align-items: flex-start;
    gap: 4px; 
  }
  .leads-table .title-cell::before { 
    content: "Title"; 
  }
  .leads-table .title-cell a { 
    display: block; 
    text-align: left; 
    word-break: break-word;
    max-width: 100%;
  }

  /* Structural adjustment for the inner elements */
  .leads-table .id-cell::before { content: "ID"; }
  .leads-table .rating-cell::before { content: "Rating"; }
  .leads-table .sub-cell::before { content: "Subreddit"; }
  .leads-table td:nth-child(5)::before { content: "Platform"; }
  .leads-table .time-cell::before { content: "Found"; }
}