html, body {
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-family-base);
}

.dashboard {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  overflow: hidden;
}

.dash-header {
  padding: 0.6rem 1.5rem;
  border-bottom: 1px solid var(--color-border);
}

.dash-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: nowrap;
}

.dash-header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: nowrap;
  min-width: 0;
}

.dash-header h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin: 0;
  flex: 0 0 auto;
  white-space: nowrap;
}

.dash-header .tool-nav {
  font-size: 0.85rem;
  flex: 0 0 auto;
  white-space: nowrap;
}

.dash-info {
  font-size: 0.85rem;
  flex: 0 0 auto;
  position: relative;
}

.dash-info summary {
  cursor: pointer;
  color: var(--color-text-muted);
  list-style: none;
  white-space: nowrap;
}

.dash-info summary::-webkit-details-marker {
  display: none;
}

.dash-info summary:hover {
  color: var(--color-text);
}

.dash-info p {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  margin: 0.4rem 0 0;
  max-width: 40ch;
  /* Opened <details> content floats over the row instead of pushing the
     rest of the header (nav/h1/cache-banner) down/around: keeps the
     collapsed state's single-line layout intact and avoids a reflow of
     neighbouring flex items when toggled open. */
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 1;
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
}

/* #cache-banner's own <details> sits at the right edge of the header —
   anchor its dropdown to the right (grows leftward) instead of the left
   edge .dash-info uses by default, so it can't overflow off-screen. */
.dash-cache-details p {
  left: auto;
  right: 0;
  max-width: 50ch;
  white-space: normal;
}

/* Compact cache banner: sits at the right of the header bar
   (justify-content: space-between on .dash-header-bar), collapsed to its
   own short summary text by default (same disclosure pattern as
   .dash-info) so the header row stays one line. Only two controls: the
   disclosure (detail on click) and "Effacer et recharger" — always both
   visible together as long as the banner itself is shown (no separate
   dismiss button to accidentally hide the clear action behind). */
#cache-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 0 0 auto;
  margin: 0;
  padding: 0.3rem 0.6rem;
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 0.78rem;
  color: var(--color-text-subtle);
}

#cache-banner button {
  flex: 0 0 auto;
  white-space: nowrap;
  font-size: 0.78rem;
  padding: 0.25rem 0.5rem;
}

.dash-main {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(340px, 1fr);
  min-height: 0;
  height: 100%;
}

.dash-content {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  padding: 1rem 1.5rem;
  overflow: hidden;
}

.dash-params {
  min-height: 0;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  border-left: 1px solid var(--color-border);
  background: var(--color-card-bg);
}

#empty-state {
  color: var(--color-text-muted);
  font-size: 1rem;
  margin-top: 2rem;
  text-align: center;
}

[data-has-results="true"] #empty-state {
  display: none;
}

.dash-results {
  display: none;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

[data-has-results="true"] .dash-results {
  display: flex;
}

.kpi-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 0.6rem;
}

.kpi-strip .result-line {
  margin: 0;
}

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

section {
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.dash-params section,
.dash-params fieldset {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--color-border);
  border-radius: 0;
  padding: 0.9rem 0;
  margin: 0;
}

.dash-params fieldset {
  margin: 0;
  padding: 0.9rem 0;
}

.dash-params legend,
.dash-params section h2 {
  font-size: 1rem;
  font-weight: 700;
  padding: 0;
  margin-bottom: 0.4rem;
}

.dash-params summary {
  cursor: pointer;
  font-weight: 700;
  padding: 0.6rem 0;
}

section h2 {
  font-size: 1.1rem;
  margin-top: 0;
  margin-bottom: 0.8rem;
}

section h3 {
  font-size: 1rem;
  margin-top: 1.2rem;
  margin-bottom: 0.6rem;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.4rem;
  margin-top: 0.9rem;
  color: var(--color-text);
}

label:first-of-type {
  margin-top: 0;
}

input[type="text"] {
  width: 100%;
  box-sizing: border-box;
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  font-family: var(--font-family-mono);
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--color-accent-1);
}

input[type="file"] {
  width: 100%;
  box-sizing: border-box;
  padding: 0.5rem 0;
  font-size: 0.9rem;
  color: var(--color-text);
}

.param-control-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.35rem;
}

.param-slider {
  flex: 1;
  accent-color: var(--color-accent-1);
}

.param-step-btn {
  flex: 0 0 auto;
  width: 1.8rem;
  height: 1.8rem;
  line-height: 1;
  font-size: 1rem;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  cursor: pointer;
}

.param-step-btn:hover {
  border-color: var(--color-accent-1);
}

.error {
  color: var(--color-error);
  min-height: 1.2em;
  font-size: 0.9rem;
  margin-top: 0.6rem;
}

.result-line {
  margin-top: 0.6rem;
  color: var(--color-text-subtle);
  font-size: 0.9rem;
}

.result-line span:first-child {
  font-weight: 600;
  color: var(--color-text);
}

.result-value {
  font-family: var(--font-family-mono);
  color: var(--color-accent-1);
}

.assumptions-note {
  margin-top: 0.6rem;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  font-style: italic;
}

#result-warnings p {
  color: var(--color-error);
  font-size: 0.85rem;
  margin-top: 0.4rem;
}

.rounding-note {
  margin-top: 1rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

#pvgis-rows-container {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.pvgis-row {
  padding: 0.8rem;
  border: 1px dashed var(--color-border);
  border-radius: 6px;
}

.pvgis-remove-button {
  margin-top: 0.8rem;
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
  font-family: inherit;
  color: var(--color-error);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  cursor: pointer;
}

.pvgis-remove-button:hover {
  border-color: var(--color-error);
}

#add-pvgis-button,
#compute-button {
  margin-top: 1rem;
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  cursor: pointer;
}

#add-pvgis-button:hover,
#compute-button:hover {
  border-color: var(--color-accent-1);
}

#compute-button {
  width: 100%;
}

.table-wrapper {
  overflow-x: auto;
}

.table-wrapper {
  max-height: 480px;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-family-mono);
  font-size: 0.85rem;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--color-card-bg);
  color: var(--color-text);
  text-align: right;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--color-border);
}

thead th:first-child {
  text-align: left;
}

tbody td {
  text-align: right;
  padding: 0.4rem 0.6rem;
  color: var(--color-text-subtle);
  border-bottom: 1px solid var(--color-border);
}

tbody td:first-child {
  text-align: left;
  color: var(--color-text-muted);
}

/* Tab bar / tab panels ------------------------------------------------- */

.tab-bar {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 0.75rem;
}

.tab-button {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--color-text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.tab-button:hover {
  color: var(--color-text);
}

.tab-button.active {
  color: var(--color-text);
  font-weight: 700;
  border-bottom-color: var(--color-accent-1);
}

.tab-panels {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.tab-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.tab-panel[hidden] {
  display: none !important;
}

#tab-table,
#tab-optim {
  overflow-y: auto;
}

.chart-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin: 0 0 0.75rem;
  flex: 0 0 auto;
}

.granularity-buttons {
  display: inline-flex;
  gap: 0.25rem;
}

.granularity-buttons button {
  padding: 0.3rem 0.7rem;
  cursor: pointer;
}

.granularity-buttons button.active {
  font-weight: 700;
  text-decoration: underline;
}

#chart-date-prev-button,
#chart-date-next-button {
  padding: 0.2rem 0.55rem;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

#chart-date-prev-button:disabled,
#chart-date-next-button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

#chart-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
}

.chart-canvas-wrapper {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
}

#battery-comparison {
  margin-top: 1rem;
}
#battery-comparison-table th,
#battery-comparison-table td {
  text-align: left;
}

#panel-brick {
  margin-bottom: 1rem;
}

#pvgis-panel-counts-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.panel-count-row label {
  margin: 0 0 0.2rem;
  display: inline;
}

.pvgis-file-name {
  display: block;
  color: var(--color-text-muted);
  font-size: 0.78rem;
  font-style: italic;
  margin: 0 0 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pvgis-file-name:empty {
  display: none;
}
#optim-table th,
#optim-table td {
  text-align: left;
  white-space: nowrap;
}
#optim-table th[data-sort-column] {
  cursor: pointer;
}
#optim-table tr.optim-recommended-row {
  font-weight: 600;
}
#optim-recommended {
  margin: 0.5rem 0;
}

@media (max-width: 1000px) {
  .dashboard {
    height: auto;
    overflow: visible;
  }
  .dash-main {
    grid-template-columns: 1fr;
    height: auto;
  }
  .dash-content {
    overflow: visible;
  }
  .dash-params {
    border-left: none;
    border-top: 1px solid var(--color-border);
  }
}
