:root {
  --bg: #0f1216; --panel: #171c22; --panel2: #1e252d; --line: #2a323c;
  --ink: #e8edf2; --muted: #8b97a5; --accent: #4ea1ff; --good: #35c07a;
  --best-bg: #12301f; --best-line: #35c07a; --corn: #f4c430; --bean: #6fbf73;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f8; --panel: #fff; --panel2: #f0f3f6; --line: #dde3ea;
    --ink: #16202b; --muted: #5c6773; --accent: #1668d6;
    --best-bg: #e6f7ee; --best-line: #1f9d57;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
header {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
h1 { margin: 0; font-size: 22px; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.controls { display: flex; align-items: center; gap: 8px; }
.status { font-size: 12px; color: var(--muted); cursor: default; }
.status.ok { color: var(--good); }
.status.warn { color: #e0a52a; font-weight: 600; }

/* Commodity tabs */
.tabs { display: flex; gap: 6px; padding: 12px 20px 0; flex-wrap: wrap; max-width: 1100px; }
.tabs .tab { font-size: 14px; padding: 8px 16px; border-radius: 999px; background: var(--panel2); }
.tabs .tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tabs .tab:hover { border-color: var(--accent); }
.tabs .tab-regional { display: inline-flex; align-items: center; gap: 6px; }
.tab-badge { background: var(--good); color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 0 6px; min-width: 18px; text-align: center; }
.tab-regional.active .tab-badge { background: #fff; color: var(--accent); }

/* Regional outlier panel */
.regional-panel { padding: 18px 20px; max-width: 1100px; }
.reg-title { margin: 0 0 4px; font-size: 18px; }
.reg-sub { font-size: 12px; margin: 0 0 16px; max-width: 760px; }
.reg-none { color: var(--good); font-weight: 600; padding: 14px; background: var(--best-bg); border: 1px solid var(--best-line); border-radius: 10px; }
.reg-crop { display: flex; align-items: center; gap: 8px; font-size: 16px; margin: 18px 0 8px; }
.reg-list { display: flex; flex-direction: column; gap: 8px; }
.reg-item { display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.reg-item.reg-big { border-color: var(--best-line); background: var(--best-bg); }
.reg-left { min-width: 0; }
.reg-mkt { font-weight: 600; }
.reg-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.reg-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.reg-cash { font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }
.reg-delta { background: var(--good); color: #fff; font-weight: 700; border-radius: 6px; padding: 2px 9px; font-size: 14px; }
button {
  background: var(--panel2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 12px; font-size: 13px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
main { padding: 18px 20px; display: grid; gap: 22px; max-width: 1100px; }
.commodity h2 { margin: 0 0 10px; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.dot.corn { background: var(--corn); }
.dot.soybeans { background: var(--bean); }
.dot.corn-nongmo { background: var(--corn); box-shadow: 0 0 0 2px var(--good) inset; }
.dot.soybeans-nongmo { background: var(--bean); box-shadow: 0 0 0 2px var(--good) inset; }

.contract {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  margin-bottom: 12px; overflow: hidden;
}
.contract-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 10px 14px; background: var(--panel2); border-bottom: 1px solid var(--line);
}
.contract-head .month { font-weight: 600; }
.contract-head .fut { color: var(--muted); font-size: 13px; }
.contract-head .fut b { color: var(--ink); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: right; padding: 8px 14px; font-variant-numeric: tabular-nums; }
th { color: var(--muted); font-weight: 500; font-size: 12px; border-bottom: 1px solid var(--line); }
td.market, th.market { text-align: left; }
tbody tr { border-bottom: 1px solid var(--line); }
tbody tr:last-child { border-bottom: none; }
tr.monthrow td { background: var(--panel2); padding: 7px 14px; border-top: 2px solid var(--line); }
tr.monthrow .mlabel { font-weight: 600; }
tr.monthrow .mfut { color: var(--muted); font-size: 12px; margin-left: 10px; }
tr.best { background: var(--best-bg); }
tr.best td.cash { color: var(--good); font-weight: 700; }
.tag { font-size: 10px; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); margin-left: 6px; }
.tag.manual { border-color: #b8860b; color: #d1a24a; }
.town { color: var(--muted); font-size: 12px; }
.linkish { color: var(--accent); cursor: pointer; font-size: 12px; background: none; border: none; padding: 0; }

.manual { margin: 0 20px; padding: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.manual h2 { margin: 0 0 6px; font-size: 16px; }
.hint { color: var(--muted); font-size: 12px; margin: 0 0 12px; }
.manual-form label { display: inline-flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 3px; }
select, input {
  background: var(--panel2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 7px; padding: 6px 8px; font-size: 13px;
}
.mrow { display: grid; grid-template-columns: 110px 110px 90px 80px 80px 28px; gap: 8px; margin: 8px 0; align-items: center; }
.mrow .lbl { display: none; }
.manual-actions { margin-top: 12px; display: flex; gap: 10px; align-items: center; }
#manualMsg { color: var(--good); font-size: 13px; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
footer { display: flex; justify-content: space-between; gap: 12px; padding: 14px 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; flex-wrap: wrap; }

.trend { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; }
.trend-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; width: min(560px, 92vw); padding: 16px; }
.trend-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.trend-head button { padding: 2px 9px; }

/* ---- Mobile ---- */
@media (max-width: 560px) {
  body { font-size: 14px; }
  header { padding: 12px 14px; gap: 8px; }
  h1 { font-size: 19px; }
  .sub { font-size: 12px; }
  .controls { gap: 6px; }
  button { padding: 6px 10px; }

  main { padding: 14px 12px; gap: 18px; }
  .tabs { padding: 12px 12px 0; gap: 5px; }
  .tabs .tab { padding: 8px 12px; font-size: 13px; flex: 1 1 auto; text-align: center; }
  .commodity h2 { font-size: 16px; }
  .regional-panel { padding: 14px 12px; }
  .reg-item { padding: 9px 12px; gap: 8px; }
  .reg-meta { font-size: 11px; }
  .reg-cash { font-size: 16px; }

  /* Tighter table so all columns fit; horizontal scroll as a fallback. */
  .contract { overflow-x: auto; }
  th, td { padding: 7px 8px; }
  tr.monthrow td { padding: 6px 8px; }
  tr.monthrow .mfut { display: block; margin-left: 0; }
  .town { font-size: 11px; }
  .linkish { font-size: 11px; }

  /* Manual form: drop the fixed 498px grid and stack into two columns. */
  .manual { margin: 0 12px; padding: 12px; }
  .manual-form label { display: flex; }
  .manual-form label select { width: 100%; }
  .mrow { grid-template-columns: 1fr 1fr; gap: 6px; }
  .mrow select, .mrow input { width: 100%; min-width: 0; }
  .mrow > button { justify-self: start; padding: 6px 12px; }
}
