/* ============================================================
   LAYOUT — App shell, sidebar, header, content
   Mobile-first: mobile = bottom nav, desktop = sidebar
   ============================================================ */

/* === App root ============================================== */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* === Login layout (no shell) =============================== */
.login-screen {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: var(--sp-lg);
  background: linear-gradient(135deg, var(--c-primary) 0%, var(--c-primary-light) 100%);
}

/* === App shell ============================================= */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* --- Mobile header ----------------------------------------- */
.mobile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 var(--sp-lg);
  background: var(--c-primary);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: var(--z-sidebar);
}

.mobile-header__title {
  font-size: 16px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mobile-header__burger {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  border-radius: var(--r-sm);
  transition: background .15s var(--ease);
}
.mobile-header__burger:hover { background: rgba(255,255,255,.12); }

.mobile-header__burger svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

/* --- Sidebar ----------------------------------------------- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--c-primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  z-index: var(--z-sidebar);
  transform: translateX(-100%);
  transition: transform .25s var(--ease);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: calc(var(--z-sidebar) - 1);
}
.sidebar-overlay.open {
  display: block;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: var(--sp-xl) var(--sp-lg);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -.02em;
  border-bottom: 1px solid rgba(255,255,255,.1);
  flex-shrink: 0;
}

.sidebar__brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c-accent);
  flex-shrink: 0;
}

.sidebar__section {
  padding: var(--sp-lg) var(--sp-sm) var(--sp-sm);
}

.sidebar__section--advanced {
  padding-top: var(--sp-md);
}

.sidebar__section-label {
  padding: 0 var(--sp-sm);
  margin-bottom: var(--sp-xs);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.4);
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: var(--sp-sm) var(--sp-md);
  border-radius: var(--r-sm);
  font-size: 14px;
  font-weight: 600;
  color: rgba(255,255,255,.7);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition: background .12s var(--ease), color .12s var(--ease);
}
.sidebar__link:hover {
  background: rgba(255,255,255,.08);
  color: #fff;
  text-decoration: none;
}
.sidebar__link.active {
  background: rgba(255,255,255,.14);
  color: #fff;
}

.sidebar__link svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: .7;
}
.sidebar__link.active svg { opacity: 1; }

.sidebar__advanced {
  padding: var(--sp-md) var(--sp-sm) var(--sp-sm);
}

.sidebar__advanced-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-sm);
  width: 100%;
  padding: var(--sp-sm) var(--sp-md);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: var(--r-md);
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.85);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.sidebar__advanced-toggle:hover {
  background: rgba(255,255,255,.1);
  color: #fff;
}

.sidebar__advanced-body {
  margin-top: var(--sp-sm);
  padding-top: var(--sp-xs);
  border-top: 1px solid rgba(255,255,255,.08);
}

.sidebar__link-badge {
  margin-left: auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--r-full);
  background: var(--c-accent);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sidebar__footer {
  margin-top: auto;
  padding: var(--sp-lg);
  border-top: 1px solid rgba(255,255,255,.1);
  flex-shrink: 0;
}

.sidebar__user {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  font-size: 13px;
  color: rgba(255,255,255,.6);
}

.sidebar__logout {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-xs);
  margin-top: var(--sp-sm);
  padding: var(--sp-xs) var(--sp-sm);
  border-radius: var(--r-sm);
  background: none;
  border: 1px solid rgba(255,255,255,.15);
  color: rgba(255,255,255,.6);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.sidebar__logout:hover {
  background: rgba(255,255,255,.08);
  color: #fff;
}

.sidebar__logout--secondary {
  opacity: .72;
}

/* --- Main content area ------------------------------------- */
.main-content {
  flex: 1;
  padding: var(--sp-lg);
  min-width: 0;
}

.main-content__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-md);
  flex-wrap: wrap;
  margin-bottom: var(--sp-xl);
}

.main-content__title {
  font-size: 20px;
  font-weight: 800;
  color: var(--c-primary);
}

.main-content__subtitle {
  font-size: 13px;
  color: var(--c-text-secondary);
  margin-top: 2px;
}

/* View transition */
.view {
  animation: view-enter .2s var(--ease);
}
@keyframes view-enter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === View container ======================================== */
.view {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

/* === Desktop (>= 1024px) =================================== */
@media (min-width: 1024px) {
  .mobile-header { display: none; }
  .sidebar-overlay { display: none !important; }

  .sidebar {
    transform: translateX(0);
    position: fixed;
  }

  .app-shell {
    flex-direction: row;
  }

  .main-content {
    margin-left: var(--sidebar-w);
    padding: var(--sp-xl) var(--sp-2xl);
  }
}

/* === Tablet (768px - 1023px) =============================== */
@media (min-width: 768px) and (max-width: 1023px) {
  .main-content {
    padding: var(--sp-lg) var(--sp-xl);
  }
}

/* === Impression ============================================ */
@media print {
  .sidebar, .sidebar-overlay, .mobile-header { display: none !important; }
  .main-content { margin-left: 0 !important; padding: 16px !important; }
  .btn { display: none !important; }
  .section-block__header .btn { display: none !important; }
  body { background: #fff !important; }
}

/* === Petit ecran (480px et moins) ========================== */
@media (max-width: 480px) {
  .main-content__header {
    flex-direction: column;
    align-items: flex-start;
  }
  .main-content__title {
    font-size: 18px;
  }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .led-scenes {
    grid-template-columns: 1fr;
  }
  .section-block__header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .btn { min-height: 44px; font-size: 14px; }
  .btn-sm { min-height: 38px; }
  .field__input, .field__select, .field__textarea { min-height: 44px; font-size: 16px; }
  .sidebar__link { padding: 12px 16px; font-size: 15px; }
  .card { padding: 14px; }
  .form-row--2, .form-row--3 { grid-template-columns: 1fr; }
}
