:root {
  color-scheme: light;
  --bg: #f7f4ed;
  --paper: #fffdf8;
  --paper-strong: #ffffff;
  --ink: #17211f;
  --muted: #68746f;
  --line: #ddd6ca;
  --teal: #164c45;
  --teal-soft: #d7ebe5;
  --gold: #f2c15d;
  --rose: #e85f5c;
  --violet: #7567b3;
  --blue: #3d7c99;
  --green: #357960;
  --shadow: 0 12px 32px rgba(37, 42, 38, 0.12);
  --radius: 8px;
  --sidebar: 268px;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(22, 76, 69, 0.08) 1px, transparent 1px),
    linear-gradient(180deg, rgba(22, 76, 69, 0.06) 1px, transparent 1px),
    var(--bg);
  background-size: 34px 34px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.layout {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100vh;
  max-width: 100vw;
  overflow-x: hidden;
}

.side {
  min-width: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px;
  background: rgba(255, 253, 248, 0.88);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: grid;
  grid-template-columns: 48px 1fr;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--teal);
  color: var(--gold);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
}

.brand-mark svg {
  width: 30px;
  height: 30px;
  fill: currentColor;
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.1;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

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

.nav button,
.icon-btn,
.primary,
.secondary,
.danger,
.chip {
  border: 1px solid transparent;
  border-radius: var(--radius);
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent;
  color: var(--ink);
}

.nav button {
  justify-content: flex-start;
  padding: 0 12px;
  color: var(--muted);
}

.nav button svg,
.icon-btn svg,
.primary svg,
.secondary svg,
.danger svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex: none;
}

.nav button.active {
  color: var(--teal);
  background: var(--teal-soft);
  border-color: #b9d9d1;
  font-weight: 700;
}

.search-wrap {
  position: relative;
}

.search-wrap input,
.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--paper-strong);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 11px 12px;
  outline: none;
}

.field textarea {
  resize: vertical;
  min-height: 82px;
}

.search-wrap input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(22, 76, 69, 0.14);
}

.side-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: auto;
}

.primary {
  background: var(--teal);
  color: #fffdf8;
  border-color: var(--teal);
  padding: 0 14px;
  font-weight: 750;
}

.secondary {
  background: var(--paper-strong);
  border-color: var(--line);
  padding: 0 14px;
  color: var(--ink);
}

.danger {
  background: #fff7f6;
  border-color: #f0c0bd;
  color: #9b2f2c;
  padding: 0 12px;
}

.primary:hover,
.secondary:hover,
.danger:hover,
.icon-btn:hover,
.chip:hover {
  transform: translateY(-1px);
}

.main {
  min-width: 0;
  overflow: hidden;
  padding: 30px clamp(18px, 4vw, 48px) 42px;
}

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

.eyebrow {
  margin: 0 0 8px;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.topline h2 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4.2rem);
  line-height: 0.95;
  overflow-wrap: break-word;
}

.topline p {
  max-width: 720px;
  color: var(--muted);
  line-height: 1.55;
  margin: 14px 0 0;
}

.status-pill {
  white-space: nowrap;
  background: var(--paper-strong);
  border: 1px solid var(--line);
  border-radius: 999px;
  min-height: 36px;
  padding: 0 13px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  box-shadow: 0 6px 18px rgba(37, 42, 38, 0.08);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
}

.grid {
  display: grid;
  gap: 14px;
}

.metrics {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 16px;
}

.metric,
.panel,
.item,
.composer,
.tool {
  background: rgba(255, 253, 248, 0.92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(37, 42, 38, 0.08);
}

.metric {
  padding: 16px;
  min-height: 118px;
}

.metric span {
  color: var(--muted);
  font-size: 0.82rem;
}

.metric strong {
  display: block;
  font-size: 2.1rem;
  line-height: 1;
  margin: 12px 0 8px;
}

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

.two-col {
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  align-items: start;
}

.panel {
  padding: 18px;
}

.panel h3,
.composer h3,
.tool h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}

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

.panel-head h3 {
  margin: 0;
}

.canvas-wrap {
  min-height: 230px;
}

canvas {
  width: 100%;
  max-width: 100%;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.item-list {
  display: grid;
  gap: 10px;
}

.item {
  padding: 14px;
}

.item-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.item h4 {
  margin: 0;
  font-size: 1rem;
}

.item p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.tags,
.row,
.button-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.tags {
  margin-top: 10px;
}

.tag,
.kind,
.chip {
  font-size: 0.78rem;
  line-height: 1;
  border-radius: 999px;
}

.tag {
  padding: 6px 8px;
  color: var(--teal);
  background: var(--teal-soft);
}

.kind {
  padding: 7px 9px;
  color: #533a00;
  background: #ffe6a9;
}

.kind.challenge {
  color: #7d2b28;
  background: #ffe0de;
}

.kind.neutral {
  color: #3c4c5a;
  background: #e4edf1;
}

.confidence {
  margin: 12px 0;
}

.meter {
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: #ece5d9;
  border: 1px solid var(--line);
}

.meter > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--rose), var(--gold), var(--green));
}

.meter-label {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 5px;
}

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

.evidence-stat {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #fffaf1;
}

.evidence-stat strong {
  display: block;
  font-size: 1.35rem;
}

.composer,
.tool {
  padding: 16px;
}

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

.field.full {
  grid-column: 1 / -1;
}

.field label {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.field input[type="range"] {
  accent-color: var(--teal);
  padding: 0;
}

.section-title {
  margin: 24px 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-title h3 {
  margin: 0;
}

.empty {
  padding: 26px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.74);
}

.decision-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin-top: 12px;
}

.decision-table th,
.decision-table td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 9px 7px;
}

.decision-table th {
  color: var(--muted);
  font-size: 0.78rem;
}

.score-badge {
  display: inline-flex;
  min-width: 44px;
  justify-content: center;
  border-radius: 999px;
  padding: 6px 8px;
  background: var(--teal-soft);
  color: var(--teal);
  font-weight: 800;
}

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

.tool output {
  display: block;
  margin-top: 12px;
  padding: 12px;
  border-radius: var(--radius);
  background: #eff7f4;
  color: var(--teal);
  font-weight: 800;
}

.notice {
  border-left: 4px solid var(--gold);
  background: #fff7df;
  padding: 12px;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: #5b4515;
  line-height: 1.45;
  overflow-wrap: break-word;
}

.hidden {
  display: none !important;
}

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

  .side {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .nav button {
    justify-content: center;
    padding: 0 8px;
    min-width: 0;
  }

  .nav span {
    display: none;
  }

  .metrics,
  .two-col,
  .lab-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .layout,
  .side,
  .main {
    width: 100vw;
    max-width: 100vw;
  }

  .side {
    padding: 22px 12px;
  }

  .side > *,
  .main > * {
    max-width: calc(100vw - 24px);
    min-width: 0;
  }

  .main {
    padding: 20px 12px 30px;
  }

  .topline {
    display: block;
  }

  .topline h2 {
    font-size: 1.85rem;
    line-height: 1.05;
    width: 100%;
    max-width: 20rem;
  }

  .topline p,
  .notice {
    width: 100%;
    max-width: 20rem;
    white-space: normal;
  }

  .search-wrap {
    width: calc(100vw - 24px);
    white-space: normal;
  }

  .status-pill {
    margin-top: 14px;
  }

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

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

  .side-actions {
    grid-template-columns: 1fr;
  }

  .item-header {
    display: block;
  }

  .button-row {
    margin-top: 10px;
  }
}
