/* ============================================================
   ProductivityHub — Panneau de paramètres (modale à onglets)
   Style inspiré des réglages Claude / ChatGPT :
   modale centrée + barre latérale d'onglets + zone de contenu.
   Chargé sur toutes les pages.
   ============================================================ */

.pf-settings-overlay {
  --pf-set-bg: #ffffff;
  --pf-set-sidebar-bg: #f7f7f5;
  --pf-set-text: #1d1d1f;
  --pf-set-muted: rgba(0, 0, 0, 0.55);
  --pf-set-faint: rgba(0, 0, 0, 0.4);
  --pf-set-border: rgba(0, 0, 0, 0.09);
  --pf-set-hover: rgba(0, 0, 0, 0.05);
  --pf-set-active: rgba(0, 0, 0, 0.075);
  --pf-set-accent: #3b82f6;
  --pf-set-accent-soft: rgba(59, 130, 246, 0.1);
  --pf-set-surface: rgba(0, 0, 0, 0.025);
}

[data-theme="dark"] .pf-settings-overlay {
  --pf-set-bg: #1c1c1e;
  --pf-set-sidebar-bg: #161618;
  --pf-set-text: #f5f5f7;
  --pf-set-muted: rgba(255, 255, 255, 0.6);
  --pf-set-faint: rgba(255, 255, 255, 0.4);
  --pf-set-border: rgba(255, 255, 255, 0.1);
  --pf-set-hover: rgba(255, 255, 255, 0.07);
  --pf-set-active: rgba(255, 255, 255, 0.1);
  --pf-set-accent: #60a5fa;
  --pf-set-accent-soft: rgba(96, 165, 250, 0.16);
  --pf-set-surface: rgba(255, 255, 255, 0.04);
}

/* ===== Bouton paramètres ===== */
.pf-settings-btn {
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.08);
  color: var(--text-primary, #1d1d1f);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}

[data-theme="dark"] .pf-settings-btn {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.pf-settings-btn:hover {
  transform: rotate(45deg);
  background: rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] .pf-settings-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.pf-settings-btn:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.pf-settings-btn--floating {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 999;
}

/* Dans Music et Discord, le bouton rejoint les actions du header afin de ne
   jamais recouvrir les commandes de l'application. */
.pf-settings-btn--embedded {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 10px;
}

.sp-header-actions .pf-settings-btn--embedded,
.dc-topbar-actions .pf-settings-btn--embedded {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.12);
  color: #f5f5f7;
}

.sp-header-actions .pf-settings-btn--embedded:hover,
.dc-topbar-actions .pf-settings-btn--embedded:hover {
  background: rgba(255, 255, 255, 0.14);
}

/* Quand le bouton de paramètres remplace .theme-toggle dans un header qui contient
   aussi le bouton d'auth (.global-auth-slot positionné top:20px right:20px), on déplace
   les paramètres sur le côté GAUCHE pour éviter toute superposition. */
.theme-toggle.pf-settings-btn {
  right: auto !important;
  left: 20px !important;
}

/* ===== Overlay ===== */
.pf-settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s ease, visibility 0.22s ease;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.pf-settings-overlay.open {
  opacity: 1;
  visibility: visible;
}

/* ===== Modale ===== */
.pf-settings-panel {
  background: var(--pf-set-bg);
  color: var(--pf-set-text);
  width: min(920px, 100%);
  height: min(640px, 100%);
  border-radius: 18px;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  transform: translateY(10px) scale(0.985);
  opacity: 0;
  transition: transform 0.26s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.26s ease;
}

.pf-settings-overlay.open .pf-settings-panel {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.pf-settings-panel *,
.pf-settings-panel *::before,
.pf-settings-panel *::after {
  box-sizing: border-box;
}

/* ===== Barre latérale ===== */
.pf-settings-sidebar {
  background: var(--pf-set-sidebar-bg);
  border-right: 1px solid var(--pf-set-border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 18px 12px 12px;
}

.pf-settings-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 10px 16px;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.pf-settings-brand i {
  color: var(--pf-set-muted);
  font-size: 14px;
}

.pf-settings-tabs {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  min-height: 0;
  flex: 1;
}

.pf-settings-tab {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 9px 11px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--pf-set-muted);
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.pf-settings-tab i {
  width: 17px;
  flex: 0 0 17px;
  font-size: 14px;
  text-align: center;
}

.pf-settings-tab:hover {
  background: var(--pf-set-hover);
  color: var(--pf-set-text);
}

.pf-settings-tab[aria-selected="true"] {
  background: var(--pf-set-active);
  color: var(--pf-set-text);
  font-weight: 600;
}

.pf-settings-tab:focus-visible {
  outline: 2px solid var(--pf-set-accent);
  outline-offset: -2px;
}

/* ===== Zone de contenu ===== */
.pf-settings-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.pf-settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--pf-set-border);
  flex-shrink: 0;
}

.pf-settings-header h2 {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin: 0;
  color: inherit;
}

.pf-settings-close {
  background: transparent;
  border: none;
  color: var(--pf-set-muted);
  font-size: 17px;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}

.pf-settings-close:hover {
  background: var(--pf-set-hover);
  color: var(--pf-set-text);
}

/* Zone défilante commune à tous les onglets. */
.pf-settings-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 20px 22px 24px;
}

.pf-settings-panes > [role="tabpanel"] {
  display: none;
}

.pf-settings-panes > [role="tabpanel"].is-active {
  display: block;
  animation: pf-settings-fade 0.18s ease;
}

/* `.pf-settings-body` reste le point de montage historique des modules
   externes (assets/js/ai-settings.js, apps/Knowvault/assets/js/knowvault.js).
   Ces modules font `querySelector('#pf-settings-overlay .pf-settings-body')`
   puis insèrent leur section avant `.pf-settings-section--footer`. On porte
   donc cette classe sur le panneau de l'onglet IA — et sur lui seul — pour
   que leurs sections atterrissent au bon endroit sans les modifier. */
.pf-settings-body {
  display: none;
}

.pf-settings-body.is-active {
  display: block;
}

/* ai-settings.css donne à sa section un `border-top` + `padding-top` : c'était
   un séparateur pertinent quand toutes les sections étaient empilées dans un
   drawer. En tête de son propre onglet, ce trait devient parasite. */
.pf-settings-body > .pf-ai-settings:first-child {
  border-top: none;
  padding-top: 0;
}

@keyframes pf-settings-fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* ===== Lignes de réglage (style Claude/ChatGPT) ===== */
.pf-settings-section {
  padding: 0;
}

.pf-settings-section + .pf-settings-section {
  margin-top: 26px;
}

.pf-settings-section > h3 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--pf-set-faint);
  margin: 0 0 10px;
}

.pf-settings-hint {
  font-size: 12.5px;
  color: var(--pf-set-muted);
  margin: 0 0 14px;
  line-height: 1.5;
}

/* Une ligne : libellé à gauche, contrôle à droite. */
.pf-settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 13px 0;
  border-top: 1px solid var(--pf-set-border);
}

.pf-settings-row:first-of-type {
  border-top: none;
}

.pf-settings-row-text {
  min-width: 0;
}

.pf-settings-row-text strong {
  display: block;
  font-size: 13.5px;
  font-weight: 550;
  line-height: 1.35;
}

.pf-settings-row-text small {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  color: var(--pf-set-muted);
  line-height: 1.45;
}

.pf-settings-row-control {
  flex: 0 0 auto;
}

.pf-settings-footnote {
  font-size: 11.5px;
  color: var(--pf-set-faint);
  line-height: 1.5;
  margin: 0;
}

.pf-settings-section--footer {
  margin-top: 26px;
  padding-top: 14px;
  border-top: 1px solid var(--pf-set-border);
}

/* ===== Menu déroulant natif stylé ===== */
.pf-settings-select {
  appearance: none;
  -webkit-appearance: none;
  background-color: var(--pf-set-bg);
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23888'%3E%3Cpath d='M4.2 6.2a1 1 0 0 1 1.4 0L8 8.6l2.4-2.4a1 1 0 1 1 1.4 1.4l-3.1 3.2a1 1 0 0 1-1.4 0L4.2 7.6a1 1 0 0 1 0-1.4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 15px;
  border: 1px solid var(--pf-set-border);
  border-radius: 8px;
  color: var(--pf-set-text);
  font-family: inherit;
  font-size: 13px;
  padding: 7px 30px 7px 11px;
  min-width: 148px;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.pf-settings-select:hover {
  border-color: var(--pf-set-muted);
}

.pf-settings-select:focus-visible {
  outline: none;
  border-color: var(--pf-set-accent);
  box-shadow: 0 0 0 3px var(--pf-set-accent-soft);
}

/* ===== Boutons ===== */
.pf-settings-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--pf-set-border);
  border-radius: 8px;
  background: var(--pf-set-bg);
  color: var(--pf-set-text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 550;
  padding: 7px 13px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.pf-settings-button:hover {
  background: var(--pf-set-hover);
}

.pf-settings-button:focus-visible {
  outline: 2px solid var(--pf-set-accent);
  outline-offset: 2px;
}

.pf-settings-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.pf-settings-button--primary {
  background: var(--pf-set-accent);
  border-color: transparent;
  color: #fff;
}

.pf-settings-button--primary:hover {
  background: var(--pf-set-accent);
  filter: brightness(1.07);
}

/* ===== Cartes de choix de style ===== */
.pf-settings-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.pf-settings-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border: 2px solid var(--pf-set-border);
  border-radius: 13px;
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease;
  background: var(--pf-set-surface);
}

.pf-settings-card:hover {
  border-color: rgba(59, 130, 246, 0.5);
}

.pf-settings-card input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.pf-settings-card:has(input:checked) {
  border-color: var(--pf-set-accent);
  background: var(--pf-set-accent-soft);
}

.pf-settings-card:has(input:focus-visible) {
  outline: 2px solid var(--pf-set-accent);
  outline-offset: 2px;
}

.pf-settings-card-label {
  font-size: 13px;
  font-weight: 600;
}

.pf-settings-card-preview {
  width: 100%;
  aspect-ratio: 1.5 / 1;
  border-radius: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 6px;
  padding: 10px;
  background: #f5f5f7;
}

[data-theme="dark"] .pf-settings-card-preview {
  background: #2c2c2e;
}

/* Aperçu Classique : cartes rectangulaires neumorphiques */
.pf-preview-classic span {
  background: linear-gradient(135deg, #c7d2fe, #93c5fd);
  border-radius: 6px;
  box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1), -2px -2px 4px rgba(255, 255, 255, 0.6);
}

[data-theme="dark"] .pf-preview-classic span {
  box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.4), -2px -2px 4px rgba(255, 255, 255, 0.05);
}

/* Aperçu iOS : icônes carrées arrondies */
.pf-preview-ios span {
  border-radius: 8px;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.15);
}
.pf-preview-ios span:nth-child(1) { background: linear-gradient(135deg, #3b82f6, #6366f1); }
.pf-preview-ios span:nth-child(2) { background: linear-gradient(135deg, #10b981, #06b6d4); }
.pf-preview-ios span:nth-child(3) { background: linear-gradient(135deg, #ef4444, #ec4899); }
.pf-preview-ios span:nth-child(4) { background: linear-gradient(135deg, #f59e0b, #f97316); }

/* ===== Segmented control (clair / sombre / auto) ===== */
.pf-settings-pills {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 3px;
  background: var(--pf-set-hover);
  padding: 3px;
  border-radius: 10px;
}

.pf-settings-pill {
  position: relative;
  cursor: pointer;
}

.pf-settings-pill input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.pf-settings-pill span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 13px;
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--pf-set-muted);
  transition: background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
  white-space: nowrap;
}

.pf-settings-pill:has(input:checked) span {
  background: var(--pf-set-bg);
  color: var(--pf-set-text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
  font-weight: 600;
}

[data-theme="dark"] .pf-settings-pill:has(input:checked) span {
  background: #3a3a3c;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.pf-settings-pill:hover span {
  color: var(--pf-set-text);
}

.pf-settings-pill:has(input:focus-visible) span {
  outline: 2px solid var(--pf-set-accent);
  outline-offset: 1px;
}

/* ===== Onglet « Thèmes des apps » ===== */
.pf-apps-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--pf-set-border);
  border-radius: 11px;
  background: var(--pf-set-surface);
  margin-bottom: 20px;
}

.pf-apps-banner i {
  color: var(--pf-set-accent);
  font-size: 14px;
  margin-top: 2px;
  flex: 0 0 auto;
}

.pf-apps-banner p {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--pf-set-muted);
}

/* Bloc « appliquer à toutes les apps » */
.pf-apps-master {
  border: 1px solid var(--pf-set-border);
  border-radius: 12px;
  padding: 14px 16px;
  background: var(--pf-set-surface);
  margin-bottom: 22px;
}

.pf-apps-master-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.pf-apps-master-head strong {
  font-size: 13.5px;
  font-weight: 600;
}

.pf-apps-master-head small {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  color: var(--pf-set-muted);
  line-height: 1.45;
}

.pf-apps-master-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Liste des apps */
.pf-apps-list {
  display: flex;
  flex-direction: column;
}

.pf-app-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-top: 1px solid var(--pf-set-border);
}

.pf-app-row:first-child {
  border-top: none;
}

.pf-app-icon {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
}

.pf-app-name {
  flex: 1;
  min-width: 0;
}

.pf-app-name strong {
  display: block;
  font-size: 13.5px;
  font-weight: 550;
  line-height: 1.3;
}

.pf-app-name small {
  display: block;
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--pf-set-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pf-app-row .pf-settings-select {
  min-width: 156px;
}

/* Badge « suit le thème global » */
.pf-app-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--pf-set-accent-soft);
  color: var(--pf-set-accent);
  margin-top: 4px;
}

.pf-apps-status {
  margin: 14px 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--pf-set-muted);
  min-height: 18px;
}

.pf-apps-status.is-success {
  color: #0f7b55;
}

[data-theme="dark"] .pf-apps-status.is-success {
  color: #34d399;
}

/* ===== Responsive ===== */
@media (max-width: 760px) {
  .pf-settings-overlay {
    padding: 0;
    align-items: stretch;
  }

  .pf-settings-panel {
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .pf-settings-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--pf-set-border);
    padding: 14px 12px 0;
  }

  .pf-settings-brand {
    padding-bottom: 12px;
  }

  /* Les onglets deviennent une barre horizontale défilante. */
  .pf-settings-tabs {
    flex-direction: row;
    gap: 4px;
    overflow-x: auto;
    overflow-y: hidden;
    flex: 0 0 auto;
    padding-bottom: 10px;
    scrollbar-width: none;
  }

  .pf-settings-tabs::-webkit-scrollbar {
    display: none;
  }

  .pf-settings-tab {
    width: auto;
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 8px 13px;
  }

  .pf-settings-header {
    padding: 14px 16px 12px;
  }

  .pf-settings-body {
    padding: 16px 16px 24px;
  }

  .pf-app-row {
    flex-wrap: wrap;
  }

  .pf-app-row .pf-settings-select {
    width: 100%;
    min-width: 0;
  }

  .pf-settings-cards {
    gap: 10px;
  }
}

@media (max-width: 420px) {
  .pf-settings-pills {
    display: grid;
    grid-auto-flow: row;
    grid-template-columns: repeat(3, 1fr);
    width: 100%;
  }

  .pf-settings-pill span {
    padding: 7px 4px;
    font-size: 11.5px;
  }

  .pf-settings-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .pf-settings-row-control {
    width: 100%;
  }

  .pf-settings-row-control .pf-settings-select {
    width: 100%;
  }
}

/* ===== Reduce motion ===== */
@media (prefers-reduced-motion: reduce) {
  .pf-settings-overlay,
  .pf-settings-panel,
  .pf-settings-btn,
  .pf-settings-card,
  .pf-settings-tab,
  .pf-settings-pill span {
    transition: none !important;
  }

  .pf-settings-panes > [role="tabpanel"].is-active {
    animation: none;
  }
}
