/* StackBelay – minimal, dependency-free styles. */
/* Colors are variables only. Light is the default; dark follows the
   browser/OS setting (prefers-color-scheme). color-scheme makes the
   browser draw form controls and scrollbars to match. */
:root {
  color-scheme: light dark;
  --fg: #1d2127; --muted: #5d6673; --bg: #f6f7f9; --card: #fff; --input: #fff;
  --accent: #2357d9; --on-accent: #fff; --error: #b3261e; --warn: #8a5a00; --border: #d9dde3;
  --ok-bg: #dcefe0; --ok-fg: #1d6b2f; --warn-bg: #fbecc8; --err-bg: #f9dedc; --run-bg: #dbe5fb;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg); background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root {
    --fg: #e3e7ed; --muted: #9aa4b2; --bg: #14171c; --card: #1c2027; --input: #12151a;
    --accent: #7ea4ff; --on-accent: #0d1424; --error: #f28b82; --warn: #e8b44c; --border: #343a44;
    --ok-bg: #1f3a27; --ok-fg: #8fd6a2; --warn-bg: #3d3216; --err-bg: #47201d; --run-bg: #1d2b4a;
  }
}
body { margin: 0; }
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .6rem 1.2rem; background: var(--card); border-bottom: 1px solid var(--border);
}
header nav { display: flex; gap: 1rem; align-items: center; }
header form { margin: 0; }
.brand { font-weight: 700; color: var(--fg); text-decoration: none; }
main { max-width: 60rem; margin: 1.5rem auto; padding: 0 1.2rem; }
footer { max-width: 60rem; margin: 2rem auto 1rem; padding: 0 1.2rem; }
a { color: var(--accent); }
.card {
  display: grid; gap: .9rem; max-width: 24rem; padding: 1.2rem;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
}
label { display: grid; gap: .3rem; font-size: .95rem; }
input, textarea { background: var(--input); color: var(--fg); }
input { padding: .45rem .55rem; border: 1px solid var(--border); border-radius: 5px; font: inherit; }
button {
  padding: .45rem .9rem; border: 0; border-radius: 5px; background: var(--accent);
  color: var(--on-accent); font: inherit; cursor: pointer;
}
header button { background: transparent; color: var(--accent); padding: 0; }
.error { color: var(--error); font-weight: 600; }
.warning { color: var(--warn); font-weight: 600; }
.info { color: var(--accent); }
.hint { color: var(--muted); font-size: .9rem; }

/* Tables, badges, sections (stack and user pages). */
h2 { font-size: 1.15rem; margin-top: 1.8rem; }
table {
  width: 100%; border-collapse: collapse; background: var(--card);
  border: 1px solid var(--border); border-radius: 8px;
}
th, td { padding: .5rem .7rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .85rem; color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
td form { margin: 0; }
tr.missing td { color: var(--muted); }
.badge {
  display: inline-block; padding: .05rem .45rem; border-radius: 999px; font-size: .75rem;
  font-weight: 600; background: var(--border); color: var(--fg); vertical-align: middle;
}
.badge.ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.muted { color: var(--muted); }
button.secondary { background: transparent; color: var(--accent); border: 1px solid var(--border); }
form.inline { display: flex; gap: .8rem; align-items: center; }
td.actions form.inline { display: inline-flex; margin-right: .4rem; }
.actions-row { display: flex; gap: .8rem 1.6rem; flex-wrap: wrap; align-items: center; }
.actions-row + .actions-row { margin-top: .8rem; }
table + form.card { margin-top: 1rem; }
label.check { display: flex; gap: .5rem; align-items: center; }
label.check:has(input:disabled) { color: var(--muted); }
.card.wide { max-width: none; margin-bottom: 1.2rem; }
code.secret { font-size: 1.1rem; user-select: all; }
@media (max-width: 40rem) {
  table { display: block; overflow-x: auto; }
}

/* Tab bar of the stack pages. */
h1 + nav.tabs { margin-top: -.4rem; }
nav.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--border); margin-bottom: 1.2rem; }
nav.tabs a {
  padding: .5rem .9rem; text-decoration: none; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
nav.tabs a:hover { color: var(--fg); }
nav.tabs a[aria-current="page"] { color: var(--fg); border-bottom-color: var(--accent); font-weight: 600; }
textarea {
  padding: .45rem .55rem; border: 1px solid var(--border); border-radius: 5px;
  font: .9rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; resize: vertical;
}
/* The compose editor: wide, tall, no wrapping (YAML indentation matters). */
textarea.code { width: 100%; box-sizing: border-box; min-height: 60vh; white-space: pre; overflow-x: auto; tab-size: 2; }
fieldset { display: grid; gap: .4rem; margin: 0; padding: .6rem .8rem; border: 1px solid var(--border); border-radius: 5px; }
legend { font-size: .95rem; padding: 0 .3rem; }
.card.wide p.hint { margin: -.5rem 0 0; }
.section-head { display: flex; align-items: center; gap: .9rem; flex-wrap: wrap; margin-top: 1.8rem; }
.section-head h2 { margin: 0; }
.section-head form { margin: 0; }
button[disabled] { opacity: .6; cursor: progress; }
form.init { border-color: var(--accent); }
form.init p { margin: 0; }

/* Jobs. */
.badge.err { background: var(--err-bg); color: var(--error); }
.badge.run { background: var(--run-bg); color: var(--accent); }
table.details { width: auto; }
table.details th { width: 10rem; }
/* The job log is a dark terminal in both modes; its colors are fixed. */
.log {
  background: #11151b; color: #d7dde5; border-radius: 8px; padding: .8rem 1rem; overflow-x: auto;
  font: .82rem/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; max-height: 70vh; overflow-y: auto;
  border: 1px solid var(--border);
}
.log .line { white-space: pre-wrap; word-break: break-word; }
.log .ts { color: #8792a2; }
.log .lvl { display: inline-block; min-width: 3.2rem; color: #8792a2; }
.log .WARN .lvl { color: #e8b44c; }
.log .ERROR .lvl, .log .ERROR { color: #f28b82; }
.log .attrs { color: #9aa5b4; }
.log .ctr { color: var(--cc, #7cb7ff); }
/* Container colors (Logs tab): stacklog.js gives each container one of
   these classes, in the order of the container checkboxes. Light enough
   for the dark log panel; red is left out, it marks errors. */
.cc0 { --cc: #7cb7ff; } .cc1 { --cc: #8fd694; } .cc2 { --cc: #f0b45e; } .cc3 { --cc: #e88fd0; }
.cc4 { --cc: #7fd8d8; } .cc5 { --cc: #b9a2ff; } .cc6 { --cc: #d9d36a; } .cc7 { --cc: #ff9f80; }
.log .line.colored { border-left: 3px solid var(--cc); padding-left: .5rem; }
.swatch { display: inline-block; width: .8rem; height: .8rem; border-radius: 2px; background: var(--cc); }
.log .line[hidden] { display: none; }
/* Container log colors (issue #29): the ANSI colors of applications
   (web/ansi.go). The log panel is dark in both modes, so one palette is
   enough; normal colors are lifted a little to stay readable on it. */
.log .af0 { color: #6b7380; } .log .af1 { color: #f28b82; } .log .af2 { color: #8fd694; } .log .af3 { color: #e8c25e; }
.log .af4 { color: #7ea4ff; } .log .af5 { color: #e88fd0; } .log .af6 { color: #7fd8d8; } .log .af7 { color: #d7dde5; }
.log .af8 { color: #9aa4b2; } .log .af9 { color: #ff9f97; } .log .af10 { color: #a8f0ad; } .log .af11 { color: #ffe17a; }
.log .af12 { color: #a3bfff; } .log .af13 { color: #ffaee6; } .log .af14 { color: #a0f0f0; } .log .af15 { color: #ffffff; }
.log .ab0 { background: #000; } .log .ab1 { background: #6b1f1a; } .log .ab2 { background: #1f4d27; } .log .ab3 { background: #5c4a12; }
.log .ab4 { background: #1d2f66; } .log .ab5 { background: #5a1f4d; } .log .ab6 { background: #164a4a; } .log .ab7 { background: #4a525c; }
.log .ab8 { background: #3a404a; } .log .ab9 { background: #8a2a23; } .log .ab10 { background: #2a6b35; } .log .ab11 { background: #7a6318; }
.log .ab12 { background: #2a428c; } .log .ab13 { background: #7a2a68; } .log .ab14 { background: #1f6666; } .log .ab15 { background: #6b737d; }
.log .abold { font-weight: 700; } .log .adim { opacity: .7; } .log .aital { font-style: italic; } .log .aund { text-decoration: underline; }
.log.nocolor .an { color: inherit; background: none; font-weight: inherit; opacity: 1; font-style: inherit; text-decoration: none; }
fieldset.containers { display: flex; flex-wrap: wrap; gap: .3rem 1.2rem; align-items: center; }
fieldset.containers .actions { margin-left: auto; display: flex; gap: .5rem; }
.log-controls { display: flex; gap: 1.2rem; align-items: center; margin: .6rem 0; }
/* Line wrapping off: long lines scroll horizontally (.log has overflow-x). */
.log.nowrap .line { white-space: pre; word-break: normal; }
/* Full screen inside the browser window: only the log and the exit button. */
.log-frame.fullscreen {
  position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column;
  gap: .4rem; padding: .4rem; background: #11151b;
}
.log-frame.fullscreen .log { flex: 1; max-height: none; margin: 0; border-radius: 4px; }
.log-bar { display: flex; align-items: center; gap: .4rem 1rem; }
.log-bar[hidden] { display: none; }
.log-bar .log-exit { margin-left: auto; flex: none; color: #d7dde5; border-color: #3a4350; }
/* The container filter in the full-screen bar: one compact row on the dark
   background; the legend stays for screen readers only. */
.log-bar fieldset.containers { flex: 1; border: none; padding: 0; color: #d7dde5; }
.log-bar fieldset.containers legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.log-bar fieldset.containers .actions { margin-left: 0; }
.log-bar fieldset.containers button.secondary { color: #d7dde5; border-color: #3a4350; }
.log-bar fieldset.containers .hint { color: #9aa4b1; }
body.log-fullscreen { overflow: hidden; }
/* Container shell (xterm.js draws inside). */
.terminal { height: 70vh; padding: .4rem; background: #11151b; border-radius: 8px; border: 1px solid var(--border); }
.term-frame.fullscreen {
  position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column;
  gap: .4rem; padding: .4rem; background: #11151b;
}
.term-frame.fullscreen .terminal { flex: 1; min-height: 0; height: auto; border-color: #3a4350; }
.term-bar { display: flex; align-items: center; gap: 1rem; color: #d7dde5; }
.term-bar[hidden] { display: none; }
.term-bar .term-title { font-weight: 600; }
.term-bar .term-exit { margin-left: auto; color: #d7dde5; border-color: #3a4350; }
body.term-fullscreen { overflow: hidden; }
button[disabled] { opacity: .5; cursor: not-allowed; }
.log:empty { display: none; }

/* Busy state (static/forms.js, HTMX): a spinner in the submit button while
   the server works; .busy-text appears next to an HTMX form's button. */
@keyframes spin { to { transform: rotate(360deg); } }
button.busy::before, form.htmx-request button::before {
  content: ""; display: inline-block; width: .8em; height: .8em; margin-right: .45em; vertical-align: -.1em;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin .8s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
  button.busy::before, form.htmx-request button::before { animation-duration: 2.4s; }
}
.busy-text { display: none; }
form.htmx-request .busy-text { display: inline; }

/* Progress of a running job (job page). */
.progress p { margin: .2rem 0; }
.progress progress { width: 100%; height: .9rem; accent-color: var(--accent); }

/* Stack list (issue #37): column groups and status dots. */
.table-scroll { overflow-x: auto; }
.stack-list th.group { text-align: center; border-left: 1px solid var(--border); }
.stack-list .group-start { border-left: 1px solid var(--border); }
.stack-list td { white-space: nowrap; }
.dot {
  display: inline-block; min-width: 1.3em; height: 1.3em; line-height: 1.3em; border-radius: 50%;
  text-align: center; font-size: .8rem; font-weight: 700; background: var(--border); color: var(--fg);
  vertical-align: middle;
}
.dot.ok { background: var(--ok-bg); color: var(--ok-fg); }
.dot.err { background: var(--err-bg); color: var(--error); }
.dot.run { background: var(--run-bg); color: var(--accent); animation: dot-pulse 1.5s ease-in-out infinite; }
@keyframes dot-pulse { 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { .dot.run { animation: none; } }

