/* Scoped styles for the electricity bill comparison page. */

.ebill-section {
  padding-top: 8px;
}

.page-electricity-bill .page-kicker a {
  color: inherit;
  text-decoration: none;
}

.page-electricity-bill .page-kicker a:hover {
  text-decoration: underline;
}

.ebill {
  display: grid;
  gap: 0;
  color: var(--color-text);
  --ebill-fuel: #d97706;
  --ebill-base: #1d4e9e;
  /* Chart geometry; the media queries below adjust these for phones. */
  --plot-h: 320px;
  --gutter: 36px;
  --col-gap: 8px;
  --bar-w: 30px;
  --lbl-gap: 6px;
  --lbl-w: 66px;
  --seg-font: 12px;
  /* How far the bar sits left of its column's centre, to leave room for its right-hand labels.
     The bar and the x-label (month and change) both shift by this, so they share one centre. */
  --bar-off: calc((var(--lbl-gap) + var(--lbl-w)) / 2);
}

.ebill > * + * {
  margin-top: 20px;
}

html[data-theme="dark"] .ebill {
  --ebill-fuel: #c47d1a;
  --ebill-base: #5f8be0;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ebill {
    --ebill-fuel: #c47d1a;
    --ebill-base: #5f8be0;
  }
}

/* One panel: the usage cell first, then one card per bill month, then the add card. Phones get
   two columns with the usage cell across the top; tablets fit cards by width; desktop puts the
   usage cell and five cards on one row. */
.ebill-inputs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px;
  align-items: stretch;
  margin: 0;
  min-width: 0;
  padding: 12px 18px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.ebill-inputs .ebill-usage {
  grid-column: 1 / -1;
}

@media (min-width: 560px) {
  .ebill-inputs {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .ebill-inputs .ebill-usage {
    grid-column: span 2;
  }
}

@media (min-width: 1100px) {
  .ebill-inputs {
    grid-template-columns: minmax(170px, 1.1fr) repeat(5, minmax(0, 1fr));
  }

  .ebill-inputs .ebill-usage {
    grid-column: auto;
  }
}

.ebill-panel-help {
  grid-column: 1 / -1;
  margin: 0 0 4px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--color-text-muted);
}

/* The kWh cell: visibly different from the bill-date cards. */
.ebill-usage {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  padding: 12px 14px;
  background: var(--color-brand-soft);
  border: 2px solid var(--color-brand);
  border-radius: var(--radius-sm);
}

.ebill-kwh-label {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text);
}

.ebill-kwh-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}

.ebill-kwh-row input {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  padding: 10px 8px;
  font: 700 20px/1.2 var(--font);
  font-variant-numeric: tabular-nums;
  color: var(--color-text);
  background: var(--color-canvas);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
}

.ebill-kwh-row span {
  font-weight: 600;
  color: var(--color-text-muted);
}

.ebill-help {
  margin: 8px 0 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--color-text-muted);
}

.ebill-add,
.ebill-copy,
.ebill-remove {
  font: inherit;
  cursor: pointer;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
}

/* Bill months: one compact card per picked month in a responsive grid. */
/* Its cards are cells of the panel grid, so the usage cell and the cards share one row. */
#ebill-periods {
  display: contents;
}

.ebill-period {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 8px 10px;
  font-size: 13px;
  background: var(--color-canvas);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.ebill-period.is-ref {
  border-color: var(--color-brand);
}

.ebill-period-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ebill-period-num {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  font-size: 13px;
  font-weight: 700;
  color: var(--color-brand);
  background: var(--color-brand-soft);
  border-radius: 50%;
}

.ebill-period-pick {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.ebill-period-pick select {
  width: 100%;
  min-width: 0;
  padding: 5px 8px;
  font: inherit;
  font-size: 13px;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
}

.ebill-ref-pick {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.ebill-remove {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.ebill-remove:disabled {
  cursor: default;
  opacity: 0.55;
}

/* Add button: the last cell of the bill-month grid, sized like a card. */
.ebill-add {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 8px 10px;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  color: var(--color-text);
  background: transparent;
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

/* The currency note sits 8px below the input boxes. Grid items do not collapse margins, so the
   whole gap to the chart is: 8px, the note line (16px), and the 4px above the chart card. */
.ebill-currency-note {
  margin: 8px 0 0;
  line-height: 16px;
  font-size: 13px;
  color: var(--color-text-muted);
}

.ebill-currency-note + .ebill-chart-card {
  margin-top: 4px;
}

/* Chart card (main view). */
.ebill-chart-card {
  position: relative;
  min-width: 0;
  padding: 18px 20px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.ebill-chart-title {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 700;
}

.ebill-legend:empty {
  display: none;
}

.ebill-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--color-text-muted);
}

.ebill-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.ebill-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
}

.ebill-swatch-fuel {
  background: var(--ebill-fuel);
}

.ebill-swatch-base {
  background: var(--ebill-base);
}

/* The chart: a left gutter holds the "$0" label, one shared $0 line runs across the plots,
   and each column's bar sits in a group (bar + value label) centred in the column. */
.ebill-chart {
  position: relative;
  display: flex;
  gap: var(--col-gap);
  padding-left: var(--gutter);
}

/* Empty state: no chart yet, so the message is centred across the whole card. */
.ebill-chart.is-empty {
  padding-left: 0;
}

.ebill-empty {
  flex: 1 1 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--plot-h);
  margin: 0;
  padding: 0 12px;
  font-size: 15px;
  line-height: 1.5;
  text-align: center;
  color: var(--color-text-muted);
}

.ebill-zero {
  position: absolute;
  z-index: 1;
  left: var(--gutter);
  right: 0;
  top: calc(var(--plot-h) * (1 - var(--zero, 0) / 100));
  height: 0;
  border-top: 1px solid var(--color-border-strong);
  pointer-events: none;
}

.ebill-zero span {
  position: absolute;
  right: 100%;
  top: 0;
  margin-right: 6px;
  transform: translateY(-50%);
  font-size: 11px;
  line-height: 1;
  color: var(--color-text-muted);
}

.ebill-col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-radius: 6px;
  outline: none;
}

.ebill-col:focus-visible {
  box-shadow: var(--ring);
}

.ebill-plot {
  position: relative;
  height: var(--plot-h);
}

.ebill-bar {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(50% - var(--bar-off) - var(--bar-w) / 2);
  width: var(--bar-w);
}

.ebill-seg {
  position: absolute;
  left: 0;
  right: 0;
  box-sizing: border-box;
}

.ebill-seg-fuel {
  background: var(--ebill-fuel);
}

.ebill-seg-base {
  background: var(--ebill-base);
  border-radius: 4px 4px 0 0;
}

.ebill-seg-below {
  border-radius: 0 0 4px 4px;
}

.ebill-seglabel {
  position: absolute;
  left: calc(100% + var(--lbl-gap));
  transform: translateY(50%);
  white-space: nowrap;
  font-size: var(--seg-font);
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--color-text);
}

.ebill-value {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  color: var(--color-text);
}

/* The label box is as wide as its column, shifted by the same offset as the bar, so its centre
   is the bar's centre. Text is centred in it and can only wrap at the space in the change text. */
.ebill-col-label {
  position: relative;
  left: calc(-1 * var(--bar-off));
  padding-top: 8px;
  text-align: center;
  font-size: 12px;
  line-height: 1.4;
  color: var(--color-text-muted);
}

.ebill-col-month {
  display: block;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
}

.ebill-col-delta {
  display: block;
}

.ebill-col .ebill-tag {
  margin-left: 0;
  padding: 1px 6px;
  font-size: 10px;
}

.ebill-tip {
  position: absolute;
  z-index: 2;
  max-width: 240px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  pointer-events: none;
}

.ebill-tip[hidden] {
  display: none;
}

.ebill-tip strong {
  display: block;
  margin-bottom: 2px;
}

.ebill-tip span {
  display: block;
}

/* Full breakdown, collapsed by default. */
.ebill-details > summary {
  display: inline-block;
  list-style: none;
  cursor: pointer;
  padding: 10px 14px;
  font-weight: 600;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
}

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

.ebill-details > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 8px;
}

.ebill-details[open] > summary::before {
  content: "▾";
}

.ebill-details[open] > summary {
  margin-bottom: 12px;
}

.ebill-details > summary:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

/* Comparison table (wide screens). */
.ebill-table-wrap {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.ebill-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.ebill-table caption {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
}

.ebill-table th,
.ebill-table td {
  padding: 10px 14px;
  vertical-align: top;
  border-bottom: 1px solid var(--color-border);
}

.ebill-table thead th {
  font-size: 13px;
  text-align: right;
  background: var(--color-canvas-subtle);
}

.ebill-table thead th:first-child,
.ebill-table tbody th {
  text-align: left;
}

.ebill-table td {
  text-align: right;
}

.ebill-table tbody th {
  font-weight: 600;
}

.ebill-table small,
.ebill-card small {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 400;
  color: var(--color-text-muted);
}

.ebill-table tr:last-child th,
.ebill-table tr:last-child td {
  border-bottom: 0;
}

.ebill-row-fuel th,
.ebill-row-fuel td,
.ebill-card .ebill-row-fuel {
  background: color-mix(in srgb, var(--color-warning) 10%, var(--color-surface));
}

.ebill-row-total th,
.ebill-row-total td {
  font-size: 16px;
  border-top: 2px solid var(--color-border-strong);
}

.ebill-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--color-brand);
  background: var(--color-brand-soft);
  border-radius: var(--radius-pill);
}

.ebill-change {
  font-weight: 600;
}

.ebill-change-higher {
  color: var(--color-negative);
}

.ebill-change-lower {
  color: var(--color-positive);
}

.ebill-change-same {
  color: var(--color-text-muted);
}

/* Cards (phones). */
.ebill-cards {
  display: none;
  gap: 12px;
}

.ebill-card {
  padding: 14px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.ebill-card.is-ref {
  border-color: var(--color-brand);
}

.ebill-card h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.ebill-card dl {
  margin: 0;
}

.ebill-card dl > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 8px;
  margin: 0 -8px;
  border-top: 1px solid var(--color-border);
  font-size: 14px;
}

.ebill-card dt {
  font-weight: 600;
}

.ebill-card dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.ebill-card .ebill-row-total {
  font-size: 16px;
}

.ebill-share {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}

.ebill-copy {
  padding: 8px 14px;
  font-weight: 600;
  font-size: 14px;
}

.ebill-add:focus-visible,
.ebill-copy:focus-visible,
.ebill-remove:focus-visible,
.ebill-period select:focus-visible,
.ebill-kwh-row input:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.ebill-note {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--color-text-muted);
}

.ebill-explain {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
  margin-top: 32px;
  line-height: 1.6;
}

.ebill-explain h2 {
  font-size: 20px;
  margin: 0 0 8px;
}

.ebill-explain ul {
  padding-left: 20px;
}

.ebill-explain li + li {
  margin-top: 6px;
}

@media (max-width: 900px) {
  .ebill-explain {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  .ebill {
    --plot-h: 240px;
  }

  .ebill-chart-card {
    padding: 14px;
  }

  .ebill-col .ebill-tag {
    padding: 1px 5px;
  }

  .ebill-table-wrap {
    display: none;
  }

  .ebill-cards {
    display: grid;
  }
}

/* Phones: five columns of about 65px. The "$0" label moves into the card padding. */
@media (max-width: 560px) {
  .ebill {
    --gutter: 0px;
    --col-gap: 0px;
    --bar-w: 18px;
    --lbl-gap: 2px;
    --lbl-w: 46px;
    --seg-font: 10px;
  }

  /* The card gives the "$0" label room on the left; the right padding shrinks to match. */
  .ebill-chart-card {
    padding: 14px 8px 14px 22px;
  }

  .ebill-zero span {
    margin-right: 2px;
  }

  .ebill-value {
    font-size: 13px;
    left: calc((var(--bar-w) + var(--lbl-gap) + var(--lbl-w)) / 2);
  }
}

/* Phones (under 560px): compact panel, three-column date cards, and bars set near the left of
   each column so the value labels fit to their right. Desktop rules above are unchanged. */
@media (max-width: 559px) {
  .ebill {
    --plot-h: 220px;
    --bar-w: 10px;
    --bar-left: 6px;
    --lbl-gap: 4px;
    --seg-font: 10px;
  }

  .ebill-inputs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px 8px;
    padding: 8px;
  }

  .ebill-panel-help {
    margin: 0 0 4px;
    font-size: 12px;
    line-height: 1.4;
  }

  /* The kWh cell: one row, label on the left, input and unit on the right. */
  .ebill-usage {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 12px;
  }

  .ebill-kwh-label {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 13px;
  }

  .ebill-kwh-row {
    flex: 0 0 auto;
    margin-top: 0;
  }

  .ebill-kwh-row input {
    flex: 0 0 110px;
    width: 110px;
    padding: 6px 8px;
    font-size: 18px;
  }

  .ebill-period {
    padding: 6px 8px;
    font-size: 12px;
  }

  .ebill-period-pick select {
    box-sizing: border-box;
    height: 32px;
    min-height: 0;
    padding: 4px 6px;
    font-size: 12px;
  }

  .ebill-ref-pick {
    gap: 4px;
    font-size: 11px;
    white-space: nowrap;
  }

  .ebill-ref-pick input {
    flex: 0 0 auto;
    width: 12px;
    height: 12px;
    margin: 0;
  }

  .ebill-add {
    padding: 6px 8px;
    font-size: 12px;
  }

  /* Bars sit 6px in from the left of each column (10px wide so 10px value labels clear the next bar); the x-label stays centred on its bar. */
  .ebill-bar {
    left: var(--bar-left);
  }

  .ebill-col-label {
    left: calc(var(--bar-left) + var(--bar-w) / 2 - 50%);
  }

  .ebill-value {
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    font-weight: 700;
  }
}
