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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f5f5;
  color: #333;
  line-height: 1.6;
  font-size: 15px;
}

.container {
  max-width: 920px;
  margin: 0 auto;
  padding: 24px 20px;
}

/* Header */
header {
  margin-bottom: 24px;
  text-align: center;
}

header h1 {
  font-size: 1.5rem;
  color: #222;
  font-weight: 600;
}

/* Form */
form {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}

.form-section {
  margin-bottom: 20px;
}

.form-section h2 {
  font-size: 0.85rem;
  color: #555;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #eee;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.hint {
  font-weight: normal;
  color: #aaa;
  font-size: 0.8rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #555;
  margin-bottom: 4px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  color: #333;
  font-family: inherit;
  font-size: 0.9rem;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: #4a90d9;
  box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.15);
}

.form-group input::placeholder {
  color: #bbb;
}

.year-range-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 0.8em;
  color: #888;
}

.year-range-row label {
  white-space: nowrap;
  font-weight: normal;
  margin-bottom: 0;
}

.year-range-row select {
  padding: 2px 6px;
  border: 1px solid #ccc;
  border-radius: 3px;
  background: #fff;
  color: #555;
  font-family: inherit;
  font-size: 0.85em;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #eee;
}

.section-header h2 {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.btn-secondary {
  padding: 6px 14px;
  background: #fff;
  color: #4a90d9;
  border: 1px solid #4a90d9;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.15s;
}

.btn-secondary:hover {
  background: #4a90d9;
  color: #fff;
}

.btn-secondary:disabled {
  border-color: #ccc;
  color: #ccc;
  background: #fff;
  cursor: not-allowed;
}

button[type="submit"] {
  width: 100%;
  padding: 12px;
  background: #4a90d9;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

button[type="submit"]:hover {
  background: #3a7bc8;
}

button[type="submit"]:disabled {
  background: #ccc;
  cursor: not-allowed;
}

/* Loading */
.loading {
  text-align: center;
  padding: 40px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  margin-bottom: 20px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid #e0e0e0;
  border-top-color: #4a90d9;
  border-radius: 50%;
  margin: 0 auto 14px;
  animation: spin 0.8s linear infinite;
}

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

.loading p {
  font-size: 0.95rem;
  color: #555;
}

.loading-hint {
  font-size: 0.85rem !important;
  color: #aaa !important;
  margin-top: 4px;
}

/* Error */
.error {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  color: #b91c1c;
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 20px;
  font-size: 0.9rem;
}

/* Results */
.results {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 20px;
}

.results h2 {
  font-size: 1.1rem;
  color: #222;
  margin-bottom: 16px;
  font-weight: 600;
}

/* Stats Cards */
.stats-cards {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.stat-card {
  background: #f9f9f9;
  padding: 12px;
  text-align: center;
  border: 1px solid #e5e5e5;
  border-radius: 6px;
}

.stat-card .stat-label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #888;
  margin-bottom: 4px;
}

.stat-card .stat-value {
  display: block;
  font-size: 1.15rem;
  font-weight: 700;
  color: #333;
}

.stat-card .stat-unit {
  display: block;
  font-size: 0.7rem;
  color: #888;
}

.stat-min { border-color: #86efac; background: #f0fdf4; }
.stat-min .stat-value { color: #16a34a; }

.stat-max { border-color: #fca5a5; background: #fef2f2; }
.stat-max .stat-value { color: #dc2626; }

.stat-avg { border-color: #93c5fd; background: #eff6ff; }
.stat-avg .stat-value { color: #2563eb; }

.stat-median { border-color: #c4b5fd; background: #f5f3ff; }
.stat-median .stat-value { color: #7c3aed; }

/* Results Actions */
.results-actions {
  margin-bottom: 16px;
}

.btn-link {
  display: inline-block;
  padding: 8px 16px;
  background: #fff;
  color: #4a90d9;
  border: 1px solid #4a90d9;
  border-radius: 4px;
  text-decoration: none;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.15s;
}

.btn-link:hover {
  background: #4a90d9;
  color: #fff;
}

/* Table */
.table-wrapper {
  overflow-x: auto;
}

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

thead th {
  background: #f9f9f9;
  padding: 10px 10px;
  text-align: left;
  font-weight: 600;
  color: #555;
  border-bottom: 2px solid #e5e5e5;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  font-size: 0.8rem;
}

thead th:hover {
  background: #f0f0f0;
  color: #333;
}

thead th.active {
  color: #4a90d9;
}

tbody tr {
  border-bottom: 1px solid #f0f0f0;
}

tbody tr:hover {
  background: #fafafa;
}

tbody td {
  padding: 8px 10px;
  color: #444;
}

.price-cell {
  font-weight: 700;
  color: #222;
  white-space: nowrap;
}

tbody a {
  color: #4a90d9;
  text-decoration: none;
}

tbody a:hover {
  text-decoration: underline;
}

/* Autocomplete */
.autocomplete-wrapper {
  position: relative;
}

.autocomplete-list {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #ccc;
  border-top: none;
  border-radius: 0 0 4px 4px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 1000;
  list-style: none;
  box-shadow: 0 4px 8px rgba(0,0,0,0.08);
}

.autocomplete-list.open {
  display: block;
}

.autocomplete-list li {
  padding: 7px 10px;
  cursor: pointer;
  font-size: 0.9rem;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.autocomplete-list li:hover,
.autocomplete-list li.ac-active {
  background: #f0f6ff;
  color: #1a6fc4;
}

.autocomplete-list .brand-hint {
  color: #aaa;
  font-size: 0.8rem;
}

/* Header subtitle */
.header-sub {
  font-size: 0.85rem;
  color: #777;
  margin-top: 6px;
  font-weight: 400;
}

/* Footer */
.site-footer {
  margin-top: 32px;
  border-top: 1px solid #e5e5e5;
  padding-top: 20px;
  padding-bottom: 24px;
}

.footer-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.footer-desc {
  font-size: 0.8rem;
  color: #888;
  line-height: 1.6;
  max-width: 720px;
}

.footer-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  font-size: 0.78rem;
  color: #aaa;
}

.footer-tags span {
  color: #bbb;
  font-weight: 600;
  margin-right: 2px;
}

.footer-tags a {
  color: #aaa;
  text-decoration: none;
  background: #f5f5f5;
  border: 1px solid #e8e8e8;
  border-radius: 3px;
  padding: 2px 8px;
  transition: color 0.15s;
}

.footer-tags a:hover {
  color: #4a90d9;
  border-color: #c0d8f0;
  background: #f0f6ff;
}

.footer-copy {
  font-size: 0.75rem;
  color: #bbb;
}

/* Utility */
.hidden {
  display: none !important;
}

/* Responsive */
@media (max-width: 768px) {
  .stats-cards {
    grid-template-columns: repeat(2, 1fr);
  }

  .stats-cards .stat-card:first-child {
    grid-column: 1 / -1;
  }

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

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

  header h1 {
    font-size: 1.2rem;
  }

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