/* recurring/recurring.css */

/* ══════════════════════════════════════════════════════════════
   PANNEAU LATÉRAL — DESKTOP
══════════════════════════════════════════════════════════════ */

#recurring-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 260px;
  height: 100dvh;
  background: #1e2a38;
  color: #e8edf2;
  display: flex;
  flex-direction: column;
  z-index: 900;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.35);
  transform: translateX(105%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  border-left: 1px solid #2c3e50;
}

#recurring-panel.open {
  transform: translateX(0);
}

/* ── En-tête ──────────────────────────────────────────────── */
#rp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  font-weight: 700;
  font-size: 0.95rem;
  background: #2c3e50;
  border-bottom: 1px solid #3d5166;
  flex-shrink: 0;
}

#rp-close {
  background: none;
  border: none;
  color: #e8edf2;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 4px;
  transition: background 0.15s;
}

#rp-close:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* ── Liste scrollable ─────────────────────────────────────── */
#rp-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 6px;
  display: flex;
  flex-wrap: wrap;
  flex-direction: row;
  align-content: flex-start;
  gap: 15px;
  scrollbar-width: thin;
  scrollbar-color: #3d5166 transparent;
}

#rp-list::-webkit-scrollbar {
  width: 5px;
}
#rp-list::-webkit-scrollbar-thumb {
  background: #3d5166;
  border-radius: 3px;
}

.rp-empty {
  font-size: 0.82rem;
  color: #7f9ab0;
  text-align: center;
  padding: 24px 8px;
  line-height: 1.6;
}

/* ── Wrapper item (card + formulaire inline) ──────────────── */
.rp-item {
  display: flex;
  flex-direction: column;
  gap: 0;
  width: 140px;
  flex-shrink: 0;
}

/* ── Card template ────────────────────────────────────────── */
.rp-card {
  background: var(--rp-bg, #cce5ff);
  color: var(--rp-txt, #003366);
  border-radius: 7px 7px 0 0;
  padding: 9px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition:
    transform 0.13s,
    box-shadow 0.13s,
    opacity 0.13s;
  user-select: none;
  border: 2px solid transparent;
  max-width: 220px;
  min-height: 48px;
  max-height: 72px;
  overflow: hidden;
}

/* Quand le formulaire est ouvert → angles bas carrés */
.rp-item:has(.rp-place-form[style*="block"]) .rp-card {
  border-radius: 7px 7px 0 0;
  border-bottom-color: rgba(0, 0, 0, 0.15);
}

.rp-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
}

.rp-card.rp-dragging {
  opacity: 0.4;
}

.rp-card-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.rp-card-title {
  font-weight: 700;
  font-size: 0.84rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.rp-card-dur {
  font-size: 0.71rem;
  opacity: 0.72;
  white-space: nowrap;
}

.rp-card-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.rp-btn-place,
.rp-btn-edit,
.rp-btn-del {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 3px 5px;
  border-radius: 4px;
  opacity: 0.65;
  transition:
    opacity 0.15s,
    background 0.15s;
  line-height: 1;
  color: inherit;
}

.rp-btn-place:hover,
.rp-btn-edit:hover,
.rp-btn-del:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.1);
}

/* Highlight slot drag-over */
td.slot.rp-drag-over {
  outline: 2px dashed #1a73e8;
  background: rgba(26, 115, 232, 0.12);
}

/* ── Formulaire de placement inline ──────────────────────── */
.rp-place-form {
  background: #162130;
  border: 1px solid #3d5166;
  border-top: none;
  border-radius: 0 0 7px 7px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rp-place-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}

.rp-place-row > div {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.rp-place-row label {
  font-size: 0.72rem;
  color: #a0b4c4;
  font-weight: 600;
}

.rp-place-row select,
.rp-place-form select {
  padding: 5px 4px;
  border: 1px solid #3d5166;
  border-radius: 5px;
  font-size: 0.78rem;
  background: #1e2a38;
  color: #e8edf2;
  width: 100%;
  cursor: pointer;
}

.rp-conflict-msg {
  font-size: 0.78rem;
  color: #f6ad55;
  background: rgba(246, 173, 85, 0.1);
  border: 1px solid rgba(246, 173, 85, 0.3);
  border-radius: 5px;
  padding: 5px 8px;
}

.rp-btn-confirm {
  width: 100%;
  padding: 8px 0;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.rp-btn-confirm:hover {
  opacity: 0.88;
}

.rp-btn-confirm.success {
  background: #38a169;
  color: #fff;
}
.rp-btn-confirm.warn {
  background: #d69e2e;
  color: #fff;
}

/* ── Pied du panneau ──────────────────────────────────────── */
#rp-footer {
  padding: 10px;
  flex-shrink: 0;
  border-top: 1px solid #3d5166;
}

#rp-add {
  width: 100%;
  padding: 9px 0;
  background: #1a73e8;
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: 0.87rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

#rp-add:hover {
  background: #1557b0;
}

#btn-recurring.active {
  background: #1557b0;
  color: #fff;
}

/* ══════════════════════════════════════════════════════════════
   MODAL ÉDITION TEMPLATE
══════════════════════════════════════════════════════════════ */

#rp-edit-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

#rp-edit-overlay.open {
  opacity: 1;
  pointer-events: all;
}

#rp-edit-modal {
  background: #fff;
  border-radius: 12px;
  padding: 24px 28px 20px;
  width: min(340px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
  transform: translateY(12px);
  transition: transform 0.22s;
  max-height: 90dvh;
  overflow-y: auto;
}

#rp-edit-overlay.open #rp-edit-modal {
  transform: translateY(0);
}

#rp-edit-modal h2 {
  margin: 0 0 6px;
  font-size: 1.05rem;
  color: #1e2a38;
}

#rp-edit-modal label {
  font-size: 0.82rem;
  font-weight: 600;
  color: #4a5568;
  margin-top: 4px;
}

#rp-edit-modal select,
#rp-edit-modal input[type="text"],
#rp-edit-modal textarea {
  padding: 7px 10px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 0.9rem;
  background: #f7fafc;
  color: #1e2a38;
  width: 100%;
  box-sizing: border-box;
  transition: border-color 0.15s;
}

#rp-edit-modal textarea {
  resize: vertical;
  min-height: 56px;
}

#rp-edit-modal select:focus,
#rp-edit-modal input:focus,
#rp-edit-modal textarea:focus {
  outline: none;
  border-color: #1a73e8;
}

.rp-input-error {
  border-color: #e53e3e !important;
  animation: rp-shake 0.3s ease;
}

@keyframes rp-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

.color-row {
  display: flex;
  gap: 16px;
}

.color-row div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.color-row input[type="color"] {
  width: 100%;
  height: 36px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  cursor: pointer;
  padding: 2px;
  background: #f7fafc;
}

#rp-edit-btns {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

#rp-edit-btns button {
  flex: 1;
  padding: 9px 0;
  border: none;
  border-radius: 7px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

#rp-edit-btns button:hover {
  opacity: 0.88;
}
#rp-edit-btns .danger {
  background: #e53e3e;
  color: #fff;
}
#rp-edit-btns .success {
  background: #38a169;
  color: #fff;
}

/* ══════════════════════════════════════════════════════════════
   TOAST
══════════════════════════════════════════════════════════════ */

.rp-toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: #1e2a38;
  color: #e8edf2;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition:
    opacity 0.25s,
    transform 0.25s;
  pointer-events: none;
  z-index: 1200;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rp-toast.rp-toast-in {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Poignée resize — DESKTOP (bord gauche) ──────────────── */
#rp-resize-handle {
  position: absolute;
  left: 0;
  top: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 10;
  background: transparent;
  transition: background 0.15s;
}

#rp-resize-handle:hover,
#rp-resize-handle.dragging {
  background: rgba(26, 115, 232, 0.4);
}

/* ── Poignée resize — MOBILE (barre en haut du bottom sheet) */
@media (max-width: 768px) {
  #rp-resize-handle {
    position: relative !important;
    left: auto !important;
    top: auto !important;
    width: 100% !important;
    height: 36px !important;
    cursor: ns-resize;
    display: flex !important;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: #2c3e50;
    border-radius: 16px 16px 0 0;
    z-index: 10;
    touch-action: none;
  }

  #rp-resize-handle::after {
    content: "";
    width: 40px;
    height: 5px;
    border-radius: 3px;
    background: #6b8599;
    transition:
      background 0.15s,
      width 0.15s;
  }

  #rp-resize-handle.dragging::after {
    background: #1a73e8;
    width: 56px;
  }

  /* snapping animé */
  #recurring-panel.snapping {
    transition:
      transform 0.28s cubic-bezier(0.4, 0, 0.2, 1),
      height 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .rp-toast {
    bottom: calc(var(--panel-h, 45dvh) + 12px);
  }
}

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE / TABLETTE
══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  #recurring-panel {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100vw !important; /* ← toute la largeur */
    height: 45dvh;
    border-left: none;
    border-top: 2px solid #3d5166;
    border-radius: 16px 16px 0 0;
    transform: translateY(105%);
    box-shadow: 0 -6px 28px rgba(0, 0, 0, 0.38);
  }

  #recurring-panel.open {
    transform: translateY(0);
  }

  .rp-item {
    width: calc(50% - 8px); /* 2 cards par ligne sur mobile */
  }

  .rp-card {
    min-width: 0;
    max-width: none;
    min-height: 44px;
    max-height: 74px;
  }

  /* Sur mobile, le formulaire inline passe en pleine largeur */
  .rp-place-form {
    grid-column: 1 / -1;
    border-radius: 0 0 7px 7px;
  }

  .rp-place-row {
    /* 3 colonnes serrées sur petit écran */
    grid-template-columns: 1fr 1fr 1fr;
    gap: 4px;
  }

  .rp-place-row select {
    font-size: 0.72rem;
    padding: 4px 2px;
  }

  /* Toast au-dessus du bottom sheet */
  .rp-toast {
    bottom: calc(45dvh + 12px);
  }
}

/* Impression */
@media print {
  #recurring-panel,
  #btn-recurring,
  #rp-edit-overlay {
    display: none !important;
  }
}
