:root {
  --bg: #f4f6f8;
  --ink: #1e2732;
  --muted: #687386;
  --line: #d8dee7;
  --panel: #ffffff;
  --head: #162334;
  --high: #c7342f;
  --elevated: #d86f22;
  --medium: #c9961a;
  --low: #4f8f5b;
  --missing: #7b8190;
  --purple: #7251a2;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 13px;
  letter-spacing: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  max-height: 56px;
  padding: 6px 12px;
  overflow: hidden;
  background: var(--head);
  color: #fff;
  border-bottom: 2px solid #9aa7b8;
}

.header-main {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
  overflow: hidden;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 15px;
  font-weight: 700;
}

.header-title {
  flex-shrink: 0;
  line-height: 1.1;
  white-space: nowrap;
}

h2 {
  font-size: 15px;
}

.meta-line,
.top-actions,
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.meta-line {
  margin-top: 0;
  color: #d7deea;
}

.header-meta {
  flex-wrap: nowrap;
  min-width: 0;
  gap: 8px;
  overflow: hidden;
  font-size: 11px;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-meta span {
  flex-shrink: 0;
  white-space: nowrap;
}

.meta-line strong {
  display: inline-block;
  max-width: 92px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
  white-space: nowrap;
}

button,
select,
input {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

button {
  padding: 0 12px;
  cursor: pointer;
  border-color: #b6c1d0;
}

.header-actions {
  flex-shrink: 0;
  flex-wrap: nowrap;
  gap: 6px;
}

.header-badge,
.header-button {
  min-height: 24px;
  padding: 4px 6px;
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
}

.pdf-download-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #8270c4;
  border-radius: 4px;
  background: #7251a2;
  color: #fff;
  text-decoration: none;
}

.pdf-download-button:hover {
  background: #8060b1;
}

button:hover {
  background: #eef2f6;
}

select,
input {
  padding: 0 8px;
}

main {
  max-width: 1680px;
  margin: 0 auto;
  padding: 14px;
}

.status-pill,
.risk-tag,
.change-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  padding: 3px 7px;
  border-radius: 4px;
  color: #fff;
  background: var(--purple);
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.muted {
  color: #1f2d3d;
  background: #dce3ec;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.summary-grid article {
  min-height: 70px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.summary-grid article[data-tab-target] {
  cursor: pointer;
}

.summary-grid article[data-tab-target]:hover {
  border-color: #9fb0c3;
  background: #fbfcfe;
}

.summary-grid span {
  display: block;
  color: var(--muted);
}

.summary-grid strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
  overflow-wrap: anywhere;
}

#reportPeriodCard {
  font-size: 18px;
  white-space: nowrap;
}

.panel-row {
  display: grid;
  grid-template-columns: 0.8fr 1.2fr 1fr;
  gap: 10px;
}

.panel {
  margin-bottom: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  background: #eef2f6;
}

.notice {
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid #c7ced9;
  border-left: 4px solid var(--purple);
  background: #fff;
  color: #394456;
}

.hidden {
  display: none;
}

.bars,
.heatmap,
.trend,
.changes,
.crop-summary,
.risk-rules {
  padding: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 50px 1fr 36px;
  align-items: center;
  gap: 8px;
  margin: 7px 0;
}

.bar {
  height: 18px;
  background: #e7ebf0;
  border-radius: 3px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  min-width: 2px;
}

.heatmap-wrap {
  overflow: auto;
}

.heatmap-table {
  width: 100%;
  min-width: 1080px;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
}

.heatmap-table th,
.heatmap-table td {
  width: 86px;
  min-width: 86px;
  max-width: 86px;
  padding: 5px;
  border-right: 1px solid #dfe5ec;
  border-bottom: 1px solid #dfe5ec;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}

.heatmap-table thead th {
  position: static;
  z-index: auto;
  background: #27374a;
  color: #fff;
}

.heatmap-table th:first-child {
  width: 150px;
  min-width: 150px;
  max-width: 150px;
  text-align: left;
  white-space: normal;
}

.heatmap-table tbody th {
  position: static;
  z-index: auto;
  background: #f4f7fa;
  color: var(--ink);
}

.heat-crop-col {
  width: 150px;
}

.heat-region-col {
  width: 86px;
}

.heatmap-cell {
  width: 100%;
  min-height: 32px;
  padding: 3px 5px;
  border: 0;
  border-radius: 4px;
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
}

.heatmap-cell.risk-none {
  color: #687386;
  background: #edf0f4;
}

.risk-rules {
  border-top: 1px solid var(--line);
}

.risk-rules summary {
  cursor: pointer;
  font-weight: 700;
  color: #26384d;
}

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

.rule-section {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fbfcfe;
}

.rule-section-wide {
  grid-column: 1 / -1;
}

.rule-section h3 {
  margin: 0 0 7px;
  font-size: 13px;
  color: #26384d;
}

.rule-table-wrap {
  overflow-x: auto;
}

.rule-table {
  min-width: 760px;
  table-layout: fixed;
  border: 1px solid #dfe5ec;
  background: #fff;
}

.rule-table th,
.rule-table td {
  padding: 6px 7px;
  border-right: 1px solid #e6ebf1;
  border-bottom: 1px solid #e6ebf1;
  line-height: 1.45;
  vertical-align: top;
}

.rule-table th {
  background: #314258;
  color: #fff;
}

.rule-table th:nth-child(1),
.rule-table td:nth-child(1) {
  width: 92px;
}

.rule-table th:nth-child(2),
.rule-table td:nth-child(2) {
  width: 140px;
}

.rule-table th:nth-child(3),
.rule-table td:nth-child(3) {
  width: 230px;
}

.rule-table th:nth-child(4),
.rule-table td:nth-child(4) {
  width: 290px;
}

.stage-rule-table {
  min-width: 860px;
}

.stage-rule-table th:nth-child(1),
.stage-rule-table td:nth-child(1) {
  width: 130px;
}

.stage-rule-table th:nth-child(2),
.stage-rule-table td:nth-child(2) {
  width: 310px;
}

.stage-rule-table th:nth-child(3),
.stage-rule-table td:nth-child(3) {
  width: 420px;
}

.rule-threshold {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  background: #fff1d6;
  color: #8b3d12;
  font-weight: 800;
}

.risk-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 12px;
  padding: 8px;
  background: #e8edf3;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.risk-tabs button.active {
  color: #fff;
  background: #27374a;
  border-color: #27374a;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.climate-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 8px;
  padding: 10px;
}

.climate-grid article {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fbfcfe;
}

.climate-grid article.wide {
  grid-column: span 2;
}

.climate-grid span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
}

.climate-grid strong {
  line-height: 1.45;
  font-weight: 600;
}

.trend-row {
  display: grid;
  grid-template-columns: 110px 1fr 34px;
  align-items: center;
  gap: 8px;
  margin: 7px 0;
}

.trend-line {
  height: 12px;
  background: #e8edf2;
  border-radius: 3px;
  overflow: hidden;
}

.trend-line span {
  display: block;
  height: 100%;
  background: var(--high);
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  min-width: 1120px;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid #edf0f4;
  text-align: left;
  vertical-align: top;
}

th {
  position: static;
  z-index: 2;
  background: #27374a;
  color: #fff;
  font-weight: 700;
  white-space: normal;
  line-height: 1.25;
  cursor: default;
}

.data-table {
  table-layout: fixed;
}

.data-table th,
.data-table td {
  overflow-wrap: anywhere;
}

.detail-table {
  min-width: 1840px;
}

.compact-risk-table {
  min-width: 1480px;
}

.change-table {
  min-width: 1500px;
}

.critical-period-table {
  min-width: 1580px;
}

.critical-period-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(132px, 1fr));
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.critical-period-stats article {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-left: 3px solid #7251a2;
  border-radius: 4px;
  background: #fff;
}

.critical-period-stats span,
.critical-period-stats strong {
  display: block;
}

.critical-period-stats span {
  color: var(--muted);
  font-size: 12px;
}

.critical-period-stats strong {
  margin-top: 4px;
  font-size: 20px;
}

.col-crop {
  width: 90px;
}

.col-country {
  width: 130px;
}

.col-region {
  width: 150px;
}

.col-stage {
  width: 130px;
}

.col-risk {
  width: 86px;
}

.col-weather {
  width: 170px;
}

.col-forecast {
  width: 180px;
}

.col-soil {
  width: 180px;
}

.col-change {
  width: 140px;
}

.col-impact {
  width: 230px;
}

.col-source {
  width: 180px;
}

th[data-sort] {
  cursor: pointer;
}

tbody tr:hover {
  background: #fbfcfe;
}

.risk-high {
  background: var(--high);
}

.risk-elevated {
  background: var(--elevated);
}

.risk-medium {
  background: var(--medium);
}

.risk-low {
  background: var(--low);
}

.risk-missing {
  background: var(--missing);
}

.risk-none {
  background: #edf0f4;
}

.change-item {
  display: grid;
  grid-template-columns: 110px 170px 110px 110px 120px 1fr 1fr;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.change-item:last-child {
  border-bottom: 0;
}

.change-up {
  background: var(--high);
}

.change-down {
  background: var(--low);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.tabs button.active {
  color: #fff;
  background: #27374a;
}

.detail-link {
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #315d96;
  font-weight: 700;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.detail-link:hover {
  color: #1e3f6a;
  background: transparent;
}

.source-status {
  display: inline-flex;
  align-items: center;
  min-width: 78px;
  padding: 3px 6px;
  border-radius: 4px;
  font-weight: 700;
  white-space: nowrap;
}

.source-status-good { color: #fff; background: #4f8f5b; }
.source-status-cache { color: #5c3b0a; background: #f4d48b; }
.source-status-manual { color: #26384d; background: #cbd5e1; }
.source-status-failed { color: #fff; background: #c7342f; }
.source-status-unknown { color: #3f4652; background: #e2e6eb; }

.crop-summary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 8px;
}

.crop-card {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fbfcfe;
}

.crop-card strong {
  display: block;
  margin-bottom: 5px;
}

.empty {
  color: var(--muted);
}

@media (max-width: 1200px) {
  .summary-grid {
    grid-template-columns: repeat(4, 1fr);
  }

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

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

  .climate-grid article.wide {
    grid-column: auto;
  }

  .critical-period-stats {
    grid-template-columns: repeat(2, minmax(132px, 1fr));
  }
}

@media (max-width: 760px) {
  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar {
    align-items: center;
    flex-direction: row;
  }

  .header-title {
    max-width: 132px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header-meta span:nth-child(2) {
    display: none;
  }

  .header-badge:first-child {
    display: none;
  }

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

  .change-item {
    grid-template-columns: 1fr;
  }

  .rule-sections {
    grid-template-columns: 1fr;
  }
}
