:root {
  color-scheme: light;
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", system-ui, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", system-ui, sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", ui-monospace, Consolas, monospace;
  --canvas: #f5f5f7;
  --surface: #ffffff;
  --surface-subtle: #f2f2f7;
  --surface-inset: #e9e9ee;
  --surface-elevated: rgba(255, 255, 255, 0.92);
  --text: #1d1d1f;
  --text-secondary: rgba(60, 60, 67, 0.86);
  --text-tertiary: rgba(60, 60, 67, 0.66);
  --accent: #007aff;
  --accent-hover: #006fe6;
  --accent-soft: rgba(0, 122, 255, 0.1);
  --green: #248a3d;
  --green-soft: rgba(52, 199, 89, 0.12);
  --warning: #9a5600;
  --warning-soft: rgba(255, 149, 0, 0.12);
  --danger: #c62920;
  --danger-soft: rgba(255, 59, 48, 0.1);
  --border: rgba(60, 60, 67, 0.18);
  --border-strong: rgba(60, 60, 67, 0.32);
  --focus: 0 0 0 3px rgba(0, 122, 255, 0.28);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 12px 30px rgba(0, 0, 0, 0.06);
  --radius-control: 6px;
  --radius-panel: 10px;
  --radius-large: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --canvas: #0f0f10;
    --surface: #1c1c1e;
    --surface-subtle: #242426;
    --surface-inset: #101011;
    --surface-elevated: rgba(44, 44, 46, 0.94);
    --text: #f2f2f7;
    --text-secondary: rgba(235, 235, 245, 0.86);
    --text-tertiary: rgba(235, 235, 245, 0.66);
    --accent: #0a84ff;
    --accent-hover: #409cff;
    --accent-soft: rgba(10, 132, 255, 0.16);
    --green: #30d158;
    --green-soft: rgba(48, 209, 88, 0.14);
    --warning: #ff9f0a;
    --warning-soft: rgba(255, 159, 10, 0.16);
    --danger: #ff6961;
    --danger-soft: rgba(255, 69, 58, 0.14);
    --border: rgba(255, 255, 255, 0.12);
    --border-strong: rgba(255, 255, 255, 0.22);
    --focus: 0 0 0 3px rgba(10, 132, 255, 0.34);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 16px 40px rgba(0, 0, 0, 0.24);
  }
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 92px;
}

body {
  margin: 0;
  background: var(--canvas);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
}

button,
input,
select,
textarea {
  font: inherit;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

a:hover {
  color: var(--accent-hover);
}

.appbar {
  position: sticky;
  z-index: 20;
  top: 0;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--canvas) 84%, transparent);
  backdrop-filter: saturate(160%) blur(18px);
}

.appbar-inner {
  display: grid;
  width: min(100% - 32px, 1240px);
  min-height: 68px;
  margin: 0 auto;
  grid-template-columns: auto minmax(170px, 1fr) auto auto;
  gap: 22px;
  align-items: center;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  width: 48px;
  height: 31px;
  place-items: center;
  border: 1px solid var(--accent);
  border-radius: 5px;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.brand-copy strong,
.brand-copy span {
  display: block;
}

.brand-copy strong {
  font-size: 13px;
}

.brand-copy span {
  color: var(--text-tertiary);
  font-size: 11px;
}

.save-summary {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 12px;
}

.state-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--text-tertiary);
}

.state-dot[data-state="saved"] {
  background: var(--green);
}

.state-dot[data-state="dirty"],
.state-dot[data-state="working"] {
  background: var(--warning);
}

.state-dot[data-state="error"] {
  background: var(--danger);
}

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

.identity {
  display: grid;
  max-width: 210px;
  justify-items: end;
  font-size: 11px;
  line-height: 1.3;
}

.identity span {
  max-width: 100%;
  overflow: hidden;
  color: var(--text-secondary);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.identity a {
  color: var(--text-tertiary);
}

.button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
}

.button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--text);
}

.button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.choice:has(input:focus-visible) {
  outline: none;
  box-shadow: var(--focus);
}

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.button.primary:hover:not(:disabled) {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
  color: #ffffff;
}

.button.secondary {
  border-color: var(--accent);
  color: var(--accent);
}

.button.quiet {
  border-color: transparent;
  background: transparent;
  color: var(--text-secondary);
}

.button.danger {
  color: var(--danger);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

.workspace {
  display: grid;
  width: min(100% - 32px, 1160px);
  margin: 34px auto 56px;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 30px;
  align-items: start;
}

.section-nav {
  position: sticky;
  top: 102px;
  padding: 8px 0;
}

.nav-label {
  margin: 0 0 10px;
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.section-nav ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

.section-nav li + li {
  margin-top: 2px;
}

.section-nav a {
  display: grid;
  min-height: 38px;
  padding: 8px 9px;
  grid-template-columns: 25px 1fr;
  gap: 6px;
  align-items: center;
  border-radius: var(--radius-control);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 650;
  text-decoration: none;
}

.section-nav a:hover,
.section-nav a:focus-visible {
  background: var(--accent-soft);
  color: var(--text);
  outline: none;
}

.section-nav a span {
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: 10px;
}

.nav-meta {
  display: grid;
  gap: 3px;
  margin-top: 26px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--text-tertiary);
  font-size: 10px;
}

.nav-meta strong {
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 650;
}

.document {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.document-header {
  display: grid;
  padding: 48px 52px 40px;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 40px;
  border-top: 5px solid var(--accent);
  border-bottom: 1px solid var(--border);
}

.eyebrow {
  margin: 0 0 11px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

h1,
h2 {
  margin-top: 0;
  font-family: var(--font-display);
  letter-spacing: -0.025em;
}

h1 {
  max-width: 540px;
  margin-bottom: 16px;
  font-size: clamp(35px, 4vw, 48px);
  line-height: 1.04;
}

.standfirst {
  max-width: 590px;
  margin: 0;
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1.55;
}

.start-note {
  align-self: end;
  padding-left: 17px;
  border-left: 3px solid var(--green);
}

.start-note strong,
.start-note span {
  display: block;
}

.start-note strong {
  margin-bottom: 4px;
}

.start-note span {
  color: var(--text-secondary);
  font-size: 12px;
}

.opening {
  padding: 28px 52px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-subtle);
}

.opening-list {
  display: grid;
  margin: 0;
  padding: 0;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  list-style: none;
}

.opening-list li {
  position: relative;
  padding-left: 21px;
  color: var(--text-secondary);
  font-size: 12px;
}

.opening-list li::before {
  position: absolute;
  left: 0;
  color: var(--green);
  content: "✓";
  font-weight: 900;
}

.secret-notice {
  display: grid;
  margin-top: 20px;
  padding: 13px 15px;
  grid-template-columns: 24px 1fr;
  gap: 11px;
  align-items: start;
  border: 1px solid color-mix(in srgb, var(--warning) 30%, transparent);
  border-left: 4px solid var(--warning);
  border-radius: var(--radius-control);
  background: var(--warning-soft);
}

.notice-mark {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--warning) 45%, transparent);
  border-radius: 50%;
  color: var(--warning);
  font-weight: 850;
}

.secret-notice strong,
.secret-notice span {
  display: block;
}

.secret-notice span {
  color: var(--text-secondary);
  font-size: 12px;
}

.secret-notice strong {
  margin-bottom: 2px;
  color: var(--text);
}

.request-section {
  display: grid;
  padding: 38px 52px 42px;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 14px;
  border-bottom: 1px solid var(--border);
  scroll-margin-top: 88px;
}

.section-number {
  padding-top: 5px;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 800;
}

.section-content h2,
.return-panel h2 {
  margin-bottom: 6px;
  font-size: 24px;
  line-height: 1.18;
}

.section-intro {
  max-width: 670px;
  margin: 0 0 21px;
  color: var(--text-secondary);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.additional-users {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.additional-users h3 {
  margin: 0 0 6px;
  font-size: 18px;
}

.additional-users > p {
  margin: 0 0 16px;
  color: var(--text-secondary);
  font-size: 13px;
}

.known-user-list {
  display: grid;
  margin: 0 0 18px;
  padding: 0;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 24px;
  list-style: none;
  border-top: 1px solid var(--border);
}

.known-user-list li {
  display: flex;
  min-width: 0;
  padding: 11px 0;
  flex-direction: column;
  gap: 2px;
  border-bottom: 1px solid var(--border);
}

.known-user-list strong {
  color: var(--text);
  font-size: 13px;
}

.known-user-list span {
  overflow-wrap: anywhere;
  color: var(--text-secondary);
  font-size: 12px;
}

.field {
  display: grid;
  min-width: 0;
  margin: 0;
  padding: 0;
  gap: 6px;
  border: 0;
}

.field.full {
  grid-column: 1 / -1;
}

.field > span,
.field legend {
  padding: 0;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 750;
}

.optional {
  color: var(--text-tertiary);
  font-weight: 550;
}

input[type="text"],
input[type="email"],
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--text);
}

textarea {
  min-height: 84px;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-tertiary);
  opacity: 0.85;
}

.choice-field {
  margin-top: 2px;
}

.choice-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 5px;
}

.choice {
  display: flex;
  min-height: 40px;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
}

.choice:hover {
  border-color: var(--accent);
}

.choice:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

.choice input {
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--accent);
}

.spaced-field {
  margin-top: 20px;
}

.inline-fact {
  margin: 18px 0 0;
  padding: 12px 14px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  color: var(--text-secondary);
  font-size: 12px;
}

.inline-fact strong {
  color: var(--text);
}

.upload-panel {
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.upload-controls {
  display: flex;
  padding: 16px 0 10px;
  gap: 10px;
  align-items: center;
}

.file-picker {
  position: relative;
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  cursor: pointer;
  font-weight: 700;
}

.file-picker:hover {
  border-color: var(--accent);
}

.file-picker:has(input:focus-visible) {
  box-shadow: var(--focus);
}

.file-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.field-help {
  margin: 0 0 14px;
  color: var(--text-tertiary);
  font-size: 11px;
}

.file-list {
  border-top: 1px solid var(--border);
}

.file-row {
  display: flex;
  min-height: 70px;
  padding: 12px 0;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
}

.file-row + .file-row {
  border-top: 1px solid var(--border);
}

.file-details {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.file-details a {
  overflow: hidden;
  color: var(--text);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-details span,
.file-details code {
  color: var(--text-tertiary);
  font-size: 10px;
}

.file-details code {
  font-family: var(--font-mono);
}

.empty-state {
  margin: 0;
  padding: 18px 0;
  color: var(--text-tertiary);
  font-size: 12px;
}

.error-text {
  color: var(--danger);
}

.return-panel {
  padding: 36px 52px 40px;
  border-top: 4px solid var(--green);
  background: var(--surface-subtle);
}

.return-panel p {
  max-width: 680px;
  margin: 0;
  color: var(--text-secondary);
}

.document-footer {
  display: flex;
  padding: 15px 52px;
  gap: 18px;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  color: var(--text-tertiary);
  font-size: 10px;
}

.decision-dialog {
  max-width: 440px;
  padding: 26px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-large);
  background: var(--surface-elevated);
  color: var(--text);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.decision-dialog::backdrop {
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(4px);
}

.decision-dialog h2 {
  margin-bottom: 7px;
  font-size: 22px;
}

.decision-dialog p {
  margin: 0;
  color: var(--text-secondary);
}

.dialog-actions {
  display: flex;
  margin-top: 24px;
  gap: 8px;
  justify-content: flex-end;
}

.toast {
  position: fixed;
  z-index: 40;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100vw - 44px));
  padding: 12px 15px;
  border: 1px solid color-mix(in srgb, var(--green) 35%, var(--border));
  border-radius: var(--radius-control);
  background: var(--surface-elevated);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 12px;
}

.toast[data-state="error"] {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
}

.is-loading #onboarding-form {
  pointer-events: none;
  opacity: 0.55;
}

.auth-page {
  display: grid;
  min-height: 100vh;
  padding: 24px;
  place-items: center;
}

.auth-panel {
  width: min(100%, 510px);
  padding: 42px;
  border: 1px solid var(--border);
  border-top: 5px solid var(--accent);
  border-radius: var(--radius-panel);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-panel .brand-mark {
  margin-bottom: 34px;
}

.auth-panel h1 {
  margin-bottom: 14px;
  font-size: 34px;
}

.auth-panel > p:not(.eyebrow) {
  color: var(--text-secondary);
}

.auth-action {
  width: 100%;
  margin-top: 18px;
}

.auth-panel .auth-footnote {
  margin: 22px 0 0;
  color: var(--text-tertiary);
  font-size: 11px;
}

@media (max-width: 980px) {
  .appbar-inner {
    grid-template-columns: auto 1fr auto;
  }

  .identity {
    display: none;
  }

  .workspace {
    grid-template-columns: 150px minmax(0, 1fr);
    gap: 20px;
  }

  .document-header {
    grid-template-columns: 1fr;
    gap: 26px;
  }

  .start-note {
    align-self: auto;
  }
}

@media (max-width: 760px) {
  html {
    scroll-padding-top: 130px;
  }

  .appbar-inner {
    width: min(100% - 24px, 720px);
    padding: 9px 0;
    grid-template-columns: 1fr auto;
    gap: 8px 12px;
  }

  .brand-copy {
    display: none;
  }

  .save-summary {
    grid-row: 2;
    grid-column: 1 / -1;
  }

  .toolbar-actions {
    justify-self: end;
  }

  .toolbar-actions .button {
    min-height: 36px;
    padding-inline: 10px;
  }

  .workspace {
    display: block;
    width: min(100% - 24px, 720px);
    margin-top: 18px;
  }

  .section-nav {
    position: static;
    margin-bottom: 14px;
    padding: 0;
    overflow-x: auto;
  }

  .nav-label,
  .nav-meta {
    display: none;
  }

  .section-nav ol {
    display: flex;
    width: max-content;
    gap: 4px;
  }

  .section-nav li + li {
    margin-top: 0;
  }

  .section-nav a {
    grid-template-columns: auto auto;
  }

  .document-header,
  .opening,
  .request-section,
  .return-panel {
    padding-right: 22px;
    padding-left: 22px;
  }

  .document-header {
    padding-top: 38px;
  }

  h1 {
    font-size: 36px;
  }

  .opening-list,
  .field-grid,
  .known-user-list {
    grid-template-columns: 1fr;
  }

  .request-section {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .document-footer {
    display: grid;
    padding-right: 22px;
    padding-left: 22px;
  }
}

@media (max-width: 480px) {
  .appbar-inner {
    grid-template-columns: auto 1fr;
  }

  .toolbar-actions {
    display: grid;
    grid-template-columns: auto auto;
  }

  .toolbar-actions #print-button {
    display: none;
  }

  .toolbar-actions #save-button {
    grid-column: 1 / -1;
  }

  .upload-controls,
  .file-row {
    align-items: stretch;
    flex-direction: column;
  }

  .file-row .button {
    align-self: flex-start;
  }

  .auth-panel {
    padding: 32px 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

@page {
  size: A4 portrait;
  margin: 13mm;
}

@media print {
  :root {
    color-scheme: light;
    --canvas: #ffffff;
    --surface: #ffffff;
    --surface-subtle: #f5f6f8;
    --text: #111111;
    --text-secondary: #343434;
    --text-tertiary: #5f5f5f;
    --accent: #0067d9;
    --accent-soft: #eef6ff;
    --green: #248a3d;
    --warning: #7a4200;
    --warning-soft: #fff8ed;
    --border: #d1d1d6;
    --border-strong: #a8a8ad;
  }

  body {
    background: #ffffff;
    font-size: 9.5pt;
  }

  .appbar,
  .section-nav,
  .upload-controls,
  .field-help,
  .file-row .button,
  .toast,
  .decision-dialog {
    display: none !important;
  }

  .workspace {
    display: block;
    width: 100%;
    margin: 0;
  }

  .document {
    overflow: visible;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .document-header {
    padding: 9mm 7mm 8mm;
  }

  h1 {
    font-size: 28pt;
  }

  .opening,
  .request-section,
  .return-panel {
    padding: 7mm;
  }

  .request-section,
  .secret-notice,
  .return-panel,
  .file-row {
    break-inside: avoid;
  }

  input[type="text"],
  input[type="email"],
  select,
  textarea {
    min-height: 30px;
    padding: 5px 2px;
    border: 0;
    border-bottom: 1px solid var(--border-strong);
    border-radius: 0;
    background: transparent;
    color: #111111;
  }

  textarea {
    min-height: 48px;
  }

  .choice {
    min-height: 30px;
    padding: 5px 8px;
  }

  .document-footer {
    padding: 5mm 7mm 0;
  }
}
