/* =============================================================================
   AIToolsay — §ATTACH  "Add Files and Photos" on the prompt composer
   -----------------------------------------------------------------------------
   Button + attachment tray + drop overlay. Driven by assets/js/ai-attachments.js,
   loaded by ai-tool-shell and ai-writers-shell right after ai-prompt-box.css.

   Scoped to `.pg-root .pg-prompt-body` (0,2,0+) so it works in BOTH shells —
   the writers shell's card has no `.pg-prompt-card`, so the --pb-* tokens from
   ai-prompt-box.css are not guaranteed; this file carries its own --att-* set.
   ========================================================================== */

.pg-root .pg-prompt-body {
  --att-accent: #60A5FA;
  --att-ink: #1D5FD1;                 /* #60A5FA fails AA as text on white */
  --att-bg: rgba(96, 165, 250, .10);
  --att-bg-hover: rgba(96, 165, 250, .18);
  --att-line: rgba(96, 165, 250, .42);
  --att-glow: 96, 165, 250;
  --att-chip: #f6f8fc;
  --att-chip-line: #e3e8ef;
  --att-text: #16202c;
  --att-text-2: #5b6779;
  --att-err: #C7362C;
  --att-err-bg: rgba(199, 54, 44, .08);
  --att-surface: #fff;
  position: relative;
}
body.theme-dark .pg-root .pg-prompt-body {
  --att-ink: #60A5FA;
  --att-bg: rgba(96, 165, 250, .12);
  --att-bg-hover: rgba(96, 165, 250, .22);
  --att-line: rgba(96, 165, 250, .38);
  --att-chip: var(--dk-surface-3, #1D1D22);
  --att-chip-line: var(--dk-line, rgba(255, 255, 255, .10));
  --att-text: var(--dk-text, #F4F5F7);
  --att-text-2: var(--dk-text-3, #9AA0AB);
  --att-err: #F58B84;
  --att-err-bg: rgba(224, 90, 80, .14);
  --att-surface: var(--dk-surface-2, #17171B);
}

/* ── FOOTER: counter left, actions right ──────────────────────────────────── */
.pg-root .pg-prompt-body .pg-prompt-footer { flex-wrap: wrap; gap: 10px 12px; }
.pg-root .pg-prompt-body .pg-prompt-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-inline-start: auto;          /* stays right even after wrapping */
  min-inline-size: 0;
}
.pg-root .pg-prompt-body .pg-att-input {
  position: absolute !important;
  inline-size: 1px; block-size: 1px;
  opacity: 0; pointer-events: none;
  clip-path: inset(50%);
}

/* ── THE BUTTON — same box as "Try Random Prompt" (7px 14px, 12.5px/1.4,
   1px border, pill) so the two read as a pair. ────────────────────────────── */
.pg-root .pg-prompt-body .pg-attach-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border: 1px solid var(--att-line);
  border-radius: 999px;
  background: var(--att-bg);
  -webkit-backdrop-filter: blur(8px) saturate(140%);
  backdrop-filter: blur(8px) saturate(140%);
  color: var(--att-ink);
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.4;
  white-space: nowrap;
  cursor: pointer;
  transition: background .18s ease, border-color .18s ease, color .18s ease,
              transform .18s ease, box-shadow .18s ease;
}
.pg-root .pg-prompt-body .pg-attach-btn i {
  font-size: 12px;
  color: var(--att-accent);
  transition: transform .3s cubic-bezier(.34, 1.56, .64, 1);
}
.pg-root .pg-prompt-body .pg-attach-btn .pg-attach-n {
  display: none;
  min-inline-size: 18px;
  padding: 0 5px;
  border-radius: 99px;
  background: var(--att-accent);
  color: #0B1B33;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}
.pg-root .pg-prompt-body .pg-attach-btn.has-files .pg-attach-n { display: inline-block; }
@media (hover: hover) and (pointer: fine) {
  .pg-root .pg-prompt-body .pg-attach-btn:hover {
    background: var(--att-bg-hover);
    border-color: var(--att-accent);
    transform: translateY(-1px);
    box-shadow: 0 8px 18px -10px rgba(var(--att-glow), .7);
  }
  .pg-root .pg-prompt-body .pg-attach-btn:hover i { transform: rotate(-20deg) scale(1.08); }
}
.pg-root .pg-prompt-body .pg-attach-btn:active { transform: translateY(0) scale(.985); }
.pg-root .pg-prompt-body .pg-attach-btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
/* Site-wide `button:focus-visible` reset sits at (0,3,2) — match its prefix. */
body:not(.admin-shell) .pg-root .pg-prompt-body .pg-attach-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--att-surface), 0 0 0 6px rgba(var(--att-glow), .85);
}

/* ── TRAY ─────────────────────────────────────────────────────────────────── */
.pg-root .pg-prompt-body .pg-att-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}
.pg-root .pg-prompt-body .pg-att-tray[hidden] { display: none; }

.pg-root .pg-prompt-body .pg-att-chip {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  inline-size: 228px;
  max-inline-size: 100%;
  padding: 6px 6px 6px 6px;
  border: 1px solid var(--att-chip-line);
  border-radius: 14px;
  background: var(--att-chip);
  overflow: hidden;
  animation: pgAttIn .22s ease both;
}
@keyframes pgAttIn { from { opacity: 0; transform: translateY(4px) scale(.98); } to { opacity: 1; transform: none; } }

.pg-root .pg-prompt-body .pg-att-thumb {
  position: relative;
  flex: 0 0 40px;
  inline-size: 40px;
  block-size: 40px;
  border-radius: 10px;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: rgba(var(--att-glow), .14);
  color: var(--att-ink);
  font-size: 18px;
}
.pg-root .pg-prompt-body .pg-att-thumb img {
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;
  display: block;
}
.pg-root .pg-prompt-body .pg-att-chip[data-type="pdf"]  .pg-att-thumb { background: rgba(229, 72, 77, .14);  color: #E5484D; }
.pg-root .pg-prompt-body .pg-att-chip[data-type="word"] .pg-att-thumb { background: rgba(54, 128, 237, .14); color: #3680ED; }
.pg-root .pg-prompt-body .pg-att-chip[data-type="sheet"] .pg-att-thumb { background: rgba(34, 160, 107, .15); color: #22A06B; }
.pg-root .pg-prompt-body .pg-att-chip[data-type="text"] .pg-att-thumb { background: rgba(130, 140, 160, .16); color: var(--att-text-2); }

.pg-root .pg-prompt-body .pg-att-meta { flex: 1 1 auto; min-inline-size: 0; line-height: 1.3; }
.pg-root .pg-prompt-body .pg-att-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--att-text);
}
.pg-root .pg-prompt-body .pg-att-sub {
  display: block;
  font-size: 11px;
  color: var(--att-text-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pg-root .pg-prompt-body .pg-att-x {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  inline-size: 26px;
  block-size: 26px;
  margin-inline-start: auto;
  padding: 0;
  border: 0;
  border-radius: 99px;
  background: transparent;
  color: var(--att-text-2);
  font-size: 12px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.pg-root .pg-prompt-body .pg-att-x:hover { background: var(--att-err-bg); color: var(--att-err); }
body:not(.admin-shell) .pg-root .pg-prompt-body .pg-att-x:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(var(--att-glow), .9);
}

/* Upload progress: a bar on the chip's bottom edge + dimmed thumb. */
.pg-root .pg-prompt-body .pg-att-bar {
  position: absolute;
  inset-inline: 0;
  inset-block-end: 0;
  block-size: 3px;
  background: rgba(var(--att-glow), .18);
}
.pg-root .pg-prompt-body .pg-att-bar > span {
  display: block;
  block-size: 100%;
  inline-size: 0;
  background: linear-gradient(90deg, #60A5FA, #3680ED);
  transition: inline-size .15s linear;
}
.pg-root .pg-prompt-body .pg-att-chip.is-done .pg-att-bar { opacity: 0; transition: opacity .4s ease .2s; }
.pg-root .pg-prompt-body .pg-att-chip.is-uploading .pg-att-thumb::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .28);
}

/* ── VALIDATION MESSAGES ──────────────────────────────────────────────────── */
.pg-root .pg-prompt-body .pg-att-msg {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 10px 0 0;
  padding: 8px 10px 8px 12px;
  border: 1px solid rgba(199, 54, 44, .28);
  border-radius: 12px;
  background: var(--att-err-bg);
  color: var(--att-err);
  font-size: 12.5px;
  line-height: 1.45;
}
.pg-root .pg-prompt-body .pg-att-msg[hidden] { display: none; }
.pg-root .pg-prompt-body .pg-att-msg ul { margin: 0; padding: 0; list-style: none; flex: 1 1 auto; }
.pg-root .pg-prompt-body .pg-att-msg i.fa-exclamation-circle { margin-top: 3px; }
.pg-root .pg-prompt-body .pg-att-msg button {
  flex: 0 0 auto;
  border: 0; background: none; color: inherit; cursor: pointer;
  padding: 2px 4px; font-size: 12px; opacity: .8;
}

/* ── DRAG & DROP ──────────────────────────────────────────────────────────── */
.pg-root .pg-att-drop-host { position: relative; }
.pg-root .pg-att-drop-host.is-dragging::after {
  content: attr(data-drop-label);
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  border: 2px dashed #60A5FA;
  border-radius: inherit;
  background: rgba(96, 165, 250, .12);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  color: #1D5FD1;
  font-size: 14px;
  font-weight: 700;
  pointer-events: none;
}
body.theme-dark .pg-root .pg-att-drop-host.is-dragging::after { color: #93C5FD; background: rgba(96, 165, 250, .14); }

/* ── RESPONSIVE ───────────────────────────────────────────────────────────── */
@media (max-width: 575.98px) {
  .pg-root .pg-prompt-body .pg-attach-btn { padding: 8px 13px; min-block-size: 36px; }
  .pg-root .pg-prompt-body .pg-att-chip { inline-size: calc(50% - 4px); min-inline-size: 150px; flex: 1 1 calc(50% - 4px); }
}
@media (max-width: 479.98px) {
  /* "Add Files" — the full name stays in aria-label. */
  .pg-root .pg-prompt-body .pg-attach-lbl-x { display: none; }
  /* Counter on its own line, both buttons sharing the next one. */
  .pg-root .pg-prompt-body .pg-prompt-actions { flex: 1 1 100%; flex-wrap: nowrap; gap: 6px; }
  .pg-root .pg-prompt-body .pg-attach-btn,
  .pg-root .pg-prompt-card .pg-random-btn {
    flex: 1 1 auto;
    justify-content: center;
    padding-inline: 10px;
    gap: 6px;
    font-size: 12px;
  }
}
@media (max-width: 329.98px) {
  .pg-root .pg-prompt-body .pg-prompt-actions { flex-wrap: wrap; }
}
@media (max-width: 359.98px) {
  .pg-root .pg-prompt-body .pg-att-chip { flex-basis: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .pg-root .pg-prompt-body .pg-attach-btn,
  .pg-root .pg-prompt-body .pg-attach-btn i,
  .pg-root .pg-prompt-body .pg-att-chip { transition: none; animation: none; }
  .pg-root .pg-prompt-body .pg-attach-btn:hover { transform: none; }
}

/* =============================================================================
   §ATTACH3 — attached files in the visitor's own Activity History
   (partials/ai-history-attachments). Uses the history panel's own --ah-*
   tokens (ai-activity-history.css), which already remap for dark mode.
   ========================================================================== */
/* Header pill: "📎 3 files", same family as the tool/model pills. */
.pg-root .pg-hist-shell .pg-hi-pill.att {
  background: rgba(96, 165, 250, .12);
  border-color: rgba(96, 165, 250, .38);
  color: var(--ah-3);
  font-size: 11px;
  letter-spacing: 0;
  text-transform: none;
}
.pg-root .pg-hist-shell .pg-hi-pill.att i { color: #60A5FA; }

/* Body strip: one chip per file, above the generated text. */
.pg-root :is(.pg-hist-shell, .pg-out-card) .pg-hist-att {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
}
.pg-root :is(.pg-hist-shell, .pg-out-card) .pg-hist-att > li { min-inline-size: 0; max-inline-size: 100%; }
.pg-root :is(.pg-hist-shell, .pg-out-card) .pg-hist-att-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  inline-size: 230px;
  max-inline-size: 100%;
  padding: 6px 10px 6px 6px;
  border: 1px solid var(--ah-line);
  border-radius: 14px;
  background: var(--ah-surface-3);
  color: var(--ah-ink);
  text-decoration: none;
  transition: border-color .18s ease, transform .18s ease, box-shadow .18s ease;
}
.pg-root .pg-hist-shell a.pg-hist-att-chip:hover {
  border-color: #60A5FA;
  color: var(--ah-ink);
  transform: translateY(-1px);
  box-shadow: 0 8px 18px -12px rgba(96, 165, 250, .8);
}
body:not(.admin-shell) .pg-root :is(.pg-hist-shell, .pg-out-card) a.pg-hist-att-chip:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--ah-surface), 0 0 0 4px rgba(96, 165, 250, .9);
}
.pg-root :is(.pg-hist-shell, .pg-out-card) .pg-hist-att-chip.is-missing { opacity: .6; }
.pg-root :is(.pg-hist-shell, .pg-out-card) .pg-hist-att-thumb {
  flex: 0 0 40px;
  display: grid;
  place-items: center;
  inline-size: 40px;
  block-size: 40px;
  border-radius: 10px;
  overflow: hidden;
  background: rgba(96, 165, 250, .14);
  color: #3680ED;
  font-size: 17px;
}
.pg-root :is(.pg-hist-shell, .pg-out-card) .pg-hist-att-thumb img { inline-size: 100%; block-size: 100%; object-fit: cover; display: block; }
.pg-root :is(.pg-hist-shell, .pg-out-card) .pg-hist-att-chip[data-type="pdf"]   .pg-hist-att-thumb { background: rgba(229, 72, 77, .14);  color: #E5484D; }
.pg-root :is(.pg-hist-shell, .pg-out-card) .pg-hist-att-chip[data-type="word"]  .pg-hist-att-thumb { background: rgba(54, 128, 237, .14); color: #3680ED; }
.pg-root :is(.pg-hist-shell, .pg-out-card) .pg-hist-att-chip[data-type="sheet"] .pg-hist-att-thumb { background: rgba(34, 160, 107, .15); color: #22A06B; }
.pg-root :is(.pg-hist-shell, .pg-out-card) .pg-hist-att-chip[data-type="text"]  .pg-hist-att-thumb { background: rgba(130, 140, 160, .16); color: var(--ah-ink-2); }
.pg-root :is(.pg-hist-shell, .pg-out-card) .pg-hist-att-meta { min-inline-size: 0; display: flex; flex-direction: column; line-height: 1.3; }
.pg-root :is(.pg-hist-shell, .pg-out-card) .pg-hist-att-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
  font-weight: 600;
}
.pg-root :is(.pg-hist-shell, .pg-out-card) .pg-hist-att-sub {
  font-size: 11px;
  color: var(--ah-ink-2);
  font-variant-numeric: tabular-nums;
}
@media (max-width: 575.98px) {
  .pg-root :is(.pg-hist-shell, .pg-out-card) .pg-hist-att > li { flex: 1 1 calc(50% - 4px); }
  .pg-root :is(.pg-hist-shell, .pg-out-card) .pg-hist-att-chip { inline-size: 100%; }
}
@media (max-width: 379.98px) {
  .pg-root :is(.pg-hist-shell, .pg-out-card) .pg-hist-att > li { flex-basis: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .pg-root :is(.pg-hist-shell, .pg-out-card) .pg-hist-att-chip { transition: none; }
  .pg-root .pg-hist-shell a.pg-hist-att-chip:hover { transform: none; }
}

/* §ATTACH4 — the same chips on the OPEN RESULT card. The card has no --ah-*
   tokens (those live on .pg-hist-shell), so the list carries its own copy,
   light and dark, and sits between the header pills and the divider. */
.pg-root .pg-out-card .pg-out-att {
  --ah-3: #2060C0;
  --ah-surface: #fff;
  --ah-surface-3: #f6f8fc;
  --ah-line: #e3e8ef;
  --ah-ink: #16202c;
  --ah-ink-2: #5b6779;
  margin: 14px 0 0;
}
.pg-root .pg-out-card .pg-out-att[hidden] { display: none; }
body.theme-dark .pg-root .pg-out-card .pg-out-att {
  --ah-3: #8CBEFA;
  --ah-surface: var(--dk-surface-2, #17171B);
  --ah-surface-3: var(--dk-surface-3, #1D1D22);
  --ah-line: var(--dk-line, rgba(255, 255, 255, .10));
  --ah-ink: var(--dk-text, #F4F5F7);
  --ah-ink-2: var(--dk-text-3, #9AA0AB);
}

/* =============================================================================
   §ATTACH6 — popup image viewer (assets/js/ai-attachments.js lbOpen()).
   Appended to <body>, so it is NOT under .pg-root. Always a dark backdrop:
   it shows photos, and a light backdrop fights them in both themes.
   ========================================================================== */
html.ait-lb-lock, html.ait-lb-lock body { overflow: hidden; }

.ait-lb {
  position: fixed;
  inset: 0;
  z-index: 2147483000;               /* above the header, drawers and widgets */
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 64px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: rgba(8, 10, 14, .88);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: #F4F5F7;
  opacity: 0;
  transition: opacity .18s ease;
}
.ait-lb[hidden] { display: none; }
.ait-lb.is-open { opacity: 1; }

.ait-lb-top {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(rgba(0, 0, 0, .45), transparent);
}
.ait-lb-cap { min-width: 0; display: flex; flex-direction: column; line-height: 1.35; }
.ait-lb-name { font-size: 14px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ait-lb-sub { font-size: 12px; color: #A1A8B3; font-variant-numeric: tabular-nums; }
.ait-lb-acts { display: flex; gap: 8px; flex: 0 0 auto; }

.ait-lb-btn,
.ait-lb-nav {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 12px;
  background: rgba(255, 255, 255, .08);
  color: #F4F5F7;
  font-size: 15px;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.ait-lb-btn:hover, .ait-lb-nav:hover {
  background: rgba(96, 165, 250, .22);
  border-color: #60A5FA;
  color: #fff;
}
.ait-lb-btn:focus-visible, .ait-lb-nav:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, .9);
}

.ait-lb-nav { align-self: center; justify-self: center; width: 46px; height: 46px; border-radius: 50%; }
.ait-lb-nav.prev { grid-column: 1; grid-row: 2; }
.ait-lb-nav.next { grid-column: 3; grid-row: 2; }
.ait-lb-nav[hidden] { visibility: hidden; display: grid; }

.ait-lb-stage {
  grid-column: 2;
  grid-row: 2;
  margin: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 8px;
}
.ait-lb-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .8);
  background: #fff;                  /* transparent PNG logos stay readable */
  transform: scale(.98);
  transition: transform .2s ease;
}
.ait-lb.is-open .ait-lb-img { transform: none; }

.ait-lb-count {
  grid-column: 1 / -1;
  grid-row: 3;
  padding: 10px 0 16px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: #A1A8B3;
  font-variant-numeric: tabular-nums;
}

/* Tray thumbnails are previewable too. */
.pg-root .pg-prompt-body .pg-att-chip[data-type="image"] .pg-att-thumb { cursor: zoom-in; }
.pg-root :is(.pg-hist-shell, .pg-out-card) a.pg-hist-att-chip[data-type="image"] { cursor: zoom-in; }

@media (max-width: 575.98px) {
  .ait-lb { grid-template-columns: 0 minmax(0, 1fr) 0; }
  /* Arrows float over the picture's edges on phones. */
  .ait-lb-nav { position: fixed; top: 50%; transform: translateY(-50%); z-index: 1; width: 40px; height: 40px; background: rgba(0, 0, 0, .5); }
  .ait-lb-nav.prev { left: 8px; }
  .ait-lb-nav.next { right: 8px; }
  .ait-lb-stage { padding: 4px; }
}
@media (prefers-reduced-motion: reduce) {
  .ait-lb, .ait-lb-img { transition: none; }
}
