:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #eef0f3;
  --text: #1c2128;
  --muted: #6b7280;
  --accent: #3563e9;
  --danger: #c22a20;
  --ok: #16794f;
  --warn: #8a5c00;
  --border: #dde1e6;

  --sidebar-width: 15rem;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.app-shell { display: flex; align-items: stretch; height: 100vh; }

/* --- Sidebar --- */

.sidebar {
  flex: none;
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 0.9rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-head .brand-logo { height: 1.5rem; width: auto; flex: none; }
.sidebar-head .brand { font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; overflow: hidden; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  white-space: nowrap;
}
.sidebar-link:hover { background: var(--panel-2); color: var(--text); }
.sidebar-link.active { background: rgba(53,99,233,0.1); color: var(--accent); font-weight: 600; }
.sidebar-icon { flex: none; display: flex; }
.sidebar-label { overflow: hidden; text-overflow: ellipsis; }

.sidebar-step-icon {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 0.72rem;
}
.sidebar-step.active { background: rgba(53,99,233,0.1); color: var(--text); font-weight: 400; }
.sidebar-step.active .sidebar-step-icon { background: var(--accent); color: #fff; }
.sidebar-step.passed .sidebar-step-icon { background: var(--ok); color: #fff; }

.sidebar-empty { padding: 0.4rem 0.7rem; font-size: 0.82rem; }

.sidebar-user {
  flex: none;
  border-top: 1px solid var(--border);
  padding: 0.6rem;
}
.user-menu { position: relative; }
.user-menu > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.5rem;
  border-radius: 8px;
}
.user-menu > summary::-webkit-details-marker,
.user-menu > summary::marker { display: none; content: ""; }
.user-menu > summary:hover { background: var(--panel-2); }

.user-avatar {
  flex: none;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.85rem;
}
.user-meta { display: flex; flex-direction: column; overflow: hidden; }
.user-name { font-size: 0.85rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.user-menu-popup {
  position: absolute;
  bottom: calc(100% + 0.4rem);
  left: 0.5rem;
  right: 0.5rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(20,26,36,0.14);
  padding: 0.3rem;
  z-index: 10;
}
.user-menu-popup form.inline { display: block; margin: 0; }
.user-menu-popup button.link { display: block; width: 100%; text-align: left; padding: 0.5rem 0.6rem; border-radius: 6px; }
.user-menu-popup button.link:hover { background: var(--panel-2); }

/* --- Main content --- */

main { flex: 1; min-width: 0; overflow-y: auto; }
main > * { max-width: 980px; margin: 2rem auto; padding: 0 1.5rem; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
}
.card.narrow { max-width: 360px; margin: 4rem auto; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }

h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.75rem; }

label { display: block; margin-bottom: 0.85rem; font-size: 0.85rem; color: var(--muted); }
/* `display: block` above otherwise wins over the browser's default
   `[hidden] { display: none }` — author rules always beat the user-agent
   stylesheet regardless of selector specificity — so a hidden label/hint
   (e.g. the new-user form's initial-password field/hint, toggled by
   app.js) would stay visible without this. */
label[hidden] { display: none; }
input, select {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.5rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.95rem;
}
fieldset { border: 1px solid var(--border); border-radius: 8px; margin: 0 0 1rem; padding: 0.9rem 1rem; }
legend { color: var(--muted); font-size: 0.8rem; padding: 0 0.4rem; }

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.link { background: none; border: none; color: var(--accent); padding: 0.25rem 0.4rem; }
button.link.danger { color: var(--danger); }
a.button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  text-decoration: none;
  display: inline-block;
}
.card-head-actions { display: flex; gap: 0.5rem; align-items: center; }
form.inline { display: inline; margin: 0; }

.form-actions { display: flex; gap: 0.75rem; align-items: center; margin-top: 0.5rem; }

.subform {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}

table.users { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.users th, table.users td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--border); }
table.users th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
td.actions { white-space: nowrap; }

/* Each user spans two <tr>s: the compact row of fields/actions, then a
   full-width detail row for provisioning status/errors and the busy
   indicator. The pair should read as one block, so only the detail row (the
   end of the block) carries the separator border. */
table.users tr.user-row td { border-bottom: none; }
table.users tr.user-detail-row td { padding: 0.3rem 0.6rem; }
.provision-detail { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 1rem; margin-bottom: 0.3rem; }
.provision-detail .error { display: inline-block; }

.role { font-size: 0.72rem; padding: 0.1rem 0.45rem; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.03em; }
.role-admin { background: rgba(53,99,233,0.12); color: var(--accent); }
.role-participant { background: rgba(107,114,128,0.14); color: var(--muted); }

code { background: var(--panel-2); padding: 0.1rem 0.35rem; border-radius: 4px; font-size: 0.85em; }
.muted { color: var(--muted); }
.error { color: var(--danger); background: rgba(194,42,32,0.08); padding: 0.5rem 0.75rem; border-radius: 6px; }
.ok { color: var(--ok); background: rgba(22,121,79,0.08); padding: 0.5rem 0.75rem; border-radius: 6px; }

.wh-cards { display: flex; flex-direction: column; gap: 1rem; margin-top: 1rem; }
.wh-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
}
.wh-card-head { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.5rem; }
.wh-card-head h2 { margin: 0; }
.wh-card .subform { background: var(--panel); margin-bottom: 0; }
.wh-summary { margin: 0.25rem 0 0.75rem; }
.wh-test:not(:empty) { margin-top: 0.75rem; }

/* HTMX shows the indicator only while its request is in flight. */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { display: inline-flex; }
.testing { align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--muted); }
.spinner {
  width: 0.85rem; height: 0.85rem;
  border: 2px solid var(--border);
  border-top-color: var(--muted);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.badge { font-size: 0.7rem; padding: 0.12rem 0.5rem; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.04em; }
.badge-ok { background: rgba(22,121,79,0.12); color: var(--ok); }
.badge-muted { background: rgba(107,114,128,0.14); color: var(--muted); }
.badge-warn { background: rgba(138,92,0,0.14); color: var(--warn); }
.hint.error { color: var(--danger); text-transform: none; }

textarea {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.5rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font: 0.85rem ui-monospace, SFMono-Regular, Menlo, monospace;
  resize: vertical;
}
.hint { display: block; margin-top: 0.2rem; font-size: 0.75rem; color: var(--muted); }
.hint[hidden] { display: none; } /* see label[hidden] above */
.req { color: var(--danger); }

table.steps { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.steps th, table.steps td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--border); }
table.steps th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }

.checks-list { margin-top: 1rem; }
.check-row { display: flex; gap: 0.75rem; align-items: flex-start; margin-bottom: 0.85rem; }
.check-row label { flex: 1; margin-bottom: 0; }
.check-row-remove { flex: none; margin-top: 1.5rem; font-size: 1.1rem; line-height: 1; padding: 0.4rem 0.6rem; }

.step-form-title { font-size: 1.35rem; }

.running-as {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin: 0 0 1rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(53,99,233,0.08);
  color: var(--muted);
  font-size: 0.82rem;
}
.running-as code { color: var(--text); }

.step-detail-card { margin-bottom: 1rem; }
.step-card-head { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.5rem; }
.step-card-head h1 { margin: 0; }
.step-description { margin-bottom: 1rem; }
.step-description > :first-child { margin-top: 0; }
.step-description > :last-child { margin-bottom: 0; }
.step-description h1, .step-description h2, .step-description h3 { margin: 1rem 0 0.5rem; }
.step-description p { margin: 0 0 0.75rem; }
.step-description ul, .step-description ol { margin: 0 0 0.75rem; padding-left: 1.4rem; }
.step-description li { margin-bottom: 0.25rem; }
.step-description a { color: var(--accent); }
.step-description code { background: var(--panel-2); }
.step-description pre { margin: 0 0 0.75rem; padding: 0.6rem 0.8rem; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--border); overflow-x: auto; }
.step-description pre code { background: none; padding: 0; }
.step-description blockquote { margin: 0 0 0.75rem; padding: 0.1rem 0 0.1rem 0.9rem; border-left: 3px solid var(--border); color: var(--muted); }
.step-description img { max-width: 100%; height: auto; border-radius: 6px; }

.section-divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0 1rem; }
.step-verify-head { margin-bottom: 1rem; }
.step-verify-head h2 { margin-bottom: 0.25rem; }
.step-verify-head p { margin: 0; }

.step-query {
  margin: 0.4rem 0 1rem;
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font: 0.82rem ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  overflow-x: auto;
}

.step-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.step-nav a.link { background: none; border: none; color: var(--accent); text-decoration: none; font-size: 0.9rem; }
.step-nav a.link:hover { text-decoration: underline; }
.step-nav-next { margin-left: auto; }
.step-detail {
  margin-top: 0.75rem;
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  background: rgba(22,121,79,0.08);
  color: var(--text);
  font: 0.82rem ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
}
.step-detail.error { background: rgba(194,42,32,0.08); }

.step-result-wrap { margin-top: 0.75rem; overflow-x: auto; border: 1px solid var(--border); border-radius: 6px; }
table.result { width: 100%; border-collapse: collapse; font-size: 0.85rem; white-space: nowrap; }
table.result th, table.result td { text-align: left; padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--border); }
table.result th { color: var(--muted); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; background: var(--panel-2); }
table.result tr:last-child td { border-bottom: none; }

#confirm-dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  max-width: 420px;
}
#confirm-dialog::backdrop { background: rgba(20,26,36,0.45); }
#confirm-dialog p { margin: 0 0 1rem; }
