/* Design tokens, app shell, lists, forms, flash, status badges. */
:root {
  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --radius: 0.625rem;
  --shell-width: 46rem;

  /* Type */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, monospace;

  /* Colour — LCH triplets, recombined as oklch() so dark mode is one override. */
  --lch-bg: 99% 0.003 250;
  --lch-surface: 100% 0 0;
  --lch-ink: 23% 0.02 260;
  --lch-muted: 55% 0.02 260;
  --lch-border: 90% 0.01 260;
  --lch-accent: 55% 0.16 255;
  --lch-positive: 62% 0.15 150;
  --lch-warning: 72% 0.15 75;
  --lch-negative: 60% 0.2 25;

  --color-bg: oklch(var(--lch-bg));
  --color-surface: oklch(var(--lch-surface));
  --color-ink: oklch(var(--lch-ink));
  --color-muted: oklch(var(--lch-muted));
  --color-border: oklch(var(--lch-border));
  --color-accent: oklch(var(--lch-accent));
  --color-positive: oklch(var(--lch-positive));
  --color-warning: oklch(var(--lch-warning));
  --color-negative: oklch(var(--lch-negative));
  --color-on-accent: oklch(99% 0 0);

  /* Brand — rose→amber gradient (home page) and a warm link/accent colour for
     admin chrome (boxes, forms). Kept separate from --color-accent (blue), which
     still drives status semantics and the conversation surface. */
  --brand-gradient: linear-gradient(to right, #f43f5e, #f59e0b);
  --color-brand: oklch(62% 0.19 40);
}

@media (prefers-color-scheme: dark) {
  :root {
    --lch-bg: 18% 0.012 260;
    --lch-surface: 23% 0.015 260;
    --lch-ink: 93% 0.01 260;
    --lch-muted: 68% 0.02 260;
    --lch-border: 33% 0.015 260;
    --lch-accent: 72% 0.15 248;
    --lch-positive: 72% 0.15 150;
    --lch-warning: 80% 0.14 80;
    --lch-negative: 68% 0.18 25;
    --color-brand: oklch(80% 0.15 65);
  }
}

body {
  font-family: var(--font-sans);
  background-color: var(--color-bg);
  color: var(--color-ink);
}

:where(a) {
  color: var(--color-accent);
  text-underline-offset: 0.15em;
}

:where(h1) {
  font-size: clamp(1.4rem, 5vw, 1.9rem);
  line-height: 1.2;
  letter-spacing: -0.01em;
}

code {
  font-family: var(--font-mono);
  font-size: 0.875em;
}

:is(a, button, input, textarea, select):focus-visible {
  outline: max(2px, 0.1em) solid var(--color-accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* --- Shell ------------------------------------------------------------- */
:where(main) {
  inline-size: min(100% - var(--space-6), var(--shell-width));
  margin-inline: auto;
  padding-block: var(--space-6) var(--space-8);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

main > header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
}

main > header nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

/* --- VIBESI.DE wordmark (Knewave + rose→amber gradient clip) ------------ */
.app-wordmark {
  font-family: "Knewave", system-ui, cursive;
  font-weight: 400;
  letter-spacing: 0.02em;
  line-height: 1;
  background: linear-gradient(to right, #f43f5e, #f59e0b);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.projects > header { align-items: center; }
.projects > header .app-wordmark { font-size: 1.875rem; }

/* "New project" — rose→amber gradient pill (matches vibeside_old). */
.nav-add {
  display: inline-flex;
  align-items: center;
  block-size: 2.5rem;
  padding-inline: var(--space-4);
  border-radius: 999px;
  font-weight: 600;
  color: #fff;
  text-decoration: none;
  background: linear-gradient(to right, #f43f5e, #f59e0b);
  box-shadow: 0 1px 2px oklch(0% 0 0 / 0.15);
  transition: box-shadow 0.15s ease, filter 0.15s ease;
}

.nav-add:hover {
  box-shadow: 0 4px 12px oklch(0% 0 0 / 0.22);
  filter: brightness(1.05);
}

/* --- "..." disclosure menu --------------------------------------------- */
.menu { position: relative; }

.menu-trigger {
  list-style: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: 2.25rem;
  block-size: 2.25rem;
  border-radius: 999px;
  color: var(--color-muted);
  cursor: pointer;
}

.menu-trigger::-webkit-details-marker { display: none; }
.menu-trigger::marker { content: ""; }
.menu-trigger:hover { background: var(--color-surface); color: var(--color-ink); }

/* Index disclosure: rose→amber gradient ring matching the brand. */
.projects > header .menu-trigger {
  border: 1.5px solid transparent;
  color: #f43f5e;
  background:
    linear-gradient(var(--color-bg), var(--color-bg)) padding-box,
    linear-gradient(120deg, #f43f5e, #f59e0b) border-box;
}

.projects > header .menu-trigger:hover {
  background:
    linear-gradient(var(--color-surface), var(--color-surface)) padding-box,
    linear-gradient(120deg, #f43f5e, #f59e0b) border-box;
}

.menu-list {
  position: absolute;
  inset-inline-end: 0;
  inset-block-start: calc(100% + var(--space-2));
  min-inline-size: 9rem;
  display: flex;
  flex-direction: column;
  padding: var(--space-1);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px oklch(0% 0 0 / 0.18);
  z-index: 50;
}

.menu-list form { margin: 0; }

/* `.menu` prefix raises specificity above the global button rule so the
   button_to "Sign out" item matches the "Boxes" link exactly. */
.menu .menu-list a,
.menu .menu-list button {
  display: block;
  inline-size: 100%;
  text-align: start;
  padding: var(--space-2) var(--space-3);
  border-radius: calc(var(--radius) - 0.2rem);
  font: inherit;
  color: var(--color-ink);
  text-decoration: none;
  background: transparent;
  border: none;
  cursor: pointer;
}

.menu .menu-list a:hover,
.menu .menu-list button:hover:not(:disabled) { background: var(--color-bg); }

.menu .menu-list button:disabled {
  color: var(--color-muted);
  opacity: 0.5;
  cursor: not-allowed;
}

.empty {
  color: var(--color-muted);
  padding-block: var(--space-6);
}

/* --- Cards / registry lists -------------------------------------------- */
:where(.project-list, .box-list) {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

:where(.project-list, .box-list) > li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-4);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.project-name,
.box-name {
  font-weight: 600;
}

.project-box,
.box-count,
.box-checked {
  color: var(--color-muted);
  font-size: 0.85rem;
}

.box-url {
  color: var(--color-muted);
  word-break: break-all;
}

/* The link carries the card padding so the whole card is clickable. */
.project-list > li { padding: 0; }

.project-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  inline-size: 100%;
  padding: var(--space-4);
  border-radius: var(--radius);
  color: inherit;
  text-decoration: none;
}

.row-dots {
  margin-inline-start: auto;
  display: inline-flex;
  gap: var(--space-2);
}

/* --- Status & health badges -------------------------------------------- */
.task-status,
.box-health {
  --badge: var(--color-muted);
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  padding-inline: var(--space-2);
  padding-block: 0.1rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--badge);
  background-color: oklch(from var(--badge) l c h / 0.14);
  border: 1px solid oklch(from var(--badge) l c h / 0.3);
}

.task-status-running { --badge: var(--color-accent); }
.task-status-needs_review { --badge: var(--color-warning); }
.task-status-failed { --badge: var(--color-negative); }
.task-status-merged { --badge: var(--color-positive); }

.box-health-up { --badge: var(--color-positive); }
.box-health-unauthorized { --badge: var(--color-warning); }
.box-health-unreachable { --badge: var(--color-negative); }

/* --- Forms ------------------------------------------------------------- */
:where(.form, .auth) form {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

:where(.form, .auth) label {
  font-weight: 600;
  font-size: 0.9rem;
  margin-block-start: var(--space-3);
}

:where(input, textarea, select) {
  inline-size: 100%;
  padding: var(--space-2) var(--space-3);
  font-size: max(16px, 1rem); /* avoids iOS zoom */
  background-color: var(--color-surface);
  color: var(--color-ink);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

:where(input, textarea):focus {
  border-color: var(--color-accent);
}

textarea {
  resize: vertical;
}

/* --- Buttons / submit -------------------------------------------------- */
:where(input[type="submit"], button) {
  cursor: pointer;
}

:where(.form, .auth) input[type="submit"],
button.btn,
input.btn {
  inline-size: auto;
  align-self: start;
  margin-block-start: var(--space-4);
  block-size: 2.5rem;
  padding-inline: var(--space-6);
  border-radius: 999px;
  border-color: transparent;
  font-weight: 600;
  color: #fff;
  background: var(--brand-gradient);
  box-shadow: 0 1px 2px oklch(0% 0 0 / 0.15);
  transition: box-shadow 0.15s ease, filter 0.15s ease;
}

:where(.form, .auth) input[type="submit"]:hover,
button.btn:hover,
input.btn:hover {
  box-shadow: 0 4px 12px oklch(0% 0 0 / 0.22);
  filter: brightness(1.05);
}

/* Submit + Cancel on one line; the row owns the top spacing. */
.form-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-block-start: var(--space-6);
}

/* Equal height + shared vertical centring. Specificity here must MATCH the
   submit's own rule (0,1,1) so `align-self: center` beats its `align-self: start`;
   `:where()` would zero it out and lose. */
.form-actions input[type="submit"],
.form-actions .btn,
.form-actions input.btn,
.form-actions .btn-cancel {
  margin-block-start: 0;
  align-self: center;
  box-sizing: border-box;
  block-size: 2.5rem;
  padding-block: 0;
  line-height: 1;
}

/* Outline secondary action, sized to match the gradient primary pill. */
.btn-cancel {
  display: inline-flex;
  align-items: center;
  block-size: 2.5rem;
  padding-inline: var(--space-4);
  border-radius: 999px;
  font-weight: 600;
  text-decoration: none;
  color: var(--color-ink);
  background: transparent;
  border: 1px solid var(--color-border);
  transition: border-color 0.15s ease, color 0.15s ease;
}

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

button:not(.btn),
form button {
  padding: var(--space-1) var(--space-3);
  font-size: 0.85rem;
  background-color: var(--color-surface);
  color: var(--color-ink);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

/* --- Errors & flash ---------------------------------------------------- */
.errors {
  padding: var(--space-3) var(--space-4);
  color: var(--color-negative);
  background-color: oklch(from var(--color-negative) l c h / 0.1);
  border: 1px solid oklch(from var(--color-negative) l c h / 0.3);
  border-radius: var(--radius);
}

/* Toast notifications: fixed, top-centered, out of flow, auto-fading. */
.flashes {
  position: fixed;
  inset-block-start: var(--space-4);
  inset-inline: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  pointer-events: none;
}

.flash {
  pointer-events: auto;
  max-inline-size: min(92vw, var(--shell-width));
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background-color: var(--color-surface);
  box-shadow: 0 8px 24px oklch(0% 0 0 / 0.22);
  opacity: 1;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.flash.flash-leaving {
  opacity: 0;
  transform: translateY(-0.5rem);
}

.flash-notice { border-color: oklch(from var(--color-positive) l c h / 0.4); }
.flash-alert { border-color: oklch(from var(--color-negative) l c h / 0.4); }

/* --- Warm admin links — harmonize the boxes/forms chrome with the brand --- */
.boxes .empty a { color: var(--color-brand); }

/* --- Per-box GitHub connect -------------------------------------------- */
.box-github { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-block-start: var(--space-2); }
.box-github form { margin: 0; } /* button_to wrapper */
.github-chip { font-size: 0.8rem; color: var(--color-muted); }
.github-chip.is-connected { color: var(--color-positive); }
.github-meta { font-size: 0.8rem; color: var(--color-muted); }

/* GitHub action buttons (Connect / Manage / Disconnect) — small pill buttons.
   Scoped under .box-github so they beat the global `button:not(.btn)` rule. */
.box-github .btn-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  block-size: 1.9rem;
  padding-block: 0;
  padding-inline: var(--space-3);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1;
  border-radius: 999px;
  text-decoration: none;
  color: var(--color-ink);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.box-github .btn-chip:hover {
  border-color: var(--color-brand);
  color: var(--color-brand);
}

.box-github .btn-chip-danger:hover {
  border-color: var(--color-negative);
  color: var(--color-negative);
}

/* --- New Project flow -------------------------------------------------- */
/* Source picker — big segmented buttons. The native radio is visually hidden;
   each label is a tappable card, highlighted when its radio is checked. */
.source-tabs { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.source-tabs label {
  flex: 1 1 7rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-block-size: 2.75rem;
  padding: var(--space-2) var(--space-3);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--color-ink);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}
.source-tabs label:hover { border-color: var(--color-brand); }
.source-tabs input[type="radio"] {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}
.source-tabs label:has(input:checked) {
  border-color: var(--color-brand);
  color: var(--color-brand);
  background: oklch(from var(--color-brand) l c h / 0.12);
}
.source-tabs label:has(input:focus-visible) {
  outline: max(2px, 0.1em) solid var(--color-accent);
  outline-offset: 2px;
}
.source-pane { display: flex; flex-direction: column; gap: var(--space-2); }
.github-hint { color: var(--color-muted); font-size: 0.85rem; }
.creating-note { color: var(--color-muted); font-size: 0.85rem; }

/* --- Settings tabs ----------------------------------------------------- */
.tabs {
  display: flex;
  gap: var(--space-1);
  border-block-end: 1px solid var(--color-border);
  margin-block-end: var(--space-6);
}
.tabs a {
  padding: var(--space-3) var(--space-4);
  color: var(--color-muted);
  text-decoration: none;
  font-weight: 600;
  border-block-end: 2px solid transparent;
  margin-block-end: -1px;
}
.tabs a:hover { color: var(--color-ink); }
.tabs a.is-active {
  color: var(--color-ink);
  border-block-end-color: var(--color-brand);
}

/* --- Settings page back link (distinct from the workspace `.back-link` pill) -- */
.settings-back {
  display: inline-block;
  margin-block-end: var(--space-4);
  color: var(--color-muted);
  text-decoration: none;
  font-weight: 600;
}
.settings-back:hover { color: var(--color-ink); }

/* Native select: give the dropdown arrow a little breathing room from the edge. */
select { padding-inline-end: var(--space-6); }

/* --- Settings summary: publish toggle + production info (above the tabs) -- */
.publish-control {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-block-end: var(--space-6);
}
.publish-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3);
}
.publish-control form { margin: 0; }

.publish-meta-item {
  margin: 0;
  font-size: 0.9rem;
}
.meta-label {
  display: inline-block;
  min-inline-size: 9rem;
  color: var(--color-muted);
  font-weight: 600;
}
.repo-path { font-family: var(--font-mono); }

.publish-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.publish-toggle:hover { border-color: var(--color-brand); }

.publish-toggle .switch {
  position: relative;
  flex-shrink: 0;
  inline-size: 1.75rem;
  block-size: 1rem;
  border-radius: 999px;
  background: var(--color-border);
  transition: background-color 0.15s ease;
}
.publish-toggle .switch::after {
  content: "";
  position: absolute;
  inset-block-start: 0.125rem;
  inset-inline-start: 0.125rem;
  inline-size: 0.75rem;
  block-size: 0.75rem;
  border-radius: 999px;
  background: #fff;
  transition: inset-inline-start 0.15s ease;
}
.publish-toggle.is-on .switch { background: var(--color-positive); }
.publish-toggle.is-on .switch::after { inset-inline-start: 0.875rem; }

.publish-toggle.is-disabled,
.publish-toggle.is-building {
  cursor: default;
  color: var(--color-muted);
}
.publish-toggle.is-disabled:hover,
.publish-toggle.is-building:hover { border-color: var(--color-border); }

.publish-url {
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 600;
}
.publish-url:hover { text-decoration: underline; }

.publish-hint {
  font-size: 0.85rem;
  color: var(--color-muted);
  text-decoration: none;
}
.publish-hint:hover { color: var(--color-ink); }

/* --- Environment variables --------------------------------------------- */
/* Space above the section so its header doesn't hug the form's Save button. */
.env-section { margin-block: var(--space-8); }

.env-table {
  inline-size: 100%;
  border-collapse: collapse;
  margin-block: var(--space-3);
  font-size: 0.9rem;
}
.env-table th {
  text-align: start;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-muted);
  padding: var(--space-2) var(--space-3);
  border-block-end: 1px solid var(--color-border);
}
.env-table td {
  padding: var(--space-2) var(--space-3);
  border-block-end: 1px solid var(--color-border);
  vertical-align: middle;
}
.env-table td:first-child { font-family: var(--font-mono); }
.env-table .masked { color: var(--color-muted); letter-spacing: 0.1em; }
.env-table .muted { color: var(--color-muted); }
.env-table .env-actions {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
}

/* Inline add-row: KEY | value | [secret] Add — aligned, not stacked. */
.env-add {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: var(--space-3);
  align-items: center;
  margin-block-start: var(--space-3);
}
.env-add input[type="text"] { margin: 0; }
.env-add .checkbox {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  white-space: nowrap;
  color: var(--color-muted);
}
/* The global :where(input) rule sets inline-size:100% on every input, which
   would stretch the bare checkbox across the grid cell — keep it intrinsic. */
.env-add .checkbox input[type="checkbox"] { inline-size: auto; padding: 0; }
.env-add input[type="submit"] { margin: 0; align-self: center; }

@media (max-width: 32rem) {
  .env-add { grid-template-columns: 1fr 1fr; }
}
