:root {
  color-scheme: light;
  --ink: #18202a;
  --muted: #66717d;
  --line: #dce3ea;
  --paper: #f6f7f2;
  --panel: #ffffff;
  --green: #246b45;
  --blue: #235d8f;
  --red: #a43d3d;
  --amber: #9a6b1d;
  --shadow: 0 18px 50px rgba(33, 42, 52, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid #111820;
  border-radius: 6px;
  background: linear-gradient(180deg, #26313d, var(--ink));
  color: white;
  cursor: pointer;
  font-weight: 700;
  padding: 0.66rem 0.95rem;
  box-shadow: 0 3px 0 #0c1117, 0 8px 18px rgba(22, 32, 42, 0.16);
}

button:hover {
  filter: brightness(1.05);
}

button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #0c1117, 0 4px 10px rgba(22, 32, 42, 0.14);
}

button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.5);
  opacity: 0.48;
  transform: none;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  align-items: end;
  padding: 1.5rem clamp(1rem, 3vw, 2.5rem);
  border-bottom: 1px solid var(--line);
  background: #fffdf8;
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.7rem, 3vw, 2.7rem);
}

h2 {
  font-size: 1.05rem;
}

.period-controls,
form {
  display: flex;
  gap: 0.8rem;
  align-items: end;
  flex-wrap: wrap;
}

.linked-tool-button {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  align-self: end;
  border: 1px solid #164d7a;
  border-radius: 6px;
  padding: 0 0.95rem;
  background: linear-gradient(180deg, #1f659c, #143d60);
  color: #fff;
  font-weight: 800;
  text-decoration: none;
  box-shadow: 0 3px 0 #0b2439, 0 8px 18px rgba(22, 32, 42, 0.16);
}

label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.field-hint {
  max-width: 230px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.25;
  text-transform: none;
}

.confirm-store-button {
  align-self: end;
  border-color: #9eb7ce;
  background: linear-gradient(180deg, #ffffff, #e9f2f9);
  color: var(--blue);
  box-shadow: 0 2px 0 #c3d3df;
}

.confirm-store-button.confirmed {
  border-color: #1f6a43;
  background: linear-gradient(180deg, #2f8658, #246b45);
  color: white;
  box-shadow: 0 2px 0 #174b2f;
}

select,
input[type="search"] {
  min-width: 210px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  padding: 0.7rem 0.75rem;
  text-transform: none;
  box-shadow: inset 0 1px 2px rgba(22, 32, 42, 0.07);
}

.layout {
  display: grid;
  gap: 1rem;
  padding: clamp(1rem, 3vw, 2.5rem);
}

.upload-panel,
.report-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.upload-panel {
  padding: 1rem;
}

.export-panel {
  padding: 0.85rem 1rem 1rem;
}

.export-controls {
  display: flex;
  gap: 0.75rem;
  align-items: end;
  flex-wrap: wrap;
}

.export-controls select {
  min-width: 170px;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid var(--line);
}

.panel-heading span,
.panel-heading input {
  color: var(--muted);
}

.brand-tools {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.category-tools {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.upload-panel .panel-heading {
  padding: 0 0 1rem;
  border-bottom: 0;
}

.drop-zone {
  min-width: min(520px, 100%);
  border: 1px solid #8ea5b7;
  border-radius: 8px;
  padding: 0.9rem 1rem;
  background: linear-gradient(180deg, #ffffff, #edf5fb);
  color: var(--ink);
  text-transform: none;
  cursor: pointer;
  box-shadow: 0 3px 0 #c9d7e2, 0 10px 20px rgba(35, 93, 143, 0.10);
}

.drop-zone.dragging {
  border-color: var(--blue);
  background: #eef6ff;
}

.drop-zone input {
  display: block;
  max-width: 100%;
  margin-bottom: 0.45rem;
}

.drop-zone span {
  color: var(--muted);
  font-weight: 600;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.8rem;
}

.metric-card {
  min-height: 78px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 0.8rem 0.9rem;
  display: grid;
  align-content: space-between;
}

.metric-card span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-card strong {
  font-size: 1.32rem;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(320px, 0.8fr);
  gap: 1rem;
}

.content-grid.compact-comparison {
  grid-template-columns: 1fr;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2) {
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
}

.total-row td {
  background: #f3f7f4;
  font-weight: 800;
}

.brand-table td:first-child {
  min-width: 280px;
}

.brand-copy {
  display: grid;
  gap: 0.12rem;
  min-width: 0;
}

.brand-name-cell {
  display: flex;
  gap: 0.58rem;
  align-items: center;
  min-width: 0;
}

.brand-name-cell.compact {
  gap: 0.44rem;
}

.brand-logo {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  padding: 4px;
}

.brand-logo-fallback {
  display: grid;
  place-items: center;
  color: #15436b;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1;
}

.brand-table td:first-child .source-brands {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  margin-top: 0.12rem;
  white-space: normal;
}

.cost-note {
  display: flex;
  gap: 0.45rem;
  align-items: baseline;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.15;
  white-space: normal;
}

.cost-delta {
  font-weight: 900;
}

.brand-section-row td {
  background: #eef3f1;
  color: #26313d;
  font-size: 0.78rem;
  font-weight: 900;
  text-align: left !important;
  text-transform: uppercase;
}

.section-unit-delta {
  display: block;
  margin-top: 0.12rem;
  font-size: 0.7rem;
  font-weight: 900;
  text-transform: none;
}

.section-total-row td {
  background: #fbfcfd;
  border-bottom: 2px solid #cbd6df;
  border-top: 1px solid #b9c7d1;
  font-weight: 900;
}

.section-total-row td:first-child {
  color: #26313d;
}

.section-total-row .cost-note {
  margin-top: 0.16rem;
}

.compare-brand-row td {
  padding-top: 0.42rem;
  padding-bottom: 0.42rem;
  vertical-align: middle;
}

.compare-brand-row .brand-logo {
  width: 30px;
  height: 30px;
  flex-basis: 30px;
  padding: 3px;
}

.compare-brand-row .brand-copy strong {
  font-size: 0.9rem;
}

.compare-brand-row .source-brands {
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unit-delta-cell {
  width: 92px;
  min-width: 92px;
  text-align: center !important;
}

.unit-delta {
  display: inline-block;
  min-width: 72px;
  border: 1px solid #d4dde5;
  border-radius: 999px;
  background: #f8fafb;
  padding: 0.28rem 0.4rem;
  font-size: 0.76rem;
  font-weight: 900;
  line-height: 1;
}

.unit-delta.positive {
  border-color: #a8c8b5;
  background: #e9f6ee;
}

.unit-delta.negative {
  border-color: #d9b1b1;
  background: #faeeee;
}

.unit-delta.neutral {
  color: var(--muted);
}

.year-box-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 0.34rem;
  min-width: 520px;
}

.category-compare-grid {
  display: grid;
  gap: 0.38rem;
  min-width: 520px;
}

.category-compare-grid.count-2 {
  grid-template-columns: repeat(2, minmax(180px, 1fr));
}

.category-compare-grid.count-3 {
  grid-template-columns: repeat(3, minmax(150px, 1fr));
}

.year-metric-box {
  border: 1px solid #cbd6df;
  border-radius: 6px;
  padding: 0.34rem 0.42rem;
  text-align: left;
}

.year-metric-box.year-0 {
  background: #eef6ff;
  border-color: #a9c7df;
}

.year-metric-box.year-1 {
  background: #f0f7ed;
  border-color: #b6d1b3;
}

.year-metric-box.year-2 {
  background: #fff4df;
  border-color: #e2c58d;
}

.year-metric-box strong {
  display: block;
  margin-bottom: 0.2rem;
  font-size: 0.78rem;
}

.year-metric-box dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.22rem 0.34rem;
  margin: 0;
}

.year-metric-box div {
  display: grid;
  gap: 0.02rem;
  min-width: 0;
}

.year-metric-box dt,
.year-metric-box dd {
  font-size: 0.68rem;
  line-height: 1.05;
}

.year-metric-box dt {
  color: var(--muted);
  font-weight: 800;
}

.year-metric-box dd {
  margin: 0;
  font-weight: 900;
}

.year-metric-box em {
  display: inline-block;
  margin-left: 0.18rem;
  font-size: 0.61rem;
  font-style: normal;
  font-weight: 900;
}

.missing-year {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.category-pill,
.locked-rule {
  border-radius: 999px;
  display: inline-block;
  font-size: 0.76rem;
  font-weight: 800;
  padding: 0.25rem 0.55rem;
}

.category-pill.state {
  background: #e7f4ec;
  color: var(--green);
}

.category-pill.affordable {
  background: #fff3d7;
  color: var(--amber);
}

.category-pill.standard {
  background: #e9f1f8;
  color: var(--blue);
}

.locked-rule {
  background: #e7f4ec;
  color: var(--green);
}

.text-button {
  border: 1px solid #9eb7ce;
  border-radius: 5px;
  background: linear-gradient(180deg, #ffffff, #e9f2f9);
  color: var(--blue);
  padding: 0.34rem 0.5rem;
  box-shadow: 0 2px 0 #c3d3df;
  font-size: 0.74rem;
  line-height: 1;
  white-space: nowrap;
}

.text-button.danger {
  border-color: #d8b2b2;
  background: linear-gradient(180deg, #fffefe, #f8eaea);
  color: var(--red);
  box-shadow: 0 2px 0 #e3c4c4;
}

.text-button.remove-brand-action {
  border-color: #9f1f1f;
  background: linear-gradient(180deg, #dc3434, #b82020);
  color: #fff;
  box-shadow: 0 2px 0 #7f1818;
}

.rule-actions {
  display: flex;
  gap: 0.32rem;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  min-width: 230px;
}

.comparison-list,
.saved-store-list {
  display: grid;
  gap: 0.5rem;
  padding: 0.78rem;
}

.comparison-controls {
  display: flex;
  gap: 0.35rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.toggle-button {
  border: 1px solid #b8c8d6;
  border-radius: 6px;
  background: linear-gradient(180deg, #ffffff, #eef4f8);
  color: var(--blue);
  padding: 0.38rem 0.56rem;
  box-shadow: 0 2px 0 #cfdae3;
  font-size: 0.74rem;
  line-height: 1;
}

.toggle-button.active {
  border-color: #18202a;
  background: linear-gradient(180deg, #26313d, #18202a);
  color: white;
  box-shadow: 0 2px 0 #0c1117;
}

.comparison-card,
.saved-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #f2f6f8);
  color: var(--ink);
  padding: 0.56rem 0.64rem;
  text-align: left;
  box-shadow: 0 3px 0 #d5dde4, 0 8px 16px rgba(33, 42, 52, 0.10);
}

.comparison-card strong {
  font-size: 0.92rem;
}

.saved-card {
  border-color: #b8c8d6;
  cursor: pointer;
}

.saved-card:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #d5dde4, 0 4px 10px rgba(33, 42, 52, 0.08);
}

.comparison-card.featured {
  border-color: #9db8cc;
}

.comparison-card dl {
  display: grid;
  gap: 0.24rem;
  margin: 0.48rem 0 0;
}

.comparison-card.mini {
  padding: 0.48rem 0.58rem;
  background: linear-gradient(180deg, #ffffff, #f7f9fa);
}

.comparison-card.mini strong {
  font-size: 0.86rem;
}

.comparison-card.mini dl {
  gap: 0.2rem;
  margin-top: 0.36rem;
}

.comparison-table {
  margin-top: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.comparison-table th,
.comparison-table td {
  padding: 0.48rem 0.55rem;
}

.comparison-card div {
  display: flex;
  justify-content: space-between;
  gap: 0.7rem;
}

dt {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

dd {
  margin: 0;
  font-size: 0.96rem;
  font-weight: 800;
}

.positive {
  color: var(--green);
}

.negative {
  color: var(--red);
}

.saved-store-list {
  gap: 0.72rem;
}

.saved-store-group {
  overflow: hidden;
  border: 1px solid #c3d0db;
  border-radius: 10px;
  background: #f7fafc;
  box-shadow: 0 3px 0 #d5dde4, 0 8px 18px rgba(33, 42, 52, 0.08);
}

.saved-store-group.active-store {
  border-color: #8eaec7;
}

.saved-store-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.72rem 0.86rem;
  cursor: pointer;
  list-style: none;
  background: linear-gradient(180deg, #ffffff, #eef4f8);
  color: var(--ink);
}

.saved-store-group summary::-webkit-details-marker {
  display: none;
}

.saved-store-group summary::after {
  content: "›";
  flex: 0 0 auto;
  color: var(--blue);
  font-size: 1.5rem;
  font-weight: 900;
  line-height: 1;
  transform: rotate(0deg);
  transition: transform 120ms ease;
}

.saved-store-group[open] summary::after {
  transform: rotate(90deg);
}

.saved-store-title {
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
  min-width: 0;
}

.saved-store-title strong {
  font-size: 1rem;
}

.saved-store-title small,
.saved-store-range {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.saved-store-range {
  margin-left: auto;
  text-align: right;
}

.saved-month-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.5rem;
  padding: 0.72rem;
  border-top: 1px solid #d7e0e7;
  background: #f8fafb;
}

.saved-card {
  display: grid;
  gap: 0.4rem;
  align-content: space-between;
  min-height: 76px;
}

.saved-card.active {
  outline: 3px solid rgba(35, 93, 143, 0.18);
  border-color: var(--blue);
}

.saved-card small {
  color: var(--muted);
}

.saved-card-metrics {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.saved-card-metrics small:last-child {
  white-space: nowrap;
}

.empty-state,
.empty-cell {
  color: var(--muted);
  padding: 1rem;
}

@media (max-width: 900px) {
  .app-header,
  .content-grid {
    grid-template-columns: 1fr;
    display: grid;
    align-items: stretch;
  }

  .summary-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  select,
  input[type="search"] {
    min-width: 100%;
  }
}

@media (max-width: 560px) {
  .summary-strip {
    grid-template-columns: 1fr;
  }

  th,
  td {
    padding: 0.7rem;
  }

  .saved-store-group summary {
    align-items: flex-start;
  }

  .saved-store-title {
    display: grid;
    gap: 0.18rem;
  }

  .saved-store-range {
    display: none;
  }

  .saved-month-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .saved-card-metrics {
    display: grid;
    gap: 0.12rem;
  }
}

@media (max-width: 400px) {
  .saved-month-grid {
    grid-template-columns: 1fr;
  }
}
