*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: var(--line-height-base);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* Loading screen — sky pastel + dark ink, aligned with the cartouche logo */
#loading-screen {
  position: fixed;
  inset: 0;
  background: #D4E8F1;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s ease, transform 0.5s ease;
}
#loading-screen.hidden {
  opacity: 0;
  transform: scale(1.06);
  pointer-events: none;
}
#loading-screen.instant {
  display: none;
}

.splash-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  animation: wordmarkIn 0.7s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.splash-wordmark {
  font-size: clamp(0.85rem, 4.2vw, 1.05rem);
  font-weight: 600;
  letter-spacing: 0.22em;
  color: #0E1B1F;
  text-transform: uppercase;
}
@keyframes wordmarkIn {
  from { opacity: 0; transform: scale(0.88) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Page loader bar === */
#page-loader {
  position: fixed;
  top: 0;
  left: 0;
  height: 4px;
  width: 0;
  background: linear-gradient(90deg, var(--color-primary), #e07a5f);
  z-index: 9998;
  border-radius: 0 3px 3px 0;
  transition: width 0.4s cubic-bezier(0.1, 0.5, 0.5, 1), opacity 0.3s ease;
  opacity: 0;
  pointer-events: none;
}
#page-loader.loading {
  opacity: 1;
  width: 70%;
  transition: width 2s cubic-bezier(0.05, 0.8, 0.5, 1), opacity 0.1s ease;
}
#page-loader.done {
  width: 100%;
  opacity: 0;
  transition: width 0.15s ease, opacity 0.3s ease 0.15s;
}

/* App layout — fixed viewport height + scrollable middle, so the bottom nav stays put
   and `.page-header` can use position: sticky reliably. */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#page-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + var(--space-4));
}

/* Bottom nav */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255,255,255,0.94);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(232,230,225,0.6);
  display: flex;
  align-items: stretch;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 100;
  box-shadow: 0 -4px 32px rgba(0,0,0,0.07);
}

.nav-item {
  flex: 1;
  height: var(--nav-height);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--color-text-light);
  transition: color var(--transition-fast);
  position: relative;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.nav-item.active { color: var(--color-primary); }
.nav-item.active::before {
  content: '';
  position: absolute;
  top: 8px;
  width: 40px;
  height: 32px;
  border-radius: 10px;
  background: rgba(61,64,91,0.09);
}
.nav-icon {
  width: 22px;
  height: 22px;
  position: relative;
  transition: transform var(--transition-fast);
  stroke: currentColor;
  flex-shrink: 0;
}
.nav-item.active .nav-icon { transform: scale(1.12); }
.nav-label {
  font-size: 10px;
  font-weight: var(--font-weight-medium);
  letter-spacing: -0.01em;
  max-width: 100%;
  /* Keep the label centered AND visible across all 6 tabs on 390px screens.
     Truncation was caused by parent flex item shrinking too aggressively. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  padding: 0 2px;
}
.nav-item { min-width: 0; padding: 0 2px; }
.nav-item.active .nav-label { font-weight: var(--font-weight-semibold); }

@media (max-width: 390px) {
  .nav-label { font-size: 9px; letter-spacing: -0.02em; }
  .nav-icon { width: 20px; height: 20px; }
  .nav-item { padding: 0 1px; }
}

/* Page wrapper — horizontal padding only; the sticky page-header brings its own
   vertical padding so it can flush to the top edge of #page-container. */
.page {
  padding: 0 var(--space-4);
  padding-bottom: calc(var(--space-8) + env(safe-area-inset-bottom, 0px));
  max-width: 640px;
  margin: 0 auto;
  min-height: 0;
}

/* Sticky title bar — stays glued to the top of #page-container during scroll.
   Negative horizontal margins make the solid background bleed past the .page
   inner padding so the bar covers the full container width. */
.page-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin: 0 calc(-1 * var(--space-4)) var(--space-5);
  padding: calc(env(safe-area-inset-top, 0px) + var(--space-4)) var(--space-4) var(--space-3);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}
.page-title {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  font-family: inherit;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all var(--transition-fast);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--color-primary-hover); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--color-danger-hover); }
.btn-ghost { background: transparent; color: var(--color-text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--color-surface-2); color: var(--color-text); }
.btn-outline { background: transparent; border: 1px solid var(--color-border); color: var(--color-text); }
.btn-outline:hover:not(:disabled) { background: var(--color-surface-2); }
.btn-full { width: 100%; }
.btn-icon { padding: var(--space-3); border-radius: var(--radius-full); min-width: 44px; min-height: 44px; }
.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--font-size-xs); }
/* Secondary action — filled but quieter than primary. Referenced by sport
   ("Rejoindre") and programme-tracking ("Logger") which previously rendered
   unstyled (the class was used but never defined). */
.btn-secondary { background: var(--color-surface-2); color: var(--color-text); }
.btn-secondary:hover:not(:disabled) { background: var(--color-border); }
/* Icon + label button (e.g. Courses toolbar) — keeps glyph and text aligned. */
.btn-with-icon { display: inline-flex; align-items: center; gap: var(--space-2); }
/* Icons inside buttons inherit the button text color and scale to 1.15em so a
   16px-ish glyph reads at the small button font sizes. Icon-only buttons get a
   slightly larger glyph for tap legibility. */
.btn .icon { width: 1.15em; height: 1.15em; }
.btn-icon .icon { width: 18px; height: 18px; }

/* Mobile tap optimisations globales (R10) */
.btn { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.todo-item, .note-card, .house-card, .house-tile, .shopping-item, .widget, .chat-bubble {
  -webkit-tap-highlight-color: transparent;
}

/* Forms — checkbox/radio excluded, they keep their native rendering */
input:not([type="checkbox"]):not([type="radio"]), textarea, select {
  width: 100%;
  padding: 14px var(--space-4);
  border: 1.5px solid var(--color-border);
  border-radius: 14px;
  font-family: inherit;
  /* Force 16px minimum pour empêcher iOS Safari de zoomer au focus.
     var(--font-size-base) = 1rem = 16px sur la base actuelle, mais on
     écrit le literal pour garantir aux futures pages qu'aucun override
     custom ne descend sous le seuil. */
  font-size: max(16px, var(--font-size-base));
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  -webkit-appearance: none;
  appearance: none;
}
input:not([type="checkbox"]):not([type="radio"]):focus, textarea:focus, select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px rgba(61,64,91,0.08);
}
/* Keyboard focus indicator — visible only for keyboard navigation, not mouse clicks */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: none;
}
input::placeholder { color: var(--color-text-light); }

/* Custom checkbox + radio — modern look, but native behavior preserved.
   IMPORTANT: keep `display: inline-block` + a positioned ::after. Using
   `display: inline-flex` here can break click hit-testing on iOS Safari and
   cause the first tap on a label to miss the input — users perceived it as
   "I can't select more than one participant". */
input[type="checkbox"], input[type="radio"] {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
  display: inline-block;
  position: relative;
  vertical-align: middle;
  margin: 0;
}
input[type="checkbox"] { border-radius: 6px; }
input[type="radio"] { border-radius: 50%; }
input[type="checkbox"]:hover, input[type="radio"]:hover { border-color: var(--color-primary); }
input[type="checkbox"]:checked, input[type="radio"]:checked {
  background: var(--color-primary);
  border-color: var(--color-primary);
}
input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 11px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: translate(-50%, -55%) rotate(45deg);
}
input[type="radio"]:checked::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  transform: translate(-50%, -50%);
}
input[type="checkbox"]:disabled, input[type="radio"]:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23b5b3ae' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  background-size: 10px 6px;
  padding-right: 44px;
  cursor: pointer;
}
select option { border-radius: 8px; padding: 8px; }
textarea { resize: vertical; min-height: 80px; }
.form-group { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); }
.form-label { font-size: var(--font-size-sm); font-weight: var(--font-weight-medium); color: var(--color-text); }
.form-row { display: flex; gap: var(--space-3); }
.form-row .form-group { flex: 1; }
/* Password reveal "eye" toggle, positioned inside a `.relative` input wrapper
   (login.js / profile.js / admin.js). Variants add .items-center / .p-1. */
.eye-btn {
  position: absolute;
  right: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  display: flex;
}

/* Toast — safe-area aware pour le notch iOS PWA standalone */
#toast-container {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + var(--space-4));
  right: calc(env(safe-area-inset-right, 0px) + var(--space-4));
  z-index: var(--z-toast, 9999);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}
.toast {
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  color: #fff;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  box-shadow: var(--shadow-lg);
  animation: slideInToast var(--transition-base) ease;
  max-width: 320px;
}
.toast.success { background: var(--color-success); }
.toast.error { background: var(--color-danger); }
.toast.info { background: var(--color-primary); }
@keyframes slideInToast {
  from { transform: translateX(110%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes slideOutToast {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(110%); opacity: 0; }
}
.toast-out {
  animation: slideOutToast 250ms ease forwards;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn var(--transition-fast);
  overscroll-behavior: contain;
}
.modal-overlay.hidden { display: none; }
/* While a modal is open, freeze the page behind it — the real scroller is
   #page-container, so a scroll/touch that escapes the modal would otherwise
   move the page underneath. */
html.modal-open #page-container,
html.modal-open body { overflow: hidden; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width: 100%;
  max-width: 640px;
  padding: var(--space-6);
  max-height: 90vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  outline: none;
  animation: slideUp var(--transition-base);
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-6);
}
.modal-title { font-size: var(--font-size-xl); font-weight: var(--font-weight-bold); }
.modal-actions { display: flex; gap: var(--space-3); margin-top: var(--space-6); }

/* Icon base — inline SVG sized to the current text size by default, tinted via
   currentColor. Components override width/height where a fixed size is needed. */
.icon {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: -0.125em;
  flex-shrink: 0;
}

/* Empty state */
.empty-state { text-align: center; padding: var(--space-12) var(--space-4); color: var(--color-text-muted); }
.empty-state-emoji { font-size: 3rem; margin-bottom: var(--space-4); }
/* Icon variant of the empty-state glyph — larger, muted, centered. */
.empty-state-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-4);
  color: var(--color-text-light);
}
.empty-state-icon .icon { width: 100%; height: 100%; stroke-width: 1.5; }
.empty-state-text { font-size: var(--font-size-lg); }
.empty-state-cta { margin-top: var(--space-5); display: inline-flex; }
/* Variant with an inline CTA button below the text */
.empty-state.with-cta .empty-state-text { margin-bottom: var(--space-2); }

/* Skeleton loaders — hidden until 200ms have elapsed so quick loads don't flash */
.skeleton, .skeleton-card {
  background: linear-gradient(90deg, var(--color-surface-2) 25%, var(--color-border) 50%, var(--color-surface-2) 75%);
  background-size: 200% 100%;
  border-radius: var(--radius-md);
  animation: skeletonShimmer 1.2s linear infinite;
  /* Delayed visibility — render-time skeletons only appear if the load takes a beat. */
  animation-delay: 200ms;
  opacity: 0;
  animation-fill-mode: forwards;
}
.skeleton.skeleton-line { height: 12px; border-radius: var(--radius-sm); }
.skeleton.skeleton-line.lg { height: 20px; }
.skeleton.skeleton-line.sm { height: 10px; }
.skeleton-card { width: 100%; border-radius: var(--radius-lg); }
@keyframes skeletonShimmer {
  0%   { background-position: 200% 0; opacity: 1; }
  100% { background-position: -200% 0; opacity: 1; }
}

/* Service-worker update banner — sticky bottom, above the bottom nav */
#sw-update-banner {
  position: fixed;
  left: var(--space-4);
  right: var(--space-4);
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + var(--space-3));
  background: var(--color-surface);
  color: var(--color-text);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  z-index: 200;
  font-size: var(--font-size-sm);
  border: 1px solid var(--color-border);
  animation: slideInToast var(--transition-base) ease;
}

.hidden { display: none !important; }

.page-enter {
  animation: pageEnter 200ms ease both;
}
@keyframes pageEnter {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
