/* ==============================
   Variables & Reset
   ============================== */
:root {
  --navy: #0d1b2a;
  --navy-light: #1b2d3e;
  --ice: #4fc3f7;
  --ice-dark: #0288d1;
  --white: #ffffff;
  --off-white: #f4f6f8;
  --text: #1a1a2e;
  --text-muted: #6b7a8d;
  --border: #d1d9e0;
  --row-alt: #eef3f7;
  --row-hover: #ddeeff;
  --red: #e53935;
}

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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--off-white);
  line-height: 1.5;
}

/* ==============================
   Header
   ============================== */
header {
  background: var(--navy);
  color: var(--white);
  padding: 20px 32px;
  border-bottom: 3px solid var(--ice);
}

header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

header p {
  color: #a0b4c8;
  font-size: 0.9rem;
  margin-top: 4px;
}

/* ==============================
   Layout
   ============================== */
.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 0;
  min-height: calc(100vh - 80px);
}

/* ==============================
   Sidebar Filters
   ============================== */
.filters {
  background: var(--navy-light);
  color: var(--white);
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.filters h2 {
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--ice);
  margin-bottom: 20px;
}

.filter-group {
  margin-bottom: 20px;
}

.filter-group label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #a0b4c8;
  margin-bottom: 6px;
}

.filter-group select,
.filter-group input[type="number"] {
  width: 100%;
  padding: 8px 10px;
  border-radius: 5px;
  border: 1px solid #334d65;
  background: #243447;
  color: var(--white);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.filter-group select:focus,
.filter-group input[type="number"]:focus {
  border-color: var(--ice);
}

.year-range {
  display: flex;
  align-items: center;
  gap: 8px;
}

.year-range input {
  width: calc(50% - 12px);
}

.year-range span {
  color: #a0b4c8;
  font-size: 0.8rem;
}

.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  color: var(--white);
  cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--ice);
  cursor: pointer;
}

#reset-btn {
  width: 100%;
  margin-top: 8px;
  padding: 9px;
  background: transparent;
  color: var(--ice);
  border: 1px solid var(--ice);
  border-radius: 5px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

#reset-btn:hover {
  background: var(--ice);
  color: var(--navy);
}

/* ==============================
   Main Content
   ============================== */
main {
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* ==============================
   Chart Section
   ============================== */
.chart-section h2,
.table-section h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 12px;
}

.chart-container {
  background: var(--white);
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 20px;
  height: 260px;
  position: relative;
}

/* ==============================
   Table Section
   ============================== */
.table-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.row-count {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.error-banner {
  background: #fff0f0;
  border: 1px solid var(--red);
  color: var(--red);
  border-radius: 6px;
  padding: 12px 16px;
  margin-bottom: 12px;
  font-size: 0.85rem;
}

.table-wrapper {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--white);
}

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

thead {
  background: var(--navy);
  color: var(--white);
}

th {
  padding: 11px 14px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  user-select: none;
}

th:not(.no-sort) {
  cursor: pointer;
}

th:not(.no-sort):hover {
  background: var(--navy-light);
}

.sort-arrow {
  display: inline-block;
  width: 12px;
  font-size: 0.7rem;
  color: var(--ice);
  margin-left: 4px;
}

td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tbody tr:nth-child(even) {
  background: var(--row-alt);
}

tbody tr:hover {
  background: var(--row-hover);
}

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

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

/* Lower-tier models: truncate with tooltip */
.lower-tier {
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-muted);
  cursor: default;
}

/* Compare checkbox column */
td.compare-cell,
th.no-sort:last-child {
  text-align: center;
  width: 70px;
}

td.compare-cell input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--ice-dark);
  cursor: pointer;
}

/* ==============================
   Compare Panel
   ============================== */
.compare-panel {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}

.compare-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.compare-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 0;
}

#clear-compare-btn {
  padding: 6px 14px;
  background: transparent;
  color: var(--red);
  border: 1px solid var(--red);
  border-radius: 5px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

#clear-compare-btn:hover {
  background: var(--red);
  color: var(--white);
}

.compare-cards {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.compare-card {
  flex: 1;
  min-width: 180px;
  background: var(--off-white);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

.compare-card h3 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 10px;
  border-bottom: 2px solid var(--ice);
  padding-bottom: 6px;
}

.compare-card .field {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 0.82rem;
  border-bottom: 1px solid var(--border);
}

.compare-card .field:last-child {
  border-bottom: none;
}

.compare-card .field-label {
  color: var(--text-muted);
  font-weight: 600;
}

.compare-card .field-value {
  color: var(--text);
  text-align: right;
}

/* ==============================
   Footer
   ============================== */
footer {
  background: var(--navy);
  color: #6b8099;
  text-align: center;
  padding: 16px 32px;
  font-size: 0.78rem;
}

/* ==============================
   Responsive
   ============================== */
@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .filters {
    position: static;
    height: auto;
  }

  main {
    padding: 16px;
  }

  .compare-cards {
    flex-direction: column;
  }
}
