/**
 * UTTOP JPO 2026 - Global Styles
 *
 * Mobile-first, lightweight, vanilla CSS
 * Based on KISSES principles
 */

/* ==================== FORCE MODE CLAIR ==================== */

:root {
  color-scheme: light; /* Force mode clair, ignore préférence OS dark mode */
}

/* Override si navigateur/OS essaie d'appliquer dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: light !important;
  }

  /* Force couleurs claires même en dark mode OS */
  body {
    background-color: #f5f5f5 !important;
    color: #2c3e50 !important;
  }

  input,
  textarea,
  select {
    background-color: white !important;
    color: #2c3e50 !important;
    border-color: rgba(0, 0, 0, 0.1) !important;
  }
}

/* === RESET & BASE === */

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  overflow-x: hidden;
  min-height: 100vh;
}

/* === TYPOGRAPHY === */

h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: var(--spacing-sm);
  color: var(--text-primary);
}

h1 { font-size: 2rem; }     /* 32px */
h2 { font-size: 1.5rem; }   /* 24px */
h3 { font-size: 1.25rem; }  /* 20px */
h4 { font-size: 1.125rem; } /* 18px */
h5 { font-size: 1rem; }     /* 16px */
h6 { font-size: 0.875rem; } /* 14px */

p {
  margin-bottom: var(--spacing-md);
}

a {
  color: var(--uttop-blue);
  text-decoration: none;
  transition: color var(--transition-base);
}

/* === LAYOUT === */

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--spacing-md);
}

.container-narrow {
  max-width: 800px;
}

.container-wide {
  max-width: 1400px;
}

/* === GRID SYSTEM === */

.grid {
  display: grid;
  gap: var(--spacing-md);
}

.grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

/* Responsive grid - mobile first */
@media (max-width: 768px) {
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .grid-3,
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* === FLEX UTILITIES === */

.flex {
  display: flex;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.flex-column {
  flex-direction: column;
}

.flex-wrap {
  flex-wrap: wrap;
}

/* === SPACING UTILITIES === */

.mt-xs { margin-top: var(--spacing-xs); }
.mt-sm { margin-top: var(--spacing-sm); }
.mt-md { margin-top: var(--spacing-md); }
.mt-lg { margin-top: var(--spacing-lg); }
.mt-xl { margin-top: var(--spacing-xl); }

.mb-xs { margin-bottom: var(--spacing-xs); }
.mb-sm { margin-bottom: var(--spacing-sm); }
.mb-md { margin-bottom: var(--spacing-md); }
.mb-lg { margin-bottom: var(--spacing-lg); }
.mb-xl { margin-bottom: var(--spacing-xl); }

.p-xs { padding: var(--spacing-xs); }
.p-sm { padding: var(--spacing-sm); }
.p-md { padding: var(--spacing-md); }
.p-lg { padding: var(--spacing-lg); }
.p-xl { padding: var(--spacing-xl); }

/* === TEXT UTILITIES === */

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.text-bold { font-weight: 700; }
.text-normal { font-weight: 400; }
.text-light { font-weight: 300; }

.text-sm { font-size: 0.875rem; }
.text-md { font-size: 1rem; }
.text-lg { font-size: 1.125rem; }
.text-xl { font-size: 1.25rem; }

/* === DISPLAY UTILITIES === */

.hidden { display: none !important; }
.visible { display: block !important; }

.hide-mobile {
  display: block;
}

.show-mobile {
  display: none;
}

@media (max-width: 768px) {
  .hide-mobile {
    display: none !important;
  }

  .show-mobile {
    display: block !important;
  }
}

/* === APP STRUCTURE === */

.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background-color: var(--bg-primary);
  border-bottom: 1px solid var(--border-light);
  padding: var(--spacing-sm) var(--spacing-md);
  box-shadow: var(--shadow-sm);
}

.app-main {
  flex: 1;
  padding: var(--spacing-md);
}

.app-footer {
  background-color: var(--bg-secondary);
  padding: var(--spacing-lg) var(--spacing-md);
  text-align: center;
  border-top: 1px solid var(--border-light);
}

/* === FORMS === */

input,
textarea,
select {
  width: 100%;
  padding: var(--spacing-sm) var(--spacing-md);
  font-size: 1rem;
  font-family: inherit;
  border: 2px solid var(--border-medium);
  border-radius: var(--radius-md);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  transition: border-color var(--transition-base);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--uttop-blue);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-disabled);
}

label {
  display: block;
  margin-bottom: var(--spacing-xs);
  font-weight: 600;
  color: var(--text-primary);
}

.form-group {
  margin-bottom: var(--spacing-md);
}

.form-error {
  color: #e53e3e;
  font-size: 0.875rem;
  margin-top: var(--spacing-xs);
}

.form-help {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-top: var(--spacing-xs);
}

/* === IMAGES === */

img {
  max-width: 100%;
  height: auto;
  display: block;
}

.img-rounded {
  border-radius: var(--radius-md);
}

.img-circle {
  border-radius: var(--radius-full);
}

/* === LOADING STATES === */

.spinner {
  border: 3px solid var(--border-light);
  border-top-color: var(--uttop-blue);
  border-radius: var(--radius-full);
  width: 40px;
  height: 40px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--gray-200) 25%,
    var(--gray-100) 50%,
    var(--gray-200) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* === ALERTS & NOTIFICATIONS === */

.alert {
  padding: var(--spacing-md);
  border-radius: var(--radius-md);
  margin-bottom: var(--spacing-md);
  border-left: 4px solid;
}

.alert-success {
  background-color: rgba(var(--uttop-light-green-rgb), 0.1);
  border-color: var(--uttop-light-green);
  color: var(--uttop-green);
}

.alert-warning {
  background-color: rgba(var(--uttop-yellow-rgb), 0.1);
  border-color: var(--uttop-yellow);
  color: #9a7b0a;
}

.alert-error {
  background-color: rgba(255, 0, 0, 0.1);
  border-color: #e53e3e;
  color: #c53030;
}

.alert-info {
  background-color: rgba(var(--uttop-blue-rgb), 0.1);
  border-color: var(--uttop-blue);
  color: var(--uttop-blue);
}

/* === MODALS === */

.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--bg-overlay);
  z-index: var(--z-modal-backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-md);
}

.modal {
  background-color: var(--bg-primary);
  border-radius: var(--radius-lg);
  xmax-width: 600px;
  width: 100%;
  xmax-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  position: relative;
  z-index: var(--z-modal);
}

.modal-header {
  padding: var(--spacing-lg);
  border-bottom: 1px solid var(--border-light);
}

.modal-body {
  padding: var(--spacing-lg);
}

.modal-footer {
  padding: var(--spacing-lg);
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: flex-end;
  gap: var(--spacing-sm);
}

/* === SAFE AREAS (iOS notch) === */

@supports (padding: max(0px)) {
  .app-header {
    padding-top: max(var(--spacing-sm), env(safe-area-inset-top));
    padding-left: max(var(--spacing-md), env(safe-area-inset-left));
    padding-right: max(var(--spacing-md), env(safe-area-inset-right));
  }

  .app-footer {
    padding-bottom: max(var(--spacing-lg), env(safe-area-inset-bottom));
  }
}

/* === PWA SPECIFIC === */

/* Hide iOS Safari UI chrome when in standalone mode */
@media (display-mode: standalone) {
  body {
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }

  /* Allow text selection in specific areas */
  input,
  textarea,
  p,
  .selectable {
    user-select: text;
    -webkit-user-select: text;
  }
}

/* === ACCESSIBILITY === */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Focus styles */
:focus-visible {
  outline: 2px solid var(--uttop-blue);
  outline-offset: 2px;
}

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

/* ==================== UNIFIED HEADERS (MODULES) ==================== */

.header, .top-bar, .program-header, .history-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: linear-gradient(135deg, #10997D 0%, #45DB97 50%, #004F78 100%);
  padding: var(--spacing-sm) 0;
  box-shadow: 0 4px 20px rgba(16, 153, 125, 0.12);
}

.header-content, .top-bar-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--spacing-md);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-title {
  font-family: var(--font-display);
  font-size: 1.25rem !important; /* Plus petit que h1 par défaut (2rem) */
  font-weight: 700;
  color: white;
  letter-spacing: -0.02em;
  margin: 0 !important;
  flex: 1;
  text-align: center;
}

.back-btn, .action-btn.back-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: white;
  transition: all var(--transition-base);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
}

.back-btn:hover, .action-btn.back-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateX(-4px);
}

.back-btn svg, .action-btn.back-btn svg {
  width: 20px;
  height: 20px;
  stroke: white !important; /* Force blanc */
}

.header-actions {
  display: flex;
  gap: var(--spacing-sm);
  align-items: center;
  flex-shrink: 0;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: white;
  transition: all var(--transition-base);
  backdrop-filter: blur(10px);
  position: relative;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  stroke: white;
}

.notification-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: #FF0000;
  color: white;
  font-size: 0.625rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid white;
}

/* Mobile */
@media (max-width: 768px) {
  .header-title {
    font-size: 1.125rem !important;
  }

  .back-btn, .action-btn.back-btn, .icon-btn {
    width: 36px;
    height: 36px;
  }

  .back-btn svg, .action-btn.back-btn svg, .icon-btn svg {
    width: 18px;
    height: 18px;
  }
}
