:root {
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-2: #f0f3f5;
  --text: #172026;
  --muted: #65727d;
  --line: #d9e0e5;
  --line-strong: #c5ced6;
  --accent: #186f65;
  --accent-2: #2f5d8c;
  --sell: #b7473d;
  --buy: #23704f;
  --nobid: #7a8288;
  --warn: #a66517;
  --shadow: 0 12px 24px rgba(23, 32, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

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

button,
select {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
}

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  background: #10171d;
  color: #f5f8fa;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #202c35;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 4px 6px 18px;
  border-bottom: 1px solid #24323d;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 6px;
  background: #e6f2ef;
  color: #153d37;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.brand-name {
  font-weight: 750;
}

.brand-sub {
  color: #a9b7c1;
  font-size: 12px;
  margin-top: 2px;
}

.nav {
  padding: 18px 0;
  display: grid;
  gap: 6px;
}

.nav-item {
  height: 40px;
  text-align: left;
  padding: 0 12px;
  color: #d7e0e6;
  background: transparent;
  border-color: transparent;
}

.nav-item:hover,
.nav-item.active {
  background: #1b2831;
  border-color: #2a3b47;
  color: #ffffff;
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px;
  background: #17222a;
  border: 1px solid #273945;
  border-radius: 6px;
  color: #d7e0e6;
  font-size: 12px;
}

.status-dot {
  width: 9px;
  height: 9px;
  background: #48b17f;
  border-radius: 50%;
}

.main {
  min-width: 0;
  padding: 22px;
}

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

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

h2 {
  font-size: 16px;
  letter-spacing: 0;
}

h3 {
  font-size: 14px;
  letter-spacing: 0;
}

.topbar p,
.panel-head p,
.muted {
  color: var(--muted);
}

.topbar p {
  margin-top: 6px;
}

.topbar-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.meta-pill {
  min-width: 126px;
  padding: 9px 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.meta-pill span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.meta-pill strong {
  display: block;
  margin-top: 2px;
  font-size: 13px;
}

.meta-pill.success {
  border-color: #b8d9c9;
  background: #eef8f3;
}

.freshness-warning {
  margin-bottom: 18px;
  padding: 10px 14px;
  border-left: 3px solid var(--warn);
  background: #fff4e5;
  color: #73470c;
  font-weight: 600;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

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

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

.two-col {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 14px;
  margin-bottom: 14px;
}

.two-col.wide-left {
  grid-template-columns: minmax(0, 1.45fr) minmax(360px, 0.55fr);
}

.panel,
.metric,
.strategy-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.command-panel {
  margin-bottom: 14px;
}

.command-box {
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
  color: #26343d;
}

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

.agent-loop div {
  min-height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #eef5f3;
  color: #214842;
  font-weight: 700;
  text-align: center;
  font-size: 12px;
}

.war-room-panel {
  margin-bottom: 14px;
}

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

.war-card {
  min-height: 138px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.war-card.primary-war {
  border-color: #bddbd4;
  background: #eff8f5;
}

.war-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.war-card strong {
  display: block;
  margin-top: 7px;
  font-size: 20px;
  line-height: 1.2;
}

.war-card p {
  margin-top: 10px;
  color: #43525c;
}

.war-summary {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.panel {
  padding: 14px;
}

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

.metric {
  padding: 14px;
  min-height: 128px;
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
}

.metric-value {
  margin-top: 8px;
  font-size: 26px;
  font-weight: 780;
  line-height: 1.1;
}

.metric-sub {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  color: var(--muted);
}

.toolbar,
.segmented {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.segmented button {
  min-height: 34px;
  padding: 0 12px;
  color: var(--muted);
}

.segmented button.active {
  color: #ffffff;
  background: var(--accent);
  border-color: var(--accent);
}

.family-panel-head {
  flex-direction: column;
}

.family-panel-head .segmented {
  width: 100%;
}

.family-panel-head .segmented button {
  max-width: 100%;
  white-space: normal;
  text-align: left;
}

.toolbar select {
  max-width: 100%;
}

.metric,
.strategy-card,
.panel,
.panel-head > div {
  min-width: 0;
  overflow-wrap: anywhere;
}

select {
  height: 36px;
  padding: 0 10px;
}

.brief {
  display: grid;
  gap: 12px;
}

.brief-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfc;
}

.brief-card strong {
  display: block;
  margin-bottom: 6px;
}

.badge-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: #34434d;
  font-size: 12px;
  white-space: nowrap;
}

.badge.sell {
  color: var(--sell);
  background: #fff1ef;
  border-color: #efc5bf;
}

.badge.buy {
  color: var(--buy);
  background: #edf8f2;
  border-color: #b9dcc9;
}

.badge.nobid {
  color: var(--nobid);
  background: #f2f4f5;
}

.badge.pass {
  color: var(--accent);
  background: #eaf7f3;
  border-color: #b7d8ce;
}

.action-bars {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr) 58px;
  gap: 10px;
  align-items: center;
}

.bar-track {
  height: 11px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
}

.bar-fill.Sell {
  background: var(--sell);
}

.bar-fill.Buy {
  background: var(--buy);
}

.bar-fill.NoBid,
.bar-fill.No-Bid {
  background: var(--nobid);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

table {
  width: 100%;
  min-width: 1120px;
  border-collapse: collapse;
  background: var(--surface);
}

th,
td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef2f4;
  color: #40505b;
  font-size: 12px;
  font-weight: 700;
}

td.numeric,
th.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

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

.action-cell {
  font-weight: 720;
}

.action-cell.Sell {
  color: var(--sell);
}

.action-cell.Buy {
  color: var(--buy);
}

.action-cell.No-Bid {
  color: var(--nobid);
}

.explain-cell {
  min-width: 320px;
  max-width: 420px;
  white-space: normal;
  color: #34434d;
}

.heatmap {
  display: grid;
  grid-template-columns: repeat(24, minmax(26px, 1fr));
  gap: 4px;
}

.heat-cell {
  min-height: 54px;
  border-radius: 6px;
  border: 1px solid var(--line);
  padding: 5px;
  background: #f4f6f7;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.heat-cell.sell {
  background: #fff1ef;
  border-color: #e5b7af;
}

.heat-cell.buy {
  background: #edf8f2;
  border-color: #afd7c2;
}

.heat-cell.mix {
  background: #eef4fb;
  border-color: #b8cde1;
}

.heat-cell.nobid {
  background: #f3f4f5;
}

.strategy-card {
  padding: 16px;
}

.strategy-card h2 {
  font-size: 18px;
}

.strategy-meta {
  margin-top: 4px;
  color: var(--muted);
}

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

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

.small-stat span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.small-stat strong {
  display: block;
  margin-top: 4px;
  font-size: 16px;
}

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

.rule-list li {
  border-left: 3px solid var(--accent-2);
  padding: 6px 0 6px 10px;
  color: #34434d;
}

.card-stack {
  display: grid;
  gap: 10px;
}

.info-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.info-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.score-item {
  padding: 9px;
  background: #f4f7f8;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.score-item span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.score-item strong {
  display: block;
  margin-top: 4px;
}

.signal-input-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr);
  gap: 12px;
}

.signal-input-grid textarea {
  min-height: 146px;
  resize: vertical;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
  color: #26343d;
}

.strategy-flow {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

.flow-step {
  min-height: 148px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.flow-step span {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  margin-bottom: 10px;
  border-radius: 50%;
  background: #e7f1ee;
  color: var(--accent);
  font-weight: 780;
}

.flow-step strong {
  display: block;
  margin-bottom: 8px;
}

.flow-step p {
  color: var(--muted);
}

.comparison-table table {
  min-width: 760px;
}

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

.asset-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  min-height: 150px;
}

.asset-card h3 {
  margin-bottom: 8px;
}

.primary {
  min-height: 36px;
  padding: 0 14px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

.secondary {
  min-height: 32px;
  padding: 0 10px;
}

.decision-list {
  display: grid;
  gap: 8px;
  max-height: 600px;
  overflow-y: auto;
}

.decision-item {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfc;
}

.decision-item input {
  width: 16px;
  height: 16px;
}

.record-block {
  display: grid;
  gap: 10px;
}

.record-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.record-row:last-child {
  border-bottom: 0;
}

.sticky-panel {
  position: sticky;
  top: 22px;
  align-self: start;
}

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

.review-step {
  min-height: 150px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.review-step h3 {
  margin-bottom: 8px;
}

.review-step p {
  color: var(--muted);
}

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

  .sidebar {
    position: static;
    height: auto;
  }

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

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

  .metrics-grid,
  .strategy-grid,
  .strategy-flow,
  .war-room-grid,
  .signal-input-grid,
  .two-col,
  .two-col.wide-left,
  .review-grid,
  .audit-grid,
  .asset-grid,
  .agent-loop {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
  }

  .topbar-meta {
    justify-content: flex-start;
  }
}

@media (max-width: 720px) {
  .main {
    padding: 14px;
  }

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

  .metrics-grid {
    gap: 10px;
  }

  .panel-head {
    flex-direction: column;
  }

  .heatmap {
    grid-template-columns: repeat(6, minmax(34px, 1fr));
  }
}
