/* ==========================================================================
   layout.css — Structure, header, navigation, landing, home, modules
   Mobile-first — KekOnFait — Theme clair
   ========================================================================== */

/* --------------------------------------------------------------------------
   Header — blanc, propre, ombre subtile
   -------------------------------------------------------------------------- */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-lg);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: var(--z-header);
}

.header__left {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.header__logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 800;
  color: white;
  background: var(--primary);
  border-radius: var(--radius-md);
  line-height: 1;
}

.header__brand {
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1;
}

.header__right {
  display: flex;
  align-items: center;
}

.header__settings {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 500;
  transition: all var(--transition-base);
  -webkit-tap-highlight-color: transparent;
}

.header__settings:hover {
  background: var(--bg-secondary);
  border-color: var(--border-hover);
  color: var(--text);
}

.header__group-name {
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Presence indicator — avatar bubbles in header
   -------------------------------------------------------------------------- */
.presence {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 0 var(--space-sm);
  min-width: 0;
}

.presence__bubble {
  position: relative;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 2px solid var(--bg);
  margin-left: -8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition-fast);
  flex-shrink: 0;
}

.presence__bubble:first-child {
  margin-left: 0;
}

.presence__bubble:hover {
  transform: translateY(-2px);
  z-index: 10 !important; /* Exception justifiee : hover doit depasser le stacking */
}

.presence__avatar {
  width: 20px;
  height: 20px;
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.presence__avatar svg {
  width: 100%;
  height: 100%;
}

.presence__dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 8px;
  height: 8px;
  background: var(--success);
  border: 2px solid var(--bg);
  border-radius: 50%;
}

.presence__overflow {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 2px solid var(--bg);
  margin-left: -8px;
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 700;
  color: var(--text-secondary);
  flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   Navigation — bottom bar mobile, blanc
   -------------------------------------------------------------------------- */
.nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  padding: 4px 0;
  padding-bottom: max(4px, env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow-up);
  z-index: var(--z-nav);
}

.nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1;
  padding: 6px 0;
  background: none;
  border: none;
  color: var(--text-tertiary);
  transition: color var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.nav__item:hover,
.nav__item--active {
  color: var(--primary);
}

.nav__item--active::after {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 3px;
  background: var(--primary);
  border-radius: var(--radius-full);
}

.nav__icon {
  font-size: 20px;
  line-height: 1;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav__icon-svg {
  width: 22px;
  height: 22px;
}

.nav__label {
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1;
}

/* --------------------------------------------------------------------------
   Main content
   -------------------------------------------------------------------------- */
.main {
  min-height: 100vh;
  min-height: 100dvh;
}

.main--app {
  padding-top: var(--header-height);
  padding-bottom: calc(var(--nav-height) + max(4px, env(safe-area-inset-bottom, 0px)));
}

/* --------------------------------------------------------------------------
   Screen base
   -------------------------------------------------------------------------- */
.screen {
  min-height: 100vh;
  min-height: 100dvh;
}

.screen--auth {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  padding-top: 56px;
  overflow-x: hidden;
}

.screen--home,
.screen--module,
.screen--journal,
.screen--stats {
  padding: var(--space-lg);
}

/* ==========================================================================
   LANDING PAGE
   ========================================================================== */

/* --------------------------------------------------------------------------
   Landing Header — sticky, compact auth
   -------------------------------------------------------------------------- */
.landing-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-md);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: var(--z-header);
}

.landing-header__left {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.landing-header__logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 800;
  color: white;
  background: var(--primary);
  border-radius: var(--radius-md);
  line-height: 1;
}

.landing-header__brand {
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.landing-header__right {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.landing-header__join {
  display: flex;
  align-items: center;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  overflow: hidden;
  transition: border-color var(--transition-base);
}

.landing-header__join:focus-within {
  border-color: var(--primary);
}

.landing-header__input {
  width: 80px;
  padding: 6px 12px;
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text);
  background: transparent;
  border: none;
  outline: none;
}

.landing-header__input::placeholder {
  color: var(--text-tertiary);
  font-weight: 500;
  letter-spacing: 0.2em;
}

.landing-header__join-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--primary);
  border: none;
  border-radius: 50%;
  color: white;
  margin-right: 2px;
  transition: background var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.landing-header__join-btn:hover {
  background: var(--primary-dark);
}

.landing-header__cta {
  padding: 7px 16px;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  color: white;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-full);
  transition: background var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.landing-header__cta:hover {
  background: var(--primary-dark);
}


/* --------------------------------------------------------------------------
   Landing content — outil complet en mode demo
   -------------------------------------------------------------------------- */
.landing {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 540px;
  margin: 0 auto;
  padding: var(--space-lg);
  flex: 1;
}

/* Landing demo — prend tout l'espace */
.landing__demo {
  width: 100%;
}

/* ==========================================================================
   HOME SCREEN
   ========================================================================== */
.home {
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  padding: var(--space-md) 0;
}

.home__hero {
  margin-bottom: var(--space-xl);
}

.home__greeting {
  font-family: var(--font-body);
  font-weight: 800;
  font-size: clamp(1.5rem, 6vw, 2rem);
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin-bottom: var(--space-xs);
}

.home__sub {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 400;
  color: var(--text-secondary);
  margin: 0;
}

/* Module list */
.home__modules {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.home__module {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-align: left;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  min-height: 68px;
}

.home__module:hover {
  border-color: var(--primary-light);
  box-shadow: var(--shadow-sm);
}

.home__module:active {
  background: var(--bg-secondary);
}

.home__module-icon {
  font-size: 24px;
  line-height: 1;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  flex-shrink: 0;
}

.home__module-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.home__module-name {
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text);
}

.home__module-desc {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 400;
  color: var(--text-tertiary);
}

.home__module-arrow {
  color: var(--text-tertiary);
  flex-shrink: 0;
  transition: color var(--transition-fast), transform var(--transition-fast);
}

.home__module:hover .home__module-arrow {
  color: var(--primary);
  transform: translateX(2px);
}

/* ==========================================================================
   MODULE SCREEN
   ========================================================================== */
.module {
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  padding: var(--space-md) 0;
}

.module__header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.module__icon {
  font-size: 24px;
  line-height: 1;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
}

.module__title {
  font-family: var(--font-body);
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1;
}

.module__body {
  width: 100%;
}

/* --------------------------------------------------------------------------
   Journal / Stats
   -------------------------------------------------------------------------- */
.journal,
.stats {
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
}

/* ==========================================================================
   MODAL — bottom sheet on mobile, centree sur desktop
   ========================================================================== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: var(--z-modal);
}

.modal__backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
}

.modal__sheet {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--bg);
  border-top: 1px solid var(--border);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--space-xl) var(--space-lg);
  padding-bottom: calc(var(--space-xl) + env(safe-area-inset-bottom, 0px));
  box-shadow: var(--shadow-xl);
  animation: sheetUp 300ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes sheetUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
}

.modal__title {
  font-family: var(--font-body);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  line-height: 1;
}

.modal__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--bg-tertiary);
  border: none;
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  font-size: var(--text-lg);
  transition: background var(--transition-base), color var(--transition-base);
}

.modal__close:hover {
  background: var(--border);
  color: var(--text);
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

@media (max-width: 479px) {
  .landing-header__brand {
    display: none;
  }
}

@media (min-width: 768px) {
  .header {
    padding: 0 var(--space-xl);
  }

  .header__brand {
    font-size: var(--text-lg);
  }

  .nav {
    position: fixed;
    top: var(--header-height);
    bottom: auto;
    padding: var(--space-xs) var(--space-xl);
    justify-content: center;
    gap: var(--space-xs);
    border-top: none;
    border-bottom: 1px solid var(--border);
    box-shadow: none;
  }

  .nav__item {
    flex-direction: row;
    gap: var(--space-xs);
    flex: unset;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
  }

  .nav__item:hover {
    background: var(--bg-tertiary);
  }

  .nav__item--active::after {
    top: auto;
    bottom: 0;
  }

  .nav__label {
    font-size: 12px;
  }

  .main--app {
    padding-top: calc(var(--header-height) + 48px);
    padding-bottom: var(--space-xl);
  }

  /* Landing header — wider on tablet */
  .landing-header {
    padding: 0 var(--space-xl);
  }

  .landing-header__input {
    width: 100px;
  }

  .landing {
    max-width: 480px;
  }

  .home {
    max-width: 560px;
  }

  .module {
    max-width: 560px;
  }

  /* Modal centered on desktop */
  .modal {
    align-items: center;
  }

  .modal__sheet {
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    max-height: 80vh;
    padding-bottom: var(--space-xl);
  }
}

@media (min-width: 1024px) {
  .home__module {
    padding: var(--space-lg);
    min-height: 76px;
  }

  .home__module-icon {
    font-size: 28px;
    width: 48px;
    height: 48px;
  }
}
