/* EP Grain Prices - South Australia */

:root {
  --green-dark: #2d5a27;
  --green-mid: #4a8c3f;
  --green-light: #7ab648;
  --earth-dark: #5c3d1e;
  --earth-mid: #8b6340;
  --earth-light: #c4a265;
  --cream: #f7f3ed;
  --cream-dark: #ede5d8;
  --text-dark: #1a2e1a;
  --text-mid: #3d4f3d;
  --text-light: #6b7c6b;
  --white: #ffffff;
  --border: #c8d8c0;
  --shadow: rgba(45, 90, 39, 0.12);
  --rise: #1a7a2e;
  --fall: #b33000;
  --neutral: #5a6a5a;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Prevent any element from triggering horizontal page scroll */
html, body {
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--cream);
  color: var(--text-dark);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Header ── */
header {
  background: linear-gradient(135deg, var(--green-dark) 0%, var(--green-mid) 60%, var(--green-light) 100%);
  color: var(--white);
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.header-logo {
  font-size: 28px;
  line-height: 1;
  opacity: 0.9;
}

.header-text h1 {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.header-text .subtitle {
  font-size: 0.78rem;
  opacity: 0.82;
  font-weight: 400;
  margin-top: 2px;
}

.header-right {
  margin-left: auto;
  text-align: right;
}

.header-date {
  font-size: 0.82rem;
  opacity: 0.88;
  background: rgba(255,255,255,0.15);
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

/* ── Nav tabs ── */
.nav-tabs {
  background: var(--green-dark);
  border-top: 1px solid rgba(255,255,255,0.1);
}

.nav-tabs-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  gap: 2px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
}

.nav-tabs-inner::-webkit-scrollbar { display: none; } /* Chrome/Safari */

.nav-tab {
  padding: 10px 20px;
  font-size: 0.875rem;
  font-weight: 500;
  color: rgba(255,255,255,0.72);
  cursor: pointer;
  border: none;
  background: transparent;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}

.nav-tab:hover {
  color: var(--white);
  background: rgba(255,255,255,0.08);
}

.nav-tab.active {
  color: var(--white);
  border-bottom-color: var(--earth-light);
}

/* ── Main layout ── */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

.section {
  display: none;
}

.section.active {
  display: block;
}

/* ── Section heading ── */
.section-heading {
  margin-bottom: 20px;
}

.section-heading h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--green-dark);
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-heading p {
  font-size: 0.83rem;
  color: var(--text-light);
  margin-top: 4px;
}

/* ── Filters ── */
.filters {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  box-shadow: 0 1px 4px var(--shadow);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 160px;
  flex: 1;
}

.filter-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-mid);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.filter-group select,
.filter-group input {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 0.875rem;
  color: var(--text-dark);
  background: var(--cream);
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

.filter-group select:focus,
.filter-group input:focus {
  border-color: var(--green-mid);
  box-shadow: 0 0 0 3px rgba(74, 140, 63, 0.15);
}

.btn-reset {
  padding: 7px 18px;
  background: var(--cream-dark);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.875rem;
  color: var(--text-mid);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  align-self: flex-end;
}

.btn-reset:hover {
  background: var(--earth-light);
  color: var(--white);
  border-color: var(--earth-mid);
}

/* ── Price table ── */
.table-wrapper {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: auto;
  box-shadow: 0 1px 4px var(--shadow);
  max-height: calc(100vh - 300px);
  min-height: 300px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

thead tr {
  background: linear-gradient(180deg, var(--green-dark) 0%, var(--green-mid) 100%);
}

th {
  padding: 11px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  color: var(--white);
  white-space: nowrap;
  border-right: 1px solid rgba(255,255,255,0.12);
}

th:last-child {
  border-right: none;
}

th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable:hover {
  background: rgba(255,255,255,0.1);
}

th .sort-indicator {
  margin-left: 4px;
  opacity: 0.6;
  font-size: 0.7rem;
}

th.sort-asc .sort-indicator::after { content: " ▲"; }
th.sort-desc .sort-indicator::after { content: " ▼"; }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

tbody tr:hover {
  background: rgba(74, 140, 63, 0.06);
}

tbody tr:last-child {
  border-bottom: none;
}

.row-even { background: var(--white); }
.row-odd  { background: var(--cream); }

td {
  padding: 9px 14px;
  border-right: 1px solid var(--border);
  color: var(--text-dark);
  white-space: nowrap;
}

td:last-child {
  border-right: none;
}

td.price-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

td.price-na {
  color: var(--text-light);
  text-align: center;
}

.grade-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--cream-dark);
  color: var(--earth-dark);
}

.grade-wheat  { background: #fff3cd; color: #7a5c00; }
.grade-barley { background: #dff0d8; color: #2d5a27; }
.grade-canola { background: #fff0b3; color: #7a6000; }
.grade-lentil { background: #f0e6ff; color: #4a2d7a; }

.change-up   { color: var(--rise);    font-size: 0.78rem; margin-left: 4px; }
.change-down { color: var(--fall);    font-size: 0.78rem; margin-left: 4px; }
.change-flat { color: var(--neutral); font-size: 0.78rem; margin-left: 4px; }

/* ── Stats bar ── */
.stats-bar {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 18px;
  min-width: 140px;
  flex: 1;
  box-shadow: 0 1px 3px var(--shadow);
}

.stat-card .stat-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-card .stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--green-dark);
  margin-top: 2px;
}

.stat-card .stat-sub {
  font-size: 0.72rem;
  color: var(--text-light);
  margin-top: 1px;
}

/* ── Charts section ── */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(440px, 1fr));
  gap: 20px;
}

.chart-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 4px var(--shadow);
}

.chart-card h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--green-dark);
  margin-bottom: 4px;
}

.chart-card .chart-sub {
  font-size: 0.78rem;
  color: var(--text-light);
  margin-bottom: 16px;
}

.chart-container {
  position: relative;
  height: 260px;
  width: 100%;
}

.chart-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 0.9rem;
}

/* ── Row count ── */
.row-count {
  font-size: 0.8rem;
  color: var(--text-light);
  margin-top: 10px;
  text-align: right;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .header-inner {
    padding: 12px 16px;
  }

  .header-text h1 {
    font-size: 1.1rem;
  }

  .nav-tab {
    padding: 8px 14px;
    font-size: 0.82rem;
  }

  main {
    padding: 14px 12px;
  }

  .filters {
    padding: 12px;
    gap: 10px;
  }

  .filter-group {
    min-width: 130px;
  }

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

  .stat-card .stat-value {
    font-size: 1.2rem;
  }

  .table-wrapper {
    max-height: 60vh;
  }
}

@media (max-width: 480px) {
  .header-logo {
    display: none;
  }

  .header-right {
    display: none;
  }

  .stats-bar {
    gap: 10px;
  }

  .stat-card {
    min-width: 100px;
    padding: 10px 12px;
  }
}

/* ── Loading ── */
.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: var(--text-light);
  font-size: 0.9rem;
  gap: 8px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--green-mid);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Market Snapshot card (prices tab) ── */

.market-snapshot {
  background: linear-gradient(135deg, #f0f7ee 0%, #faf7f2 100%);
  border: 1px solid var(--green-light);
  border-left: 4px solid var(--green-mid);
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 20px;
  box-shadow: 0 1px 4px var(--shadow);
}

.market-snapshot.hidden { display: none; }

.snapshot-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.snapshot-icon {
  font-size: 1.4rem;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 2px;
}

.snapshot-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--green-dark);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.snapshot-meta {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-top: 1px;
}

.snapshot-expand-btn {
  margin-left: auto;
  flex-shrink: 0;
  background: var(--green-dark);
  color: var(--white);
  border: none;
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.snapshot-expand-btn:hover { background: var(--green-mid); }

.snapshot-body {
  font-size: 0.88rem;
  color: var(--text-mid);
  line-height: 1.6;
}

/* ── News tab ── */

.news-section-heading {
  font-size: 1rem;
  font-weight: 700;
  color: var(--green-dark);
  margin: 28px 0 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.news-source {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-light);
  background: var(--cream-dark);
  padding: 2px 8px;
  border-radius: 10px;
}

/* ── AI Briefing card ── */

.briefing-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px var(--shadow);
  margin-bottom: 8px;
}

.briefing-header {
  background: linear-gradient(135deg, var(--green-dark) 0%, var(--green-mid) 100%);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.briefing-badge {
  background: rgba(255,255,255,0.2);
  color: var(--white);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.3);
}

.briefing-date {
  font-size: 0.82rem;
  color: rgba(255,255,255,0.75);
  margin-left: auto;
}

.briefing-body {
  padding: 24px;
  line-height: 1.75;
  color: var(--text-dark);
  font-size: 0.925rem;
}

.briefing-body p {
  margin-bottom: 1em;
}

.briefing-body p:last-child {
  margin-bottom: 0;
}

.briefing-footer {
  padding: 12px 24px;
  background: var(--cream);
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--text-light);
}

/* ── News headline grid ── */

.news-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.news-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 1px 3px var(--shadow);
  transition: box-shadow 0.15s, border-color 0.15s, transform 0.1s;
}

.news-card:hover {
  box-shadow: 0 4px 14px var(--shadow);
  border-color: var(--green-light);
  transform: translateY(-2px);
}

.news-card-date {
  font-size: 0.72rem;
  color: var(--text-light);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.news-card-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-dark);
  line-height: 1.35;
}

.news-card-snippet {
  font-size: 0.8rem;
  color: var(--text-mid);
  line-height: 1.5;
  flex: 1;
}

.news-card-link {
  font-size: 0.75rem;
  color: var(--green-mid);
  font-weight: 600;
  margin-top: 4px;
}

@media (max-width: 600px) {
  .news-grid {
    grid-template-columns: 1fr;
  }

  .briefing-body {
    padding: 16px;
    font-size: 0.875rem;
  }

  .snapshot-expand-btn {
    display: none;
  }
}

/* ── Trend chart builder ── */

.trends-controls {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 20px;
  box-shadow: 0 1px 4px var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tc-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tc-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-mid);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tc-site-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.tc-link-btn {
  background: none;
  border: none;
  color: var(--green-mid);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 4px 6px;
  min-height: 36px;
  text-decoration: underline;
  text-underline-offset: 2px;
  touch-action: manipulation;
}

.tc-link-btn:hover { color: var(--green-dark); }

.tc-divider {
  color: var(--border);
  font-size: 0.7rem;
}

/* Site tag picker */
.site-tag-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.site-tag {
  padding: 4px 10px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--cream);
  color: var(--text-mid);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}

.site-tag:hover {
  border-color: var(--green-mid);
  color: var(--green-dark);
}

.site-tag.active {
  background: var(--green-dark);
  border-color: var(--green-dark);
  color: var(--white);
}

/* Type / time pills */
.type-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.type-pill {
  padding: 5px 13px;
  border-radius: 16px;
  border: 1.5px solid var(--border);
  background: var(--cream);
  color: var(--text-mid);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}

.type-pill:hover {
  border-color: var(--green-mid);
  color: var(--green-dark);
}

.type-pill.active {
  background: var(--green-dark);
  border-color: var(--green-dark);
  color: var(--white);
}

/* Bottom row of controls */
.tc-bottom-row {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}

.tc-bottom-row .tc-group {
  flex: 1;
  min-width: 200px;
}

/* Custom date range */
.tc-date-range {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.tc-date-range.hidden { display: none; }

.tc-date-input {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 0.82rem;
  color: var(--text-dark);
  background: var(--cream);
  outline: none;
}

.tc-date-input:focus {
  border-color: var(--green-mid);
  box-shadow: 0 0 0 3px rgba(74,140,63,0.15);
}

/* Add chart button row */
.tc-add-row {
  display: flex;
  justify-content: center;
  margin-top: 4px;
}

.btn-add-chart {
  padding: 9px 24px;
  background: var(--white);
  border: 1.5px dashed var(--green-mid);
  border-radius: 8px;
  color: var(--green-dark);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-add-chart:hover {
  background: var(--green-dark);
  border-style: solid;
  border-color: var(--green-dark);
  color: var(--white);
}

/* Chart builder card */
.chart-builder-card {
  margin-bottom: 16px;
}

.chart-builder-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.chart-builder-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chart-builder-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-mid);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.chart-grade-select {
  border: 1.5px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.85rem;
  color: var(--text-dark);
  background: var(--cream);
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
  min-width: 200px;
}

.chart-grade-select:focus {
  border-color: var(--green-mid);
  box-shadow: 0 0 0 3px rgba(74,140,63,0.15);
}

.chart-title-text {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--green-dark);
  flex: 1;
  text-align: center;
}

.btn-remove-chart {
  margin-left: auto;
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  color: var(--text-light);
  font-size: 0.8rem;
  padding: 5px 10px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-remove-chart:hover {
  background: var(--fall);
  border-color: var(--fall);
  color: var(--white);
}

/* No-data state inside a chart card */
.chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 120px;
  color: var(--text-light);
  font-size: 0.875rem;
  background: var(--cream);
  border-radius: 8px;
  border: 1px dashed var(--border);
}

@media (max-width: 640px) {
  .tc-bottom-row {
    flex-direction: column;
    gap: 14px;
  }

  .tc-bottom-row .tc-group {
    min-width: 0;
    width: 100%;
  }

  .chart-title-text {
    font-size: 0.95rem;
  }

  .chart-grade-select {
    min-width: 0;
    width: 100%;
  }

  .trends-controls {
    padding: 14px;
  }

  /* Date range stacks on mobile */
  .tc-date-range {
    flex-wrap: wrap;
    gap: 6px;
  }

  .tc-date-input {
    flex: 1;
    min-width: 130px;
  }

  /* Link buttons bigger touch targets */
  .tc-link-btn {
    padding: 6px 8px;
    font-size: 0.82rem;
  }

  /* Site tags slightly smaller */
  .site-tag {
    font-size: 0.74rem;
    padding: 4px 8px;
  }

  /* Chart builder header stacks */
  .chart-builder-left {
    flex: 1;
    min-width: 0;
    width: 100%;
  }

  .chart-card-header {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Add chart button full width */
  .add-chart-btn {
    width: 100%;
    justify-content: center;
  }

  /* Type pills wrap tightly */
  .type-pills {
    gap: 4px;
  }

  .type-pill {
    font-size: 0.76rem;
    padding: 4px 10px;
  }
}
