/* ==================================================================
   Script Management Platform - single stylesheet, no external assets
   ================================================================== */

:root {
  --bg:            #f6f7f9;
  --surface:       #ffffff;
  --surface-2:     #fafbfc;
  --border:        #e3e6ea;
  --border-strong: #cfd4da;
  --text:          #1a1d21;
  --text-muted:    #6b7280;
  --text-faint:    #9aa1ab;

  --accent:        #2563eb;
  --accent-soft:   #eff4ff;
  --ok:            #15803d;
  --ok-soft:       #e9f7ee;
  --warn:          #b45309;
  --warn-soft:     #fdf3e3;
  --bad:           #b91c1c;
  --bad-soft:      #fdecec;
  --run:           #1d4ed8;
  --run-soft:      #e8eeff;

  --radius:   8px;
  --radius-sm: 5px;
  --shadow:   0 1px 2px rgba(16, 24, 40, .05);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, .10);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #0f1115;
    --surface:       #171a1f;
    --surface-2:     #1c2027;
    --border:        #282d35;
    --border-strong: #3a414b;
    --text:          #e8eaed;
    --text-muted:    #98a1ad;
    --text-faint:    #6c7683;

    --accent:        #5b8cff;
    --accent-soft:   #1a2338;
    --ok:            #4ade80;
    --ok-soft:       #16281d;
    --warn:          #fbbf24;
    --warn-soft:     #2b2312;
    --bad:           #f87171;
    --bad-soft:      #2d1618;
    --run:           #7ba3ff;
    --run-soft:      #16203a;

    --shadow:    0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------------- Layout ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 650; font-size: 15px; color: var(--text);
  letter-spacing: -.01em; white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  display: grid; place-items: center;
  color: #fff; font-size: 11px; font-weight: 700;
}
.nav { display: flex; gap: 2px; flex: 1; }
.nav a {
  padding: 6px 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 12px; color: var(--text-faint); font-size: 12.5px; }

.container { max-width: 1320px; margin: 0 auto; padding: 24px; }
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-head h1 { margin: 0 0 2px; font-size: 20px; font-weight: 650; letter-spacing: -.02em; }
.page-head p  { margin: 0; color: var(--text-muted); font-size: 13px; }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------------- Cards ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.card-head h2 { margin: 0; font-size: 13.5px; font-weight: 620; letter-spacing: -.01em; }
.card-head .sub { color: var(--text-faint); font-size: 12px; font-weight: 400; }
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }

/* ---------------- Stats ---------------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.stat .label { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stat .value { font-size: 25px; font-weight: 660; letter-spacing: -.02em; margin-top: 4px; line-height: 1.1; }
.stat .value small { font-size: 13px; color: var(--text-faint); font-weight: 500; }
.stat.is-bad  .value { color: var(--bad); }
.stat.is-ok   .value { color: var(--ok); }
.stat.is-run  .value { color: var(--run); }

/* ---------------- Tables ---------------- */
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; padding: 9px 16px;
  font-size: 11px; font-weight: 640; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-faint); background: var(--surface-2);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.nowrap, th.nowrap { white-space: nowrap; }

.cell-title { font-weight: 560; color: var(--text); }
.cell-sub { font-size: 12px; color: var(--text-faint); margin-top: 1px; }

/* ---------------- Badges ---------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2.5px 8px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  border: 1px solid transparent;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge-success, .badge-healthy { background: var(--ok-soft);   color: var(--ok); }
.badge-failed, .badge-failing,
.badge-timeout                { background: var(--bad-soft);  color: var(--bad); }
.badge-running, .badge-queued { background: var(--run-soft);  color: var(--run); }
.badge-unstable               { background: var(--warn-soft); color: var(--warn); }
.badge-never, .badge-cancelled,
.badge-muted                  { background: var(--surface-2); color: var(--text-faint); border-color: var(--border); }
.badge-running .dot { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.pill {
  display: inline-block; padding: 1.5px 7px; border-radius: 4px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-family: var(--mono); font-size: 11.5px; color: var(--text-muted);
}

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font-size: 13px; font-weight: 550;
  cursor: pointer; font-family: inherit; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-danger { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.btn-sm { padding: 4.5px 10px; font-size: 12.5px; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); }

/* ---------------- Forms ---------------- */
.field { margin-bottom: 15px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; }
.field .help { font-size: 12px; color: var(--text-faint); margin-top: 4px; line-height: 1.45; }
input[type=text], input[type=password], input[type=number], input[type=date],
input[type=email], select, textarea {
  width: 100%; padding: 7px 10px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-size: 13px; font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 68px; }
.field-inline { display: flex; align-items: center; gap: 8px; }
.field-inline input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--accent); margin: 0; }
.field-inline label { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 0 18px; }
.form-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface-2);
}
.mono-input { font-family: var(--mono); }

/* ---------------- Flash ---------------- */
.flashes { margin-bottom: 16px; display: flex; flex-direction: column; gap: 8px; }
.flash {
  padding: 10px 14px; border-radius: var(--radius);
  font-size: 13px; border: 1px solid transparent;
}
.flash-success { background: var(--ok-soft);  color: var(--ok);  border-color: currentColor; }
.flash-error   { background: var(--bad-soft); color: var(--bad); border-color: currentColor; }

/* ---------------- Console ---------------- */
.console {
  background: #0d1117; color: #d5dae2;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.65;
  padding: 14px 16px; max-height: 560px; overflow: auto;
  white-space: pre-wrap; word-break: break-word;
  border-radius: 0 0 var(--radius) var(--radius);
}
.console .ln { display: block; }
.console .ln-err { color: #ff9d9d; }
.console .empty { color: #6e7681; font-style: italic; }

/* ---------------- Sparkline ---------------- */
/* Daily volume bars on the report page. Each column stacks good over bad. */
.daybars {
  display: flex; align-items: flex-end; gap: 3px;
  height: 110px; overflow-x: auto; padding-bottom: 2px;
}
.daybar {
  display: flex; flex-direction: column-reverse; justify-content: flex-start;
  min-width: 8px; flex: 1 1 8px; height: 100%;
}
.daybar i { display: block; width: 100%; border-radius: 2px; background: var(--ok); opacity: .75; }
.daybar i.bad { background: var(--bad); opacity: .9; }
.daybar:hover i { opacity: 1; }

.spark { display: flex; align-items: flex-end; gap: 2px; height: 30px; }
.spark i {
  flex: 1; min-width: 3px; border-radius: 1.5px;
  background: var(--accent); opacity: .55; display: block;
}
.spark i.bad { background: var(--bad); opacity: .85; }

/* ---------------- Misc ---------------- */
.group-title {
  display: flex; align-items: center; gap: 9px;
  margin: 26px 0 10px; font-size: 12px; font-weight: 660;
  text-transform: uppercase; letter-spacing: .07em; color: var(--text-faint);
}
.group-title::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.group-title .count {
  text-transform: none; letter-spacing: 0; font-weight: 500;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 1px 7px; border-radius: 10px; color: var(--text-muted);
}
.empty-state { padding: 40px 20px; text-align: center; color: var(--text-faint); font-size: 13px; }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters select { width: auto; min-width: 150px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 7px 18px; font-size: 13px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; word-break: break-word; }
.split { display: grid; grid-template-columns: 1.55fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }
.tag-list { display: flex; flex-wrap: wrap; gap: 5px; }
.tag {
  font-size: 11.5px; padding: 2px 7px; border-radius: 4px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted);
}
.env-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 12.5px;
}
.env-row:last-child { border-bottom: none; }
.env-row code { font-family: var(--mono); font-size: 12px; color: var(--text-muted); }

/* ---------------- Login ---------------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 372px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 30px; box-shadow: var(--shadow-lg);
}
.login-card h1 { margin: 14px 0 4px; font-size: 18px; font-weight: 650; }
.login-card .lead { margin: 0 0 22px; color: var(--text-muted); font-size: 13px; }
