:root {
  --bg: #f5f1e8;
  --surface: #fffdf7;
  --surface-2: #ebe4d5;
  --text: #211f19;
  --muted: #6c675b;
  --border: #d6ccb9;
  --primary: #285c42;
  --primary-2: #173b2b;
  --gold: #b88932;
  --red: #9d3b2f;
  --green: #3f7d49;
  --shadow: 0 16px 40px rgba(71, 55, 31, 0.12);
  font-family: "Satoshi", "Inter", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 15% 0%, rgba(184, 137, 50, 0.13), transparent 32rem),
    var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  background: var(--primary);
  color: white;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  z-index: 20;
}

.skip-link:focus {
  top: 1rem;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 1.25rem;
  background: #26261f;
  color: #f7f1df;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand svg {
  width: 44px;
  height: 44px;
  color: #d2a64d;
  stroke: currentColor;
  stroke-width: 3;
  fill: none;
  flex: 0 0 auto;
}

.brand strong {
  display: block;
  font-size: 1rem;
}

.brand span,
.sidebar-card p,
.footer,
.eyebrow {
  color: var(--muted);
}

.brand span {
  color: #c9bea8;
  font-size: 0.85rem;
}

nav {
  display: grid;
  gap: 0.35rem;
}

nav a {
  color: #f7f1df;
  text-decoration: none;
  padding: 0.7rem 0.8rem;
  border-radius: 0.7rem;
}

nav a:hover,
nav a:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  outline: none;
}

.sidebar-card {
  margin-top: 0.25rem;
  padding: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.05);
  min-width: 0;
}

.sidebar-card .eyebrow,
.sidebar-card p {
  color: #c9bea8;
}

.main {
  padding: 1.15rem 1.35rem;
  display: grid;
  gap: 0.9rem;
  min-width: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  min-width: 0;
  width: 100%;
  max-width: 100%;
}

.topbar > div {
  min-width: 0;
  width: 100%;
  max-width: 100%;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: 700;
  margin: 0 0 0.35rem;
}

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

h1 {
  display: block;
  width: 100%;
  max-width: min(760px, 100%);
  font-size: clamp(1.45rem, 2vw, 2rem);
  line-height: 1.08;
  margin-bottom: 0;
  overflow-wrap: anywhere;
  word-break: normal;
  text-wrap: wrap;
}

.subhead,
.helper {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.subhead {
  margin: 0.45rem 0 0;
}

h2 {
  font-size: 1.08rem;
  margin-bottom: 0;
}

h3 {
  font-size: 0.92rem;
  margin: 0 0 0.45rem;
}

button {
  border: 0;
  background: var(--primary);
  color: white;
  border-radius: 999px;
  min-height: 44px;
  padding: 0.7rem 1rem;
  font-weight: 700;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  background: var(--primary-2);
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}

.metric-card,
.panel {
  background: rgba(255, 253, 247, 0.86);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 1.1rem;
}

.metric-card {
  padding: 0.78rem 0.9rem;
}

.metric-card span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.metric-card strong {
  display: block;
  margin-top: 0.35rem;
  font-size: 1.18rem;
  font-variant-numeric: tabular-nums;
}

.panel {
  padding: 0.95rem;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.65rem;
  align-items: center;
}

.pill {
  background: #ede3cf;
  color: #5d4931;
  border-radius: 999px;
  padding: 0.35rem 0.6rem;
  font-size: 0.78rem;
  font-weight: 700;
}

.note-list {
  margin: 0;
  padding-left: 1.2rem;
  display: grid;
  gap: 0.38rem;
}

.note-list li {
  line-height: 1.45;
}

.skeleton {
  list-style: none;
  height: 18px;
  border-radius: 999px;
  background: linear-gradient(90deg, #e9dfcd, #f8f2e4, #e9dfcd);
  background-size: 200% 100%;
  animation: shimmer 1.25s infinite;
}

@keyframes shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

.commodity-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.65rem;
}

.commodity-card {
  background: #f8f1e4;
  border: 1px solid #dfd2bd;
  border-radius: 0.95rem;
  padding: 0.75rem;
}

.commodity-card header {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
}

.commodity-card strong {
  display: block;
}

.commodity-card .price {
  font-size: 1.18rem;
  margin: 0.35rem 0 0.1rem;
  font-variant-numeric: tabular-nums;
}

.history-block {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid #eadfcd;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.65rem;
}

.history-card,
.history-row {
  background: #fbf6ec;
  border: 1px solid #dfd2bd;
  border-radius: 0.85rem;
  padding: 0.75rem;
}

.history-card strong,
.history-row strong {
  display: block;
  font-size: 0.9rem;
}

.history-card span,
.history-row span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 0.18rem;
}

.history-list {
  display: grid;
  gap: 0.5rem;
}

.sparkline {
  display: flex;
  align-items: end;
  gap: 3px;
  height: 66px;
  margin-top: 0.65rem;
  padding: 0.35rem;
  border-radius: 0.65rem;
  background: #efe5d4;
}

.sparkline span {
  flex: 1;
  min-width: 4px;
  border-radius: 999px 999px 0 0;
  background: linear-gradient(180deg, #2d7651, #b88932);
}

.sparkline.empty {
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.78rem;
}

.up {
  color: var(--green);
}

.down {
  color: var(--red);
}

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

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

th {
  text-align: left;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
  padding: 0.7rem 0.55rem;
}

td {
  border-bottom: 1px solid #eadfcd;
  padding: 0.7rem 0.55rem;
  vertical-align: top;
  font-size: 0.92rem;
}

td small {
  color: var(--muted);
}

.drought-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.drought-item {
  border: 1px solid #dfd2bd;
  background: #f8f1e4;
  border-radius: 0.9rem;
  padding: 0.85rem;
}

.bar {
  height: 10px;
  background: #e6ddcc;
  border-radius: 999px;
  overflow: hidden;
  margin: 0.55rem 0;
}

.bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #d9b65b, #a84f35);
}

.email-card {
  max-width: 820px;
}

.email-card ol {
  margin-bottom: 0;
}

.footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.82rem;
  padding: 0.5rem 0.25rem 1rem;
}

/* ─── Clickable rows, cards, and detail modal ─────────────────────────── */

.clickable-row {
  cursor: pointer;
  transition: background 0.12s ease;
}

.clickable-row:hover,
.clickable-row:focus-visible {
  background: #fbf3df;
  outline: none;
}

.row-hint {
  color: var(--gold);
  font-weight: 600;
  margin-left: 0.35rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  vertical-align: middle;
}

button.commodity-card,
button.history-card,
button.drought-item {
  font: inherit;
  text-align: left;
  width: 100%;
  cursor: pointer;
  color: inherit;
  border-radius: 0.95rem;
}

button.commodity-card.clickable,
button.history-card.clickable,
button.drought-item.clickable {
  background: #f8f1e4;
  border: 1px solid #dfd2bd;
  padding: 0.75rem;
  display: block;
  min-height: 0;
}

button.commodity-card.clickable:hover,
button.commodity-card.clickable:focus-visible,
button.history-card.clickable:hover,
button.history-card.clickable:focus-visible,
button.drought-item.clickable:hover,
button.drought-item.clickable:focus-visible {
  background: #fbf3df;
  border-color: var(--gold);
  outline: none;
}

.card-hint {
  display: block;
  margin-top: 0.4rem;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(33, 31, 25, 0.55);
}

.modal-dialog {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.1rem;
  box-shadow: var(--shadow);
  width: min(960px, calc(100vw - 1.5rem));
  max-width: calc(100vw - 1.5rem);
  max-height: calc(100vh - 1.5rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  padding: 1rem 1.1rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 253, 247, 0.95);
}

.modal-header h2 {
  margin: 0.15rem 0 0;
  font-size: 1.15rem;
}

.modal-close {
  background: transparent;
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  min-height: 36px;
}

.modal-close:hover,
.modal-close:focus-visible {
  background: var(--surface-2);
  color: var(--primary-2);
}

.modal-body {
  padding: 1rem 1.1rem 1.2rem;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
  max-width: 100%;
}

.modal-body .table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.modal-body .detail-table {
  min-width: 0;
  width: 100%;
  table-layout: auto;
}

.modal-body .detail-headline {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.modal-body .detail-stats dd,
.modal-body .detail-stats dt {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.modal-body .sparkline {
  max-width: 100%;
  overflow: hidden;
}

body.modal-open {
  overflow: hidden;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: 1rem;
}

.detail-section {
  border: 1px solid var(--border);
  border-radius: 0.95rem;
  padding: 0.85rem;
  background: #fbf6ec;
  min-width: 0;
}

.detail-section h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.detail-section h4 {
  margin: 0.85rem 0 0.35rem;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

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

.detail-headline {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 0.25rem;
  font-variant-numeric: tabular-nums;
}

.detail-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  margin: 0.75rem 0 0;
}

.detail-stats > div {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  padding: 0.55rem 0.65rem;
}

.detail-stats dt {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.detail-stats dd {
  margin: 0.15rem 0 0;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.detail-table {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.detail-table th,
.detail-table td {
  border-bottom: 1px solid #eadfcd;
  padding: 0.4rem 0.45rem;
  text-align: left;
  font-variant-numeric: tabular-nums;
}

.detail-table th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.range-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.25rem 0 0.65rem;
}

.range-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 700;
  min-height: 32px;
  cursor: pointer;
}

.range-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary-2);
}

.range-btn:hover,
.range-btn:focus-visible {
  background: var(--primary-2);
  color: white;
  outline: none;
}

.sparkline.detail-spark {
  height: 110px;
  background: #f1e6d3;
}

.helper.warn {
  color: var(--red);
}

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

  .sidebar {
    position: static;
    height: auto;
    width: 100%;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  }

  .status-grid,
  .commodity-grid,
  .drought-list,
  .history-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .footer {
    flex-direction: column;
  }

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

@media (max-width: 520px) {
  body {
    background: var(--bg);
  }

  .main {
    padding: 0.85rem;
    gap: 0.75rem;
  }

  .sidebar {
    padding: 0.85rem;
    gap: 0.75rem;
    border-radius: 0 0 1.05rem 1.05rem;
  }

  .brand {
    gap: 0.6rem;
  }

  .brand svg {
    width: 34px;
    height: 34px;
  }

  .brand strong {
    font-size: 0.95rem;
  }

  .brand span {
    font-size: 0.78rem;
  }

  .sidebar nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem;
    overflow-x: hidden;
    width: 100%;
    padding-bottom: 0;
    scrollbar-width: auto;
  }

  .sidebar nav a {
    min-width: 0;
    width: 100%;
    padding: 0.5rem 0.55rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    font-size: 0.88rem;
    line-height: 1.15;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .sidebar-card {
    padding: 0.7rem 0.8rem;
    border-radius: 0.85rem;
  }

  .sidebar-card p {
    display: none;
  }

  .sidebar-card strong {
    font-size: 0.9rem;
  }

  .topbar {
    gap: 0.7rem;
  }

  h1 {
    font-size: 1.28rem;
    line-height: 1.15;
    width: calc(100vw - 1.7rem);
    max-width: calc(100vw - 1.7rem);
  }

  button {
    min-height: 40px;
    padding: 0.58rem 0.85rem;
  }

  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.55rem;
  }

  .metric-card,
  .panel {
    border-radius: 0.9rem;
  }

  .metric-card {
    padding: 0.68rem;
  }

  .metric-card span {
    font-size: 0.7rem;
  }

  .metric-card strong {
    font-size: 1rem;
    line-height: 1.15;
  }

  .panel {
    padding: 0.78rem;
  }

  .section-heading {
    align-items: flex-start;
    gap: 0.55rem;
  }

  .pill {
    padding: 0.28rem 0.48rem;
    font-size: 0.7rem;
  }

  .note-list {
    padding-left: 1rem;
    font-size: 0.9rem;
  }

  .subhead {
    font-size: 0.84rem;
  }

  .commodity-grid {
    gap: 0.55rem;
  }

  .commodity-card {
    border-radius: 0.82rem;
    padding: 0.68rem;
  }

  .commodity-card header {
    gap: 0.45rem;
  }

  .table-wrap {
    margin: 0;
    overflow: visible;
  }

  table {
    min-width: 0;
    table-layout: auto;
    border-collapse: separate;
    border-spacing: 0 0.55rem;
  }

  thead {
    display: none;
  }

  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  tr {
    background: #f8f1e4;
    border: 1px solid #dfd2bd;
    border-radius: 0.82rem;
    padding: 0.65rem;
  }

  td {
    border: 0;
    padding: 0.22rem 0;
    font-size: 0.88rem;
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 0.55rem;
    align-items: baseline;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  td:first-child {
    grid-template-columns: 1fr;
    padding-bottom: 0.35rem;
  }

  td:first-child::before {
    display: none;
  }

  .drought-item {
    padding: 0.7rem;
  }

  .history-block {
    margin-top: 0.8rem;
    padding-top: 0.7rem;
  }

  .history-card,
  .history-row {
    padding: 0.68rem;
  }

  .sparkline {
    height: 52px;
  }

  .email-card ol {
    padding-left: 1.15rem;
  }

  .sidebar-card p,
  .email-card p,
  .note-list li {
    max-width: none;
  }

  .modal-dialog {
    width: calc(100vw - 0.6rem);
    max-height: calc(100vh - 0.6rem);
    border-radius: 0.85rem;
  }

  .modal-header {
    padding: 0.7rem 0.75rem 0.55rem;
  }

  .modal-body {
    padding: 0.75rem 0.75rem 1rem;
  }

  .detail-grid {
    grid-template-columns: 1fr;
    gap: 0.7rem;
  }

  .detail-section {
    padding: 0.7rem;
  }

  .detail-stats {
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
  }

  .detail-table {
    font-size: 0.8rem;
  }

  .detail-table th,
  .detail-table td {
    padding: 0.32rem 0.35rem;
  }

  .sparkline.detail-spark {
    height: 84px;
  }

  .range-btn {
    padding: 0.3rem 0.55rem;
    font-size: 0.74rem;
  }

  /* Keep detail-modal tables as real tables (with horizontal scroll), not the
     block-stacked card layout used for the main page tables on mobile. */
  .modal-body .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .modal-body .detail-table {
    display: table;
    width: max-content;
    min-width: 100%;
    table-layout: auto;
    border-collapse: collapse;
    border-spacing: 0;
  }

  .modal-body .detail-table thead {
    display: table-header-group;
  }

  .modal-body .detail-table tbody {
    display: table-row-group;
  }

  .modal-body .detail-table tr {
    display: table-row;
    background: transparent;
    border: 0;
    border-radius: 0;
    padding: 0;
  }

  .modal-body .detail-table th,
  .modal-body .detail-table td {
    display: table-cell;
    width: auto;
    grid-template-columns: none;
    gap: 0;
    padding: 0.32rem 0.4rem;
    border-bottom: 1px solid #eadfcd;
    white-space: nowrap;
  }

  .modal-body .detail-table td::before,
  .modal-body .detail-table th::before {
    content: none;
    display: none;
  }
}
