/* =============================================================================
 * css/style.css — BiblioPrompt
 * -----------------------------------------------------------------------------
 * PALETTE IMPOSÉE : rouge, gris, blanc, noir. Aucune autre teinte.
 *   - Rouge = couleur d'accent unique (actions principales, état actif, favori,
 *     danger). On nuance le danger par une variante plus sombre du même rouge.
 *   - Gris = toute la hiérarchie de surfaces et de textes secondaires.
 *   - Blanc / noir = fonds et textes selon le thème.
 * Les puces d'IA n'ont PAS de couleur propre : elles utilisent des niveaux de
 * gris (classes .tone-0..3), la plus intense tirant vers le rouge.
 *
 * Thèmes pilotés par [data-theme] ; bascule auto via JS.
 * La variable sentinelle --bp-loaded sert au garde-fou de décompression (§2).
 * ========================================================================== */

:root { --bp-loaded: 1; }

/* ---------- THÈME CLAIR (blanc + gris, accent rouge) ---------- */
:root, :root[data-theme="light"] {
  --red:          #d32128;   /* accent unique */
  --red-strong:   #a51017;   /* danger / hover */
  --red-soft:     #fbe7e8;   /* fond léger d'état actif */
  --on-red:       #ffffff;

  --bg:           #f4f4f5;   /* gris très clair */
  --surface:      #ffffff;   /* blanc */
  --surface-2:    #ededf0;
  --surface-3:    #e3e3e7;
  --on-surface:   #161618;   /* quasi-noir */
  --on-surface-var:#5f5f66;  /* gris texte secondaire */
  --outline:      #d2d2d7;
  --outline-soft: #e8e8ec;

  --star:         var(--red);

  --shadow-1: 0 1px 2px rgba(0,0,0,.10);
  --shadow-2: 0 4px 12px rgba(0,0,0,.12);
  --shadow-3: 0 12px 30px rgba(0,0,0,.20);
}

/* ---------- THÈME SOMBRE (noir + gris, accent rouge) ---------- */
:root[data-theme="dark"] {
  --red:          #ff5a5f;
  --red-strong:   #ff7a7e;
  --red-soft:     #3a1d1f;
  --on-red:       #14070800;  /* texte sombre sur rouge clair */
  --on-red:       #1a0d0e;

  --bg:           #0e0e10;   /* quasi-noir */
  --surface:      #1a1a1d;
  --surface-2:    #232327;
  --surface-3:    #2c2c31;
  --on-surface:   #f1f1f3;   /* quasi-blanc */
  --on-surface-var:#a1a1aa;  /* gris clair */
  --outline:      #38383e;
  --outline-soft: #2a2a2f;

  --star:         var(--red);

  --shadow-1: 0 1px 2px rgba(0,0,0,.5);
  --shadow-2: 0 4px 14px rgba(0,0,0,.55);
  --shadow-3: 0 14px 34px rgba(0,0,0,.65);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--on-surface);
  font-family: "Inter", "Roboto", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
button { font-family: inherit; cursor: pointer; color: inherit; }
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

/* Icônes Material. Repli si le CDN est bloqué : on masque le texte de ligature. */
.mi {
  font-family: "Material Icons"; font-weight: normal; font-style: normal;
  font-size: 20px; line-height: 1; vertical-align: middle; white-space: nowrap;
  -webkit-font-feature-settings: "liga"; font-feature-settings: "liga";
}
.no-icons .mi { font-size: 0 !important; }

/* ======================= BARRE D'APPLICATION ======================= */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 24px; background: var(--surface);
  border-bottom: 1px solid var(--outline-soft); box-shadow: var(--shadow-1);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  background: var(--red); color: var(--on-red); box-shadow: var(--shadow-1);
}
.brand-mark .mi { font-size: 22px; }
.brand h1 { font-size: 20px; letter-spacing: .2px; }
.brand .sub { font-size: 12px; color: var(--on-surface-var); margin-top: -2px; }
.appbar-spacer { flex: 1; }
.appbar-actions { display: flex; align-items: center; gap: 4px; }

/* ======================= BOUTONS ======================= */
.btn {
  position: relative; display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid transparent; border-radius: 999px;
  padding: 10px 20px; font-size: 14px; font-weight: 600;
  background: var(--surface-2); color: var(--on-surface);
  transition: background .15s, box-shadow .15s, transform .05s, border-color .15s;
}
.btn:active { transform: scale(.98); }
.btn .mi { font-size: 18px; }
.btn-primary { background: var(--red); color: var(--on-red); box-shadow: var(--shadow-1); }
.btn-primary:hover { background: var(--red-strong); box-shadow: var(--shadow-2); }
.btn-ghost { background: transparent; border-color: var(--outline); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-text { background: transparent; }
.btn-text:hover { background: var(--surface-2); }
.btn-danger { background: var(--red-strong); color: #fff; }
.btn-danger:hover { filter: brightness(.92); }

.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border: none; border-radius: 50%; background: transparent; color: var(--on-surface-var);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--on-surface); }
.icon-btn.active { color: var(--red); }
.star.star-on { color: var(--star); }

/* ======================= RECHERCHE + TRI ======================= */
.toolbar { max-width: 1180px; margin: 0 auto; padding: 24px 24px 0; }
.search-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.search-field { position: relative; flex: 1; min-width: 240px; }
.search-field .mi.lead {
  position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  color: var(--on-surface-var); pointer-events: none;
}
.search-field input {
  width: 100%; height: 52px; padding: 0 48px;
  border: 1px solid var(--outline); border-radius: 28px;
  background: var(--surface); color: var(--on-surface); font-size: 15px;
  transition: border-color .15s, box-shadow .15s;
}
.search-field input:focus {
  outline: none; border-color: var(--red);
  box-shadow: 0 0 0 3px var(--red-soft);
}
.search-field .clear { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); }

.sort-field { position: relative; }
.sort-field select {
  height: 52px; padding: 0 40px 0 16px;
  border: 1px solid var(--outline); border-radius: 16px;
  background: var(--surface); color: var(--on-surface);
  font-size: 14px; appearance: none; cursor: pointer;
}
.sort-field::after {
  content: "expand_more"; font-family: "Material Icons";
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  pointer-events: none; color: var(--on-surface-var);
}

/* ======================= FILTRES ======================= */
.filters { max-width: 1180px; margin: 16px auto 0; padding: 0 24px; display: grid; gap: 10px; }
.filter-line { display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.filter-label {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px;
  color: var(--on-surface-var); padding-top: 8px; min-width: 52px;
}
.chip-wrap { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; }
.filter-empty { color: var(--on-surface-var); font-size: 13px; padding-top: 7px; }

/* Chips (gris ; actif = rouge) */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--outline); border-radius: 999px;
  padding: 6px 14px; font-size: 13px; font-weight: 600;
  background: var(--surface); color: var(--on-surface);
  transition: background .15s, border-color .15s, color .15s;
}
.chip-filter::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: .55; }
.chip-filter:hover, .chip-tag:hover { border-color: var(--red); }
.chip-active { background: var(--red); color: var(--on-red); border-color: transparent; }
.chip-active::before { opacity: .9; }
.chip-count { font-size: 11px; opacity: .7; background: var(--surface-2); border-radius: 999px; padding: 1px 7px; }
.chip-active .chip-count { background: rgba(0,0,0,.18); }

/* Niveaux de gris des puces d'IA (tone-0..3), la plus forte tire vers le rouge */
.tone-0 { --tone-bg: var(--surface-2);  --tone-fg: var(--on-surface-var); }
.tone-1 { --tone-bg: var(--surface-3);  --tone-fg: var(--on-surface); }
.tone-2 { --tone-bg: #cfcfd6;           --tone-fg: #161618; }
.tone-3 { --tone-bg: var(--red-soft);   --tone-fg: var(--red-strong); }
:root[data-theme="dark"] .tone-2 { --tone-bg: #3a3a41; --tone-fg: #f1f1f3; }

/* ======================= GRILLE + CARTES ======================= */
.statusbar {
  max-width: 1180px; margin: 18px auto 0; padding: 0 24px;
  display: flex; align-items: center; gap: 12px; color: var(--on-surface-var); font-size: 13px;
}
.statusbar .reset { margin-left: auto; font-size: 13px; padding: 6px 14px; }
.grid {
  max-width: 1180px; margin: 12px auto 120px; padding: 0 24px;
  display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
}
.card {
  display: flex; flex-direction: column; gap: 12px;
  background: var(--surface); border: 1px solid var(--outline-soft); border-radius: 18px;
  padding: 20px; box-shadow: var(--shadow-1);
  transition: box-shadow .2s, transform .1s, border-color .2s;
}
.card:hover { box-shadow: var(--shadow-2); transform: translateY(-2px); }
.card-fav { border-color: var(--red); }
.card-head { display: flex; align-items: flex-start; gap: 8px; }
.card-title { flex: 1; font-size: 17px; line-height: 1.3; word-break: break-word; }
.card-desc { margin: 0; color: var(--on-surface-var); font-size: 14px; }
.card-content {
  margin: 0; padding: 12px 14px; background: var(--surface-2); border-radius: 10px;
  font-family: "Roboto Mono", ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12.5px; line-height: 1.5; color: var(--on-surface);
  white-space: pre-wrap; word-break: break-word; max-height: 168px; overflow: auto;
}
.card-targets, .card-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-target {
  padding: 4px 11px; font-size: 12px; border-color: transparent;
  background: var(--tone-bg); color: var(--tone-fg);
}
.tag-link {
  border: none; background: transparent; padding: 2px 4px;
  color: var(--red); font-size: 13px; font-weight: 600; border-radius: 6px;
}
.tag-link:hover { background: var(--surface-2); }
.card-foot {
  margin-top: auto; display: flex; align-items: center; gap: 10px;
  padding-top: 12px; border-top: 1px solid var(--outline-soft);
}
.card-meta { flex: 1; font-size: 12.5px; color: var(--on-surface-var); }
.card-actions { display: flex; align-items: center; gap: 4px; }
.copy-btn { padding: 8px 16px; font-size: 13px; }
.copy-btn.copied { background: var(--red-strong); }

/* ======================= PARTAGE PAR LIEN ======================= */
.share-link-row { display: flex; gap: 8px; margin-bottom: 8px; }
.share-link-row input {
  flex: 1; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--outline);
  background: var(--surface-2); color: var(--on-surface-var); font-size: 13px;
}

/* ======================= AFFICHAGE COMPACT ======================= */
/* La structure DOM des cartes est identique en grille/compact : seul l'attribut
   data-view du conteneur change, le reste est purement CSS. */
.grid[data-view="compact"] {
  display: flex; flex-direction: column; gap: 8px;
}
.grid[data-view="compact"] .card {
  flex-direction: row; align-items: center; gap: 14px;
  padding: 10px 16px; border-radius: 12px;
}
.grid[data-view="compact"] .card-head { flex: 0 0 auto; width: 220px; min-width: 0; }
.grid[data-view="compact"] .card-desc,
.grid[data-view="compact"] .card-content { display: none; }
.grid[data-view="compact"] .card-targets,
.grid[data-view="compact"] .card-tags { flex: 0 0 auto; max-width: 220px; }
.grid[data-view="compact"] .card-foot {
  margin-top: 0; margin-left: auto; padding-top: 0; border-top: none;
  flex: 0 0 auto; gap: 8px;
}
.grid[data-view="compact"] .card-meta { display: none; }
@media (max-width: 720px) {
  .grid[data-view="compact"] .card { flex-wrap: wrap; }
  .grid[data-view="compact"] .card-head { width: 100%; }
}

/* ======================= ÉTAT VIDE ======================= */
.empty { max-width: 460px; margin: 60px auto; text-align: center; padding: 0 24px; }
.empty .mi { font-size: 64px; color: var(--on-surface-var); opacity: .5; }
.empty h2 { font-size: 20px; margin: 16px 0 8px; }
.empty p { color: var(--on-surface-var); margin: 0 0 24px; }

/* ======================= FAB ======================= */
.fab {
  position: fixed; right: 28px; bottom: 28px; z-index: 30;
  display: inline-flex; align-items: center; gap: 10px;
  border: none; border-radius: 16px; padding: 16px 22px; font-size: 15px; font-weight: 700;
  background: var(--red); color: var(--on-red); box-shadow: var(--shadow-3);
  transition: transform .12s, box-shadow .2s, background .15s;
}
.fab:hover { transform: translateY(-2px); background: var(--red-strong); }
.fab .mi { font-size: 22px; }

/* ======================= DIALOGUES ======================= */
dialog {
  border: none; border-radius: 22px; padding: 0;
  background: var(--surface); color: var(--on-surface); box-shadow: var(--shadow-3);
  max-width: 640px; width: calc(100% - 32px);
}
dialog::backdrop { background: rgba(0,0,0,.55); }
.dialog-head { display: flex; align-items: center; gap: 12px; padding: 24px 24px 8px; }
.dialog-head h2 { font-size: 20px; flex: 1; }
.dialog-body { padding: 8px 24px; max-height: 64vh; overflow: auto; }
.dialog-foot { display: flex; align-items: center; gap: 8px; padding: 16px 24px 24px; flex-wrap: wrap; }
.dialog-foot .spacer { flex: 1; }

.field { margin-bottom: 18px; }
.field > label { display: block; font-size: 13px; font-weight: 600; color: var(--on-surface-var); margin-bottom: 6px; }
.field input[type="text"], .field textarea {
  width: 100%; padding: 12px 14px; border: 1px solid var(--outline); border-radius: 10px;
  background: var(--surface); color: var(--on-surface); font-family: inherit; font-size: 14px; resize: vertical;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea#field-content { font-family: "Roboto Mono", ui-monospace, monospace; min-height: 150px; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.field .hint { font-size: 12px; color: var(--on-surface-var); margin-top: 5px; }

.check-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.check-chip {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--outline); border-radius: 999px; padding: 7px 14px;
  font-size: 13px; cursor: pointer; user-select: none;
  transition: background .15s, border-color .15s, color .15s;
}
.check-chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--tone-bg); }
.check-chip input { position: absolute; opacity: 0; width: 0; height: 0; }
.check-chip:hover { border-color: var(--red); }
.check-chip:has(input:checked) { background: var(--red); border-color: transparent; color: var(--on-red); }
.check-chip:has(input:checked)::before { background: rgba(255,255,255,.85); }
/* repli si :has() non supporté : on s'appuie sur la classe ajoutée par JS au besoin */

/* Aide */
.help-item { margin-bottom: 18px; }
.help-item h3 { font-size: 15px; margin-bottom: 4px; }
.help-item p { margin: 0; color: var(--on-surface-var); font-size: 14px; }
.help-foot { text-align: center; color: var(--on-surface-var); font-size: 12px; padding: 8px 0 0; border-top: 1px solid var(--outline-soft); margin-top: 8px; }

/* ======================= TOAST ======================= */
#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 16px);
  z-index: 60; max-width: 90vw; background: var(--on-surface); color: var(--surface);
  padding: 13px 20px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow-3);
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
}
#toast.toast-show { opacity: 1; transform: translate(-50%, 0); }

/* ======================= SPLASH ======================= */
#splash {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: var(--bg); transition: opacity .4s;
}
#splash.hide { opacity: 0; pointer-events: none; }
.splash-mark {
  width: 64px; height: 64px; border-radius: 16px; background: var(--red); color: var(--on-red);
  display: grid; place-items: center; animation: pulse 1.1s ease-in-out infinite; box-shadow: var(--shadow-2);
}
.splash-mark .mi { font-size: 34px; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.12); } }
@media (prefers-reduced-motion: reduce) { .splash-mark { animation: none; } .card:hover { transform: none; } }

/* ======================= GARDE-FOU DE DÉCOMPRESSION ======================= */
#unzip-error {
  position: fixed; inset: 0; z-index: 200; display: none; place-items: center; padding: 24px;
  background: #0e0e10; color: #fff;
}
#unzip-error .box { max-width: 480px; background: #1a1a1d; border-radius: 14px; padding: 28px; border: 1px solid var(--red); }
#unzip-error h2 { color: #ff5a5f; margin-bottom: 12px; }
#unzip-error p { color: #d0d0d4; line-height: 1.6; }

/* ======================= CONFIGURATION DES CIBLES IA ======================= */
.config-hint {
  font-size: 13px; color: var(--on-surface-var); margin: 0 0 14px; line-height: 1.5;
}
#config-list { display: flex; flex-direction: column; }
.config-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--outline-soft);
}
.config-row:last-child { border-bottom: none; }

/* Pastilles de sélection de ton */
.tone-picker { display: flex; gap: 5px; flex-shrink: 0; }
.tone-dot {
  width: 20px; height: 20px; border-radius: 50%; padding: 0;
  border: 2px solid transparent; background: var(--tone-bg);
  cursor: pointer; transition: border-color .15s, transform .1s;
}
.tone-dot:hover { transform: scale(1.18); }
.tone-dot.tone-dot-active {
  border-color: var(--on-surface); transform: scale(1.12);
}

/* Champ label */
.config-label {
  flex: 1; padding: 7px 10px;
  border: 1px solid var(--outline); border-radius: 8px;
  background: var(--surface); color: var(--on-surface);
  font-size: 14px; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.config-label:focus {
  outline: none; border-color: var(--red);
  box-shadow: 0 0 0 3px var(--red-soft);
}

/* Identifiant affiché en lecture seule */
.config-id {
  font-size: 11px; color: var(--on-surface-var);
  font-family: "Roboto Mono", ui-monospace, monospace;
  min-width: 72px; flex-shrink: 0; text-align: right;
}

/* Bouton Ajouter une IA */
.config-add-row {
  margin-top: 12px; width: 100%; justify-content: center;
  border-radius: 10px; border-style: dashed;
}

/* ======================= BANNIÈRE D'ALERTE (email non vérifié, etc.) ======================= */
#persist-banner, #verify-banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  max-width: 1180px; margin: 16px auto 0; padding: 14px 20px;
  background: var(--red-soft); border: 1px solid var(--red);
  border-radius: 14px; color: var(--on-surface);
}
/* L'attribut [hidden] masque l'élément ; sans lui il s'affiche en flex. */
#persist-banner[hidden], #verify-banner[hidden] { display: none; }
.persist-banner-icon { color: var(--red); font-size: 22px; flex-shrink: 0; }
.persist-banner-msg { flex: 1; font-size: 14px; min-width: 200px; }
@media (max-width: 640px) {
  #persist-banner, #verify-banner { margin: 12px 16px 0; border-radius: 12px; }
}

/* ======================= ÉCRAN D'AUTHENTIFICATION ======================= */
#auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--bg);
}
#auth-screen[hidden] { display: none; }
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface);
  border: 1px solid var(--outline); border-radius: 18px;
  padding: 32px 28px; box-shadow: var(--shadow-2); text-align: center;
}
.auth-card h1 { margin: 12px 0 4px; font-size: 22px; }
.auth-card .sub { color: var(--on-surface-var); font-size: 14px; margin-bottom: 20px; }
.auth-card .brand-mark { margin: 0 auto 8px; }
.auth-tabs { display: flex; gap: 4px; background: var(--surface-2); border-radius: 10px; padding: 4px; margin-bottom: 20px; }
.auth-tab {
  flex: 1; border: none; background: transparent; padding: 8px 0; border-radius: 8px;
  font-size: 13px; font-weight: 600; color: var(--on-surface-var); cursor: pointer;
}
.auth-tab.active { background: var(--surface); color: var(--on-surface); box-shadow: var(--shadow-1); }
.auth-form { text-align: left; }
.auth-form[hidden] { display: none; }
.auth-form .field input[type="email"], .auth-form .field input[type="password"], .auth-form .field input[type="text"] {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--outline);
  background: var(--surface); color: var(--on-surface); font-size: 14px;
}
.auth-form .field input:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.auth-submit { width: 100%; justify-content: center; margin-top: 4px; }
.auth-error, .auth-info {
  font-size: 13px; padding: 10px 12px; border-radius: 10px; margin-bottom: 16px; text-align: left;
}
.auth-error { background: var(--red-soft); color: var(--red-strong); border: 1px solid var(--red); }
.auth-info { background: var(--surface-2); color: var(--on-surface); border: 1px solid var(--outline); }
.auth-error[hidden], .auth-info[hidden] { display: none; }
.auth-remember {
  display: flex; align-items: center; gap: 8px; margin: -6px 0 14px;
  font-size: 13px; color: var(--on-surface-var); cursor: pointer;
}
.auth-remember input { accent-color: var(--red); width: 16px; height: 16px; }

/* ======================= RESPONSIVE ======================= */
@media (max-width: 640px) {
  .appbar { padding: 10px 16px; }
  .brand .sub { display: none; }
  .toolbar, .filters, .statusbar, .grid { padding-left: 16px; padding-right: 16px; }
  .grid { grid-template-columns: 1fr; }
  .fab { right: 16px; bottom: 16px; padding: 14px 18px; }
  .appbar h1 { font-size: 18px; }
  /* sur mobile, le bouton « Nouveau prompt » du header laisse place au FAB */
  #new-btn .label { display: none; }
}
