/* ==========================================================================
   B'DESK — MODULE TÂCHES & PLANNING (DESIGN BOULANGER MODERNE)
   ========================================================================== */

.tasks-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.tasks-layout-stacked {
  grid-template-columns: minmax(0, 1fr);
}

.tasks-sidebar,
.tasks-planning {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.tasks-sidebar {
  position: static;
}

.tasks-library-full {
  width: 100%;
}

.tasks-section-title {
  margin: 0;
  color: var(--blue);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.4px;
}

.tasks-section-text {
  margin: 6px 0 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.tasks-form,
.tasks-field {
  display: grid;
  gap: 8px;
}

.tasks-form {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line-light);
}

.tasks-field label {
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
}

.tasks-field input,
.tasks-field textarea,
.tasks-field select {
  box-sizing: border-box;
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfd;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  transition: var(--transition);
}

.tasks-field textarea {
  min-height: 75px;
  resize: vertical;
}

.tasks-field input:focus,
.tasks-field textarea:focus {
  border-color: var(--orange);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(243, 112, 33, 0.15);
  outline: none;
}

.tasks-form-actions,
.tasks-week-actions,
.task-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tasks-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.tasks-button-primary {
  background: var(--orange-gradient);
  color: var(--white);
  box-shadow: 0 4px 12px rgba(243, 112, 33, 0.28);
}

.tasks-button-primary:hover {
  background: linear-gradient(135deg, #ff7e33 0%, #f37021 100%);
  box-shadow: 0 6px 16px rgba(243, 112, 33, 0.38);
  transform: translateY(-1px);
}

.tasks-button-secondary {
  border-color: var(--line);
  background: var(--white);
  color: var(--blue);
}

.tasks-button-secondary:hover {
  border-color: #cbd5e1;
  background: var(--blue-soft);
  transform: translateY(-1px);
}

.tasks-button-danger {
  border-color: #fecaca;
  background: #fef2f2;
  color: var(--red-dark);
}

.tasks-button-danger:hover {
  background: #fee2e2;
  color: var(--red);
}

.tasks-button-warning {
  border-color: #e2e8f0;
  background: #f8fafc;
  color: var(--muted);
}

.tasks-button-warning:hover {
  border-color: #cbd5e1;
  color: var(--blue);
}

.tasks-notice {
  min-height: 20px;
  margin: 0 0 12px;
  color: var(--red);
  font-size: 12px;
  font-weight: 700;
}

/* Bibliothèque pleine largeur — formulaire horizontal + tuiles en grille */
@media (min-width: 900px) {
  .tasks-library-form {
    grid-template-columns: 300px minmax(0, 1fr) auto;
    align-items: end;
    gap: 12px;
  }

  .tasks-library-form .tasks-form-actions {
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }
}

/* Modèles de tâches — bibliothèque optimisée (recherche + grille pleine largeur) */
.tasks-search-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  background: var(--white);
  padding-bottom: 6px;
}

.tasks-search-wrap input[type="search"] {
  flex: 1 1 auto;
  min-width: 0;
}

.tasks-search-wrap input[type="search"] {
  box-sizing: border-box;
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfd;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  transition: var(--transition);
}

.tasks-search-wrap input[type="search"]:focus {
  border-color: var(--orange);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(243, 112, 33, 0.15);
  outline: none;
}

.tasks-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

.tasks-template-list {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  max-height: 360px;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
  align-content: start;
}

.tasks-template-list::-webkit-scrollbar {
  width: 6px;
}

.tasks-template-list::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 6px;
}

.tasks-template-list .task-card.compact {
  padding: 10px 12px;
}

.task-card {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--orange);
  border-radius: 12px;
  background: var(--white);
  box-shadow: var(--shadow-xs);
  cursor: grab;
  transition: var(--transition);
}

.task-card:hover {
  border-color: #cbd5e1;
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.task-card.is-dragging {
  opacity: 0.4;
  cursor: grabbing;
}

.task-card.is-done {
  border-left-color: var(--green);
  background: var(--green-soft);
}

.task-card.is-not-done {
  border-left-color: var(--red);
  background: var(--red-soft);
}

.task-card-title {
  display: block;
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.35;
}

.task-card-description,
.task-card-meta,
.task-card-comment {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.task-card-comment {
  color: var(--green-dark);
  font-weight: 700;
}

.task-card.is-not-done .task-card-meta {
  color: var(--red-dark);
  font-weight: 800;
}

.task-card-actions {
  margin-top: 8px;
}

.task-card-actions .tasks-button {
  min-height: 28px;
  padding: 0 10px;
  font-size: 11px;
}

/* En-tête Semaine & Planning */
.tasks-week-actions {
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}

.tasks-week-label {
  color: var(--blue);
  font-size: 15px;
  font-weight: 800;
  text-align: center;
}

/* Calendrier hebdomadaire — collaborateurs en colonnes, jours en lignes, tout visible */
.tasks-calendar-wrap {
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: visible;
  box-shadow: var(--shadow-xs);
}

.tasks-calendar {
  display: grid;
  grid-template-columns: 140px repeat(4, minmax(0, 1fr));
  background: var(--line);
  gap: 1px;
  border-radius: 14px;
  overflow: hidden;
}

.calendar-corner,
.calendar-day,
.calendar-person,
.calendar-cell {
  min-width: 0;
  padding: 10px;
  background: var(--white);
}

.calendar-corner {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--blue);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: #f8fafc;
  text-align: center;
}

.calendar-person {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  background: #f8fafc;
  padding: 12px 10px;
}

.calendar-day {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  background: #f8fafc;
  border-right: 1px solid var(--line-light);
}

.calendar-day.is-today {
  background: var(--orange-soft);
  color: var(--orange-dark);
}

.calendar-day.is-today::after {
  content: "Aujourd'hui";
  display: block;
  font-size: 9px;
  font-weight: 800;
  color: var(--orange);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 2px;
}

.calendar-cell {
  display: grid;
  align-content: start;
  gap: 6px;
  min-height: 84px;
  transition: var(--transition);
}

.calendar-cell .task-card {
  padding: 8px 10px;
  font-size: 12px;
}

.calendar-cell .task-card-description,
.calendar-cell .task-card-actions {
  display: none;
}

.calendar-cell.is-over {
  background: var(--orange-soft);
  outline: 2px dashed var(--orange);
  outline-offset: -3px;
}

.tasks-empty {
  padding: 16px;
  border: 1.5px dashed #cbd5e1;
  border-radius: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

/* Modale Tâche */
.task-modal[hidden] {
  display: none !important;
}

.task-modal {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
}

.task-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 35, 64, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.task-modal-panel {
  position: relative;
  z-index: 1;
  width: min(100%, 460px);
  padding: 28px;
  border-radius: var(--radius-lg);
  background: var(--white);
  box-shadow: var(--shadow-lg);
  animation: slide-up 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.task-modal-panel h2 {
  margin: 0 0 10px;
  color: var(--blue);
  font-size: 20px;
  font-weight: 800;
}

@media (max-width: 1050px) {
  .tasks-layout > *,
  .tasks-planning,
  .tasks-sidebar {
    min-width: 0;
  }

  .tasks-calendar-wrap {
    width: 100%;
    overflow-x: auto;
  }

  .tasks-calendar {
    min-width: 860px;
  }
}

@media (max-width: 800px) {
  .tasks-layout {
    grid-template-columns: 1fr;
  }

  .tasks-sidebar {
    position: static;
  }
}

@media (max-width: 600px) {
  .tasks-page > .footer {
    width: calc(100% - 24px);
    margin-left: 12px;
  }

  .tasks-sidebar,
  .tasks-planning {
    padding: 18px;
  }

  .tasks-week-actions {
    align-items: stretch;
  }

  .tasks-week-actions > * {
    flex: 1 1 auto;
  }

  .tasks-week-label {
    order: -1;
    width: 100%;
  }

  .task-modal-panel {
    padding: 22px 18px;
  }
}

/* ==========================================================================
   TÂCHES QUOTIDIENNES (ROUTINE JOURNALIÈRE)
   ========================================================================== */

.tasks-divider {
  border: 0;
  height: 1px;
  background: var(--line-light);
  margin: 24px 0;
}

.daily-tasks-section {
  display: grid;
  gap: 16px;
  margin-bottom: 24px;
  padding: 20px;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  background: linear-gradient(180deg, #fbfcfe 0%, #ffffff 100%);
  box-shadow: 0 2px 8px rgba(12, 35, 64, 0.04);
}

.daily-tasks-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.daily-tasks-title-group {
  display: grid;
  gap: 4px;
}

.daily-tasks-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: fit-content;
  padding: 3px 10px;
  border-radius: 20px;
  background: #fff0e6;
  color: #df5d12;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.daily-tasks-title {
  margin: 0;
  color: var(--blue);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.4px;
}

.daily-tasks-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.daily-tasks-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.daily-date-navigator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
}

.daily-nav-btn {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--blue);
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  transition: var(--transition);
}

.daily-nav-btn:hover {
  background: var(--blue-soft);
  border-color: var(--line);
}

.daily-current-date {
  padding: 0 6px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.daily-nav-today-btn {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--blue);
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  transition: var(--transition);
}

.daily-nav-today-btn:hover {
  background: var(--blue-soft);
  border-color: var(--orange);
  color: var(--orange);
}

/* Barre de progression */
.daily-progress-wrap {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #f8fafc;
  border: 1px solid #eef2f6;
}

.daily-progress-bar {
  height: 8px;
  border-radius: 10px;
  background: #e2e8f0;
  overflow: hidden;
}

.daily-progress-fill {
  height: 100%;
  border-radius: 10px;
  background: var(--orange-gradient);
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.daily-progress-fill.is-all-done {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.daily-progress-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
}

.daily-progress-count {
  color: var(--blue);
}

.daily-progress-status {
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  background: #edf3f8;
  color: var(--muted);
}

.daily-progress-status.is-all-done {
  background: #edf8f1;
  color: #1d8051;
  font-weight: 800;
}

/* Grille des tâches quotidiennes */
.daily-tasks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 12px;
}

.daily-task-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: var(--white);
  box-shadow: var(--shadow-xs);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
}

.daily-task-card:hover {
  border-color: #cbd5e1;
  box-shadow: 0 4px 14px rgba(12, 35, 64, 0.08);
  transform: translateY(-1px);
}

.daily-task-card.is-completed {
  border-color: #86efac;
  background: #f0fdf4;
}

.daily-task-order {
  flex-shrink: 0;
  min-width: 32px;
  height: 24px;
  padding: 0 6px;
  margin-top: 1px;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: inline-grid;
  place-items: center;
}

.daily-order-badge {
  flex-shrink: 0;
  padding: 2px 8px;
  border-radius: 12px;
  background: #eef2ff;
  color: var(--blue);
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}

.daily-task-checkbox {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  margin-top: 1px;
  border: 2px solid #cbd5e1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--white);
  color: transparent;
  font-size: 13px;
  font-weight: 900;
  transition: all 0.2s ease;
}

.daily-task-card:hover .daily-task-checkbox {
  border-color: var(--orange);
}

.daily-task-card.is-completed .daily-task-checkbox {
  border-color: #16a34a;
  background: #16a34a;
  color: #ffffff;
  transform: scale(1.05);
}

.daily-task-body {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 4px;
}

.daily-task-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.daily-task-title {
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.35;
  transition: color 0.2s ease;
}

.daily-task-card.is-completed .daily-task-title {
  color: #166534;
  text-decoration: line-through;
  text-decoration-color: #86efac;
}

.daily-task-time {
  flex-shrink: 0;
  padding: 2px 6px;
  border-radius: 6px;
  background: #fff0e6;
  color: #c2410c;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}

.daily-task-desc {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.daily-task-validation-meta {
  margin-top: 2px;
  font-size: 10px;
  font-weight: 700;
  color: #15803d;
}

.daily-empty {
  padding: 24px;
  border: 2px dashed #cbd5e1;
  border-radius: 12px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

/* Modale de gestion des tâches quotidiennes */
.daily-manager-modal .task-modal-panel {
  width: min(100%, 620px);
  max-height: 88vh;
  overflow-y: auto;
}

.daily-manager-list {
  display: grid;
  gap: 8px;
  margin: 16px 0;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 4px;
}

.daily-manager-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
}

.daily-manager-item-info {
  flex: 1;
  min-width: 0;
}

.daily-manager-item-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
}

.daily-manager-item-desc {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.daily-manager-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Dark mode */
body.dark-mode .daily-tasks-section {
  background: var(--surface-alt);
  border-color: var(--line);
}

body.dark-mode .daily-date-navigator,
body.dark-mode .daily-task-card,
body.dark-mode .daily-manager-item {
  background: var(--surface-hover);
  border-color: var(--line);
}

body.dark-mode .daily-task-card.is-completed {
  background: rgba(22, 163, 74, 0.15);
  border-color: rgba(34, 197, 94, 0.4);
}

body.dark-mode .daily-task-checkbox {
  background: var(--surface-alt);
  border-color: var(--line);
}

body.dark-mode .daily-progress-wrap {
  background: var(--surface-alt);
  border-color: var(--line);
}

body.dark-mode .daily-tasks-title,
body.dark-mode .daily-current-date,
body.dark-mode .daily-task-title,
body.dark-mode .daily-manager-item-title {
  color: var(--text);
}

body.dark-mode .daily-task-card.is-completed .daily-task-title {
  color: #86efac;
}

body.dark-mode .tasks-divider {
  background: var(--line);
}

body.dark-mode .tasks-search-wrap {
  background: transparent;
}

body.dark-mode .tasks-search-wrap input[type="search"] {
  background: var(--surface-alt);
  border-color: var(--line);
  color: var(--text);
}

body.dark-mode .tasks-count {
  color: var(--text-muted);
}

body.dark-mode .daily-task-order {
  background: var(--orange);
}

body.dark-mode .daily-order-badge {
  background: rgba(243, 112, 33, 0.15);
  color: var(--orange);
}

body.dark-mode .tasks-field input,
body.dark-mode .tasks-field textarea,
body.dark-mode .tasks-field select,
body.dark-mode .tasks-button-secondary,
body.dark-mode .tasks-button-warning,
body.dark-mode .task-card {
  background: var(--surface-alt);
  border-color: var(--line);
  color: var(--text);
}

body.dark-mode .tasks-field input:focus,
body.dark-mode .tasks-field textarea:focus,
body.dark-mode .tasks-field select:focus {
  background: var(--surface-hover);
}

body.dark-mode .task-card.is-done {
  background: var(--green-soft);
}

body.dark-mode .task-card.is-not-done {
  background: var(--red-soft);
}

body.dark-mode .tasks-field input::placeholder,
body.dark-mode .tasks-field textarea::placeholder {
  color: var(--text-muted);
}

body.dark-mode .task-modal-panel .tasks-button-secondary,
body.dark-mode .task-modal-panel .tasks-button-warning {
  background: var(--surface-alt);
  border-color: var(--line);
  color: var(--text);
}

body.dark-mode .tasks-field input,
body.dark-mode .tasks-field textarea,
body.dark-mode #complete-comment {
  background: var(--surface-alt) !important;
  border-color: var(--line) !important;
  color: var(--text) !important;
  -webkit-text-fill-color: var(--text) !important;
  caret-color: var(--orange) !important;
}

body.dark-mode .tasks-field input::placeholder,
body.dark-mode .tasks-field textarea::placeholder,
body.dark-mode #complete-comment::placeholder {
  color: var(--text-muted) !important;
  -webkit-text-fill-color: var(--text-muted) !important;
}

/* Tablette */
@media (max-width: 1024px) {
  .tasks-layout,
  .tasks-layout-stacked {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
  }
}

/* Mobile */
@media (max-width: 768px) {
  .tasks-layout,
  .tasks-layout-stacked {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .tasks-sidebar,
  .tasks-planning {
    padding: 16px;
  }
  
  .tasks-section-title {
    font-size: 18px;
  }
  
  .tasks-section-text {
    font-size: 12px;
  }
  
  .tasks-form-actions {
    flex-direction: column;
  }
  
  .tasks-form-actions .tasks-button {
    width: 100%;
  }
}

/* Mobile petit */
@media (max-width: 480px) {
  .tasks-layout {
    gap: 12px;
  }
  
  .tasks-sidebar,
  .tasks-planning {
    padding: 14px;
    border-radius: 14px;
  }
  
  .tasks-template-list {
    max-height: 300px;
    grid-template-columns: minmax(0, 1fr);
  }
  
  .week-grid {
    font-size: 11px;
  }
  
  .week-day-column {
    min-width: 50px;
  }
  
  .week-hour-label {
    font-size: 10px;
  }
  
  .daily-tasks-header {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }
  
  .daily-date-navigator {
    flex-wrap: wrap;
  }
  
  .daily-task-card {
    padding: 12px;
  }
  
  .task-card {
    padding: 14px;
  }
}

/* Mode paysage mobile — on reste empilé pleine largeur */
@media (max-width: 768px) and (orientation: landscape) {
  .tasks-layout,
  .tasks-layout-stacked {
    display: flex;
    flex-direction: column;
  }

  .tasks-planning {
    overflow-x: auto;
  }
}
