/* vibe - Linear-inspired design system. Plain CSS, no libraries.
   Dark surfaces, Inter, 4px spacing grid, 6px radii, 1px borders. */

:root {
  color-scheme: dark;

  /* Surfaces */
  --surface-base: #080a0a;
  --surface-raised: #0e1011;
  --surface-overlay: #17191b;
  --surface-inset: #050607;
  --surface-hover: #1a1c1e;
  --surface-control: #16181a;

  /* Borders */
  --border: #202325;
  --border-strong: #2c3033;

  /* Text */
  --text-primary: #f7f8f8;
  --text-secondary: #b4b8bf;
  --text-tertiary: #8a8f98;

  /* Accent + status */
  --accent: #5e6ad2;
  --accent-hover: #6e79d6;
  --accent-soft: rgba(94, 106, 210, 0.14);
  --good: #4cb782;
  --good-soft: rgba(76, 183, 130, 0.12);
  --warn: #f2c94c;
  --warn-soft: rgba(242, 201, 76, 0.12);
  --bad: #eb5757;
  --bad-soft: rgba(235, 87, 87, 0.12);

  /* Spacing — 4px grid */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;

  --radius: 6px;
  --radius-lg: 8px;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "DejaVu Sans Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--surface-base);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: var(--s-6);
}

code, kbd, pre, .mono { font-family: var(--font-mono); font-size: 0.92em; }

code {
  background: var(--surface-control);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1px 5px;
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}

/* ---------- Focus ---------- */

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

/* ---------- Header ---------- */

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s-4);
  height: 48px;
  padding: 0 var(--s-4);
  padding-left: max(var(--s-4), env(safe-area-inset-left));
  padding-right: max(var(--s-4), env(safe-area-inset-right));
  background: var(--surface-base);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

nav { display: flex; gap: var(--s-1); align-items: center; min-width: 0; }

nav a {
  color: var(--text-tertiary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  padding: var(--s-1) var(--s-2);
  border-radius: var(--radius);
  white-space: nowrap;
}
nav a:hover { color: var(--text-primary); background: var(--surface-hover); }
nav a[aria-current="page"] { color: var(--text-primary); background: var(--surface-hover); }

nav .brand {
  color: var(--text-primary);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
  margin-right: var(--s-3);
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
}
nav .brand::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}
nav .brand:hover { background: none; color: var(--text-primary); }

/* ---------- Layout ---------- */

main {
  padding: var(--s-6) var(--s-4) var(--s-8);
  max-width: 1280px;
  margin: 0 auto;
}

h1, h2, h3 {
  color: var(--text-primary);
  letter-spacing: -0.012em;
  text-wrap: balance;
  margin: 0;
}
h1 { font-size: 22px; font-weight: 600; }
h2 { font-size: 15px; font-weight: 600; }

p { text-wrap: pretty; margin: 0 0 var(--s-3); }
main > p { margin-bottom: var(--s-4); }

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

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s-4);
  flex-wrap: wrap;
  margin-bottom: var(--s-4);
}
.row-between > div { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-4); }
.two-col.files { grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .two-col, .two-col.files { grid-template-columns: 1fr; } }

.actions { display: flex; gap: var(--s-2); flex-wrap: wrap; align-items: center; }
/* Inside a table the cell must stay a cell, or the row separators break. */
td.actions { display: table-cell; white-space: nowrap; }
td.actions button + button { margin-left: var(--s-2); }

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

.card {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--s-5);
  margin: var(--s-4) 0;
}
.card > h2 { margin-bottom: var(--s-4); }
.card > .row-between:first-child { margin-top: 0; }
.card.warn { border-color: rgba(242, 201, 76, 0.4); background: var(--warn-soft); }
.card.warn strong { color: var(--warn); }

.login { width: 340px; max-width: 100%; margin: 0; }
.login h1 {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: var(--s-5);
  display: flex;
  align-items: center;
  gap: var(--s-3);
}
.login h1::before {
  content: "";
  width: 24px;
  height: 24px;
  border-radius: var(--radius);
  background: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}
.login button[type="submit"] { width: 100%; justify-content: center; margin-top: var(--s-4); }

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

label {
  display: block;
  margin: 0 0 var(--s-4);
  color: var(--text-tertiary);
  font-size: 13px;
  font-weight: 500;
}
label.inline {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin-bottom: var(--s-3);
  color: var(--text-secondary);
  font-weight: 400;
  cursor: pointer;
}

input, textarea, select {
  display: block;
  width: 100%;
  max-width: 100%;
  margin-top: var(--s-2);
  background: var(--surface-inset);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: var(--s-2) var(--s-3);
  font-family: var(--font);
  font-size: 13px;
  line-height: 20px;
}
label.inline input, label.inline select { margin-top: 0; }
input::placeholder, textarea::placeholder { color: var(--text-tertiary); opacity: 0.7; }
input:hover, textarea:hover, select:hover { border-color: #383c40; }
textarea { font-family: var(--font-mono); resize: vertical; min-height: 96px; }

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-width: 16px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
input[type="number"] { font-variant-numeric: tabular-nums; }

form.row-inline { display: flex; gap: var(--s-2); align-items: flex-end; }
form.row-inline input { margin-top: 0; }

/* Inline search/add forms sit on one line */
.row-between form { display: flex; gap: var(--s-2); align-items: center; margin: 0; }
.row-between form input { margin-top: 0; }
.card > form:last-child { display: flex; gap: var(--s-2); align-items: center; margin-top: var(--s-3); }
.card > form:last-child input { margin-top: 0; }
.card > form.card { display: block; }

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

button {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  background: var(--surface-control);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 0 var(--s-3);
  height: 28px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--surface-hover); border-color: #3a3e42; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button[type="submit"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button[type="submit"]:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

button.danger { color: #ff9b9b; border-color: rgba(235, 87, 87, 0.35); background: var(--bad-soft); }
button.danger:hover:not(:disabled) { background: rgba(235, 87, 87, 0.2); border-color: var(--bad); }

button.link {
  background: none;
  border: none;
  color: var(--text-tertiary);
  padding: var(--s-1) var(--s-2);
  height: auto;
  text-decoration: none;
}
button.link:hover:not(:disabled) { background: var(--surface-hover); color: var(--text-primary); }

header form { margin: 0; }

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

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 0 0 var(--s-4);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}
.card table { border: none; border-radius: 0; background: none; margin-bottom: 0; }

th, td {
  text-align: left;
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  color: var(--text-tertiary);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: var(--surface-base);
  white-space: nowrap;
}
.card table th { background: transparent; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-hover); }
td a { font-weight: 500; }

/* ---------- Text utilities ---------- */

.muted { color: var(--text-tertiary); }
.small { font-size: 12px; }
.bad { color: var(--bad); }
td .small, td .muted { line-height: 1.4; }
td > .muted.small { margin-top: 2px; }

/* ---------- Status pills ---------- */

.state {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 2px var(--s-2);
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface-control);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  line-height: 18px;
  white-space: nowrap;
}
.state::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.state.running { color: var(--good); border-color: rgba(76, 183, 130, 0.35); background: var(--good-soft); }
.state.crashed { color: var(--bad); border-color: rgba(235, 87, 87, 0.35); background: var(--bad-soft); }
.state.stopped { color: var(--text-tertiary); }

.run-committed { color: var(--good); font-weight: 500; }
.run-skipped { color: var(--text-tertiary); }
.run-error { color: var(--bad); font-weight: 500; }

/* ---------- Banners, flashes, toast ---------- */

.banner {
  display: flex;
  align-items: baseline;
  gap: var(--s-2);
  flex-wrap: wrap;
  padding: var(--s-3) var(--s-4);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text-secondary);
  margin-bottom: var(--s-4);
  font-size: 13px;
}
.banner strong { color: var(--text-primary); font-weight: 600; }
.banner.green { border-color: rgba(76, 183, 130, 0.35); background: var(--good-soft); }
.banner.green strong { color: var(--good); }
.banner.yellow { border-color: rgba(242, 201, 76, 0.35); background: var(--warn-soft); }
.banner.yellow strong { color: var(--warn); }
.banner.red { border-color: rgba(235, 87, 87, 0.35); background: var(--bad-soft); }
.banner.red strong { color: var(--bad); }

.flashes { margin-bottom: var(--s-4); }
.flash {
  padding: var(--s-3) var(--s-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-raised);
  margin-bottom: var(--s-2);
  font-size: 13px;
}
.flash.error { border-color: rgba(235, 87, 87, 0.35); background: var(--bad-soft); color: #ff9b9b; }
.login .flash { margin-bottom: var(--s-4); }

.toast {
  position: fixed;
  right: max(var(--s-4), env(safe-area-inset-right));
  bottom: max(var(--s-4), env(safe-area-inset-bottom));
  background: var(--surface-overlay);
  border: 1px solid var(--border-strong);
  border-left: 2px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: var(--s-3) var(--s-4);
  max-width: 420px;
  color: var(--text-primary);
  font-size: 13px;
  white-space: pre-wrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  z-index: 40;
}
.toast.error { border-left-color: var(--bad); color: #ff9b9b; }

/* ---------- Confirm dialog ---------- */

dialog.confirm {
  background: var(--surface-overlay);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--text-secondary);
  padding: var(--s-5);
  width: 400px;
  max-width: calc(100vw - var(--s-8));
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
  font-family: var(--font);
  font-size: 13px;
}
dialog.confirm::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog.confirm h2 { margin-bottom: var(--s-2); }
dialog.confirm p { color: var(--text-tertiary); margin-bottom: var(--s-5); }
dialog.confirm .actions { justify-content: flex-end; }

/* ---------- Logs & preformatted ---------- */

.logs {
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s-3);
  max-height: 28rem;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
}
pre.runlog {
  max-height: 8rem;
  overflow: auto;
  margin: 0;
  white-space: pre-wrap;
  color: var(--text-tertiary);
  font-size: 12px;
  line-height: 1.5;
}

/* ---------- File tree ---------- */

.tree { list-style: none; padding: 0; margin: 0; max-height: 32rem; overflow: auto; }
.tree li {
  display: flex;
  gap: var(--s-2);
  align-items: baseline;
  padding: var(--s-1) var(--s-2);
  border-radius: var(--radius);
}
.tree li:hover { background: var(--surface-hover); }
.tree .name { cursor: pointer; flex: 1; overflow-wrap: anywhere; color: var(--text-secondary); }
.tree li:hover .name { color: var(--text-primary); }
.tree .dir > .name { font-weight: 500; }
.tree .dir > .name::before { content: "/"; color: var(--accent); margin-right: var(--s-1); }
.tree .unreadable { color: var(--bad); cursor: not-allowed; }
.tree li button {
  background: transparent;
  border-color: transparent;
  color: var(--text-tertiary);
  font-size: 12px;
  height: 24px;
  opacity: 0;
}
.tree li:hover button, .tree li button:focus-visible { opacity: 1; }
.tree li button:hover { color: var(--text-primary); border-color: var(--border-strong); }
@media (hover: none) { .tree li button { opacity: 1; } }
.crumbs {
  margin-bottom: var(--s-3);
  padding-bottom: var(--s-3);
  border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere;
  font-size: 13px;
  color: var(--text-tertiary);
}

/* ---------- Definition list ---------- */

dl.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--s-2) var(--s-6);
  margin: 0 0 var(--s-5);
  font-size: 13px;
}
dl.kv dt { color: var(--text-tertiary); font-weight: 500; }
dl.kv dd { margin: 0; overflow-wrap: anywhere; color: var(--text-secondary); }

/* ---------- Lists ---------- */

.card ul { list-style: none; padding: 0; margin: 0 0 var(--s-3); }
.card ul li {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2);
  border-radius: var(--radius);
}
.card ul li:hover { background: var(--surface-hover); }
.card ul li code { flex: 1; background: none; border: none; padding: 0; }
.card ul li.muted { color: var(--text-tertiary); }
/* A repeated destructive action stays quiet until the row is hovered. */
.card ul li button.danger { background: transparent; border-color: transparent; color: var(--text-tertiary); }
.card ul li:hover button.danger, .card ul li button.danger:focus-visible {
  color: #ff9b9b;
  border-color: rgba(235, 87, 87, 0.35);
  background: var(--bad-soft);
}

@media (max-width: 640px) {
  main { padding: var(--s-4) var(--s-3) var(--s-6); }
  header { height: auto; padding-top: var(--s-2); padding-bottom: var(--s-2); flex-wrap: wrap; }
  nav { flex-wrap: wrap; }
  table { display: block; overflow-x: auto; }
}
