/* ==========================================================================
   GestHeures - Feuille de styles principale
   Inspirée du tableau Excel avec ergonomie moderne & responsive
   ========================================================================== */

:root {
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border-color: #cbd5e1;
  --border-dark: #334155;
  --grid-line-hour: #475569;
  --grid-line-quarter: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent-red: #ff0000;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.08);
  --radius: 8px;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding: 1.25rem;
}

.app-container {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ==========================================================================
   1. Header de l'application
   ========================================================================== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
  gap: 1rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.app-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  border-radius: 10px;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

.app-title {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #0f172a;
}

.app-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Navigation Semaine */
.week-navigator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #f1f5f9;
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}

.btn-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: #ffffff;
  color: var(--text-main);
  border-radius: 6px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}

.btn-nav:hover {
  background: #e2e8f0;
  color: var(--primary);
}

.week-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 170px;
  text-align: center;
}

.week-text {
  font-weight: 700;
  font-size: 0.95rem;
  color: #0f172a;
}

.week-dates {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.date-picker {
  border: 1px solid #cbd5e1;
  background: #fff;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--text-main);
  cursor: pointer;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.save-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--success);
  background: #dcfce7;
  padding: 0.3rem 0.65rem;
  border-radius: 20px;
  opacity: 0.9;
  transition: opacity 0.3s;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border-color);
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s;
}

.btn-icon:hover {
  background: #f1f5f9;
  color: var(--text-main);
}

/* ==========================================================================
   2. Barre d'outils et palette de couleurs
   ========================================================================== */
.toolbar-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
  gap: 1rem;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.palette-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.toolbar-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-right: 0.25rem;
}

.palette-colors {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.color-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: #ffffff;
  border: 1.5px solid #cbd5e1;
  border-radius: 6px;
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.color-dot {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  background-color: var(--c);
  border: 1px solid rgba(0, 0, 0, 0.15);
}

.color-btn:hover {
  border-color: #94a3b8;
  background: #f8fafc;
}

.color-btn.active {
  border-color: #0f172a;
  background: #f1f5f9;
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.15);
}

.custom-color-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.5rem;
  border: 1.5px dashed #cbd5e1;
  border-radius: 6px;
  cursor: pointer;
  background: #ffffff;
  font-size: 0.8rem;
  font-weight: 500;
}

.custom-color-wrapper input[type="color"] {
  -webkit-appearance: none;
  border: none;
  width: 20px;
  height: 20px;
  border-radius: 3px;
  cursor: pointer;
  padding: 0;
  background: none;
}

.custom-color-wrapper input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.custom-color-wrapper input[type="color"]::-webkit-color-swatch {
  border: 1px solid #cbd5e1;
  border-radius: 3px;
}

.custom-color-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #ffffff;
  border: 1.5px solid #cbd5e1;
  border-radius: 6px;
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s ease;
}

.tool-btn:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
}

.tool-btn.active {
  background: #fee2e2;
  border-color: #ef4444;
  color: #b91c1c;
}

/* Boutons génériques */
.btn-primary, .btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
}

.btn-primary {
  background: #2563eb;
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.25);
}

.btn-primary:hover {
  background: #1d4ed8;
}

.btn-secondary {
  background: #ffffff;
  color: #334155;
  border: 1px solid #cbd5e1;
}

.btn-secondary:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.btn-sm {
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
}

/* Dropdown actions */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.35rem;
  background: #ffffff;
  min-width: 280px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  z-index: 100;
  padding: 0.4rem;
}

.dropdown-menu.show {
  display: block;
  animation: fadeIn 0.15s ease;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: none;
  border: none;
  border-radius: 5px;
  font-size: 0.8rem;
  color: #334155;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}

.dropdown-item:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.dropdown-item.text-danger {
  color: #dc2626;
}

.dropdown-item.text-danger:hover {
  background: #fef2f2;
}

.dropdown-divider {
  height: 1px;
  background: #e2e8f0;
  margin: 0.3rem 0;
}

/* Astuce utilisateur */
.user-hint {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
  padding: 0.5rem 0.85rem;
  border-radius: 6px;
  font-size: 0.8rem;
}

/* ==========================================================================
   3. Grille de planning (Tableau Excel)
   ========================================================================== */
.schedule-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
  overflow: hidden;
}

.table-responsive {
  overflow-x: auto;
  user-select: none; /* Évite de sélectionner du texte en glissant */
  -webkit-user-select: none;
}

.schedule-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  border: 2px solid #000000;
  background: #ffffff;
}

/* Cellules globales */
.schedule-table th,
.schedule-table td {
  padding: 0;
  margin: 0;
  text-align: center;
  vertical-align: middle;
}

/* En-tête des heures (8h, 9h, 10h...) */
.th-day-corner {
  width: 110px;
  min-width: 110px;
  background: #ffffff;
  border-right: 2px solid #000000;
  border-bottom: 2px solid #000000;
}

.th-hour {
  height: 26px;
  font-size: 0.85rem;
  font-weight: 700;
  color: #000000;
  text-align: left;
  padding-left: 3px !important;
  border-bottom: 1.5px solid #000000;
  border-right: 1.5px solid #000000;
  background: #ffffff;
  transition: background-color 0.1s ease, color 0.1s ease;
}

.th-hour.col-highlight {
  background-color: #dbeafe !important;
  color: #1d4ed8 !important;
}

.schedule-table tr.row-highlight .td-day-name {
  color: #1d4ed8;
  background-color: #eff6ff;
}

/* Colonnes de calculs (En-tête) */
.th-calc {
  font-size: 0.82rem;
  font-weight: 800;
  color: #000000;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 0.4rem 0.6rem !important;
  border-bottom: 2px solid #000000;
  background: #ffffff;
  white-space: nowrap;
}

.th-calc-empty {
  width: 60px;
  min-width: 60px;
  border-left: 2px solid #000000;
  border-right: 1px solid #cbd5e1;
}

.th-calc-matin {
  width: 85px;
  min-width: 85px;
  border-right: 1px solid #cbd5e1;
}

.th-calc-apresm {
  width: 85px;
  min-width: 85px;
  border-right: 1px solid #cbd5e1;
}

.th-calc-total {
  width: 95px;
  min-width: 95px;
  border-right: 2px solid #000000;
}

/* Lignes des jours */
.tr-day {
  height: 28px;
}

.td-day-name {
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  text-align: right !important;
  padding-right: 8px !important;
  color: #000000;
  border-right: 2px solid #000000;
  border-bottom: 1.5px solid #000000;
  background: #ffffff;
  white-space: nowrap;
}

/* Cases de 15 minutes */
.time-slot {
  width: 17px;
  min-width: 17px;
  max-width: 17px;
  height: 26px;
  background: #ffffff;
  cursor: pointer;
  border-right: 1px solid #94a3b8; /* Ligne fine 15 min */
  border-bottom: 1.5px solid #000000;
  transition: opacity 0.08s ease;
  position: relative;
}

/* Marqueur pour les heures pleines (bordure plus épaisse) */
.time-slot.hour-start {
  border-left: 1.5px solid #000000;
}

.time-slot.last-slot-of-day {
  border-right: 2px solid #000000;
}

/* Cellule cochée / colorée */
.time-slot.filled {
  /* La couleur est définie dynamiquement en JS (ex: #ff0000) */
}

.time-slot:hover {
  filter: brightness(0.92);
  outline: 1.5px solid #2563eb;
  z-index: 5;
}

/* Colonnes de calculs (Corps du tableau) */
.td-calc {
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 0.86rem;
  color: #000000;
  padding: 0 6px !important;
  border-bottom: 1.5px solid #000000;
  white-space: nowrap;
}

.td-calc-decimal {
  text-align: right !important;
  font-weight: 500;
  border-left: 2px solid #000000;
  border-right: 1px solid #cbd5e1;
  padding-right: 10px !important;
}

.td-calc-matin {
  text-align: center !important;
  font-weight: 500;
  border-right: 1px solid #cbd5e1;
}

.td-calc-apresm {
  text-align: center !important;
  font-weight: 500;
  border-right: 1px solid #cbd5e1;
}

.td-calc-total {
  text-align: center !important;
  font-weight: 600;
  border-right: 2px solid #000000;
}

/* Ligne de synthèse en bas du tableau (Exactement comme dans l'Excel) */
.tr-totals {
  height: 36px;
}

.td-totals-empty-grid {
  border-right: 2px solid #000000;
  border-bottom: none;
  background: #ffffff;
}

.td-totals-decimal {
  border: 2px solid #2563eb; /* Encadré bleu fidèle à la sélection Excel */
  text-align: center !important;
  font-size: 0.95rem;
  font-weight: 700;
  color: #000000;
  background: #ffffff;
}

.td-totals-matin {
  font-style: italic;
  font-size: 0.88rem;
  color: #000000;
  text-align: center !important;
  border-bottom: none;
}

.td-totals-apresm {
  font-style: italic;
  font-size: 0.88rem;
  color: #000000;
  text-align: center !important;
  border-bottom: none;
}

.td-totals-global {
  font-weight: 900;
  font-style: italic;
  font-size: 1.05rem;
  color: #000000;
  text-align: center !important;
  border-bottom: none;
  letter-spacing: -0.01em;
}

/* ==========================================================================
   4. Cartes Récapitulatives & Objectif
   ========================================================================== */
.summary-section {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.stat-total {
  background: linear-gradient(135deg, #1e293b, #0f172a);
  color: #ffffff;
  border: none;
}

.stat-total .stat-title {
  color: #94a3b8;
}

.stat-total .stat-sub-value {
  font-size: 0.85rem;
  color: #cbd5e1;
}

.stat-title {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.stat-main-value {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: #0f172a;
}

.stat-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.stat-balance-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--success);
}

.stat-balance-value.negative {
  color: var(--danger);
}

.stat-balance-value.neutral {
  color: var(--primary);
}

/* ==========================================================================
   5. Répartition par activité / couleur
   ========================================================================== */
.breakdown-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-sm);
}

.breakdown-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.75rem;
}

.breakdown-bars {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.breakdown-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
}

.breakdown-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.breakdown-name {
  font-weight: 600;
  color: #334155;
}

.breakdown-time {
  font-weight: 700;
  color: #0f172a;
  margin-left: 0.25rem;
}

/* ==========================================================================
   6. Infobulle / Tooltip
   ========================================================================== */
.cell-tooltip {
  position: fixed;
  display: none;
  background: rgba(15, 23, 42, 0.92);
  color: #ffffff;
  padding: 0.35rem 0.65rem;
  border-radius: 5px;
  font-size: 0.75rem;
  font-weight: 600;
  pointer-events: none;
  z-index: 9999;
  box-shadow: var(--shadow-md);
  transform: translate(-50%, -125%);
  white-space: nowrap;
}

/* ==========================================================================
   7. Modal Paramètres
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-backdrop.show {
  display: flex;
  animation: fadeIn 0.15s ease;
}

.modal-card {
  background: #ffffff;
  width: 100%;
  max-width: 480px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #e2e8f0;
}

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-group label {
  font-size: 0.82rem;
  font-weight: 600;
  color: #334155;
}

.form-control {
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  background: #ffffff;
  color: #0f172a;
}

.form-help {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.form-check {
  margin-top: 0.25rem;
}

.check-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
}

.modal-footer {
  padding: 0.85rem 1.25rem;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  display: flex;
  justify-content: flex-end;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   8. Pied de page (Footer)
   ========================================================================== */
.app-footer {
  text-align: center;
  padding: 1.5rem 0 0.5rem 0;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 500;
  border-top: 1px solid var(--border-color);
  margin-top: 0.5rem;
  letter-spacing: 0.01em;
}

/* ==========================================================================
   9. Styles d'impression & PDF (@media print)
   ========================================================================== */
@media print {
  @page {
    size: landscape;
    margin: 1cm;
  }

  body {
    background: #ffffff;
    padding: 0;
    font-size: 11pt;
  }

  .app-header,
  .toolbar-section,
  .user-hint,
  .breakdown-section,
  .btn-icon,
  .modal-backdrop {
    display: none !important;
  }

  .schedule-card {
    border: none;
    box-shadow: none;
    padding: 0;
    margin-bottom: 20px;
  }

  .schedule-table {
    border: 2px solid #000000 !important;
    width: 100% !important;
  }

  .schedule-table th,
  .schedule-table td {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .time-slot.filled {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .summary-section {
    display: flex !important;
    flex-direction: row;
    gap: 15px;
  }

  .summary-card {
    border: 1px solid #000000;
    box-shadow: none;
    padding: 8px 12px;
  }

  .stat-total {
    background: #f1f5f9 !important;
    color: #000000 !important;
  }

  .stat-total .stat-title,
  .stat-total .stat-sub-value {
    color: #334155 !important;
  }
}
