:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #3b82f6;
  --primary-2: #2563eb;
  --danger: #dc2626;
  --ok: #16a34a;
  --bad: #b91c1c;
  --match: #ecfdf5;
  --no-match: #fef2f2;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

body.dark {
  --bg: #0f172a;
  --panel: #111827;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: #334155;
  --primary: #60a5fa;
  --primary-2: #3b82f6;
  --danger: #ef4444;
  --ok: #22c55e;
  --bad: #f87171;
  --match: #052e1d;
  --no-match: #3b0a0a;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  width: min(1500px, 96%);
  margin: 24px auto 48px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
}

.topbar h1 {
  margin: 0 0 6px;
  font-size: 2rem;
}

.topbar p { margin: 0; color: var(--muted); }

.panel { margin-bottom: 20px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.controls-grid, .analysis-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.metric-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.metric-card span { color: var(--muted); display: block; margin-bottom: 6px; }
.metric-card strong { font-size: 1.8rem; }

label {
  display: block;
  margin: 12px 0 6px;
  font-weight: 600;
}

input[type="file"], input[type="text"], select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}

.info {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.95rem;
}

.button-row, .results-toolbar, .pagination, .toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.results-toolbar {
  justify-content: space-between;
  margin-bottom: 14px;
}

.pagination {
  margin-bottom: 12px;
}

.page-size-label {
  margin: 0 0 0 10px;
}

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.btn.primary:hover { background: var(--primary-2); }
.btn.danger {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}
.btn.secondary {
  background: transparent;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1100px;
}

th, td {
  border-bottom: 1px solid var(--border);
  padding: 12px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
}

.row-match { background: var(--match); }
.row-no-match { background: var(--no-match); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.9rem;
}
.badge-ok {
  background: rgba(34, 197, 94, 0.15);
  color: var(--ok);
}
.badge-bad {
  background: rgba(239, 68, 68, 0.15);
  color: var(--bad);
}

.chart-wrap {
  margin-top: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
}

.stats-desc { margin: 0 0 12px; color: var(--muted); font-size: 0.9rem; }
.stats-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}
.stats-controls select { max-width: 280px; }
.stats-results {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
}
.stat-item {
  background: rgba(37, 99, 235, 0.08);
  border: 1px solid rgba(37, 99, 235, 0.2);
  border-radius: 12px;
  padding: 12px 14px;
}
.stat-item span { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.stat-item strong { font-size: 1.2rem; }
body.dark .stat-item {
  background: rgba(96, 165, 250, 0.1);
  border-color: rgba(96, 165, 250, 0.25);
}

.search-highlight {
  background: rgba(255, 193, 7, 0.45);
  padding: 1px 4px;
  border-radius: 4px;
  font-weight: 600;
}
body.dark .search-highlight {
  background: rgba(251, 191, 36, 0.4);
}

.toast-container {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
}

.toast {
  min-width: 260px;
  max-width: 340px;
  padding: 12px 14px;
  border-radius: 14px;
  color: white;
  box-shadow: var(--shadow);
  animation: fadeIn 0.2s ease;
}
.toast.success { background: #166534; }
.toast.error { background: #991b1b; }
.toast-title { font-weight: 700; margin-bottom: 4px; }
.toast-message { opacity: 0.95; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 980px) {
  .grid-2, .metrics-grid {
    grid-template-columns: 1fr;
  }
  .topbar {
    flex-direction: column;
  }
}
