/* =========================================================================
   Vela Ops — an operations ledger for n8n.
   Palette is cool slate paper with ink text; colour is reserved for status
   so a red row means something. Type: Archivo for figures and headings,
   IBM Plex Sans for reading, IBM Plex Mono for anything a machine produced.
   ========================================================================= */

:root {
  --paper: #eef1f5;
  --surface: #ffffff;
  --surface-sunk: #f6f8fa;
  --ink: #0f1620;
  --ink-soft: #384352;
  --muted: #5b6878;
  --line: #d7dee7;
  --line-soft: #e6ebf1;

  --accent: #2e3aa8;
  --accent-soft: #eceefb;
  --success: #0e8a5f;
  --success-soft: #e4f4ed;
  --error: #c42b3a;
  --error-soft: #fbeaec;
  --warn: #b8730a;
  --warn-soft: #fdf1de;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(15, 22, 32, 0.05), 0 8px 24px -16px rgba(15, 22, 32, 0.3);

  --sans: 'IBM Plex Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --display: 'Archivo', var(--sans);
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --nav-w: 232px;
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  -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;
  border-radius: 3px;
}

button { font: inherit; cursor: pointer; }

h1, h2, h3 {
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0;
}

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

/* ---------- boot + loading ---------- */

.boot {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  gap: 14px;
  justify-items: center;
  color: var(--muted);
  font-size: 13px;
}

.boot-mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.86); }
}

/* ---------- sign in ---------- */

.signin {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(80% 60% at 50% 0%, #ffffff 0%, var(--paper) 60%);
}

.signin-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}

.signin-card h1 { font-size: 24px; margin-bottom: 4px; }
.signin-card .sub { color: var(--muted); margin: 0 0 24px; font-size: 13px; }

/* ---------- app shell ---------- */

.shell { display: flex; min-height: 100dvh; }

.nav {
  width: var(--nav-w);
  flex: 0 0 var(--nav-w);
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100dvh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 18px;
  border-bottom: 1px solid var(--line-soft);
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--accent);
  display: grid;
  align-content: center;
  gap: 3px;
  padding: 7px 5px;
  flex: none;
}
.brand-mark i { display: block; height: 3px; background: #fff; border-radius: 1px; }
.brand-mark i:nth-child(2) { width: 62%; opacity: 0.75; }
.brand-mark i:nth-child(3) { width: 82%; opacity: 0.5; }

.brand-text strong {
  display: block;
  font-family: var(--display);
  font-size: 15px;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.brand-text span { font-size: 11px; color: var(--muted); }

.nav-links { padding: 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  font-weight: 500;
  font-size: 13.5px;
}
.nav-link:hover { background: var(--surface-sunk); text-decoration: none; }
.nav-link[aria-current='page'] { background: var(--accent-soft); color: var(--accent); }
.nav-link svg { width: 16px; height: 16px; flex: none; }
.nav-link .count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}
.nav-link[aria-current='page'] .count { color: var(--accent); }

.nav-foot { padding: 12px; border-top: 1px solid var(--line-soft); }

.who { display: flex; align-items: center; gap: 9px; padding: 6px 4px; }
.who-badge {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface-sunk); border: 1px solid var(--line);
  display: grid; place-items: center;
  font-family: var(--display); font-size: 12px; font-weight: 600;
  flex: none;
}
.who-name { font-size: 12.5px; font-weight: 500; line-height: 1.25; }
.who-role { font-size: 11px; color: var(--muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar h1 { font-size: 19px; }
.topbar .eyebrow {
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 1px;
}
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.page { padding: 24px 28px 56px; flex: 1; }
.page > * + * { margin-top: 20px; }

/* ---------- primitives ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
}
.card-head h2 { font-size: 14.5px; }
.card-head .spacer { margin-left: auto; }
.card-body { padding: 18px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.btn:hover { background: var(--surface-sunk); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #262f8e; }
.btn-danger { color: var(--error); border-color: #f0c9ce; }
.btn-danger:hover { background: var(--error-soft); }
.btn-sm { padding: 4px 9px; font-size: 12px; }

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 5px;
}

input[type='text'], input[type='email'], input[type='password'],
input[type='number'], input[type='search'], select, textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 13.5px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
select { appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5 6 8l3-3.5' fill='none' stroke='%235b6878' stroke-width='1.4' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 12px;
}

.note {
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  border: 1px solid transparent;
}
.note-error { background: var(--error-soft); border-color: #f0c9ce; color: #8e1f2b; }
.note-ok { background: var(--success-soft); border-color: #bfe3d3; color: #0a6547; }
.note-info { background: var(--accent-soft); border-color: #ccd2f4; color: #26307f; }
.note-warn { background: var(--warn-soft); border-color: #f0d7ab; color: #8a5607; }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-family: var(--display); font-size: 15px; margin-bottom: 4px; }

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar .grow { flex: 1; min-width: 160px; }

/* ---------- status ---------- */

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.status-success { color: var(--success); }
.status-error { color: var(--error); }
.status-running { color: var(--accent); }
.status-running::before { animation: pulse 1.2s ease-in-out infinite; }
.status-waiting { color: var(--warn); }
.status-canceled, .status-unknown { color: var(--muted); }

/* ---------- KPI band ---------- */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.kpi { padding: 18px 20px; border-right: 1px solid var(--line-soft); }
.kpi:last-child { border-right: 0; }
.kpi-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.kpi-value {
  font-family: var(--display);
  font-size: 30px;
  font-weight: 600;
  line-height: 1.15;
  margin-top: 6px;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.kpi-value small { font-size: 15px; color: var(--muted); font-weight: 500; margin-left: 2px; }
.kpi-foot { font-size: 12px; color: var(--muted); margin-top: 3px; }
.kpi-value.is-error { color: var(--error); }
.kpi-value.is-success { color: var(--success); }

/* ---------- run chart ---------- */

.runchart { display: flex; align-items: flex-end; gap: 4px; height: 132px; padding: 4px 0 0; }
.runchart-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 2px;
  min-width: 0;
  height: 100%;
  border-radius: 3px;
  position: relative;
}
.runchart-col:hover { background: var(--surface-sunk); }
.runchart-ok { background: #c3cbe8; border-radius: 2px 2px 0 0; min-height: 2px; }
.runchart-bad { background: var(--error); border-radius: 2px 2px 0 0; min-height: 2px; }
.runchart-col[data-empty='1'] .runchart-ok { background: var(--line-soft); }
.runchart-axis {
  display: flex; gap: 4px; margin-top: 8px;
  font-family: var(--mono); font-size: 10px; color: var(--muted);
}
.runchart-axis span { flex: 1; text-align: center; min-width: 0; overflow: hidden; }

/* ---------- ledger table ---------- */

.ledger-wrap { overflow-x: auto; }

table.ledger {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.ledger th {
  text-align: left;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-sunk);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}
table.ledger th.sortable { cursor: pointer; user-select: none; }
table.ledger th.sortable:hover { color: var(--ink); }
table.ledger th .dir { color: var(--accent); margin-left: 3px; }

table.ledger td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
table.ledger tbody tr:hover { background: var(--surface-sunk); }
table.ledger tbody tr:last-child td { border-bottom: 0; }

/* the ledger gutter: a row number, then a status spine */
td.gutter, th.gutter {
  width: 46px;
  text-align: right;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  padding-right: 8px;
  position: relative;
}
tr[data-state] td.gutter::after {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--line);
}
tr[data-state='error'] td.gutter::after { background: var(--error); }
tr[data-state='success'] td.gutter::after { background: var(--success); }
tr[data-state='running'] td.gutter::after { background: var(--accent); }
tr[data-state='waiting'] td.gutter::after { background: var(--warn); }

td.num, th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 220px; }
td.nowrap { white-space: nowrap; }
.cell-null { color: #aab4c0; }
.cell-bool { font-family: var(--mono); font-size: 12px; }

.table-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-top: 1px solid var(--line-soft);
  font-size: 12.5px;
  color: var(--muted);
  background: var(--surface-sunk);
}
.table-foot .spacer { margin-left: auto; }

/* ---------- signature: the trace strip ---------- */

.strip {
  display: flex;
  gap: 1px;
  height: 16px;
  width: 190px;
  align-items: stretch;
  background: var(--line-soft);
  border-radius: 3px;
  overflow: hidden;
}
.strip i {
  display: block;
  background: #a9b4d6;
  min-width: 1px;
  transition: filter 0.1s ease;
}
.strip i[data-error='1'] { background: var(--error); }
.strip i:hover { filter: brightness(0.78); }
.strip-empty {
  width: 190px; height: 16px; border-radius: 3px;
  background: repeating-linear-gradient(135deg, var(--line-soft) 0 5px, transparent 5px 10px);
}

/* ---------- waterfall ---------- */

.waterfall { display: flex; flex-direction: column; }
.wf-row {
  display: grid;
  grid-template-columns: minmax(180px, 34%) 1fr 74px;
  gap: 12px;
  align-items: center;
  padding: 5px 18px;
  border-bottom: 1px solid var(--line-soft);
}
.wf-row:hover { background: var(--surface-sunk); }
.wf-name {
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px; min-width: 0;
}
.wf-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wf-type { font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.wf-track { position: relative; height: 18px; background: var(--surface-sunk); border-radius: 3px; }
.wf-bar {
  position: absolute; top: 3px; bottom: 3px;
  background: var(--accent); border-radius: 2px; min-width: 2px;
}
.wf-bar[data-error='1'] { background: var(--error); }
.wf-ms { font-family: var(--mono); font-size: 11.5px; text-align: right; color: var(--ink-soft); }
.wf-depth-1 { padding-left: 14px; }
.wf-depth-2 { padding-left: 28px; }

/* ---------- misc detail ---------- */

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; align-items: start; }

.deflist { display: grid; grid-template-columns: auto 1fr; gap: 7px 18px; font-size: 13px; }
.deflist dt { color: var(--muted); }
.deflist dd { margin: 0; font-family: var(--mono); font-size: 12.5px; word-break: break-all; }

.codebox {
  background: #101827;
  color: #dfe6f0;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  white-space: pre;
  margin: 0;
}
.codebox .k { color: #8fb8ff; }

.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row input { font-family: var(--mono); font-size: 12px; }

.pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-sunk);
  border: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}

.errbox {
  border-left: 3px solid var(--error);
  background: var(--error-soft);
  padding: 11px 14px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13px;
}
.errbox strong { display: block; font-size: 12px; margin-bottom: 3px; color: #8e1f2b; }

.tabs { display: flex; gap: 4px; }
.tab {
  padding: 5px 11px; border-radius: var(--radius-sm);
  font-size: 12.5px; font-weight: 500; color: var(--muted);
  border: 1px solid transparent; background: none;
}
.tab[aria-selected='true'] { background: var(--accent-soft); color: var(--accent); }

.sync-dot { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.sync-dot i { width: 6px; height: 6px; border-radius: 50%; background: var(--success); }
.sync-dot.is-stale i { background: var(--warn); }
.sync-dot.is-down i { background: var(--error); }

/* ---------- responsive ---------- */

.nav-toggle { display: none; }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .nav {
    position: static; width: 100%; flex: none; height: auto;
    border-right: 0; border-bottom: 1px solid var(--line);
  }
  .nav-links { flex-direction: row; overflow-x: auto; padding: 8px; }
  .nav-link { white-space: nowrap; }
  .nav-link .count { display: none; }
  .nav-foot { display: flex; justify-content: space-between; align-items: center; }
  .page { padding: 18px 16px 48px; }
  .topbar { padding: 14px 16px; }
  .wf-row { grid-template-columns: minmax(120px, 42%) 1fr 60px; }
  .strip, .strip-empty { width: 110px; }
}

@media print {
  .nav, .topbar-actions, .toolbar, .table-foot { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; }
  .page { padding: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
