:root {
  color-scheme: light;
  --background: #f5f7fb;
  --surface: #ffffff;
  --surface-muted: #eef2f7;
  --text: #1f2937;
  --muted: #667085;
  --border: #d7dee8;
  --accent: #0b7285;
  --accent-strong: #075d6c;
  --success: #15803d;
  --warning: #b45309;
  --danger: #b42318;
  --shadow: 0 16px 40px rgba(31, 41, 55, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--background);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

main {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

.page-header {
  margin-bottom: 24px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(2rem, 5vw, 3.5rem);
  line-height: 1.05;
}

.page-header p {
  max-width: 720px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.app-grid {
  display: grid;
  grid-template-columns: minmax(0, 420px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.app-grid > * {
  min-width: 0;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.form-panel {
  padding: 20px;
}

.form-section + .form-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.form-section h2 {
  margin-bottom: 14px;
  font-size: 1rem;
}

.compact-section {
  padding-top: 0;
}

.section-heading {
  display: grid;
  gap: 12px;
}

.plant-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.plant-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdff;
}

.plant-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 114, 133, 0.12);
}

.plant-select-button {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 0;
  border: 0;
  padding: 0;
  color: var(--text);
  text-align: left;
  background: transparent;
}

.plant-select-button strong {
  font-size: 1rem;
}

.plant-select-button span,
.empty-message {
  color: var(--muted);
  font-size: 0.9rem;
}

.plant-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.plant-card-actions button {
  min-height: 36px;
  padding: 7px 10px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.plant-system-grid {
  margin-top: 14px;
}

input[readonly] {
  color: var(--muted);
  background: var(--surface-muted);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.weather-field {
  margin-top: 14px;
}

.weather-details-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.number-stepper {
  position: relative;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  gap: 6px;
}

.number-stepper input {
  appearance: textfield;
  padding-right: 34px;
  text-align: center;
}

.number-stepper input::-webkit-inner-spin-button,
.number-stepper input::-webkit-outer-spin-button {
  margin: 0;
  appearance: none;
}

.number-stepper .unit {
  right: 54px;
  bottom: 9px;
}

.stepper-button {
  min-width: 42px;
  padding: 6px;
  border-color: var(--border);
  color: var(--text);
  background: var(--surface-muted);
}

.field-help {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.4;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--text);
  font: inherit;
  background: #ffffff;
}

input:focus,
select:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(11, 114, 133, 0.14);
}

.input-with-unit {
  position: relative;
}

.input-with-unit input {
  padding-right: 38px;
}

.unit {
  position: absolute;
  right: 10px;
  bottom: 9px;
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 9px 14px;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

button.primary {
  color: #ffffff;
  background: var(--accent);
}

button.primary:hover {
  background: var(--accent-strong);
}

button.secondary {
  border-color: var(--border);
  color: var(--text);
  background: var(--surface-muted);
}

button.secondary:hover {
  background: #e2e8f0;
}

button.danger {
  border-color: #fecaca;
  color: var(--danger);
  background: #fff5f5;
}

button.danger:hover {
  background: #fee2e2;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.icon-button {
  min-width: 40px;
  padding: 8px;
  border-color: var(--border);
  color: var(--muted);
  background: var(--surface-muted);
}

.plant-dialog {
  width: min(760px, calc(100% - 24px));
  max-height: min(860px, calc(100vh - 24px));
  max-height: min(860px, calc(100dvh - 24px));
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.plant-dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.plant-dialog form {
  display: grid;
  max-height: inherit;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-padding-bottom: calc(90px + env(safe-area-inset-bottom, 0px));
  padding: 20px;
  -webkit-overflow-scrolling: touch;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.dialog-header h2 {
  margin-bottom: 4px;
}

.dialog-header p {
  margin-bottom: 0;
  color: var(--muted);
}

.dialog-actions {
  position: sticky;
  z-index: 2;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 20px -20px -20px;
  padding: 16px 20px calc(16px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 -10px 18px rgba(31, 41, 55, 0.08);
}

.save-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-top: 14px;
}

.panel-set-list {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.panel-set {
  min-width: 0;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  background: #fbfdff;
}

.panel-set legend {
  padding: 0 6px;
  color: var(--text);
  font-weight: 800;
}

.remove-panel-set-button {
  margin-top: 12px;
}

.status {
  min-height: 22px;
  margin-top: 14px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.status.error {
  color: var(--danger);
}

.results-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.hero-result {
  padding: 24px;
}

.result-kicker {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.angle-value {
  margin-bottom: 8px;
  font-size: clamp(3rem, 12vw, 6rem);
  font-weight: 800;
  line-height: 1;
}

.output-value {
  margin-bottom: 18px;
  color: var(--success);
  font-size: 1.35rem;
  font-weight: 800;
}

.meter {
  height: 16px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-muted);
}

.meter-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #f59e0b, #16a34a);
  transition: width 180ms ease;
}

.result-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.result-item,
.timing-item {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.result-item h3,
.timing-item h3 {
  margin: 0 0 2px;
  font-size: 1rem;
}

.result-item p,
.timing-item p {
  margin: 0;
  color: var(--muted);
}

.result-numbers {
  display: grid;
  gap: 2px;
  justify-items: end;
  text-align: right;
  white-space: nowrap;
}

.result-numbers strong {
  font-size: 1.1rem;
}

.result-numbers span {
  color: var(--muted);
  font-size: 0.9rem;
}

.alignment-result-numbers {
  flex: 0 1 460px;
  min-width: 0;
  white-space: normal;
}

.power-breakdown {
  display: grid;
  grid-template-columns: repeat(3, max-content);
  justify-content: end;
  gap: 18px;
  margin-top: 8px;
}

.power-breakdown > div {
  display: grid;
  gap: 1px;
}

.power-breakdown span {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.power-breakdown strong {
  font-size: 0.9rem;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.detail-card,
.timing-card {
  padding: 16px;
}

.detail-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.detail-value {
  font-size: 1.35rem;
  font-weight: 800;
}

.chart-card,
.production-card {
  padding: 16px;
}

.chart-card h2 {
  margin-bottom: 6px;
  font-size: 1.05rem;
}

.chart-card p {
  margin-bottom: 12px;
  color: var(--muted);
}

.chart-wrap {
  position: relative;
  height: 360px;
  min-width: 0;
}

.short-chart-wrap {
  height: 280px;
}

.yearly-total {
  margin: 0 0 12px;
  font-size: 1.3rem;
  font-weight: 800;
}

.production-clipping-summary {
  margin: -6px 0 12px !important;
  color: var(--muted);
  font-size: 0.9rem;
}

.production-clipping-summary:empty {
  display: none;
}

.production-card p {
  margin-bottom: 0;
  color: var(--muted);
}

.daily-energy-breakdown {
  display: grid;
  gap: 4px;
  margin: 4px 0 10px;
}

.daily-energy-breakdown:empty {
  display: none;
}

.daily-energy-breakdown div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  max-width: 420px;
  color: var(--muted);
}

.daily-energy-breakdown strong {
  color: var(--text);
}

.daily-sunlight-list {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.daily-sunlight-item {
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.daily-sunlight-item h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.daily-plant-maximum {
  border-top: 0;
  border-radius: 10px;
  padding: 14px;
  background: var(--surface-muted);
}

.daily-plant-maximum-total {
  margin-bottom: 12px !important;
}

.daily-plant-maximum-total strong {
  color: var(--text);
  font-size: 1.15rem;
}

.daily-sunlight-details {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

/* Pair peak values above sunlight entry and exit for each panel set. */
.daily-sunlight-details.daily-panel-timing-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.daily-sunlight-detail {
  display: grid;
  gap: 3px;
}

.daily-sunlight-detail span {
  color: var(--muted);
  font-size: 0.82rem;
}

.daily-sunlight-detail strong {
  font-size: 1.05rem;
}

.timing-card h2 {
  margin-bottom: 10px;
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1.2;
}

.timing-item h3 {
  font-size: 0.95rem;
  font-weight: 650;
}

.timing-card p {
  margin-bottom: 8px;
  color: var(--muted);
}

.timing-list {
  display: grid;
  gap: 10px;
  margin: 12px 0 0;
  padding: 0;
}

.yearly-best-item {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.yearly-best-item h3 {
  margin: 0 0 10px;
  font-size: 0.95rem;
  font-weight: 650;
}

.yearly-best-details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.warning {
  color: var(--warning);
}

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

@media (max-width: 580px) {
  main {
    width: min(100% - 20px, 1120px);
    padding-top: 20px;
  }

  .field-grid,
  .weather-details-grid,
  .details-grid,
  .daily-sunlight-details,
  .yearly-best-details {
    grid-template-columns: 1fr;
  }

  .save-row,
  .result-item,
  .timing-item {
    display: grid;
    gap: 8px;
  }

  .plant-dialog {
    width: calc(100% - 16px);
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
  }

  .dialog-actions button {
    flex: 1;
    min-height: 48px;
  }

  .result-numbers {
    justify-items: start;
    text-align: left;
    white-space: normal;
  }

  .alignment-result-numbers {
    width: 100%;
  }

  .power-breakdown {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    justify-content: stretch;
    width: 100%;
    gap: 10px;
  }

  .chart-wrap {
    height: 300px;
  }
}

/* Dashboard hierarchy: setup first, then one focused results view. */
[hidden] { display: none !important; }
.app-grid { grid-template-columns: minmax(0, 1fr); }
h1 { max-width: 900px; font-size: clamp(1.8rem, 4vw, 2.7rem); line-height: 1.15; }
.form-panel { padding: 24px; }
.step-number { display: inline-grid; place-items: center; width: 25px; height: 25px; margin-right: 6px; border-radius: 50%; background: var(--surface-muted); color: var(--accent); font-size: .8rem; }
.plant-toolbar { display: flex; gap: 10px; align-items: end; }
.plant-selector-label { flex: 1; }
.context-summary { margin: 10px 0; color: var(--muted); font-size: .86rem; overflow-wrap: anywhere; }
.scenario-controls { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 28px; margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--border); }
.scenario-controls .form-section { margin: 0; padding: 0; border: 0; }
.scenario-controls .weather-field { margin-top: 0; }
summary { cursor: pointer; color: var(--accent-strong); font-weight: 650; padding: 8px 0; }
summary:focus-visible, button:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.results-heading h2 { margin: 8px 0 0; font-size: 1.3rem; }
.result-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.result-tabs button { border-radius: 6px 6px 0 0; color: var(--muted); background: transparent; border-bottom: 3px solid transparent; }
.result-tabs button[aria-selected="true"] { color: var(--accent-strong); border-bottom-color: var(--accent); background: #e5f2f4; }
.result-view { display: grid; grid-template-columns: minmax(0, 1fr); min-width: 0; gap: 16px; }
.result-view > *, .summary-grid > * { min-width: 0; }
.summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.summary-grid .panel { padding: 20px; }
.summary-grid .angle-value { font-size: clamp(1.8rem, 3.6vw, 2.8rem); line-height: 1.15; margin: 12px 0; }
.summary-grid .result-kicker { font-size: .72rem; letter-spacing: .04em; }
.summary-grid .output-value, .summary-grid p:not(.result-kicker) { color: var(--muted); font-size: .85rem; font-weight: 400; }
.summary-grid .meter { height: 6px; }
.chart-switch { display: flex; gap: 8px; flex-wrap: wrap; }
button[aria-pressed="true"] { background: #e5f2f4; border-color: var(--accent); color: var(--accent-strong); }
.disclosure { padding: 10px 18px; }
.disclosure > summary { padding: 8px 0; }
.disclosure h3 { font-size: .95rem; margin-top: 18px; }
.disclosure .details-grid { margin: 12px 0; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.clipping-notice { margin: 0; padding: 12px 16px; border-radius: 8px; background: #fff3dc; color: #874b08; }
.editor-section-title { margin-top: 24px; }
.inverter-settings { margin-top: 20px; }
.panel-set summary { color: var(--text); }
.panel-set details[open] > summary { margin-bottom: 12px; }
.dialog-actions #delete-plant-button { margin-right: auto; }
@media (max-width: 700px) {
  .scenario-controls { grid-template-columns: 1fr; gap: 20px; }
  .scenario-controls .date-controls { padding-top: 20px; border-top: 1px solid var(--border); }
  .summary-grid { grid-template-columns: 1fr; gap: 10px; }
  .summary-grid .panel { padding: 16px; }
  .summary-grid .angle-value { font-size: 2.2rem; }
  .plant-toolbar { flex-wrap: wrap; }
  .plant-selector-label { flex-basis: 100%; }
  .form-panel { padding: 18px; }
  .result-tabs button { flex: 1; padding: 10px 6px; font-size: .85rem; }
  .disclosure .details-grid { grid-template-columns: 1fr; }
  .dialog-actions { flex-wrap: wrap; }
  .dialog-actions #delete-plant-button { flex: 0 0 100%; }
}

/* Long-term solar data (Global Solar Atlas) in the plant editor */
.form-hint {
  margin: 10px 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.solar-atlas-steps {
  padding-left: 20px;
}

.solar-atlas-steps li + li {
  margin-top: 4px;
}

.solar-atlas-grid .input-with-unit input,
.solar-atlas-monthly-grid .input-with-unit input {
  padding-right: 70px;
}

.solar-atlas-monthly-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.solar-atlas-monthly {
  margin-top: 12px;
}

/* Source, loading and download error message in the long-term data editor. */
#solar-data-source:empty {
  display: none;
}

#solar-data-source.error {
  color: var(--danger);
}

.solar-data-source {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.solar-data-source:empty {
  display: none;
}

@media (max-width: 580px) {
  .solar-atlas-monthly-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Plant editor location picker: address search, map and coordinates. */
.location-section > label,
.location-section > .place-search,
.location-section > .location-coordinates {
  margin-top: 12px;
}

.place-search {
  position: relative;
}

.place-search > label {
  display: block;
}

/* Suggestions float over the map, above Leaflet's panes and controls. */
.place-suggestions {
  position: absolute;
  top: 70px;
  right: 0;
  left: 0;
  z-index: 1100;
  max-height: 280px;
  margin: 0;
  padding: 4px 0;
  overflow-y: auto;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.place-suggestions li {
  display: grid;
  padding: 8px 12px;
  cursor: pointer;
}

.place-suggestions li:hover,
.place-suggestions li[aria-selected="true"] {
  background: var(--surface-muted);
}

.place-suggestion-label {
  font-weight: 600;
}

.place-suggestion-detail {
  color: var(--muted);
  font-size: 0.86rem;
}

.location-message:empty {
  display: none;
}

.location-message.error {
  color: var(--danger);
}

.location-map {
  height: 340px;
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
  /* Crosshair shows that a click places the plant. */
  cursor: crosshair;
}

.location-map .leaflet-marker-icon {
  cursor: grab;
}

.location-map-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  margin-top: 10px;
}

.location-map-actions .form-hint {
  margin: 0;
}

.location-coordinates summary {
  cursor: pointer;
  color: var(--accent-strong);
  font-weight: 600;
}

.location-coordinates summary span {
  margin-left: 6px;
  color: var(--muted);
  font-weight: 400;
}

.location-coordinates .field-grid {
  margin-top: 10px;
}

@media (max-width: 580px) {
  .location-map {
    height: 280px;
  }
}

/* Satellite tiles are clipping boxes (see createFallbackTileLayer); a one
   pixel overlap hides hairline seams between neighbouring tiles. */
.location-map .fallback-tile {
  width: 257px !important;
  height: 257px !important;
}

/* Choice shown when precise long-term data is for a point more than 1 km away. */
.solar-data-choice {
  margin: 8px 0;
  padding: 10px 12px;
  border: 1px solid var(--warning);
  border-radius: 6px;
  background: var(--surface-muted);
}

.solar-data-choice .form-hint {
  margin: 0 0 8px;
  color: var(--text);
}

/* Where the long-term data comes from, under the section heading (visible
   even when the section is collapsed). */
.section-data-source {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 400;
}

.section-data-source:empty {
  display: none;
}

/* Tip about Global Solar Atlas: a tinted box with an info icon, clearly help
   rather than a heading of the data. With atlas data it shrinks to one line. */
.atlas-tip {
  margin: 14px 0 6px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: var(--surface-muted);
  color: var(--text);
}

.atlas-tip-text {
  margin: 0;
}

.atlas-tip .help-icon {
  margin-right: 4px;
  color: var(--accent);
  vertical-align: -2px;
}

.atlas-tip .solar-atlas-steps {
  margin: 8px 0 0;
  font-size: 0.9rem;
}

.atlas-tip.is-compact {
  padding: 6px 12px;
  font-size: 0.86rem;
}

.help-icon {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  font-size: 0.7rem;
  font-style: italic;
  font-weight: 700;
  line-height: 1;
}

/* A button that looks like a text link (for "Show me how"). */
.link-button {
  width: auto;
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-strong);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

/* Small heading that names the yearly data boxes. */
.data-subheading {
  margin: 18px 0 4px;
  color: var(--text);
  font-size: 0.95rem;
}

/* Shown when Save was clicked before the keep-or-load question was answered. */
.solar-data-choice-required {
  display: none;
  color: var(--danger);
  font-weight: 600;
}

.solar-data-choice.needs-answer {
  border-color: var(--danger);
}

.solar-data-choice.needs-answer .solar-data-choice-required {
  display: block;
}
