/* Premium Scraper — Dark Theme */
:root {
  --bg-base:    #05050f;
  --bg-card:    rgba(255,255,255,0.03);
  --bg-input:   #0f1724;
  --border:     rgba(255,255,255,0.06);
  --border-alt: rgba(99,102,241,0.2);
  --accent:     #6366f1;
  --accent-2:   #818cf8;
  --green:      #34d399;
  --yellow:     #fbbf24;
  --red:        #f87171;
  --text:       #e2e8f0;
  --text-muted: #64748b;
  --text-dim:   #94a3b8;
  --sidebar-w:  220px;
  --radius:     14px;
  --radius-sm:  8px;
}

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

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

.bg-orb {
  position: fixed;
  border-radius: 999px;
  filter: blur(65px);
  opacity: 0.25;
  z-index: -1;
  pointer-events: none;
}
.bg-orb-1 {
  width: 360px;
  height: 360px;
  background: #6366f1;
  top: -120px;
  right: -80px;
}
.bg-orb-2 {
  width: 420px;
  height: 420px;
  background: #14b8a6;
  bottom: -220px;
  left: -120px;
}

/* ── Layout ─────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: linear-gradient(180deg, rgba(7,10,31,0.95), rgba(5,5,20,0.92));
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 100;
  backdrop-filter: blur(20px);
}

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 32px;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.topbar-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.topbar-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  max-width: 760px;
}

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

/* ── Sidebar ─────────────────────────────────────────── */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px;
  border-bottom: 1px solid var(--border);
}
.logo-icon { font-size: 22px; }
.logo-text { font-weight: 700; font-size: 15px; color: var(--text); }
.sidebar-kicker { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.sidebar-nav {
  flex: 1;
  min-height: 0;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.15s;
}
.nav-item:hover { background: rgba(99,102,241,0.08); color: var(--text-dim); }
.nav-item.active { background: rgba(99,102,241,0.15); color: var(--accent-2); }
.nav-icon { font-size: 16px; }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
}
.sidebar-footer-title { font-size: 12px; color: var(--text-dim); font-weight: 600; }
.sidebar-footer-sub { font-size: 11px; color: var(--text-muted); }
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: pulse 2s infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ── Cards ─────────────────────────────────────────── */
.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  backdrop-filter: blur(10px);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.2);
}

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 24px; }
.hero-grid { display:grid; grid-template-columns:2fr 1.3fr; gap:16px; margin-bottom:24px; }
.stat-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.02));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s;
}
.stat-card:hover { border-color: var(--border-alt); }
.stat-card:hover { transform: translateY(-2px); }
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.stat-value { font-size: 32px; font-weight: 800; line-height: 1; }
.stat-hint { font-size: 11px; color: var(--text-muted); margin-top: 6px; }
.stat-icon {
  position: absolute;
  top: 16px; right: 16px;
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}

/* ── Page Header ─────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-title { font-size: 22px; font-weight: 700; }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 3px; }

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
  border: none; cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  color: #fff;
  box-shadow: 0 4px 14px rgba(99,102,241,0.35);
}
.btn-primary:hover { filter: brightness(1.1); box-shadow: 0 6px 20px rgba(99,102,241,0.45); }
.btn:hover { transform: translateY(-1px); }
.btn-danger  { background: rgba(239,68,68,0.15);  color: var(--red);   border: 1px solid rgba(239,68,68,0.25); }
.btn-success { background: rgba(16,185,129,0.15); color: var(--green); border: 1px solid rgba(16,185,129,0.25); }
.btn-ghost   { background: rgba(255,255,255,0.05); color: var(--text-dim); border: 1px solid var(--border); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-icon { padding: 7px; border-radius: 8px; }

/* ── Form ─────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }
.form-control {
  width: 100%; padding: 9px 14px;
  background: var(--bg-input);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.15s;
  outline: none;
}
.form-control:focus { border-color: var(--accent); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ── Table ─────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px 14px; font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid var(--border); }
td { padding: 12px 14px; border-bottom: 1px solid rgba(255,255,255,0.03); color: var(--text-dim); }
tr:hover td { background: rgba(255,255,255,0.02); }
tr:last-child td { border-bottom: none; }

/* ── Badges ─────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.badge-completed { background: rgba(16,185,129,0.12); color: var(--green); }
.badge-running   { background: rgba(245,158,11,0.12); color: var(--yellow); }
.badge-failed    { background: rgba(239,68,68,0.12);  color: var(--red); }
.badge-pending   { background: rgba(148,163,184,0.12);color: var(--text-dim); }
.badge-cancelled { background: rgba(148,163,184,0.12);color: var(--text-muted); }

/* ── Progress ─────────────────────────────────────────── */
.progress-bar { height: 5px; background: rgba(255,255,255,0.05); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 3px; transition: width 0.4s; }

/* ── Loading ─────────────────────────────────────────── */
.loading-spinner { display: flex; justify-content: center; align-items: center; height: 200px; }
.spinner { width: 36px; height: 36px; border: 3px solid rgba(99,102,241,0.2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ─────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 9999; }
.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  backdrop-filter: blur(20px);
  animation: slideIn 0.25s ease;
  max-width: 320px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
}
.toast-success { background: rgba(16,185,129,0.2); border: 1px solid rgba(16,185,129,0.3); color: var(--green); }
.toast-error   { background: rgba(239,68,68,0.2);  border: 1px solid rgba(239,68,68,0.3);  color: var(--red); }
.toast-info    { background: rgba(99,102,241,0.2); border: 1px solid rgba(99,102,241,0.3); color: var(--accent-2); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Misc ─────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 60px 20px; text-align: center;
  color: var(--text-muted);
}
.empty-icon { font-size: 48px; margin-bottom: 16px; }
.empty-title { font-size: 16px; font-weight: 600; color: var(--text-dim); margin-bottom: 8px; }
.empty-sub { font-size: 13px; color: var(--text-muted); }

.chip {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(99,102,241,0.1);
  border: 1px solid rgba(99,102,241,0.15);
  color: var(--accent-2);
  border-radius: 20px;
  font-size: 11px;
  margin: 2px;
}

.detail-grid {
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:12px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.admin-tile {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 12px;
  padding: 16px;
}

.admin-tile-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.admin-tile-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
}

.download-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}

.download-script-output {
  width: 100%;
  min-height: 240px;
  margin-top: 12px;
  background: #050914;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  color: #cbd5e1;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  resize: vertical;
}

.download-preview {
  margin-top: 12px;
}

.download-preview-item {
  padding: 8px 10px;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 12px;
  color: #94a3b8;
  background: rgba(255,255,255,0.02);
}

/* Data View (Phase 1–2 toolbar) */
.dv-card {
  margin-bottom: 16px;
}

.dv-toolbar {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px 14px;
  align-items: end;
}

.dv-field .form-label {
  font-size: 11px;
}

.dv-field-wide {
  grid-column: 1 / -1;
}

.dv-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.dv-hint {
  margin-top: 12px;
  margin-bottom: 0;
}

.dv-stats {
  margin-bottom: 12px;
}

.dv-stats-inner {
  font-size: 13px;
  line-height: 1.5;
  color: #e2e8f0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(15,23,42,0.55);
}

.dv-table-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.dv-table-meta {
  font-size: 13px;
  color: #64748b;
  margin: 0;
}

table.dv-table {
  width: 100%;
}

.dv-cell-title {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dv-cell-embed {
  max-width: 240px;
}

.dv-cell-tags {
  max-width: 180px;
}

.dv-cell-time {
  font-size: 11px;
  white-space: nowrap;
}

.dv-thumb {
  width: 60px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
}

.dv-link {
  color: #818cf8;
  font-size: 11px;
}

.dv-embed-link {
  color: #34d399;
  font-size: 11px;
  word-break: break-all;
}

.dv-embed-fallback {
  font-size: 11px;
  color: #64748b;
}

.dv-row-highlight {
  background: rgba(16, 185, 129, 0.12);
  box-shadow: inset 0 0 0 1px rgba(16, 185, 129, 0.2);
}

.publish-api-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.publish-api-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.publish-api-label {
  font-size: 12px;
  font-weight: 700;
  color: #e2e8f0;
  margin-bottom: 6px;
}

.publish-api-url {
  display: block;
  font-size: 11px;
  color: #a5b4fc;
  word-break: break-all;
  line-height: 1.45;
}

.batch-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.batch-card {
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 16px;
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02));
}

.batch-card-done {
  border-color: rgba(16,185,129,0.25);
  box-shadow: 0 0 0 1px rgba(16,185,129,0.08) inset;
}

.batch-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.link-inline {
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.link-inline:hover {
  text-decoration: underline;
}

.dupes-row {
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
  background: rgba(255,255,255,0.02);
}

.dupes-row:last-child {
  margin-bottom: 0;
}

.batch-modal {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(920px, calc(100vw - 40px));
  max-height: min(80vh, 900px);
  overflow: auto;
  z-index: 400;
  background: linear-gradient(180deg, rgba(9,12,32,0.98), rgba(3,6,23,0.96));
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.45);
}

.auth-shell {
  min-height: calc(100vh - 56px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  width: min(460px, 100%);
  background: linear-gradient(180deg, rgba(9,12,32,0.96), rgba(4,7,24,0.94));
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 28px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.35);
}

.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 14px;
}

.auth-title {
  font-size: 28px;
  margin-bottom: 8px;
}

.auth-subtitle,
.auth-hint {
  font-size: 13px;
  color: var(--text-muted);
}

.auth-hint {
  margin-top: 14px;
}

.auth-submit {
  width: 100%;
  justify-content: center;
  margin-top: 8px;
}

.auth-error {
  margin-bottom: 16px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.2);
  color: var(--red);
  font-size: 12px;
}

body.auth-mode .sidebar,
body.auth-mode .topbar {
  display: none;
}

body.auth-mode .main-content {
  margin-left: 0;
}

.metric-card {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 12px;
  padding: 14px;
}

.metric-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.metric-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.68);
  z-index: 300;
}

.drawer-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(520px, 100vw);
  height: 100vh;
  overflow-y: auto;
  background: linear-gradient(180deg, rgba(9,12,32,0.98), rgba(3,6,23,0.96));
  border-left: 1px solid rgba(255,255,255,0.08);
  padding: 24px;
  z-index: 301;
  box-shadow: -18px 0 48px rgba(0, 0, 0, 0.35);
}

.log-stream {
  display:flex;
  flex-direction:column;
  gap:8px;
  max-height: 55vh;
  overflow-y:auto;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
}

.log-row {
  display:grid;
  grid-template-columns: 74px 50px 82px 1fr;
  gap:10px;
  border-bottom:1px solid rgba(255,255,255,0.04);
  padding-bottom:8px;
}

.log-time { color:#64748b; }
.log-phase { color:#818cf8; text-transform:capitalize; }
.log-level { text-transform:uppercase; font-size:10px; font-weight:700; }
.log-level-info { color:#60a5fa; }
.log-level-warn { color:#fbbf24; }
.log-level-error { color:#f87171; }
.log-level-debug { color:#94a3b8; }

.toggle {
  position: relative;
  width: 40px; height: 22px;
  cursor: pointer;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; inset: 0;
  background: rgba(255,255,255,0.1);
  border-radius: 11px;
  transition: 0.2s;
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle-track::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  top: 3px; left: 3px;
  transition: 0.2s;
}
.toggle input:checked + .toggle-track::after { transform: translateX(18px); }

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .logo-text, .nav-item span:last-child, .sidebar-footer span { display: none; }
  .main-content { margin-left: 60px; padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .hero-grid, .detail-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; }
  .log-row { grid-template-columns: 1fr; }
}
