:root {
  --ink: #22223b;
  --paper: #fefae0;
  --olive: #606c38;
  --amber: #dda15e;
  --line: rgba(34, 34, 59, 0.16);
  --muted: rgba(34, 34, 59, 0.68);
  --danger: #9b2c2c;
  --surface: #fffdf0;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(96, 108, 56, 0.09) 1px, transparent 1px),
    linear-gradient(0deg, rgba(34, 34, 59, 0.06) 1px, transparent 1px),
    var(--paper);
  background-size: 36px 36px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px clamp(16px, 3vw, 34px);
  border-bottom: 2px solid var(--ink);
  background: rgba(254, 250, 224, 0.94);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 230px;
}

.brand img {
  width: 46px;
  height: 46px;
}

.brand strong {
  display: block;
  font-size: 1.1rem;
}

.brand span,
.mono,
.panel-label,
.task-row p,
.finance-row p,
.ledger-row p,
.form-note {
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
}

.brand span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.tab,
.stage-chip,
.action-button,
.icon-action {
  border: 2px solid var(--ink);
  background: transparent;
  color: var(--ink);
  border-radius: 6px;
  min-height: 38px;
}

.tab {
  padding: 8px 12px;
}

.tab.is-active,
.action-button,
.stage-chip.is-active {
  background: var(--ink);
  color: var(--paper);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(210px, 250px) minmax(0, 1fr) minmax(220px, 300px);
  gap: 18px;
  padding: 18px clamp(16px, 3vw, 34px) 32px;
}

.filters,
.inspector,
.canvas {
  min-width: 0;
}

.filters,
.inspector {
  border-left: 2px solid var(--ink);
  padding: 14px 0 0 14px;
}

.panel-label,
.mono {
  color: var(--olive);
  font-size: 0.72rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

.filters label {
  display: grid;
  gap: 7px;
  margin: 14px 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.filters input,
.filters select,
.request-form input,
.request-form select {
  width: 100%;
  min-height: 42px;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 6px;
  padding: 8px 10px;
}

.stage-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 16px 0;
}

.stage-chip {
  padding: 7px 9px;
  min-height: 34px;
  font-size: 0.83rem;
}

.totals {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.totals div {
  border-top: 2px solid var(--line);
  padding-top: 10px;
}

.totals span,
.audit-row time,
.ledger-row span,
.finance-row span {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}

.totals strong {
  display: block;
  margin-top: 2px;
  font-size: clamp(1.05rem, 1vw + 0.82rem, 1.45rem);
}

.canvas {
  border: 2px solid var(--ink);
  background: rgba(255, 253, 240, 0.92);
  border-radius: 8px;
  min-height: calc(100vh - 122px);
  overflow: hidden;
}

.canvas-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 2px solid var(--ink);
  background: linear-gradient(90deg, rgba(221, 161, 94, 0.3), rgba(96, 108, 56, 0.12));
}

.canvas-head h1 {
  margin: 3px 0 0;
  font-size: clamp(1.45rem, 2vw + 1rem, 2.65rem);
  line-height: 1.05;
}

.canvas-head p {
  margin: 0;
}

.action-button {
  padding: 9px 14px;
  font-weight: 700;
}

.screen {
  display: none;
  padding: 16px;
}

.screen.is-active {
  display: block;
}

.stage-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(190px, 1fr));
  min-height: 560px;
  border: 2px solid var(--ink);
  border-radius: 6px;
  overflow-x: auto;
  overflow-y: hidden;
}

.stage-lane {
  min-width: 0;
  background: rgba(254, 250, 224, 0.72);
  border-right: 2px solid var(--ink);
}

.stage-lane:last-child {
  border-right: 0;
}

.stage-lane header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 46px;
  padding: 10px 12px;
  background: var(--ink);
  color: var(--paper);
}

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

.task-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 12px;
  border-bottom: 2px solid var(--line);
  background: var(--surface);
}

.task-row.status-risk {
  background: #fff1dc;
  border-left: 5px solid var(--danger);
}

.task-row.status-done {
  background: rgba(96, 108, 56, 0.12);
}

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

.task-main strong,
.ledger-row strong,
.finance-row strong {
  display: block;
  margin: 4px 0;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.task-main p,
.ledger-row p,
.finance-row p {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.task-side {
  display: grid;
  gap: 8px;
  justify-items: end;
  align-content: start;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(96, 108, 56, 0.16);
  color: var(--olive);
  font-size: 0.76rem;
  white-space: nowrap;
}

.icon-action {
  width: 34px;
  height: 34px;
  font-size: 1.1rem;
  background: var(--amber);
}

.empty-lane {
  padding: 14px;
  color: var(--muted);
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.78rem;
}

.request-form {
  max-width: 760px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

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

.span-2 {
  grid-column: span 2;
}

.form-note {
  color: var(--muted);
  margin: 12px 0 0;
}

.ledger-list,
.finance-grid {
  display: grid;
  gap: 0;
  border: 2px solid var(--ink);
  border-radius: 6px;
  overflow: hidden;
}

.ledger-row,
.finance-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(110px, auto);
  gap: 18px;
  padding: 13px 14px;
  border-bottom: 2px solid var(--line);
  background: var(--surface);
}

.ledger-row:last-child,
.finance-row:last-child {
  border-bottom: 0;
}

.ledger-row > div:last-child,
.finance-row > div:last-child {
  text-align: right;
}

.delta-up {
  color: var(--olive);
}

.delta-down {
  color: var(--danger);
}

.audit-trail {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.audit-row {
  border-top: 2px solid var(--line);
  padding-top: 10px;
}

.audit-row strong {
  display: block;
  margin: 3px 0;
}

.audit-row p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.audit-row span {
  display: inline-block;
  margin-top: 6px;
  color: var(--olive);
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.76rem;
}

.audit-row.is-error {
  color: var(--danger);
}

@media (max-width: 1360px) {
  .workspace {
    grid-template-columns: 230px minmax(0, 1fr);
  }

  .inspector {
    grid-column: 1 / -1;
    border-top: 2px solid var(--ink);
    border-left: 0;
    padding: 14px 0 0;
  }

  .audit-trail {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .canvas {
    order: 1;
  }

  .filters {
    order: 2;
    border-left: 0;
    border-bottom: 2px solid var(--ink);
    padding: 0 0 14px;
  }

  .inspector {
    order: 3;
  }

  .canvas {
    min-height: auto;
  }

  .canvas-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .stage-board {
    display: flex;
    min-height: 0;
    overflow-x: auto;
  }

  .stage-lane {
    flex: 0 0 min(86vw, 330px);
  }

  .audit-trail {
    grid-template-columns: 1fr;
  }

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

  .span-2 {
    grid-column: span 1;
  }

  .ledger-row > div:last-child,
  .finance-row > div:last-child {
    text-align: left;
  }
}
