/* ——— Base : thème sombre, page ——— */
:root { color-scheme: dark; }
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: 'Outfit', system-ui, "Segoe UI", Arial, sans-serif;
  background: #000000;
  color: #f0f0f0;
  padding: clamp(12px, 2.5vw, 22px) clamp(12px, 3vw, 28px);
  padding-left: max(12px, env(safe-area-inset-left, 0px));
  padding-right: max(12px, env(safe-area-inset-right, 0px));
  padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ——— Conteneur : largeur = plein écran, unités cqi pour typo fluide ——— */
.layout-scope {
  container-type: inline-size;
  container-name: solar-layout;
  width: 100%;
}

/* ——— En-tête : titre centré, bouton Rafraîchir à droite ——— */
.page-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: start;
  gap: clamp(8px, 1.5cqi, 14px);
  margin-bottom: clamp(6px, 1.1cqi, 12px);
}

.page-header__spacer {
  grid-column: 1;
}

.page-header h2 {
  grid-column: 2;
  color: #ff2a2a;
  text-transform: uppercase;
  text-align: center;
  letter-spacing: 0.04em;
  font-size: clamp(1.38rem, 1.14rem + 2.85cqi, 1.95rem);
  line-height: 1.25;
  margin: 0;
}

.page-header__actions {
  grid-column: 3;
  justify-self: end;
}

.btn-refresh {
  margin: 0;
  padding: clamp(6px, 1cqi, 10px) clamp(12px, 2cqi, 18px);
  font: inherit;
  font-size: clamp(0.85rem, 0.72rem + 1.1cqi, 1rem);
  font-weight: 600;
  line-height: 1.2;
  color: #fecaca;
  background: #450a0a;
  border: 1px solid #7f1d1d;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}

.btn-refresh:hover:not(:disabled) {
  background: #7f1d1d;
  color: #fff;
}

.btn-refresh:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ——— Ligne date / heure (et erreur réseau) ——— */
.subtitle {
  color: #aaa;
  font-size: clamp(1.02rem, 0.86rem + 1.6cqi, 1.26rem);
  line-height: 1.45;
  margin-bottom: clamp(12px, 2.2cqi, 22px);
  text-align: center;
}
.subtitle.is-error { color: #f87171; }

/* ——— Cartes résumé (Live, totaux, etc.) ——— */
.summary-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 10.5rem), 1fr));
  gap: clamp(8px, 1.5cqi, 14px);
  margin-bottom: clamp(12px, 2.4cqi, 22px);
  align-items: stretch;
}

.summary-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: clamp(4px, 0.65cqi, 8px);
  min-height: clamp(4.25rem, 11cqi, 5.75rem);
  padding: clamp(10px, 1.35cqi, 14px) clamp(12px, 1.8cqi, 18px);
  background: #121212;
  border: 1px solid #1a1a1a;
  border-top: 2px solid #ff5a5a; /* Top border for premium visibility */
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  font-size: clamp(0.95rem, 0.77rem + 1.45cqi, 1.2rem);
}

.summary-chip__label {
  display: block;
  font-size: 0.72em;
  font-weight: 600;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #9ca3af;
}

.summary-chip__value {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 0.15em;
  font-weight: 700;
  line-height: 1.15;
  color: #ff5a5a;
}

.summary-chip.cached .summary-chip__value { color: #fb923c; }
.summary-chip.cached.is-live .summary-chip__value { color: #22c55e; }
.summary-chip.error .summary-chip__value { color: #f87171; }
.summary-chip.error .summary-chip__value { color: #f87171; }

.summary-num {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 1.12em;
  letter-spacing: 0.02em;
}

.summary-unit {
  margin-left: 0.28em;
  font-size: 0.78em;
  font-weight: 600;
  opacity: 0.88;
  letter-spacing: 0.03em;
}

/* ——— Tableau : structure, en-têtes, cellules ——— */
.table-wrap {
  width: 100%;
  border-radius: 10px;
  border: 1px solid #2a2a2a;
}

table {
  width: 100%;
  max-width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  background: #0a0a0a;
}

th,
td {
  text-align: center;
  vertical-align: middle;
  padding: clamp(7px, 1.35cqi, 16px) clamp(5px, 1.12cqi, 14px);
  overflow-wrap: break-word;
  word-wrap: break-word;
}

th {
  background: #1a0000;
  color: #ff2a2a;
  font-weight: 600;
  font-size: clamp(0.77rem, 0.63rem + 1.42cqi, 1.1rem);
  line-height: 1.35;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid #3d1515;
}

td {
  border-bottom: 1px solid #2a2a2a;
  font-size: clamp(1rem, 0.8rem + 2.05cqi, 1.32rem);
  line-height: 1.45;
}

/* ——— Largeurs colonnes (total 100 %, SN inclut cache / délai) ——— */
th:nth-child(1),
td:nth-child(1) { width: 5%; }
th:nth-child(2),
td:nth-child(2) { width: 27%; }
th:nth-child(3),
td:nth-child(3) { width: 16%; }
th:nth-child(4),
td:nth-child(4),
th:nth-child(5),
td:nth-child(5),
th:nth-child(6),
td:nth-child(6),
th:nth-child(7),
td:nth-child(7),
th:nth-child(8),
td:nth-child(8) { width: 10.4%; }

tbody tr:hover { background: #1f0000; }

/* ——— Pastilles statut, SN, valeurs + unités en cellule ——— */
.badge {
  padding: 0.25em 0.6em;
  border-radius: 10px;
  font-size: 0.98em;
  line-height: 1.35;
}

.badge-normal { background: #052e16; color: #4ade80; }
.badge-fault { background: #3b0000; color: #ff6b6b; }
.badge-waiting { background: #2a1a00; color: #fbbf24; }
.badge-other { background: #1a1a3a; color: #a5b4fc; }

.badge-cache { background: orange; font-size: 0.96em; }
.badge-live { background: green; font-size: 0.96em; }

.sn-cell {
  vertical-align: middle;
}

.sn-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 0.8cqi, 10px);
}

.sn {
  font-family: monospace, ui-monospace, monospace;
  font-size: 1em;
  word-break: break-all;
  line-height: 1.4;
}
.num { font-variant-numeric: tabular-nums; }

.cell-value {
  font-variant-numeric: tabular-nums;
}

.cell-unit {
  display: inline-block;
  margin-left: 0.22em;
  font-size: 0.72em;
  font-weight: 600;
  opacity: 0.82;
  vertical-align: baseline;
  white-space: nowrap;
}

.cell-empty {
  opacity: 0.45;
}

.cell-error {
  color: #fca5a5;
  font-size: 0.88em;
  line-height: 1.35;
  text-align: left;
  word-break: break-word;
}

/* ——— Graphique production instantanée (journée) ——— */
.chart-section {
  margin-top: clamp(16px, 3cqi, 28px);
}

.chart-toolbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: clamp(6px, 1.2cqi, 12px);
  margin-bottom: 12px;
}

.chart-nav-btn {
  flex-shrink: 0;
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  font: inherit;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
  color: #fecaca;
  background: #450a0a;
  border: 1px solid #7f1d1d;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.chart-nav-btn:hover:not(:disabled) {
  background: #7f1d1d;
  color: #fff;
}

.chart-nav-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.chart-toolbar-center {
  text-align: center;
  min-width: 0;
}

.chart-title-main {
  margin: 0;
  font-size: clamp(0.85rem, 0.74rem + 1cqi, 1rem);
  font-weight: 600;
  color: #ff5a5a;
  letter-spacing: 0.03em;
}

.chart-date-label {
  margin: 4px 0 0;
  font-size: clamp(0.8rem, 0.7rem + 0.9cqi, 0.95rem);
  font-weight: 500;
  color: #c4b5b5;
  text-transform: capitalize;
  line-height: 1.25;
}

.chart-wrap {
  position: relative;
  width: 100%;
  height: min(22rem, 45vh);
  min-height: 200px;
  padding: 12px 8px 8px;
  background: #141414;
  border: 1px solid #2a2a2a;
  border-radius: 10px;
}

/* ——— Téléphone / portrait étroit : cartes à la place du tableau ——— */
@media (max-width: 640px) {
  .page-header {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    justify-items: stretch;
  }

  .page-header__spacer {
    display: none;
  }

  .page-header h2 {
    grid-column: 1;
    grid-row: 1;
    font-size: clamp(1rem, 4.2vw, 1.35rem);
    padding: 0 4px;
  }

  .page-header__actions {
    grid-column: 1;
    grid-row: 2;
    justify-self: stretch;
  }

  .btn-refresh {
    width: 100%;
    min-height: 44px;
    padding: 10px 16px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .subtitle {
    font-size: clamp(0.88rem, 3.8vw, 1rem);
    margin-bottom: 14px;
  }

  .summary-bar {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .summary-chip {
    min-height: auto;
    padding: 12px 14px;
  }

  .table-wrap {
    overflow-x: visible;
    border: none;
    background: transparent;
  }

  table {
    display: block;
    table-layout: auto;
    background: transparent;
  }

  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  tbody {
    display: block;
  }

  tbody tr {
    display: block;
    margin-bottom: 14px;
    padding: 12px 12px 4px;
    background: #1a1a1a;
    border: 1px solid #2a2a2a;
    border-radius: 12px;
  }

  tbody tr:hover {
    background: #1f0a0a;
  }

  tbody td {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    width: 100%;
    padding: 10px 4px;
    border-bottom: 1px solid #2a2a2a;
    font-size: clamp(0.92rem, 3.6vw, 1.05rem);
    text-align: center;
  }

  tbody td:last-child {
    border-bottom: none;
    padding-bottom: 8px;
  }

  tbody td::before {
    content: attr(data-label);
    display: block;
    text-align: center;
    font-size: 0.68em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #e8a8a8;
    line-height: 1.25;
  }

  tbody td.sn-cell .sn-inline {
    justify-content: center;
    min-width: 0;
  }

  tbody td.cell-error[colspan] {
    text-align: left;
  }

  tbody td.cell-error[colspan]::before {
    text-align: center;
  }

  th:nth-child(n),
  td:nth-child(n) {
    width: auto !important;
  }

  .chart-section {
    margin-top: 18px;
  }

  .chart-toolbar {
    gap: 8px;
    margin-bottom: 10px;
  }

  .chart-nav-btn {
    min-width: 40px;
    min-height: 40px;
    padding: 0 8px;
    font-size: 1.2rem;
  }

  .chart-title-main {
    font-size: clamp(0.78rem, 3.4vw, 0.9rem);
  }

  .chart-date-label {
    font-size: clamp(0.74rem, 3.2vw, 0.85rem);
  }

  .chart-wrap {
    height: min(18rem, 42vh);
    min-height: 180px;
    padding: 10px 4px 6px;
  }
}

/* ——— Animations ——— */
@keyframes pulseGlow {
  0% { text-shadow: 0 0 0 rgba(255, 90, 90, 0); transform: scale(1); }
  35% { text-shadow: 0 0 12px rgba(255, 90, 90, 0.82); transform: scale(1.04); }
  100% { text-shadow: 0 0 0 rgba(255, 90, 90, 0); transform: scale(1); }
}

.val-updated {
  animation: pulseGlow 0.4s ease-out;
  display: inline-block;
}


/* ——— Status Dot & Pulse ——— */
.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  background-color: currentColor;
  border-radius: 50%;
  margin-right: 8px;
}
.status-dot.pulse {
  animation: sse-pulse 2s infinite;
}
@keyframes sse-pulse {
  0% { transform: scale(0.95); opacity: 1; box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); }
  70% { transform: scale(1.1); opacity: 0.8; box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
  100% { transform: scale(0.95); opacity: 1; box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}
