/* ==========================================================================
   MAIA — Design system « Apple-like »
   Clarté · Déférence · Profondeur.
   Tout est piloté par tokens (--*). Changer de skin / mode = surcharger un thème.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. TOKENS — thème clair (défaut)
   -------------------------------------------------------------------------- */
:root {
  color-scheme: light;

  /* Teintes système (fonctionnelles, utilisées avec parcimonie) */
  --blue:   #007aff;
  --green:  #34c759;
  --red:    #ff3b30;
  --orange: #ff9500;
  --yellow: #ffcc00;
  --teal:   #30b0c7;
  --purple: #af52de;
  --pink:   #ff2d55;
  --indigo: #5856d6;

  /* Accent global (action) */
  --primary: var(--blue);
  --live:    var(--red);

  /* Fonds & surfaces (profondeur par élévation) */
  --bg:            #f5f5f7;
  --bg-tint-a:     rgba(0, 122, 255, 0.05);
  --bg-tint-b:     rgba(175, 82, 222, 0.04);
  --surface:       #ffffff;
  --surface-2:     #ffffff;

  /* Remplissages translucides (lignes, encarts imbriqués) */
  --fill-1: rgba(120, 120, 128, 0.08);
  --fill-2: rgba(120, 120, 128, 0.05);
  --fill-3: rgba(120, 120, 128, 0.03);

  /* Séparateurs — traits fins */
  --separator:        rgba(60, 60, 67, 0.11);
  --separator-strong: rgba(60, 60, 67, 0.20);

  /* Texte (hiérarchie par opacité, à la SF) */
  --text:           #1d1d1f;
  --text-secondary: rgba(60, 60, 67, 0.62);
  --text-tertiary:  rgba(60, 60, 67, 0.42);
  --text-quaternary:rgba(60, 60, 67, 0.26);
  /* Alias rétro-compat (utilisés inline dans app.js) */
  --text-dim:   var(--text-secondary);
  --text-faint: var(--text-tertiary);

  /* Matériaux translucides (barres, overlays) */
  --material:     rgba(255, 255, 255, 0.72);
  --material-blur: saturate(180%) blur(20px);

  /* Ombres — diffuses, discrètes (la lumière, pas le contour) */
  --shadow-card:
    0 0.5px 1px rgba(0, 0, 0, 0.04),
    0 8px 28px -10px rgba(0, 0, 0, 0.14);
  --shadow-card-hover:
    0 1px 2px rgba(0, 0, 0, 0.05),
    0 18px 42px -14px rgba(0, 0, 0, 0.20);
  --shadow-pop: 0 12px 48px -8px rgba(0, 0, 0, 0.28);

  /* Sur teinte accent (icône) */
  --on-accent: #ffffff;

  /* Couleurs du graphe (lues par Chart.js via JS) */
  --chart-line: #ff3b30;
  --chart-fill: rgba(255, 59, 48, 0.10);
  --chart-grid: rgba(60, 60, 67, 0.08);
  --chart-tick: rgba(60, 60, 67, 0.42);

  /* Géométrie */
  --radius-xl: 26px;
  --radius:    20px;
  --radius-sm: 14px;
  --radius-xs: 10px;

  /* Rythme typographique */
  --font-sans: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text',
               'Inter', 'Segoe UI', system-ui, sans-serif;

  /* Mouvement (physique organique) */
  --ease-out:    cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-fast: 0.18s;
  --dur:      0.32s;
}

/* --------------------------------------------------------------------------
   2. TOKENS — thème sombre (OLED) : surcharge ciblée
   -------------------------------------------------------------------------- */
[data-theme='dark'] {
  color-scheme: dark;

  --blue:   #0a84ff;
  --green:  #30d158;
  --red:    #ff453a;
  --orange: #ff9f0a;
  --yellow: #ffd60a;
  --teal:   #40c8e0;
  --purple: #bf5af2;
  --pink:   #ff375f;
  --indigo: #5e5ce6;

  --bg:        #000000;
  --bg-tint-a: rgba(10, 132, 255, 0.10);
  --bg-tint-b: rgba(191, 90, 242, 0.07);
  --surface:   #1c1c1e;
  --surface-2: #2c2c2e;

  --fill-1: rgba(120, 120, 128, 0.28);
  --fill-2: rgba(120, 120, 128, 0.18);
  --fill-3: rgba(120, 120, 128, 0.12);

  --separator:        rgba(255, 255, 255, 0.10);
  --separator-strong: rgba(255, 255, 255, 0.18);

  --text:            #f5f5f7;
  --text-secondary:  rgba(235, 235, 245, 0.60);
  --text-tertiary:   rgba(235, 235, 245, 0.38);
  --text-quaternary: rgba(235, 235, 245, 0.22);

  --material:      rgba(28, 28, 30, 0.72);

  --shadow-card:
    0 0.5px 1px rgba(0, 0, 0, 0.5),
    0 10px 30px -12px rgba(0, 0, 0, 0.7);
  --shadow-card-hover:
    0 1px 2px rgba(0, 0, 0, 0.6),
    0 20px 46px -16px rgba(0, 0, 0, 0.8);
  --shadow-pop: 0 16px 56px -8px rgba(0, 0, 0, 0.7);

  --chart-line: #ff453a;
  --chart-fill: rgba(255, 69, 58, 0.14);
  --chart-grid: rgba(235, 235, 245, 0.08);
  --chart-tick: rgba(235, 235, 245, 0.38);
}

/* Suivi du système quand l'utilisateur n'a pas choisi explicitement */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']):not([data-theme='dark']) {
    color-scheme: dark;
    --blue: #0a84ff; --green: #30d158; --red: #ff453a; --orange: #ff9f0a;
    --yellow: #ffd60a; --teal: #40c8e0; --purple: #bf5af2; --pink: #ff375f; --indigo: #5e5ce6;
    --bg: #000000; --bg-tint-a: rgba(10,132,255,0.10); --bg-tint-b: rgba(191,90,242,0.07);
    --surface: #1c1c1e; --surface-2: #2c2c2e;
    --fill-1: rgba(120,120,128,0.28); --fill-2: rgba(120,120,128,0.18); --fill-3: rgba(120,120,128,0.12);
    --separator: rgba(255,255,255,0.10); --separator-strong: rgba(255,255,255,0.18);
    --text: #f5f5f7; --text-secondary: rgba(235,235,245,0.60);
    --text-tertiary: rgba(235,235,245,0.38); --text-quaternary: rgba(235,235,245,0.22);
    --material: rgba(28,28,30,0.72);
    --shadow-card: 0 0.5px 1px rgba(0,0,0,0.5), 0 10px 30px -12px rgba(0,0,0,0.7);
    --shadow-card-hover: 0 1px 2px rgba(0,0,0,0.6), 0 20px 46px -16px rgba(0,0,0,0.8);
    --shadow-pop: 0 16px 56px -8px rgba(0,0,0,0.7);
    --chart-line: #ff453a; --chart-fill: rgba(255,69,58,0.14);
    --chart-grid: rgba(235,235,245,0.08); --chart-tick: rgba(235,235,245,0.38);
  }
}

/* --------------------------------------------------------------------------
   3. BASE
   -------------------------------------------------------------------------- */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'cv11', 'ss01';
}

body {
  background:
    radial-gradient(1200px 700px at 85% -15%, var(--bg-tint-a), transparent 60%),
    radial-gradient(1000px 700px at -5% 110%, var(--bg-tint-b), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  transition: background-color var(--dur) var(--ease-out), color var(--dur) var(--ease-out);
}

::selection { background: color-mix(in srgb, var(--primary) 22%, transparent); }

/* Données chiffrées : chasse fixe (alignement à la SF) */
.glucose-value, .stat .v, .match-score, .clim-setpoint, .weather-temp,
.glucose-trend, .clim-room, .clim-setpoint {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum';
}

/* --------------------------------------------------------------------------
   4. BARRE SUPÉRIEURE — matériau translucide
   -------------------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--material);
  -webkit-backdrop-filter: var(--material-blur);
  backdrop-filter: var(--material-blur);
  border-bottom: 1px solid var(--separator);
}
.topbar-inner {
  max-width: 1120px; margin: 0 auto;
  padding: 11px clamp(16px, 3vw, 32px);
  display: flex; align-items: center; gap: 14px;
}
.wordmark {
  font-size: 17px; font-weight: 700; letter-spacing: 0.14em;
  color: var(--text);
}
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }

/* Bouton icône — fin, discret */
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: 50%; border: 1px solid var(--separator);
  background: var(--fill-2); color: var(--text-secondary);
  cursor: pointer; transition: all var(--dur-fast) var(--ease-out);
}
.icon-btn:hover { background: var(--fill-1); color: var(--text); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg { width: 19px; height: 19px; }

/* --------------------------------------------------------------------------
   5. MISE EN PAGE
   -------------------------------------------------------------------------- */
.briefing {
  max-width: 1120px; margin: 0 auto;
  padding: clamp(24px, 4vw, 52px) clamp(16px, 3vw, 32px) 72px;
}

.briefing-header { margin-bottom: clamp(22px, 3vw, 34px); }
.greeting {
  font-size: clamp(32px, 5.5vw, 46px);
  font-weight: 700; letter-spacing: -0.025em; line-height: 1.04;
}
.greeting .accent { color: var(--primary); }
.subline {
  color: var(--text-tertiary); margin-top: 8px;
  font-size: 16px; font-weight: 500; text-transform: capitalize;
}

.grid { display: grid; grid-template-columns: 1fr; gap: clamp(14px, 1.6vw, 20px); }
@media (min-width: 760px) {
  .grid { grid-template-columns: 1.12fr 1fr; }
  .card.span-2 { grid-column: 1 / -1; }
}

/* --------------------------------------------------------------------------
   6. CARTES
   -------------------------------------------------------------------------- */
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: var(--radius);
  padding: clamp(18px, 2vw, 24px);
  box-shadow: var(--shadow-card);
  transition: box-shadow var(--dur) var(--ease-out),
              transform var(--dur) var(--ease-out);
  /* Entrée organique */
  animation: card-in 0.5s var(--ease-out) both;
}
.card:hover { box-shadow: var(--shadow-card-hover); transform: translateY(-2px); }

@keyframes card-in {
  from { opacity: 0; transform: translateY(12px) scale(0.99); }
  to   { opacity: 1; transform: none; }
}
/* léger décalage en cascade */
.grid > .card:nth-child(2) { animation-delay: 0.04s; }
.grid > .card:nth-child(3) { animation-delay: 0.08s; }
.grid > .card:nth-child(4) { animation-delay: 0.12s; }
.grid > .card:nth-child(5) { animation-delay: 0.16s; }
.grid > .card:nth-child(6) { animation-delay: 0.20s; }
.grid > .card:nth-child(n+7) { animation-delay: 0.24s; }

.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.card-icon {
  width: 38px; height: 38px; flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 11px;
  color: var(--accent, var(--primary));
  background: color-mix(in srgb, var(--accent, var(--primary)) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent, var(--primary)) 22%, transparent);
}
.card-icon svg { width: 21px; height: 21px; }
.card-title {
  font-size: 17px; font-weight: 600; letter-spacing: -0.01em; color: var(--text);
}
.card-badge {
  margin-left: auto; font-size: 12.5px; font-weight: 500; color: var(--text-secondary);
  background: var(--fill-2); border: 1px solid var(--separator);
  padding: 4px 11px; border-radius: 999px; white-space: nowrap;
}

/* --------------------------------------------------------------------------
   7. GLUCOSE
   -------------------------------------------------------------------------- */
.glucose-hero { display: flex; align-items: baseline; gap: 12px; }
.glucose-value { font-size: 60px; font-weight: 700; line-height: 0.95; letter-spacing: -0.04em; }
.glucose-unit { color: var(--text-tertiary); font-size: 15px; font-weight: 500; }
.glucose-trend { font-size: 30px; font-weight: 600; }
.glucose-meta { color: var(--text-secondary); font-size: 13.5px; margin-top: 8px; line-height: 1.4; }

.zone-target { color: var(--green); }
.zone-low, .zone-hypo, .zone-hyper { color: var(--red); }
.zone-high { color: var(--orange); }

.glucose-chart-wrap { margin-top: 18px; height: 150px; }

.glucose-stats { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.stat {
  flex: 1; min-width: 70px; text-align: center;
  background: var(--fill-3); border: 1px solid var(--separator);
  border-radius: var(--radius-sm); padding: 12px 6px;
}
.stat .v { font-size: 21px; font-weight: 600; letter-spacing: -0.02em; }
.stat .l {
  font-size: 11px; color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: 0.04em; margin-top: 3px; font-weight: 500;
}

/* --------------------------------------------------------------------------
   8. RAPPELS / LISTES
   -------------------------------------------------------------------------- */
.rem-section-label {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-tertiary); font-weight: 600; margin: 4px 0 9px;
}
.rem-list { display: flex; flex-direction: column; gap: 7px; }
.rem-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--fill-3); border: 1px solid var(--separator);
  border-radius: var(--radius-sm); padding: 11px 13px;
  transition: background var(--dur-fast) var(--ease-out);
}
.rem-item:hover { background: var(--fill-2); }
.rem-item.overdue { border-color: color-mix(in srgb, var(--red) 32%, transparent); }
.rem-cover {
  width: 34px; height: 34px; border-radius: 10px; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 13px; font-weight: 600;
  background: var(--primary); color: #fff; letter-spacing: -0.01em;
}
.rem-body { flex: 1; min-width: 0; }
.rem-title { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rem-sub { font-size: 12.5px; color: var(--text-secondary); margin-top: 2px; }
.rem-pill {
  font-size: 11.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px; flex: 0 0 auto;
}
.rem-pill.late { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }
.rem-pill.soon { background: color-mix(in srgb, var(--orange) 16%, transparent); color: var(--orange); }
.rem-tag { font-size: 11.5px; color: var(--text-tertiary); }

/* --------------------------------------------------------------------------
   9. MATCHS
   -------------------------------------------------------------------------- */
.match-list { display: flex; flex-direction: column; gap: 7px; max-height: 440px; overflow-y: auto; padding-right: 4px; }
.match-item {
  display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 12px;
  background: var(--fill-3); border: 1px solid var(--separator);
  border-radius: var(--radius-sm); padding: 11px 13px;
  transition: background var(--dur-fast) var(--ease-out);
}
.match-item:hover { background: var(--fill-2); }
.match-time { font-size: 13px; font-weight: 600; color: var(--text-secondary); text-align: center; }
.match-time .live { color: var(--live); display: inline-flex; align-items: center; gap: 5px; font-weight: 700; }
.match-time .live::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--live); animation: pulse 1.6s ease-in-out infinite; }
.match-main { min-width: 0; }
.match-teams { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.match-comp { font-size: 11.5px; color: var(--text-tertiary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.match-sport-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; vertical-align: middle; }
.match-score { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* --------------------------------------------------------------------------
   10. ÉTATS
   -------------------------------------------------------------------------- */
.empty { color: var(--text-tertiary); font-size: 13.5px; padding: 6px 2px; }
.module-error { color: var(--red); font-size: 13.5px; }
.skeleton {
  color: var(--text-tertiary); text-align: center; padding: 100px 0; font-size: 15px;
  animation: breathe 2s ease-in-out infinite;
}
@keyframes breathe { 0%, 100% { opacity: 0.5; } 50% { opacity: 1; } }

/* --------------------------------------------------------------------------
   11. CONNEXION
   -------------------------------------------------------------------------- */
.overlay {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 20px;
  background: var(--material);
  -webkit-backdrop-filter: var(--material-blur);
  backdrop-filter: var(--material-blur);
  z-index: 50;
}
.login-card {
  width: min(380px, 92vw);
  background: var(--surface); border: 1px solid var(--separator);
  border-radius: var(--radius-xl); padding: 34px 30px;
  box-shadow: var(--shadow-pop);
  animation: card-in 0.4s var(--ease-spring) both;
}
.login-card h1 { font-size: 30px; font-weight: 700; letter-spacing: 0.06em; margin-bottom: 6px; }
.login-card p { color: var(--text-secondary); font-size: 14px; margin-bottom: 22px; }
.field { margin-bottom: 11px; }
.field input {
  width: 100%; padding: 13px 15px; border-radius: var(--radius-sm);
  background: var(--fill-2); border: 1px solid var(--separator);
  color: var(--text); font-size: 15px; font-family: inherit;
  transition: border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
.field input::placeholder { color: var(--text-tertiary); }
.field input:focus {
  outline: none; background: var(--surface);
  border-color: var(--primary);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 16%, transparent);
}
.btn {
  width: 100%; padding: 13px; border-radius: var(--radius-sm); border: none; cursor: pointer;
  background: var(--primary); color: #fff; font-size: 16px; font-weight: 600; font-family: inherit;
  margin-top: 6px; transition: filter var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: default; }
.login-error { color: var(--red); font-size: 13px; margin-top: 12px; min-height: 18px; }
.hidden { display: none !important; }

/* --------------------------------------------------------------------------
   12. PIED — méta & rafraîchissement
   -------------------------------------------------------------------------- */
.refresh-bar {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 30px; color: var(--text-tertiary); font-size: 12.5px;
}

/* --------------------------------------------------------------------------
   13. MÉTÉO
   -------------------------------------------------------------------------- */
.weather-hero { display: flex; align-items: center; gap: 18px; }
.weather-emoji { font-size: 52px; line-height: 1; }
.weather-temp { font-size: 46px; font-weight: 700; letter-spacing: -0.04em; }
.weather-label { color: var(--text-secondary); font-size: 14px; margin-top: 2px; }
.weather-range { color: var(--text-tertiary); font-size: 13px; margin-top: 3px; }
.weather-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.weather-grid .stat .v { font-size: 17px; }

/* --------------------------------------------------------------------------
   14. CLIM (surface de contrôle)
   -------------------------------------------------------------------------- */
.clim-list { display: flex; flex-direction: column; gap: 11px; }
.clim-item {
  background: var(--fill-3); border: 1px solid var(--separator);
  border-radius: var(--radius-sm); padding: 16px;
  transition: opacity var(--dur) var(--ease-out);
}
.clim-item.off { opacity: 0.55; }
.clim-top { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.clim-name { font-weight: 600; font-size: 16px; letter-spacing: -0.01em; }
.clim-room { color: var(--text-secondary); font-size: 13px; margin-top: 1px; }
.clim-offline {
  font-size: 11px; color: var(--red);
  border: 1px solid color-mix(in srgb, var(--red) 40%, transparent);
  border-radius: 999px; padding: 2px 9px;
}
.clim-power {
  margin-left: auto; width: 48px; height: 29px; border-radius: 999px; border: none; cursor: pointer;
  background: var(--fill-1); position: relative; transition: background var(--dur-fast) var(--ease-out);
}
.clim-power.on { background: var(--green); }
.clim-power::after {
  content: ''; position: absolute; top: 2.5px; left: 2.5px; width: 24px; height: 24px;
  border-radius: 50%; background: #fff; transition: transform var(--dur-fast) var(--ease-spring);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.22);
}
.clim-power.on::after { transform: translateX(19px); }
.clim-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.clim-temp { display: flex; align-items: center; gap: 6px; }
.clim-temp button {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--separator);
  background: var(--surface); color: var(--text); font-size: 20px; cursor: pointer; line-height: 1;
  transition: background var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.clim-temp button:hover { background: var(--fill-1); }
.clim-temp button:active { transform: scale(0.9); }
.clim-setpoint { font-size: 23px; font-weight: 600; min-width: 56px; text-align: center; letter-spacing: -0.02em; }
.clim-selects { display: flex; gap: 8px; margin-left: auto; }
.clim-selects select {
  background: var(--surface); border: 1px solid var(--separator); color: var(--text);
  border-radius: var(--radius-xs); padding: 8px 10px; font-size: 13px; cursor: pointer; font-family: inherit;
}
.clim-busy { opacity: 0.5; pointer-events: none; }

/* --------------------------------------------------------------------------
   15. MODULE « à configurer »
   -------------------------------------------------------------------------- */
.module-config { color: var(--text-secondary); font-size: 13.5px; line-height: 1.55; }
.module-config code {
  background: var(--fill-1); padding: 2px 7px; border-radius: 6px; font-size: 12px;
  font-family: 'SF Mono', ui-monospace, monospace;
}

/* --------------------------------------------------------------------------
   16. ACCESSIBILITÉ — réduction du mouvement
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
