:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e2e5ea;
  --text: #16191f;
  --muted: #667085;
  --accent: #0f766e;
  --accent-soft: #e6f4f2;
  --ok: #157f3c;      --ok-bg: #e7f6ec;
  --bad: #b42318;     --bad-bg: #fdecea;
  --warn: #9a6700;    --warn-bg: #fff4d6;
  --run: #1d4ed8;     --run-bg: #e8efff;
  --create: #157f3c;  --update: #9a6700;  --delete: #b42318;  --replace: #7c3aed;  --read: #1d4ed8;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --border: #2a2f3a;
    --text: #e6e8ec;
    --muted: #9aa3b2;
    --accent: #2dd4bf;
    --accent-soft: #11302d;
    --ok: #4ade80;      --ok-bg: #12301d;
    --bad: #f87171;     --bad-bg: #3a1615;
    --warn: #facc15;    --warn-bg: #362b0b;
    --run: #93b4ff;     --run-bg: #18264a;
    --create: #4ade80;  --update: #facc15;  --delete: #f87171;  --replace: #c4a1ff;  --read: #93b4ff;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: var(--mono); font-size: 12.5px; }
pre { margin: 0; white-space: pre-wrap; word-break: break-word; }
h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.strong { font-weight: 600; }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 52px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 2;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 650; }
.brand:hover { text-decoration: none; }
.orgs { display: flex; gap: 4px; overflow-x: auto; }
.orgs a { color: var(--muted); padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.orgs a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.orgs a[aria-current] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.me { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--surface);
  display: grid; place-items: center; font-weight: 700; text-transform: uppercase; font-size: 12px;
}
.me form { margin: 0; }
button.link { background: none; border: 0; color: var(--muted); padding: 0; font: inherit; cursor: pointer; }
button.link:hover { color: var(--text); }

main { max-width: 1320px; margin: 0 auto; padding: 24px; }

/* page + stack header */
.pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.pagehead p { margin: 4px 0 0; }
.crumbs { color: var(--muted); margin-bottom: 4px; }
.crumbs a { color: var(--muted); }
.stackhead { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.cli {
  margin-left: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 8px; color: var(--muted); max-width: 100%; overflow-x: auto; white-space: nowrap;
}
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 16px 0 20px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a[aria-current] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* forms */
input[type=search], input[type=password], select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button {
  font: inherit; font-weight: 600; background: var(--accent); color: var(--surface); border: 0;
  border-radius: 6px; padding: 7px 14px; cursor: pointer;
}
.search input { width: 280px; max-width: 100%; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters input { width: 260px; max-width: 100%; }

/* surfaces */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 20px; min-width: 0; }
.panel h2 { display: flex; align-items: baseline; justify-content: space-between; }
.panel .more { font-size: 13px; font-weight: 500; }
details.panel summary { cursor: pointer; list-style: none; }
details.panel summary h2 { display: inline; margin: 0; }
details.panel[open] summary { margin-bottom: 12px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; }
.cols .panel { margin-bottom: 0; }
.cols + .panel, .cols + details { margin-top: 20px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 20px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.card .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.card .value { font-size: 22px; font-weight: 650; margin: 6px 0 2px; }
.card .sub { color: var(--muted); font-size: 13px; }
.empty { text-align: center; padding: 48px 16px; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.empty pre { display: inline-block; text-align: left; background: var(--surface-2); padding: 12px 16px; border-radius: 6px; }

/* tables */
table { border-collapse: collapse; width: 100%; }
.grid { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: table; }
.panel .grid { border: 0; }
.grid th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 10px 12px; background: var(--surface-2); }
.grid td { padding: 9px 12px; border-top: 1px solid var(--border); vertical-align: top; }
.grid tbody tr:hover td { background: var(--surface-2); }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid .msg { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.resources .id code, .type { color: var(--muted); }
.resources .id { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid tbody tr.selected td { background: var(--accent-soft); }
.grid tbody tr.selected td:first-child { box-shadow: inset 3px 0 var(--accent); }
.stacklist tr.project td { background: var(--surface-2); padding-top: 7px; padding-bottom: 7px; }
.stacklist tbody tr.project:hover td { background: var(--surface-2); }
.stacklist tr.stack td:first-child { padding-left: 32px; }
.resources tr.provider .strong { color: var(--muted); font-weight: 500; }
.kv th { text-align: left; font-weight: 500; color: var(--muted); padding: 7px 12px 7px 0; width: 32%; vertical-align: top; word-break: break-word; }
.kv td { padding: 7px 0; border-top: 0; word-break: break-word; }
.kv tr + tr th, .kv tr + tr td { border-top: 1px solid var(--border); }
.kv pre { background: var(--surface-2); padding: 8px 10px; border-radius: 6px; }

/* badges & status */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.running { background: var(--run-bg); color: var(--run); }
.badge.muted { background: var(--surface-2); color: var(--muted); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .dot { animation: none; } }
.status { font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.status.ok { color: var(--ok); }
.chgtxt { font-size: 12.5px; white-space: nowrap; }
.chgtxt.create { color: var(--create); } .chgtxt.update { color: var(--update); } .chgtxt.delete { color: var(--delete); }
.chgtxt.replace { color: var(--replace); } .chgtxt.read { color: var(--read); } .chgtxt.same { color: var(--muted); }
.chgtxt.bad { color: var(--bad); font-weight: 600; }
.change { white-space: nowrap; }
.card .value.changes { font-size: 14px; white-space: normal; line-height: 1.9; }
.status::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; background: currentColor; vertical-align: 0; }
.status.create { color: var(--create); } .status.update { color: var(--update); } .status.delete { color: var(--delete); }
.status.replace { color: var(--replace); } .status.read { color: var(--read); } .status.same { color: var(--muted); }
.status.warn { color: var(--warn); } .status.bad { color: var(--bad); }
.tag { font-size: 11px; border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; margin-left: 6px; color: var(--muted); }
.secret { font-family: var(--mono); font-size: 12px; color: var(--muted); background: var(--surface-2); padding: 1px 6px; border-radius: 4px; }
.changes { white-space: nowrap; }
.chg { font-family: var(--mono); font-size: 12.5px; font-weight: 600; margin-right: 8px; }
.chg.create { color: var(--create); } .chg.update { color: var(--update); } .chg.delete { color: var(--delete); }
.chg.replace { color: var(--replace); } .chg.read { color: var(--read); } .chg.same { color: var(--muted); font-weight: 400; }
.changes.big .chg { font-size: 15px; }

/* resources split view */
.split { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; align-items: start; }
.split.with-detail { grid-template-columns: minmax(0, 1fr) minmax(0, 440px); }
.detail { position: sticky; top: 72px; max-height: calc(100vh - 92px); overflow: auto; margin: 0; }
.detailhead { display: flex; justify-content: space-between; align-items: center; }
.detailhead h2 { margin: 0; word-break: break-word; }
.close { font-size: 22px; color: var(--muted); line-height: 1; padding: 0 4px; }
.close:hover { text-decoration: none; color: var(--text); }
.meta { display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 6px 12px; margin: 12px 0 0; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }
.wrap { word-break: break-all; }
.deps { margin: 0; padding-left: 18px; word-break: break-all; font-family: var(--mono); font-size: 12px; }

/* update page */
.updatehead { margin-bottom: 20px; }
.updatehead h2 { font-size: 18px; display: flex; gap: 10px; align-items: center; margin-bottom: 4px; }
.updatehead p { margin: 0 0 8px; }
.log { list-style: none; margin: 0; padding: 12px; background: var(--surface-2); border-radius: 6px; font-family: var(--mono); font-size: 12.5px; overflow-x: auto; }
.log li { display: grid; grid-template-columns: 44px 22px minmax(0, 1fr); gap: 4px; padding: 1px 0; }
.log .t { color: var(--muted); }
.log .sym { font-weight: 700; text-align: center; }
.log .txt { white-space: pre-wrap; word-break: break-word; }
.log .create .sym, .log .create .txt { color: var(--create); }
.log .update .sym, .log .update .txt { color: var(--update); }
.log .delete .sym, .log .delete .txt { color: var(--delete); }
.log .replace .sym, .log .replace .txt { color: var(--replace); }
.log .read .sym, .log .read .txt { color: var(--read); }
.log .bad .sym, .log .bad .txt { color: var(--bad); }
.log .warn .sym, .log .warn .txt { color: var(--warn); }
.log .dim .txt, .log .dim .sym { opacity: .6; }
.log .summary { margin-top: 6px; border-top: 1px solid var(--border); padding-top: 6px; font-weight: 600; }

/* login */
.login { max-width: 380px; margin: 48px auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; }
.login form { display: grid; gap: 8px; margin-top: 16px; }
.login label { font-weight: 600; }
.login button { margin-top: 8px; padding: 9px; }
.login .hint { color: var(--muted); font-size: 13px; margin-top: 18px; }
.error { color: var(--bad); background: var(--bad-bg); padding: 8px 10px; border-radius: 6px; }

/* small screens */
@media (max-width: 860px) {
  .split.with-detail { grid-template-columns: minmax(0, 1fr); }
  .detail { position: static; max-height: none; }
}
@media (max-width: 640px) {
  main { padding: 16px; }
  .topbar { padding: 0 16px; gap: 12px; }
  .brand span, .me .username { display: none; }
  .cli { margin-left: 0; }
  .grid { display: block; overflow-x: auto; }
  .grid .msg { max-width: 200px; }
  .search, .search input, .filters input { width: 100%; }
}

/* live update view */
.livetag { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--run); }
.livetag.off { color: var(--muted); }
.livetag.off .dot { animation: none; }
a.badge:hover { text-decoration: none; filter: brightness(0.97); }
.progress { font-size: 13px; }
.progress td { padding: 6px 12px; }
.progress .sym { width: 36px; font-family: var(--mono); font-weight: 700; text-align: center; white-space: nowrap; }
.progress .type { font-family: var(--mono); font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.progress .tree { color: var(--border); }
.progress .name { font-weight: 600; }
.progress .stat { white-space: nowrap; font-weight: 600; }
.progress .stat .muted { font-weight: 400; margin-left: 6px; }
.progress tr.same td { color: var(--muted); font-weight: 400; }
.progress tr.st-pending .name { color: var(--text); }
.progress .sym.create, .progress .stat.create { color: var(--create); }
.progress .sym.update, .progress .stat.update { color: var(--update); }
.progress .sym.delete, .progress .stat.delete { color: var(--delete); }
.progress .sym.replace, .progress .stat.replace { color: var(--replace); }
.progress .sym.read, .progress .stat.read { color: var(--read); }
.progress .sym.bad, .progress .stat.bad { color: var(--bad); }
.progress .stat.pending { color: var(--run); }
.spin {
  display: inline-block; width: 10px; height: 10px; margin-right: 7px; vertical-align: -1px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; border-right-color: currentColor; opacity: .5; } }
#live-counts .chg { font-family: inherit; font-size: 14px; }

.banner { background: var(--warn-bg); color: var(--warn); border: 1px solid currentColor; border-radius: var(--radius); padding: 10px 14px; margin-bottom: 20px; font-weight: 600; }

/* settings / access forms */
form.inline { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0; }
input[name], select[name] { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px 9px; }
button.small { padding: 4px 10px; font-size: 13px; }
button.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.panel h2 form.inline { font-weight: 400; }
.flash { background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 8px 12px; }
ul.members { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 6px 16px; }
.tokenform { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.newtoken { border-color: var(--ok); }
.secretvalue { background: var(--surface-2); padding: 10px 12px; border-radius: 6px; font-size: 14px; user-select: all; word-break: break-all; }
.audit td.details { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.button { display: block; text-align: center; font-weight: 600; background: var(--accent); color: var(--surface); border-radius: 6px; padding: 9px; margin-top: 16px; }
a.button:hover { text-decoration: none; filter: brightness(1.05); }
.login .divider { text-align: center; margin: 18px 0 4px; }
