:root {
  color-scheme: light;
  --bg: #f4f7f5;
  --surface: #ffffff;
  --surface-2: #eef4ef;
  --ink: #17211b;
  --muted: #68776f;
  --line: #d8e2dc;
  --line-strong: #b7c8bf;
  --sow: #2f9461;
  --sow-dark: #1d7046;
  --harvest: #d88a25;
  --harvest-dark: #9e5f10;
  --water: #25859d;
  --berry: #8c4c8f;
  --danger: #be4d42;
  --shadow: 0 18px 50px rgba(21, 36, 27, 0.16);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(47, 148, 97, 0.08), transparent 320px),
    var(--bg);
  color: var(--ink);
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    "Noto Sans CJK SC",
    system-ui,
    sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 22px clamp(14px, 3vw, 34px) 32px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  align-items: end;
  max-width: 1520px;
  margin: 0 auto 18px;
}

.brand {
  min-width: 0;
}

.kicker {
  margin: 0 0 6px;
  color: var(--water);
  font-size: 13px;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: clamp(30px, 5vw, 56px);
  line-height: 1.05;
  letter-spacing: 0;
}

.summary {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.summary div {
  min-width: 92px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.84);
}

.summary strong {
  display: block;
  font-size: 25px;
  line-height: 1;
}

.summary span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.controls {
  display: grid;
  grid-template-columns: minmax(240px, 360px) minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  max-width: 1520px;
  margin: 0 auto 14px;
}

.search {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.search span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
}

.search input::placeholder {
  color: #8a9690;
}

.category-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.tab {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.tab[aria-selected="true"] {
  border-color: #8cbca2;
  background: #dfefe5;
  color: #185437;
  font-weight: 700;
}

.workspace {
  max-width: 1520px;
  margin: 0 auto;
}

.timeline-section {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}

.timeline-meta {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(37, 133, 157, 0.08), rgba(216, 138, 37, 0.08)),
    #fbfdfb;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.legend span {
  display: inline-flex;
  gap: 7px;
  align-items: center;
}

.legend i {
  width: 30px;
  height: 10px;
  border-radius: 999px;
}

.legend-sow {
  background: var(--sow);
}

.legend-harvest {
  background: var(--harvest);
}

.source {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.chart-scroll {
  overflow: auto;
  max-height: calc(100vh - 220px);
  min-height: 420px;
  scrollbar-color: #a7b9ae #edf4ef;
  scrollbar-width: thin;
}

.chart-grid {
  --label-width: 174px;
  display: grid;
  grid-template-columns: var(--label-width) repeat(12, minmax(68px, 1fr));
  min-width: 1020px;
  opacity: 1;
  transform: translateY(0);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.chart-grid.is-fading {
  opacity: 0;
  transform: translateY(6px);
}

.corner,
.month-head {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  min-height: 42px;
  border-bottom: 1px solid var(--line-strong);
  background: #f9fbfa;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.corner {
  left: 0;
  z-index: 7;
  padding: 0 14px;
  border-right: 1px solid var(--line-strong);
}

.month-head {
  justify-content: center;
  border-right: 1px solid var(--line);
}

.crop-label {
  position: sticky;
  left: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 4px;
  min-width: 0;
  min-height: 56px;
  padding: 8px 12px 8px 14px;
  border: 0;
  border-right: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  animation: rowEnter 260ms ease both;
  animation-delay: min(calc(var(--row, 0) * 12ms), 160ms);
}

.crop-label:hover,
.crop-label:focus-visible {
  background: #f0f7f2;
  outline: 0;
}

.crop-label strong,
.crop-label span {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crop-label strong {
  font-size: 14px;
  line-height: 1.15;
}

.crop-label span {
  color: var(--muted);
  font-size: 11px;
}

.track {
  position: relative;
  min-height: 56px;
  grid-column: span 12;
  border-bottom: 1px solid var(--line);
  background:
    repeating-linear-gradient(
      to right,
      transparent 0,
      transparent calc(8.333333% - 1px),
      rgba(104, 119, 111, 0.2) calc(8.333333% - 1px),
      rgba(104, 119, 111, 0.2) 8.333333%
    ),
    repeating-linear-gradient(
      to right,
      transparent 0,
      transparent calc(2.777777% - 1px),
      rgba(104, 119, 111, 0.08) calc(2.777777% - 1px),
      rgba(104, 119, 111, 0.08) 2.777777%
    ),
    linear-gradient(90deg, rgba(47, 148, 97, 0.04), rgba(216, 138, 37, 0.04));
  animation: rowEnter 260ms ease both;
  animation-delay: min(calc(var(--row, 0) * 12ms), 160ms);
}

.track:hover {
  background:
    repeating-linear-gradient(
      to right,
      transparent 0,
      transparent calc(8.333333% - 1px),
      rgba(104, 119, 111, 0.24) calc(8.333333% - 1px),
      rgba(104, 119, 111, 0.24) 8.333333%
    ),
    repeating-linear-gradient(
      to right,
      transparent 0,
      transparent calc(2.777777% - 1px),
      rgba(104, 119, 111, 0.1) calc(2.777777% - 1px),
      rgba(104, 119, 111, 0.1) 2.777777%
    ),
    #fbfdfb;
}

.segment {
  position: absolute;
  left: calc(var(--left) * 1%);
  top: var(--top);
  width: max(calc(var(--width) * 1%), 34px);
  height: 18px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 18px;
  text-align: left;
  cursor: pointer;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.16);
}

.segment span {
  display: block;
  overflow: hidden;
  padding: 0 8px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.segment:focus-visible {
  outline: 2px solid #123623;
  outline-offset: 2px;
}

.segment.sow {
  --top: 9px;
  background: linear-gradient(90deg, var(--sow), var(--sow-dark));
}

.segment.harvest {
  --top: 31px;
  background: linear-gradient(90deg, var(--harvest), var(--harvest-dark));
}

.empty-state {
  grid-column: 1 / -1;
  min-height: 260px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
  animation: rowEnter 220ms ease both;
}

@keyframes rowEnter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.shade {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(17, 28, 22, 0.32);
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 30;
  width: min(440px, 92vw);
  height: 100vh;
  transform: translateX(105%);
  border-left: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: transform 180ms ease;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-close {
  position: absolute;
  top: 13px;
  right: 13px;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #f8fbf9;
  color: var(--ink);
  font-size: 25px;
  line-height: 1;
  cursor: pointer;
}

.drawer-close:hover,
.drawer-close:focus-visible {
  border-color: #9bb9a9;
  background: #e9f4ee;
  outline: 0;
}

.drawer-content {
  height: 100%;
  overflow-y: auto;
  padding: 30px 24px 28px;
}

.drawer-kicker {
  margin: 0 0 7px;
  color: var(--water);
  font-size: 13px;
  font-weight: 800;
}

.drawer h2 {
  margin: 0 42px 8px 0;
  font-size: 30px;
  line-height: 1.15;
  letter-spacing: 0;
}

.drawer-source {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 12px;
}

.detail-grid {
  display: grid;
  gap: 10px;
}

.detail-item {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.detail-item dt {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.detail-item dd {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.7;
}

.month-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 4px;
}

.month-pills span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.month-pills .sow-pill {
  background: #dff0e7;
  color: #195b39;
}

.month-pills .harvest-pill {
  background: #f7e6ce;
  color: #7a440a;
}

@media (max-width: 860px) {
  .app-shell {
    padding: 16px 10px 24px;
  }

  .topbar,
  .controls {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: start;
  }

  .summary {
    width: 100%;
  }

  .summary div {
    flex: 1 1 0;
  }

  .timeline-meta {
    align-items: flex-start;
    flex-direction: column;
  }

  .source {
    text-align: left;
  }

  .chart-scroll {
    max-height: calc(100vh - 310px);
  }

  .chart-grid {
    --label-width: 136px;
    grid-template-columns: var(--label-width) repeat(12, 62px);
  }

  .crop-label {
    padding-left: 10px;
  }

  .drawer {
    top: auto;
    bottom: 0;
    width: 100vw;
    height: min(78vh, 660px);
    transform: translateY(105%);
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .drawer.open {
    transform: translateY(0);
  }
}

@media (max-width: 520px) {
  h1 {
    font-size: 32px;
  }

  .search {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .tab {
    min-height: 38px;
    padding: 0 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chart-grid,
  .crop-label,
  .track,
  .empty-state,
  .drawer {
    animation: none;
    transition: none;
  }
}
