/* ── Srangoods - TidyTrade Design System ── */

@import url('https://fonts.googleapis.com/css2?family=Hanken+Grotesk:wght@400;500;600;700;800&family=IBM+Plex+Mono:wght@400;600&display=swap');

:root {
  /* Palette */
  --sidebar-bg:   #0d1b2e;
  --sidebar-text: #aeb9c9;
  --sidebar-text-hover: #ffffff;
  --accent:       #2d7ef0;
  --accent-hover: #1c6bd6;
  --bg:           #f6f7f9;
  --bg-soft:      #f6f7f9;
  --surface:      #ffffff;
  --border:       #e2e6ec;
  --text:         #0d1b2e;
  --text-muted:   #64748b;

  /* Status colours */
  --status-discovered: #94a3b8;
  --status-enriched:   #0ea5b7;
  --status-scored:     #2d7ef0;
  --status-contacted:  #f59e0b;
  --status-accepted:   #15a34a;
  --status-rejected:   #ef4444;

  /* Semantic */
  --success: #15a34a;
  --warning: #f59e0b;
  --info:    #2d7ef0;
  --danger:  #ef4444;

  /* Radius / shadow */
  --radius:   8px;
  --shadow:   0 1px 4px rgba(13,27,46,0.07), 0 4px 16px rgba(13,27,46,0.05);
  --shadow-sm: 0 1px 3px rgba(13,27,46,0.08);
}

* { box-sizing: border-box; }

body {
  font-family: 'Hanken Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

/* ── Sidebar ── */
.sidebar {
  width: 232px;
  background: var(--sidebar-bg);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  transition: width 0.22s ease;
}
.sidebar.collapsed { width: 52px; }
.sidebar.collapsed .sidebar-brand-logo,
.sidebar.collapsed .nav-caption,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .sidebar-footer { opacity: 0; pointer-events: none; }
.sidebar-brand-logo,
.nav-caption,
.nav-label,
.sidebar-footer { transition: opacity 0.15s ease; }

.sidebar-brand {
  padding: 18px 14px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sidebar-toggle {
  background: none;
  border: none;
  color: rgba(174,185,201,0.5);
  cursor: pointer;
  padding: 4px 6px;
  font-size: 1.1rem;
  line-height: 1;
  border-radius: 5px;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}
.sidebar-toggle:hover { color: #fff; background: rgba(255,255,255,0.08); }


.sidebar nav {
  padding: 10px 10px;
  flex: 1;
}

.sidebar .nav-item {
  display: flex;
  flex-direction: column;
  padding: 9px 12px;
  margin-bottom: 2px;
  border-radius: 7px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.sidebar .nav-item:hover {
  background: rgba(255,255,255,0.07);
  color: var(--sidebar-text-hover);
}

.sidebar .nav-item.active {
  background: var(--accent);
  color: #ffffff;
}

.sidebar .nav-item.active .nav-caption {
  color: rgba(255,255,255,0.7);
}

.sidebar .nav-caption {
  display: block;
  font-size: 0.72rem;
  font-weight: 400;
  color: rgba(174,185,201,0.6);
  margin-top: 1px;
}

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,0.07);
  font-size: 0.75rem;
  color: rgba(174,185,201,0.5);
  line-height: 1.5;
  font-family: 'IBM Plex Mono', monospace;
}

/* ── Main ── */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.topbar-time {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.page-body {
  padding: 28px 32px;
  flex: 1;
}

/* ── Typography ── */
h1 { font-size: 1.6rem; font-weight: 800; margin: 0 0 20px; letter-spacing: -0.4px; color: var(--text); }
h2 { font-size: 1.25rem; font-weight: 700; margin: 24px 0 12px; letter-spacing: -0.2px; }
h3 { font-size: 1.05rem; font-weight: 700; margin: 18px 0 10px; }
h4 { font-size: 0.9rem; font-weight: 600; margin: 14px 0 6px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; }

hr.divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.caption, .text-muted {
  color: var(--text-muted);
  font-size: 0.82rem;
}

/* ── Flash messages ── */
.flash-messages { margin-bottom: 8px; }
.alert {
  padding: 11px 16px;
  border-radius: var(--radius);
  margin: 8px 0;
  border: 1px solid transparent;
  font-size: 0.88rem;
}
.alert-success { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.alert-info    { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }
.alert-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.alert-danger  { background: #fef2f2; color: #991b1b; border-color: #fecaca; }

/* ── KPI / Metric cards ── */
.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}
.metric-label { font-size: 0.78rem; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; }
.metric-value { font-size: 2rem; font-weight: 800; margin-top: 4px; color: var(--text); line-height: 1.1; }
.high-score { color: var(--success); font-weight: 700; }
.low-score  { color: var(--danger);  font-weight: 700; }

/* ── Grid / columns ── */
.cols { display: flex; gap: 14px; flex-wrap: wrap; }
.cols > * { flex: 1 1 0; min-width: 0; }
.cols.c2 > * { flex-basis: calc(50% - 7px); }
.cols.c3 > * { flex-basis: calc(33.33% - 10px); }
.cols.c4 > * { flex-basis: calc(25% - 11px); }
.cols.c5 > * { flex-basis: calc(20% - 12px); }
.col-3 { flex: 3 1 0; min-width: 0; }
.col-2 { flex: 2 1 0; min-width: 0; }
.col-1 { flex: 1 1 0; min-width: 0; }

/* ── Form controls ── */
.form-group { margin: 10px 0; }
.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.82rem;
  margin-bottom: 5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.form-group .help {
  display: block;
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-top: 4px;
}

input[type="text"], input[type="number"], input[type="email"],
input[type="url"], input[type="password"], textarea, select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45,126,240,0.12);
}
input[type="range"] { width: 100%; accent-color: var(--accent); }
textarea { font-family: inherit; resize: vertical; min-height: 80px; }
input[type="checkbox"], input[type="radio"] { transform: scale(1.1); accent-color: var(--accent); }

/* ── Buttons ── */
.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.btn:hover { background: var(--bg); border-color: #c5cdd8; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { background: var(--bg); border-color: var(--border); }
.btn-danger {
  background: var(--surface);
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 5px 11px; font-size: 0.8rem; }

/* ── Toggle ── */
.toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  vertical-align: middle;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #d1d9e6;
  border-radius: 22px;
  transition: 0.2s;
}
.toggle .slider:before {
  content: "";
  position: absolute;
  height: 16px; width: 16px;
  left: 3px; bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle input:checked + .slider { background: var(--accent); }
.toggle input:checked + .slider:before { transform: translateX(18px); }

/* ── Tables ── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-sm); }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
table.data th {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
}
table.data td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
}
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: #f8f9fb; }

/* ── Expander / details ── */
.expander {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 10px 0;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.expander > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 16px;
  background: var(--bg);
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: var(--radius) var(--radius) 0 0;
  color: var(--text);
}
.expander[open] > summary { border-bottom: 1px solid var(--border); }
.expander > summary::-webkit-details-marker { display: none; }
.expander > summary::before { content: "▶ "; color: var(--accent); font-size: 0.75rem; }
.expander[open] > summary::before { content: "▼ "; }
.expander > .expander-body { padding: 18px; }

/* ── Tabs ── */
.tabs { margin: 10px 0; }
.tab-headers {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}
.tab-header {
  padding: 9px 18px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.88rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s;
}
.tab-header:hover { color: var(--text); }
.tab-header.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Status / badge pills ── */
.badge, .status-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.73rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* Generic badge colours */
.badge { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }
.badge.success { background: #f0fdf4; color: #166534; }
.badge.warning { background: #fffbeb; color: #92400e; }
.badge.danger  { background: #fef2f2; color: #991b1b; }

/* Status-specific pills */
.status-pill                          { background: #f1f5f9; color: #64748b; }
.status-pill.status-discovered,
.status-pill[data-status="discovered"] { background: rgba(148,163,184,0.15); color: #64748b; }
.status-pill.status-enriched,
.status-pill[data-status="enriched"]   { background: rgba(14,165,183,0.12); color: #0e7490; }
.status-pill.status-scored,
.status-pill[data-status="scored"]     { background: rgba(45,126,240,0.12); color: #1d4ed8; }
.status-pill.status-contacted,
.status-pill[data-status="contacted"]  { background: rgba(245,158,11,0.12); color: #92400e; }
.status-pill.status-accepted,
.status-pill[data-status="accepted"]   { background: rgba(21,163,74,0.12); color: #166534; }
.status-pill.status-rejected,
.status-pill[data-status="rejected"]   { background: rgba(239,68,68,0.12); color: #991b1b; }

/* Pipeline log status */
.status-pill.status-success  { background: #f0fdf4; color: #166534; }
.status-pill.status-started  { background: #eff6ff; color: #1e40af; }
.status-pill.status-warning  { background: #fffbeb; color: #92400e; }
.status-pill.status-failed   { background: #fef2f2; color: #991b1b; }
.status-pill.status-pending  { background: #f1f5f9; color: #64748b; }

/* ── Misc utilities ── */
.code-block, .json-result {
  background: #0f172a;
  color: #e2e8f0;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-family: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
  font-size: 0.82rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.json-result { max-height: 320px; white-space: pre; }

.inline-code {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 0.8rem;
  word-break: break-all;
}

.row-flex { display: flex; gap: 12px; align-items: center; }
.justify-between { justify-content: space-between; }
.slider-row { display: flex; align-items: center; gap: 8px; }
.slider-row output { min-width: 36px; text-align: right; font-weight: 700; color: var(--accent); }
.weight-warn { color: var(--danger); font-weight: 700; }
.weight-ok   { color: var(--success); font-weight: 700; }
.weight-bad  { color: var(--danger);  font-weight: 700; }
.checkbox-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.form-inline { display: block; margin: 12px 0; }
.summary-cell { max-width: 600px; white-space: pre-wrap; word-break: break-word; font-size: 0.88rem; }

/* ── Run controls (pipeline page) ── */
.run-controls {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin: 14px 0;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.run-controls > legend {
  padding: 0 8px;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text);
}
.run-controls h4 {
  margin: 18px 0 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.run-controls h4:first-of-type { border-top: none; padding-top: 0; }

/* ── Chart wrapper ── */
.chart-wrap { position: relative; height: 280px; margin: 14px 0; }

/* ── Pipeline banner ── */
.run-live-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 0.9rem;
  border: 1px solid transparent;
  flex-wrap: wrap;
  box-shadow: var(--shadow-sm);
}
.run-live-actions { display: flex; gap: 8px; }
.run-live-running {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1e40af;
  animation: pulse-border 2s ease-in-out infinite;
}
.run-live-done { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
@keyframes pulse-border {
  0%, 100% { border-color: #bfdbfe; }
  50%       { border-color: var(--accent); }
}

/* ── Pipeline progress page ── */
.progress-label { display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 5px; }
.progress-count { font-weight: 700; color: var(--text-muted); font-family: 'IBM Plex Mono', monospace; }

.progress-track { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; transition: width 0.4s ease; }
.progress-fill-green { background: var(--success); }
.progress-fill-blue  { background: var(--accent); }

#log-terminal {
  background: #0d1b2e;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  padding: 14px 16px;
  height: 480px;
  overflow-y: auto;
  font-family: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
  font-size: 0.78rem;
  line-height: 1.6;
  margin-top: 12px;
}
.log-line { display: flex; gap: 8px; align-items: baseline; padding: 1px 0; }
.log-time { color: rgba(174,185,201,0.35); flex-shrink: 0; font-size: 0.73rem; }
.log-lvl  { flex-shrink: 0; width: 40px; font-size: 0.7rem; font-weight: 700; text-align: right; }
.log-msg  { color: #aeb9c9; word-break: break-word; flex: 1; }

.log-debug .log-lvl { color: rgba(174,185,201,0.3); }
.log-debug .log-msg { color: rgba(174,185,201,0.4); }
.log-info .log-lvl  { color: var(--accent); }
.log-info .log-msg  { color: #c9d1d9; }
.log-warning .log-lvl { color: var(--warning); }
.log-warning .log-msg { color: #fcd34d; }
.log-error .log-lvl { color: var(--danger); }
.log-error .log-msg { color: #fca5a5; }
.log-line .log-msg[data-highlight="qualify"] { color: #4ade80; }
.log-line .log-msg[data-highlight="score"]   { color: #93c5fd; }

/* ── Project cards (unified Projects page) ── */
details.project-card > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
details.project-card > summary::-webkit-details-marker { display: none; }
details.project-card > summary::before {
  content: '›';
  color: var(--text-muted);
  font-size: 1.15rem;
  line-height: 1;
  transition: transform 0.18s ease;
  flex-shrink: 0;
}
details.project-card[open] > summary::before { transform: rotate(90deg); }

.toggle-form { flex-shrink: 0; }

.project-summary-left {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 6px;
  overflow: hidden;
}
.project-summary-left strong {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.project-summary-chips {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.project-summary-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  margin-left: 4px;
}

.pchip {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 20px;
  font-size: 0.69rem;
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.5;
}
.pchip-neutral { background: rgba(255,255,255,0.07); color: var(--text-muted); }
.pchip-blue    { background: rgba(45,126,240,0.18);  color: #6ab0f5; }
.pchip-green   { background: rgba(34,197,94,0.15);   color: #4ade80; }
.pchip-yellow  { background: rgba(251,191,36,0.15);  color: #fbbf24; }
