:root {
  --ink: #22223b;
  --paper: #fefae0;
  --olive: #606c38;
  --amber: #dda15e;
  --rust: #bc6c25;
  --line: rgba(34, 34, 59, 0.14);
  --muted: rgba(34, 34, 59, 0.64);
  --panel: rgba(255, 252, 232, 0.86);
  --white: #fffdf4;
  --shadow: 0 22px 60px rgba(34, 34, 59, 0.12);
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(90deg, rgba(34,34,59,0.045) 1px, transparent 1px) 0 0 / 42px 42px,
    linear-gradient(rgba(34,34,59,0.035) 1px, transparent 1px) 0 0 / 42px 42px,
    radial-gradient(circle at 78% 8%, rgba(221, 161, 94, 0.18), transparent 28%),
    var(--paper);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

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

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: 0;
}

.nav {
  display: grid;
  gap: 6px;
  margin-top: 34px;
}

.nav__item {
  width: 100%;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: rgba(254, 250, 224, 0.72);
  text-align: left;
  padding: 8px 10px;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

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

.rail__footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  color: rgba(254, 250, 224, 0.58);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: #8ec07c;
  box-shadow: 0 0 0 5px rgba(142, 192, 124, 0.14);
}

.workspace {
  min-width: 0;
  padding: 22px clamp(16px, 2.4vw, 34px) 28px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow,
.metric span,
.risk,
.status,
.file-row span,
.finance-grid span,
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 46px);
  line-height: 0.95;
}

h2 {
  font-size: clamp(18px, 2vw, 25px);
  line-height: 1.05;
}

p {
  color: var(--muted);
  line-height: 1.5;
}

.topbar__actions {
  display: flex;
  align-items: end;
  gap: 10px;
}

.search {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

input,
select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 244, 0.78);
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}

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

.primary,
.ghost,
.chip {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 8px 12px;
}

.primary {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}

.ghost,
.chip {
  background: rgba(255, 253, 244, 0.62);
  color: var(--ink);
}

.chip.is-active {
  background: var(--olive);
  border-color: var(--olive);
  color: #fffdf4;
}

.ledger {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
  box-shadow: var(--shadow);
}

.metric {
  min-width: 0;
  padding: 16px;
  background: rgba(255, 253, 244, 0.86);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: clamp(23px, 3vw, 36px);
  line-height: 1;
}

.metric em {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.screen {
  display: none;
  margin-top: 18px;
}

.screen.is-visible {
  display: block;
  animation: enter 220ms ease both;
}

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

.canvas-grid {
  display: grid;
  grid-template-columns: minmax(340px, 1.02fr) minmax(390px, 0.98fr);
  gap: 18px;
  align-items: stretch;
}

.map-panel,
.registry-panel,
.request-form,
.work-queue,
.documents,
.finance {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

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

.map-panel__head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.map-panel__head p {
  max-width: 520px;
  margin: 8px 0 0;
}

.route-map {
  position: relative;
  height: min(58vh, 492px);
  min-height: 360px;
  margin-top: 20px;
  overflow: hidden;
  border: 1px solid rgba(34, 34, 59, 0.16);
  border-radius: 8px;
  background:
    linear-gradient(120deg, rgba(96, 108, 56, 0.12), transparent 42%),
    linear-gradient(0deg, rgba(34,34,59,0.05) 1px, transparent 1px) 0 0 / 100% 58px,
    linear-gradient(90deg, rgba(34,34,59,0.06) 1px, transparent 1px) 0 0 / 58px 100%,
    #fffdf4;
}

.route-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.route-lines path {
  fill: none;
  stroke: var(--ink);
  stroke-width: 0.7;
  stroke-dasharray: 3 2;
  opacity: 0.42;
  animation: routePulse 7s linear infinite;
}

@keyframes routePulse {
  to { stroke-dashoffset: -30; }
}

.checkpoint {
  position: absolute;
  z-index: 2;
  display: grid;
  gap: 2px;
  min-width: 72px;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  transform: translate(-50%, -50%);
}

.checkpoint span {
  width: 18px;
  height: 18px;
  border: 4px solid #fffdf4;
  border-radius: 99px;
  background: var(--pin);
  box-shadow: 0 6px 18px rgba(34,34,59,0.22);
}

.checkpoint strong,
.checkpoint em {
  display: block;
  width: max-content;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: 6px;
  background: rgba(255, 253, 244, 0.84);
  padding: 2px 5px;
  font-size: 11px;
  font-style: normal;
}

.checkpoint:hover {
  z-index: 4;
}

.checkpoint:hover span {
  transform: scale(1.18);
}

.registry-panel {
  min-height: 560px;
  padding: 14px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.object-list,
#taskList,
.document-list,
.audit__list {
  display: grid;
  gap: 8px;
}

.object-row {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr) 76px 70px 70px;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 68px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: rgba(255, 253, 244, 0.7);
  padding: 9px 10px;
  color: var(--ink);
  text-align: left;
  transition: border 160ms ease, background 160ms ease, transform 160ms ease;
}

.object-row:hover,
.object-row.is-selected {
  border-color: rgba(96,108,56,0.42);
  background: #fffdf4;
  transform: translateY(-1px);
}

.object-row strong,
.task-row strong,
.file-row strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.object-row em,
.task-row em,
.file-row em {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.risk,
.status {
  display: inline-flex;
  width: fit-content;
  min-width: 62px;
  justify-content: center;
  border-radius: 99px;
  padding: 4px 7px;
  font-size: 11px;
  line-height: 1;
}

.risk-critical { background: #7f1d1d; color: #fff7ed; }
.risk-high { background: var(--rust); color: #fff7ed; }
.risk-medium { background: var(--amber); color: var(--ink); }
.risk-low { background: rgba(96,108,56,0.16); color: var(--olive); }
.status-new { background: rgba(221,161,94,0.3); }
.status-assigned { background: rgba(96,108,56,0.16); color: var(--olive); }
.status-route { background: rgba(34,34,59,0.12); }
.status-closed { background: rgba(96,108,56,0.24); color: var(--olive); }

.delta {
  color: var(--rust);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 800;
}

.split {
  display: grid;
  grid-template-columns: minmax(320px, 0.92fr) minmax(360px, 1.08fr);
  gap: 18px;
}

.request-form,
.work-queue,
.documents,
.finance {
  padding: 18px;
}

.request-form {
  display: grid;
  align-content: start;
  gap: 14px;
}

.request-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.request-form input,
.request-form select {
  width: 100%;
}

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: end;
}

.task-row,
.file-row,
.finance-grid article,
.audit-row {
  border: 1px solid rgba(34,34,59,0.1);
  border-radius: 8px;
  background: rgba(255, 253, 244, 0.72);
}

.task-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  min-height: 74px;
  padding: 10px;
}

.task-row > div:last-child {
  display: flex;
  align-items: center;
  gap: 8px;
}

.savings {
  color: var(--olive);
  font-weight: 800;
  white-space: nowrap;
}

.documents,
.finance {
  display: grid;
  gap: 18px;
}

.documents p,
.finance p {
  max-width: 640px;
  margin: 8px 0 0;
}

.file-row {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr) minmax(160px, 0.7fr) 92px;
  gap: 12px;
  align-items: center;
  min-height: 58px;
  padding: 10px;
}

.file-row b {
  color: var(--olive);
  font-size: 12px;
}

.finance-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.finance-grid article {
  min-height: 150px;
  padding: 18px;
}

.finance-grid strong {
  display: block;
  margin-top: 16px;
  font-size: clamp(25px, 3vw, 39px);
}

.finance-grid em {
  display: block;
  margin-top: 9px;
  color: var(--muted);
  font-style: normal;
}

.audit {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: rgba(255, 253, 244, 0.64);
  padding: 22px 14px;
}

.audit__head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 14px;
}

.audit__head h2 {
  font-size: 18px;
}

.audit__head span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.audit-row {
  display: grid;
  gap: 4px;
  padding: 10px;
  border-left: 4px solid var(--amber);
}

.audit-row span {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}

.audit-row strong {
  font-size: 13px;
  line-height: 1.25;
}

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

.severity-critical { border-left-color: #7f1d1d; }
.severity-high { border-left-color: var(--rust); }
.severity-medium { border-left-color: var(--amber); }
.severity-low { border-left-color: var(--olive); }

.empty {
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

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

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

@media (max-width: 1180px) {
  .shell {
    grid-template-columns: 128px minmax(0, 1fr);
  }

  .audit {
    position: static;
    grid-column: 2;
    height: auto;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

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

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

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

  .brand br,
  .rail__footer {
    display: none;
  }

  .nav {
    display: flex;
    gap: 6px;
    margin-top: 12px;
    overflow-x: auto;
  }

  .nav__item {
    flex: 0 0 auto;
    width: auto;
    white-space: nowrap;
  }

  .topbar {
    display: grid;
  }

  .topbar__actions,
  .pair,
  .map-panel__head {
    display: grid;
    grid-template-columns: 1fr;
  }

  .ledger,
  .finance-grid {
    grid-template-columns: 1fr 1fr;
  }

  .object-row {
    grid-template-columns: 72px minmax(0, 1fr) 58px;
  }

  .object-row .mono,
  .object-row span:last-child {
    display: none;
  }

  .file-row {
    grid-template-columns: 78px minmax(0, 1fr);
  }

  .file-row em,
  .file-row b {
    grid-column: 2;
  }
}

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

  .ledger,
  .finance-grid {
    grid-template-columns: 1fr;
  }

  .map-panel,
  .registry-panel,
  .request-form,
  .work-queue,
  .documents,
  .finance {
    padding: 12px;
  }

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

  .task-row > div:last-child {
    justify-content: space-between;
  }
}
