/* ==========================================================================
   Signal Console — design tokens
   Charcoal ops-console palette, amber signal accent, mono numerals.
   ========================================================================== */

:root {
  --ink: #111214;
  --panel: #17181b;
  --panel-2: #1e2023;
  --panel-3: #26282c;
  --border: #2b2d32;
  --border-soft: #232529;
  --text: #edeef0;
  --muted: #8b8e96;
  --muted-2: #5b5e66;

  --accent: #ffb238;
  --accent-strong: #ffc35c;
  --accent-ink: #241a04;
  --accent-wash: rgba(255, 178, 56, 0.13);

  --good: #3dd68c;
  --good-wash: rgba(61, 214, 140, 0.13);
  --bad: #f1584d;
  --bad-wash: rgba(241, 88, 77, 0.13);

  --radius-sm: 5px;
  --radius-md: 7px;
  --radius-pill: 999px;

  --font-display: "Space Grotesk", "Inter", sans-serif;
  --font-body: "Inter", -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", "Consolas", monospace;

  --sidebar-w: 226px;
}

* { box-sizing: border-box; }
::selection { background: var(--accent-wash); color: var(--text); }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
  color: var(--text);
}
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
h4 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 10px;
}

.mono, .num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------- */
/* App shell: sidebar + main                                              */
/* --------------------------------------------------------------------- */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--ink);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  padding: 20px 18px 16px;
  display: flex;
  align-items: center;
  gap: 9px;
}
.sidebar-brand .mark-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-wash);
  flex-shrink: 0;
}
.sidebar-brand .mark-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.15;
}
.sidebar-brand .mark-text small {
  display: block;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.sidebar nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 10px;
}
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 500;
}
.sidebar nav a svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.9; }
.sidebar nav a:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.sidebar nav a.active {
  background: var(--panel-2);
  color: var(--text);
  box-shadow: inset 2px 0 0 var(--accent);
}
.sidebar nav .nav-gap { height: 10px; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 10px;
}
.user-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}
.user-chip:hover { background: var(--panel); }
.user-chip .avatar {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--panel-3);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 0.7rem; color: var(--muted);
  flex-shrink: 0;
}
.user-chip .name { font-size: 0.82rem; color: var(--text); flex: 1; }
.user-chip form button {
  background: none; border: none; color: var(--muted-2); cursor: pointer;
  font-size: 0.72rem; padding: 2px 4px;
}
.user-chip form button:hover { color: var(--bad); }

.main { background: var(--panel); min-height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 5;
}
.topbar .eyebrow {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 2px;
}
.topbar h1 { font-size: 1.28rem; }

.content { padding: 26px 32px 60px; max-width: 1180px; }

/* --------------------------------------------------------------------- */
/* Flash messages                                                         */
/* --------------------------------------------------------------------- */

.flash {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  font-size: 0.86rem;
  border: 1px solid transparent;
}
.flash-success { background: var(--good-wash); color: var(--good); border-color: rgba(61,214,140,0.25); }
.flash-danger { background: var(--bad-wash); color: var(--bad); border-color: rgba(241,88,77,0.25); }
.flash-warning { background: var(--accent-wash); color: var(--accent); border-color: rgba(255,178,56,0.25); }

/* --------------------------------------------------------------------- */
/* Cards, stat tiles                                                      */
/* --------------------------------------------------------------------- */

.card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 22px;
  margin-bottom: 20px;
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.animate-in { animation: fadeSlideIn 0.3s ease both; }

.hero { margin-bottom: 20px; }
.hero p { color: var(--muted); margin: 4px 0 0; font-size: 0.92rem; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin: 4px 0 22px;
}
.stat-tile {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 15px 17px;
}
.stat-tile .value {
  font-family: var(--font-mono);
  font-size: 1.55rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.2;
}
.stat-tile .label {
  color: var(--muted);
  font-size: 0.71rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 5px;
}

/* --------------------------------------------------------------------- */
/* Tables                                                                 */
/* --------------------------------------------------------------------- */

table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
th {
  text-align: left;
  padding: 9px 12px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}
tbody tr:hover { background: rgba(255, 255, 255, 0.018); }
tbody tr:last-child td { border-bottom: none; }

/* --------------------------------------------------------------------- */
/* Status: dot + badge                                                   */
/* --------------------------------------------------------------------- */

.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block; margin-right: 8px; position: relative; top: -1px;
  flex-shrink: 0;
}
.status-dot.running { background: var(--accent); animation: pulse-dot 1.7s ease-in-out infinite; }
.status-dot.completed { background: var(--good); }
.status-dot.failed { background: var(--bad); }
.status-dot.stopped, .status-dot.stopping, .status-dot.pending { background: var(--muted-2); }

@keyframes pulse-dot {
  0% { box-shadow: 0 0 0 0 rgba(255, 178, 56, 0.5); }
  70% { box-shadow: 0 0 0 6px rgba(255, 178, 56, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 178, 56, 0); }
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 11px;
  border-radius: var(--radius-pill);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-running { background: var(--accent-wash); color: var(--accent); }
.badge-completed { background: var(--good-wash); color: var(--good); }
.badge-failed { background: var(--bad-wash); color: var(--bad); }
.badge-stopped, .badge-pending, .badge-stopping { background: rgba(139, 142, 150, 0.14); color: var(--muted); }

/* --------------------------------------------------------------------- */
/* Rating meter — signature element                                      */
/* --------------------------------------------------------------------- */

.rating-meter {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  white-space: nowrap;
}
.rating-meter .track {
  position: relative;
  width: 58px;
  height: 5px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--bad) 0%, var(--accent) 50%, var(--good) 100%);
  opacity: 0.9;
}
.rating-meter .marker {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 11px;
  background: #fff;
  border-radius: 1px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
  transform: translateX(-1px);
}
.rating-meter .value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
  color: var(--text);
}
.rating-meter.na .track { opacity: 0.25; }
.rating-meter.na .value { color: var(--muted-2); }

/* --------------------------------------------------------------------- */
/* Progress bar with scan-line ("live crawl") state                      */
/* --------------------------------------------------------------------- */

.progress-track {
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: var(--panel-3);
  border: 1px solid var(--border);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px 0 0 3px;
  transition: width 0.4s ease;
  position: relative;
}
.progress-fill.scanning::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(
    115deg,
    rgba(255, 255, 255, 0.4) 0 5px,
    transparent 5px 11px
  );
  background-size: 200% 100%;
  animation: scan-move 0.9s linear infinite;
}
@keyframes scan-move {
  from { background-position: 0 0; }
  to { background-position: -16px 0; }
}

/* --------------------------------------------------------------------- */
/* Buttons                                                                */
/* --------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.82rem;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel-3);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}
.btn:hover { border-color: var(--muted-2); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-danger { background: var(--bad-wash); border-color: rgba(241, 88, 77, 0.3); color: var(--bad); }
.btn-danger:hover { background: rgba(241, 88, 77, 0.22); }
.btn-sm { padding: 5px 10px; font-size: 0.76rem; }
.btn-lg { padding: 12px 20px; font-size: 0.92rem; }

form.inline { display: inline; }

/* --------------------------------------------------------------------- */
/* Forms                                                                  */
/* --------------------------------------------------------------------- */

label {
  display: block;
  margin: 14px 0 6px;
  font-size: 0.79rem;
  color: var(--muted);
  font-weight: 500;
}
input[type=text], input[type=number], input[type=password], select, textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.87rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-wash);
}
textarea { min-height: 80px; font-family: inherit; resize: vertical; }

.field-hint { color: var(--muted-2); font-size: 0.76rem; margin-top: 5px; }

.checkbox-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.checkbox-row input { width: auto; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }

/* Toggle switch */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border-soft);
}
.switch-row:last-child { border-bottom: none; }
.switch-row .switch-label { font-size: 0.88rem; color: var(--text); }
.switch-row .switch-desc { color: var(--muted); font-size: 0.76rem; margin-top: 2px; }

.switch { position: relative; display: inline-block; width: 40px; height: 23px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider-track {
  position: absolute; inset: 0;
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.switch .slider-track::before {
  content: "";
  position: absolute;
  width: 15px; height: 15px;
  left: 3px; top: 3px;
  background: var(--muted);
  border-radius: 50%;
  transition: transform 0.2s ease, background 0.2s ease;
}
.switch input:checked + .slider-track { background: var(--accent-wash); border-color: var(--accent); }
.switch input:checked + .slider-track::before { transform: translateX(17px); background: var(--accent); }

/* Slider + number combo */
.slider-row { display: flex; align-items: center; gap: 12px; }
.slider-row input[type=range] { flex: 1; accent-color: var(--accent); }
.slider-row .slider-value {
  min-width: 40px; text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* Number stepper */
.stepper {
  display: flex; align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--ink);
}
.stepper button {
  width: 36px; border: none; background: var(--panel-3); color: var(--text);
  font-size: 1.05rem; cursor: pointer; transition: background 0.15s ease, color 0.15s ease;
}
.stepper button:hover { background: var(--accent); color: var(--accent-ink); }
.stepper input {
  border: none; text-align: center; background: transparent; width: 100%;
  font-family: var(--font-mono);
}
.stepper input:focus { outline: none; box-shadow: none; }

/* Keyword chips */
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; min-height: 0; }
.chip {
  display: inline-flex; align-items: center;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  background: var(--panel-3);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  animation: chipIn 0.18s ease both;
}
@keyframes chipIn {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

/* Advanced collapsible */
.advanced-toggle {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  background: none; border: none;
  color: var(--accent);
  font-size: 0.86rem; font-weight: 600;
  cursor: pointer;
  padding: 14px 0 4px;
  border-top: 1px solid var(--border-soft);
  margin-top: 18px;
}
.advanced-toggle .chevron { transition: transform 0.25s ease; display: inline-block; font-size: 0.72rem; }
.advanced-toggle.open .chevron { transform: rotate(180deg); }
.advanced-body { max-height: 0; overflow: hidden; transition: max-height 0.3s ease; }
.advanced-body.open { max-height: 2400px; }
.advanced-section { padding-top: 10px; }
.advanced-section + .advanced-section {
  margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border-soft);
}

.engine-note {
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 10px;
}

/* Submit / loading state */
.spinner {
  display: inline-block; width: 13px; height: 13px;
  border: 2px solid rgba(0, 0, 0, 0.3);
  border-top-color: var(--accent-ink);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.form-actions { display: flex; align-items: center; gap: 14px; margin-top: 24px; }
.form-actions .link-btn {
  color: var(--muted); font-size: 0.84rem; background: none; border: none; cursor: pointer;
}
.form-actions .link-btn:hover { color: var(--text); text-decoration: underline; }

.ajax-error { display: none; margin-bottom: 16px; }
.ajax-error.show { display: block; animation: fadeSlideIn 0.25s ease both; }

/* --------------------------------------------------------------------- */
/* Log console                                                           */
/* --------------------------------------------------------------------- */

.log-box {
  background: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  height: 320px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 0.79rem;
  color: #c7cad1;
  white-space: pre-wrap;
  line-height: 1.6;
}

/* --------------------------------------------------------------------- */
/* Login page                                                            */
/* --------------------------------------------------------------------- */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(600px 300px at 50% 0%, rgba(255, 178, 56, 0.06), transparent),
    var(--ink);
}
.login-wrap { width: 100%; max-width: 380px; padding: 0 20px; }
.login-wrap .sidebar-brand { padding: 0 0 24px; justify-content: center; }

/* --------------------------------------------------------------------- */
/* Utility                                                                */
/* --------------------------------------------------------------------- */

.text-muted { color: var(--muted); }
.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--muted);
}
.empty-state svg { opacity: 0.5; margin-bottom: 14px; }
.empty-state p { margin: 0 0 16px; }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
