/* PPS Scraper Dashboard - shared stylesheet.
   Same-origin only: no external fonts, no CDN, no external assets of
   any kind. System fonts and CSS custom properties only. */

:root {
  color-scheme: light dark;

  /* Step 65: palette aligned with the approved design mockup - a cool
     blue-biased neutral ground with a clear sky-blue accent. */
  --color-bg: #f3f6fa;
  --color-surface: #ffffff;
  --color-border: #d7dee8;
  --color-text: #17212e;
  --color-text-muted: #5b6b80;
  --color-accent: #0b6bcb;
  --color-accent-contrast: #ffffff;
  --color-accent-hover: #095aa9;

  --color-success: #15803d;
  --color-success-bg: #dcfce7;
  --color-info: #1d4ed8;
  --color-info-bg: #dbeafe;
  --color-warning: #b45309;
  --color-warning-bg: #fef3c7;
  --color-danger: #b91c1c;
  --color-danger-bg: #fee2e2;
  --color-neutral: #667085;
  --color-neutral-bg: #e9ebef;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  /* Step 65: the data face - run IDs, counters, timestamps. */
  --font-data: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas,
    "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Step 65: mockup-approved dark - deep blue-slate, sky-blue accent. */
    --color-bg: #12161d;
    --color-surface: #1a212b;
    --color-border: #2a3442;
    --color-text: #e8edf4;
    --color-text-muted: #93a1b4;
    --color-accent: #58a6ff;
    --color-accent-contrast: #0e1116;
    --color-accent-hover: #79b8ff;

    --color-success: #4ade80;
    --color-success-bg: rgba(74, 222, 128, 0.14);
    --color-info: #60a5fa;
    --color-info-bg: rgba(96, 165, 250, 0.14);
    --color-warning: #fbbf24;
    --color-warning-bg: rgba(251, 191, 36, 0.14);
    --color-danger: #f87171;
    --color-danger-bg: rgba(248, 113, 113, 0.14);
    --color-neutral: #9aa1ac;
    --color-neutral-bg: rgba(154, 161, 172, 0.14);

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.45);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
}

a {
  color: var(--color-accent);
}

h1,
h2,
h3 {
  color: var(--color-text);
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* --- App shell ------------------------------------------------------ */

.app-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-4) var(--space-6);
}

.app-header__brand {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.page {
  max-width: 42rem;
  margin: 0 auto;
  padding: var(--space-6) var(--space-4) var(--space-8);
}

.page--wide {
  max-width: 76rem;
}

.page--narrow {
  max-width: 26rem;
}

.back-link {
  display: inline-block;
  margin-bottom: var(--space-4);
  font-size: 0.9rem;
  color: var(--color-text-muted);
  text-decoration: none;
}

.back-link:hover {
  color: var(--color-accent);
}

/* --- Cards ------------------------------------------------------------ */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-6);
  margin-bottom: var(--space-6);
}

.card h2 {
  margin: 0 0 var(--space-4);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Step 105: a quiet note beside a card heading - used to say which clock
   the event times are in, without shouting it in the heading itself. */
.card h2 .card-sub {
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  opacity: 0.75;
  margin-left: var(--space-2);
}

.card:last-child {
  margin-bottom: 0;
}

.field-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-2) var(--space-6);
}

.field-list li {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.9rem;
}

.field-list li:last-child {
  border-bottom: none;
}

.field-list .field-label {
  color: var(--color-text-muted);
}

.field-list .field-value {
  font-weight: 500;
  text-align: right;
}

/* --- KPI grid --------------------------------------------------------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-4);
}

.kpi-card__label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
}

.kpi-card__value {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* --- Status badge ------------------------------------------------------ */

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: capitalize;
  line-height: 1.4;
}

.status-completed {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.status-running {
  background: var(--color-info-bg);
  color: var(--color-info);
}

.status-queued {
  background: var(--color-neutral-bg);
  color: var(--color-neutral);
}

.status-stopped {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.status-failed {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.status-unavailable {
  background: var(--color-neutral-bg);
  color: var(--color-neutral);
}

/* --- Buttons / links as buttons ---------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.btn-primary {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-accent-contrast);
}

.btn-primary:hover {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
  color: var(--color-accent-contrast);
}

/* --- Step 64: sidebar shell -------------------------------------------- */

body.has-sidebar {
  display: flex;
  min-height: 100vh;
  margin: 0;
}

.sidebar {
  width: 200px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 12px;
  border-right: 1px solid var(--color-border);
}

.sidebar__brand {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  padding: 4px 10px 16px;
}

.sidebar__brand span { color: var(--color-accent); }

.nav-link {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 7px;
  text-decoration: none;
  color: var(--color-text-muted);
  font-size: 0.95rem;
}

.nav-link:hover { color: inherit; }

.nav-link--active {
  color: inherit;
  font-weight: 600;
  background: var(--color-surface);
}

.nav-link__glyph {
  width: 16px;
  text-align: center;
  color: var(--color-accent);
  font-family: var(--font-data);
}

.sidebar__logout { margin-top: auto; padding: 8px 4px 0; }

/* Step 69: queued/running runs pinned in the sidebar, mockup-style. */
.sidebar__active {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border);
}

.sidebar__active-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  padding: 0 10px 8px;
}

.active-run-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 7px;
  text-decoration: none;
  color: var(--color-text-muted);
  font-family: var(--font-data);
  font-size: 0.82rem;
}

.active-run-link:hover { color: inherit; }

.active-run-link__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.active-run-link__dot--running { background: var(--color-accent); }
.active-run-link__dot--queued { background: #b98a26; }
/* Step 71: a finished run whose company enrichment is still working. */
.active-run-link__dot--enriching { background: #3fb27f; }

body.has-sidebar .page { flex: 1; min-width: 0; }

.btn-small { padding: 0.25rem 0.7rem; font-size: 0.85rem; }

.page-sub { color: var(--color-text-muted); margin-top: -0.4rem; }

.field-hint {
  color: var(--color-text-muted);
  font-weight: 400;
  font-size: 0.85em;
}

.warn-note {
  border: 1px solid #b98a26;
  background: rgba(240, 180, 41, 0.09);
  border-radius: 7px;
  padding: 0.65rem 0.9rem;
  margin: 0.6rem 0;
  font-size: 0.92rem;
}

/* Step 64: the poisoned-filter warning is CSS-driven (the new-run
   template deliberately carries no script): hidden only while BOTH
   selects sit on "any". Browsers without :has() simply always show the
   warning - a safe failure direction. */
form:has(#work_type option[value="any"]:checked):has(#job_type option[value="any"]:checked) #filter-warning {
  display: none;
}

.cell-num { text-align: right; font-variant-numeric: tabular-nums; }
.cell-mono { font-family: var(--font-data); font-size: 0.85em; }
.cell-keywords { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-downloads { white-space: nowrap; }

.dl-unavailable {
  color: var(--color-text-muted);
  opacity: 0.55;
  font-size: 0.85rem;
  padding: 0.25rem 0.5rem;
  cursor: not-allowed;
}

@media (max-width: 760px) {
  body.has-sidebar { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    padding: 8px 10px;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    overflow-x: auto;
  }
  .sidebar__brand { padding: 0 10px 0 4px; white-space: nowrap; }
  .sidebar__nav { display: flex; gap: 4px; }
  .sidebar__active { display: none; }
  .sidebar__logout { margin-top: 0; margin-left: auto; padding: 0; }
}

/* Step 63: the one-line "what is this run doing right now" phase line. */
.phase-line {
  color: var(--color-text-muted);
  font-size: 0.95rem;
  margin: 0.35rem 0 1.1rem;
  min-height: 1.3em;
}

/* --- Step 72: mockup run page ---------------------------------------- */

.run-header {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 0.3rem;
}

.run-header h1 { margin: 0; }

.run-header__duration {
  font-family: var(--font-data);
  font-size: 1.05rem;
  color: var(--color-text-muted);
}

.run-header__actions { margin-left: auto; }

/* display:flex would defeat the hidden attribute - keep hidden winning. */
.confirm-banner[hidden] { display: none; }

.confirm-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  border: 1px solid #b4554a;
  background: rgba(214, 96, 77, 0.09);
  border-radius: var(--radius);
  padding: 0.7rem 1rem;
  margin: 0.6rem 0 1rem;
}

.confirm-banner__text { flex: 1; min-width: 240px; }

.kpi-card__sub {
  color: var(--color-text-muted);
  font-size: 0.8rem;
  margin-top: 0.35rem;
  min-height: 1.1em;
}

.kpi-card__of {
  color: var(--color-text-muted);
  font-size: 0.95rem;
  font-family: var(--font-data);
}

.kpi-card__value--ok { color: #3fb27f; }
.kpi-card__value--time { font-family: var(--font-data); }

.kpi-progress {
  height: 5px;
  border-radius: 3px;
  background: var(--color-border);
  margin-top: 0.55rem;
  overflow: hidden;
}

.kpi-progress--wide { margin: 0.2rem 0 1rem; }

.kpi-progress__fill {
  height: 100%;
  border-radius: 3px;
  background: var(--color-accent);
}

.dl-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.dl-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 0.65rem 0;
  border-top: 1px solid var(--color-border);
}

.dl-row:first-child { border-top: none; }

.dl-desc { color: var(--color-text-muted); font-size: 0.88rem; }

.dl-state { display: flex; align-items: center; gap: 10px; }

.dl-ready { color: #3fb27f; font-weight: 600; font-size: 0.88rem; }

.dl-wait { color: var(--color-text-muted); font-size: 0.88rem; }

.event-row {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 0.3rem 0;
}

.event-time {
  font-family: var(--font-data);
  font-size: 0.82rem;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

/* Step 62: destructive-action button (Stop / Cancel a run). */
.btn-danger {
  border-color: #b3453f;
  color: #d9645d;
  background: transparent;
}

.btn-danger:hover {
  border-color: #d9645d;
  color: #ffffff;
  background: #b3453f;
}

.btn-block {
  display: flex;
  width: 100%;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-2);
}

/* --- Notices ------------------------------------------------------------ */

.notice {
  background: var(--color-info-bg);
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--color-text);
  padding: var(--space-4);
  margin: 0 0 var(--space-4);
  font-size: 0.9rem;
}

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

.form-field {
  margin-bottom: var(--space-4);
}

.form-field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: var(--space-1);
  color: var(--color-text-muted);
}

.form-field input[type="text"],
.form-field input[type="password"],
.form-field input[type="number"],
.form-field select,
.form-field textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: inherit;
  font-size: 0.9rem;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

/* --- Step 68: compact new-run page ---------------------------------- */
/* Form on the left, preview / what-happens-next on the right, so the
   whole request fits a normal laptop screen instead of one long column.
   Related fields share a row inside the form for the same reason. */

.new-run-layout {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: var(--space-4);
  align-items: start;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 var(--space-3);
}

.form-row--3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.steps-list {
  margin: 0 0 var(--space-4);
  padding-left: 1.2rem;
  font-size: 0.9rem;
}

.steps-list li {
  margin-bottom: var(--space-2);
}

@media (max-width: 980px) {
  .new-run-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 600px) {
  .form-row,
  .form-row--3 {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* --- Table ------------------------------------------------------------ */

.table-wrap {
  overflow-x: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

table.data-table th {
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

table.data-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

table.data-table tbody tr:last-child td {
  border-bottom: none;
}

table.data-table tbody tr:hover {
  background: var(--color-bg);
}

/* --- Events list -------------------------------------------------------- */

.event-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.event-list li {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  font-size: 0.85rem;
}

.event-list strong {
  color: var(--color-text);
}

/* --- Step 65: data-face + numeric treatment --------------------------- */

.kpi-card__value {
  font-family: var(--font-data);
  font-variant-numeric: tabular-nums;
}

.data-table td {
  font-variant-numeric: tabular-nums;
}

.warn-note {
  border-color: var(--color-warning);
  background: var(--color-warning-bg);
}

.btn-danger {
  border-color: var(--color-danger);
  color: var(--color-danger);
  background: transparent;
}

.btn-danger:hover {
  border-color: var(--color-danger);
  color: var(--color-accent-contrast);
  background: var(--color-danger);
}

/* --- Step 78B: enrichment paste-box reveal --------------------------- */
/* <details>/<summary> so the box opens with zero script - a fully
   terminal run page renders no <script> at all by design. The summary
   carries .btn/.btn-primary; these rules only remove the browser's
   default disclosure triangle and space the revealed form. */
.en-reveal > summary {
  list-style: none;
}

.en-reveal > summary::-webkit-details-marker {
  display: none;
}

.en-reveal[open] > summary {
  margin-bottom: var(--space-3);
}

/* --- Step 79: honest completion ------------------------------------- */
.kpi-card__sub--warn {
  color: var(--color-warning);
}
