:root {
  --ink: #22223b;
  --paper: #fefae0;
  --olive: #606c38;
  --copper: #dda15e;
  --line: rgba(34, 34, 59, 0.16);
  --muted: rgba(34, 34, 59, 0.64);
  --white: #fffdf1;
  --risk: #b8422f;
  --ok: #3d7552;
  --shadow: 0 24px 80px rgba(34, 34, 59, 0.13);
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(34, 34, 59, 0.05) 1px, transparent 1px),
    linear-gradient(0deg, rgba(34, 34, 59, 0.05) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
  font-family: Inter, Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.rail {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
  height: 100vh;
  padding: 22px;
  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 {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
}

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

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

.nav-tab:hover,
.nav-tab.is-active {
  color: var(--paper);
  background: rgba(221, 161, 94, 0.16);
  transform: translateX(2px);
}

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

.rail-note strong {
  display: block;
  margin-top: 8px;
  line-height: 1.45;
}

.mono,
.eyebrow,
th,
.metric-strip span,
.search span {
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
}

.mono,
.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.rail .mono {
  color: rgba(254, 250, 224, 0.56);
}

.workspace {
  display: grid;
  align-content: start;
  gap: 18px;
  padding: 24px;
}

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

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

h1 {
  margin-top: 6px;
  font-size: 34px;
}

h2 {
  font-size: 22px;
}

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

.search {
  display: grid;
  gap: 6px;
}

.search input,
select,
.form-surface input,
.form-surface select {
  min-height: 42px;
  padding: 10px 12px;
  color: var(--ink);
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
}

.search input:focus,
select:focus,
.form-surface input:focus,
.form-surface select:focus {
  border-color: var(--copper);
  box-shadow: 0 0 0 3px rgba(221, 161, 94, 0.24);
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border: 1px solid var(--ink);
  background: var(--white);
  box-shadow: var(--shadow);
}

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

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

.metric-strip span,
.metric-strip strong {
  display: block;
}

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

.metric-strip strong {
  margin-top: 8px;
  font-size: 24px;
  line-height: 1;
  word-break: break-word;
}

.screen {
  display: none;
}

.screen.is-visible {
  display: grid;
  gap: 18px;
  animation: rise 220ms ease both;
}

.canvas-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 0.7fr);
  gap: 18px;
}

.forecast-canvas,
.audit-panel,
.ledger,
.form-surface,
.document-desk,
.finance-desk {
  background: rgba(255, 253, 241, 0.88);
  border: 1px solid var(--line);
  box-shadow: 0 18px 48px rgba(34, 34, 59, 0.09);
}

.forecast-canvas {
  min-height: 430px;
  padding: 18px;
}

.canvas-head,
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status-chip,
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 6px 10px;
  color: var(--ink);
  background: rgba(221, 161, 94, 0.22);
  border: 1px solid rgba(221, 161, 94, 0.7);
  border-radius: 999px;
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
}

.status-chip.stable,
.status-pill.done {
  color: #173822;
  background: rgba(96, 108, 56, 0.18);
  border-color: rgba(96, 108, 56, 0.52);
}

.status-chip.risk,
.status-pill.open {
  color: #5b1b12;
  background: rgba(184, 66, 47, 0.14);
  border-color: rgba(184, 66, 47, 0.44);
}

.status-pill.planned {
  color: #62430f;
}

.zone-map {
  position: relative;
  min-height: 340px;
  margin-top: 18px;
  overflow: hidden;
  border: 1px solid rgba(34, 34, 59, 0.2);
  background:
    linear-gradient(90deg, rgba(34, 34, 59, 0.08) 1px, transparent 1px),
    linear-gradient(0deg, rgba(34, 34, 59, 0.08) 1px, transparent 1px),
    linear-gradient(135deg, rgba(96, 108, 56, 0.18), rgba(221, 161, 94, 0.18));
  background-size: 36px 36px, 36px 36px, auto;
}

.zone-map:before {
  position: absolute;
  inset: 18% 10% auto;
  height: 46%;
  border: 2px dashed rgba(34, 34, 59, 0.26);
  border-radius: 50%;
  content: "";
  transform: rotate(-8deg);
}

.zone-node {
  position: absolute;
  left: var(--x);
  top: var(--y);
  display: grid;
  grid-template-columns: 20px minmax(120px, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: min(290px, 42%);
  min-height: 74px;
  padding: 12px;
  background: var(--white);
  border: 1px solid rgba(34, 34, 59, 0.24);
  border-left: 8px solid var(--olive);
  box-shadow: 0 18px 38px rgba(34, 34, 59, 0.12);
  transform: translateY(0);
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.zone-node:hover {
  transform: translateY(-3px);
  box-shadow: 0 26px 48px rgba(34, 34, 59, 0.18);
}

.zone-node.risk {
  border-left-color: var(--risk);
}

.zone-node.watch {
  border-left-color: var(--copper);
}

.node-pulse {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--olive);
  box-shadow: 0 0 0 0 rgba(96, 108, 56, 0.42);
  animation: pulse 1.8s ease-out infinite;
}

.risk .node-pulse {
  background: var(--risk);
}

.watch .node-pulse {
  background: var(--copper);
}

.zone-node strong,
.zone-node small,
.file-row strong,
.file-row span,
.finance-row span {
  display: block;
}

.zone-node small,
.file-row span,
.finance-row span,
td small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.zone-node b {
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
}

.audit-panel,
.ledger,
.document-desk,
.finance-desk {
  padding: 18px;
}

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

.audit-list li {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.audit-list time {
  color: var(--olive);
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
}

.table-wrap {
  width: 100%;
  margin-top: 14px;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

td strong {
  display: block;
  max-width: 320px;
}

.icon-button {
  width: 38px;
  height: 38px;
  color: var(--paper);
  background: var(--ink);
  border: 0;
  border-radius: 6px;
  font-size: 22px;
  line-height: 1;
}

.form-surface {
  display: grid;
  gap: 16px;
  max-width: 820px;
  padding: 22px;
}

.form-surface label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

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

.primary-action {
  justify-self: start;
  min-height: 44px;
  padding: 0 18px;
  color: var(--paper);
  background: var(--olive);
  border: 1px solid rgba(34, 34, 59, 0.18);
  border-radius: 6px;
  font-weight: 800;
  transition: transform 160ms ease, background 160ms ease;
}

.primary-action:hover {
  background: var(--ink);
  transform: translateY(-2px);
}

.form-result {
  min-height: 22px;
  margin: 0;
  color: var(--olive);
}

.file-list,
.finance-rows {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.file-row,
.finance-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.finance-row {
  grid-template-columns: minmax(130px, 0.55fr) minmax(120px, 1fr) minmax(120px, 0.45fr);
}

.file-row b,
.finance-row b {
  color: var(--ink);
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
}

.bar {
  height: 12px;
  overflow: hidden;
  background: rgba(34, 34, 59, 0.12);
  border-radius: 999px;
}

.bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--olive), var(--copper));
  border-radius: inherit;
  animation: grow 520ms ease both;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(96, 108, 56, 0.38); }
  70% { box-shadow: 0 0 0 12px rgba(96, 108, 56, 0); }
  100% { box-shadow: 0 0 0 0 rgba(96, 108, 56, 0); }
}

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

@keyframes grow {
  from { width: 0; }
}

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

  .rail {
    position: relative;
    height: auto;
  }

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

  .nav-tab {
    text-align: center;
  }

  .topbar,
  .top-actions,
  .canvas-layout {
    align-items: stretch;
    flex-direction: column;
    grid-template-columns: 1fr;
  }

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

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

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

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

  h1 {
    font-size: 28px;
  }

  h2 {
    font-size: 19px;
  }

  .nav-tabs,
  .metric-strip,
  .finance-row,
  .file-row {
    grid-template-columns: 1fr;
  }

  .metric-strip div {
    border-right: 0;
  }

  .zone-map {
    min-height: 560px;
  }

  .zone-node {
    left: 12px;
    right: 12px;
    top: auto;
    width: auto;
    transform: none;
  }

  .zone-node:nth-child(1) { top: 16px; }
  .zone-node:nth-child(2) { top: 130px; }
  .zone-node:nth-child(3) { top: 244px; }
  .zone-node:nth-child(4) { top: 358px; }
  .zone-node:nth-child(5) { top: 472px; }
  .zone-node:nth-child(6) { top: 486px; }

  .table-wrap {
    overflow-x: visible;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  thead {
    display: none;
  }

  tr {
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
  }

  td {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
    gap: 10px;
    padding: 7px 0;
    border: 0;
    overflow-wrap: anywhere;
  }

  td:before {
    color: var(--muted);
    font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
    font-size: 11px;
    text-transform: uppercase;
    content: attr(data-label);
  }
}
