/* Thème portail : communautés (bleu) */
:root {
  --font-xs: 12px;
  --font-sm: 13px;
  --font-md: 15px;
  --font-lg: 18px;
  --font-xl: 24px;
  --font-kpi: 28px;

  --theme: #2563eb;
  --theme-dark: #1d4ed8;
  --theme-soft: rgba(37, 99, 235, 0.1);
  --accent: var(--theme);
  --accent-dark: var(--theme-dark);
  --accent-soft: var(--theme-soft);
  --accent-border: rgba(37, 99, 235, 0.28);
  --border: #cbd5e1;
  --muted: #94a3b8;
  --radius-pill: 999px;
}

* {
  box-sizing: border-box;
}

body {
  font-size: var(--font-md);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 400;
  margin: 0;
  padding: 1.5rem 2rem 3rem;
  background:
    radial-gradient(ellipse 90% 60% at 100% 0%, #dbeafe 0%, transparent 50%),
    linear-gradient(180deg, #e8eef6 0%, #f8fafc 100%);
  color: #0f172a;
  max-width: 1200px;
}

header {
  margin-bottom: 0.25rem;
}

header h1 {
  display: none;
}

.subtitle {
  margin: 0;
  color: #94a3b8;
  font-size: var(--font-sm);
}

.purpose {
  margin: 0.5rem 0 0;
  font-size: var(--font-sm);
  color: #94a3b8;
  max-width: 46rem;
}

.periods-section {
  margin-bottom: 1.75rem;
}

.periods-section > .section-title {
  display: block;
  margin: 0.5rem 0 0.75rem;
}

.controls {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
  margin: 0;
  padding: 1rem;
  background: #fff;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}

.controls-dates {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.controls-dates label {
  font-size: var(--font-sm);
  font-weight: 500;
  color: #334155;
}

.controls-dates input[type="date"] {
  margin-left: 0.35rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}

#load-btn {
  padding: 0.28rem 0.75rem;
  font-size: var(--font-sm);
  font-weight: 500;
  line-height: 1.25;
  border-radius: var(--radius-pill);
  border: 1px solid var(--accent-dark);
  background: var(--accent-dark);
  color: #fff;
  cursor: pointer;
  transition: filter 0.15s ease;
}

#load-btn:hover {
  filter: brightness(1.05);
}

.period-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.granularity-label {
  font-size: var(--font-sm);
  font-weight: 500;
  color: var(--muted);
  margin-right: 0.25rem;
}

.preset-btn {
  padding: 0.28rem 0.6rem;
  font-size: var(--font-sm);
  font-weight: 500;
  line-height: 1.25;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.preset-btn:hover {
  background: #f8fafc;
  color: #334155;
}

.preset-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent-dark);
}

.status {
  font-size: var(--font-sm);
  color: #94a3b8;
}

.status.error {
  color: #dc2626;
}

.overview {
  margin-top: 0.75rem;
  margin-bottom: 1.5rem;
}

.section-title {
  font-size: var(--font-lg);
  font-weight: 600;
  color: #1e293b;
  margin: 0 0 0.75rem;
  border: none !important;
  padding: 0 !important;
  display: block;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
}

.kpi-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 0.85rem 1rem;
}

.kpi-label {
  font-size: var(--font-xs);
  color: #94a3b8;
  margin: 0 0 0.25rem;
}

.kpi-value {
  font-size: var(--font-lg);
  font-weight: 700;
  margin: 0;
}

.kpi-sub {
  font-size: var(--font-xs);
  color: #94a3b8;
  margin: 0.25rem 0 0;
}

.data-note {
  margin: 0.75rem 0 0;
  font-size: var(--font-sm);
  color: #94a3b8;
  max-width: 52rem;
}

.panel {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  margin-bottom: 1rem;
}

.panel > summary {
  padding: 0.85rem 1rem;
  font-weight: 600;
  cursor: pointer;
  list-style-position: inside;
}

.panel-body {
  padding: 0 1rem 1rem;
  border-top: 1px solid #f1f5f9;
}

.subsection {
  font-size: var(--font-sm);
  margin: 1rem 0 0.5rem;
  color: #334155;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}

.chart-card {
  background: #fafafa;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.75rem;
}

.chart-card h4 {
  margin: 0 0 0.5rem;
  font-size: var(--font-sm);
  font-weight: 600;
  color: #334155;
}

.chart-card canvas {
  width: 100% !important;
  max-height: 280px;
}

.member-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin: 0.5rem 0 0.75rem;
}

.member-toolbar label {
  font-size: var(--font-sm);
}

.member-toolbar select {
  min-width: 280px;
  padding: 0.4rem 0.5rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: var(--font-sm);
}

.member-table-wrap {
  overflow-x: auto;
  margin-top: 0.75rem;
}

.member-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-sm);
}

.member-table th,
.member-table td {
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid #e2e8f0;
  text-align: left;
}

.member-table th {
  background: #f8fafc;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.member-table th:hover {
  background: #f1f5f9;
}

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

.member-table tr:hover td {
  background: #f8fafc;
}

.badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: var(--font-xs);
  font-weight: 600;
}

.badge-consumption {
  background: #d1fae5;
  color: #065f46;
}

.badge-production {
  background: #fef3c7;
  color: #92400e;
}

.badge-prosumer {
  background: #e0e7ff;
  color: #3730a3;
}

.num-negative {
  color: #dc2626;
}

.num-positive {
  color: #059669;
}

.errors {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.balance-banner {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.88rem;
  line-height: 1.45;
}

.balance-banner.balance-ok {
  background: #f0fdf4;
  border: 1px solid #86efac;
  color: #14532d;
}

.balance-banner.balance-warn {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  color: #78350f;
}

.balance-hint {
  font-size: 0.82rem;
}

.balance-link {
  color: inherit;
  opacity: 0.85;
  font-size: 0.8rem;
}

@media (max-width: 640px) {
  body {
    padding: 1rem;
  }

  .member-toolbar select {
    min-width: 100%;
  }
}

body.embedded > header:first-of-type {
  display: none !important;
}

body.embedded .periods-section > .section-title {
  margin-top: 0;
}

.app-build-stamp {
  position: fixed;
  left: 0.55rem;
  bottom: 0.3rem;
  margin: 0;
  font-size: 0.62rem;
  line-height: 1.2;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: #94a3b8;
  pointer-events: auto;
  user-select: none;
  z-index: 40;
  opacity: 0.75;
}

body.embedded .app-build-stamp {
  left: 0.45rem;
  bottom: 0.2rem;
}
