/* package2.css
 * Package 2: author's note, lorebook drawer, Character Studio V2, PNG cards,
 * visual tag builder, vision presets and full backup/restore.
 * Colours come from the existing theme tokens so every theme keeps working.
 */

/* ================= AUTHOR'S NOTE ================= */
.author-note-bar { margin-bottom: 0.5rem; }

.author-note-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: 0.6rem;
  border: 1px dashed rgba(255, 255, 255, 0.16);
  background: transparent;
  color: #94a3b8;
  font-size: 0.68rem;
  font-weight: 600;
}

.author-note-toggle:hover { border-color: rgba(129, 140, 248, 0.5); color: #c7d2fe; }
.author-note-toggle[aria-expanded="true"] { border-style: solid; background: rgba(99, 102, 241, 0.14); color: #c7d2fe; }

.author-note-badge {
  display: inline-grid;
  place-items: center;
  min-width: 1rem;
  height: 1rem;
  padding: 0 0.25rem;
  border-radius: 9999px;
  background: rgba(129, 140, 248, 0.9);
  color: #0b0d16;
  font-size: 0.6rem;
  font-weight: 800;
}

.author-note-body { margin-top: 0.4rem; }
.author-note-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.35rem;
}
.author-note-oneshot {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.65rem;
  color: #94a3b8;
  cursor: pointer;
}
.author-note-clear {
  display: grid;
  place-items: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: #94a3b8;
  font-size: 0.7rem;
}
.author-note-clear:hover { background: rgba(244, 63, 94, 0.2); color: #fda4af; }

/* ================= LOREBOOK DRAWER ================= */
.lore-drawer {
  position: fixed;
  inset-block: 0;
  inset-inline-end: 0;
  z-index: 8000;
  width: min(23rem, 92vw);
  padding: 1rem;
  overflow-y: auto;
  border-inline-start: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(11, 13, 22, 0.98);
  box-shadow: -24px 0 60px -20px rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(20px);
}

body[data-theme="light"] .lore-drawer {
  background: rgba(255, 255, 255, 0.98);
  border-inline-start-color: rgba(15, 23, 42, 0.14);
}

.lore-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.lore-drawer-title { margin: 0; font-size: 0.9rem; font-weight: 700; color: #fff; }

.lore-drawer-close {
  display: grid;
  place-items: center;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: #cbd5e1;
}

.lore-add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  width: 100%;
  margin: 0.6rem 0;
  padding: 0.5rem;
  border-radius: 0.7rem;
  border: 1px dashed rgba(129, 140, 248, 0.4);
  background: rgba(99, 102, 241, 0.1);
  color: #c7d2fe;
  font-size: 0.72rem;
  font-weight: 600;
}

.lore-add-btn:hover { background: rgba(99, 102, 241, 0.2); }
.lore-entry-list { display: flex; flex-direction: column; gap: 0.6rem; }

.lore-entry {
  padding: 0.6rem;
  border-radius: 0.8rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.035);
}
.lore-entry.is-disabled { opacity: 0.55; }

.lore-entry-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin-bottom: 0.35rem;
}

.lore-entry-index {
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #a5b4fc;
  text-transform: uppercase;
}

.lore-entry-del {
  display: grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 0.45rem;
  border: 1px solid rgba(244, 63, 94, 0.3);
  background: rgba(244, 63, 94, 0.12);
  color: #fda4af;
  font-size: 0.7rem;
}

.lore-field {
  width: 100%;
  margin-bottom: 0.3rem;
  padding: 0.35rem 0.55rem;
  border-radius: 0.55rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(8, 10, 18, 0.7);
  color: #e2e8f0;
  font-size: 0.7rem;
}
.lore-field:focus { outline: none; border-color: rgba(129, 140, 248, 0.7); }
.lore-field-area { min-height: 3.5rem; resize: vertical; }
.lore-empty { margin-top: 0.6rem; font-size: 0.7rem; color: #64748b; text-align: center; }

/* ================= CHARACTER STUDIO V2 ================= */
.autofill-panel {
  margin-bottom: 1.1rem;
  padding: 0.8rem;
  border-radius: 1rem;
  border: 1px solid rgba(129, 140, 248, 0.28);
  background: rgba(99, 102, 241, 0.07);
}

.autofill-row { display: flex; gap: 0.5rem; }

.autofill-btn {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.85rem;
  border-radius: 0.8rem;
  border: 1px solid rgba(129, 140, 248, 0.5);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.85), rgba(236, 72, 153, 0.7));
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
}
.autofill-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.autofill-status { margin: 0.45rem 0 0; font-size: 0.68rem; color: #94a3b8; min-height: 1em; }

.completeness-meter { margin-bottom: 1.1rem; }
.completeness-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.3rem;
  font-size: 0.68rem;
  font-weight: 600;
  color: #94a3b8;
}
.completeness-value { color: #a5b4fc; font-variant-numeric: tabular-nums; }

.completeness-bar {
  width: 100%;
  height: 0.4rem;
  appearance: none;
  border: none;
  border-radius: 9999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
}
.completeness-bar::-webkit-progress-bar { background: rgba(255, 255, 255, 0.08); border-radius: 9999px; }
.completeness-bar::-webkit-progress-value {
  border-radius: 9999px;
  background: linear-gradient(90deg, #6366f1, #ec4899);
  transition: width 0.3s ease;
}
.completeness-bar::-moz-progress-bar { border-radius: 9999px; background: linear-gradient(90deg, #6366f1, #ec4899); }

/* ================= VISUAL TAG BUILDER ================= */
.tag-chip { position: relative; }


.tag-weight {
  display: inline-flex;
  align-items: center;
  gap: 0.1rem;
  margin-inline-start: 0.25rem;
  font-size: 0.6rem;
  opacity: 0.6;
}
.tag-weight button {
  display: grid;
  place-items: center;
  width: 0.95rem;
  height: 0.95rem;
  padding: 0;
  border-radius: 0.25rem;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.25);
  color: #cbd5e1;
  font-size: 0.55rem;
  line-height: 1;
}
.tag-weight button:hover { background: rgba(129, 140, 248, 0.4); color: #fff; }

/* ================= VISION PRESETS ================= */
.vision-preset-row { display: flex; flex-wrap: wrap; gap: 0.35rem; }

.vision-preset {
  padding: 0.35rem 0.65rem;
  border-radius: 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  color: #cbd5e1;
  font-size: 0.68rem;
  font-weight: 600;
}
.vision-preset:hover { background: rgba(255, 255, 255, 0.14); }
.vision-preset[aria-pressed="true"] {
  border-color: rgba(244, 114, 182, 0.6);
  background: rgba(236, 72, 153, 0.25);
  color: #fff;
}

/* ================= BACKUP & RESTORE ================= */
.backup-block {
  margin-top: 0.75rem;
  padding: 0.75rem;
  border-radius: 0.9rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.03);
}
.backup-title { margin: 0 0 0.6rem; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: #94a3b8; }

.backup-optin {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.6rem;
  font-size: 0.68rem;
  color: #fca5a5;
  cursor: pointer;
}

.backup-warning {
  margin: 0.4rem 0 0;
  font-size: 0.63rem;
  line-height: 1.5;
  color: #64748b;
}

/* RTL: mirror the drawer shadow and progress direction. */
[dir="rtl"] .lore-drawer { box-shadow: 24px 0 60px -20px rgba(0, 0, 0, 0.85); }
[dir="rtl"] .completeness-bar::-webkit-progress-value { background: linear-gradient(270deg, #6366f1, #ec4899); }

@media (max-width: 640px) {
  .autofill-row { flex-direction: column; }
  .autofill-btn { justify-content: center; }
}

/* ================= UX ENHANCEMENTS: LAST 3 SECTIONS ================= */

/* --- Character Studio: starter templates + token counter --- */
.starter-templates { margin-top: 0.75rem; }
.starter-templates-label {
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--text-2, #9aa5b8); margin-bottom: 0.4rem;
}
.starter-templates-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.starter-template-btn {
  border: 1px solid var(--hairline, rgba(255,255,255,0.12));
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-1, #e8ecf4);
  border-radius: 0.75rem; padding: 0.45rem 0.8rem;
  font-size: 0.78rem; font-weight: 500; cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.starter-template-btn:hover { background: rgba(99, 102, 241, 0.18); border-color: rgba(129, 140, 248, 0.5); }
.starter-template-btn:focus-visible { outline: 2px solid var(--accent, #6366f1); outline-offset: 2px; }
.token-count-label { font-size: 0.72rem; color: var(--text-2, #9aa5b8); }
.token-count-value { font-size: 0.72rem; font-weight: 700; color: var(--accent, #a3a6ff); }

/* --- Image Prompt: guided chips + engine buttons + prompt actions --- */
.guided-chips {
  margin-top: 0.85rem; display: flex; flex-direction: column; gap: 0.6rem;
  border: 1px solid var(--hairline, rgba(255,255,255,0.1));
  background: rgba(255, 255, 255, 0.03);
  border-radius: 1rem; padding: 0.75rem;
}
.guided-chip-group { display: flex; flex-direction: column; gap: 0.35rem; }
.guided-chip-label {
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-2, #9aa5b8);
}
.guided-chip-row { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.guided-chip {
  border: 1px solid rgba(244, 114, 182, 0.28);
  background: rgba(244, 114, 182, 0.1);
  color: #fbcfe8; border-radius: 999px;
  padding: 0.32rem 0.72rem; font-size: 0.72rem; font-weight: 500;
  cursor: pointer; transition: background-color 0.15s ease, border-color 0.15s ease;
}
.guided-chip:hover { background: rgba(244, 114, 182, 0.22); border-color: rgba(244, 114, 182, 0.55); }
.guided-chip:focus-visible { outline: 2px solid #f472b6; outline-offset: 2px; }

.engine-row { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.35rem; }
.engine-btn {
  border: 1px solid var(--hairline, rgba(255,255,255,0.12));
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-1, #e8ecf4); border-radius: 0.65rem;
  padding: 0.4rem 0.85rem; font-size: 0.75rem; font-weight: 600;
  cursor: pointer; transition: background-color 0.15s ease, border-color 0.15s ease;
}
.engine-btn[aria-pressed="true"] {
  background: rgba(99, 102, 241, 0.25);
  border-color: rgba(129, 140, 248, 0.65);
  color: #ffffff;
}
.engine-btn:hover { background: rgba(99, 102, 241, 0.16); }

.img-prompt-actions {
  margin-top: 0.55rem; display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem;
}

/* --- Vision: quick actions --- */
.vision-quick-actions {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.45rem;
  margin-top: 0.5rem;
}
.vision-quick-btn {
  border: 1px solid rgba(244, 114, 182, 0.28);
  background: rgba(244, 114, 182, 0.1);
  color: #fbcfe8; border-radius: 0.7rem;
  padding: 0.5rem 0.6rem; font-size: 0.72rem; font-weight: 600;
  cursor: pointer; text-align: center;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.vision-quick-btn:hover { background: rgba(244, 114, 182, 0.22); border-color: rgba(244, 114, 182, 0.55); }
.vision-quick-btn:focus-visible { outline: 2px solid #f472b6; outline-offset: 2px; }

@media (max-width: 480px) {
  .vision-quick-actions { grid-template-columns: 1fr; }
  .img-prompt-actions { flex-direction: column; align-items: stretch; }
}

/* --- Phase A: Arabic preview + Character Consistency Anchor --- */
.img-arabic-preview {
  margin-top: 0.6rem;
  padding: 0.6rem 0.8rem;
  border-radius: 0.75rem;
  border: 1px solid rgba(56, 189, 248, 0.25);
  background: rgba(56, 189, 248, 0.08);
  color: #bae6fd;
  font-size: 0.8rem;
  line-height: 1.6;
  text-align: right;
}
.img-arabic-preview[hidden] { display: none; }

.consistency-anchor {
  margin-top: 1rem;
  border: 1px solid rgba(217, 119, 87, 0.28);
  background: rgba(217, 119, 87, 0.06);
  border-radius: 1rem;
  padding: 0.85rem;
}
.consistency-head {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.6rem;
}
.consistency-title { font-size: 0.85rem; font-weight: 700; color: #fcd9c9; }
.consistency-lock-btn {
  border: 1px solid rgba(217, 119, 87, 0.5);
  background: rgba(217, 119, 87, 0.16);
  color: #ffd9c9;
  border-radius: 0.6rem; padding: 0.4rem 0.8rem;
  font-size: 0.72rem; font-weight: 600; cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.consistency-lock-btn[aria-pressed="true"] {
  background: rgba(217, 119, 87, 0.35);
  border-color: rgba(217, 119, 87, 0.9);
  color: #ffffff;
}
.consistency-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem;
}
.consistency-input { font-size: 0.78rem !important; padding: 0.5rem 0.75rem !important; }
.consistency-scenes-label {
  margin-top: 0.7rem; margin-bottom: 0.35rem;
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.05em;
  text-transform: uppercase; color: #d9b3a0;
}
.consistency-scenes { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.scene-chip {
  border: 1px solid rgba(217, 119, 87, 0.35);
  background: rgba(217, 119, 87, 0.1);
  color: #fcd9c9; border-radius: 999px;
  padding: 0.32rem 0.7rem; font-size: 0.72rem; font-weight: 500; cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.scene-chip:hover { background: rgba(217, 119, 87, 0.22); border-color: rgba(217, 119, 87, 0.65); }
.scene-chip:focus-visible { outline: 2px solid #d97757; outline-offset: 2px; }
.consistency-status { margin-top: 0.5rem; font-size: 0.72rem; color: #cbb6a0; }

@media (max-width: 480px) {
  .consistency-grid { grid-template-columns: 1fr; }
  .consistency-head { flex-direction: column; align-items: stretch; }
}
