:root {
  --ink: #22223b;
  --paper: #fefae0;
  --olive: #606c38;
  --amber: #dda15e;
  --line: rgba(34, 34, 59, 0.16);
  --muted: rgba(34, 34, 59, 0.66);
  --white: #fffdf2;
  --danger: #a23e48;
  --blueprint: #315a72;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(90deg, rgba(34, 34, 59, 0.05) 1px, transparent 1px),
    linear-gradient(180deg, rgba(34, 34, 59, 0.04) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
}

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

button {
  cursor: pointer;
}

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

.rail {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 28px;
  height: 100vh;
  padding: 26px 20px;
  color: var(--paper);
  background: var(--ink);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
  font-weight: 800;
  letter-spacing: 0;
}

.brand img {
  flex: 0 0 auto;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab {
  width: 100%;
  padding: 13px 14px;
  color: rgba(254, 250, 224, 0.72);
  text-align: left;
  border: 1px solid rgba(254, 250, 224, 0.12);
  border-radius: 8px;
  background: transparent;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.nav-tab:hover,
.nav-tab.is-active {
  color: var(--paper);
  background: rgba(254, 250, 224, 0.09);
  transform: translateX(2px);
}

.rail-note {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding-top: 20px;
  border-top: 1px solid rgba(254, 250, 224, 0.18);
}

.rail-note span,
.mono,
label span,
.metric span,
.task-top,
dt,
.document-row span,
.finance-bars span {
  font-family: "Roboto Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  line-height: 1.3;
  text-transform: uppercase;
  letter-spacing: 0;
}

.rail-note strong {
  font-size: 14px;
  line-height: 1.45;
  color: rgba(254, 250, 224, 0.84);
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
  animation: enter 420ms ease both;
}

.topbar h1,
.map-header h2,
.panel-heading h2,
.request-form h2,
.preview-ledger h2,
.documents-toolbar h2,
.finance-board h2 {
  margin: 0;
  line-height: 1.08;
  letter-spacing: 0;
}

.topbar h1 {
  max-width: 740px;
  font-size: clamp(30px, 4.2vw, 58px);
}

.mono {
  margin: 0 0 8px;
  color: var(--olive);
  font-weight: 800;
}

.filters {
  display: grid;
  grid-template-columns: minmax(180px, 250px) 140px;
  gap: 10px;
  min-width: 340px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 242, 0.72);
  outline: none;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--olive);
  box-shadow: 0 0 0 3px rgba(96, 108, 56, 0.12);
}

.metrics-ledger {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 22px 0;
  border: 1px solid var(--line);
  background: rgba(255, 253, 242, 0.58);
  animation: enter 520ms ease 90ms both;
}

.metric {
  min-width: 0;
  padding: 18px;
  border-right: 1px solid var(--line);
}

.metric:last-child {
  border-right: 0;
}

.metric strong {
  display: block;
  margin: 8px 0 2px;
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1;
}

.metric small {
  color: var(--muted);
}

.metric.risk {
  background: rgba(162, 62, 72, 0.08);
}

.view {
  display: none;
}

.view.is-visible {
  display: block;
  animation: enter 260ms ease both;
}

.canvas-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 18px;
  align-items: start;
}

.map-surface,
.audit-panel,
.request-form,
.preview-ledger,
.documents-list,
.finance-board {
  border: 1px solid var(--line);
  background: rgba(255, 253, 242, 0.76);
}

.map-surface {
  min-height: 560px;
  padding: 18px;
}

.map-header,
.documents-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 18px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  color: var(--muted);
  font-size: 13px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--ink);
}

.dot.order {
  background: var(--blueprint);
}

.dot.loading {
  background: var(--amber);
}

.dot.route {
  background: var(--olive);
}

.dot.accepted {
  background: #2f7d62;
}

.route-lanes {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 6px;
}

.lane {
  min-width: 180px;
  background: rgba(34, 34, 59, 0.035);
  border: 1px solid rgba(34, 34, 59, 0.09);
}

.lane header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.lane header span {
  font-weight: 800;
}

.lane header b {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  color: var(--paper);
  border-radius: 999px;
  background: var(--ink);
}

.lane-items {
  display: grid;
  gap: 10px;
  padding: 10px;
}

.task-card {
  position: relative;
  display: grid;
  gap: 10px;
  padding: 13px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--olive);
  border-radius: 8px;
  background: var(--white);
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.task-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px rgba(34, 34, 59, 0.12);
}

.risk-high {
  border-left-color: var(--danger);
}

.risk-medium {
  border-left-color: var(--amber);
}

.task-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
}

.task-card h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.22;
}

.task-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.42;
}

dl {
  display: grid;
  gap: 7px;
  margin: 0;
}

dl div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding-top: 7px;
  border-top: 1px dashed rgba(34, 34, 59, 0.14);
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  text-align: right;
  font-weight: 700;
}

.task-card button,
.request-form button,
.documents-toolbar button {
  min-height: 38px;
  padding: 9px 12px;
  color: var(--paper);
  border: 0;
  border-radius: 8px;
  background: var(--ink);
}

.done-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  color: var(--olive);
  border: 1px solid rgba(96, 108, 56, 0.26);
  border-radius: 8px;
  font-weight: 800;
}

.empty-lane {
  margin: 0;
  padding: 16px 10px;
  color: var(--muted);
  font-size: 13px;
}

.audit-panel {
  padding: 18px;
}

.audit-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.audit-list li {
  display: grid;
  gap: 5px;
  padding-left: 14px;
  border-left: 3px solid var(--amber);
}

.audit-list span {
  font-family: "Roboto Mono", Consolas, monospace;
  font-size: 11px;
  color: var(--muted);
}

.audit-list strong {
  line-height: 1.25;
}

.audit-list em {
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
}

.split-pane {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr);
  gap: 18px;
}

.request-form,
.preview-ledger,
.finance-board {
  padding: 22px;
}

.request-form {
  display: grid;
  gap: 16px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 0.7fr;
  gap: 12px;
}

.preview-ledger {
  display: grid;
  align-content: start;
  gap: 14px;
  background: var(--ink);
  color: var(--paper);
}

.preview-ledger .mono {
  color: var(--amber);
}

.preview-ledger p {
  color: rgba(254, 250, 224, 0.76);
}

.documents-toolbar {
  padding: 18px 0 0;
}

.documents-list {
  display: grid;
  overflow: hidden;
}

.document-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

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

.document-row div {
  display: grid;
  gap: 4px;
}

.document-row strong {
  font-size: 17px;
}

.document-row small {
  color: var(--muted);
}

.document-row b {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
}

.status-needs_review b {
  color: var(--danger);
  border-color: rgba(162, 62, 72, 0.26);
}

.finance-board {
  display: grid;
  gap: 22px;
}

.finance-bars {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
}

.finance-bars div {
  padding: 16px;
  border-right: 1px solid var(--line);
}

.finance-bars div:last-child {
  border-right: 0;
}

.finance-bars strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.finance-table {
  width: 100%;
  border-collapse: collapse;
  background: rgba(255, 253, 242, 0.74);
}

.finance-table th,
.finance-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.finance-table th {
  font-family: "Roboto Mono", Consolas, monospace;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(360px, calc(100vw - 44px));
  padding: 12px 14px;
  color: var(--paper);
  border-radius: 8px;
  background: var(--ink);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@keyframes enter {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

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

  .nav-tabs {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .rail-note {
    display: none;
  }

  .canvas-grid,
  .split-pane {
    grid-template-columns: 1fr;
  }

  .audit-panel {
    order: -1;
  }
}

@media (max-width: 760px) {
  .workspace {
    padding: 16px;
  }

  .topbar,
  .map-header,
  .documents-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .filters,
  .metrics-ledger,
  .form-row,
  .finance-bars {
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .metric,
  .finance-bars div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .metric:last-child,
  .finance-bars div:last-child {
    border-bottom: 0;
  }

  .nav-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .route-lanes {
    grid-template-columns: repeat(4, minmax(220px, 1fr));
  }

  .document-row {
    align-items: start;
    flex-direction: column;
  }

  .finance-board {
    overflow-x: auto;
  }

  .finance-table {
    min-width: 680px;
  }
}
