:root {
  --page: #e6eaed;
  --surface: #f8f9fa;
  --raised: #ffffff;
  --ink: #17212b;
  --muted: #56636f;
  --line: #c6ced6;
  --rail: #1f2b37;
  --rail-ink: #dfe5ea;
  --rail-muted: #93a1ad;
  --orange: #c9440e;
  --orange-deep: #a8380b;
  --orange-wash: #fdeee4;
  --good: #1c6e46;
  --good-wash: #e3f2ea;
  --danger: #ad2218;
  --danger-wash: #fbe9e7;
  --sans: "Avenir Next", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --radius: 4px;
}

*, *::before, *::after { box-sizing: border-box; }

html { font-size: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.9375rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, ul, fieldset { margin: 0; padding: 0; }
h1 { font-size: 1.75rem; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.125rem; line-height: 1.3; font-weight: 650; letter-spacing: -0.01em; }
h3 { font-size: 0.9375rem; font-weight: 650; margin-top: 1.25rem; }
ul { list-style: none; }
fieldset { border: 0; }
a { color: inherit; }

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

.mono { font-family: var(--mono); font-size: 0.875rem; }
.quiet { color: var(--muted); }
.nowrap { white-space: nowrap; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.375rem;
  padding: 0 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--raised);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.button:hover { border-color: var(--muted); }
.button:disabled { opacity: 0.5; cursor: not-allowed; }
.button.primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.button.primary:hover { background: var(--orange-deep); border-color: var(--orange-deep); }
.button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.button.small { min-height: 1.875rem; padding: 0 0.6rem; font-size: 0.8125rem; }
.button.wide { width: 100%; }

.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 3px;
  cursor: pointer;
}
.link:hover { text-decoration-color: currentColor; }
.link:disabled { opacity: 0.5; cursor: not-allowed; }
.danger-text { color: var(--danger); }

.field { display: flex; flex-direction: column; gap: 0.3rem; margin-top: 0.9rem; }
.field-label { font-size: 0.8125rem; font-weight: 600; }
.hint { color: var(--muted); font-size: 0.8125rem; }

input, select, textarea {
  width: 100%;
  min-height: 2.375rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--raised);
  color: var(--ink);
  font: inherit;
}
textarea { resize: vertical; }
input[type="checkbox"] { width: 1.05rem; min-height: 0; height: 1.05rem; margin: 0.2rem 0 0; accent-color: var(--orange); }
input:disabled, textarea:disabled, select:disabled { background: var(--page); }
select { width: auto; max-width: 100%; }
.field select { width: 100%; }

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; }
.row-end { align-items: flex-end; }
.row-end .field { margin-top: 0; }
.grow { flex: 1 1 14rem; }
.narrow { max-width: 26rem; }
.narrow .button { margin-top: 1rem; }
.stack { display: flex; flex-direction: column; }
.check { display: flex; gap: 0.6rem; margin: 1.25rem 0 1rem; }

.notice, .problem {
  margin-top: 1rem;
  padding: 0.6rem 0.8rem;
  border-left: 3px solid var(--orange);
  background: var(--orange-wash);
  font-size: 0.875rem;
}
.problem { border-color: var(--danger); background: var(--danger-wash); color: #6e150e; }
.notice-good { border-color: var(--good); background: var(--good-wash); }

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.9375rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.brand-mark {
  width: 1.15rem;
  height: 1.15rem;
  border: 3px solid var(--orange);
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px var(--rail), inset 0 0 0 5px var(--orange);
}

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background:
    repeating-linear-gradient(90deg, transparent 0 119px, rgba(23, 33, 43, 0.05) 119px 120px),
    var(--page);
}
.door {
  width: min(27rem, 100%);
  padding: 2rem 2rem 1.5rem;
  border: 1px solid var(--line);
  border-top: 6px solid var(--rail);
  border-radius: var(--radius);
  background: var(--surface);
}
.door .brand-mark { box-shadow: inset 0 0 0 2px var(--surface), inset 0 0 0 5px var(--orange); }
.door h1 { margin-top: 1.5rem; }
.door .lede { margin-top: 0.75rem; }
.door .button.wide { margin-top: 1.25rem; }
.door > .hint { display: block; margin-top: 1.25rem; }
.lede { color: var(--muted); max-width: 60ch; }
.door-foot { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.8125rem; }
.door-links { display: flex; justify-content: space-between; margin-top: 1rem; }
.dev-login { margin-top: 1.5rem; padding-top: 0.25rem; border-top: 1px dashed var(--line); }
.dev-login .button { margin-top: 0.9rem; }

.recovery-code, .fingerprint {
  margin-top: 1rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--raised);
  font-family: var(--mono);
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 1.7;
  overflow-wrap: anywhere;
  user-select: all;
}
.recovery-code + .row { margin-top: 0.75rem; }
.fingerprint.small { display: block; margin: 0.3rem 0 0; padding: 0; border: 0; background: none; font-size: 0.8125rem; letter-spacing: 0.04em; }

.shell { display: grid; grid-template-columns: 15.5rem minmax(0, 1fr); min-height: 100vh; }

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0.75rem 1rem;
  background: var(--rail);
  color: var(--rail-ink);
  overflow-y: auto;
}
.rail .brand { padding: 0 0.6rem 1.25rem; color: #fff; }
.rail nav { display: flex; flex-direction: column; gap: 2px; }
.rail-head { margin: 1.25rem 0 0.3rem; padding: 0 0.6rem; color: var(--rail-muted); font-size: 0.75rem; font-weight: 600; }
.rail-foot { margin-top: auto; padding-top: 1rem; display: flex; flex-direction: column; gap: 2px; border-top: 1px solid rgba(255, 255, 255, 0.12); }
.nav, .nav-side {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 2.125rem;
  padding: 0 0.6rem;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.nav { flex: 1; min-width: 0; }
.nav > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav:hover, .nav-side:hover { background: rgba(255, 255, 255, 0.07); }
.nav-on { border-left-color: #f76707; background: rgba(255, 255, 255, 0.1); color: #fff; font-weight: 600; }
.nav-pair { display: flex; gap: 2px; }
.nav-side { flex: none; border-left: 0; border-radius: var(--radius); color: var(--rail-muted); font-size: 0.8125rem; }
.nav-side::before { content: ""; width: 0.5rem; height: 0.5rem; border: 1.5px solid currentColor; border-radius: 50%; margin-right: 0.3rem; }
.nav-add { justify-content: flex-start; color: var(--rail-muted); }
.nav-add::before { content: "+"; }
.count { color: var(--rail-muted); font-size: 0.8125rem; font-variant-numeric: tabular-nums; }

.stage { padding: 2rem clamp(1rem, 4vw, 3rem) 4rem; max-width: 68rem; width: 100%; }
.stage-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.stage-head .quiet { margin-top: 0.35rem; max-width: 62ch; }
.stage > .notice { margin: 0 0 1.5rem; }
.search { margin-bottom: 1.5rem; }
.section-title { margin: 2rem 0 0.75rem; }

.app {
  margin-bottom: 1.25rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.app-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.75rem; padding: 1rem 1.25rem; }
.app-head h2 { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; font-size: 1.25rem; }
.app-desc { margin-top: 0.2rem; color: var(--muted); max-width: 70ch; }

.env { border-top: 1px solid var(--line); padding: 0.9rem 1.25rem 1rem 1.25rem; position: relative; }
.env::before { content: ""; position: absolute; left: -1px; top: -1px; bottom: -1px; width: 4px; background: var(--rail); }
.env-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.75rem; }
.env-name {
  padding: 0.05rem 0.5rem;
  border-radius: 2px;
  background: var(--rail);
  color: #fff;
  font-family: var(--mono);
  font-size: 0.8125rem;
  font-weight: 600;
}
.env-add { margin-left: auto; }
.env-desc { margin-top: 0.35rem; color: var(--muted); font-size: 0.875rem; }
.env-empty { margin-top: 0.6rem; font-size: 0.875rem; }
.url { font-family: var(--mono); font-size: 0.8125rem; overflow-wrap: anywhere; text-underline-offset: 3px; }
.url-plain { color: var(--muted); }

.creds { margin-top: 0.75rem; display: flex; flex-direction: column; gap: 0.5rem; }
.cred {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--raised);
}
.cred-main { flex: 1 1 16rem; min-width: 0; }
.cred-title { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; font-weight: 650; }
.cred-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.6rem; margin-top: 0.15rem; color: var(--muted); }
.cred-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; align-self: flex-start; }
.secret {
  margin-top: 0.6rem;
  padding: 0.45rem 0.6rem;
  border: 1px dashed var(--orange);
  border-radius: var(--radius);
  background: var(--orange-wash);
  font-size: 1rem;
  overflow-wrap: anywhere;
  user-select: all;
}
.notes { margin-top: 0.5rem; color: var(--muted); font-size: 0.875rem; white-space: pre-wrap; max-width: 70ch; }

.tag {
  padding: 0 0.4rem;
  border: 1px solid var(--line);
  border-radius: 2px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}
.tag-plain { border-style: dashed; }
.tag-warn { border-color: var(--danger); color: var(--danger); }

.empty { padding: 3rem 1.5rem; border: 1px dashed var(--line); border-radius: var(--radius); text-align: center; }
.empty-title { font-size: 1.125rem; font-weight: 650; }

.veil { position: fixed; inset: 0; background: rgba(23, 33, 43, 0.45); }
.sheet {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(32rem, 100%);
  padding: 1.75rem 1.75rem 0;
  background: var(--surface);
  border-left: 1px solid var(--line);
  overflow-y: auto;
}
.sheet h2 { font-size: 1.375rem; }
.sheet .lede { margin-top: 0.5rem; }
.sheet > .button { margin-top: 0.9rem; }
.sheet > .hint { display: block; margin-top: 0.75rem; }
.sheet-foot {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin: 1.5rem -1.75rem 0;
  padding: 0.9rem 1.75rem;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.env-edit { margin-top: 0.75rem; padding: 0.1rem 0.9rem 0.8rem; border: 1px solid var(--line); border-left: 4px solid var(--rail); border-radius: var(--radius); background: var(--raised); }
.env-edit-grid { display: grid; grid-template-columns: 8rem 1fr; gap: 0.75rem; }
.env-edit .link { margin-top: 0.7rem; }

.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); }
.table th { padding: 0.55rem 0.9rem; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 0.8125rem; font-weight: 600; text-align: left; }
.table td { padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table td > .quiet, .table td > .person, .table td > .status { display: block; }
.table td > .quiet { font-size: 0.8125rem; }
.table td > .tag { display: inline-block; margin-top: 0.25rem; }
.table-dense td { padding: 0.4rem 0.9rem; font-size: 0.8125rem; overflow-wrap: anywhere; }
.table-dense .mono { white-space: nowrap; overflow-wrap: normal; font-size: 0.75rem; }
.table + .button { margin-top: 1rem; }
.person { font-weight: 650; }
.cell-actions { text-align: right; white-space: nowrap; }
.cell-actions > * { margin-left: 0.6rem; }
.status { font-weight: 600; }
.status-wait { color: var(--orange-deep); }
.status-off { color: var(--danger); }
.row-pending td { background: var(--orange-wash); }

.panel { margin-top: 1.5rem; padding: 1.1rem 1.25rem 1.25rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.panel > .quiet { margin-top: 0.3rem; max-width: 68ch; }
.panel > .button, .panel > .row { margin-top: 0.9rem; }

.flash {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  display: flex;
  align-items: baseline;
  gap: 1rem;
  max-width: min(40rem, calc(100% - 2rem));
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  background: var(--rail);
  color: #fff;
  box-shadow: 0 6px 24px rgba(23, 33, 43, 0.3);
}
.flash .link { color: #fff; text-decoration-color: rgba(255, 255, 255, 0.5); }
.flash-error { background: var(--danger); }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; }
  .rail-foot { margin-top: 1rem; }
  .table, .table tbody, .table tr, .table td { display: block; }
  .table thead { display: none; }
  .table td { border-bottom: 0; padding: 0.3rem 0.9rem; }
  .table tr { padding: 0.5rem 0; border-bottom: 1px solid var(--line); }
  .cell-actions { text-align: left; white-space: normal; }
  .cell-actions > * { margin: 0 0.6rem 0 0; }
  .env-edit-grid { grid-template-columns: 1fr; gap: 0; }
}

@media (prefers-reduced-motion: no-preference) {
  .sheet { animation: sheet-in 160ms ease-out; }
  @keyframes sheet-in { from { transform: translateX(1.5rem); opacity: 0; } }
}
