:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #dde3ea;
  --line-strong: #c6cfda;
  --text: #16202b;
  --text-2: #475467;
  --text-3: #667085;
  --brand: #1d4ed8;
  --brand-hover: #1e40af;
  --brand-soft: #e8efff;
  --nav: #0f1b2d;
  --nav-2: #1b2a42;
  --amber-bg: #fff4dc;
  --amber-fg: #8a4b00;
  --amber-line: #f5d596;
  --slate-bg: #edf1f5;
  --slate-fg: #3d4b5c;
  --red-bg: #fdecee;
  --red-fg: #a3122a;
  --red-line: #f6c2ca;
  --green-bg: #e7f6ec;
  --green-fg: #146c36;
  --green-line: #b9e3c7;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }

h1, h2, h3 { color: var(--text); letter-spacing: -0.01em; }
h1 { font-size: 1.55rem; line-height: 1.25; margin: 0; }
h2 { font-size: 1.05rem; margin: 0; }
h3 { font-size: 0.95rem; margin: 0; }
p { margin: 0 0 0.75rem; }

.muted { color: var(--text-2); }
.subtle { color: var(--text-3); font-size: 0.875rem; }
.mono { font-family: var(--mono); font-size: 0.85em; }
.nowrap { white-space: nowrap; }

/* Top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--nav);
  color: #fff;
  border-bottom: 1px solid #0a1422;
}
.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: #fff;
  font-weight: 700;
  font-size: 1.02rem;
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 800;
  color: #fff;
}
.mainnav { display: flex; gap: 0.25rem; flex: 1; }
.mainnav a {
  color: #c7d2e3;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.92rem;
}
.mainnav a:hover { color: #fff; background: var(--nav-2); text-decoration: none; }
.mainnav a.active { color: #fff; background: var(--nav-2); }
.account { display: flex; align-items: center; gap: 0.75rem; margin-left: auto; color: #c7d2e3; font-size: 0.88rem; }
.account .who { max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account form { margin: 0; }
.account button {
  background: transparent;
  color: #e2e8f0;
  border: 1px solid #334155;
  padding: 0.3rem 0.7rem;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.account button:hover { background: var(--nav-2); color: #fff; }

/* Page */

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.page-head p { margin: 0.3rem 0 0; }
.eyebrow {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  margin-bottom: 0.2rem;
}
.eyebrow a { color: var(--text-3); }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }

/* Org tabs */

.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--line);
  margin: -0.25rem 0 1.25rem;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  padding: 0.6rem 0.9rem;
  color: var(--text-2);
  font-weight: 600;
  font-size: 0.92rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }
.tabs .count {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: var(--slate-bg);
  color: var(--slate-fg);
  font-size: 0.75rem;
  line-height: 1.5;
}
.tabs a.active .count { background: var(--brand-soft); color: var(--brand); }

/* Flash */

.flash {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid;
  margin-bottom: 1.25rem;
  font-weight: 500;
}
.flash-ok { background: var(--green-bg); color: var(--green-fg); border-color: var(--green-line); }
.flash-error { background: var(--red-bg); color: var(--red-fg); border-color: var(--red-line); }
.flash-warn { background: var(--amber-bg); color: var(--amber-fg); border-color: var(--amber-line); }

/* Buttons */

.btn, button.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 0.95rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--brand-hover); border-color: var(--brand-hover); text-decoration: none; }
.btn:focus-visible, .field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible, .search input:focus-visible {
  outline: 3px solid rgba(29, 78, 216, 0.3);
  outline-offset: 1px;
}
.btn.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
.btn.btn-secondary:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn.btn-danger { background: var(--surface); color: var(--red-fg); border-color: var(--red-line); }
.btn.btn-danger:hover { background: var(--red-bg); border-color: var(--red-fg); }
.btn.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.82rem; }
.btn[disabled], .btn.busy { opacity: 0.65; cursor: progress; }
.btn.busy::before {
  content: "";
  width: 0.8em;
  height: 0.8em;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Cards */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--line);
}
.card-head p { margin: 0.15rem 0 0; }
.card-body { padding: 1.1rem; }
.card-body > :last-child { margin-bottom: 0; }
.card-foot {
  padding: 0.9rem 1.1rem;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius);
}
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(22rem, 100%), 1fr)); gap: 1.25rem; align-items: start; margin-bottom: 1.25rem; }
.grid-2 > .card { margin-bottom: 0; }
.stack > * + * { margin-top: 1.25rem; }

/* Stats */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.5rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow);
}
a.stat { display: block; color: var(--text); }
a.stat:hover { text-decoration: none; border-color: var(--line-strong); box-shadow: 0 2px 6px rgba(16, 24, 40, 0.08); }
.stat-label { font-size: 0.8rem; font-weight: 600; color: var(--text-2); }
.stat-value { font-size: 1.65rem; font-weight: 700; line-height: 1.2; margin-top: 0.15rem; font-variant-numeric: tabular-nums; }
.stat-amber .stat-value { color: var(--amber-fg); }
.stat-red .stat-value { color: var(--red-fg); }
.stat-green .stat-value { color: var(--green-fg); }
.stats-compact { margin-bottom: 1rem; }
.stats-compact .stat { padding: 0.6rem 0.9rem; }
.stats-compact .stat-value { font-size: 1.35rem; }

/* Dashboard organization tiles */

label.toggle {
  display: inline-flex; align-items: center; gap: 0.45rem;
  padding: 0.42rem 0.75rem; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); font-size: 0.86rem; color: var(--text-2); cursor: pointer; user-select: none;
}
label.toggle input { margin: 0; accent-color: var(--brand); }
label.toggle:has(input:checked) { background: var(--brand-soft); color: var(--brand); border-color: #cbd9ff; }

.org-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(24rem, 100%), 1fr)); gap: 1rem; align-items: start; }
.org-tile { margin: 0; display: flex; flex-direction: column; }
.tile-head { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; padding: 0.8rem 1rem 0.4rem; }
.tile-head h2 { font-size: 1.02rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-head h2 a { color: var(--text); }
.tile-head .pill { flex-shrink: 0; }
.tile-stats { display: flex; flex-wrap: wrap; gap: 0.35rem; padding: 0.2rem 1rem 0.75rem; border-bottom: 1px solid var(--line); }
.tile-stat {
  font-size: 0.8rem; color: var(--text-2); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 999px; padding: 0.12rem 0.6rem; white-space: nowrap;
}
a.tile-stat:hover { text-decoration: none; border-color: var(--line-strong); color: var(--text); }
.tile-stat b { color: var(--text); font-variant-numeric: tabular-nums; }
.tile-stat-amber { background: var(--amber-bg); border-color: var(--amber-line); color: var(--amber-fg); }
.tile-stat-amber b { color: var(--amber-fg); }
.tile-stat-red { background: var(--red-bg); border-color: var(--red-line); color: var(--red-fg); }
.tile-stat-red b { color: var(--red-fg); }

.tile-list { list-style: none; margin: 0; padding: 0.25rem 0; flex: 1; }
.tile-list li {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 0.5rem;
  padding: 0.32rem 1rem; font-size: 0.88rem; line-height: 1.35;
}
.tile-list li:nth-child(even) { background: var(--surface-2); }
.tile-list li.tile-none { display: block; color: var(--text-3); padding: 0.9rem 1rem; }
.tile-list li[hidden] { display: none; }
.tile-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-meta { color: var(--text-3); font-size: 0.8rem; white-space: nowrap; grid-column: 3; }
.tile-list .pill { font-size: 0.7rem; padding: 0 0.4rem; }
.dash:not(.show-ended) .tile-list li[data-status="ended"] { display: none; }
.tile-hooks { padding: 0.55rem 1rem 0.65rem; border-top: 1px solid var(--line); }
.tile-hooks-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.6rem; margin-bottom: 0.25rem; }
.tile-hooks h3 { margin: 0; font-size: 0.72rem; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-3); }
.tile-hooks-head a { font-size: 0.78rem; }
.hook-log { list-style: none; margin: 0; padding: 0; }
.hook-log li { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) auto; align-items: baseline; gap: 0.45rem; padding: 0.12rem 0; font-size: 0.8rem; }
.hook-who { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hook-event { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hook-log li .subtle { white-space: nowrap; text-align: right; }
.hook-empty { margin: 0; color: var(--text-3); font-size: 0.8rem; }
.tile-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 0.6rem;
  padding: 0.55rem 1rem; border-top: 1px solid var(--line); background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius); font-size: 0.84rem;
}
.tile-foot form { margin: 0; }

/* Pills */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.5;
  white-space: nowrap;
  border: 1px solid transparent;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.8; }
.pill-plain::before { display: none; }
.pill-suspended { background: var(--amber-bg); color: var(--amber-fg); border-color: var(--amber-line); }
.pill-ended, .pill-neutral { background: var(--slate-bg); color: var(--slate-fg); border-color: var(--line); }
.pill-active, .pill-ok { background: var(--green-bg); color: var(--green-fg); border-color: var(--green-line); }
.pill-fail { background: var(--red-bg); color: var(--red-fg); border-color: var(--red-line); }
.pill-warn { background: var(--amber-bg); color: var(--amber-fg); border-color: var(--amber-line); }
.pill-parking { background: #efe9ff; color: #5b21b6; border-color: #d9ccff; }
.pill-count { background: var(--brand-soft); color: var(--brand); border-color: #cbd9ff; }
.pill-count::before { display: none; }

/* Filters */

.filterbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: center;
  margin-bottom: 1.25rem;
}
.search { position: relative; flex: 1 1 18rem; max-width: 26rem; }
.search input {
  width: 100%;
  padding: 0.5rem 2.2rem 0.5rem 0.75rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.search kbd {
  position: absolute;
  right: 0.55rem;
  top: 50%;
  transform: translateY(-50%);
  font: 600 0.72rem var(--mono);
  color: var(--text-3);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 0 0.3rem;
  background: var(--surface-2);
}
.toggles { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.toggles label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.8rem;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
  margin: 0;
}
.toggles label + label { border-left: 1px solid var(--line-strong); }
.toggles input { margin: 0; accent-color: var(--brand); }
.toggles label:has(input:checked) { background: var(--brand-soft); color: var(--brand); }
.result-count { font-size: 0.86rem; color: var(--text-2); font-variant-numeric: tabular-nums; }

/* Tables */

.table-wrap { position: relative; }
table { border-collapse: collapse; width: 100%; background: var(--surface); }
th, td {
  text-align: left;
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  color: var(--text);
  overflow-wrap: anywhere;
}
thead th {
  position: sticky;
  top: 56px;
  z-index: 5;
  background: var(--surface-2);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-2);
  border-bottom: 1px solid var(--line-strong);
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafbfd; }
td.client { font-weight: 600; }
td.client .sub { display: block; font-weight: 400; color: var(--text-3); font-size: 0.84rem; }
td.actions-cell { text-align: right; width: 1%; white-space: nowrap; }
td.actions-cell form { display: inline; margin: 0; }

table.fixed { table-layout: fixed; }
table.fixed .c-client { width: 20%; }
table.fixed .c-service { width: 15%; }
table.fixed .c-status { width: 8.5rem; }
table.fixed .c-devices { width: 35%; }

.device { display: block; padding: 0.05rem 0; }
.device + .device { border-top: 1px dashed var(--line); margin-top: 0.3rem; padding-top: 0.35rem; }
.device-name { font-weight: 600; }
.device-meta { color: var(--text-2); font-size: 0.86rem; }
.parked { display: inline-block; margin-top: 0.1rem; color: #5b21b6; font-size: 0.82rem; font-weight: 600; }
.prefixes { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.prefix {
  font: 0.8rem/1.5 var(--mono);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 0.35rem;
  white-space: nowrap;
}
details.more > summary {
  cursor: pointer;
  color: var(--brand);
  font-weight: 600;
  font-size: 0.86rem;
  list-style: none;
}
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: "▸ "; }
details.more[open] > summary::before { content: "▾ "; }
details.more[open] > summary { margin-bottom: 0.4rem; }

.empty {
  padding: 2rem 1.1rem;
  text-align: center;
  color: var(--text-2);
}
.empty strong { display: block; color: var(--text); margin-bottom: 0.2rem; }

/* Forms */

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 0.9rem 1rem; }
.form-grid .span-all { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field > span { font-size: 0.84rem; font-weight: 600; color: var(--text); }
.field .hint { font-size: 0.8rem; color: var(--text-3); font-weight: 400; }
.field textarea { resize: vertical; min-height: 4.5rem; font-family: var(--mono); font-size: 0.85rem; line-height: 1.5; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 0.52rem 0.7rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.field input::placeholder { color: #98a2b3; }
.field input[type="file"] { padding: 0.4rem 0.5rem; font-size: 0.88rem; }
.hook-url { word-break: break-all; }
label.check { display: flex; align-items: center; gap: 0.5rem; font-size: 0.88rem; color: var(--text-2); cursor: pointer; }
label.check input { margin: 0; accent-color: var(--red-fg); }
.form-actions { display: flex; gap: 0.6rem; align-items: center; margin-top: 1.1rem; flex-wrap: wrap; }
.note { font-size: 0.86rem; color: var(--text-2); }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.45rem 1.25rem; margin: 0; }
dl.facts dt { color: var(--text-2); font-size: 0.88rem; }
dl.facts dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
dl.facts dd .pill { margin-right: 0.35rem; }
.text-fail { color: var(--red-fg); }
.card-foot form { margin: 0; }
.card-body details.more { margin-top: 1rem; }
ul.plain-list { list-style: none; margin: 0.6rem 0; padding: 0; font-size: 0.88rem; }
ul.plain-list li { padding: 0.3rem 0; border-top: 1px solid var(--line); }
ul.plain-list li .subtle { display: inline-block; min-width: 10.5rem; font-family: var(--mono); font-size: 0.78rem; }
table.changes .col-action { width: 7rem; }
table.changes .col-menu { width: 15rem; }

/* Auth pages */

body.auth main { max-width: 26rem; padding-top: 12vh; }
.auth-card { padding: 1.75rem; }
.auth-card h1 { margin-bottom: 0.35rem; }
.auth-card .field + .field { margin-top: 0.9rem; }
.auth-card .btn { width: 100%; margin-top: 1.25rem; padding: 0.65rem; }
.auth-brand { display: flex; justify-content: center; margin-bottom: 1.25rem; }
.auth-brand .brand { color: var(--text); font-size: 1.2rem; }
.auth-brand .brand-mark { width: 32px; height: 32px; font-size: 0.95rem; }

/* Small screens */

@media (max-width: 820px) {
  .topbar-inner { height: auto; min-height: 56px; flex-wrap: wrap; gap: 0.5rem 1rem; padding: 0.55rem 1rem; }
  .mainnav { order: 3; flex-basis: 100%; }
  .account .who { display: none; }
  main { padding: 1rem 0.85rem 2.5rem; }
  thead th { top: 0; }
  table.stack-sm, table.stack-sm tbody, table.stack-sm tr, table.stack-sm td { display: block; width: auto; }
  table.stack-sm thead { display: none; }
  table.stack-sm tr { padding: 0.55rem 0; border-bottom: 1px solid var(--line); }
  table.stack-sm tbody tr:last-child { border-bottom: 0; }
  table.stack-sm td { border: 0; padding: 0.15rem 1rem; }
  table.stack-sm td[data-label]::before {
    content: attr(data-label);
    display: block;
    margin-top: 0.35rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-3);
  }
  table.stack-sm td.actions-cell { text-align: left; padding-top: 0.5rem; }
  .search { max-width: none; }
}
