/* Asistente virtual de la AMN (personal de guardia) — botón flotante, panel de chat y bienvenida */
.tm {
    --tm-navy: var(--navy-800, #07182E);
    --tm-navy2: var(--navy-700, #0B2240);
    --tm-navy3: var(--navy-600, #13325C);
    --tm-gold: var(--gold, #E0B23C);
    --tm-gold-soft: var(--gold-soft, #F1D58A);
    --tm-sea: var(--sea, #2F7FB8);
    --tm-paper: #F4F6F9;
    --tm-ink: var(--ink, #0E1B2C);
    --tm-muted: var(--muted, #5A6878);
    --tm-line: #DCE2EA;
    font-family: var(--font, 'Barlow', system-ui, sans-serif);
    color: var(--tm-ink);
}
.tm [hidden] { display: none !important; }
.tm button { font: inherit; }

/* ---------- Botón flotante ---------- */
.tm-fab {
    position: fixed; right: 22px; bottom: 22px; z-index: 800;
    width: 66px; height: 66px; border-radius: 50%;
    display: grid; place-items: center; cursor: pointer; padding: 0;
    background: radial-gradient(circle at 50% 35%, var(--tm-navy3), var(--tm-navy) 70%);
    border: 2px solid var(--tm-gold);
    box-shadow: 0 10px 28px rgba(4, 14, 28, .38), 0 0 0 4px rgba(224, 178, 60, .14);
    transition: transform .25s ease, box-shadow .25s ease, opacity .3s ease;
}
.tm-fab img { width: 60px; height: 60px; border-radius: 50%; object-fit: cover; }
.tm-fab:hover { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(4, 14, 28, .45), 0 0 0 5px rgba(224, 178, 60, .22); }
.tm-fab:focus-visible { outline: 3px solid var(--tm-gold-soft); outline-offset: 4px; }
.tm-fab__ring {
    position: absolute; inset: -2px; border-radius: 50%;
    border: 2px solid var(--tm-gold); opacity: 0; pointer-events: none;
    animation: tm-pulso 3.2s ease-out infinite;
}
.tm-fab[aria-expanded="true"] .tm-fab__ring { animation: none; }
body.is-loading .tm-fab { opacity: 0; pointer-events: none; }
@keyframes tm-pulso {
    0% { transform: scale(1); opacity: .55; }
    70%, 100% { transform: scale(1.45); opacity: 0; }
}

/* ---------- Panel ---------- */
.tm-panel {
    position: fixed; right: 22px; bottom: 100px; z-index: 810;
    width: 400px; max-width: calc(100vw - 32px);
    height: min(640px, calc(100vh - 124px));
    display: flex; flex-direction: column; overflow: hidden;
    background: #fff; border-radius: 16px;
    box-shadow: 0 24px 60px rgba(4, 14, 28, .35), 0 0 0 1px rgba(7, 24, 46, .08);
    transform-origin: 100% 100%;
    animation: tm-abrir .28s cubic-bezier(.2, .8, .2, 1);
}
@keyframes tm-abrir { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }

.tm-head {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 12px 14px 16px; color: #fff;
    background: linear-gradient(135deg, var(--tm-navy3) 0%, var(--tm-navy) 70%);
    position: relative;
}
.tm-head::after {
    content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1px;
    background: linear-gradient(90deg, transparent, var(--tm-gold), transparent); opacity: .7;
}
.tm-head__escudo {
    width: 46px; height: 46px; border-radius: 50%; flex: none;
    display: grid; place-items: center;
    background: rgba(255, 255, 255, .06); box-shadow: inset 0 0 0 1px rgba(224, 178, 60, .55);
}
.tm-head__escudo { position: relative; }
.tm-head__escudo .tm-foto { width: 46px; height: 46px; border-radius: 50%; object-fit: cover; }
.tm-badge {
    position: absolute; right: -3px; bottom: -3px; width: 20px; height: 20px; border-radius: 50%;
    display: grid; place-items: center; color: var(--tm-gold); background: var(--tm-navy); box-shadow: 0 0 0 1.5px var(--tm-gold);
}
.tm-badge--lg { width: 30px; height: 30px; right: 2px; bottom: 2px; }
.tm-badge svg { display: block; }
.tm-head__txt { flex: 1; min-width: 0; }
.tm-head h2 { margin: 0; font-family: var(--font-cond, sans-serif); font-size: 1.35rem; font-weight: 700; letter-spacing: .04em; color: #fff; line-height: 1.1; }
.tm-head p { margin: 2px 0 0; font-size: .84rem; color: rgba(255, 255, 255, .78); display: flex; align-items: center; gap: 6px; }
.tm-dot { width: 8px; height: 8px; border-radius: 50%; background: #4CC38A; box-shadow: 0 0 0 3px rgba(76, 195, 138, .2); }
.tm-ibtn {
    width: 38px; height: 38px; border-radius: 10px; flex: none; cursor: pointer;
    display: grid; place-items: center; color: #fff;
    background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .14);
    transition: background .2s ease, color .2s ease;
}
.tm-ibtn:hover { background: rgba(255, 255, 255, .16); }
.tm-ibtn:focus-visible { outline: 2px solid var(--tm-gold); outline-offset: 2px; }
.tm-ibtn .tm-vz-on { display: none; }
.tm-ibtn[aria-pressed="true"] { color: var(--tm-navy); background: var(--tm-gold); border-color: var(--tm-gold); }
.tm-ibtn[aria-pressed="true"] .tm-vz-on { display: block; }
.tm-ibtn[aria-pressed="true"] .tm-vz-off { display: none; }
.tm-ibtn span { display: grid; }

/* Acciones rápidas */
.tm-acc { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 10px 12px; background: var(--tm-navy); }
.tm-acc a {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 7px 4px; border-radius: 10px; text-decoration: none;
    color: var(--tm-gold-soft); font-size: .76rem; font-weight: 600; letter-spacing: .02em;
    background: rgba(255, 255, 255, .05); border: 1px solid rgba(224, 178, 60, .22);
    transition: background .2s ease, color .2s ease;
}
.tm-acc a:hover { background: rgba(224, 178, 60, .16); color: #fff; }
.tm-acc a:focus-visible { outline: 2px solid var(--tm-gold); outline-offset: 1px; }

/* Pestañas */
.tm-tabs { display: flex; background: var(--tm-paper); border-bottom: 1px solid var(--tm-line); }
.tm-tab {
    flex: 1; padding: 10px 8px; cursor: pointer; background: none; border: 0;
    font-size: .9rem; font-weight: 600; color: var(--tm-muted); position: relative;
}
.tm-tab.is-on { color: var(--tm-navy); }
.tm-tab.is-on::after { content: ""; position: absolute; left: 22%; right: 22%; bottom: -1px; height: 2px; border-radius: 2px; background: var(--tm-gold); }
.tm-tab:focus-visible { outline: 2px solid var(--tm-sea); outline-offset: -3px; }

.tm-vista { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--tm-paper); }

/* Conversación */
.tm-log { flex: 1; overflow-y: auto; padding: 16px 14px 6px; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; overscroll-behavior: contain; }
.tm-log:focus-visible { outline: 2px solid var(--tm-sea); outline-offset: -2px; }
.tm-msg { max-width: 88%; display: flex; flex-direction: column; gap: 4px; animation: tm-entra .25s ease; }
@keyframes tm-entra { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.tm-msg--bot { align-self: flex-start; flex-direction: row; align-items: flex-start; gap: 8px; max-width: 94%; }
.tm-msg__col { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tm-avatar { width: 32px; height: 32px; flex: none; border-radius: 50%; object-fit: cover; margin-top: 2px; box-shadow: 0 0 0 1.5px var(--tm-gold); }
.tm-escribiendo .tm-burbuja { margin-left: 40px; }
.tm-msg--yo { align-self: flex-end; }
.tm-burbuja { padding: 10px 13px; border-radius: 14px; font-size: .95rem; line-height: 1.5; overflow-wrap: anywhere; }
.tm-msg--bot .tm-burbuja { background: #fff; color: var(--tm-ink); border-top-left-radius: 4px; box-shadow: 0 1px 2px rgba(7, 24, 46, .08), 0 0 0 1px rgba(7, 24, 46, .05); }
.tm-msg--yo .tm-burbuja { background: var(--tm-navy2); color: #fff; border-top-right-radius: 4px; }
.tm-md p { margin: 0 0 .55em; }
.tm-md p:last-child, .tm-md ul:last-child { margin-bottom: 0; }
.tm-md ul { margin: .2em 0 .55em; padding-left: 1.15em; }
.tm-md li { margin: .15em 0; }
.tm-md li::marker { color: var(--tm-gold); }
.tm-md a { color: var(--tm-sea); font-weight: 600; text-underline-offset: 2px; }
.tm-md strong { color: var(--tm-navy); }
.tm-pie { display: flex; align-items: center; gap: 8px; padding-left: 4px; }
.tm-pie small { font-size: .72rem; color: var(--tm-muted); letter-spacing: .02em; }
.tm-hablar {
    display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; cursor: pointer;
    font-size: .76rem; font-weight: 600; color: var(--tm-navy3);
    background: transparent; border: 1px solid var(--tm-line); border-radius: 999px;
}
.tm-hablar:hover { background: #fff; border-color: var(--tm-gold); }
.tm-hablar[aria-pressed="true"] { background: var(--tm-navy); color: var(--tm-gold-soft); border-color: var(--tm-navy); }
.tm-hablar:focus-visible { outline: 2px solid var(--tm-sea); outline-offset: 1px; }

.tm-escribiendo .tm-burbuja { display: inline-flex; align-items: center; gap: 8px; color: var(--tm-muted); font-size: .88rem; }
.tm-puntos { display: inline-flex; gap: 4px; }
.tm-puntos i { width: 6px; height: 6px; border-radius: 50%; background: var(--tm-navy3); opacity: .35; animation: tm-punto 1.2s ease-in-out infinite; }
.tm-puntos i:nth-child(2) { animation-delay: .15s; }
.tm-puntos i:nth-child(3) { animation-delay: .3s; }
@keyframes tm-punto { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.tm-chips { display: flex; gap: 6px; padding: 8px 14px 4px; overflow-x: auto; scrollbar-width: thin; flex: none; }
.tm-chip {
    flex: none; white-space: nowrap; cursor: pointer;
    padding: 6px 11px; border-radius: 999px; font-size: .82rem; font-weight: 500;
    color: var(--tm-navy2); background: #fff; border: 1px solid rgba(224, 178, 60, .6);
    transition: background .2s ease, color .2s ease;
}
.tm-chip:hover { background: var(--tm-navy); color: #fff; border-color: var(--tm-navy); }
.tm-chip:focus-visible { outline: 2px solid var(--tm-sea); outline-offset: 1px; }

.tm-form { display: flex; align-items: flex-end; gap: 8px; padding: 8px 12px 6px; flex: none; }
.tm-form textarea {
    flex: 1; resize: none; min-height: 44px; max-height: 120px; overflow-y: hidden;
    padding: 11px 13px; border-radius: 12px; font: inherit; font-size: .95rem; line-height: 1.4;
    color: var(--tm-ink); background: #fff; border: 1px solid var(--tm-line);
}
.tm-form textarea:focus { outline: none; border-color: var(--tm-sea); box-shadow: 0 0 0 3px rgba(47, 127, 184, .18); }
.tm-send {
    width: 44px; height: 44px; flex: none; border-radius: 12px; cursor: pointer;
    display: grid; place-items: center; border: 0;
    background: var(--tm-gold); color: var(--tm-navy);
    transition: background .2s ease, opacity .2s ease;
}
.tm-send:hover { background: var(--tm-gold-soft); }
.tm-send:disabled { opacity: .5; cursor: default; }
.tm-send:focus-visible { outline: 2px solid var(--tm-navy); outline-offset: 2px; }
.tm-nota { margin: 0; padding: 0 14px 10px; font-size: .72rem; color: var(--tm-muted); flex: none; }

/* Preguntas frecuentes */
.tm-faq { overflow-y: auto; padding: 12px 12px 16px; gap: 8px; overscroll-behavior: contain; }
.tm-faq__item { background: #fff; border-radius: 12px; box-shadow: 0 0 0 1px rgba(7, 24, 46, .07); flex: none; }
.tm-faq__item summary {
    list-style: none; cursor: pointer; padding: 11px 38px 11px 14px; position: relative;
    font-weight: 600; font-size: .92rem; color: var(--tm-navy2);
}
.tm-faq__item summary::-webkit-details-marker { display: none; }
.tm-faq__item summary::after {
    content: ""; position: absolute; right: 15px; top: 50%; width: 8px; height: 8px; margin-top: -6px;
    border-right: 2px solid var(--tm-gold); border-bottom: 2px solid var(--tm-gold);
    transform: rotate(45deg); transition: transform .2s ease;
}
.tm-faq__item[open] summary::after { transform: rotate(225deg); margin-top: -2px; }
.tm-faq__item summary:focus-visible { outline: 2px solid var(--tm-sea); outline-offset: -2px; border-radius: 12px; }
.tm-faq__item .tm-md { padding: 0 14px 12px; font-size: .9rem; line-height: 1.5; }

/* ---------- Bienvenida ---------- */
.tm-hola {
    position: fixed; right: 22px; bottom: 102px; z-index: 805;
    width: 340px; max-width: calc(100vw - 32px);
    padding: 22px 20px 30px; overflow: hidden; text-align: center; color: #fff;
    border-radius: 18px;
    background: radial-gradient(ellipse at 50% 0%, var(--tm-navy3) 0%, var(--tm-navy) 62%, #050F1F 100%);
    box-shadow: 0 24px 60px rgba(4, 14, 28, .45), inset 0 0 0 1px rgba(224, 178, 60, .35);
    animation: tm-hola-in .7s cubic-bezier(.2, .8, .2, 1) both;
}
@keyframes tm-hola-in { from { opacity: 0; transform: translateY(24px) scale(.94); } to { opacity: 1; transform: none; } }
.tm-hola.is-saliendo { animation: tm-hola-out .3s ease forwards; }
@keyframes tm-hola-out { to { opacity: 0; transform: translateY(14px) scale(.97); } }
.tm-hola__x {
    position: absolute; top: 10px; right: 10px; width: 32px; height: 32px; border-radius: 8px; cursor: pointer;
    display: grid; place-items: center; color: rgba(255, 255, 255, .8);
    background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .12);
}
.tm-hola__x:hover { color: #fff; background: rgba(255, 255, 255, .14); }
.tm-hola__x:focus-visible { outline: 2px solid var(--tm-gold); outline-offset: 2px; }
.tm-hola__escudo { position: relative; width: 112px; height: 112px; margin: 2px auto 10px; display: grid; place-items: center; }
.tm-hola__foto { width: 92px; height: 92px; border-radius: 50%; object-fit: cover; position: relative; box-shadow: 0 6px 18px rgba(0, 0, 0, .45); animation: tm-respira 3s ease-in-out infinite; }
.tm-hola__onda { position: absolute; inset: 6px; border-radius: 50%; border: 1px solid var(--tm-gold); opacity: 0; animation: tm-onda 2.8s ease-out infinite; }
.tm-hola__onda + .tm-hola__onda { animation-delay: 1.4s; }
@keyframes tm-onda { 0% { transform: scale(.7); opacity: .7; } 100% { transform: scale(1.35); opacity: 0; } }
@keyframes tm-respira { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.04); } }
.tm-hola__kicker { margin: 0 0 4px; font-family: var(--font-cond, sans-serif); font-size: .78rem; font-weight: 600; letter-spacing: .18em; text-transform: uppercase; color: var(--tm-gold-soft); }
.tm-hola__t { margin: 0 0 8px; font-family: var(--font-cond, sans-serif); font-size: 2rem; font-weight: 700; line-height: 1.05; letter-spacing: .02em; color: #fff; }
.tm-hola__p { margin: 0 auto 16px; max-width: 280px; font-size: .95rem; line-height: 1.5; color: rgba(255, 255, 255, .84); }
.tm-hola__btns { display: flex; flex-direction: column; gap: 8px; position: relative; z-index: 1; }
.tm-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 11px 16px; border-radius: 10px; cursor: pointer; font-weight: 700; font-size: .95rem; letter-spacing: .02em;
    transition: background .2s ease, color .2s ease;
}
.tm-btn--oro { background: var(--tm-gold); color: var(--tm-navy); border: 1px solid var(--tm-gold); }
.tm-btn--oro:hover { background: var(--tm-gold-soft); }
.tm-btn--oro[aria-pressed="true"] { background: #fff; border-color: #fff; }
.tm-btn--linea { background: transparent; color: #fff; border: 1px solid rgba(255, 255, 255, .35); }
.tm-btn--linea:hover { background: rgba(255, 255, 255, .1); }
.tm-btn:focus-visible { outline: 2px solid var(--tm-gold-soft); outline-offset: 2px; }
.tm-hola__olas { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 26px; fill: rgba(47, 127, 184, .22); }
.tm-hola.is-hablando .tm-hola__onda { animation-duration: 1.2s; }

/* ---------- Móvil: panel a pantalla completa ---------- */
@media (max-width: 560px) {
    .tm-fab { right: 16px; bottom: 16px; width: 60px; height: 60px; }
    .tm-fab img { width: 54px; height: 54px; }
    .tm-panel {
        inset: 0; right: 0; bottom: 0; width: 100%; max-width: none; height: 100%; height: 100dvh;
        border-radius: 0;
    }
    .tm-hola { right: 16px; left: 16px; bottom: 90px; width: auto; }
    body.tm-abierto { overflow: hidden; }
    body.tm-abierto .tm-fab { display: none; }
    .tm-form textarea { font-size: 16px; } /* evita el zoom automático en iOS */
}

@media (prefers-reduced-motion: reduce) {
    .tm-fab__ring, .tm-hola__onda, .tm-hola__foto, .tm-puntos i { animation: none !important; }
    .tm-panel, .tm-msg, .tm-hola, .tm-hola.is-saliendo { animation: none !important; }
    .tm-log { scroll-behavior: auto; }
    .tm-fab, .tm-fab:hover { transition: none; transform: none; }
}

@media print { .tm { display: none !important; } }

/* ---------- Mientras el personaje habla: anillo dorado animado en el retrato ---------- */
.tm-head__escudo::after, .tm-hola__escudo::after {
    content: ""; position: absolute; inset: -4px; border-radius: 50%;
    border: 2px solid var(--tm-gold); opacity: 0; pointer-events: none;
}
.tm-hola__escudo::after { inset: 4px; }
.tm.tm-hablando .tm-head__escudo::after,
.tm.tm-hablando .tm-hola__escudo::after { animation: tm-habla 1.1s ease-out infinite; }
.tm.tm-hablando .tm-fab { box-shadow: 0 10px 28px rgba(4, 14, 28, .38), 0 0 0 4px rgba(224, 178, 60, .45); }
.tm.tm-hablando .tm-fab__ring { animation-duration: 1.1s; }
@keyframes tm-habla { 0% { transform: scale(1); opacity: .9; } 100% { transform: scale(1.22); opacity: 0; } }

/* Botón grande para escuchar el saludo cuando el navegador bloquea el sonido automático */
.tm-escuchar { display: flex; justify-content: center; padding: 2px 0 6px; }
.tm-btn--grande { min-height: 48px; padding: 12px 22px; font-size: 1rem; box-shadow: 0 6px 16px rgba(224, 178, 60, .25); }
.tm-btn--grande[aria-pressed="true"] { background: var(--tm-navy); color: var(--tm-gold-soft); border-color: var(--tm-navy); }

@media (prefers-reduced-motion: reduce) {
    .tm.tm-hablando .tm-head__escudo::after, .tm.tm-hablando .tm-hola__escudo::after { animation: none; opacity: 1; }
}
