/**
 * common.css - Styles de base pour Velopointage
 * À importer sur toutes les pages : <link rel="stylesheet" href="/static/css/common.css">
 */

/* ========== RESET & BASE ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, 
    Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
  font-size: 16px; /* Minimum mobile */
  line-height: 1.6;
  color: #222;
  background: #ffffff;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ========== THÈME CLAIR/SOMBRE ========== */
:root {
  /* Couleurs primaires */
  --color-primary: #007bff;
  --color-primary-dark: #0056b3;
  --color-secondary: #6c757d;
  --color-success: #28a745;
  --color-danger: #dc3545;
  --color-warning: #ffc107;
  --color-info: #17a2b8;
  
  /* Neutres */
  --color-bg: #ffffff;
  --color-surface: #f8f9fa;
  --color-border: #dee2e6;
  --color-text: #222222;
  --color-text-secondary: #666666;
  
  /* Ombres */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.15);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.2);
  
  /* Espacements */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 12px;
  --spacing-lg: 16px;
  --spacing-xl: 24px;
  
  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-base: 0.3s ease;
  --transition-slow: 0.5s ease;
}

/* Mode sombre */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #1e1e1e;
    --color-surface: #2d2d2d;
    --color-border: #444444;
    --color-text: #e0e0e0;
    --color-text-secondary: #b0b0b0;
  }
  
  body {
    background: var(--color-bg);
    color: var(--color-text);
  }
}

/* Toggle manuel dark mode (optionnel) */
body.dark {
  --color-bg: #1e1e1e;
  --color-surface: #2d2d2d;
  --color-border: #444444;
  --color-text: #e0e0e0;
  --color-text-secondary: #b0b0b0;
  background: var(--color-bg);
  color: var(--color-text);
}

/* ========== TYPOGRAPHIE ========== */
h1 { font-size: 1.75em; font-weight: 700; margin-bottom: 0.5em; }
h2 { font-size: 1.5em; font-weight: 600; margin-bottom: 0.5em; }
h3 { font-size: 1.25em; font-weight: 600; margin-bottom: 0.4em; }
h4 { font-size: 1.1em; font-weight: 600; margin-bottom: 0.3em; }

p { margin-bottom: 1em; }
small { font-size: 0.875em; }

/* ========== BOUTONS ========== */
button, a.btn {
  display: inline-block;
  padding: 0.75em 1em;
  min-height: 44px; /* Touch target min 44x44px */
  min-width: 44px;
  font-size: 16px; /* Évite zoom iPhone */
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition-base);
  user-select: none;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button:hover:not(:disabled),
a.btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

button:active:not(:disabled),
a.btn:active {
  transform: scale(0.98);
}

button:focus,
a.btn:focus {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Variantes de couleur */
.btn-primary {
  background: var(--color-primary);
  color: white;
}
.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-dark);
}

.btn-success {
  background: var(--color-success);
  color: white;
}
.btn-success:hover:not(:disabled) {
  background: #1e7e34;
}

.btn-danger {
  background: var(--color-danger);
  color: white;
}
.btn-danger:hover:not(:disabled) {
  background: #a71d2a;
}

.btn-secondary {
  background: var(--color-secondary);
  color: white;
}
.btn-secondary:hover:not(:disabled) {
  background: #5a6268;
}

/* ========== BADGES ========== */
.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.85em;
  font-weight: 600;
  vertical-align: baseline;
}

.badge-success {
  background: #d4edda;
  color: #155724;
}

.badge-warning {
  background: #fff3cd;
  color: #856404;
}

.badge-danger {
  background: #f8d7da;
  color: #721c24;
}

.badge-info {
  background: #d1ecf1;
  color: #0c5460;
}

body.dark .badge-success { background: #1e4620; color: #86efac; }
body.dark .badge-warning { background: #704d1a; color: #fcd34d; }
body.dark .badge-danger { background: #5a2a2a; color: #fca5a5; }
body.dark .badge-info { background: #1a4d52; color: #67e8f9; }

/* ========== CARDS ========== */
.card {
  background: var(--color-surface);
  border-radius: 12px;
  padding: var(--spacing-lg);
  margin-bottom: var(--spacing-md);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-base);
  border: 1px solid var(--color-border);
}

.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.card-title {
  font-weight: 600;
  margin-bottom: var(--spacing-sm);
  color: var(--color-text);
}

.card-subtitle {
  font-size: 0.9em;
  color: var(--color-text-secondary);
  margin-bottom: var(--spacing-md);
}

/* ========== INPUTS ========== */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 0.75em;
  margin-bottom: var(--spacing-md);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 16px; /* Évite zoom iPhone */
  font-family: inherit;
  background: var(--color-bg);
  color: var(--color-text);
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.15);
}

input[type="color"] {
  width: 50px;
  height: 40px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  cursor: pointer;
}

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

/* ========== TABLES ========== */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95em;
}

th, td {
  padding: var(--spacing-sm) var(--spacing-md);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

th {
  background: var(--color-surface);
  font-weight: 600;
  color: var(--color-text);
}

tr:hover {
  background: var(--color-surface);
}

/* ========== STATUS INDICATOR ========== */
#connection-status {
  position: fixed;
  top: 0;
  right: 0;
  padding: var(--spacing-sm) var(--spacing-lg);
  border-radius: 0 0 0 8px;
  z-index: 1000;
  font-size: 0.9em;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  backdrop-filter: blur(10px);
}

#status-indicator {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

#status-indicator.connected {
  background: var(--color-success);
}

#status-indicator.disconnected {
  background: var(--color-danger);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ========== TOAST NOTIFICATIONS ========== */
#toast-container {
  position: fixed;
  bottom: var(--spacing-lg);
  right: var(--spacing-lg);
  z-index: 1000;
  max-width: 400px;
}

.toast {
  background: var(--color-surface);
  padding: var(--spacing-lg);
  border-radius: 8px;
  margin-bottom: var(--spacing-md);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--color-primary);
  animation: slideIn 0.3s ease;
  min-width: 280px;
}

.toast.success {
  border-left-color: var(--color-success);
}

.toast.error {
  border-left-color: var(--color-danger);
}

.toast.warning {
  border-left-color: var(--color-warning);
}

@keyframes slideIn {
  from {
    transform: translateX(400px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(400px);
    opacity: 0;
  }
}

.toast.removing {
  animation: slideOut 0.3s ease;
}

/* ========== LOADING SKELETON ========== */
.skeleton {
  background: linear-gradient(90deg, var(--color-surface) 25%, #e0e0e0 50%, var(--color-surface) 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
  border-radius: 4px;
  min-height: 20px;
}

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

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  body {
    font-size: 15px;
    padding: var(--spacing-md);
  }
  
  h1 { font-size: 1.5em; }
  h2 { font-size: 1.25em; }
  
  button, a.btn {
    width: 100%;
    justify-content: center;
    padding: 1em;
  }
  
  .container {
    max-width: 100%;
    padding: 0;
  }
  
  #toast-container {
    left: var(--spacing-md);
    right: var(--spacing-md);
    max-width: none;
  }
  
  .toast {
    min-width: auto;
  }
}

/* ========== ACCESSIBILITÉ ========== */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Focus visible pour keyboard navigation */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

/* Augmenter hitbox en mobile */
@media (hover: none) and (pointer: coarse) {
  button, a.btn, input[type="checkbox"], input[type="radio"] {
    min-height: 48px;
    min-width: 48px;
  }
}

/* ========== UTILITAIRES ========== */
.hidden {
  display: none !important;
}

.invisible {
  visibility: hidden;
}

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

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

.mt-1 { margin-top: var(--spacing-sm); }
.mt-2 { margin-top: var(--spacing-md); }
.mt-3 { margin-top: var(--spacing-lg); }

.mb-1 { margin-bottom: var(--spacing-sm); }
.mb-2 { margin-bottom: var(--spacing-md); }
.mb-3 { margin-bottom: var(--spacing-lg); }

.p-1 { padding: var(--spacing-sm); }
.p-2 { padding: var(--spacing-md); }
.p-3 { padding: var(--spacing-lg); }
