/*
 * ProductivityHub — accueil personnalisable : glisser-déposer des cartes
 * et panneau App Store. Complète assets/css/style.css sans le remplacer.
 */

/* ------------------------------------------------ barre d'actions ------- */

.home-actions {
  display: flex;
  justify-content: center;
  margin: 0 0 22px;
}

.home-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  border: none;
  border-radius: 14px;
  background: var(--card-bg, #fff);
  color: var(--text-primary, #1c1c1e);
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
  transition: transform 0.18s, box-shadow 0.18s;
}

.home-action-btn i {
  color: var(--primary-color, #007aff);
}

.home-action-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.12);
}

.home-hint {
  text-align: center;
  color: var(--text-secondary, #8e8e93);
  font-size: 0.82rem;
  margin: -10px 0 22px;
}

/* --------------------------------------------------- cartes : drag ------ */

.app-card {
  position: relative;
  touch-action: manipulation;
}

/* Pendant un déplacement, on empêche la sélection de texte parasite. */
body.is-dragging-app {
  user-select: none;
  cursor: grabbing;
}

.app-card--ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10001;
  pointer-events: none;
  opacity: 0.92;
  transform-origin: top left;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  transition: none;
  animation: none;
}

.app-card--placeholder {
  border: 2px dashed var(--primary-color, #007aff);
  background: transparent;
  box-shadow: none;
  animation: none;
  opacity: 0.6;
}

/* Cartes d'applications encore en développement. */
.app-card--dev {
  opacity: 0.9;
}

.app-dev-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(142, 142, 147, 0.16);
  color: var(--text-secondary, #8e8e93);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.app-link--disabled {
  display: inline-block;
  background-color: #9ca3af !important;
  box-shadow: none !important;
  cursor: not-allowed;
}

/* --------------------------------------------------------- App Store ---- */

.app-store {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: none;
}

body.app-store-open .app-store {
  display: block;
}

/* Pendant qu'on fait glisser une app hors du store, le panneau s'efface
   pour laisser voir et atteindre la grille de l'accueil. */
body.is-dragging-from-store .app-store-panel,
body.is-dragging-from-store .app-store-backdrop {
  opacity: 0.12;
  pointer-events: none;
}

.app-store-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  transition: opacity 0.2s;
}

.app-store-panel {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: min(460px, 100%);
  overflow-y: auto;
  padding: 22px 22px 40px;
  background: var(--bg-color, #f2f2f7);
  box-shadow: -10px 0 40px rgba(0, 0, 0, 0.2);
  transition: opacity 0.2s;
}

.app-store-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.app-store-head h2 {
  margin: 0;
  font-size: 1.4rem;
  color: var(--text-primary, #1c1c1e);
}

.app-store-close {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--card-bg, #fff);
  color: var(--text-secondary, #8e8e93);
  cursor: pointer;
}

.app-store-hint {
  margin: 0 0 18px;
  color: var(--text-secondary, #8e8e93);
  font-size: 0.82rem;
}

.app-store-section {
  margin: 22px 0 12px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary, #8e8e93);
}

.app-store-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}

/* Dans le store, les cartes sont compactes. `.app-card` demarre a opacity 0
   et compte sur l'animation d'apparition : en coupant l'animation il faut
   donc remettre l'opacite a 1, sinon les cartes sont invisibles. */
.app-store-grid .app-card {
  padding: 14px 10px;
  margin: 0;
  animation: none;
  opacity: 1;
  cursor: grab;
}

.app-store-grid .app-icon-container {
  width: 52px;
  height: 52px;
  margin-bottom: 8px;
}

.app-store-grid .app-icon {
  font-size: 22px !important;
}

.app-store-grid .app-title {
  font-size: 0.9rem;
  margin: 0 0 8px;
}

.app-store-grid .app-link,
.app-store-grid .app-dev-badge {
  display: none;
}

.app-store-add {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--primary-color, #007aff);
  color: #fff;
  font-size: 0.78rem;
  cursor: pointer;
}

.app-store-empty {
  color: var(--text-secondary, #8e8e93);
  font-size: 0.85rem;
}

.app-store-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.app-store-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--card-bg, #fff);
}

.app-store-row-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  color: #fff;
  font-size: 0.85rem;
}

.app-store-row-name {
  flex: 1;
  font-size: 0.9rem;
  color: var(--text-primary, #1c1c1e);
}

.app-store-remove {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 59, 48, 0.12);
  color: var(--danger-color, #ff3b30);
  cursor: pointer;
}

@media (max-width: 560px) {
  .app-store-panel {
    width: 100%;
    top: auto;
    height: 86vh;
    border-radius: 20px 20px 0 0;
  }
}

/* Cartes : jamais de selection de texte ni de drag natif de l'icone, sinon
   le navigateur intercepte le geste et le glisser-deposer n'a jamais lieu. */
.app-card,
.app-card * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}

.app-card img,
.app-card i {
  pointer-events: none;
}

/* Choix de la couleur du logo, dans l'App Store. */
.app-store-color {
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: none;
  cursor: pointer;
}

.app-store-color::-webkit-color-swatch-wrapper { padding: 2px; }
.app-store-color::-webkit-color-swatch {
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 6px;
}

.app-store-reset {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(142, 142, 147, 0.16);
  color: var(--text-secondary, #8e8e93);
  cursor: pointer;
  font-size: 0.72rem;
}

/* Meme piege pour les cartes re-rendues apres le premier affichage : rejouer
   l'animation d'entree a chaque reordonnancement faisait clignoter la grille. */
.app-card--no-anim {
  animation: none !important;
  opacity: 1 !important;
}

/* ------------------------------------------- mode edition facon iOS ------ */

@keyframes pf-jiggle {
  0%   { transform: rotate(-1.1deg) translateY(0); }
  50%  { transform: rotate(1.1deg) translateY(-1px); }
  100% { transform: rotate(-1.1deg) translateY(0); }
}

body.home-edit .app-card {
  animation: pf-jiggle 0.28s ease-in-out infinite !important;
  opacity: 1 !important;
}

/* Desynchronise les cartes pour que le tremblement ne soit pas mecanique. */
body.home-edit .app-card:nth-child(even) { animation-delay: 0.09s !important; }
body.home-edit .app-card:nth-child(3n)   { animation-delay: 0.05s !important; }

/* En mode edition, une carte ne s'ouvre plus : elle se deplace ou se retire. */
body.home-edit .app-link {
  pointer-events: none !important;
}

body.home-edit .app-card--ghost,
body.home-edit .app-card--placeholder {
  animation: none !important;
}

/* Pastille « retirer », comme la croix des icones iOS. */
.app-remove-badge {
  position: absolute;
  top: -6px;
  left: -6px;
  z-index: 6;
  display: none;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: #ff3b30;
  color: #fff;
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

body.home-edit .app-remove-badge {
  display: block;
}

/* Bouton « Terminé », visible seulement en mode edition. */
#home-edit-done {
  display: none;
}

body.home-edit #home-edit-done {
  display: inline-flex;
}

body.home-edit #open-app-store {
  display: none;
}

/* Carte en cours de deplacement : elle doit liberer sa place dans la grille.
   Deux pieges cumules ici, tous deux constates a l'ecran le 2026-08-29 :
   1. la feuille iOS impose `display: flex !important` sur .app-card, ce qu'un
      style inline ne bat pas — d'ou le passage par une classe ;
   2. `html[data-style="ios"] .app-card` a une specificite (0,2,1) SUPERIEURE
      a `.app-card--dragging` (0,1,0) : entre deux `!important`, c'est la
      specificite qui tranche. Il faut donc monter au-dessus. */
.app-card--dragging,
html[data-style] .app-card.app-card--dragging,
html .app-card.app-card--dragging {
  display: none !important;
}
