:root {
  --bg: #f2efe7;
  --surface: #fffdf8;
  --ink: #122620;
  --muted: #51635d;
  --accent: #2f6f4f;
  --accent-soft: #d6e8dc;
  --border: #d6d1c5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", serif;
  background: radial-gradient(circle at 10% 10%, #fff6d8, transparent 50%),
    radial-gradient(circle at 90% 0%, #dceee4, transparent 45%),
    var(--bg);
  color: var(--ink);
}

main {
  max-width: 980px;
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3rem);
}

p {
  color: var(--muted);
}

.label-with-help {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.help-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--accent-soft);
  color: var(--ink);
  font-size: 0.75rem;
  cursor: help;
}

.controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.8rem;
  margin: 1.25rem 0;
}

.controls > div {
  min-width: 0;
}

.control-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.control-field > label {
  font-weight: 600;
  color: #1a2f29;
}

.control-field > input,
.control-field > select {
  width: 100%;
}

input,
select,
button {
  font: inherit;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.search-shell {
  position: relative;
}

#suggestions {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  right: 0;
  z-index: 5;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.suggestion {
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 0;
  border-bottom: 1px solid var(--border);
}

.suggestion:last-child {
  border-bottom: 0;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-bottom: 0;
}

.plots-panel {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  margin-bottom: 1rem;
  overflow: hidden;
}

.plots-panel > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.72rem 0.85rem;
  font-weight: 700;
  color: var(--ink);
  background: linear-gradient(180deg, #fbf8f1 0%, #f3ede2 100%);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.plots-panel > summary::-webkit-details-marker {
  display: none;
}

.plots-panel > summary::before {
  content: "▸";
  color: var(--accent);
  font-size: 0.85rem;
  transition: transform 140ms ease;
}

.plots-panel[open] > summary::before {
  transform: rotate(90deg);
}

.plots-panel > summary:hover {
  background: #efe8da;
}

.plots-panel > summary:focus-visible {
  outline: 3px solid #8ec3a7;
  outline-offset: -2px;
}

.plots-panel[open] > summary {
  border-bottom: 1px solid var(--border);
}

.plots-panel-content {
  padding: 0.75rem;
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem;
}

.summary-card h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.summary-total {
  margin: 0.6rem 0 0;
  font-size: 0.88rem;
  font-weight: 600;
}

.monthly-chart {
  display: flex;
  align-items: flex-end;
  gap: 0.35rem;
  min-height: 120px;
  padding-top: 0.5rem;
}

.monthly-bar {
  flex: 1;
  min-width: 12px;
  background: linear-gradient(180deg, #86ba9d 0%, #2f6f4f 100%);
  border-radius: 4px 4px 0 0;
  position: relative;
}

.monthly-bar span {
  position: absolute;
  top: -1.3rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  color: var(--muted);
  white-space: nowrap;
}

.summary-table,
.results-table {
  width: 100%;
  border-collapse: collapse;
}

.summary-table th,
.summary-table td,
.results-table th,
.results-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.45rem 0.35rem;
  text-align: left;
  vertical-align: top;
}

.results-table th:nth-child(1),
.results-table td:nth-child(1),
.results-table th:nth-child(2),
.results-table td:nth-child(2),
.results-table th:nth-child(3),
.results-table td:nth-child(3) {
  white-space: nowrap;
}

.summary-table th,
.results-table th {
  font-size: 0.82rem;
  color: var(--muted);
  background: #f6f1e8;
}

.th-sort {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.sort-controls {
  display: inline-flex;
  flex-direction: column;
  gap: 0.1rem;
}

.sort-arrow {
  padding: 0;
  width: 1rem;
  height: 0.8rem;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: #76847f;
  line-height: 0.8rem;
  cursor: pointer;
}

.sort-arrow:hover {
  color: var(--ink);
  background: #e8e2d6;
}

.sort-arrow.active {
  color: #1f4f39;
  background: #d3e4da;
}

.results-table-shell {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: auto;
  background: var(--surface);
}

.results-table td {
  font-size: 0.92rem;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
}

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

.hidden {
  display: none;
}

#status {
  min-height: 1.2rem;
}

#status.status-loading {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

#status.status-loading::before {
  content: "";
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 999px;
  border: 2px solid #b7c4be;
  border-top-color: #2f6f4f;
  animation: status-spin 0.8s linear infinite;
}

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

a {
  color: var(--accent);
}

@media (min-width: 760px) {
  .controls {
    grid-template-columns:
      minmax(240px, 1.25fr)
      minmax(180px, 1fr)
      minmax(180px, 1fr)
      minmax(220px, 1.15fr);
    align-items: end;
  }

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

@media (max-width: 759px) {
  .results-table th,
  .results-table td {
    font-size: 0.86rem;
    padding: 0.4rem 0.3rem;
  }

  .results-table th:nth-child(3),
  .results-table td:nth-child(3),
  .results-table th:nth-child(5),
  .results-table td:nth-child(5),
  .results-table th:nth-child(6),
  .results-table td:nth-child(6),
  .results-table th:nth-child(7),
  .results-table td:nth-child(7) {
    display: none;
  }
}
