/* Additions of the PV optimiser on top of the shared UI styles. */

.brand {
  gap: 0.6rem;
}

.brand-logo {
  width: 1.6rem;
  height: 1.6rem;
  flex: none;
}

.login-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.login-logo {
  width: 2.25rem;
  height: 2.25rem;
  flex: none;
}

/* The delete button of a form, apart from the fields above it. */
.form-danger {
  display: flex;
  justify-content: flex-end;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

/* --- dashboard ------------------------------------------------------------------- */

.pv-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
  gap: 0.75rem;
}

.pv-tile {
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.pv-tile-label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.87rem;
  color: var(--text-muted);
}

.pv-tile-value {
  margin: 0.2rem 0;
  font-size: 1.55rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.pv-tile-detail {
  font-size: 0.82rem;
}

/* The colours of the energy flows (chart.js COLORS); the page policy allows no inline style. */
.pv-dot {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  flex: none;
  border-radius: 50%;
  background: var(--text-muted);
}
.pv-dot[data-color="pv"] { background: #e5a50a; }
.pv-dot[data-color="load"] { background: #3584e4; }
.pv-dot[data-color="house"] { background: #1c71d8; }
.pv-dot[data-color="ev"] { background: #2ec27e; }
.pv-dot[data-color="grid"] { background: #c01c28; }
.pv-dot[data-color="battery"] { background: #9141ac; }
.pv-dot[data-color="price"] { background: #c98500; }
.pv-dot[data-color="heater"] { background: #e66100; }

.pv-columns {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(16rem, 1fr);
  gap: 1rem;
  align-items: start;
}

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

.pv-side {
  display: grid;
  gap: 1rem;
}

.panel-head h2 {
  margin: 0;
  font-size: 1rem;
}

/* Label and value side by side; the value starts right of the label, left-aligned. */
.pv-facts {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.35rem 1rem;
  margin: 0;
  align-items: baseline;
}

.pv-facts dt {
  color: var(--text-muted);
}

.pv-facts dd {
  margin: 0;
  text-align: left;
  font-variant-numeric: tabular-nums;
}

.pv-facts-wide {
  grid-template-columns: repeat(2, max-content minmax(0, 1fr));
  column-gap: 1.25rem;
}

@media (min-width: 1500px) {
  .pv-facts-wide {
    grid-template-columns: repeat(3, max-content minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .pv-facts-wide {
    grid-template-columns: max-content minmax(0, 1fr);
  }
}

.pv-hints {
  margin: 0;
  padding-left: 1.2rem;
}

/* --- charts and tables -------------------------------------------------------------- */

.pv-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1rem;
}

.pv-toolbar .choice button {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.pv-nav {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.pv-day {
  margin-left: 0.4rem;
  font-variant-numeric: tabular-nums;
}

.pv-hint {
  margin: 0 0 0.5rem;
  font-size: 0.82rem;
}

.pv-readout {
  min-height: 1.4em;
  margin: 0.25rem 0 0;
  font-size: 0.87rem;
  font-variant-numeric: tabular-nums;
}

.pv-date {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.pv-warn-text {
  color: var(--warn);
}

/* --- appliances (overview) -------------------------------------------------------------- */

.pv-device-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.pv-runs {
  display: grid;
  gap: 0.3rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pv-runs li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.6rem;
  font-variant-numeric: tabular-nums;
}

.pv-run-what {
  overflow-wrap: anywhere;
}

.pv-run-dialog {
  width: min(34rem, calc(100vw - 2rem));
}

/* The time window: "frühestens" and "fertig bis" side by side. */
.pv-run-window {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 0 1rem;
}

.pv-suggestion {
  min-height: 2.6em;
  margin: 0 0 0.75rem;
  font-size: 0.92rem;
}

.pv-suggestion button {
  margin-left: 0.4rem;
  padding: 0.1rem 0.6rem;
  font-size: 0.87rem;
}

/* --- settings ------------------------------------------------------------------------- */

.pv-arrays {
  border-collapse: collapse;
  margin-bottom: 0.5rem;
}

.pv-arrays th {
  padding: 0.25rem 0.5rem 0.25rem 0;
  text-align: left;
  font-size: 0.87rem;
  color: var(--text-muted);
}

.pv-arrays td {
  padding: 0.2rem 0.5rem 0.2rem 0;
}

.pv-arrays input.short {
  width: 6rem;
}

/* The name of an appliance: room for "Spülmaschine Küche" and the like; the time fields
   beside it would otherwise squeeze it to a few characters. */
.pv-devices input[name="name"] {
  width: 16rem;
}

/* As wide as its fields, not the whole panel (tables fill the width by default). */
table.pv-devices {
  width: auto;
}

/* The table of appliances is wider than a form of fields; the text keeps its width, the
   table scrolls only where the window is too narrow. */
.form.pv-devices-form {
  max-width: none;
}

.pv-devices-form p {
  max-width: 34rem;
}

/* --- forecast ---------------------------------------------------------------------------- */

.pv-days {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.pv-days th,
.pv-days td {
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid var(--border);
  text-align: right;
  white-space: nowrap;
}

.pv-days th:first-child,
.pv-days td:first-child {
  text-align: left;
}

.pv-days th {
  font-size: 0.87rem;
  color: var(--text-muted);
}

/* --- span marked in a chart (Shift and drag) ---------------------------------------------- */

.pv-marking .u-select {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  outline: 1px solid var(--accent);
}

.pv-summary {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.pv-summary th,
.pv-summary td {
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid var(--border);
  text-align: right;
  white-space: nowrap;
}

.pv-summary th:first-child,
.pv-summary td:first-child {
  text-align: left;
}

.pv-summary th {
  font-size: 0.87rem;
  color: var(--text-muted);
}

.pv-summary .pv-dot {
  margin-right: 0.45rem;
}

/* Costs: label, amount, and how it came about (may wrap). */
.pv-summary-costs td:last-child {
  text-align: left;
  white-space: normal;
  font-size: 0.87rem;
}

.pv-summary-head {
  margin: 1.1rem 0 0.4rem;
  font-size: 1rem;
}

.pv-summary-notes {
  margin: 0.6rem 0 0;
  font-size: 0.87rem;
}

.pv-hourly {
  margin-top: 0.8rem;
  font-size: 0.87rem;
}

.pv-hourly-grid {
  display: grid;
  grid-template-columns: repeat(4, auto auto);
  gap: 0.2rem 0.8rem;
  margin-top: 0.4rem;
  font-variant-numeric: tabular-nums;
}

/* --- charts below each other or side by side ------------------------------------------ */

/* Two columns, the first chart down the left one and the others beside it; one column again
   where a column would be narrower than 380px (at most two: never narrower than half). */
.pv-chart-grid.side {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, max(380px, calc(50% - 0.75rem))), 1fr));
  align-items: start;
  gap: 0 1.5rem;
}

.pv-chart-grid.side > figure {
  min-width: 0;
}

.pv-chart-grid.side > figure:first-child {
  grid-row: span 2;
}

/* --- chart legend ---------------------------------------------------------------------- */

.pv-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.9rem;
  margin: 0 0 0.2rem;
  padding-left: 64px; /* starts where the plot does, after the left axis */
  font-size: 0.82rem;
}

.pv-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  height: auto;
  min-height: 0;
  padding: 0.1rem 0.3rem;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.pv-legend-item:hover {
  background: var(--border);
}

/* The green and red fills between measured and planned: named, not switched. */
.pv-legend-key {
  cursor: default;
}

.pv-legend-key:hover {
  background: transparent;
}

.pv-legend-item[aria-pressed="false"] {
  opacity: 0.45;
  text-decoration: line-through;
}

/* At the right end of the legend: "Zoom zurücksetzen" (only while the chart is zoomed or
   moved) and the button for double height. */
.pv-legend-tools {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-left: auto;
}

.pv-zoom-reset,
.pv-chart-tool {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  height: auto;
  min-height: 0;
  padding: 0.1rem 0.5rem;
  font-size: inherit;
}

.pv-chart-tool[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.pv-zoom-reset[hidden] {
  display: none;
}

.pv-legend-value {
  min-width: 4.5em;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.pv-swatch {
  width: 1.1rem;
  height: 3px;
  flex: none;
  border-radius: 2px;
  background: var(--swatch);
}

.pv-swatch.area {
  height: 0.7rem;
  border-top: 2px solid var(--swatch);
  border-radius: 0;
  background: color-mix(in srgb, var(--swatch) 30%, transparent);
}

.pv-swatch.dashed {
  background: repeating-linear-gradient(90deg, var(--swatch) 0 4px, transparent 4px 7px);
}

.pv-charge-now {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1rem;
  margin-top: 0.9rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

/* A choice to tick: the box in front, the text beside it and wrapping there. */
.pv-check {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0.6rem 0;
  font-weight: 400;
}

.pv-check input {
  flex: none;
  width: auto;
  min-height: 0;
  margin: 0.2rem 0 0;
}

/* The download button with the expected size beside it. */
.pv-download {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
}

/* A heading inside a panel, for the second and later parts of one tab. */
form + .pv-subhead {
  border-top: 1px solid var(--border);
}

/* "Was bedeuten die Werte?" under the totals of the costs page. */
.pv-explain {
  margin: 0.8rem 0 0.6rem;
  font-size: 0.87rem;
}

.pv-explain > summary {
  cursor: pointer;
  color: var(--accent);
}

.pv-explain .pv-facts {
  margin-top: 0.5rem;
}

/* The plan history on the plan page: a slider over the stored plans. */
.pv-history {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-bottom: 0.3rem;
}

.pv-history input[type="range"] {
  flex: 1;
  min-width: 6rem;
  accent-color: var(--accent);
}

/* One line of fixed height, so that the charts below never move. */
.pv-history-label {
  height: 1.7rem;
  margin: 0 0 0.4rem;
  padding: 0 0.5rem;
  overflow: hidden;
  border-left: 3px solid transparent;
  color: var(--text-muted);
  font-size: 0.87rem;
  line-height: 1.7rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.pv-history-label.old {
  border-left-color: var(--warn);
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  color: var(--text);
}

/* Locks of the sign-in protection (settings, tab "Anmeldeschutz"). */
#login-locks > .panel-head {
  border-top: 1px solid var(--border);
}

.pv-locks {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.pv-locks th,
.pv-locks td {
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.pv-locks td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* The heater tab: heater, meter and what they report now, side by side. */
.form.pv-columns-form {
  max-width: none;
}

.pv-settings-columns {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0 2rem;
  align-items: start;
}

.pv-settings-column > h3 {
  margin: 0 0 0.8rem;
  font-size: 1rem;
}

.pv-settings-column .field input:not(.short) {
  width: 100%;
}

@media (max-width: 1100px) {
  .pv-settings-columns {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pv-settings-columns > #heater-status {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .pv-settings-columns {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* The page "Datenquellen": the sources one below the other, name and state on the left, the
   details on the right, their labels in one column for all of them. */
.pv-source {
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr);
  gap: 0.5rem 1.5rem;
  padding: 0.85rem 0.75rem;
}

.pv-source + .pv-source {
  border-top: 1px solid var(--border);
}

.pv-source-name {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
}

.pv-source-name h2 {
  margin: 0;
  font-size: 1rem;
}

.pv-source .pv-facts {
  grid-template-columns: 9.5rem minmax(0, 1fr);
}

.pv-source dd {
  overflow-wrap: anywhere;
}

@media (max-width: 720px) {
  .pv-source {
    grid-template-columns: minmax(0, 1fr);
  }

  .pv-source .pv-facts {
    grid-template-columns: minmax(0, 1fr);
  }
}
