/* ==========================================================================
   LAYOUT — structure générale : démarrage, connexion, menu, barre du haut
   Breakpoint principal : 960px  (au-dessus = ordinateur, en dessous = mobile/tablette)
   ========================================================================== */

/* ---------- Marque ---------- */
.brand-mark {
  width: 52px; height: 52px; border-radius: 16px; flex: none;
  display: grid; place-items: center; font-size: 25px; font-weight: 800; color: #fff;
  background: var(--grad-brand); box-shadow: var(--shadow-brand);
  position: relative; overflow: hidden;
}
.brand-mark::after { /* reflet */
  content: ''; position: absolute; inset: 0 0 50% 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, .28), transparent);
}
.brand-mark--xl { width: 68px; height: 68px; font-size: 32px; border-radius: 20px; }

/* ---------- Écran de démarrage ---------- */
.boot {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: var(--bg);
}
.boot__logo { font-size: 24px; font-weight: 800; letter-spacing: -.03em; }
.boot__logo span { color: var(--brand-600); }
.boot__bar { width: 140px; height: 4px; border-radius: 9px; background: var(--surface-3); overflow: hidden; }
.boot__bar span { display: block; width: 40%; height: 100%; border-radius: inherit; background: var(--grad-brand); animation: slide 1.1s var(--ease) infinite; }
@keyframes slide { from { transform: translateX(-110%); } to { transform: translateX(260%); } }

/* ---------- Écran de connexion ---------- */
.login { position: fixed; inset: 0; z-index: 90; display: grid; grid-template-columns: 1.05fr 1fr; background: var(--bg); overflow-y: auto; }
.login__hero {
  position: relative; overflow: hidden; color: #fff; display: flex; align-items: center; padding: 56px;
  background:
    radial-gradient(600px 400px at 85% 10%, rgba(168, 85, 247, .55), transparent 60%),
    radial-gradient(700px 500px at 0% 100%, rgba(56, 189, 248, .35), transparent 60%),
    linear-gradient(160deg, #1e1b4b 0%, #312e81 45%, #4c1d95 100%);
}
.login__hero::before { /* grille décorative */
  content: ''; position: absolute; inset: 0; opacity: .14;
  background-image: linear-gradient(rgba(255, 255, 255, .5) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, .5) 1px, transparent 1px);
  background-size: 44px 44px; mask-image: radial-gradient(circle at 30% 40%, #000, transparent 75%);
  -webkit-mask-image: radial-gradient(circle at 30% 40%, #000, transparent 75%);
}
.login__hero-inner { position: relative; max-width: 480px; }
.login__hero-brand { display: flex; align-items: center; gap: 12px; font-weight: 800; font-size: 19px; margin-bottom: 52px; }
.login__hero-brand .brand-mark { width: 42px; height: 42px; font-size: 20px; border-radius: 13px; background: rgba(255, 255, 255, .16); box-shadow: none; border: 1px solid rgba(255, 255, 255, .25); }
.login__hero h2 { font-size: 36px; line-height: 1.15; font-weight: 800; letter-spacing: -.035em; }
.login__features { list-style: none; padding: 0; margin: 28px 0 40px; display: grid; gap: 14px; font-size: 15px; color: rgba(255, 255, 255, .85); }
.login__features li { display: flex; gap: 12px; align-items: center; }
.login__features span { width: 24px; height: 24px; border-radius: 8px; display: grid; place-items: center; background: rgba(255, 255, 255, .16); font-size: 12px; flex: none; }
.login__hero-card { display: flex; gap: 14px; }
.login__hero-stat { flex: 1; padding: 16px 18px; border-radius: 16px; background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .14); backdrop-filter: blur(8px); }
.login__hero-stat b { display: block; font-size: 26px; letter-spacing: -.03em; }
.login__hero-stat small { color: rgba(255, 255, 255, .7); font-size: 12.5px; }

.login__side { display: grid; place-items: center; padding: 32px 20px; }
.login__card { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 18px; }
.login__brand { margin-bottom: 8px; }
.login__brand .brand-mark { display: none; margin-bottom: 18px; }
.login__brand h1 { font-size: 28px; font-weight: 800; letter-spacing: -.035em; }
.login__brand p { color: var(--text-2); font-size: 14.5px; margin-top: 6px; }
.login__foot { text-align: center; font-size: 12.5px; color: var(--text-3); }

@media (max-width: 960px) {
  .login { grid-template-columns: 1fr; background: radial-gradient(600px 380px at 50% -10%, color-mix(in srgb, var(--brand-500) 22%, transparent), transparent 70%), var(--bg); }
  .login__hero { display: none; }
  .login__brand { text-align: center; }
  .login__brand .brand-mark { display: grid; margin: 0 auto 18px; }
  .login__card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); padding: 30px 24px; box-shadow: var(--shadow-lg); }
}

/* ---------- Application ---------- */
.app { min-height: 100vh; min-height: 100dvh; }
.main { margin-left: var(--sidebar-w); min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

/* ---------- Menu latéral (sombre) ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40; width: var(--sidebar-w);
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--side-bg-2) 0%, var(--side-bg) 60%);
  color: var(--side-text); padding: 20px 14px 14px; overflow-y: auto;
  scrollbar-color: rgba(255, 255, 255, .15) transparent;
}
.sidebar::before { /* halo de couleur en haut */
  content: ''; position: absolute; top: -120px; left: -60px; width: 300px; height: 260px; pointer-events: none;
  background: radial-gradient(circle, rgba(99, 102, 241, .35), transparent 65%);
}
.sidebar__brand { position: relative; display: flex; align-items: center; gap: 12px; padding: 2px 8px 22px; }
.sidebar__brand .brand-mark { width: 38px; height: 38px; font-size: 18px; border-radius: 12px; }
.sidebar__brand strong { display: block; font-size: 17px; letter-spacing: -.03em; font-weight: 800; color: #fff; }
.sidebar__brand small { display: block; font-size: 11.5px; color: var(--side-muted); font-weight: 500; }

.nav-group { position: relative; margin-bottom: 16px; }
.nav-group__label {
  padding: 0 12px 7px; font-size: 10.5px; font-weight: 700; color: var(--side-muted);
  text-transform: uppercase; letter-spacing: .1em;
}
.nav-link {
  position: relative; display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 9px 12px; margin-bottom: 2px; border: 0; border-radius: var(--r-sm); background: transparent;
  color: var(--side-text); font-weight: 600; font-size: 13.5px; text-align: left; text-decoration: none;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.nav-link:hover { background: var(--side-hover); color: #fff; text-decoration: none; }
.nav-link .i { width: 18px; height: 18px; opacity: .75; transition: opacity .18s; }
.nav-link:hover .i { opacity: 1; }
.nav-link[aria-current="page"] {
  color: #fff; background: linear-gradient(90deg, rgba(99, 102, 241, .32), rgba(99, 102, 241, .10));
  box-shadow: inset 0 0 0 1px rgba(129, 140, 248, .25);
}
.nav-link[aria-current="page"] .i { opacity: 1; color: #a5b4fc; }
.nav-link[aria-current="page"]::before {
  content: ''; position: absolute; left: -14px; top: 9px; bottom: 9px; width: 4px; border-radius: 0 4px 4px 0;
  background: var(--grad-brand);
}
.nav-link__badge {
  margin-left: auto; min-width: 22px; padding: 1px 7px; border-radius: 99px;
  background: #f59e0b; color: #1f1300; font-size: 11px; font-weight: 800; text-align: center;
}

.sidebar__user {
  position: relative; margin-top: auto; padding: 12px; border-radius: var(--r-md);
  background: rgba(255, 255, 255, .05); border: 1px solid var(--side-border);
  display: flex; align-items: center; gap: 10px;
}
.sidebar__user-info { min-width: 0; flex: 1; }
.sidebar__user-info strong { display: block; font-size: 12.5px; color: #fff; }
.sidebar__user-info span { display: block; font-size: 11px; color: var(--side-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar__user .icon-btn { color: var(--side-text); }
.sidebar__user .icon-btn:hover { background: var(--side-hover); color: #fff; }

.sidebar-backdrop {
  position: fixed; inset: 0; z-index: 35; background: rgba(5, 8, 20, .55);
  backdrop-filter: blur(3px); opacity: 0; pointer-events: none; transition: opacity .25s var(--ease);
}

/* ---------- Barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) 28px 0;
  display: flex; align-items: center; gap: 12px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(18px) saturate(1.6); -webkit-backdrop-filter: blur(18px) saturate(1.6);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}
.topbar__title { display: none; font-size: 17px; font-weight: 800; letter-spacing: -.02em; }
.topbar__spacer { flex: 1; }
.icon-btn.topbar__burger { display: none; }
.topbar__create .i { width: 18px; height: 18px; }

/* Bouton de recherche globale */
.search-trigger {
  display: flex; align-items: center; gap: 10px; width: min(420px, 40vw); height: 40px; padding: 0 8px 0 13px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text-3);
  font-size: 13.5px; box-shadow: var(--shadow-xs); transition: border-color .15s, box-shadow .15s;
}
.search-trigger:hover { border-color: var(--border-2); box-shadow: var(--shadow-sm); }
.search-trigger .i { width: 17px; height: 17px; }
.search-trigger span:not(.kbd) { flex: 1; text-align: left; }
.kbd {
  font-family: var(--font); font-size: 11px; font-weight: 700; color: var(--text-3);
  padding: 2px 7px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2);
}

/* Indicateur de synchronisation */
.sync {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 10px;
  border-radius: 99px; font-size: 12px; font-weight: 700;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-2);
}
.sync__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.sync--ok .sync__dot      { background: var(--success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 25%, transparent); }
.sync--pending .sync__dot { background: var(--warning); animation: pulse 1s infinite; }
.sync--offline .sync__dot { background: var(--danger); }
.sync--error { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.sync--error .sync__dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- Zone de contenu ---------- */
.page { flex: 1; padding: 28px 28px 48px; width: 100%; max-width: 1320px; margin: 0 auto; outline: none; }
.page > div { animation: page-in .35s var(--ease); }
@keyframes page-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Bouton flottant & barre du bas (mobile uniquement) ---------- */
.fab, .bottom-nav { display: none; }

/* ==========================================================================
   MOBILE & TABLETTE  (< 960px)
   ========================================================================== */
@media (max-width: 960px) {
  .main { margin-left: 0; }

  /* Le menu devient un tiroir qui glisse depuis la gauche */
  .sidebar {
    width: min(86vw, 320px); transform: translateX(-102%);
    transition: transform .3s var(--ease); box-shadow: var(--shadow-lg);
    padding-top: calc(20px + var(--safe-top)); padding-bottom: calc(14px + var(--safe-bottom));
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }

  .topbar { padding-left: 10px; padding-right: 10px; gap: 6px; height: calc(58px + var(--safe-top)); }
  .icon-btn.topbar__burger { display: inline-grid; }
  .topbar__title { display: block; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar__spacer, .btn.topbar__create, .sync__label, .search-trigger span { display: none; }
  .search-trigger { width: 40px; height: 40px; padding: 0; justify-content: center; border-color: transparent; background: transparent; box-shadow: none; color: var(--text-2); }
  .search-trigger .i { width: 20px; height: 20px; }
  .sync { padding: 8px; border-color: transparent; background: transparent; }

  .page { padding: 18px 14px calc(var(--bottom-nav-h) + var(--safe-bottom) + 90px); }

  /* Bouton flottant d'ajout */
  .fab {
    display: grid; place-items: center; position: fixed; z-index: 31;
    right: 18px; bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 16px);
    width: 58px; height: 58px; border-radius: 19px; border: 0; color: #fff;
    background: var(--grad-brand); box-shadow: var(--shadow-brand), 0 4px 14px rgba(0, 0, 0, .18);
    transition: transform .15s var(--ease);
  }
  .fab:active { transform: scale(.94); }
  .fab .i { width: 26px; height: 26px; }
  .fab[hidden] { display: none !important; }

  /* Barre d'onglets en bas */
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; inset: auto 0 0 0; z-index: 30;
    height: calc(var(--bottom-nav-h) + var(--safe-bottom)); padding: 0 6px var(--safe-bottom);
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(20px) saturate(1.6); -webkit-backdrop-filter: blur(20px) saturate(1.6);
    border-top: 1px solid var(--border);
  }
  .bottom-nav__item {
    position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    border: 0; background: transparent; color: var(--text-3); font-size: 10.5px; font-weight: 700;
    text-decoration: none; padding: 6px 2px;
  }
  .bottom-nav__item .i { width: 22px; height: 22px; transition: transform .2s var(--ease); }
  .bottom-nav__item[aria-current="page"] { color: var(--brand-600); }
  .bottom-nav__item[aria-current="page"] .i { transform: translateY(-1px); }
  .bottom-nav__item[aria-current="page"]::before {
    content: ''; position: absolute; top: 0; left: 30%; right: 30%; height: 3px; border-radius: 0 0 4px 4px; background: var(--grad-brand);
  }
  .bottom-nav__item:hover { text-decoration: none; }
}

@media (min-width: 961px) { .sidebar-backdrop { display: none; } }
@media (max-width: 1180px) and (min-width: 961px) { .search-trigger { width: 260px; } }

/* Impression de l'écran (rarement utilisé : les documents ont leur propre rendu) */
@media print {
  .sidebar, .topbar, .bottom-nav, .fab { display: none !important; }
  .main { margin: 0; }
}
