/* apphost console. One stylesheet, no framework, no external assets (the page's
   security policy allows only its own origin). Light and dark follow the system. */

:root {
  --bg: #f3f4f6; --bg-2: #ffffff; --bg-3: #f8f9fb; --ink: #15171c; --ink-2: #4b5160; --ink-3: #7b8494;
  --line: #e5e7eb; --line-2: #d4d7de;
  --side-bg: #111318; --side-ink: #c7ccd6; --side-ink-2: #7d8696; --side-active: #1d2129; --side-line: #22262f;
  --accent: #e8590c; --accent-ink: #ffffff; --accent-soft: #fdebdc; --accent-2: #0b7285;
  --ok: #1f8a4c; --ok-soft: #e4f5ea; --bad: #c92a2a; --bad-soft: #fbe6e6; --warn: #b7791f; --warn-soft: #fbf0d9; --grey: #6b7280; --grey-soft: #eceef2; --info-soft: #dff3f7;
  --shadow: 0 1px 2px rgba(16, 18, 24, .06), 0 8px 24px -16px rgba(16, 18, 24, .25);
  --radius: 12px; --radius-s: 8px;
  --mono: ui-monospace, "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --bg-2: #171a21; --bg-3: #1d2129; --ink: #e8eaef; --ink-2: #aab1bf; --ink-3: #7b8494;
    --line: #262a33; --line-2: #343946;
    --side-bg: #0b0d11; --side-active: #171a21; --side-line: #1c1f27;
    --accent: #ff7a30; --accent-ink: #15171c; --accent-soft: #3a2314; --accent-2: #3bc9db;
    --ok: #51cf66; --ok-soft: #14301d; --bad: #ff6b6b; --bad-soft: #3b1717; --warn: #fcc419; --warn-soft: #3a2d0f; --grey: #9aa3b2; --grey-soft: #262a33; --info-soft: #0f2f36;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px -16px rgba(0, 0, 0, .8);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14.5px/1.5 var(--sans); color: var(--ink); background: var(--bg); }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 15px; } h3 { font-size: 12px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; margin: 18px 0 8px; }
small, .muted { color: var(--ink-3); }
.mono { font-family: var(--mono); font-size: 12.5px; word-break: break-all; }
.hidden { display: none !important; }
svg.i { width: 16px; height: 16px; vertical-align: -3px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--side-bg); color: var(--side-ink); display: flex; flex-direction: column; padding: 18px 14px; position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--side-line); }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 16px; letter-spacing: -.01em; padding: 4px 8px 18px; text-decoration: none; }
.brand .mark { width: 26px; height: 26px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), #ffb86b); display: grid; place-items: center; color: #15171c; font-weight: 800; font-size: 13px; }
.brand:hover { text-decoration: none; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--side-ink); font-weight: 500; }
.side nav a:hover { background: var(--side-active); color: #fff; text-decoration: none; }
.side nav a.active { background: var(--side-active); color: #fff; box-shadow: inset 2px 0 0 var(--accent); }
.side nav .sep { margin: 12px 10px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--side-ink-2); }
.side-foot { margin-top: auto; padding: 12px 10px 0; font-size: 12px; color: var(--side-ink-2); border-top: 1px solid var(--side-line); line-height: 1.6; }
.side-foot b { color: var(--side-ink); font-weight: 600; display: block; }
.main { min-width: 0; display: flex; flex-direction: column; }
.bar { display: flex; align-items: center; gap: 16px; padding: 14px 28px; background: var(--bg-2); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.bar .crumbs { color: var(--ink-3); font-size: 13px; display: flex; gap: 8px; align-items: center; }
.bar .crumbs b { color: var(--ink); font-weight: 600; }
.bar .grow { flex: 1; }
.menu-btn { display: none; }
.side-top { display: flex; align-items: flex-start; justify-content: space-between; }
.close-nav { display: none; background: none; border: 0; color: var(--side-ink-2); cursor: pointer; padding: 6px; border-radius: 8px; margin-top: 2px; }
.close-nav:hover { background: var(--side-active); color: #fff; }
.scrim { display: none; }
.content { padding: 24px 32px 64px; width: 100%; }

/* header rows */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .lede { color: var(--ink-2); margin-top: 4px; max-width: 70ch; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.title-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.title-row .mono { color: var(--ink-3); }

/* cards and grids */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(12, 1fr); margin-bottom: 16px; }
.col-12 { grid-column: span 12; } .col-8 { grid-column: span 8; } .col-6 { grid-column: span 6; } .col-4 { grid-column: span 4; } .col-3 { grid-column: span 3; }
.card { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card .card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card .card-b { padding: 16px 18px; }
.card .card-b + .card-b { border-top: 1px solid var(--line); }
.card.narrow { max-width: 440px; margin: 10vh auto; text-align: center; }
.card.narrow .card-b { padding: 36px 32px; }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--bg-3); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 14px 16px; position: relative; overflow: hidden; }
.tile b { display: block; font-size: 28px; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; }
.tile span { color: var(--ink-3); font-size: 12.5px; }
.tile::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--grey); }
.tile.healthy::after { background: var(--ok); } .tile.failing::after { background: var(--bad); } .tile.unknown::after { background: var(--warn); }

/* facts (key/value) */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; font-size: 13.5px; }
.facts dt { color: var(--ink-3); } .facts dd { margin: 0; min-width: 0; word-break: break-word; }
.hook-settings { margin: 4px 0 10px; font-size: 13px; gap: 4px 14px; }

/* pills */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 7px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--grey-soft); color: var(--grey); white-space: nowrap; line-height: 1.6; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.healthy, .pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.failing, .pill.failed { background: var(--bad-soft); color: var(--bad); }
.pill.unknown, .pill.running, .pill.check { background: var(--warn-soft); color: var(--warn); }
.pill.stopped, .pill.not-deployed { background: var(--grey-soft); color: var(--grey); }
.pill.big { font-size: 13px; padding: 4px 12px 4px 10px; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px; background: var(--grey-soft); color: var(--ink-2); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.avatar { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--accent-2); color: #fff; font-size: 11px; font-weight: 700; margin-right: 6px; vertical-align: middle; }

/* tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
td > .pill, td > .chip, td > .avatar { vertical-align: top; }
td > .pill, td > .chip { margin-top: 1px; }
td.nowrap, td.user { white-space: nowrap; }
td.user .avatar { margin-right: 8px; }
td .sub.wrap { white-space: normal; }
thead th { color: var(--ink-3); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; background: var(--bg-3); position: sticky; top: 0; }
tbody tr:hover { background: var(--bg-3); }
tbody tr:last-child td { border-bottom: 0; }
td .sub { display: block; color: var(--ink-3); font-size: 12px; margin-top: 2px; }
td.detail { max-width: 420px; word-break: break-word; font-size: 12.5px; color: var(--ink-2); }
.empty { padding: 32px; text-align: center; color: var(--ink-3); }

/* toasts */
.toasts { position: fixed; top: 16px; right: 16px; z-index: 50; display: flex; flex-direction: column; gap: 8px; max-width: 420px; }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line); box-shadow: var(--shadow); border-left: 4px solid var(--accent-2); font-size: 13.5px; }
.toast.ok { border-left-color: var(--ok); } .toast.error { border-left-color: var(--bad); }
.toast button { margin-left: auto; background: none; border: 0; color: var(--ink-3); cursor: pointer; padding: 0 2px; font-size: 16px; line-height: 1; }
.notice { padding: 12px 14px; border-radius: 10px; background: var(--bg-3); border: 1px solid var(--line); border-left: 4px solid var(--accent-2); margin-bottom: 16px; font-size: 13.5px; }
.notice.error { border-left-color: var(--bad); background: var(--bad-soft); }
.notice.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.notice.ok { border-left-color: var(--ok); background: var(--ok-soft); }

/* buttons */
.btn, button.btn { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line-2); background: var(--bg-2); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.3; transition: background .12s, border-color .12s, transform .05s; }
.btn:hover { background: var(--bg-3); text-decoration: none; } .btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; } .btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); } .btn.ghost:hover { background: var(--bg-3); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* forms */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field > span { font-weight: 600; font-size: 13px; }
.field .hint { color: var(--ink-3); font-size: 12.5px; font-weight: 400; }
.input, textarea.input { width: 100%; padding: 9px 11px; border: 1px solid var(--line-2); border-radius: 9px; background: var(--bg-2); color: var(--ink); font: inherit; outline: none; transition: border-color .12s, box-shadow .12s; }
.input:focus, textarea.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.mono, textarea.input.mono { font-family: var(--mono); font-size: 12.5px; }
.input.sm { padding: 6px 9px; font-size: 13px; width: auto; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 500; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle .sw { width: 36px; height: 20px; border-radius: 999px; background: var(--line-2); position: relative; transition: background .15s; flex: none; }
.toggle .sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.toggle input:checked + .sw { background: var(--accent); } .toggle input:checked + .sw::after { transform: translateX(16px); }
.toggle input:focus-visible + .sw { box-shadow: 0 0 0 3px var(--accent-soft); }
.toggle .hint { color: var(--ink-3); font-size: 12.5px; font-weight: 400; display: block; }
pre.code, textarea.code { background: var(--bg-3); border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; word-break: break-all; margin: 0; color: var(--ink); }
.copy-row { display: flex; gap: 8px; align-items: stretch; }
.copy-row pre { flex: 1; }

/* custom dropdown: built by app.js around each <select>, which stays in the form hidden */
.dd { position: relative; display: inline-block; min-width: 160px; }
.dd-trigger { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; padding: 8px 10px 8px 12px; border: 1px solid var(--line-2); border-radius: 9px; background: var(--bg-2); color: var(--ink); font: inherit; cursor: pointer; text-align: left; }
.dd-trigger:focus-visible, .dd.open .dd-trigger { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.dd-trigger .caret { width: 14px; height: 14px; color: var(--ink-3); transition: transform .15s; }
.dd.open .dd-trigger .caret { transform: rotate(180deg); }
.dd-menu { position: absolute; z-index: 40; top: calc(100% + 6px); left: 0; min-width: 100%; max-height: 300px; overflow: auto; margin: 0; padding: 6px; list-style: none; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); display: none; }
.dd.open .dd-menu { display: block; animation: dd-in .12s ease-out; }
.dd.up .dd-menu { top: auto; bottom: calc(100% + 6px); }
.dd.right .dd-menu { left: auto; right: 0; }
@keyframes dd-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.dd-menu li { padding: 8px 10px; border-radius: 7px; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 10px; white-space: nowrap; }
.dd-menu li:hover, .dd-menu li.hl { background: var(--bg-3); }
.dd-menu li[aria-selected="true"] { color: var(--accent); font-weight: 600; }
.dd-menu li[aria-selected="true"]::after { content: "✓"; font-size: 12px; }
.dd.sm .dd-trigger { padding: 5px 8px 5px 10px; font-size: 12.5px; border-radius: 7px; }
.dd.sm { min-width: 110px; }
.dd.inline { display: inline-block; vertical-align: middle; }
select.enhanced { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }

/* user menu */
.umenu { position: relative; }
.umenu .dd-menu { right: 0; left: auto; min-width: 220px; }
.umenu .who { display: flex; align-items: center; gap: 8px; padding: 6px 10px 6px 6px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg-2); cursor: pointer; font: inherit; color: var(--ink); }
.umenu .who .avatar { margin: 0; }
.umenu .dd-menu .hd { padding: 8px 10px 6px; color: var(--ink-3); font-size: 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.umenu .dd-menu .hd b { display: block; color: var(--ink); font-weight: 600; font-size: 13px; word-break: break-all; }
.umenu form button { width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 7px; font: inherit; color: var(--ink); cursor: pointer; display: flex; gap: 8px; align-items: center; }
.umenu form button:hover { background: var(--bg-3); }

/* filter bar */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters .search { position: relative; flex: 1; min-width: 220px; max-width: 420px; }
.filters .search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--ink-3); }
.filters .search input { padding-left: 32px; }
.group-h { display: flex; align-items: baseline; gap: 10px; margin: 20px 0 8px; }
.group-h h2 { font-size: 14px; } .group-h .count { color: var(--ink-3); font-size: 12.5px; }

/* live log */
pre.log { background: #0e1014; color: #d6dae2; padding: 14px 16px; border-radius: 10px; max-height: 68vh; overflow: auto; font-family: var(--mono); font-size: 12.5px; line-height: 1.55; white-space: pre-wrap; margin: 0; border: 1px solid #1f232c; }
.live-head { display: flex; align-items: center; gap: 10px; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--line-2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.live-head.done .spinner { display: none; }

details { border: 1px solid var(--line); border-radius: 9px; padding: 0 12px; }
details summary { cursor: pointer; color: var(--ink-2); padding: 10px 0; font-weight: 500; }
details[open] summary { border-bottom: 1px solid var(--line); margin-bottom: 10px; }
details .inner { padding-bottom: 12px; }


/* environment editor */
table.env td { vertical-align: middle; }  /* the editor has one line per row; middle reads best there */
table.env .input.sm { width: 100%; }
table.env tr.extra td:first-child .input { width: 100%; }
.input.secret { -webkit-text-security: disc; }
.btn.icon { padding: 4px 9px; font-size: 15px; line-height: 1; }
tr.removed td { opacity: .45; }
tr.removed td .input { text-decoration: line-through; }

/* rendered documents */
.prose { max-width: 86ch; font-size: 15px; line-height: 1.6; }
.prose h1 { display: none; } .prose h2 { font-size: 19px; margin: 28px 0 10px; } .prose h3 { font-size: 13px; margin: 20px 0 8px; }
.prose p { margin: 0 0 12px; } .prose ul, .prose ol { margin: 0 0 14px; padding-left: 24px; } .prose li { margin: 4px 0; }
.prose code { font-family: var(--mono); font-size: 13px; background: var(--bg-3); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; }
.prose pre { background: var(--bg-3); border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px; overflow: auto; margin: 8px 0 14px; }
.prose pre code { background: none; border: 0; padding: 0; }
.prose table { margin: 8px 0 16px; } .prose a { text-decoration: underline; }
/* a small button in a top-aligned cell: pull it up by its own padding so its text sits on the row's first line */
td > .btn.sm, td > form > .btn.sm, td > .btn-row > form > .btn.sm, td > .btn-row > .btn.sm { margin-top: -5px; margin-bottom: -5px; }

/* ---------- small screens ----------
   900px and below: the sidebar is a drawer behind a scrim, the grid one column,
   the actions fill the width. 720px and below: tables stack into blocks, one row
   per record, each cell labelled by its header (data-th, set by app.js); filters
   fill the width. 480px and below: key/value lists stack. Touch: taller targets,
   16px inputs so iOS does not zoom into them. */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(284px, 86vw); height: 100vh; height: 100dvh; z-index: 70; transform: translateX(-100%); transition: transform .2s ease-out; overflow-y: auto; padding-bottom: calc(18px + env(safe-area-inset-bottom)); padding-left: max(14px, env(safe-area-inset-left)); }
  .side.open { transform: none; box-shadow: 24px 0 48px -24px rgba(0, 0, 0, .7); }
  .close-nav { display: inline-flex; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 65; background: rgba(8, 10, 14, .55); opacity: 0; pointer-events: none; transition: opacity .2s; }
  body.nav-open .scrim { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }
  .menu-btn { display: inline-flex; }
  .bar { padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top)); gap: 10px; }
  .bar .crumbs { min-width: 0; overflow: hidden; white-space: nowrap; }
  .bar .crumbs b, .bar .crumbs a { overflow: hidden; text-overflow: ellipsis; }
  .umenu .who > span:not(.avatar) { display: none; }
  .umenu .who { padding: 4px 6px 4px 4px; gap: 2px; }
  .content { padding: 16px 16px 56px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .grid { grid-template-columns: 1fr; gap: 12px; }
  /* every card takes the one column; a "span 12" left in place would make the
     browser invent eleven extra columns and squeeze the rest into slivers */
  .grid > * { grid-column: 1 / -1; }
  .main { overflow-x: clip; }
  .two { grid-template-columns: 1fr; }
  .card .card-h { padding: 12px 14px; flex-wrap: wrap; }
  .card .card-b { padding: 14px; }
  .card.narrow { margin: 6vh auto; }
  .card.narrow .card-b { padding: 28px 20px; }
  h1 { font-size: 20px; }
  .page-head { margin-bottom: 16px; gap: 12px; }
  .page-head .actions { width: 100%; }
  .page-head .actions > .btn, .page-head .actions > form, .page-head .actions form.btn-row > .btn { flex: 1 1 auto; justify-content: center; }
  .toasts { top: auto; bottom: calc(12px + env(safe-area-inset-bottom)); left: 12px; right: 12px; max-width: none; }
  .dd-menu { max-width: calc(100vw - 24px); }
  .dd-menu li { white-space: normal; }
  pre.log { max-height: 60vh; padding: 12px; }
  .prose table { display: block; overflow-x: auto; }
  td.detail { max-width: none; }
}

@media (max-width: 720px) {
  .filters { gap: 8px; }
  .filters .search { flex: 1 1 100%; max-width: none; min-width: 0; }
  .filters .dd, .filters .input.sm { flex: 1 1 calc(50% - 4px); min-width: 0; width: auto; }
  .filters .btn { flex: 1 1 100%; justify-content: center; }
  .group-h { margin: 16px 0 8px; }
  .tiles { grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 8px; }
  .tile { padding: 12px; } .tile b { font-size: 24px; }

  /* stacked tables */
  .table-wrap { overflow-x: visible; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; }
  table.stack thead { display: none; }
  table.stack tr { padding: 10px 14px 12px; border-bottom: 1px solid var(--line); }
  table.stack tbody tr:hover { background: none; }
  table.stack tbody tr:last-child { border-bottom: 0; }
  table.stack td { padding: 3px 0; border: 0; white-space: normal; }
  table.stack td[data-th]:not([data-th=""]) { position: relative; padding-left: 104px; min-height: 26px; }
  table.stack td[data-th]:not([data-th=""])::before { content: attr(data-th); position: absolute; left: 0; top: 5px; width: 94px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-3); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
  table.stack tbody td:first-child, table.stack tbody td:first-child[data-th] { padding-left: 0; font-size: 14.5px; margin-bottom: 4px; }
  table.stack tbody td:first-child::before, table.stack tbody td:first-child[data-th]::before { display: none; }
  table.stack td:last-child[data-th=""]:not(:first-child) { display: flex; justify-content: flex-end; gap: 8px; padding-top: 8px; }
  table.stack td > .btn.sm, table.stack td > form > .btn.sm, table.stack td > .btn-row > form > .btn.sm, table.stack td > .btn-row > .btn.sm { margin-top: 0; margin-bottom: 0; }
  table.stack td .sub { margin-top: 1px; }
  .empty { padding: 24px 16px; }

  /* the environment editor: key, state and × on one line, the value below */
  table.env, table.env tbody, table.env tr, table.env td { display: block; }
  table.env thead { display: none; }
  table.env tr { display: grid; grid-template-columns: 1fr auto auto; gap: 6px 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
  table.env tr:last-child { border-bottom: 0; }
  table.env td { padding: 0; border: 0; min-width: 0; white-space: normal; }
  table.env td:nth-child(1) { grid-column: 1; }
  table.env td:nth-child(2) { grid-column: 2; }
  table.env td:nth-child(4) { grid-column: 3; }
  table.env td:nth-child(3) { grid-column: 1 / -1; }
  table.env tr.extra td:nth-child(1) { grid-column: 1; }
  table.env td > .btn.sm { margin: 0; }
  table.env .input.sm { width: 100%; }
}

@media (max-width: 480px) {
  .facts { grid-template-columns: 1fr; gap: 0; }
  .facts dt { margin-top: 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
  .facts dt:first-child { margin-top: 0; }
  .copy-row { flex-wrap: wrap; }
  .copy-row pre { flex: 1 1 100%; }
  .copy-row .btn { flex: 1; justify-content: center; }
  .btn-row > .input.sm { flex: 1 1 100%; width: 100%; }
  .page-head .actions form.btn-row { width: 100%; }
}

@media (pointer: coarse) {
  .btn, button.btn { min-height: 40px; }
  .btn.sm { min-height: 34px; }
  .btn.icon { min-width: 34px; justify-content: center; }
  .dd-trigger { min-height: 40px; } .dd.sm .dd-trigger { min-height: 34px; }
  .dd-menu li { padding: 10px 12px; }
  .side nav a { padding: 12px 10px; }
  .umenu form button { padding: 11px 10px; }
  details summary { padding: 12px 0; }
  .toggle .sw { width: 42px; height: 24px; } .toggle .sw::after { width: 20px; height: 20px; } .toggle input:checked + .sw::after { transform: translateX(18px); }
}
@media (pointer: coarse) and (max-width: 900px) {
  .input, textarea.input, .input.sm, .input.mono, textarea.input.mono { font-size: 16px; }
  .input, textarea.input { min-height: 42px; }
  .input.sm { min-height: 36px; }
}

/* parked: switched off on purpose, nothing wrong */
.pill.parked { background: var(--info-soft); color: var(--accent-2); }
.tile.parked::after { background: var(--accent-2); }

/* tabs on the app page. Without the script every panel shows, one after another. */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 0 0 18px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { display: inline-flex; align-items: center; gap: 7px; padding: 10px 14px; color: var(--ink-2); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.tabs .count { font-size: 11.5px; font-weight: 700; padding: 0 7px; border-radius: 999px; background: var(--grey-soft); color: var(--ink-2); line-height: 1.6; }
.tabs .count.bad { background: var(--bad-soft); color: var(--bad); }
.js-tabs .tab-panel { display: none; }
.js-tabs .tab-panel.active { display: block; }
.tab-panel + .tab-panel { margin-top: 8px; }

/* access keys */
.key-new { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.key-new .field { margin-bottom: 0; }
.key-new .key-label { flex: 1 1 280px; }
.key-new .key-go { padding-top: 25px; }
details.sessions { border: 0; padding: 0; }
details.sessions summary { padding: 0; font-weight: 500; color: var(--accent-2); }
details.sessions[open] summary { border: 0; margin: 0 0 6px; }
details.sessions ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
details.sessions li { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; font-size: 12.5px; }
details.sessions li .btn.sm { margin: -4px 0; }

@media (max-width: 720px) {
  .tabs { margin: 0 -16px 14px; padding: 0 8px; }
  .tabs a { padding: 10px 10px; }
  .key-new .key-go { padding-top: 0; width: 100%; }
  .key-new .key-go .btn { width: 100%; justify-content: center; }
  .key-new .field { flex: 1 1 100%; }
  .key-new .dd { width: 100%; }
}

/* visibility as choice cards on the Access tab */
.vis-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.vis-card { position: relative; display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--line-2); border-radius: var(--radius-s); background: var(--bg-2); cursor: pointer; transition: border-color .12s, box-shadow .12s, background .12s; }
.vis-card:hover { background: var(--bg-3); }
.vis-card input { appearance: none; -webkit-appearance: none; flex: none; width: 16px; height: 16px; margin: 2px 0 0; border: 2px solid var(--line-2); border-radius: 50%; display: grid; place-items: center; }
.vis-card input::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); transform: scale(0); transition: transform .12s; }
.vis-card input:checked { border-color: var(--accent); }
.vis-card input:checked::after { transform: scale(1); }
.vis-card input:focus-visible { box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
.vis-card:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.vis-body { display: flex; flex-direction: column; gap: 2px; }
.vis-body span { color: var(--ink-3); font-size: 12.5px; line-height: 1.45; }
.vis-save { margin-top: 14px; }
.key-new .key-switch { flex: 1 1 100%; order: 3; margin-top: 2px; }

/* code blocks: label and Copy in a bar above the code, never over it */
.code-block { border: 1px solid var(--line); border-radius: 9px; background: var(--bg-3); overflow: hidden; min-width: 0; }
.code-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 34px; padding: 3px 4px 3px 12px; border-bottom: 1px solid var(--line); background: var(--bg-2); }
.code-label { color: var(--ink-3); font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code-bar .copy-btn { margin: 0; flex: none; }
.code-actions { display: flex; gap: 6px; flex: none; }
.code-block > pre, .code-block > pre.code, .prose .code-block > pre { margin: 0; border: 0; border-radius: 0; background: transparent; }
.prose .code-block { margin: 8px 0 14px; }
.code-block + .code-block, .code-block + p, p + .code-block, h3 + .code-block { margin-top: 10px; }
.code-block.dark { border-color: #1f232c; background: #0e1014; }
.code-block.dark .code-bar { background: #15181e; border-bottom-color: #1f232c; }
.code-block.dark .code-label { color: #8a93a3; }
.code-block.dark .copy-btn { color: #c8ced8; }
.code-block.dark .copy-btn:hover { background: #1f232c; }
.code-block.dark > pre.log { border: 0; border-radius: 0; }

.notice-action { margin-top: 10px; }

/* Tables whose rows are mostly form controls (Users): centre every cell, so a
   line of text sits level with the text inside the inputs and dropdowns beside
   it. Data tables keep top alignment, which suits cells of several lines. */
table.controls td { vertical-align: middle; }
table.controls td > .avatar, table.controls td > .pill, table.controls td > .chip { vertical-align: middle; margin-top: 0; }
table.controls td > .btn.sm, table.controls td > form > .btn.sm, table.controls td > .btn-row > form > .btn.sm { margin-top: 0; margin-bottom: 0; }

/* A disabled dropdown must look disabled, not merely refuse to open. */
.dd-trigger:disabled { opacity: .5; cursor: not-allowed; }
.dd-trigger:disabled .caret { display: none; }

/* dropdown options with a description line */
.dd-menu li.has-desc { white-space: normal; align-items: flex-start; }
.dd-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.dd-desc { color: var(--ink-3); font-size: 12px; font-weight: 400; line-height: 1.4; max-width: 300px; }
.dd-menu li[aria-selected="true"] .dd-desc { color: var(--ink-3); }

/* the role legend on the Users page */
.roles { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; margin: 0 0 16px; }
.role { display: flex; flex-direction: column; gap: 3px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--bg-2); }
.role span { color: var(--ink-3); font-size: 12.5px; line-height: 1.45; }

/* Phones, tables made of controls (Users): the label goes above each value, not
   beside it, so inputs and buttons get the card's full width and share a line. */
@media (max-width: 720px) {
  table.stack td.user { white-space: normal; overflow-wrap: anywhere; }
  table.stack td.user .avatar { margin-right: 8px; }
  table.stack.controls tbody td[data-th]:not([data-th=""]):not(:first-child) { padding-left: 0; padding-top: 20px; }
  table.stack.controls tbody td[data-th]:not([data-th=""]):not(:first-child)::before { top: 3px; width: auto; }
  table.stack.controls tbody tr { display: grid; grid-template-columns: 1fr 1fr; column-gap: 12px; }
  table.stack.controls tbody td { min-width: 0; }
  table.stack.controls tbody td:first-child,
  table.stack.controls tbody td:nth-child(2),
  table.stack.controls tbody td:nth-child(3) { grid-column: 1 / -1; }
  table.stack.controls .btn-row { flex-wrap: nowrap; }
  table.stack.controls .btn-row > .input.sm { flex: 1 1 auto; width: auto; min-width: 0; }
  table.stack.controls .btn-row > .dd { flex: 1 1 auto; min-width: 0; }
  table.stack.controls tbody td:last-child[data-th=""] { padding-top: 20px; align-items: flex-start; }
}
