:root {
  --paper: #f6f1e8;
  --paper-deep: #ebe2d2;
  --ink: #1e2521;
  --ink-soft: #5f675f;
  --ink-faint: #858c83;
  --line: #d7cdbd;
  --card: #fffaf1;
  --cortexa: #006c67;
  --clinical: #8b3a31;
  --billing: #78621f;
  --client: #37637a;
  --warn: #a05a18;
  --open: #7d5069;
  --shadow: 0 18px 40px rgba(45, 40, 32, 0.12);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

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

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 26px 20px;
  border-right: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(255, 250, 241, 0.96), rgba(255, 250, 241, 0.86)),
    repeating-linear-gradient(0deg, transparent, transparent 23px, rgba(0, 108, 103, 0.045) 24px);
}

.brand {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.brand-kicker,
.crumb,
.nav-label,
.callout-label,
.mb-cap {
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 11px;
  font-weight: 800;
}

.brand-kicker {
  color: var(--cortexa);
}

.brand h1 {
  margin: 5px 0 6px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 30px;
  line-height: 1;
}

.brand p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 14px;
}

.account-switcher {
  display: grid;
  gap: 8px;
}

.account-switcher button,
.nav-item {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
  border-radius: 8px;
  cursor: pointer;
}

.account-switcher button {
  padding: 10px 12px;
  color: var(--ink-soft);
}

.account-switcher button.active {
  border-color: var(--line);
  background: var(--card);
  color: var(--ink);
}

.search input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: rgba(255, 250, 241, 0.72);
  color: var(--ink);
  outline: none;
}

.search input:focus {
  border-color: var(--cortexa);
  box-shadow: 0 0 0 3px rgba(0, 108, 103, 0.12);
}

.nav {
  overflow: auto;
  padding-right: 2px;
}

.nav-group + .nav-group {
  margin-top: 22px;
}

.nav-label {
  display: block;
  margin: 0 0 8px 8px;
  color: var(--ink-faint);
}

.nav-item {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  margin-bottom: 5px;
  color: var(--ink-soft);
}

.nav-item:hover,
.nav-item.active {
  background: var(--card);
  border-color: var(--line);
  color: var(--ink);
}

.nav-item.active {
  box-shadow: inset 3px 0 0 var(--cortexa);
}

.scope-dot {
  color: var(--ink-faint);
  font-size: 11px;
}

.nav-empty,
.rail-foot {
  color: var(--ink-faint);
  font-size: 12px;
}

.rail-foot {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--cortexa);
  cursor: pointer;
  padding: 0;
  font-weight: 700;
}

.main {
  min-width: 0;
  padding: 48px clamp(24px, 6vw, 82px);
}

.doc {
  max-width: 1080px;
}

.doc-head {
  margin-bottom: 34px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.crumb {
  color: var(--ink-faint);
}

.doc-head h2 {
  margin: 8px 0 12px;
  max-width: 840px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(34px, 5vw, 62px);
  line-height: 0.96;
  font-weight: 700;
}

.coverage-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.coverage-row span {
  border: 1px solid var(--line);
  background: var(--paper-deep);
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  color: var(--ink-soft);
}

.doc-body {
  display: grid;
  gap: 18px;
}

.mb-prose {
  max-width: 820px;
  margin: 0;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.68;
}

.mb-subhead {
  margin: 22px 0 0;
  font-size: 22px;
  line-height: 1.18;
  font-weight: 800;
}

.mb-list,
.mb-ol,
.mb-steps {
  max-width: 880px;
  margin: 0;
  padding-left: 24px;
  line-height: 1.62;
}

.mb-list li,
.mb-ol li,
.mb-steps li {
  margin: 5px 0;
}

.mb-steps {
  counter-reset: step;
  list-style: none;
  padding-left: 0;
}

.mb-steps li {
  position: relative;
  min-height: 36px;
  padding: 6px 0 10px 46px;
  border-bottom: 1px solid rgba(215, 205, 189, 0.68);
}

.mb-steps li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 0;
  top: 4px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--cortexa);
  color: white;
  font-size: 12px;
  font-weight: 800;
}

.mb-cap {
  margin-top: 10px;
  color: var(--ink-faint);
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  text-align: left;
  font-size: 14px;
  line-height: 1.48;
}

th {
  background: var(--paper-deep);
  color: var(--ink-soft);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

tr:last-child td {
  border-bottom: 0;
}

.kv {
  max-width: 880px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--card);
}

.kv-row {
  display: grid;
  grid-template-columns: minmax(160px, 0.35fr) minmax(0, 1fr);
  border-bottom: 1px solid var(--line);
}

.kv-row:last-child {
  border-bottom: 0;
}

.kv-key,
.kv-value {
  padding: 13px 15px;
  line-height: 1.5;
}

.kv-key {
  background: var(--paper-deep);
  color: var(--ink-soft);
  font-weight: 800;
}

.mb-diagram {
  margin: 0;
  max-width: 980px;
  overflow-x: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #262a25;
  color: #f8ead2;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.callout {
  max-width: 880px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--cortexa);
  border-radius: 8px;
  padding: 16px 18px;
  background: var(--card);
}

.callout.tone-warn {
  border-left-color: var(--warn);
}

.callout.tone-open {
  border-left-color: var(--open);
}

.callout p {
  margin: 6px 0 0;
  line-height: 1.6;
}

.callout-label {
  color: var(--ink-soft);
}

.inline-link {
  display: inline;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--cortexa);
  font-weight: 800;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.inline-disabled {
  color: var(--ink-soft);
}

code {
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  background: rgba(255, 250, 241, 0.8);
  font-family: "SF Mono", Consolas, monospace;
  font-size: 0.9em;
}

.login-only,
.loading-only {
  display: grid;
  grid-template-columns: 1fr;
  place-items: center;
  padding: 24px;
}

.login-panel,
.loading-panel {
  width: min(100%, 460px);
}

.login-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.login-card h1,
.loading-panel h1 {
  margin: 6px 0 22px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 38px;
  line-height: 1;
}

.login-card form {
  display: grid;
  gap: 14px;
}

.login-card label {
  display: grid;
  gap: 7px;
  color: var(--ink-soft);
  font-weight: 800;
}

.login-card input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--paper);
  color: var(--ink);
}

.login-card button[type="submit"] {
  height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--cortexa);
  color: white;
  cursor: pointer;
  font-weight: 800;
}

.login-card button[type="submit"]:disabled {
  opacity: 0.6;
  cursor: wait;
}

.form-error,
.setup-copy {
  min-height: 20px;
  margin: 0;
  color: var(--clinical);
  line-height: 1.45;
}

@media (max-width: 860px) {
  .app-shell {
    display: block;
  }

  .rail {
    position: relative;
    height: auto;
    padding: 20px 16px;
  }

  .nav {
    max-height: 42vh;
  }

  .main {
    padding: 30px 16px 48px;
  }

  .kv-row {
    grid-template-columns: 1fr;
  }

  .doc-head h2 {
    font-size: 36px;
  }
}
