:root {
  --bg: #f5f7f7;
  --surface: #ffffff;
  --surface-2: #f0f3f3;
  --text: #13262f;
  --muted: #5d6e76;
  --border: #dde4e6;
  --header: #001e2b;
  --header-text: #e8f0ee;
  --accent: #00684a;
  --accent-hover: #00543c;
  --accent-soft: #e3f6ec;
  --bright: #00ed64;
  --danger: #c4302b;
  --danger-soft: #fdecea;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --info-soft: #e8f1fb;
  --info: #1a5a96;
  --log-bg: #0e1a20;
  --log-text: #d3dde0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 32, 40, 0.06), 0 2px 8px rgba(16, 32, 40, 0.05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1418;
    --surface: #111e24;
    --surface-2: #16262d;
    --text: #e3eaec;
    --muted: #93a4ab;
    --border: #23363e;
    --header: #06131a;
    --accent: #00a35c;
    --accent-hover: #00b866;
    --accent-soft: #0f2e22;
    --danger: #f0625c;
    --danger-soft: #3a1716;
    --warn: #e6b450;
    --warn-soft: #33290f;
    --info-soft: #132739;
    --info: #8cbdf0;
    --log-bg: #060d10;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: 1.75rem; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 0.95rem; }
p { margin: 0 0 0.8em; }
code, pre { font-family: var(--mono); font-size: 0.9em; }
code { background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 4px; }
img { max-width: 100%; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 28px; padding-bottom: 64px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hint { display: block; color: var(--muted); font-size: 0.82rem; font-weight: 400; margin-top: 4px; }
.error-text { color: var(--danger); }
[hidden] { display: none !important; }

/* Top bar */
.topbar { background: var(--header); color: var(--header-text); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; gap: 24px; min-height: 56px; flex-wrap: wrap; }
.brand { color: #fff; font-weight: 700; font-size: 1.05rem; display: flex; align-items: center; gap: 10px; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 14px; height: 14px; border-radius: 4px; background: var(--bright); box-shadow: 6px 6px 0 -2px rgba(0, 237, 100, 0.45); display: inline-block; margin-right: 4px; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a, .me a { color: var(--header-text); opacity: 0.8; padding: 6px 10px; border-radius: 6px; font-size: 0.92rem; white-space: nowrap; }
.nav a:hover, .me a:hover { opacity: 1; text-decoration: none; background: rgba(255, 255, 255, 0.07); }
.nav a.active, .me a.active { opacity: 1; background: rgba(0, 237, 100, 0.14); color: #fff; }
.me { display: flex; align-items: center; gap: 4px; }
.me form { margin: 0; }
button.link { background: none; border: 0; color: var(--header-text); opacity: 0.7; cursor: pointer; font: inherit; font-size: 0.92rem; padding: 6px 10px; }
button.link:hover { opacity: 1; }

/* Buttons and forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550; font-size: 0.92rem;
  cursor: pointer; white-space: nowrap; line-height: 1.2;
}
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-ghost { background: transparent; color: var(--danger); border-color: transparent; }
.btn-danger-ghost:hover { background: var(--danger-soft); border-color: var(--danger-soft); }
.btn-small { padding: 5px 10px; font-size: 0.85rem; }
.btn input[type=file] { display: none; }
form.inline { display: inline; margin: 0; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }

input:not([type=checkbox]):not([type=radio]), select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; font-weight: 400; margin-top: 4px;
}
textarea { font-family: var(--mono); font-size: 0.88rem; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-weight: 550; font-size: 0.92rem; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; margin: 0; }
fieldset.row { border: 0; padding: 0; }
legend { font-weight: 600; font-size: 0.9rem; padding: 0 4px; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > label { flex: 1 1 180px; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 16px; max-height: 280px; overflow: auto; }

/* Layout pieces */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 20px; }
.panel.narrow { max-width: 560px; margin: 0 auto; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.grid-2.grid-wide-left { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; align-items: start; }
.grid-2 > .panel, .grid-3 > .panel { margin-bottom: 0; }
.grid-2, .grid-3 { margin-bottom: 20px; }
.page-head, .project-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1, .project-head h1 { margin: 0; }
.crumbs { color: var(--muted); font-size: 0.85rem; margin: 0 0 4px; }
.empty { text-align: center; padding: 64px 16px; }
.danger-zone { border-color: var(--danger-soft); }
.danger-zone h2 { color: var(--danger); }
.danger-zone .row input { max-width: 280px; margin: 0; }

.flash { border-radius: 8px; padding: 10px 14px; margin-bottom: 18px; border: 1px solid transparent; }
.flash ul { margin: 6px 0 0; padding-left: 20px; }
.flash-ok { background: var(--accent-soft); border-color: var(--accent); }
.flash-error { background: var(--danger-soft); border-color: var(--danger); }
.flash-info { background: var(--info-soft); border-color: var(--info); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 8px; }
.kv dt { color: var(--muted); font-size: 0.88rem; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li + li { margin-top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.badge-off { opacity: 0.55; text-decoration: line-through; }
form.stack + .panel, form.stack + section { margin-top: 24px; }
.list-rows li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
ol.steps { padding-left: 20px; }
ol.steps li + li { margin-top: 6px; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 22px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 550; font-size: 0.93rem; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel .table-wrap { border: 0; box-shadow: none; }
.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.row-disabled { opacity: 0.55; }
.table td.nowrap { white-space: nowrap; }
.table .col-description { min-width: 200px; max-width: 400px; color: var(--muted); }
.table .col-default { min-width: 140px; max-width: 240px; overflow-wrap: break-word; }
.table .col-default code { white-space: nowrap; }

/* Badges and statuses */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: 0.78rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.badge-small { font-size: 0.7rem; padding: 0 6px; }
.badge-ok, .badge-stable { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge-warn, .badge-experimental, .badge-idea { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-beta { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge-error { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; font-weight: 600; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-running .dot, .status-job-success .dot { background: #12b55f; }
.status-starting .dot, .status-stopping .dot, .status-job-running .dot, .status-job-queued .dot { background: #e0a100; animation: pulse 1.2s infinite; }
.status-crashed .dot, .status-job-failed .dot { background: var(--danger); }
.status-job-failed { color: var(--danger); }
@keyframes pulse { 50% { opacity: 0.35; } }

/* Catalog */
.catalog-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 24px; flex-wrap: wrap; }
.catalog-head h1 { margin: 0; }
.catalog-head p { margin: 4px 0 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input, .filters select { margin: 0; width: auto; }
.filters input[type=search] { width: 280px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.card { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; color: inherit; box-shadow: var(--shadow); transition: transform 0.12s ease, border-color 0.12s ease; }
.card:hover { text-decoration: none; transform: translateY(-2px); border-color: var(--accent); }
.card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card-body h2 { font-size: 1.05rem; margin: 0; }
.card-body p { color: var(--muted); font-size: 0.9rem; margin: 0; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { display: flex; align-items: center; gap: 8px; font-size: 0.78rem; }
.kind { text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; color: var(--muted); }
.live { color: #0a8f4a; font-weight: 700; display: inline-flex; align-items: center; gap: 4px; }
.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #12b55f; }
.tags { list-style: none; padding: 0; margin: 4px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.tags li { font-size: 0.76rem; background: var(--surface-2); border-radius: 6px; padding: 2px 8px; color: var(--muted); }
.tags a { color: inherit; }
.cover { background: var(--surface-2); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.cover-card { aspect-ratio: 16 / 8; }
.cover-hero { aspect-ratio: 16 / 10; border-radius: var(--radius); border: 1px solid var(--border); }
.cover img { width: 100%; height: 100%; object-fit: cover; }
.cover-generated { background: linear-gradient(135deg, hsl(var(--hue) 55% 22%), hsl(calc(var(--hue) + 40) 60% 34%)); }
.cover-generated span { color: rgba(255, 255, 255, 0.9); font-weight: 800; font-size: 2.2rem; letter-spacing: 0.04em; }
.cover-hero.cover-generated span { font-size: 3.4rem; }
.empty-filter { text-align: center; padding: 40px 0; }

/* Project page */
.project-hero { display: grid; grid-template-columns: minmax(0, 360px) minmax(0, 1fr); gap: 28px; align-items: start; margin-bottom: 32px; }
.lead { font-size: 1.1rem; color: var(--muted); }
.hero-badges { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.hero-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 18px; }
.project-layout { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 32px; }
.project-side section { border-top: 1px solid var(--border); padding-top: 12px; margin-bottom: 18px; }
.project-side h3 { text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.05em; color: var(--muted); }
.markdown { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px 28px; min-width: 0; }
.markdown h1 { font-size: 1.5rem; }
.markdown h1, .markdown h2 { padding-bottom: 6px; border-bottom: 1px solid var(--border); margin-top: 1.4em; }
.markdown h1:first-child, .markdown h2:first-child { margin-top: 0; }
.markdown pre { background: var(--surface-2); padding: 12px 14px; border-radius: 8px; overflow-x: auto; }
.markdown pre code { background: none; padding: 0; }
.markdown table { border-collapse: collapse; display: block; overflow-x: auto; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 6px 10px; }
.markdown blockquote { margin: 0 0 1em; padding: 4px 16px; border-left: 3px solid var(--border); color: var(--muted); }
.markdown img { border-radius: 6px; }
.contract { max-width: 900px; }
.markdown ul:has(> li > input[type=checkbox]) { list-style: none; padding-left: 4px; }
.markdown li > input[type=checkbox] { margin-right: 8px; }

/* Logs */
.log {
  background: var(--log-bg); color: var(--log-text); border-radius: var(--radius);
  padding: 14px 16px; margin: 0; height: 62vh; overflow: auto; font-size: 0.82rem; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
}
.log .l-err { color: #ff9b8f; }
.log .l-sys { color: #7fd7a8; }
.log .ts { color: #5d7a85; margin-right: 8px; user-select: none; }
.log.log-short { height: 40vh; }
.job-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.job-head h2 { display: flex; align-items: center; gap: 12px; margin: 0; text-transform: capitalize; }

/* Secrets, data */
.secret-form { display: flex; gap: 6px; align-items: center; }
.secret-form input { margin: 0; min-width: 150px; }
.under { margin-top: 4px; }
code.copy { cursor: pointer; overflow-wrap: anywhere; }
code.copy.copied { outline: 1px solid var(--accent); }
code.secret:not(.revealed) { filter: blur(5px); }
.drop { border: 2px dashed var(--border); border-radius: var(--radius); padding: 24px; text-align: center; background: var(--surface-2); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .row { justify-content: center; }
.drop .row > label { flex: 0 0 auto; }
progress { width: 100%; height: 10px; }
.tree { list-style: none; padding: 0; margin: 0; font-family: var(--mono); font-size: 0.85rem; max-height: 420px; overflow: auto; }
.tree li { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0 2px calc(var(--depth) * 18px); }
.tree li.dir > span:first-child { font-weight: 700; }
.tree li.dir > span:first-child::after { content: "/"; color: var(--muted); }

/* Auth */
.auth-card { max-width: 380px; margin: 8vh auto 0; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 32px; box-shadow: var(--shadow); }

@media (max-width: 900px) {
  .grid-3 { grid-template-columns: 1fr; }
  .grid-2, .grid-2.grid-wide-left { grid-template-columns: 1fr; }
  .project-hero, .project-layout { grid-template-columns: 1fr; }
  .filters { width: 100%; }
  .filters input[type=search] { width: auto; flex: 1 1 100%; }
  .topbar-inner { gap: 6px 16px; padding-top: 10px; padding-bottom: 6px; }
  .me { margin-left: auto; }
  .nav { order: 3; flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; margin: 0 -10px; }
}
@media (max-width: 600px) {
  .topbar { position: static; }
  .markdown { padding: 16px; }
  .secret-form { flex-wrap: wrap; }
  .kv { grid-template-columns: 1fr; gap: 0 0; }
  .kv dd { margin-bottom: 8px; }
}
