:root {
  color-scheme: dark;
  --bg: #191919;
  --sidebar: #141414;
  --surface: #202020;
  --surface-raised: #262626;
  --field: #121212;
  --line: #2c2c2c;
  --strong-line: #3a3a3a;
  --fg: #ededed;
  --muted: #a3a3a3;
  --faint: #757575;
  --blue: #2457ff;
  --blue-hover: #1c47e0;
  --link: #8fa6ff;
  --focus: #6f8cff;
  --green: #7dd8a2;
  --green-bg: #1d3328;
  --amber: #f3a43b;
  --amber-bg: #34281a;
  --amber-line: #6b4a1a;
  --indigo: #a3b1ff;
  --indigo-bg: #262c48;
  --grey: #c2c2c2;
  --grey-bg: #2d2d2d;
  --red: #ff8f8f;
  --red-bg: #3a2222;
  --red-line: #6e2f2f;
  --font: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 10px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3, p, dl, dd, ol, ul { margin: 0; }
h1 { font-size: 1.75rem; font-weight: 650; letter-spacing: -0.02em; line-height: 1.2; }
h2 { font-size: 1.1rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[tabindex="-1"]:focus { outline: none; }
hr { border: 0; border-top: 1px solid var(--line); margin: 22px 0; }

.visually-hidden, .skip-link {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.skip-link:focus { z-index: 10; inset: 12px auto auto 12px; width: auto; height: auto; padding: 8px 14px; clip-path: none; background: var(--surface); border-radius: 8px; }
.loading { padding: 40vh 24px 0; color: var(--muted); text-align: center; }
.language-picker { display: flex; justify-content: flex-end; padding: 12px 24px 0; }
.language-picker select {
  max-width: 100%; min-height: 36px; padding: 4px 8px;
  border: 1px solid var(--strong-line); border-radius: 8px; background: var(--field); font-size: 0.875rem;
}
.sidebar .language-picker { padding: 0 10px; justify-content: stretch; }
.sidebar .language-picker select { width: 100%; }

/* Shell */
.app { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; display: flex; flex-direction: column; gap: 22px;
  height: 100vh; padding: 22px 14px 18px; overflow-y: auto;
  background: var(--sidebar); border-right: 1px solid var(--line);
}
.sidebar-logo { padding: 2px 10px 0; line-height: 0; }
.sidebar-logo img { width: 96px; height: auto; }
.preview-label { margin: -14px 10px 0; color: var(--amber); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
select.project-switch {
  width: 100%; min-height: 44px; padding: 0 36px 0 12px; appearance: none;
  border: 1px solid var(--strong-line); border-radius: var(--radius); background-color: var(--sidebar);
  font-weight: 600;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='14' viewBox='0 0 10 14' fill='none' stroke='%23a3a3a3' stroke-width='1.5'%3E%3Cpath d='M2 5l3-3 3 3M2 9l3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
#nav { display: grid; gap: 22px; }
.nav-group { display: grid; gap: 2px; }
.nav-heading { padding: 0 10px 6px; color: var(--faint); font-size: 0.8rem; }
#nav a, .user-link {
  display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 6px 10px;
  border-radius: 8px; color: #d6d6d6; font-size: 0.94rem; text-decoration: none;
}
#nav a:hover, .user-link:hover { background: #1c1c1c; color: var(--fg); }
#nav a[aria-current="page"], .user-link[aria-current="page"] { background: #262626; color: var(--fg); font-weight: 600; }
#nav a.attention::after { content: ""; margin-left: auto; width: 7px; height: 7px; border-radius: 50%; background: var(--amber); }
#nav .external { margin-left: auto; color: var(--faint); font-size: 0.85em; }
.user-link { margin-top: auto; gap: 12px; }
.avatar {
  display: grid; place-items: center; flex: none; width: 30px; height: 30px; border-radius: 50%;
  background: #2b2f45; color: var(--indigo); font-size: 0.72rem; font-weight: 700;
}
.user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { min-width: 0; }
.view { max-width: 980px; padding: 36px clamp(20px, 4vw, 44px) 72px; }
.view > * + * { margin-top: 24px; }
.page-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px 20px; }
.page-actions { display: flex; align-items: center; gap: 10px; }
.title-with-badge { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.back-link { display: inline-block; margin-bottom: -12px; font-size: 0.92rem; }
.description, .hint { color: var(--muted); }
.hint { font-size: 0.85rem; }
.lede { max-width: 42rem; font-size: 1.35rem; font-weight: 550; line-height: 1.4; letter-spacing: -0.01em; }
.section > * + * { margin-top: 12px; }
.subtle { color: #cfcfcf; font-size: 1rem; }

/* Controls */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 0 14px;
  border: 1px solid var(--strong-line); border-radius: 8px; background: transparent; color: var(--fg);
  font-weight: 550; font-size: 0.92rem; text-decoration: none; white-space: nowrap;
}
.button:hover { background: #242424; text-decoration: none; }
.button.primary { border-color: var(--blue); background: var(--blue); color: #fff; font-weight: 650; }
.button.primary:hover { background: var(--blue-hover); }
.button.block { width: 100%; min-height: 46px; }
.button.wide { justify-content: flex-start; width: 100%; }
.button.dashed { border-style: dashed; color: var(--muted); }
.button.danger { border-color: #b33a3a; background: #b33a3a; color: #fff; }
.button.danger-quiet { border-color: var(--red-line); color: var(--red); }
.button.danger-quiet:hover { background: var(--red-bg); }
.button:disabled, .button.primary:disabled { border-color: #2e2e2e; background: #2a2a2a; color: #777; }
.link-button { border: 0; padding: 0; background: none; color: var(--link); font-size: 0.9rem; text-decoration: underline; text-underline-offset: 3px; }
.link-button:disabled { color: var(--faint); }

input:not([type="checkbox"]), select {
  width: 100%; min-height: 44px; padding: 0 12px;
  border: 1px solid var(--strong-line); border-radius: 8px; background: var(--field); color: var(--fg);
}
input:focus, select:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 1px var(--focus); }
input[readonly] { color: #d9d9d9; }
input:disabled, select:disabled { color: var(--faint); }
select { appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none' stroke='%23a3a3a3' stroke-width='1.5'%3E%3Cpath d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
label { display: block; margin-bottom: 8px; color: #cfcfcf; font-size: 0.9rem; }
.field-row { display: flex; flex-wrap: wrap; gap: 16px; }
.field-row > * { min-width: 0; }
.field-row .grow { flex: 1 1 220px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }
.form-actions.start { justify-content: flex-start; }
.form-error { color: var(--red); font-size: 0.9rem; }
.form-error:empty, .form-status:empty { display: none; }
.form-status { color: var(--green); font-size: 0.9rem; }
.locked { display: inline-flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.lock-reason { color: var(--muted); font-size: 0.85rem; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; }
.inline-form input { flex: 1 1 220px; width: auto; }
.inline-form select { width: auto; min-width: 110px; }

/* Badges and status */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px;
  border-radius: 999px; background: var(--grey-bg); color: var(--grey);
  font-size: 0.8rem; font-weight: 550; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge:is([data-state="ready"], [data-state="online"], [data-state="active"]) { background: var(--green-bg); color: var(--green); }
.badge:is([data-state="offline"], [data-state="grace"]) { background: var(--amber-bg); color: var(--amber); }
.badge[data-state="offline"]::before, .badge[data-state="grace"]::before { background: transparent; border: 1.5px solid currentColor; width: 7px; height: 7px; }
.badge:is([data-state="reserved"], [data-state="pending"]) { background: var(--indigo-bg); color: var(--indigo); }
.badge:is([data-state="reserved"], [data-state="pending"])::before { background: transparent; border: 1.5px dotted currentColor; width: 8px; height: 8px; }
.badge[data-state="paused"]::before { width: 6px; height: 8px; border-radius: 0; background: linear-gradient(90deg, currentColor 0 2px, transparent 2px 4px, currentColor 4px); }
.badge[data-state="suspended"] { background: var(--red-bg); color: var(--red); }
.badge[data-state="suspended"]::before { border-radius: 1px; }
.dot-label { display: inline-flex; align-items: center; gap: 8px; }
.dot-label::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.dot-label[data-state="ready"]::before { background: var(--green); }
.dot-label[data-state="reserved"]::before { background: var(--indigo); }
.dot-label[data-state="offline"]::before { background: var(--amber); }
.dot-label[data-state="suspended"]::before { background: var(--red); }
.result[data-tone="success"] { color: var(--green); }
.result[data-tone="warning"] { color: var(--amber); }
.result[data-tone="danger"] { color: var(--red); }

/* Overview */
.stats { display: flex; flex-wrap: wrap; gap: 14px 52px; }
.stat dt { color: var(--muted); font-size: 0.9rem; }
.stat dd { margin-top: 4px; font-size: 1.2rem; font-weight: 600; }

/* Rows */
.rows { list-style: none; padding: 0; border-top: 1px solid var(--line); }
.row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 12px 24px;
  min-height: 74px; padding: 12px 0; border-bottom: 1px solid var(--line);
}
.row:has(.row-meta) { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto auto; }
.connector-row, .connector-row:has(.row-meta) { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 0.7fr) auto; }
.member-row, .member-row:has(.row-meta) { grid-template-columns: minmax(0, 1fr) auto 150px 90px; }
.row-title { overflow-wrap: anywhere; color: var(--fg); font-weight: 600; }
a.row-title:hover { color: #fff; }
code.row-title { font-weight: 500; }
.row-meta { color: var(--muted); font-size: 0.92rem; overflow-wrap: anywhere; }
code.row-meta { color: #bdbdbd; }
.route-label span { font-weight: 600; }
.person { display: grid; }
.person small { color: var(--muted); font-size: 0.85rem; }
.role-label { color: var(--muted); }
.row-links { display: inline-flex; gap: 14px; }

/* Cards and notices */
.card { padding: 28px 30px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.card > * + * { margin-top: 16px; }
.card > label + * { margin-top: 0; }
.card h2 .route-label { font-size: 1.05rem; }
.url-field { display: flex; gap: 10px; }
.url-field input { flex: 1; font-family: var(--mono); font-size: 0.92rem; }
.url-field .button { min-height: 44px; }
.url-preview { color: #d9d9d9; overflow-wrap: anywhere; }
.notice {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px 20px;
  padding: 18px 22px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
.notice[data-tone="warning"] { border-color: var(--amber-line); background: #2a2116; }
.notice[data-tone="danger"] { border-color: var(--red-line); background: #2b1b1b; }
.notice[data-tone="success"] { border-color: #2b5a40; background: #182a20; }
.notice p { color: #d6d6d6; }
.notice strong { color: var(--fg); }
.notice code { color: var(--fg); }
.notice-actions { display: flex; gap: 10px; }
.notice .button { background: #1d1d1d; }
.state-card { padding: 24px 26px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.state-card > * + * { margin-top: 12px; }
.state-card p { color: var(--muted); }
.state-card[data-tone="danger"] { border-color: var(--red-line); background: #2a1c1c; }
.state-card[data-tone="danger"] h2 { color: var(--red); }
.with-spinner { display: flex; align-items: flex-start; gap: 10px; }
.empty-card { padding: 24px 26px; border: 1px dashed var(--strong-line); border-radius: 14px; }
.empty-card > * + * { margin-top: 10px; }
.empty-card p { color: var(--muted); }
.empty-state { padding: 40px 0; }
.empty-state > * + * { margin-top: 10px; }
.empty-state p { color: var(--muted); max-width: 36rem; }
.guide ol { padding-left: 22px; }
.guide li + li { margin-top: 6px; }
.manage > * + * { margin-top: 10px; }
.form-card { max-width: 640px; }
.form-card > label + input, .form-card > label + select { margin-top: 0; }

/* Spinners */
.spinner {
  display: inline-block; flex: none; width: 14px; height: 14px; margin-top: 3px;
  border: 2px solid var(--indigo); border-right-color: transparent; border-radius: 50%; animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; border-right-color: var(--indigo); opacity: 0.6; } }
.waiting { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.92rem; }
.waiting .spinner { margin-top: 0; }
.waiting.done { color: var(--green); }

/* Deliveries */
.search-row { display: flex; gap: 10px; }
.search-field { position: relative; flex: 1; }
.search-field input { padding-left: 38px; }
.search-icon { position: absolute; left: 14px; top: 50%; width: 12px; height: 12px; border: 1.5px solid var(--muted); border-radius: 50%; transform: translateY(-60%); }
.search-icon::after { content: ""; position: absolute; right: -4px; bottom: -4px; width: 5px; height: 1.5px; background: var(--muted); transform: rotate(45deg); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
.deliveries { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.deliveries th { padding: 12px 16px; border-bottom: 1px solid var(--line); color: #cfcfcf; font-weight: 500; text-align: left; white-space: nowrap; }
.deliveries td { padding: 11px 16px; border-bottom: 1px solid #242424; white-space: nowrap; }
.deliveries tr:last-child td { border-bottom: 0; }
.deliveries tbody tr:hover { background: #1d1d1d; }
.deliveries a { color: var(--fg); }
.numeric { text-align: right !important; }
.muted { color: var(--muted); }
.timeline { list-style: none; padding: 0; }
.step { position: relative; display: flex; gap: 16px; padding-bottom: 18px; }
.step:not(:last-child)::before { content: ""; position: absolute; left: 12px; top: 28px; bottom: 2px; width: 1px; background: var(--strong-line); }
.step-mark { position: relative; flex: none; width: 25px; height: 25px; border-radius: 50%; background: var(--green-bg); }
.step-mark::after { content: "✓"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--green); font-size: 0.75rem; font-weight: 700; }
.step[data-state="failed"] .step-mark { background: var(--amber-bg); }
.step[data-state="failed"] .step-mark::after { content: "✕"; color: var(--amber); }
.step[data-state="pending"] .step-mark { background: transparent; border: 1.5px dashed var(--strong-line); }
.step[data-state="pending"] .step-mark::after { content: ""; }
.step div { display: grid; }
.step strong { font-weight: 600; }
.step[data-state="pending"] strong { color: var(--muted); font-weight: 500; }
.step div > span:not(.visually-hidden) { color: var(--muted); font-size: 0.92rem; }
.privacy { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.88rem; }
.lock-icon { position: relative; width: 11px; height: 9px; margin-top: 4px; border: 1.5px solid var(--muted); border-radius: 2px; }
.lock-icon::before { content: ""; position: absolute; left: 1px; bottom: 7px; width: 6px; height: 5px; border: 1.5px solid var(--muted); border-bottom: 0; border-radius: 4px 4px 0 0; }

/* Team, billing, settings */
.invite-form { max-width: 640px; }
.role-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.role-card { padding: 18px 20px; border-radius: 12px; background: var(--surface); }
.role-card p { margin-top: 6px; color: var(--muted); }
.product-card { max-width: 640px; padding: 22px 24px; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.facts { display: flex; flex-wrap: wrap; gap: 12px 40px; }
.facts dt { color: var(--muted); font-size: 0.88rem; }
.facts dd { margin-top: 2px; font-size: 1.05rem; font-weight: 600; }
.card-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.card-actions > .locked:only-child, .card-actions > .button:only-child { width: 100%; }
.settings-form { display: grid; max-width: 440px; }
.settings-form > label:not(:first-child) { margin-top: 20px; }
.settings-form > .form-actions, .settings-form > .form-error, .settings-form > .hint { margin-top: 14px; }
.settings-form > .hint { margin-top: 8px; }
.danger-zone {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  max-width: 640px; padding: 18px 20px; border: 1px solid var(--red-line); border-radius: 12px;
}
.danger-zone p { color: var(--muted); font-size: 0.9rem; }
.view > .button.wide { max-width: 640px; }

/* Sign-in */
.auth { display: grid; place-items: center; min-height: 100vh; padding: 24px; background: #121212; }
.auth-card {
  display: grid; width: min(100%, 440px); padding: 38px; gap: 0;
  border: 1px solid var(--line); border-radius: 16px; background: var(--bg);
}
.auth-card > * + * { margin-top: 14px; }
.auth-card > label { margin: 22px 0 8px; }
.auth-card > label + input { margin-top: 0; }
.auth-card .description { margin-top: 6px; }
.auth-card .button.block { margin-top: 22px; }
.auth-card > .link-button { justify-self: center; margin-top: 18px; }
.auth-logo { width: 110px; height: auto; margin-bottom: 18px; }
.code-input { font-family: var(--mono); font-size: 1.4rem !important; letter-spacing: 0.5em; padding-left: 16px !important; }
.error-box { padding: 12px 16px; border: 1px solid var(--red-line); border-radius: 8px; background: #2b1b1b; color: var(--red); }
.auth-links { display: flex; justify-content: center; gap: 20px; margin-top: 18px !important; }
.scope-list { margin: 0; padding-left: 20px; color: var(--muted); }
.auth-card > p { color: var(--muted); }
.auth-card > p strong, .auth-card > p code { color: var(--fg); }
.device-form { display: grid; gap: 8px; margin-top: 18px !important; }
.device-form input { font-family: var(--mono); letter-spacing: 0.12em; text-transform: uppercase; }
.device-form .button { margin-top: 10px; }
.decision { display: flex; gap: 10px; margin-top: 24px !important; }
.decision .button { flex: 1; }

/* Dialog */
.dialog { width: min(92vw, 460px); padding: 0; border: 1px solid var(--strong-line); border-radius: 14px; background: var(--surface); color: var(--fg); }
.dialog::backdrop { background: rgb(0 0 0 / 0.6); }
.dialog form { display: grid; gap: 14px; padding: 26px; }
.dialog p { color: var(--muted); }
.dialog label { margin: 4px 0 -6px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

@media (max-width: 820px) {
  .app { display: block; }
  .sidebar { position: static; height: auto; gap: 14px; padding: 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  #nav { display: flex; flex-wrap: wrap; gap: 4px 18px; }
  .nav-group { display: flex; flex-wrap: wrap; gap: 2px; }
  .nav-heading { display: none; }
  .user-link { margin-top: 0; }
  .view { padding: 24px 16px 56px; }
  .row, .row:has(.row-meta), .connector-row, .member-row, .member-row:has(.row-meta) { grid-template-columns: minmax(0, 1fr) auto; }
  .row-meta { grid-column: 1; }
  .url-field, .search-row { flex-wrap: wrap; }
  .card { padding: 20px; }
}
