/* 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;
  --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;
    --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; }
.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; }

/* 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: middle; }
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); }
@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; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 60; transform: translateX(-100%); transition: transform .18s; }
  .side.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .content { padding: 16px; }
  .grid { grid-template-columns: 1fr; }
  .col-8, .col-6, .col-4, .col-3 { grid-column: span 1; }
  .two { grid-template-columns: 1fr; }
  .bar { padding: 10px 16px; }
}

/* environment editor */
table.env td { vertical-align: middle; }
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; }
