/* =============================================
   SMR Deduplication Agent – Design System CSS
   ============================================= */

/* ---- Custom Properties ---- */
:root {
  --bg-deep:       #07091a;
  --bg-mid:        #0d1130;
  --bg-card:       rgba(18, 24, 60, 0.65);
  --bg-card-hover: rgba(22, 30, 72, 0.80);
  --border:        rgba(99, 130, 255, 0.18);
  --border-hover:  rgba(99, 130, 255, 0.4);

  --text-primary:  #e0e7ff;
  --text-muted:    #6b7db3;
  --text-faint:    #3a4870;

  --accent-blue:   #60a5fa;
  --accent-violet: #a78bfa;
  --accent-pink:   #f472b6;
  --accent-teal:   #2dd4bf;
  --accent-amber:  #fbbf24;

  --grad-main:  linear-gradient(135deg, #60a5fa, #a78bfa);
  --grad-warm:  linear-gradient(135deg, #f472b6, #a855f7);
  --grad-teal:  linear-gradient(135deg, #2dd4bf, #60a5fa);
  --grad-amber: linear-gradient(135deg, #fbbf24, #f97316);

  --sidebar-w: 240px;
  --topbar-h:  58px;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --transition: 0.22s cubic-bezier(.4,0,.2,1);
  --shadow-glow: 0 0 24px rgba(96,165,250,0.12), 0 4px 24px rgba(0,0,0,0.5);
}

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;

  /* Subtle animated star-field background */
  background-image:
    radial-gradient(circle at 15% 20%, rgba(96,165,250,0.07) 0%, transparent 50%),
    radial-gradient(circle at 85% 80%, rgba(167,139,250,0.07) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(45,212,191,0.04) 0%, transparent 60%);
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(99,130,255,0.25); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: rgba(99,130,255,0.45); }

/* ---- Typography ---- */
h1 { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.02em; background: var(--grad-main); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
h3 { font-size: 1rem; font-weight: 600; color: var(--text-primary); margin-bottom: 1rem; }
p  { color: var(--text-muted); line-height: 1.6; font-size: 0.875rem; }
small { font-size: 0.75rem; color: var(--text-muted); }
code { font-family: 'JetBrains Mono', monospace; background: rgba(99,130,255,0.12); padding: 2px 6px; border-radius: 4px; font-size: 0.8em; color: var(--accent-blue); }

/* ========================
   SIDEBAR
   ======================== */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: rgba(13,17,48,0.85);
  backdrop-filter: blur(20px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
}

.logo-icon {
  width: 42px; height: 42px;
  background: rgba(96,165,250,0.1);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid rgba(96,165,250,0.2);
  flex-shrink: 0;
}

.logo-text { display: flex; flex-direction: column; }
.logo-brand { font-size: 1rem; font-weight: 800; background: var(--grad-main); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; line-height: 1.2; }
.logo-sub { font-size: 0.6rem; color: var(--text-muted); font-weight: 500; letter-spacing: 0.05em; }

.sidebar-nav {
  flex: 1;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  width: 100%;
}

.nav-item:hover {
  background: rgba(99,130,255,0.1);
  color: var(--text-primary);
}

.nav-item.active {
  background: linear-gradient(135deg, rgba(96,165,250,0.18), rgba(167,139,250,0.18));
  color: var(--accent-blue);
  border: 1px solid rgba(96,165,250,0.25);
}

.nav-item svg { flex-shrink: 0; }

.sidebar-footer {
  padding: 14px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--grad-main);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }

.user-info { display: flex; flex-direction: column; min-width: 0; }
.user-name { font-size: 0.8rem; font-weight: 600; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-status { font-size: 0.68rem; color: var(--text-muted); }

.btn-auth {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(99,130,255,0.08);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-auth:hover { background: rgba(99,130,255,0.2); border-color: var(--border-hover); }

/* Storage mode badge (sidebar) */
.storage-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  width: 100%;
  text-align: center;
}
.storage-badge.local {
  background: rgba(251,191,36,0.1);
  border: 1px solid rgba(251,191,36,0.2);
  color: var(--accent-amber);
}
.storage-badge.cloud {
  background: rgba(96,165,250,0.1);
  border: 1px solid rgba(96,165,250,0.2);
  color: var(--accent-blue);
}

/* History mode bar */
.history-mode-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(99,130,255,0.06);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.btn-clear-history {
  padding: 4px 10px;
  border-radius: 99px;
  border: 1px solid rgba(244,114,182,0.25);
  background: rgba(244,114,182,0.07);
  color: var(--accent-pink);
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-clear-history:hover { background: rgba(244,114,182,0.15); }

/* History card top row */
.hc-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.hc-storage {
  font-size: 0.85rem;
  flex-shrink: 0;
  opacity: 0.7;
}

/* ========================
   MAIN CONTENT
   ======================== */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ========================
   TOPBAR
   ======================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 90;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  background: rgba(7,9,26,0.75);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.menu-toggle {
  display: none;
  border: none; background: transparent;
  color: var(--text-muted); cursor: pointer;
}

.topbar-title {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: 99px;
  background: rgba(45,212,191,0.1);
  border: 1px solid rgba(45,212,191,0.25);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-teal);
  transition: all var(--transition);
}
.status-pill.running { background: rgba(96,165,250,0.1); border-color: rgba(96,165,250,0.3); color: var(--accent-blue); }
.status-pill.error { background: rgba(244,114,182,0.1); border-color: rgba(244,114,182,0.3); color: var(--accent-pink); }

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent-teal);
  animation: pulse-dot 2s infinite;
}
.status-pill.running .status-dot { background: var(--accent-blue); }
.status-pill.error .status-dot { background: var(--accent-pink); animation: none; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.75); }
}

/* ========================
   TAB PANELS
   ======================== */
.tab-panel {
  display: none;
  flex: 1;
  padding: 28px 28px 48px;
  animation: fadeSlide 0.3s ease;
}
.tab-panel.active { display: block; }

@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.page-header {
  margin-bottom: 24px;
}
.page-header p { margin-top: 4px; }

/* ========================
   GLASS CARD
   ======================== */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-glow);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.glass-card:hover {
  border-color: var(--border-hover);
  box-shadow: 0 0 32px rgba(96,165,250,0.18), 0 4px 24px rgba(0,0,0,0.5);
}

/* ========================
   STATS GRID
   ======================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all var(--transition);
  cursor: default;
}
.stat-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(0,0,0,0.4), 0 0 20px rgba(96,165,250,0.1);
}

.stat-icon {
  width: 46px; height: 46px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sessions-icon { background: rgba(96,165,250,0.12); color: var(--accent-blue); }
.input-icon    { background: rgba(167,139,250,0.12); color: var(--accent-violet); }
.unique-icon   { background: rgba(45,212,191,0.12);  color: var(--accent-teal); }
.removed-icon  { background: rgba(244,114,182,0.12); color: var(--accent-pink); }

.stat-body { display: flex; flex-direction: column; }
.stat-value {
  font-size: 1.7rem;
  font-weight: 800;
  background: var(--grad-main);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.2;
  transition: all 0.5s ease;
}
.stat-label { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; margin-top: 2px; }

/* ========================
   CHART ROW
   ======================== */
.chart-row {
  display: grid;
  grid-template-columns: 200px 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

/* Donut */
.chart-card { display: flex; flex-direction: column; align-items: center; }
.donut-wrapper { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.donut-chart { filter: drop-shadow(0 0 12px rgba(96,165,250,0.15)); }
.donut-ring { transition: stroke-dasharray 0.8s ease; }
.donut-label { font-family: 'Inter', sans-serif; }
.donut-legend { display: flex; flex-direction: column; gap: 6px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 0.75rem; color: var(--text-muted); }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

/* Method bars */
.method-bars { display: flex; flex-direction: column; gap: 10px; }
.method-bar-row { display: flex; flex-direction: column; gap: 4px; }
.method-bar-meta { display: flex; justify-content: space-between; font-size: 0.75rem; }
.method-bar-label { color: var(--text-muted); }
.method-bar-count { color: var(--text-primary); font-weight: 600; }
.method-bar-track { height: 6px; background: rgba(99,130,255,0.12); border-radius: 99px; overflow: hidden; }
.method-bar-fill { height: 100%; border-radius: 99px; background: var(--grad-main); transition: width 0.8s cubic-bezier(0.34,1.56,0.64,1); }

/* How list */
.how-list { list-style: none; display: flex; flex-direction: column; gap: 14px; }
.how-list li { display: flex; align-items: flex-start; gap: 12px; }
.step-badge {
  min-width: 28px; height: 28px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700;
  flex-shrink: 0;
}
.step-badge.doi   { background: rgba(96,165,250,0.15); color: var(--accent-blue); }
.step-badge.pmid  { background: rgba(167,139,250,0.15); color: var(--accent-violet); }
.step-badge.exact { background: rgba(45,212,191,0.15);  color: var(--accent-teal); }
.step-badge.fuzzy { background: rgba(251,191,36,0.15);  color: var(--accent-amber); }
.how-list strong { font-size: 0.8rem; color: var(--text-primary); }

/* Recent sessions */
.recent-card { margin-top: 0; }
.session-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(99,130,255,0.08);
  cursor: pointer;
  transition: background var(--transition);
  border-radius: var(--radius-sm);
}
.session-row:last-child { border-bottom: none; }
.session-row:hover { background: rgba(99,130,255,0.06); padding-left: 8px; }
.session-name { flex: 1; font-size: 0.85rem; font-weight: 600; color: var(--text-primary); }
.session-meta { font-size: 0.72rem; color: var(--text-muted); }
.session-badge { font-size: 0.7rem; font-weight: 700; padding: 3px 8px; border-radius: 99px; }
.session-badge.ok { background: rgba(45,212,191,0.12); color: var(--accent-teal); }

/* ========================
   UPLOAD ZONE
   ======================== */
.upload-zone {
  border: 2px dashed rgba(99,130,255,0.3);
  border-radius: var(--radius-lg);
  padding: 48px 32px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
}
.upload-zone::before {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 50%, rgba(96,165,250,0.04) 0%, transparent 70%);
  pointer-events: none;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: rgba(96,165,250,0.7);
  background: rgba(96,165,250,0.05);
  box-shadow: 0 0 40px rgba(96,165,250,0.12);
}
.upload-icon-wrap {
  margin: 0 auto 14px;
  width: 72px; height: 72px;
  border-radius: 18px;
  background: rgba(96,165,250,0.1);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.upload-zone:hover .upload-icon-wrap { transform: translateY(-4px); background: rgba(96,165,250,0.15); }
.upload-label { font-size: 1rem; font-weight: 600; color: var(--text-primary); margin-bottom: 6px; }
.upload-browse { color: var(--accent-blue); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.upload-sublabel { font-size: 0.78rem; color: var(--text-muted); }

/* File Queue */
.file-queue {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  animation: fadeSlide 0.2s ease;
}
.file-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.65rem; font-weight: 700; font-family: 'JetBrains Mono', monospace;
  flex-shrink: 0;
}
.ext-ris  { background: rgba(96,165,250,0.15); color: var(--accent-blue); }
.ext-bib  { background: rgba(167,139,250,0.15); color: var(--accent-violet); }
.ext-txt, .ext-nbib { background: rgba(45,212,191,0.15); color: var(--accent-teal); }
.ext-csv  { background: rgba(251,191,36,0.15); color: var(--accent-amber); }
.ext-other { background: rgba(244,114,182,0.15); color: var(--accent-pink); }

.file-info { flex: 1; min-width: 0; }
.file-name { font-size: 0.82rem; font-weight: 600; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { font-size: 0.7rem; color: var(--text-muted); }
.file-remove {
  border: none; background: transparent;
  color: var(--text-faint); cursor: pointer;
  transition: color var(--transition);
  padding: 4px;
  border-radius: 6px;
}
.file-remove:hover { color: var(--accent-pink); background: rgba(244,114,182,0.1); }

/* Run Card */
.run-card { margin-bottom: 20px; }
.run-options {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 18px;
}
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field label { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.form-field input {
  padding: 10px 14px;
  background: rgba(7,9,26,0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.875rem;
  outline: none;
  transition: all var(--transition);
}
.form-field input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(96,165,250,0.12);
}
.form-field input::placeholder { color: var(--text-faint); }

.btn-run {
  width: 100%;
  padding: 14px 24px;
  background: var(--grad-main);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  display: flex; align-items: center; justify-content: center; gap: 8px;
  letter-spacing: 0.02em;
  position: relative;
  overflow: hidden;
}
.btn-run::after {
  content: '';
  position: absolute; inset: 0;
  background: rgba(255,255,255,0);
  transition: background var(--transition);
}
.btn-run:hover:not(:disabled)::after { background: rgba(255,255,255,0.08); }
.btn-run:active:not(:disabled) { transform: scale(0.98); }
.btn-run:disabled { opacity: 0.4; cursor: not-allowed; }

/* Progress */
.progress-title { margin-bottom: 14px; }
.progress-bar-wrap {
  height: 8px;
  background: rgba(99,130,255,0.12);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 14px;
}
.progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: var(--grad-main);
  /* NO transition — RAF drives the animation directly.
     CSS transition + RAF causes cascading reflows that block clicks. */
  box-shadow: 0 0 10px rgba(96,165,250,0.5);
  position: relative;
  overflow: hidden;
}

/* Shimmer overlay — visible while .processing is active */
.progress-bar.processing::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    100deg,
    transparent 20%,
    rgba(255,255,255,0.22) 50%,
    transparent 80%
  );
  background-size: 200% 100%;
  animation: shimmer-slide 1.4s linear infinite;
}

@keyframes shimmer-slide {
  0%   { background-position: 200% center; }
  100% { background-position: -200% center; }
}
.progress-log {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  color: var(--text-muted);
  max-height: 180px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.log-line { display: flex; gap: 10px; }
.log-time { color: var(--text-faint); flex-shrink: 0; }
.log-msg { color: var(--text-muted); }
.log-msg.success { color: var(--accent-teal); }
.log-msg.warn { color: var(--accent-amber); }
.log-msg.error { color: var(--accent-pink); }

/* ========================
   RESULTS
   ======================== */
.results-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.result-mini {
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  text-align: center;
}
.result-mini .rval {
  font-size: 1.5rem; font-weight: 800;
  display: block;
  background: var(--grad-main);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.result-mini .rlabel { font-size: 0.7rem; color: var(--text-muted); }

.file-results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.file-result-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  transition: all var(--transition);
}
.file-result-card:hover { border-color: var(--border-hover); transform: translateY(-2px); }

.frc-header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.frc-name { font-size: 0.82rem; font-weight: 700; color: var(--text-primary); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.frc-format { font-size: 0.65rem; font-weight: 600; padding: 2px 7px; border-radius: 99px; background: rgba(96,165,250,0.1); color: var(--accent-blue); }

.frc-bar-label { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--text-muted); margin-bottom: 5px; }
.frc-bar-track { height: 6px; background: rgba(99,130,255,0.12); border-radius: 99px; overflow: hidden; margin-bottom: 8px; }
.frc-bar-fill  { height: 100%; border-radius: 99px; background: var(--grad-teal); transition: width 0.8s cubic-bezier(0.34,1.56,0.64,1); }
.frc-stats { display: flex; gap: 14px; font-size: 0.72rem; }
.frc-stat { color: var(--text-muted); }
.frc-stat strong { color: var(--text-primary); }

/* ========================
   MERGED DOWNLOAD CARD
   ======================== */
.merged-download-card {
  margin-bottom: 16px;
  border-color: rgba(96,165,250,0.35) !important;
  background: linear-gradient(135deg, rgba(96,165,250,0.07), rgba(167,139,250,0.07)) !important;
}

.merged-header {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 12px;
}

.merged-tip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
  background: rgba(99,130,255,0.07);
  border: 1px solid rgba(99,130,255,0.12);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin-bottom: 16px;
}
.merged-tip svg { flex-shrink: 0; color: var(--accent-blue); }

.merged-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-download-merged {
  flex: 1;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 20px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.btn-download-merged svg {
  position: absolute;
  top: 14px; left: 16px;
}

.btn-download-merged.ris {
  background: var(--grad-main);
  color: #fff;
  box-shadow: 0 4px 20px rgba(96,165,250,0.3);
}
.btn-download-merged.ris:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(96,165,250,0.45);
}

.btn-download-merged.csv {
  background: rgba(45,212,191,0.1);
  border-color: rgba(45,212,191,0.3);
  color: var(--accent-teal);
}
.btn-download-merged.csv:hover {
  background: rgba(45,212,191,0.18);
  border-color: rgba(45,212,191,0.5);
  transform: translateY(-2px);
}

.fmt-badge {
  font-size: 0.68rem;
  font-weight: 500;
  opacity: 0.8;
}

/* Per-file download button */
.btn-dl-file {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 10px;
  padding: 6px 12px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: rgba(99,130,255,0.07);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  width: 100%;
  justify-content: center;
}
.btn-dl-file:hover {
  border-color: var(--accent-blue);
  color: var(--accent-blue);
  background: rgba(96,165,250,0.1);
}

/* Flagged panel */
.flagged-panel { margin-top: 0; }
.flagged-row {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(99,130,255,0.07);
  display: flex; flex-direction: column; gap: 4px;
}
.flagged-row:last-child { border-bottom: none; }
.flagged-title { font-size: 0.8rem; color: var(--text-primary); line-height: 1.4; }
.flagged-matched { font-size: 0.73rem; color: var(--text-muted); }
.flagged-meta { display: flex; gap: 10px; font-size: 0.7rem; }
.conf-badge { padding: 2px 7px; border-radius: 99px; font-weight: 600; }
.conf-high { background: rgba(45,212,191,0.1); color: var(--accent-teal); }
.conf-med  { background: rgba(251,191,36,0.1); color: var(--accent-amber); }
.conf-low  { background: rgba(244,114,182,0.1); color: var(--accent-pink); }

/* ========================
   AUDIT LOG
   ======================== */
.audit-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.search-wrap {
  flex: 1;
  min-width: 200px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: border-color var(--transition);
}
.search-wrap:focus-within { border-color: var(--accent-blue); }
.search-wrap input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
}
.search-wrap input::placeholder { color: var(--text-faint); }

.filter-group { display: flex; gap: 4px; }
.filter-btn {
  padding: 7px 14px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.filter-btn:hover { border-color: var(--border-hover); color: var(--text-primary); }
.filter-btn.active { background: var(--grad-main); border-color: transparent; color: #fff; }

.btn-export {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(99,130,255,0.08);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  display: flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.btn-export:hover:not(:disabled) { border-color: var(--accent-blue); color: var(--accent-blue); }
.btn-export:disabled { opacity: 0.4; cursor: not-allowed; }

.audit-table-wrap { overflow-x: auto; }

.audit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.audit-table th {
  padding: 10px 12px;
  text-align: left;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.audit-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(99,130,255,0.06);
  vertical-align: top;
  color: var(--text-muted);
}
.audit-table tr:hover td { background: rgba(99,130,255,0.04); }
.audit-table .empty-cell { text-align: center; padding: 32px; color: var(--text-faint); }

.action-badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 0.68rem; font-weight: 700; }
.action-badge.removed  { background: rgba(244,114,182,0.12); color: var(--accent-pink); }
.action-badge.kept     { background: rgba(45,212,191,0.12);  color: var(--accent-teal); }
.action-badge.flagged  { background: rgba(251,191,36,0.12);  color: var(--accent-amber); }

.method-pill { background: rgba(99,130,255,0.1); color: var(--accent-blue); padding: 2px 7px; border-radius: 99px; font-size: 0.68rem; font-weight: 700; font-family: 'JetBrains Mono', monospace; }

.conf-bar { display: flex; align-items: center; gap: 6px; }
.conf-num { font-family: 'JetBrains Mono', monospace; font-size: 0.72rem; }
.mini-bar { flex: 1; height: 4px; background: rgba(99,130,255,0.1); border-radius: 99px; max-width: 60px; overflow: hidden; }
.mini-bar-fill { height: 100%; border-radius: 99px; background: var(--grad-main); }

.audit-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding-top: 14px;
  flex-wrap: wrap;
}
.page-btn {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.page-btn:hover { border-color: var(--accent-blue); color: var(--accent-blue); }
.page-btn.active { background: var(--grad-main); border-color: transparent; color: #fff; }

/* ========================
   HISTORY
   ======================== */
.history-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }

.history-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  cursor: pointer;
  transition: all var(--transition);
}
.history-card:hover { border-color: var(--border-hover); transform: translateY(-2px); box-shadow: 0 8px 30px rgba(0,0,0,0.3); }
.hc-name { font-size: 0.9rem; font-weight: 700; color: var(--text-primary); margin-bottom: 4px; }
.hc-date { font-size: 0.72rem; color: var(--text-muted); margin-bottom: 12px; }
.hc-stats { display: flex; gap: 14px; font-size: 0.75rem; }
.hc-stat { display: flex; flex-direction: column; }
.hc-stat .v { font-weight: 700; color: var(--text-primary); }
.hc-stat .k { color: var(--text-muted); font-size: 0.68rem; }

/* ========================
   EMPTY STATES
   ======================== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 80px 20px;
  text-align: center;
}
.empty-state p { font-size: 0.9rem; }
.empty-state-small { color: var(--text-faint); font-size: 0.8rem; text-align: center; padding: 20px 0; }

/* ========================
   TOAST
   ======================== */
.toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: rgba(22,30,72,0.95);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-primary);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  animation: toast-in 0.3s ease;
}
.toast.success { border-color: rgba(45,212,191,0.3); }
.toast.error   { border-color: rgba(244,114,182,0.3); }
.toast.warn    { border-color: rgba(251,191,36,0.3); }
.toast-icon { font-size: 1rem; flex-shrink: 0; }
.toast-out { animation: toast-out 0.3s ease forwards; }

@keyframes toast-in  { from { opacity:0; transform: translateY(12px); } to { opacity:1; transform: translateY(0); } }
@keyframes toast-out { from { opacity:1; transform: translateY(0); } to { opacity:0; transform: translateY(12px); } }

/* ========================
   UTILITY
   ======================== */
[hidden] { display: none !important; }

/* ========================
   RESPONSIVE
   ======================== */
@media (max-width: 900px) {
  :root { --sidebar-w: 0px; }
  .sidebar {
    transform: translateX(-240px);
    width: 240px;
  }
  .sidebar.open {
    transform: translateX(0);
    --sidebar-w: 240px;
  }
  .main-content { margin-left: 0; }
  .menu-toggle { display: flex; }
  .chart-row { grid-template-columns: 1fr; }
  .run-options { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .tab-panel { padding: 16px 14px 40px; }
  .topbar { padding: 0 14px; }
  h1 { font-size: 1.3rem; }
}
