:root {
  --ink: #22223b;
  --paper: #fefae0;
  --olive: #606c38;
  --amber: #dda15e;
  --line: rgba(34, 34, 59, 0.14);
  --muted: #74706a;
  --surface: #fffdf0;
  --white: #ffffff;
  --hot: #a9432d;
  --good: #496f31;
  --shadow: 0 18px 46px 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.05) 1px, transparent 1px),
    linear-gradient(0deg, rgba(34, 34, 59, 0.04) 1px, transparent 1px),
    var(--paper);
  background-size: 48px 48px;
}

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

button {
  cursor: pointer;
}

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

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

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand img {
  flex: 0 0 auto;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.25));
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 1.15rem;
}

.brand small {
  color: rgba(254, 250, 224, 0.66);
}

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

.tab {
  min-height: 42px;
  border: 1px solid rgba(254, 250, 224, 0.16);
  border-radius: 8px;
  padding: 0 14px;
  background: transparent;
  color: rgba(254, 250, 224, 0.72);
  text-align: left;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.tab:hover,
.tab.is-active {
  background: var(--paper);
  color: var(--ink);
  transform: translateX(2px);
}

.rail-block {
  margin-top: auto;
  border-top: 1px solid rgba(254, 250, 224, 0.18);
  padding-top: 18px;
}

.rail-flow {
  margin-top: 0;
}

.rail-block strong {
  display: block;
  margin-top: 7px;
  line-height: 1.35;
}

.mono {
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.72rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--olive);
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.74rem;
  line-height: 1.35;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.9rem, 3vw, 3.4rem);
  line-height: 0.98;
}

h2 {
  margin-bottom: 6px;
  font-size: 1rem;
}

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

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.search-box {
  display: grid;
  gap: 4px;
  min-width: min(270px, 100%);
  color: var(--muted);
}

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

textarea {
  resize: vertical;
}

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

.primary-button,
.secondary-button,
.icon-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 15px;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

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

.secondary-button {
  width: 100%;
  margin-top: 16px;
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.icon-button {
  width: 42px;
  padding: 0;
  background: var(--amber);
  color: var(--ink);
  font-size: 1.25rem;
}

.primary-button:hover,
.secondary-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.wide {
  width: 100%;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 253, 240, 0.82);
}

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

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

.metric strong {
  display: block;
  margin: 7px 0 4px;
  font-size: clamp(1.45rem, 2vw, 2rem);
}

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

.metric-accent {
  background: rgba(96, 108, 56, 0.12);
}

.metric-alert {
  background: rgba(221, 161, 94, 0.22);
}

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

.view.is-visible {
  display: block;
  animation: rise 220ms ease both;
}

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

.operations-layout,
.create-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: start;
}

.map-panel,
.ledger-panel,
.table-zone,
.create-form,
.audit-panel,
.document-grid,
.finance-ledger {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 240, 0.88);
}

.map-panel,
.table-zone,
.create-form,
.audit-panel,
.document-grid,
.finance-ledger {
  padding: 18px;
}

.ledger-panel {
  position: sticky;
  top: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.section-head p {
  margin-bottom: 0;
  max-width: 760px;
}

.status-filter {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.chip {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  background: transparent;
  color: var(--ink);
}

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

.route-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
  min-height: 210px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(96, 108, 56, 0.16), transparent 42%),
    rgba(255, 255, 255, 0.42);
}

.route-board::before {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  top: 50%;
  height: 4px;
  background: var(--ink);
  opacity: 0.16;
}

.route-node {
  position: relative;
  z-index: 1;
  align-self: center;
  display: grid;
  gap: 7px;
  min-height: 132px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  box-shadow: 0 10px 22px rgba(34, 34, 59, 0.08);
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.route-node:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}

.route-node strong {
  font-size: 1.08rem;
}

.route-node em {
  color: var(--muted);
  font-style: normal;
}

.node-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.75rem;
}

.route-amber .node-index { background: var(--amber); color: var(--ink); }
.route-green .node-index,
.route-olive .node-index { background: var(--olive); color: var(--paper); }

.table-zone {
  margin-top: 18px;
}

.request-table {
  display: grid;
  gap: 8px;
}

.sample-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 94px 72px 112px;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 68px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.58);
  color: var(--ink);
  text-align: left;
}

.sample-row.is-selected {
  border-color: var(--ink);
  background: var(--white);
}

.row-main {
  min-width: 0;
}

.row-main strong,
.row-main small {
  display: block;
  overflow-wrap: anywhere;
}

.row-main small,
.due {
  color: var(--muted);
}

.status-pill,
.delta,
.doc-type,
.audit-state {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 0.78rem;
  white-space: nowrap;
}

.status-sample { background: rgba(96, 108, 56, 0.13); }
.status-anomaly { background: rgba(221, 161, 94, 0.34); }
.status-work { background: rgba(34, 34, 59, 0.12); }
.status-result { background: rgba(73, 111, 49, 0.18); }

.delta {
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  justify-self: start;
}

.is-hot {
  color: var(--hot);
}

.is-good {
  color: var(--good);
}

.ledger-panel h2 {
  margin-top: 8px;
  font-size: 1.25rem;
}

.ledger-panel dl {
  display: grid;
  gap: 10px;
  margin: 16px 0 0;
}

.ledger-panel dl div {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

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

dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.create-form,
.audit-panel {
  margin-top: 0;
}

.create-form {
  display: grid;
  gap: 12px;
}

.create-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

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

.form-status {
  min-height: 22px;
  margin-bottom: 0;
}

.timeline {
  display: grid;
  gap: 10px;
  max-height: 520px;
  overflow: auto;
  padding-right: 4px;
}

.timeline-item {
  border-left: 3px solid var(--amber);
  padding: 6px 0 8px 12px;
}

.timeline-item strong,
.timeline-item small {
  display: block;
}

.timeline-item p {
  margin: 4px 0;
  color: var(--ink);
}

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

.document-grid,
.finance-ledger {
  display: grid;
  gap: 10px;
}

.doc-row,
.ledger-row,
.ledger-total {
  display: grid;
  align-items: center;
  gap: 10px;
  min-height: 68px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.62);
}

.doc-row {
  grid-template-columns: 98px minmax(180px, 1fr) minmax(120px, 0.7fr) 120px 112px;
}

.doc-row strong,
.doc-row small,
.ledger-row strong,
.ledger-row small {
  overflow-wrap: anywhere;
}

.doc-row em {
  font-style: normal;
  color: var(--olive);
}

.ledger-total {
  grid-template-columns: 1fr auto auto;
  background: var(--ink);
  color: var(--paper);
}

.ledger-total small {
  color: rgba(254, 250, 224, 0.72);
}

.ledger-total strong {
  font-size: 1.9rem;
}

.ledger-row {
  grid-template-columns: 86px minmax(180px, 1fr) minmax(120px, 0.7fr) 72px 90px 112px;
}

.ledger-row em {
  font-style: normal;
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
}

.ledger-row b {
  font-weight: 700;
  text-align: right;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
}

dialog {
  width: min(520px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(34, 34, 59, 0.48);
}

.dialog-form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.dialog-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.dialog-actions button:not(.primary-button) {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: transparent;
}

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

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

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

  .rail-block {
    display: none;
  }

  .operations-layout,
  .create-grid {
    grid-template-columns: 1fr;
  }

  .ledger-panel {
    position: static;
  }
}

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

  .topbar {
    display: grid;
  }

  .toolbar,
  .search-box {
    width: 100%;
  }

  .metric-strip {
    grid-template-columns: 1fr 1fr;
  }

  .metric:nth-child(2) {
    border-right: 0;
  }

  .metric:nth-child(1),
  .metric:nth-child(2) {
    border-bottom: 1px solid var(--line);
  }

  .route-board {
    grid-template-columns: 1fr;
  }

  .route-board::before {
    display: none;
  }

  .sample-row,
  .doc-row,
  .ledger-row,
  .ledger-total {
    grid-template-columns: 1fr;
  }

  .due,
  .ledger-row b {
    text-align: left;
  }

  .tabs {
    grid-template-columns: 1fr 1fr;
  }

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

  .section-head {
    display: grid;
  }

  .eyebrow {
    font-size: 0.68rem;
  }
}
