/**
 * Version: 2.7.0
 * Description: Visual system for the Thresh in-browser tool. System-font stack with
 *              optional Inter, slate palette, soft shadows, careful spacing. No external
 *              fonts loaded so the tool stays 100% self-contained.
 * Author: Ali Kahwaji
 */

:root {
  --bg: #f8fafc;                /* slate-50 */
  --bg-deep: #f1f5f9;           /* slate-100 */
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #e2e8f0;            /* slate-200 */
  --border-strong: #cbd5e1;     /* slate-300 */

  --text: #0f172a;              /* slate-900 */
  --text-muted: #475569;        /* slate-600 */
  --text-subtle: #64748b;       /* slate-500 */

  --accent: #2563eb;            /* blue-600 */
  --accent-hover: #1d4ed8;      /* blue-700 */
  --accent-soft: #eff6ff;       /* blue-50 */

  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --warning: #d97706;

  --code-bg: #f1f5f9;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 6px -1px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -2px rgba(15, 23, 42, 0.04);

  --font: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Keyboard focus — visible only when focus arrives via keyboard, not mouse */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
[role="tab"]:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Respect "reduce motion" — kill animations/transitions for users who ask */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .progress.indeterminate > .bar { animation: none !important; }
}

/* Screen-reader-only utility (used for skip-to-content if added later) */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

code, .mono { font-family: var(--mono); font-size: 0.85em; }
code {
  padding: 0.1em 0.35em;
  background: var(--code-bg);
  border-radius: 4px;
}

/* ---------- Layout ---------- */

.page {
  max-width: 980px;
  margin: 0 auto;
  padding: 2.25rem 1.5rem 4rem;
}

/* ---------- Site nav ---------- */

.site-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand svg { color: var(--accent); }
.brand .wordmark { letter-spacing: -0.02em; }

.nav-links { display: flex; align-items: center; gap: 1.25rem; }
.nav-links a {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
}
.nav-links a:hover { color: var(--text); text-decoration: none; }

/* ---------- Hero ---------- */

.hero {
  padding: 3rem 0 2.25rem;
  text-align: left;
}
.hero .eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.7rem;
  margin-bottom: 1rem;
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid #bbf7d0;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.hero .eyebrow .dot {
  width: 6px; height: 6px; border-radius: 999px; background: currentColor;
}
.hero h1 {
  margin: 0;
  font-size: 2.5rem;
  line-height: 1.1;
  letter-spacing: -0.03em;
  font-weight: 700;
}
.hero .lede {
  margin: 0.85rem 0 0;
  font-size: 1.15rem;
  color: var(--text-muted);
  max-width: 640px;
  line-height: 1.5;
}
@media (max-width: 640px) {
  .hero h1 { font-size: 2rem; }
  .hero .lede { font-size: 1rem; }
}

/* ---------- Card ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.75rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.card h2 { margin: 0 0 0.4rem; font-size: 1.05rem; font-weight: 600; letter-spacing: -0.005em; }
.card .card-subtitle { margin: 0 0 1.25rem; color: var(--text-muted); font-size: 0.9rem; }

details.card summary {
  cursor: pointer;
  font-size: 1.05rem;
  font-weight: 600;
  list-style: none;
  display: flex; justify-content: space-between; align-items: center;
}
details.card summary::-webkit-details-marker { display: none; }
details.card summary::after {
  content: "▾"; color: var(--text-subtle); font-size: 0.85rem;
  transition: transform 0.15s ease;
}
details.card[open] summary::after { transform: rotate(180deg); }

/* ---------- Rules grid ---------- */

.rules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-top: 1.25rem;
}
.rule {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-deep);
}
.rule strong { display: block; margin-bottom: 0.35rem; font-size: 0.875rem; font-weight: 600; }
.rule span { color: var(--text-muted); font-size: 0.85rem; line-height: 1.5; }

/* ---------- Drop zone ---------- */

.drop-zone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 2.25rem 1rem;
  background: var(--bg-deep);
  text-align: center;
  color: var(--text-subtle);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
.drop-zone p { margin: 0; font-size: 0.95rem; }
.drop-zone .hint { display: block; margin-top: 0.35rem; font-size: 0.8rem; color: var(--text-subtle); }

input[type="file"] { display: none; }

/* ---------- Controls / buttons ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
  align-items: center;
}

button {
  padding: 0.55rem 1.05rem;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  letter-spacing: -0.005em;
}
.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { background: #94a3b8; cursor: not-allowed; box-shadow: none; }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg-deep); border-color: var(--border-strong); }

.btn-danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--border);
}
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }

.btn-ghost {
  background: transparent;
  color: var(--text-subtle);
  border-color: transparent;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
}
.btn-ghost:hover { color: var(--text); background: var(--bg-deep); }

.selected-file { margin-top: 0.5rem; font-size: 0.9rem; color: var(--text-muted); }

/* ---------- Progress ---------- */

.progress {
  margin-top: 0.85rem;
  height: 6px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  display: none;
}
.progress.visible { display: block; }
.progress > .bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.15s ease;
}
.progress.indeterminate > .bar {
  width: 35% !important;
  animation: indet 1.1s ease-in-out infinite;
}
@keyframes indet {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(285%); }
}

.status {
  margin-top: 0.85rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  min-height: 1.25rem;
}
.status.error { color: var(--danger); }
.status.success { color: var(--success); }

/* ---------- Results ---------- */

#results { display: none; }
#results.visible { display: block; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.stat {
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-deep);
}
.stat .value {
  font-size: 1.65rem;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
}
.stat .label {
  font-size: 0.72rem;
  color: var(--text-subtle);
  margin-top: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.stat.warn {
  background: #fffbeb;
  border-color: #fde68a;
}
.stat.warn .value { color: #92400e; }
.stat.warn .label { color: #b45309; }

/* ---------- Tabs ---------- */

.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.tab {
  padding: 0.55rem 0.95rem;
  cursor: pointer;
  background: none;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 500;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  margin-bottom: -1px;
  font-weight: 600;
}
.tab .badge {
  display: inline-block;
  margin-left: 0.45rem;
  padding: 0.05rem 0.45rem;
  font-size: 0.72rem;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-subtle);
  font-weight: 500;
}
.tab[aria-selected="true"] .badge { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.panel-header .grow { flex: 1; }
.panel-header strong { color: var(--text); font-weight: 600; }

/* ---------- CSV preview ---------- */

.table-wrap {
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
table.preview {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  font-family: var(--mono);
}
table.preview thead th {
  position: sticky;
  top: 0;
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border);
  padding: 0.55rem 0.85rem;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  color: var(--text);
}
table.preview tbody td {
  padding: 0.45rem 0.85rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
table.preview tbody tr:nth-child(even) td { background: var(--surface-muted); }
table.preview tbody tr:hover td { background: var(--accent-soft); }

.preview-meta { font-size: 0.8rem; color: var(--text-subtle); margin-top: 0.5rem; }
.preview-empty { padding: 1.25rem; color: var(--text-subtle); font-size: 0.9rem; text-align: center; }

/* ---------- JSON preview ---------- */

pre.json-preview {
  max-height: 360px;
  overflow: auto;
  margin: 0;
  padding: 0.95rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--code-bg);
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.55;
}

/* ---------- History ---------- */

/* ---------- Rules editor ---------- */

.rules-editor {
  width: 100%;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.55;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--code-bg);
  color: var(--text);
  resize: vertical;
  min-height: 220px;
}
.rules-editor:focus {
  border-color: var(--accent);
  outline: none;
  background: var(--surface);
}
.rules-status {
  margin-top: 0.65rem;
  font-size: 0.85rem;
  min-height: 1.1rem;
  color: var(--text-subtle);
  font-family: var(--mono);
}
.rules-status.error { color: var(--danger); }
.rules-status.success { color: var(--success); }
.rules-pill {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.1rem 0.5rem;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-subtle);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.rules-pill.custom {
  background: var(--accent-soft);
  border-color: rgba(37, 99, 235, 0.25);
  color: var(--accent);
}

.history-list { display: flex; flex-direction: column; gap: 0.5rem; }
.history-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.7rem;
  padding: 0.65rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-deep);
  font-size: 0.88rem;
}
.history-row .name { font-weight: 600; flex: 1; min-width: 140px; color: var(--text); }
.history-row .meta { color: var(--text-subtle); font-size: 0.8rem; }

/* ---------- Footer ---------- */

footer.app-footer {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-subtle);
}
footer.app-footer .row { margin-bottom: 0.4rem; }
footer.app-footer a { color: var(--text-muted); }
