:root {
  --ink: #18231d;
  --muted: #69736a;
  --paper: #f7f3ea;
  --panel: #fffdf8;
  --line: #d9d2c3;
  --green: #2e6c52;
  --green-dark: #174934;
  --saffron: #c4812c;
  --clay: #9d4735;
  --blue: #315f70;
  --shadow: 0 18px 42px rgba(34, 37, 29, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px clamp(18px, 4vw, 44px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.94);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--green-dark);
  color: #fff;
  font-weight: 800;
}

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

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.15rem, 2vw, 1.55rem);
  line-height: 1.15;
}

h2 {
  margin-bottom: 10px;
  font-size: clamp(1.35rem, 2.6vw, 2.35rem);
  line-height: 1.08;
}

h3 {
  margin-bottom: 10px;
  font-size: 1rem;
}

.header-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

.header-meta span {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  background: #fff;
}

main {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px clamp(14px, 4vw, 44px) 46px;
}

.hero-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  min-height: 270px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.hero-copy {
  padding: clamp(24px, 4vw, 46px);
  align-self: center;
}

.hero-copy p:last-child {
  max-width: 780px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1rem;
}

.hero-image {
  min-height: 230px;
  background:
    linear-gradient(90deg, rgba(255, 253, 248, 0.1), rgba(24, 35, 29, 0.08)),
    url("assets/rice.jpg") center / cover no-repeat;
}

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

.metric {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metric-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.84rem;
}

.metric strong {
  display: block;
  color: var(--green-dark);
  font-size: clamp(1.55rem, 3vw, 2.2rem);
  line-height: 1;
}

.portal-layout {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.control-panel,
.results-panel,
.sources-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.control-panel {
  position: sticky;
  top: 98px;
  padding: 16px;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f2ebdf;
}

.segment {
  border: 0;
  border-radius: 6px;
  padding: 10px 8px;
  color: var(--muted);
  background: transparent;
  font-size: 0.92rem;
  font-weight: 800;
}

.segment.is-active {
  color: #fff;
  background: var(--green);
}

.field {
  display: grid;
  gap: 7px;
  margin-top: 15px;
}

.field span,
.check-row span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

input[type="search"],
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: #fff;
  color: var(--ink);
}

input[type="search"]:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(196, 129, 44, 0.35);
  outline-offset: 2px;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 16px;
}

.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 18px;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  border-radius: 6px;
  padding: 9px 12px;
  font-weight: 800;
}

.primary-button {
  border: 1px solid var(--green-dark);
  color: #fff;
  background: var(--green-dark);
}

.secondary-button {
  border: 1px solid var(--line);
  color: var(--ink);
  background: #fff;
}

.source-note {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.source-note p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.results-panel {
  min-width: 0;
  overflow: hidden;
}

.results-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.results-toolbar h2 {
  margin-bottom: 0;
  font-size: clamp(1.25rem, 2vw, 1.65rem);
}

.mini-legend {
  max-width: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--muted);
  background: #fff;
  font-size: 0.86rem;
}

.chart-panel {
  padding: 16px 18px 6px;
  border-bottom: 1px solid var(--line);
}

.bar-chart {
  display: grid;
  gap: 8px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(92px, 180px) 1fr 44px;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 0.86rem;
}

.bar-track {
  height: 10px;
  overflow: hidden;
  border-radius: 8px;
  background: #eee6da;
}

.bar-fill {
  height: 100%;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--green), var(--saffron));
}

.bar-count {
  text-align: right;
  color: var(--ink);
  font-weight: 800;
}

.profile-detail {
  display: grid;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: #fbf7ef;
}

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

.detail-header h3 {
  margin-bottom: 0;
  font-size: 1.2rem;
}

.detail-score {
  flex: 0 0 auto;
  border-radius: 8px;
  padding: 8px 10px;
  color: #fff;
  background: var(--green-dark);
}

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

.detail-facts dt {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.detail-facts dd {
  margin: 2px 0 0;
  color: var(--ink);
  font-weight: 750;
  overflow-wrap: anywhere;
}

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

.detail-group h4 {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

.detail-group.is-wide {
  grid-column: 1 / -1;
}

.evidence-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 18px;
  color: var(--ink);
  font-size: 0.9rem;
}

.muted-detail {
  color: var(--muted);
  font-size: 0.86rem;
}

.table-shell {
  overflow: auto;
  max-height: 680px;
}

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

th:nth-child(1),
td:nth-child(1) {
  min-width: 190px;
}

th:nth-child(2),
td:nth-child(2) {
  min-width: 170px;
}

th:nth-child(4),
td:nth-child(4),
th:nth-child(5),
td:nth-child(5),
th:nth-child(6),
td:nth-child(6),
th:nth-child(7),
td:nth-child(7),
th:nth-child(8),
td:nth-child(8) {
  min-width: 170px;
}

th:nth-child(9),
td:nth-child(9) {
  min-width: 68px;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #f3ecdf;
  color: var(--green-dark);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

th button {
  width: 100%;
  border: 0;
  padding: 0;
  color: inherit;
  background: transparent;
  text-align: left;
  font-weight: 900;
  text-transform: inherit;
}

td {
  color: var(--muted);
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

td.company-cell {
  color: var(--ink);
  font-weight: 800;
}

tbody tr[data-company] {
  cursor: pointer;
}

tbody tr[data-company].is-selected {
  background: #f2eadc;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.code-pill,
.country-pill,
.signal-tag,
.priority-pill,
.value-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
  padding: 3px 7px;
  font-size: 0.78rem;
  font-weight: 800;
  overflow-wrap: normal;
  white-space: nowrap;
}

.code-pill {
  color: #fff;
  background: var(--blue);
}

.country-pill {
  color: #fff;
  background: var(--clay);
}

.signal-tag {
  color: var(--green-dark);
  background: #e9f0e7;
}

.priority-pill {
  color: var(--green-dark);
  background: #f0e5d2;
}

.value-pill {
  color: var(--ink);
  background: #e6edf0;
  white-space: normal;
}

.empty-state {
  padding: 32px;
  color: var(--muted);
  text-align: center;
}

.sources-panel {
  display: grid;
  grid-template-columns: minmax(240px, 0.7fr) minmax(0, 1.3fr);
  gap: 18px;
  margin-top: 18px;
  padding: 20px;
}

.sources-panel h2 {
  margin-bottom: 0;
  font-size: 1.35rem;
}

.sources-panel ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.sources-panel a {
  color: var(--green-dark);
  font-weight: 800;
}

.sources-panel li {
  color: var(--muted);
}

@media (max-width: 980px) {
  .app-header,
  .results-toolbar,
  .sources-panel {
    display: grid;
  }

  .header-meta {
    justify-content: start;
  }

  .hero-panel,
  .portal-layout,
  .sources-panel {
    grid-template-columns: 1fr;
  }

  .hero-image {
    min-height: 210px;
    order: -1;
  }

  .control-panel {
    position: static;
  }

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

  .detail-facts,
  .detail-groups {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 620px) {
  main {
    padding-inline: 12px;
  }

  .app-header {
    padding-inline: 12px;
  }

  .brand-lockup {
    align-items: flex-start;
  }

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

  .hero-copy {
    padding: 22px;
  }

  .bar-row {
    grid-template-columns: 98px 1fr 34px;
    gap: 8px;
  }

  .action-row {
    grid-template-columns: 1fr;
  }

  .detail-header,
  .detail-facts,
  .detail-groups {
    display: grid;
    grid-template-columns: 1fr;
  }
}
