/* stamps.cl — UX 2026 layer (added 2026-09-19). Loaded LAST so it refines the existing skins
   without editing them. Every colour comes from the theme tokens (--accent, --bg-2, --text…),
   so all skins (Patrimonio, Oscuro, Clásico, Moderno, Infantil, Personalizado) and the Senior /
   high-contrast modes keep working. Motion only animates transform/opacity and is switched off
   under prefers-reduced-motion. */

/* ============================== Ficha (detail modal) ============================== */
/* The ficha fits the viewport: fixed-height card, the image in a fixed frame, and every block of
   information in tabs whose pane scrolls on its own. No page scroll, ever. */
#detailModal .modal-dialog { max-width: 1180px; }
#detailModal .detail-content { height: min(90vh, 820px); max-height: none; }
#detailModal .detail-body {
  display: grid; grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.3fr);
  grid-template-rows: minmax(0, 1fr); gap: 22px; padding: 22px 26px; overflow: hidden;
}

/* Media column: frame + actions. The frame's size is set by CSS, and the photo is absolutely
   positioned and contained inside it, so NO photo can overflow (fixes Scott 8 & co. on phones). */
#detailModal .detail-gallery { display: flex; flex-direction: column; gap: 12px; min-height: 0; align-self: stretch; position: relative; }
#detailModal .detail-gallery .main-img {
  position: relative; flex: 1 1 auto; min-height: 220px; height: auto; padding: 0; display: block; overflow: hidden;
}
#detailModal .detail-gallery .main-img img,
#detailModal .detail-gallery .main-img.gal-locked img {
  position: absolute; inset: 16px; width: calc(100% - 32px); height: calc(100% - 32px);
  max-width: none; max-height: none; object-fit: contain; margin: 0;
}
#detailModal .detail-gallery .main-img .noimg { position: absolute; inset: 0; display: grid; place-items: center; }
#detailModal .gal-zoom { top: auto; bottom: 10px; right: 10px; }

/* Action bar under the image: few, labelled, thumb-sized buttons. */
.dx-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.dx-act {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 44px; padding: 0 16px; border-radius: 999px; cursor: pointer;
  background: var(--card); color: var(--text); border: 1px solid var(--panel-border);
  font-size: 14px; font-weight: 700; transition: transform .14s ease, border-color .14s ease, background .14s ease;
}
.dx-act span { font-size: 13.5px; }
.dx-act:hover { border-color: var(--accent); transform: translateY(-1px); }
.dx-act.on { background: color-mix(in srgb, var(--accent) 22%, transparent); border-color: var(--accent); }
/* Theme colours only (text = --text on a tinted surface): readable in every skin (WCAG AA), unlike
   white text on the light Patrimonio accent. The accent shows in the border and the tint. */
.dx-listen { background: color-mix(in srgb, var(--accent) 24%, var(--bg-2)); color: var(--text); border: 2px solid var(--accent); }
.dx-listen:hover { background: color-mix(in srgb, var(--accent) 36%, var(--bg-2)); }
/* A soft pulse tells the visitor there IS an audio for this stamp. */
.dx-listen.has-audio { position: relative; }
.dx-listen.has-audio::after {
  content: ''; position: absolute; top: 6px; right: 8px; width: 8px; height: 8px; border-radius: 50%;
  background: #ffd166; box-shadow: 0 0 0 0 rgba(255, 209, 102, .7); animation: dxPing 1.8s infinite;
}
@keyframes dxPing { 70% { box-shadow: 0 0 0 7px rgba(255, 209, 102, 0); } 100% { box-shadow: 0 0 0 0 rgba(255, 209, 102, 0); } }

/* 🎺 menu */
.dx-menu {
  position: absolute; left: 0; right: 0; bottom: 58px; z-index: 7;
  display: flex; flex-direction: column; gap: 6px; padding: 8px; border-radius: 16px;
  background: var(--bg-2); border: 1px solid var(--panel-border); box-shadow: var(--shadow);
  max-height: min(46vh, 360px); overflow-y: auto;
}
.dx-menu[hidden] { display: none; }
.dx-mi {
  display: flex; align-items: flex-start; gap: 10px; text-align: left; width: 100%; min-height: 48px; flex: 0 0 auto;
  padding: 10px 12px; border-radius: 12px; cursor: pointer; background: transparent; color: var(--text);
  border: 1px solid transparent;
}
.dx-mi:hover, .dx-mi:focus-visible { background: var(--card); border-color: var(--panel-border); outline: none; }
.dx-mi-ico { font-size: 20px; line-height: 1.2; }
.dx-mi-txt { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.dx-mi-txt b { font-size: 14px; }
.dx-mi-txt small { font-size: 12px; color: var(--muted); line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.dx-mi-note { margin: 2px 10px 4px; font-size: 12px; color: var(--muted); }

/* Info column: header + tabs; only the active tab pane scrolls. */
#detailModal .detail-info { display: flex; flex-direction: column; min-height: 0; padding-right: 44px; }
.dx-head { flex: 0 0 auto; }
.dx-head .scott-line { margin-bottom: 2px; font-size: 13px; letter-spacing: .4px; }
.dx-head h2 { font-size: clamp(18px, 1.6vw + 8px, 23px); font-weight: 800; line-height: 1.2; margin: 0 0 8px; }
.dx-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.dx-chip {
  font-size: 12.5px; padding: 4px 10px; border-radius: 999px; background: var(--card);
  border: 1px solid var(--panel-border); color: var(--text); white-space: nowrap; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis;
}
.dx-chip b { color: var(--muted); font-weight: 700; margin-right: 3px; }
.dx-chip-val { border-color: color-mix(in srgb, var(--accent-2) 60%, transparent); color: var(--text); font-weight: 700; }

#detailModal .detail-info .ficha-tabs { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; margin: 12px 0 0; }
#detailModal .detail-info .tab-bar { flex: 0 0 auto; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; margin-bottom: 10px; }
#detailModal .detail-info .tab-btn { white-space: nowrap; min-height: 40px; }
#detailModal .detail-info .tab-pane.active {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 2px 8px 8px 0;
}
.tab-combo { display: none; }

/* Prev/next arrows sit on the card edges without covering text. */
#detailModal .detail-nav.prev { left: -58px; }
#detailModal .detail-nav.next { right: -58px; }
@media (max-width: 1320px) {
  #detailModal .detail-nav.prev { left: 8px; }
  #detailModal .detail-nav.next { right: 8px; }
  #detailModal .detail-body { padding-left: 64px; padding-right: 64px; }
  #detailModal .detail-info { padding-right: 0; }
}

/* Tablet / phone: one column, compact frame, tabs chosen from a combo, arrows in the top strip. */
@media (max-width: 760px) {
  #detailModal .modal-dialog { max-width: 100%; width: 100%; margin: 0; min-height: 100%; }
  #detailModal .detail-content { height: 100vh; height: 100dvh; border-radius: 0; border-left: 0; border-right: 0; }
  #detailModal .detail-body {
    grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr);
    gap: 12px; padding: 60px 14px 12px;
  }
  #detailModal .detail-gallery .main-img { flex: none; height: clamp(170px, 31dvh, 300px); min-height: 0; }
  #detailModal .detail-gallery .main-img img { inset: 10px; width: calc(100% - 20px); height: calc(100% - 20px); }
  .dx-actions { flex-wrap: nowrap; }
  .dx-act { flex: 1 1 0; padding: 0 10px; }
  #detailModal .detail-nav { top: 10px; transform: none; width: 44px; height: 44px; }
  #detailModal .detail-nav:hover:not(:disabled) { transform: none; }
  #detailModal .detail-nav.prev { left: 10px; }
  #detailModal .detail-nav.next { left: 62px; right: auto; }
  #detailModal .modal-x { top: 10px; right: 10px; width: 44px; height: 44px; }
  .dx-head h2 { font-size: 18px; margin-bottom: 6px; }
  /* Many sections do not fit as a row of tabs on a phone: pick them from a combo instead. */
  .tab-combo {
    display: block; width: 100%; min-height: 44px; margin: 0 0 10px; padding: 0 12px; border-radius: 12px;
    background-color: var(--bg-2); color: var(--text); border: 1px solid var(--panel-border);
    font-size: 15px; font-weight: 700; appearance: auto;
  }
  .tab-combo option { background-color: var(--bg-2); color: var(--text); }
  #detailModal .detail-info .tab-bar { display: none; }
}

/* Lightbox: always inside the screen, whatever the photo's shape. */
.lightbox img { max-width: min(94vw, 1400px); max-height: 90vh; max-height: 90dvh; width: auto; height: auto; object-fit: contain; }

/* ============================== Grid card badge ============================== */
.card-audio {
  position: absolute; top: 38px; left: 9px; z-index: 3; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-size: 14px; pointer-events: none;
  background: color-mix(in srgb, var(--bg-2) 80%, transparent); border: 1px solid var(--panel-border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
}

/* ============================== Edit form (admin) ============================== */
/* The editor (stamps, blocks, timbres, oficiales and SPD) fits the screen: tabs on top, one pane at
   a time, Save/Delete always visible. The whole record is still one <form>. */
#editModal .modal-dialog { max-width: 880px; }
#editModal .edit-content {
  display: flex; flex-direction: column; height: min(86vh, 720px); padding: 22px 24px 18px;
}
#editModal .edit-title { flex: 0 0 auto; margin: 0 48px 12px 0; font-size: 19px; }
#editModal .edit-form { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 0; }
.ef-tabs {
  flex: 0 0 auto; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: thin;
  border-bottom: 1px solid var(--panel-border); margin-bottom: 14px;
}
.ef-tab {
  flex: 0 0 auto; min-height: 42px; padding: 0 14px; background: none; border: none; cursor: pointer;
  border-bottom: 3px solid transparent; color: var(--muted); font-weight: 700; font-size: 14px; margin-bottom: -1px;
}
.ef-tab:hover { color: var(--text); }
.ef-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.ef-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding-right: 4px; display: flex; flex-direction: column; }
.ef-pane { display: none; }
.ef-pane.active { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; align-content: start; }
.ef-pane[data-ef="story"].active { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.ef-pane[data-ef="story"] .full { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.ef-pane[data-ef="story"] textarea { flex: 1 1 auto; min-height: 220px; resize: none; line-height: 1.5; }
.ef-pane[data-ef="photos"].active { grid-template-columns: 1fr; }
#editModal .edit-form .full { grid-column: 1 / -1; }
#editModal .edit-form input, #editModal .edit-form textarea { min-height: 42px; font-size: 14.5px; }
#editModal .edit-actions { flex: 0 0 auto; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--panel-border); }
@media (max-width: 640px) {
  #editModal .modal-dialog { margin: 0; max-width: 100%; }
  #editModal .edit-content { height: 100vh; height: 100dvh; border-radius: 0; padding: 16px 14px 12px; }
  .ef-pane.active { grid-template-columns: 1fr; }
  #editModal .edit-actions button { flex: 1 1 0; min-height: 46px; }
}

/* ============================== Chat · conversation mode ============================== */
.asst-panel.asst-top { z-index: 1065; }   /* opened from a ficha: stay above the modal */
.asst-stage {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  border-top: 1px solid var(--panel-border, rgba(255, 255, 255, .12));
  background: color-mix(in srgb, var(--accent, #5b8cff) 10%, var(--bg, #0b0f1a));
}
.asst-stage[hidden] { display: none; }
.asst-stage-txt { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.asst-stage-txt b { font-size: .95rem; }
.asst-stage-txt small { font-size: .74rem; color: var(--muted, #8a96b3); }
.asst-stage-end {
  flex: 0 0 auto; min-height: 40px; padding: 0 14px; border-radius: 999px; cursor: pointer; font-weight: 700;
  background: transparent; color: var(--text, #e8edf7); border: 1px solid var(--panel-border, rgba(255, 255, 255, .25));
}
.asst-stage-end:hover { border-color: #e5484d; color: #e5484d; }
/* The orb follows the microphone level (--lvl, 0..1) and changes colour with the phase. */
.asst-orb {
  --lvl: 0; flex: 0 0 auto; width: 42px; height: 42px; border-radius: 50%; position: relative;
  display: grid; place-items: center; background: var(--accent, #5b8cff);
  box-shadow: 0 0 0 calc(4px + var(--lvl) * 14px) color-mix(in srgb, var(--accent, #5b8cff) 28%, transparent);
  transition: box-shadow .08s linear, background .2s ease;
}
.asst-orb i { width: 12px; height: 12px; border-radius: 50%; background: #fff; transform: scale(calc(.8 + var(--lvl) * .9)); transition: transform .08s linear; }
.asst-stage[data-phase="speaking"] .asst-orb { background: var(--accent-2, #d2ad5b); animation: asstTalk 1.1s ease-in-out infinite; }
.asst-stage[data-phase="thinking"] .asst-orb,
.asst-stage[data-phase="transcribing"] .asst-orb { animation: asstThink 1s ease-in-out infinite; }
.asst-stage[data-phase="holding"] .asst-orb { background: #8a96b3; }
@keyframes asstTalk { 50% { transform: scale(1.08); } }
@keyframes asstThink { 50% { opacity: .55; } }
.asst-mic.rec { animation: none; box-shadow: 0 0 0 3px rgba(229, 72, 77, .35); }

/* Related historical audio inside an answer. */
.asst-audios { display: flex; flex-direction: column; gap: .4rem; margin-top: .55rem; }
.asst-audio {
  display: flex; align-items: center; gap: .55rem; text-align: left; width: 100%; cursor: pointer;
  padding: .5rem .65rem; border-radius: 12px; font-size: .8rem; color: inherit;
  background: color-mix(in srgb, var(--accent-2, #d2ad5b) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent-2, #d2ad5b) 45%, transparent);
}
.asst-audio:hover { border-color: var(--accent-2, #d2ad5b); }
.asst-audio b { margin-right: .25rem; }

/* Bigger, easier targets in the chat footer and header (WCAG 2.5.5 target size). */
.asst-fb { min-width: 34px; min-height: 34px; }
.asst-head .asst-act, .asst-head .asst-close { min-width: 40px; min-height: 40px; }
@media (max-width: 480px) {
  .asst-panel { height: 92vh; height: 92dvh; }
  .asst-mic, .asst-send { width: 3rem; height: 3rem; }
}

/* ============================== Global accessibility polish ============================== */
:where(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
@media (pointer: coarse) {
  .pager button { min-height: 44px; min-width: 44px; }
  .tab-btn { min-height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  .dx-listen.has-audio::after, .asst-orb, .asst-orb i, .asst-stage .asst-orb,
  .dx-act, .asst-dot { animation: none !important; transition: none !important; }
}

/* ============================== Brand ============================== */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 36px; height: 36px; flex: 0 0 auto; filter: drop-shadow(0 2px 6px rgba(0, 0, 0, .3)); }

/* ============================== Text on accent surfaces (WCAG AA) ============================== */
/* White text only reaches AA on DARK accents (Clásico, Moderno). On the light accents of Patrimonio
   (the default skin) and Infantil it measured ~2.2:1, so every text-bearing accent surface now uses
   --on-accent, defined per skin (the custom skin computes it from the chosen colour, see app.js). */
:root { --on-accent: #ffffff; }
[data-theme="patrimonio"] { --on-accent: #0c1420; }
[data-theme="kids"] { --on-accent: #1d1433; }
.range-list li a.active, .link-list li a.active-collection.active, .admin-link.on, .btn-new, .scott-badge,
.pager button.active, .btn-primary-pro, .set-seg button.active, .set-toggle.on, .mine-filter button.active,
.auth-tab.active, .sort-filter #sortDir, .scott-filter .yf-apply, .year-filter .yf-apply, .an-range-btn.active,
.gal-nav:hover, .gal-zoom:hover, #detailModal .detail-nav:hover:not(:disabled), .sotd-btn,
.asst-send, .asst-catalog-btn, .asst-trend-chip:hover, .asst-fab {
  color: var(--on-accent);
}
/* Chat header and the visitor's own bubbles: tinted surfaces with the theme text colour. */
.asst-head { background: color-mix(in srgb, var(--accent) 34%, var(--bg-2)); color: var(--text); }
.asst-head .asst-act, .asst-head .asst-close { color: var(--text); }
.asst-head .asst-avatar { background: color-mix(in srgb, var(--accent) 40%, transparent); }
.asst-row.user .asst-bubble {
  background: color-mix(in srgb, var(--accent) 30%, var(--bg-2)); color: var(--text);
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
}
.asst-row.user .asst-foot-time, .asst-row.user .asst-fb { color: var(--text); }
/* Themes whose buttons keep WHITE text (Oscuro, Clásico, Moderno, custom with a dark accent) get a
   subtle shade over the accent under the text, lifting white-text contrast from ~3.2:1 to ~5:1 without
   changing the palette. Patrimonio and Infantil use dark text instead, so they need no shade. */
:root { --accent-shade: rgba(0, 0, 0, .24); }
[data-theme="patrimonio"], [data-theme="kids"] { --accent-shade: transparent; }
.range-list li a.active, .link-list li a.active-collection.active, .admin-link.on, .btn-new, .scott-badge,
.pager button.active, .btn-primary-pro, .set-seg button.active, .set-toggle.on, .mine-filter button.active,
.auth-tab.active, .sort-filter #sortDir, .scott-filter .yf-apply, .year-filter .yf-apply,
#detailModal .detail-nav:hover:not(:disabled) {
  background-image: linear-gradient(var(--accent-shade), var(--accent-shade)), linear-gradient(135deg, var(--accent), var(--accent-2));
}
.an-range-btn.active, .gal-nav:hover, .gal-zoom:hover, .sotd-btn, .asst-send, .asst-catalog-btn,
.asst-trend-chip:hover, .asst-fab {
  background-image: linear-gradient(var(--accent-shade), var(--accent-shade));
}

/* ============================== Ficha · two-level tabs ============================== */
/* Level 1: a segmented control of at most four groups (always fits, never scrolls sideways).
   Level 2: wrapping pills inside the active group. Only the active pane scrolls, vertically. */
.ft-main {
  flex: 0 0 auto; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px;
  padding: 4px; border-radius: 14px; background: var(--card); border: 1px solid var(--panel-border);
}
.ft-main-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-width: 0; min-height: 44px;
  padding: 0 10px; border: 0; border-radius: 10px; background: transparent; color: var(--muted);
  font-size: 14px; font-weight: 700; letter-spacing: .2px; cursor: pointer;
}
.ft-main-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ft-main-btn svg { width: 18px; height: 18px; flex: 0 0 auto; }
.ft-main-btn:hover { color: var(--text); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.ft-main-btn.active {
  color: var(--text); background: color-mix(in srgb, var(--accent) 22%, var(--bg-2));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 60%, transparent), 0 6px 16px -10px rgba(0, 0, 0, .55);
}
.ft-main-btn.active svg { color: var(--accent); }
.ft-group { display: none; }
.ft-group.active { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.ft-sub { flex: 0 0 auto; display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 10px; }
.ft-sub.single { display: none; }
.ft-sub.single ~ .tab-pane { margin-top: 12px; }
.ft-sub-btn {
  min-height: 34px; max-width: 100%; padding: 0 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--panel-border); background: transparent; color: var(--muted);
  font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ft-sub-btn:hover { color: var(--text); border-color: color-mix(in srgb, var(--accent) 45%, var(--panel-border)); }
.ft-sub-btn.active { color: var(--text); background: color-mix(in srgb, var(--accent) 16%, transparent); border-color: var(--accent); }
#detailModal .ft-group > .tab-pane.active {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; padding: 2px 8px 8px 0;
  animation: ftIn .18s ease;
}
@keyframes ftIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (max-width: 760px) {
  .ft-main-btn { flex-direction: column; gap: 3px; min-height: 54px; padding: 4px 2px; font-size: 11.5px; }
  .ft-main-btn svg { width: 20px; height: 20px; }
  .ft-sub { margin: 10px 0 8px; }
  .ft-sub-btn { min-height: 38px; font-size: 13px; }
}
@media (pointer: coarse) { .ft-sub-btn { min-height: 40px; } }
@media (prefers-reduced-motion: reduce) { #detailModal .ft-group > .tab-pane.active { animation: none; } }
