:root {
  --bg: #0c0e12;
  --surface: #161a21;
  --surface-2: #1d2230;
  --text: #e7e9ec;
  --muted: #8c93a0;
  --accent: #5b8def;
  --accent-strong: #3a6dd9;
  --danger: #ef5b5b;
  --success: #4ade80;
  --border: #262c38;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Inter, sans-serif;
  min-height: 100vh;
}

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

button, input, select, textarea {
  font: inherit; color: inherit;
}

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 16px; color: var(--text); }
.userbar { display: flex; gap: 12px; align-items: center; font-size: 13px; color: var(--muted); }
.userbar .signedin { color: var(--text); }
.userbar button { background: none; border: none; color: var(--muted); cursor: pointer; }
.userbar button:hover { color: var(--text); }

main { max-width: 980px; margin: 0 auto; padding: 32px 24px; }

h1 { font-size: 22px; margin: 0 0 16px; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 24px 0 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

form.stack { display: flex; flex-direction: column; gap: 12px; }
form.stack label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
form.stack input, form.stack textarea, form.stack select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  color: var(--text);
}
form.stack input:focus, form.stack textarea:focus {
  outline: none; border-color: var(--accent);
}

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); border-color: rgba(239,91,91,0.3); }
.btn.danger:hover { background: rgba(239,91,91,0.1); }
.btn.sm { padding: 4px 10px; font-size: 12px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 0 -20px 20px; padding: 0 20px; }
.tabs button {
  background: transparent; border: none;
  padding: 10px 14px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent;
}
.tabs button.active { color: var(--text); border-color: var(--accent); }
.tabs button:hover { color: var(--text); }

.empty { color: var(--muted); font-size: 13px; padding: 24px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }

table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
table th, table td {
  padding: 10px 12px; text-align: left;
  border-bottom: 1px solid var(--border);
}
table th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
table tr:last-child td { border-bottom: none; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; }
.muted { color: var(--muted); }

.tag {
  display: inline-block; padding: 2px 8px;
  border-radius: 999px; font-size: 11px;
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border);
}
.tag.ok { color: var(--success); border-color: rgba(74,222,128,0.3); }
.tag.warn { color: #fbbf24; border-color: rgba(251,191,36,0.3); }

.userbar-name {
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
}
.userbar-name:hover { color: var(--accent); }

.field-error {
  display: block;
  min-height: 16px;
  margin-top: 4px;
  color: var(--danger);
  font-size: 12px;
}
.field-hint {
  display: block;
  margin-top: 4px;
  font-size: 12px;
}
input.invalid {
  border-color: var(--danger) !important;
}
input.invalid:focus {
  outline-color: var(--danger);
}

.divider {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0;
  color: var(--muted);
  font-size: 12px;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.token-copy {
  appearance: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  padding: 3px 8px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.token-copy:hover {
  background: rgba(91,141,239,0.12);
  border-color: var(--accent);
}
.token-copy:active {
  background: rgba(91,141,239,0.22);
}

/* Stage tabs sit at the very top edge of the .card they're inside, sharing
   the look of the app-level .tabs but bound to a single card. The negative
   margin pulls the row up to cancel the card's 20px top padding. */
.stage-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin: -20px -20px 16px;
  padding: 0 12px;
}
.stage-tabs > button[data-stage] {
  appearance: none;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 12px 16px;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
  /* nudge button border-bottom flush against the row border-bottom */
  margin-bottom: -1px;
}
.stage-tabs > button[data-stage]:hover { color: var(--text); }
.stage-tabs > button[data-stage].active {
  color: var(--text);
  border-color: var(--accent);
  cursor: default;
}
.stage-tabs-actions {
  margin-left: auto;
  gap: 8px;
  padding: 6px 0;
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  color: var(--muted);
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: rgba(91,141,239,0.05);
  color: var(--text);
}
.dropzone .dz-title { font-size: 14px; }
.dropzone .dz-title strong { color: var(--text); }
.dropzone .dz-hint { font-size: 12px; max-width: 480px; line-height: 1.5; }
/* Action buttons inside the dropzone — `pointer-events: auto` makes sure
   the buttons stay clickable even when the parent <label> claims clicks
   for its file input. */
.dropzone .dz-actions { margin-top: 4px; gap: 8px; justify-content: center; }
.dropzone .dz-actions .btn { pointer-events: auto; cursor: pointer; }
.dropzone input[type=file] { display: none; }

.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  max-width: 360px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  z-index: 100;
}
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--success); }

.auth-wrap { max-width: 380px; margin: 64px auto; }
.auth-wrap h1 { text-align: center; }
.auth-switch { text-align: center; margin-top: 12px; font-size: 13px; color: var(--muted); }

.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.preview-link {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px;
}

.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 560px; width: 100%;
  max-height: 85vh; overflow: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}
.modal h2 { font-size: 16px; color: var(--text); text-transform: none; letter-spacing: 0; margin-bottom: 12px; }
.modal label { font-size: 12px; }

.breadcrumb {
  font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.breadcrumb a { color: var(--text); }
.breadcrumb a:hover { color: var(--accent); }

a.folder-link {
  font-weight: 500;
  text-decoration: none;
}
a.folder-link:hover { color: var(--accent); text-decoration: underline; }
