:root {
  --page: #f2f4f1;
  --surface: #ffffff;
  --surface-muted: #eef2ee;
  --ink: #111511;
  --muted: #5c675f;
  --line: #d5ddd4;
  --line-strong: #aeb9ad;
  --merchant: #1d6f4a;
  --merchant-soft: #e2f4e9;
  --blue: #285f9f;
  --blue-soft: #e7f0fb;
  --amber: #8a6100;
  --amber-soft: #fff3cf;
  --red: #b3271d;
  --red-soft: #fff0ec;
  --charcoal: #2a302c;
  --shadow: 0 14px 36px rgba(17, 21, 17, 0.08);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    linear-gradient(180deg, rgba(29, 111, 74, 0.11), rgba(29, 111, 74, 0) 280px),
    linear-gradient(90deg, rgba(17, 21, 17, 0.035) 1px, transparent 1px),
    var(--page);
  background-size: auto, 32px 32px, auto;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: "Aptos", "IBM Plex Sans", "Segoe UI", ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-size: 15px;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

a {
  color: var(--blue);
  text-underline-offset: 3px;
}

code,
pre,
textarea {
  font-family: "IBM Plex Mono", "SFMono-Regular", "Cascadia Code", ui-monospace, monospace;
}

textarea,
pre,
td,
.empty-card,
.score-band,
.compact-list li,
.work-list li,
.gap-grid li {
  overflow-wrap: anywhere;
}

.app-shell {
  width: min(1380px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 44px;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 0 0 18px;
}

.app-header h1,
.section-heading h2 {
  margin: 0;
  line-height: 1.12;
  letter-spacing: 0;
  font-weight: 760;
}

.app-header h1 {
  max-width: 780px;
  font-size: 2rem;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--merchant);
  font-size: 0.72rem;
  font-weight: 780;
  letter-spacing: 0;
  text-transform: uppercase;
}

.source-box {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px 12px;
  max-width: 580px;
  color: var(--muted);
  line-height: 1.38;
  font-size: 0.88rem;
}

.source-box strong {
  flex-basis: 100%;
  color: var(--ink);
  text-align: right;
}

.mapper-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.44fr) minmax(360px, 0.9fr);
  align-items: stretch;
  gap: 16px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 22px;
}

.section-heading {
  margin-bottom: 16px;
}

.section-heading h2 {
  font-size: 1.18rem;
}

.field-label {
  display: block;
  margin: 0 0 8px;
  font-size: 0.84rem;
  font-weight: 740;
}

textarea {
  width: 100%;
  min-height: 322px;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
  padding: 13px 14px;
  font-size: 0.9rem;
  line-height: 1.5;
}

textarea:focus {
  border-color: var(--merchant);
  box-shadow: 0 0 0 3px rgba(29, 111, 74, 0.15);
}

.input-meta {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.36;
}

.input-meta span:last-child {
  text-align: right;
}

.input-message {
  min-height: 20px;
  margin: 8px 0 0;
  color: var(--red);
  font-size: 0.86rem;
}

.action-row,
.copy-toolbar,
.tab-bar,
.boundary-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.action-row {
  align-items: center;
  margin-top: 14px;
}

.primary-action,
.secondary-action,
.ghost-action,
.copy-button,
.tab-button {
  min-height: 40px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 740;
}

.primary-action {
  background: var(--merchant);
  color: #fff;
}

.secondary-action {
  border-color: var(--merchant);
  background: var(--merchant-soft);
  color: var(--merchant);
}

.ghost-action {
  border-color: var(--line);
  background: var(--surface);
  color: var(--charcoal);
}

.summary-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.summary-layout {
  display: grid;
  grid-template-columns: minmax(130px, 0.72fr) minmax(150px, 1fr);
  gap: 12px;
  align-items: stretch;
}

.score-box {
  display: flex;
  min-height: 150px;
  flex-direction: column;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  padding: 16px;
}

.score-value {
  display: block;
  font-size: 3.1rem;
  line-height: 0.96;
  font-weight: 820;
  letter-spacing: 0;
}

.score-label {
  margin-top: 8px;
  color: var(--muted);
  font-weight: 740;
}

.score-band {
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.35;
}

.score-box.state-critical {
  border-color: rgba(179, 39, 29, 0.34);
  background: var(--red-soft);
}

.score-box.state-high {
  border-color: rgba(138, 97, 0, 0.34);
  background: var(--amber-soft);
}

.score-box.state-planned {
  border-color: rgba(40, 95, 159, 0.3);
  background: var(--blue-soft);
}

.flow-mark {
  width: 100%;
  height: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbf8;
}

.flow-mark rect {
  fill: #ffffff;
  stroke: var(--line-strong);
}

.flow-mark path {
  fill: none;
  stroke: var(--merchant);
  stroke-width: 3;
}

.flow-mark circle {
  fill: var(--merchant);
}

.flow-mark text {
  fill: var(--charcoal);
  font: 700 14px "Aptos", "Segoe UI", sans-serif;
  text-anchor: middle;
}

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

.metric-grid div {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  padding: 10px;
}

.metric-grid dt {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 760;
  text-transform: uppercase;
}

.metric-grid dd {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 780;
}

.summary-block,
.next-action {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 14px;
}

.summary-block h3,
.next-action strong,
.subpanel h3 {
  margin: 0 0 9px;
  font-size: 0.98rem;
}

.compact-list,
.work-list,
.gap-grid {
  margin: 0;
  padding-left: 18px;
  color: var(--charcoal);
  line-height: 1.45;
}

.compact-list li + li,
.work-list li + li,
.gap-grid li + li {
  margin-top: 7px;
}

.next-action span {
  display: block;
  color: var(--muted);
  line-height: 1.42;
}

.scope-note {
  margin: 0;
  border-left: 3px solid var(--merchant);
  padding-left: 11px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.results-panel {
  margin-top: 16px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.result-status {
  max-width: 520px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
  text-align: right;
}

.tab-bar {
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.tab-button {
  border-color: var(--line);
  border-bottom: 0;
  background: #f8faf8;
  color: var(--charcoal);
  border-radius: 6px 6px 0 0;
}

.tab-button.is-active {
  background: var(--merchant);
  color: #fff;
  border-color: var(--merchant);
}

.tab-panel[hidden] {
  display: none;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.matrix-table {
  width: 100%;
  min-width: 850px;
  border-collapse: collapse;
  background: #fff;
}

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

.matrix-table th {
  background: #f7faf7;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.matrix-table tr:last-child td {
  border-bottom: 0;
}

.empty-row td,
.empty-card {
  color: var(--muted);
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 0.78rem;
  font-weight: 780;
  white-space: nowrap;
}

.chip.immediate {
  background: var(--red-soft);
  color: var(--red);
}

.chip.planned {
  background: var(--amber-soft);
  color: var(--amber);
}

.chip.monitor {
  background: var(--blue-soft);
  color: var(--blue);
}

.chip.needs-evidence {
  background: var(--surface-muted);
  color: var(--charcoal);
}

.snippet {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.45;
}

.inventory-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.inventory-card,
.empty-card {
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 13px;
}

.inventory-card strong {
  display: block;
  margin-bottom: 7px;
}

.inventory-card span {
  display: block;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.4;
}

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

.subpanel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 16px;
}

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

.gap-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
  padding-left: 0;
  list-style: none;
}

.gap-grid li {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fff;
}

.copy-toolbar {
  margin-bottom: 12px;
}

.copy-button {
  border-color: var(--line);
  background: #fbfcfb;
  color: var(--charcoal);
}

.copy-button:not(:disabled):hover,
.secondary-action:hover,
.ghost-action:hover,
.tab-button:not(.is-active):hover {
  border-color: var(--merchant);
}

.artifact-preview {
  min-height: 320px;
  max-height: 520px;
  overflow: auto;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101511;
  color: #ecf6ef;
  padding: 16px;
  font-size: 0.84rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

.boundary-strip {
  justify-content: center;
  margin-top: 16px;
  color: var(--muted);
}

.boundary-strip span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  padding: 6px 10px;
  font-size: 0.8rem;
  font-weight: 760;
}

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

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

@media (max-width: 1050px) {
  .app-header,
  .panel-head {
    display: block;
  }

  .source-box {
    justify-content: flex-start;
    margin-top: 12px;
  }

  .source-box strong,
  .result-status {
    text-align: left;
  }

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

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

@media (max-width: 680px) {
  .app-shell {
    width: min(100% - 20px, 1380px);
    padding-top: 16px;
  }

  .app-header h1 {
    font-size: 1.42rem;
  }

  .panel {
    padding: 16px;
  }

  textarea {
    min-height: 280px;
  }

  .input-meta,
  .summary-layout {
    display: block;
  }

  .input-meta span:last-child {
    display: block;
    margin-top: 7px;
    text-align: left;
  }

  .flow-mark {
    margin-top: 12px;
  }

  .metric-grid,
  .inventory-grid,
  .checklist-grid,
  .gap-grid {
    grid-template-columns: 1fr;
  }

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

  .primary-action,
  .secondary-action,
  .ghost-action,
  .copy-button,
  .tab-button {
    width: 100%;
  }
}
