:root {
  color-scheme: light;
  --bg: #f7f5ef;
  --text: #181a1f;
  --muted: #606874;
  --line: #d9d4ca;
  --paper: #fffdf8;
  --ink: #223942;
  --blue: #256f8f;
  --green: #5f7d4f;
  --red: #a84f42;
  --gold: #b38b3e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.site-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 48px clamp(20px, 5vw, 72px) 30px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(135deg, rgba(37, 111, 143, 0.14), transparent 42%),
    var(--paper);
}

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

h1 {
  margin-bottom: 12px;
  max-width: 860px;
  font-size: clamp(38px, 6vw, 76px);
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 18px;
  font-size: clamp(22px, 2.6vw, 32px);
  line-height: 1.05;
}

h3 {
  margin-bottom: 12px;
  font-size: 15px;
}

p {
  max-width: 760px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.55;
}

a {
  color: var(--ink);
}

.source-pill {
  min-width: 104px;
  border: 1px solid var(--ink);
  padding: 10px 14px;
  color: var(--ink);
  text-align: center;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

main {
  padding: 28px clamp(20px, 5vw, 72px) 56px;
}

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

.metrics article,
.panel {
  background: var(--paper);
  border: 1px solid var(--line);
}

.metrics article {
  border-left: 4px solid var(--blue);
  padding: 18px;
  min-height: 112px;
}

.metrics article:nth-child(2) {
  border-color: var(--green);
}

.metrics article:nth-child(3) {
  border-color: var(--red);
}

.metrics article:nth-child(4) {
  border-color: var(--gold);
}

.metrics span,
.group-row span {
  display: block;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.metrics strong {
  display: block;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1;
}

.insight-band {
  margin-bottom: 26px;
  padding: clamp(28px, 5vw, 48px);
  background: #263b42;
  color: white;
}

.insight-band p {
  color: rgba(255, 255, 255, 0.78);
}

.analysis-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 22px;
  margin-bottom: 26px;
}

.mining-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.55fr);
  gap: 22px;
  margin-bottom: 26px;
}

.panel {
  padding: 24px;
}

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

.panel-head h2 {
  margin-bottom: 0;
}

.controls {
  display: flex;
  gap: 10px;
}

input,
select {
  min-height: 42px;
  border: 1px solid var(--line);
  background: white;
  padding: 0 12px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

button {
  min-height: 42px;
  border: 1px solid var(--ink);
  background: var(--ink);
  padding: 0 16px;
  color: white;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.chat-box {
  display: grid;
  gap: 14px;
}

.chat-log {
  display: grid;
  gap: 10px;
  max-height: 340px;
  overflow: auto;
  border: 1px solid var(--line);
  background: #f8f5ed;
  padding: 14px;
}

.chat-message {
  max-width: 860px;
  padding: 12px 14px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.chat-message.assistant {
  justify-self: start;
  background: white;
  border-left: 4px solid var(--blue);
}

.chat-message.user {
  justify-self: end;
  background: #263b42;
  color: white;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.chat-form input {
  width: 100%;
}

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

.group-row,
.lift-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.group-row strong,
.lift-row strong {
  font-size: 16px;
}

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

.lift-row b {
  min-width: 76px;
  color: var(--red);
  font-size: 28px;
  text-align: right;
}

.lift-row small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.rank-bands {
  display: grid;
  gap: 12px;
}

.band-row {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.band-row strong {
  display: block;
  margin-bottom: 10px;
  color: var(--ink);
}

.band-row dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.band-row dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.band-row dd {
  margin: 2px 0 0;
  font-size: 18px;
  font-weight: 800;
}

.group-stats {
  min-width: 170px;
  text-align: right;
}

.group-stats b {
  display: block;
  color: var(--blue);
  font-size: 22px;
}

.group-stats small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.signal-stack {
  display: grid;
  gap: 24px;
}

.bar-row + .bar-row {
  margin-top: 10px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
}

.bar-label span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  height: 8px;
  background: #ece7dc;
}

.bar-track i {
  display: block;
  height: 100%;
  background: var(--green);
}

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

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

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

td:first-child,
td:nth-child(3),
td:nth-child(4),
td:nth-child(6),
td:nth-child(7),
td:nth-child(8) {
  font-variant-numeric: tabular-nums;
}

.error-state {
  padding: 40px;
}

@media (max-width: 900px) {
  .site-header,
  .panel-head,
  .mining-layout,
  .analysis-grid {
    display: block;
  }

  .source-pill,
  .controls,
  .panel-head select {
    margin-top: 16px;
  }

  .controls {
    display: grid;
  }

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

@media (max-width: 540px) {
  main {
    padding-inline: 16px;
  }

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

  h1 {
    font-size: 39px;
  }
}
