/* ============================================================
   LAYOUT.CSS — Variables globales + Structure principale
   ============================================================
   CHARGEMENT : Ce fichier DOIT être chargé EN PREMIER.
   Il définit toutes les variables CSS utilisées dans l'app.
   ============================================================ */

/* ============================================================
   POLICES — Funnel Sans / Funnel Display (design XD, licence OFL)
   ============================================================ */
@font-face {
  font-family: 'Funnel Sans';
  font-style: normal;
  font-weight: 300 800;
  font-display: swap;
  src: url('../assets/fonts/FunnelSans-latin.woff2') format('woff2');
}
@font-face {
  font-family: 'Funnel Sans';
  font-style: italic;
  font-weight: 300 800;
  font-display: swap;
  src: url('../assets/fonts/FunnelSans-Italic-latin.woff2') format('woff2');
}
@font-face {
  font-family: 'Funnel Display';
  font-style: normal;
  font-weight: 300 800;
  font-display: swap;
  src: url('../assets/fonts/FunnelDisplay-latin.woff2') format('woff2');
}

/* ============================================================
   DESIGN TOKENS — Source unique de vérité
   ============================================================ */
:root {

  /* --- COULEURS PRINCIPALES --- */
  --accent:           #007FFF;
  --accent-hover:     #0066CC;
  --accent-glow:      rgba(0, 127, 255, 0.4);
  --accent-glow-sm:   rgba(0, 123, 255, 0.2);
  --accent-cyan:      #00f2ff;

  /* --- BACKGROUNDS --- */
  --bg-main:          #0b0e14;
  --bg-dark:          #0F1726;
  --bg-side:          #111418;
  --bg-card:          #222A3F;
  --bg-input:         #0b0f15;
  --bg-input-deep:    #0f172a;
  --bg-hover:         #1e2533;
  --bg-hover-deep:    #1e293b;
  --bg-info:          #303C59;
  --bg-overlay:       rgba(10, 12, 18, 0.85);

  /* --- TEXTES --- */
  --text-main:        #FFFFFF;
  --text-muted:       #8b949e;
  --text-soft:        #8a92a6;
  --text-dim:         #606A80;
  --text-body:        #c9d1d9;
  --text-light:       #ced4da;
  --text-slate:       #94a3b8;
  --text-blue-gray:   #cbd5e0;

  /* --- BORDURES --- */
  --border-subtle:    #1e2533;
  --border-default:   #252f3d;
  --border-medium:    #303746;
  --border-strong:    #334155;
  --border-nav:       #21262d;
  --border-muted:     #30363d;
  --border-deep:      #3d4659;

  /* --- STATUTS --- */
  --status-ready:     #57D147;
  --status-ready-bg:  rgba(87, 209, 71, 0.15);
  --status-off:       #FF3B30;
  --status-off-bg:    #3d1a1a;
  --status-off-text:  #ff4d4d;
  --status-online:    #2ecc71;
  --status-error:     #e74c3c;

  /* --- TYPOGRAPHIE --- */
  --font-body:        'Funnel Sans', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-display:     'Funnel Display', 'Funnel Sans', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-ui:          'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  --text-xs:          9px;
  --text-sm:          11px;
  --text-base:        13px;
  --text-md:          14px;
  --text-lg:          16px;
  --text-xl:          18px;
  --text-2xl:         20px;
  --text-nav:         14px;
  --text-carousel:    52px; /* flèches carrousel */

  /* --- ESPACEMENT --- */
  --space-xs:         4px;
  --space-sm:         8px;
  --space-md:         12px;
  --space-lg:         15px;
  --space-xl:         20px;
  --space-2xl:        25px;
  --space-3xl:        30px;
  --space-page-x:     40px;  /* marge gauche pages */
  --space-page-xr:    96px;  /* marge droite pages */

  /* --- ARRONDI --- */
  --radius-xs:        2px;
  --radius-sm:        4px;
  --radius-md:        6px;
  --radius-lg:        8px;
  --radius-xl:        10px;
  --radius-2xl:       12px;
  --radius-pill:      16px;
  --radius-round:     50%;
  --radius-badge:     34px;
  --radius-tooltip:   18px;

  /* --- OMBRES --- */
  --shadow-card:      0px 4px 8px rgba(0, 0, 0, 0.05);
  --shadow-card-lg:   0px 8px 16px rgba(0, 0, 0, 0.16);
  --shadow-glow:      0 0 10px var(--accent-cyan), 0 0 20px var(--accent-glow);
  --shadow-glow-sm:   0px 0px 8px rgba(0, 127, 255, 0.3);
  --shadow-glow-thumb: 0px 0px 10px #B3D2FF;
  --shadow-modal:     0 15px 50px rgba(0, 0, 0, 0.6);
  --shadow-dropdown:  0 8px 20px rgba(0, 0, 0, 0.6);
  --shadow-tooltip:   8px 8px 0 #000, 0 15px 35px rgba(0, 0, 0, 0.45);
  --shadow-accent-sm: 0 4px 12px var(--accent-glow-sm);
  --shadow-inset:     inset 0 1px 4px rgba(0, 0, 0, 0.5);
  --shadow-game-sel:  inset 0px 0px 32px #000000, 0px 0px 32px #0E151D;

  /* --- TRANSITIONS --- */
  --t-fast:           0.2s;
  --t-base:           0.3s;
  --t-ease:           0.2s ease;
  --t-ease-base:      0.3s ease;
  --t-cubic:          0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --t-spring:         0.25s cubic-bezier(.2, 1.4, .4, 1);
  --t-transform:      transform 0.2s ease;
  --t-opacity:        opacity 0.25s ease;
  --t-color:          color 0.2s ease;
  --t-bg:             background 0.2s;
  --t-all:            all 0.2s ease;

  /* --- STRUCTURE APP --- */
  --sidebar-width:    200px;
  --header-height:    50px;
  --footer-height:    35px;
}

/* ============================================================
   RESET COMPLÉMENTAIRE
   ============================================================ */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  overflow: hidden;
  height: 100vh;
}

/* Tactile : un swipe vertical démarré sur un slider fait défiler la page
   (le slider ne capte que les gestes horizontaux). */
input[type="range"] {
  touch-action: pan-y;
}

/* ============================================================
   STRUCTURE PRINCIPALE
   ============================================================ */
#app {
  display: grid;
  grid-template-columns: auto 1fr;
  height: calc(100vh - var(--header-height));
  background: var(--bg-dark);
}

/* ============================================================
   TITLEBAR
   ============================================================ */
.custom-titlebar {
  height: var(--header-height);
  background: var(--bg-dark);
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 10000;
  border-bottom: 1px solid #333;
}

.titlebar-drag-region {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  -webkit-app-region: drag;
}

.titlebar-logo {
  height: 22px;
  margin-left: 15px;
  -webkit-app-region: no-drag;
}

.window-controls {
  display: flex;
  height: 100%;
  -webkit-app-region: no-drag;
}

.control-btn {
  width: 45px;
  height: 100%;
  border: none;
  background: transparent;
  color: var(--text-main);
  cursor: pointer;
  transition: var(--t-fast);
}

.control-btn:hover          { background: #333; }
.control-btn.close:hover    { background: var(--status-error); }

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-width);
  height: 100%;
  background-color: var(--bg-dark);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 100;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  padding-top: 10px;
  width: 100%;
}

.nav-btn {
  display: flex;
  align-items: center;
  width: 100%;
  height: 60px;
  background: transparent;
  border: none;
  cursor: pointer;
  position: relative;
  text-decoration: none;
  margin-top: 10%;
  margin-left: 20%;
}

.nav-btn .nav-icon-wrapper {
  width: 48px;
  height: 48px;
  background: #222A3F;
  border-radius: var(--radius-sm);
  margin-left: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-btn.active .nav-icon-wrapper {
  background: var(--accent);
}

.nav-btn .nav-icon {
  width: 24px;
  height: 24px;
  opacity: 0.5;
}

.nav-btn.active .nav-icon {
  opacity: 1;
}

.nav-text {
  color: var(--text-main);
  font-size: var(--text-nav);
  line-height: 18px;
  opacity: 0.5;
  white-space: nowrap;
  margin-left: 10px;
}

.nav-btn.active .nav-text {
  font-weight: 600;
  opacity: 1;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main {
  overflow: hidden;
  background-color: var(--bg-main);
}

#page-container {
  height: 100%;
  background: var(--bg-dark);
  border-radius: var(--radius-sm);
}

/* ============================================================
   SCROLLBAR CUSTOM
   ============================================================ */
::-webkit-scrollbar               { width: 6px; height: 6px; }
::-webkit-scrollbar-track         { background: transparent; }
::-webkit-scrollbar-thumb         { background: #333; border-radius: 10px; border: 2px solid transparent; }
::-webkit-scrollbar-thumb:hover   { background: #444; }

/* ============================================================
   FOOTER
   ============================================================ */
.app-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: var(--footer-height);
  background: var(--bg-dark);
  border-top: 1px solid #333;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 15px;
  font-family: var(--font-display);
  font-size: 12px;
  color: #666;
  z-index: 9999;
}

.footer-left              { display: flex; align-items: center; gap: 15px; }
.brand-text               { font-weight: bold; color: #999; }
.footer-devices           { display: flex; gap: var(--space-md); }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-round);
  display: inline-block;
  margin-right: var(--space-xs);
}
.status-dot.online        { background: var(--status-online); box-shadow: 0 0 5px var(--status-online); }
.status-dot.offline       { background: var(--status-error);  box-shadow: 0 0 5px var(--status-error); }

.social-links             { display: flex; gap: var(--space-md); }
.social-icon img          { width: 14px; filter: grayscale(1) opacity(0.5); transition: var(--t-fast); }
.social-icon img:hover    { filter: grayscale(0) opacity(1); }

/* ============================================================
   INFO ICON
   ============================================================ */
.info-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  cursor: pointer;
  z-index: 50;
  transition: var(--t-opacity), var(--t-transform);
}

.info-icon img {
  width: 100%;
  height: 100%;
  opacity: 0.8;
  transition: var(--t-transform), opacity var(--t-fast);
}

body.tooltip-open .info-icon           { opacity: 0.35; }
body.tooltip-open .info-icon.active    { opacity: 1; z-index: 1000; }
body:not(.tooltip-open) .info-icon:hover img { transform: scale(1.15); opacity: 1; }
body.tooltip-open .sidebar             { opacity: 0.35; transition: var(--t-opacity); }
body:not(.tooltip-open) .sidebar       { opacity: 1; transition: var(--t-opacity); }

/* ============================================================
   TOOLTIP COMIC — Triangle rectangle BD (gauche par défaut)
   ============================================================ */
.comic-tooltip {
  position: fixed;
  width: 280px;
  background: var(--bg-info);
  color: var(--text-main);
  border: 4px solid #000;
  border-radius: var(--radius-tooltip);
  padding: 16px;
  box-shadow: var(--shadow-tooltip);
  opacity: 0;
  visibility: hidden;
  transform: scale(0.85) translateY(-4px);
  transition: opacity var(--t-fast), transform var(--t-spring), visibility 0s linear var(--t-fast);
  z-index: 999;
  pointer-events: none;
  /* Position verticale de la flèche sur le côté (JS override via --arrow-top) */
  --arrow-top: 14px;
}

/* ── Triangle rectangle en BAS-GAUCHE de la bulle (défaut) ────────────────
   Angle droit au coin bas-gauche.
   Deux pseudo-éléments : bordure noire + remplissage couleur bulle.        */

/* Bordure noire */
.comic-tooltip::before {
  content: "";
  position: absolute;
  bottom: -22px;
  left: 14px;
  width: 0;
  height: 0;
  border-top: 22px solid #000;
  border-right: 22px solid transparent;
}

/* Remplissage couleur bulle */
.comic-tooltip::after {
  content: "";
  position: absolute;
  bottom: -15px;
  left: 16px;
  width: 0;
  height: 0;
  border-top: 16px solid var(--bg-info);
  border-right: 18px solid transparent;
}

/* ── Variante : triangle en BAS-DROITE ───────────────────────────────────── */
.comic-tooltip.arrow-right::before {
  left: auto;
  right: 14px;
  border-right: none;
  border-left: 22px solid transparent;
  border-top: 22px solid #000;
}

.comic-tooltip.arrow-right::after {
  left: auto;
  right: 16px;
  border-right: none;
  border-left: 18px solid transparent;
  border-top: 16px solid var(--bg-info);
}

.comic-tooltip p {
  margin: 0;
  font-size: var(--text-md);
  line-height: 1.5;
  font-weight: 600;
  font-style: normal;
}

/* État actif */
.info-icon.active ~ .comic-tooltip,
.comic-tooltip.active-tooltip {
  opacity: 1;
  visibility: visible;
  transform: scale(1) translateY(0);
  transition: opacity var(--t-fast), transform var(--t-spring);
  pointer-events: none;
}

/* ============================================================
   BACKDROP
   ============================================================ */
#tooltip-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: var(--t-opacity);
  z-index: 40;
}
#tooltip-backdrop.active { opacity: 1; pointer-events: auto; }

/* ============================================================
   RESPONSIVE — TABLET / MOBILE
   ============================================================ */
@media (hover: none) and (pointer: coarse) {
  :root {
    --space-page-x: 16px;
    --space-page-xr: 16px;
    --sidebar-width: 100%;
    --header-height: 0px;   /* titlebar masqué sur mobile */
    --bottomnav-height: 64px;
  }

  body {
    height: 100dvh;
  }

  /* Titlebar (logo OPLITE) masqué : surface d'écran fonctionnelle maximale. */
  .custom-titlebar {
    display: none;
  }

  body > br,
  .sidebar > br {
    display: none;
  }

  .titlebar-drag-region {
    justify-content: flex-start;
  }

  .window-controls {
    display: none;
  }

  #app {
    display: block;
    height: 100dvh;
    padding-top: env(safe-area-inset-top, 0px);   /* encoche/barre d'état */
  }

  /* Tactile pur : le contrôle natif ne reçoit plus les touchers — le geste
     est arbitré par le contrôleur de global.js (vertical = scroll,
     horizontal = réglage). */
  input[type="range"] {
    pointer-events: none;
  }

  /* ── Barre de navigation basse (XD p.9 : Groupe 141) ──────────────
     Fond #0F1726 à 50 % + blur d'arrière-plan, séparateur en haut,
     4 cellules égales, item actif = bloc #007FFF pleine cellule. */
  .sidebar {
    display: flex;
    align-items: stretch;
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: calc(var(--bottomnav-height) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(15, 23, 38, 0.5);
    -webkit-backdrop-filter: blur(50px);
    backdrop-filter: blur(50px);
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    z-index: 10020;
  }

  .sidebar nav {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    align-items: stretch;
    justify-items: stretch;
    gap: 0;
    width: 100%;
    margin-left: 0;
    height: 100%;
    padding: 0;
  }

  .nav-btn {
    width: 100%;
    height: 100%;
    min-width: 0;
    margin: 0;
    padding: 6px 0 8px;
    border-radius: 0;
    background: transparent;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    opacity: 0.75;
  }

  .nav-btn.active {
    background: #007FFF;
    opacity: 1;
  }

  .nav-btn .nav-icon-wrapper,
  .nav-btn.active .nav-icon-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    width: 24px;
    height: 24px;
    background: transparent;
    border-radius: 0;
  }

  .nav-btn .nav-icon,
  .nav-btn.active .nav-icon {
    width: 24px;
    height: 24px;
    filter: brightness(0) invert(1);   /* icônes blanches (XD) */
  }

  .nav-text,
  .nav-btn.active .nav-text {
    display: block;
    width: 100%;
    margin-left: 0;
    font-size: 11px;
    line-height: 1.05;
    white-space: nowrap;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #FFFFFF;
  }

  .main {
    height: calc(100dvh - env(safe-area-inset-top, 0px)
                 - var(--bottomnav-height) - env(safe-area-inset-bottom, 0px));
    min-height: 0;
  }

  #page-container {
    border-radius: 0;
  }

  /* En plein écran (API Fullscreen), la barre d'état Android disparaît :
     on récupère l'espace réservé à l'encoche au-dessus du contenu. */
  html:fullscreen #app {
    padding-top: 0;
  }

  html:fullscreen .main {
    height: calc(100dvh - var(--bottomnav-height) - env(safe-area-inset-bottom, 0px));
  }

  .app-footer {
    display: none;
  }

  .comic-tooltip {
    width: min(260px, calc(100vw - 24px));
  }
}

@media (hover: none) and (pointer: coarse) and (max-width: 480px) {
  .comic-tooltip {
    width: min(240px, calc(100vw - 20px));
  }
}