:root {
  --navy: #0c1b33;
  --navy-2: #163154;
  --brass: #8d6732;
  --paper: #eef1f4;
  --ink: #172033;
  --muted: #5c6b7c;
  --line: #e1e6ee;
  --white: #ffffff;
  --focus: #1f4f86;
  --danger: #8d1d1d;
  --shadow: 0 1px 2px rgba(16, 32, 51, 0.05), 0 10px 28px rgba(16, 32, 51, 0.05);
  --sans: "Segoe UI", system-ui, sans-serif;
  --serif: Georgia, "Iowan Old Style", Palatino, "Palatino Linotype", serif;
  color-scheme: light;
}

*,
*::before,
*::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
}

a { color: var(--focus); }
a:hover { text-decoration: none; }

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--white);
  color: var(--navy);
  padding: 8px 12px;
  z-index: 40;
}

.skip:focus { top: 12px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 252px 1fr;
}

.sidebar {
  background: var(--navy);
  color: #d7e0ea;
  padding: 28px 16px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand { padding: 0 10px; }

.brand-kicker {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #9aabbe;
}

.brand h1,
.brand-name {
  margin: 0;
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 600;
  color: white;
  letter-spacing: 0.04em;
}

.brand p { margin: 6px 0 0; color: #c5d0de; font-size: 14px; }

.sidebar nav { display: grid; gap: 4px; }

.sidebar button {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: #d7e0ea;
  border-radius: 8px;
  min-height: 44px;
  padding: 8px 12px;
  cursor: pointer;
}

.sidebar button:hover { background: rgba(255, 255, 255, 0.06); }

.sidebar button[aria-current="page"] {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  box-shadow: inset 3px 0 0 #c6a15b;
}

.sidebar :focus-visible { outline-color: #f2d48a; }

.workspace {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 22px 32px 0;
}

.nav-toggle {
  display: none;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--white);
  cursor: pointer;
}

#view-heading {
  margin: 0;
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.content { padding: 18px 32px 72px; max-width: 1180px; }

.lede { max-width: 68ch; color: var(--muted); margin-top: 0; }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin: 8px 0 22px;
  padding: 0;
  list-style: none;
}

.metric {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 16px 16px 14px;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.metric-value {
  display: block;
  margin-top: 8px;
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 600;
}

.actions, .record-actions, .dialog-actions, .toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.actions { margin-bottom: 22px; }

.button, button.button, a.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid var(--navy);
  background: var(--navy);
  color: white;
  text-decoration: none;
  cursor: pointer;
}

.button.secondary, button.button.secondary {
  background: white;
  color: var(--navy);
}

.button.ghost, button.button.ghost {
  background: transparent;
  color: var(--navy);
  border-color: transparent;
  padding-inline: 10px;
}

.button.danger, button.button.danger { color: var(--danger); }

.panel {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

.panel h2, .record h3, .preview-doc h3 {
  font-family: var(--serif);
  font-weight: 600;
  margin: 0;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
}

.panel-head p, .hint, .empty { color: var(--muted); }

.stack { display: grid; gap: 12px; }

.record {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  background: #fcfdfe;
}

.record + .record { margin-top: 12px; }

.record-top, .panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.record-title { margin: 8px 0; font-weight: 600; }

.record-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px 16px;
  margin: 0;
}

.record-meta div { min-width: 0; }
.record-meta dt { color: var(--muted); font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
.record-meta dd { margin: 2px 0 0; }

.record-actions { margin-top: 12px; }

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #eef2f6;
  color: var(--ink);
  font-size: 13px;
  white-space: nowrap;
}

.pill-pending-acceptance,
.pill-awaiting-acceptance,
.pill-partially-paid,
.pill-on-hold { background: #f8f1e3; color: #6a4810; }

.pill-acceptance-email-required,
.pill-issued,
.pill-not-started,
.pill-sample-record { background: #e7f0f8; color: #1d4e89; }

.pill-accepted,
.pill-paid,
.pill-active { background: #e5f4ec; color: #1f6b45; }

.pill-draft,
.pill-closed,
.pill-void,
.pill-cancelled,
.pill-browser-local,
.pill-completed { background: #eef1f4; color: #4d5b6a; }

.inline-field select, .toolbar input, .field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid #cfd6e0;
  border-radius: 8px;
  background: white;
  min-height: 44px;
  padding: 8px 10px;
}

.inline-field select { width: auto; min-width: 180px; }

.toolbar input { max-width: 320px; }
.inline-field { display: grid; gap: 6px; }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 12px 0; }

.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field textarea { min-height: 110px; resize: vertical; }
.form-error { color: var(--danger); margin: 0 0 12px; }

.prose { white-space: pre-wrap; }

.activity { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.activity li { display: grid; gap: 2px; }
.activity time { color: var(--muted); font-size: 13px; }

.preview-doc {
  border: 1px solid var(--line);
  border-top: 6px solid var(--navy);
  border-radius: 12px;
  padding: 18px;
  background: white;
}

.kicker {
  margin: 0 0 6px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--brass);
}

.template-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 16px;
  align-items: start;
}

.footer-note {
  color: var(--muted);
  font-size: 14px;
  max-width: 78ch;
}

dialog {
  width: min(560px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
}

dialog::backdrop { background: rgba(8, 16, 28, 0.48); }

dialog h2 { font-family: var(--serif); margin: 0 0 8px; }

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(8, 16, 28, 0.45);
  border: 0;
  z-index: 15;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 24px));
  background: var(--navy);
  color: white;
  border-radius: 10px;
  padding: 12px 14px;
  z-index: 30;
  box-shadow: var(--shadow);
}

.is-flash { animation: flash 1.4s ease; }

@keyframes flash {
  from { background: #f8f1e3; }
  to { background: #fcfdfe; }
}

@media (max-width: 980px) {
  .metrics, .record-meta, .template-layout { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .nav-toggle { display: inline-flex; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(280px, 86vw);
    z-index: 20;
    transform: translateX(-105%);
    transition: transform 160ms ease;
  }
  .sidebar.is-open { transform: none; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  #view-heading { font-size: 28px; }
}

@media (max-width: 640px) {
  .metrics, .record-meta, .template-layout { grid-template-columns: 1fr; }
  .record-top, .panel-head { align-items: stretch; flex-direction: column; }
  .inline-field select, .toolbar input { width: 100%; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .sidebar, .is-flash { transition: none; animation: none; }
}
