:root {
  color-scheme: light;
  --page: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --sidebar: #111722;
  --sidebar-text: #aab3c2;
  --sidebar-hover: #1c2432;
  --sidebar-active: #243146;
  --line: #e0e4ea;
  --line-strong: #c9cfd9;
  --text: #171c26;
  --muted: #5e6878;
  --accent: #2257d6;
  --accent-hover: #1a47b5;
  --accent-soft: #e9effc;
  --good: #137a4b;
  --good-soft: #e4f4ec;
  --warn: #975d00;
  --warn-soft: #fbf1dc;
  --bad: #c02b2b;
  --bad-hover: #a12222;
  --bad-soft: #fbe9e9;
  --log-bg: #10151e;
  --log-text: #d5dbe5;
  --log-bad: #ff9c9c;
  --log-head: #8fb4ff;
  --shadow: 0 1px 2px rgb(17 23 34 / 6%);
  --shadow-big: 0 12px 32px rgb(17 23 34 / 22%);
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0e131b;
    --surface: #151b25;
    --surface-2: #1a212d;
    --sidebar: #0a0e15;
    --sidebar-text: #9aa4b4;
    --sidebar-hover: #151b25;
    --sidebar-active: #1d2838;
    --line: #262f3d;
    --line-strong: #364152;
    --text: #e6eaf0;
    --muted: #97a1b1;
    --accent: #5b8cf5;
    --accent-hover: #7aa3f8;
    --accent-soft: #1b2a47;
    --good: #4cc38a;
    --good-soft: #14291f;
    --warn: #e3ac4d;
    --warn-soft: #2e2413;
    --bad: #f07070;
    --bad-hover: #f58c8c;
    --bad-soft: #331b1d;
    --log-bg: #0a0e15;
    --shadow: none;
    --shadow-big: 0 12px 32px rgb(0 0 0 / 55%);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}

[hidden] { display: none !important; }

h1, h2, h3, p, dl, dd { margin: 0; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; line-height: 1.25; }
h2 { font-size: 14px; font-weight: 600; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.break { overflow-wrap: anywhere; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Shell */
#shell { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100vh; }

#sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 0 12px 16px;
  background: var(--sidebar);
  color: var(--sidebar-text);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  padding: 0 10px;
  color: #fff;
  font-size: 15px;
  font-weight: 650;
}
.brand:hover { text-decoration: none; }
.brand .icon { width: 22px; height: 22px; color: #7ea6ff; }

.nav-group {
  margin: 16px 10px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #717c8e;
}

#sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  margin-bottom: 2px;
  border-radius: 6px;
  color: var(--sidebar-text);
  font-weight: 500;
}
#sidebar nav a:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
#sidebar nav a.active { background: var(--sidebar-active); color: #fff; }
#sidebar nav a.active .icon { color: #7ea6ff; }

#workspace { display: flex; flex-direction: column; min-width: 0; }

#topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 56px;
  padding: 0 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

#crumbs { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--muted); }
#crumbs span[aria-current] { color: var(--text); font-weight: 600; }
#crumbs a { color: var(--muted); }
.crumb-gap { color: var(--line-strong); }

.topbar-actions { display: flex; gap: 8px; flex: none; }

#view { flex: 1; padding: 24px 28px 48px; outline: none; }
#view[aria-busy="true"] { opacity: 0.6; transition: opacity 0.15s 0.15s; }

/* Page structure */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-subtitle { margin-top: 4px; color: var(--muted); max-width: 72ch; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.stack { display: flex; flex-direction: column; gap: 16px; }
.columns { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; align-items: start; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
}
.card-head p { color: var(--muted); font-size: 12.5px; }
.card-body { padding: 16px; }
.card-body > * + * { margin-top: 12px; }
.card.danger-zone { border-color: var(--bad); }
.card.danger-zone .card-head h2 { color: var(--bad); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 16px; }
.tile { padding: 14px 16px; }
.tile-label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; font-weight: 500; }
.tile-value { margin-top: 6px; font-size: 24px; font-weight: 650; letter-spacing: -0.01em; }
.tile-note { margin-top: 2px; color: var(--muted); font-size: 12.5px; }
.tile.bad .tile-value { color: var(--bad); }

/* Buttons */
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 5px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
button:hover, .button:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover, .button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button.danger:hover { background: var(--bad-hover); border-color: var(--bad-hover); }
button.quiet { background: none; border-color: transparent; color: var(--muted); }
button.quiet:hover { background: var(--surface-2); color: var(--text); }
button.wide { width: 100%; }
button.square { width: 32px; padding: 0; }

@media (prefers-color-scheme: dark) {
  button.primary, .button.primary, button.danger { color: #0c111a; }
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

/* Status */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--line);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.plain::before { display: none; }

.banner {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  margin-bottom: 16px;
}
.banner > .icon { margin-top: 2px; }
.banner-body { flex: 1; min-width: 0; }
.banner-body > * + * { margin-top: 6px; }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.info { background: var(--accent-soft); color: var(--accent); }
.banner.good { background: var(--good-soft); color: var(--good); }
.banner-title { font-weight: 600; }
.banner-text { color: var(--text); }
.banner a { color: inherit; text-decoration: underline; }
.stack .banner { margin-bottom: 0; }

/* Tabs */
.tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tab {
  padding: 8px 12px;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  padding: 8px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}
td { padding: 10px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
tr.detail-row:hover td { background: none; }
td.end, th.end { text-align: right; }

/* Details list */
.details { display: grid; grid-template-columns: minmax(110px, 170px) minmax(0, 1fr); gap: 8px 16px; }
.details dt { color: var(--muted); }
.details dd { overflow-wrap: anywhere; }

/* Meters */
.meter + .meter { margin-top: 14px; }
.meter-label { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 5px; font-size: 13px; }
.meter-bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.meter-bar span { display: block; height: 100%; background: var(--accent); }
.meter-bar.warn span { background: var(--warn); }
.meter-bar.bad span { background: var(--bad); }
td .meter-bar { width: 140px; }
td.mono.break { min-width: 190px; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label, .field-label { font-weight: 550; }
.field-help { color: var(--muted); font-size: 12.5px; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; }
.card-body > .field-grid { margin-top: 12px; }
.card-body > .field-grid:first-child { margin-top: 0; }

input, select, textarea {
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input[type="checkbox"] { width: 15px; height: 15px; min-height: 0; margin: 0; flex: none; accent-color: var(--accent); }
input::placeholder { color: var(--muted); opacity: 0.75; }
input.mono { font-family: var(--mono); font-size: 13px; }

.check { display: flex; align-items: flex-start; gap: 8px; }
.check input { margin-top: 3px; }
.check small { display: block; color: var(--muted); font-size: 12.5px; }

.rows { display: flex; flex-direction: column; gap: 8px; }
.row-line { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.row-line.pair { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr) auto; }
.row-line.pair.secret { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr) auto auto; }

details.advanced > summary { cursor: pointer; font-weight: 550; padding: 2px 0; }
details.advanced[open] > summary { margin-bottom: 12px; }
details.advanced > * + * { margin-top: 12px; }

.form-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.summary { position: sticky; top: 72px; }
.summary .details { grid-template-columns: 90px minmax(0, 1fr); }
#view form > div { scroll-margin-top: 72px; }
.form-foot { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* Logs */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar select { width: auto; }
.toolbar input[type="search"] { width: 240px; max-width: 100%; }
.toolbar .check { align-items: center; }
.toolbar .spacer { flex: 1; }

.log {
  max-height: calc(100vh - 300px);
  min-height: 240px;
  margin: 0;
  padding: 12px 14px;
  overflow: auto;
  background: var(--log-bg);
  color: var(--log-text);
  border-radius: 8px;
  font: 12.5px/1.55 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.log .bad { color: var(--log-bad); }
.log .head { color: var(--log-head); font-weight: 600; margin-top: 8px; }
.log .head:first-child { margin-top: 0; }
.log.short { max-height: 320px; min-height: 0; }

pre.plain {
  margin: 0;
  padding: 10px 12px;
  max-height: 320px;
  overflow: auto;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: 12.5px/1.55 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; }
.segmented button { min-height: 30px; border: 0; border-radius: 0; background: var(--surface); }
.segmented button + button { border-left: 1px solid var(--line-strong); }
.segmented button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 10px; justify-content: space-between; padding: 9px 16px; border-bottom: 1px solid var(--line); }
.feed li:last-child { border-bottom: 0; }

.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.empty > * + * { margin-top: 12px; }
.empty h1 { color: var(--text); }

/* Dialog and toasts */
dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-big);
}
dialog::backdrop { background: rgb(10 14 21 / 55%); }
dialog h2 { font-size: 16px; }
dialog p { margin-top: 8px; color: var(--muted); }
dialog .field { margin-top: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

#toasts {
  position: fixed;
  z-index: 20;
  top: 12px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(380px, calc(100vw - 32px));
}
.toast {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  box-shadow: var(--shadow-big);
  overflow-wrap: anywhere;
}
.toast.good { border-left-color: var(--good); }
.toast.bad { border-left-color: var(--bad); }
.toast .icon { margin-top: 2px; }
.toast.good .icon { color: var(--good); }
.toast.bad .icon { color: var(--bad); }

/* Sign-in */
.gate {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 16px;
  background: var(--sidebar);
}
.gate-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(400px, 100%);
  padding: 28px;
  background: var(--surface);
  border-radius: 10px;
  box-shadow: var(--shadow-big);
}
.gate-brand { display: flex; align-items: center; gap: 8px; font-weight: 650; color: var(--accent); }
.gate-brand .icon { width: 22px; height: 22px; }
.file-pick {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}
.file-pick:hover { background: var(--accent-soft); }
.file-input { position: absolute; width: 1px; height: 1px; min-height: 0; padding: 0; opacity: 0; }
.file-input:focus-visible + .check { outline: none; }

/* Source of a project */
.source-picker { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.source-option {
  position: relative;
  display: flex;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.source-option:hover { background: var(--surface-2); }
.source-option input { position: absolute; width: 1px; height: 1px; min-height: 0; padding: 0; opacity: 0; }
.source-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.source-option:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
.source-mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
}
.source-option:has(input:checked) .source-mark { background: var(--accent); color: #fff; }
.source-text { display: flex; flex-direction: column; min-width: 0; }
.source-text strong { font-weight: 600; }
.source-text small { color: var(--muted); font-size: 12.5px; line-height: 1.35; }
.source-cell { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.source-cell .mono { min-width: 0; max-width: 260px; overflow: hidden; color: var(--text); text-overflow: ellipsis; white-space: nowrap; }
td.child { padding-left: 34px; }
td.child a::before { content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 7px; border-left: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong); transform: translateY(-3px); }

textarea { display: block; resize: vertical; line-height: 1.5; }
textarea.code { font: 12.5px/1.6 var(--mono); tab-size: 2; white-space: pre; overflow-x: auto; }
textarea.code.tall { min-height: 240px; }

.copy-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 2px 2px 2px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}
.copy-field code { flex: 1; min-width: 0; font-size: 12.5px; }

tr.selected td { background: var(--accent-soft); }
tbody tr.selected:hover td { background: var(--accent-soft); }
.actions.end { justify-content: flex-end; flex-wrap: nowrap; }
.card-body > .table-wrap, .card-body .stack > .table-wrap { border: 1px solid var(--line); border-radius: 6px; }
td.break { min-width: 170px; overflow-wrap: break-word; }
.log-card { overflow: hidden; }
.log-card .log { border-radius: 0; max-height: 520px; min-height: 200px; }
.log.flat { border-radius: 0 0 8px 8px; }
.log .head:not(:first-child) { margin-top: 2px; }

.badge.pulse::before { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .badge.pulse::before { animation: none; } }

/* Narrow screens */
@media (max-width: 1100px) {
  .columns, .form-layout { grid-template-columns: minmax(0, 1fr); }
  .summary { position: static; }
}

@media (max-width: 800px) {
  #shell { display: block; }
  #sidebar { position: static; height: auto; padding: 0 16px 8px; }
  .brand { height: 48px; padding: 0; }
  .nav-group { display: none; }
  #sidebar nav { display: flex; gap: 4px; overflow-x: auto; }
  #sidebar nav a { flex: none; margin: 0; }
  #topbar { position: static; height: auto; min-height: 52px; padding: 8px 16px; flex-wrap: wrap; }
  #view { padding: 16px 16px 40px; }
  .row-line.pair, .row-line.pair.secret { grid-template-columns: minmax(0, 1fr) auto; }
  .row-line.pair > input:first-child { grid-column: 1 / -1; }
  .details { grid-template-columns: minmax(0, 1fr); gap: 2px 0; }
  .details dd { margin-bottom: 8px; }
  .log { max-height: 60vh; }
  .source-picker { grid-template-columns: minmax(0, 1fr); }
  .card-head { flex-wrap: wrap; }
  .table-wrap { overflow-x: visible; }
  .table-wrap table, .table-wrap tbody { display: block; }
  .table-wrap thead { display: none; }
  .table-wrap tbody tr { display: block; padding: 10px 16px; border-bottom: 1px solid var(--line); }
  .table-wrap tbody tr:last-child { border-bottom: 0; }
  .table-wrap tbody td { display: block; min-width: 0; padding: 4px 0; border: 0; background: none; }
  .table-wrap tbody td[data-label] { display: flex; align-items: center; justify-content: space-between; gap: 16px; text-align: right; }
  .table-wrap tbody td[data-label]::before { content: attr(data-label); flex: none; color: var(--muted); font: 12.5px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; text-align: left; }
  .table-wrap tbody td[data-label=""] { justify-content: flex-start; }
  .table-wrap tbody td[data-label=""]::before { display: none; }
  .table-wrap tbody td:empty { display: none; }
  .table-wrap td.child { padding-left: 0; }
  .table-wrap td .actions.end { flex-wrap: wrap; justify-content: flex-start; }
  .source-cell .mono { max-width: 190px; }
  td .meter-bar { width: 100px; }
}
