/* ==========================================================================
   Botón flotante de reporte de averías · AppImpulsa
   --------------------------------------------------------------------------
   Se coloca ARRIBA del asistente IA existente para no solaparlo:
     · chat IA    -> right:22px  bottom:22px   (botón de 60px)
     · averías    -> right:22px  bottom:94px
   Si cambias la posición del chat, ajusta --av-bottom con la misma fórmula:
     --av-bottom = bottom_del_chat + alto_del_chat + separación
   ========================================================================== */

.averias-widget {
    --av-right: 22px;
    --av-bottom: 94px;          /* 22 + 60 + 12 */
    --av-accent: #f97316;
    --av-accent-2: #c2410c;
    --av-ink: #0f172a;
    --av-line: #e2e8f0;

    position: fixed;
    right: var(--av-right);
    bottom: var(--av-bottom);
    z-index: 1210;              /* por encima del chat IA (1200) */
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* --------------------------------------------------------------------------
   Botón
   -------------------------------------------------------------------------- */

.averias-btn {
    position: relative;
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--av-accent), var(--av-accent-2));
    color: #fff;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(194, 65, 12, .32);
    transition: transform .18s ease, box-shadow .18s ease;
}

.averias-btn:hover,
.averias-btn:focus-visible {
    transform: translateY(-2px);
    box-shadow: 0 14px 30px rgba(194, 65, 12, .42);
    outline: none;
}

.averias-btn:focus-visible {
    box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--av-accent);
}

.averias-btn svg {
    width: 25px;
    height: 25px;
    display: block;
}

/* Punto rojo cuando el Panel Admin General ya respondió */
.averias-btn.has-reply::after {
    content: '';
    position: absolute;
    top: 1px;
    right: 1px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #dc2626;
    border: 2px solid #fff;
    box-shadow: 0 0 0 0 rgba(220, 38, 38, .55);
    animation: avDot 1.6s ease-out infinite;
}

@keyframes avDot {
    0%   { box-shadow: 0 0 0 0 rgba(220, 38, 38, .55); }
    100% { box-shadow: 0 0 0 10px rgba(220, 38, 38, 0); }
}

.averias-btn-label {
    position: absolute;
    right: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--av-ink);
    color: #fff;
    font-size: .78rem;
    font-weight: 700;
    white-space: nowrap;
    padding: 7px 12px;
    border-radius: 8px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
}

.averias-btn:hover + .averias-btn-label,
.averias-btn:focus-visible + .averias-btn-label {
    opacity: 1;
}

/* --------------------------------------------------------------------------
   Panel
   -------------------------------------------------------------------------- */

.averias-panel {
    position: absolute;
    right: 0;
    bottom: 70px;
    width: min(360px, calc(100vw - 28px));
    background: #fff;
    border: 1px solid var(--av-line);
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, .22);
    overflow: hidden;
}

.averias-panel[hidden] {
    display: none;
}

.averias-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 15px 16px 13px;
    background: linear-gradient(120deg, #0f3d45, #1769aa);
    color: #fff;
}

.averias-head strong {
    display: block;
    font-size: .92rem;
    font-weight: 800;
    line-height: 1.25;
}

.averias-head span {
    display: block;
    font-size: .75rem;
    color: #c7e0e6;
    margin-top: 3px;
    line-height: 1.4;
}

.averias-close {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 8px;
    background: #ffffff26;
    color: #fff;
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
}

.averias-close:hover {
    background: #ffffff3d;
}

.averias-body {
    padding: 15px 16px 16px;
    max-height: min(70vh, 560px);
    overflow-y: auto;
}

.averias-body label {
    display: block;
    font-size: .78rem;
    font-weight: 750;
    color: #334155;
    margin-bottom: 6px;
}

.averias-body textarea,
.averias-body input[type="text"],
.averias-body input[type="email"] {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    padding: 11px 12px;
    font: inherit;
    font-size: .88rem;
    color: var(--av-ink);
    background: #fbfdff;
}

.averias-body textarea {
    min-height: 104px;
    max-height: 240px;
    resize: vertical;
}

.averias-body textarea:focus,
.averias-body input[type="text"]:focus,
.averias-body input[type="email"]:focus {
    outline: none;
    border-color: #1769aa;
    box-shadow: 0 0 0 3px #1769aa1f;
}

/* Nombre y correo, en dos columnas (se apilan en pantallas estrechas) */
.averias-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 12px;
}

.averias-field {
    min-width: 0;
}

@media (max-width: 420px) {
    .averias-row {
        grid-template-columns: 1fr;
    }
}

.averias-counter {
    text-align: right;
    font-size: .72rem;
    color: #94a3b8;
    margin-top: 5px;
}

.averias-counter.over {
    color: #dc2626;
    font-weight: 700;
}

.averias-send {
    width: 100%;
    margin-top: 11px;
    border: 0;
    border-radius: 10px;
    padding: 11px 16px;
    background: linear-gradient(135deg, #f97316, #c2410c);
    color: #fff;
    font: inherit;
    font-size: .88rem;
    font-weight: 800;
    cursor: pointer;
}

.averias-send:hover:not(:disabled) {
    filter: brightness(1.06);
}

.averias-send:disabled {
    opacity: .55;
    cursor: not-allowed;
}

.averias-note {
    margin: 10px 0 0;
    font-size: .72rem;
    color: #94a3b8;
    line-height: 1.5;
}

/* --------------------------------------------------------------------------
   Hilo de conversación con el Panel Admin General
   -------------------------------------------------------------------------- */

.averias-hilo {
    max-height: 260px;
    overflow-y: auto;
    margin-bottom: 14px;
    padding-right: 2px;
}

.averias-hilo[hidden] {
    display: none;
}

.averias-hilo-title {
    font-size: .68rem;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: #64748b;
    margin-bottom: 8px;
}

.av-bubble {
    border-radius: 12px;
    padding: 9px 11px;
    font-size: .82rem;
    line-height: 1.45;
    margin-bottom: 8px;
}

.av-user {
    background: #eef6ff;
    border: 1px solid #cfe4ff;
}

.av-admin {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
}

.av-pending {
    background: #fff7ed;
    border: 1px solid #fed7aa;
}

.av-who {
    font-size: .68rem;
    font-weight: 800;
    color: #475569;
    margin-bottom: 3px;
}

.av-text {
    white-space: pre-wrap;
    word-wrap: break-word;
    color: #0f172a;
}

/* --------------------------------------------------------------------------
   Estados
   -------------------------------------------------------------------------- */

.averias-msg {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: 9px;
    font-size: .82rem;
    line-height: 1.5;
}

.averias-msg[hidden] {
    display: none;
}

.averias-msg.ok {
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    color: #065f46;
}

.averias-msg.err {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

/* Honeypot: invisible para humanos, visible para bots */
.averias-hp {
    position: absolute !important;
    left: -9999px !important;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* --------------------------------------------------------------------------
   Móvil — el chat IA pasa a right:14px / bottom:14px con botón de 56px
   -------------------------------------------------------------------------- */

@media (max-width: 560px) {
    .averias-widget {
        --av-right: 14px;
        --av-bottom: 80px;      /* 14 + 56 + 10 */
    }

    .averias-btn {
        width: 52px;
        height: 52px;
    }

    .averias-btn svg {
        width: 23px;
        height: 23px;
    }

    .averias-btn-label {
        display: none;
    }

    .averias-panel {
        bottom: 64px;
        width: min(340px, calc(100vw - 24px));
    }
}

/* Accesibilidad: respeta la preferencia de movimiento reducido */
@media (prefers-reduced-motion: reduce) {
    .averias-btn,
    .averias-btn-label,
    .averias-btn.has-reply::after {
        transition: none;
        animation: none;
    }
}
