/**
 * Design system — Tableaux de bord (juin 2026)
 * Source canonique : _Launcher/shared/design-system.css
 * Copier dans chaque module web/ (ou servir via /design-system.css sur Estepona).
 *
 * Accents sémantiques (attribut html) :
 *   data-accent="residence"  — Maison, Appartement (orange)
 *   data-accent="analytics"  — PV, communautés, énergie (bleu)
 *   data-accent="billing"    — décomptes, pipelines (vert)
 */

/* —— Tokens —— */
:root {
  --space-1: 0.25rem;  /* 4px */
  --space-2: 0.5rem;   /* 8px */
  --space-3: 0.75rem;  /* 12px */
  --space-4: 1rem;     /* 16px */
  --space-5: 1.25rem;  /* 20px */
  --space-6: 1.5rem;   /* 24px */
  --space-8: 2rem;     /* 32px */

  --font: "Segoe UI", system-ui, -apple-system, sans-serif;

  /* Typography scale (canonical — do not add sizes) */
  --font-xs: 12px;
  --font-sm: 13px;
  --font-md: 15px;
  --font-lg: 18px;
  --font-xl: 24px;
  --font-kpi: 28px;

  /* Aliases (legacy — map to scale above) */
  --text-xs: var(--font-xs);
  --text-sm: var(--font-sm);
  --text-base: var(--font-md);
  --text-lg: var(--font-lg);
  --text-xl: var(--font-xl);
  --text-2xl: var(--font-kpi);

  --bg: #eef2f6;
  --bg-accent: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --muted: #94a3b8;
  --border: #cbd5e1;
  --border-soft: #e2e8f0;

  --radius: 10px;
  --radius-sm: 6px;
  --radius-pill: 999px;

  --shadow: 0 4px 24px rgba(15, 23, 42, 0.06);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05);

  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --accent-border: rgba(37, 99, 235, 0.28);

  --ok: #059669;
  --warn: #d97706;
  --danger: #dc2626;

  --content-max: 68.75rem;
  --transition: 0.15s ease;
}

html[data-accent="residence"] {
  --accent: #d97706;
  --accent-dark: #b45309;
  --accent-soft: rgba(217, 119, 6, 0.12);
  --accent-border: rgba(217, 119, 6, 0.28);
}

html[data-accent="analytics"] {
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --accent-border: rgba(37, 99, 235, 0.28);
}

html[data-accent="billing"] {
  --accent: #0d9488;
  --accent-dark: #0f766e;
  --accent-soft: rgba(13, 148, 136, 0.12);
  --accent-border: rgba(13, 148, 136, 0.28);
}

/* —— Base —— */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--font-md);
  font-weight: 400;
  line-height: 1.5;
  color: var(--text);
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-accent) 100%);
  min-height: 100vh;
}

/* —— Typography hierarchy —— */
h1, .ds-header h1, .ds-module-header h1 {
  font-size: var(--font-xl);
  font-weight: 700;
  line-height: 1.2;
}

.ds-title-row {
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.app-version {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted, #6b7280);
  padding: 0.15rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  user-select: all;
}

h2, .ds-section h2, section h2 {
  font-size: var(--font-lg);
  font-weight: 600;
  line-height: 1.25;
}

h3, .ds-section h3, section h3 {
  font-size: var(--font-md);
  font-weight: 600;
  line-height: 1.3;
}

.ds-subtitle,
.subtitle,
.ds-note,
label {
  font-size: var(--font-sm);
  font-weight: 400;
  color: var(--muted);
}

/* —— Layout —— */
.ds-page,
main.ds-page {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-5);
}

.wrap {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-5);
}

.ds-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.ds-shell__body {
  flex: 1;
  min-height: 0;
}

.ds-shell__body iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: none;
  background: var(--surface);
}

.ds-shell__body iframe.active { display: block; }

/* —— Header —— */
.ds-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.ds-header--bar {
  align-items: center;
  padding: var(--space-3) var(--space-5);
  min-height: 3.25rem;
}

.ds-module-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.ds-header__main,
.ds-module-header__main { min-width: 0; flex: 1; }

.ds-header h1,
.ds-module-header h1 {
  margin: 0;
  font-size: var(--font-xl);
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text);
}

.ds-subtitle,
.subtitle {
  margin: var(--space-1) 0 0;
  font-size: var(--font-sm);
  font-weight: 400;
  color: var(--muted);
}

.ds-header__actions,
.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

/* —— Tabs —— */
.ds-tabs,
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.ds-tab,
.tab {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  padding: 0.28rem 0.65rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font: inherit;
  font-size: var(--font-sm);
  font-weight: 500;
  line-height: 1.25;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

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

.ds-tab.active,
.tab.active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent-dark);
  font-weight: 500;
}

/* —— Buttons —— */
button,
.ds-btn,
.btn-link {
  font: inherit;
  font-size: var(--font-sm);
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.28rem 0.65rem;
  line-height: 1.25;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition), filter var(--transition);
}

button:hover:not(:disabled),
.ds-btn:hover:not(:disabled) {
  background: var(--bg-accent);
  border-color: var(--border-soft);
}

button.primary,
.ds-btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}

button.primary:hover:not(:disabled),
.ds-btn--primary:hover:not(:disabled) {
  filter: brightness(1.05);
  background: var(--accent);
}

button.danger,
.ds-btn--danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  font-weight: 500;
}

button:disabled,
.ds-btn:disabled { opacity: 0.55; cursor: not-allowed; filter: none; }

.hidden { display: none !important; }

/* —— Segment / filter controls —— */
.ds-segment,
.filters,
.chart-period,
.chart-toolbar,
.period-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.chart-period-label,
.period-label,
.ds-segment__label {
  color: var(--muted);
  font-size: var(--font-sm);
  font-weight: 500;
}

.chart-period-hint,
.period-hint,
.ds-segment__hint {
  color: var(--muted);
  font-size: var(--font-sm);
  font-weight: 400;
}

.filters button,
.chart-period button,
.ds-segment button,
.ds-segment__btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: var(--radius-pill);
  padding: 0.28rem 0.6rem;
  font: inherit;
  font-size: var(--font-sm);
  font-weight: 500;
  line-height: 1.25;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.filters button.active,
.chart-period button.active,
.ds-segment button.active,
.ds-segment__btn.active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent-dark);
  font-weight: 500;
}

.period-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  overflow: hidden;
  background: var(--surface);
}

.period-btn {
  border: none;
  border-radius: 0;
  background: transparent;
  padding: 0.28rem 0.65rem;
  font-size: var(--font-sm);
  font-weight: 500;
  line-height: 1.25;
  color: var(--muted);
}

.period-btn + .period-btn {
  border-left: 1px solid var(--border);
}

.period-btn.active {
  background: var(--accent);
  color: #fff;
  font-weight: 500;
}

/* —— KPI / summary cards —— */
.ds-kpi-grid,
.grid:not(.two-cols):not([class*="span"]) {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(auto-fit, minmax(12.25rem, 1fr));
  margin-bottom: var(--space-2);
}

.kpis,
.charge-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12.25rem, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.ds-kpi,
.card,
.kpi,
.charge-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}

.ds-kpi h2,
.card h2,
.kpi .label,
.charge-card .label {
  margin: 0 0 var(--space-1);
  font-size: var(--font-sm);
  text-transform: none;
  letter-spacing: normal;
  color: var(--muted);
  font-weight: 500;
  line-height: 1.35;
}

.ds-kpi .value,
.card .value,
.kpi .value,
.charge-card .value {
  font-size: var(--font-lg);
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.value .unit {
  font-size: var(--font-sm);
  font-weight: 500;
  color: var(--text);
}

.ds-kpi .sub,
.card .sub,
.kpi .hint,
.charge-card .hint {
  font-size: var(--font-sm);
  font-weight: 400;
  color: var(--muted);
  margin-top: var(--space-2);
  line-height: 1.4;
}

.card .sub-extra { margin-top: var(--space-2); }

.kpi { display: flex; flex-direction: column; min-height: 7.25rem; }
.kpi .hint { margin-top: auto; padding-top: var(--space-2); }

.charge-card { min-height: 6.75rem; }
.charge-card.highlight {
  border-color: var(--accent-border);
  background: linear-gradient(145deg, var(--accent-soft), var(--surface));
}

.summary-footnote {
  font-size: var(--font-xs);
  font-weight: 400;
  color: var(--muted);
  margin: 0 0 var(--space-6);
  line-height: 1.4;
}

/* —— Sections & panels —— */
.ds-section,
section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-bottom: var(--space-6);
  box-shadow: var(--shadow-sm);
}

.ds-section h2,
section h2 {
  margin: 0 0 var(--space-2);
  font-size: var(--font-lg);
  font-weight: 600;
  color: var(--text);
  text-transform: none;
  letter-spacing: normal;
}

.card h2 {
  font-size: var(--font-sm);
  font-weight: 500;
  color: var(--muted);
  text-transform: none;
  letter-spacing: normal;
}

.ds-note {
  margin: 0 0 var(--space-2);
  font-weight: 400;
  color: var(--muted);
  font-size: var(--font-sm);
  line-height: 1.45;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
  flex-wrap: wrap;
}

.card-head h2 { margin: 0; }

.two-cols {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: 1fr;
}

@media (min-width: 1000px) and (hover: hover) {
  .two-cols { grid-template-columns: 1fr 1fr; }
  .two-cols section { margin-bottom: 0; }
}

/* iPhone paysage : Safari grossit parfois les sous-textes des cartes */
@media (orientation: landscape) and (max-height: 500px) {
  .card .sub,
  .card .sub-extra,
  .summary-footnote,
  .ds-note,
  .kpi .hint,
  .charge-card .hint {
    font-size: var(--font-xs);
    line-height: 1.35;
  }
}

.secondary {
  margin-top: var(--space-8);
  padding-top: var(--space-6);
  border-top: 1px solid var(--border-soft);
}

.secondary h2.section-title {
  margin: 0 0 var(--space-2);
  font-size: var(--font-sm);
  color: var(--muted);
  font-weight: 500;
  text-transform: none;
  letter-spacing: normal;
}

/* —— Grid layouts (12-col) —— */
.grid[class*="span"],
.grid:has(.span-4) {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.card {
  padding: var(--space-4);
}

.span-12 { grid-column: span 12; }
.span-8 { grid-column: span 8; }
.span-7 { grid-column: span 7; }
.span-6 { grid-column: span 6; }
.span-5 { grid-column: span 5; }
.span-4 { grid-column: span 4; }

@media (max-width: 960px) {
  .span-8, .span-7, .span-6, .span-5, .span-4 { grid-column: span 12; }
}

/* —— Charts —— */
.chart-wrap,
.chart-box {
  position: relative;
  height: 280px;
}

.chart-wrap.chart-wrap-gaz { height: 480px; }
.chart-wrap.chart-wrap-sm { height: 220px; margin-bottom: var(--space-4); }
.chart-box.tall { height: 340px; }

/* —— Tables —— */
table,
.ds-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-sm);
}

th, td {
  text-align: left;
  padding: var(--space-2) var(--space-2);
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 500;
  font-size: var(--font-xs);
}

tr:hover td { background: rgba(248, 250, 252, 0.85); }

td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.table-wrap {
  max-height: 32.5rem;
  overflow: auto;
  border-radius: var(--radius);
}

table.hist-table { font-size: var(--font-sm); }
table.hist-table th,
table.hist-table td {
  padding: 0.35rem var(--space-2);
}

/* —— Tags —— */
.tag,
.ds-tag {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius-pill);
  font-size: var(--font-xs);
  font-weight: 500;
  white-space: nowrap;
}

.tag.paid, .tag.abono { background: rgba(5, 150, 105, 0.12); color: var(--ok); }
.tag.due_soon { background: rgba(234, 179, 8, 0.12); color: #a16207; }
.tag.overdue, .tag.renewal_needed { background: rgba(239, 68, 68, 0.12); color: var(--danger); }
.tag.planned { background: var(--accent-soft); color: var(--accent-dark); }
.tag.unknown { background: rgba(148, 163, 184, 0.15); color: var(--muted); }

/* —— Form controls —— */
select,
.ds-select {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: var(--font-sm);
}

/* —— Collapsible sections —— */
.section-toggle,
.collapse-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  margin: 0 0 var(--space-3);
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  font-size: var(--font-lg);
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  color: var(--text);
}

.section-toggle:hover,
.collapse-toggle:hover { color: var(--text); }

.section-toggle .chev,
.collapse-toggle .chevron {
  font-size: var(--font-xs);
  color: var(--muted);
  transition: transform var(--transition);
}

.section-toggle[aria-expanded="true"] .chev,
.collapse-toggle[aria-expanded="true"] .chevron { transform: rotate(90deg); }

/* —— Status & alerts —— */
.status {
  color: var(--muted);
  font-size: var(--font-sm);
  font-weight: 400;
  margin-bottom: var(--space-3);
}

#error {
  display: none;
  padding: var(--space-4);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  margin: var(--space-4);
  color: #991b1b;
  font-size: var(--font-sm);
}

.contract-note {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  font-size: var(--font-sm);
  font-weight: 400;
  line-height: 1.5;
  color: var(--muted);
}

.contract-note strong { color: var(--text); }

.check {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  font-size: var(--font-sm);
  line-height: 1.45;
}

.check.error { border-color: rgba(239, 68, 68, 0.35); background: rgba(239, 68, 68, 0.06); }
.check.warning { border-color: rgba(245, 158, 11, 0.35); background: rgba(245, 158, 11, 0.06); }
.check.info { border-color: var(--accent-border); background: var(--accent-soft); }
.check.ok { border-color: rgba(5, 150, 105, 0.35); background: rgba(5, 150, 105, 0.06); }

/* —— Footer —— */
footer,
.ds-footer {
  text-align: center;
  color: var(--muted);
  font-size: var(--font-sm);
  font-weight: 400;
  padding: var(--space-4);
}

footer code { font-size: 0.78em; }

/* —— Mode portail (iframe, ?embedded=1) —— */
html[data-embedded="1"] body,
body.embedded {
  background: var(--bg-accent);
  min-height: auto;
}

body.embedded .ds-header,
body.embedded > header:not(.ds-panel header),
body.embedded header.page-header {
  display: none !important;
}

body.embedded .ds-module-header__main {
  display: none !important;
}

body.embedded .ds-module-header {
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border-soft);
}

body.embedded .ds-page,
body.embedded main.ds-page,
body.embedded main#app,
body.embedded .wrap {
  max-width: none;
  padding-top: var(--space-4);
}

body.embedded .main-tabs {
  display: none !important;
}

/* Estepona — onglets Endesa / Hidralia / Charges conservés */
body.embedded.ds-shell {
  height: auto;
  min-height: 100vh;
  overflow: auto;
}

body.embedded.ds-shell .ds-header__main {
  display: none !important;
}

body.embedded.ds-shell .ds-header--bar {
  min-height: auto;
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface);
}

body.embedded.ds-shell .ds-shell__body {
  flex: 1 1 auto;
  height: auto;
  min-height: 55dvh;
  min-height: 55vh;
}

html[data-embedded="1"] .ds-shell__body iframe.active {
  min-height: 50dvh;
  min-height: 50vh;
}

html[data-embedded="1"] .ds-shell__body iframe {
  background: var(--bg-accent);
}

body.embedded footer,
body.embedded .ds-footer {
  display: none;
}

/* Version app — visible même en mode portail (header masqué) */
.app-build-stamp {
  position: fixed;
  left: 0.55rem;
  bottom: 0.3rem;
  margin: 0;
  padding: 0;
  font-size: 0.62rem;
  line-height: 1.2;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: #94a3b8;
  text-align: left;
  pointer-events: auto;
  user-select: none;
  z-index: 40;
  opacity: 0.75;
  background: transparent;
  border: 0;
}

body.embedded .app-build-stamp,
html[data-embedded="1"] .app-build-stamp {
  display: block !important;
  left: 0.45rem;
  bottom: 0.2rem;
}
