/* ──────────────────────────────────────────────────────────────────────────
   zofi.css — estilos de la app (dashboard) y chrome compartido (navbar/footer).
   La landing pública vive en landing.css (.zofi-lp) y las pantallas de acceso
   en auth.css (.zofi-auth); acá NO va nada de esas dos.
   ────────────────────────────────────────────────────────────────────────── */

/* ── Variables ─────────────────────────────────────────────── */
:root {
    /* Backgrounds */
    --zofi-bg:          #f9fafb;
    --zofi-bg-card:     #ffffff;
    --zofi-bg-glass:    rgba(255,255,255,0.85);
    --zofi-border:      #e5e7eb;
    --zofi-border-soft: #f3f4f6;

    /* Brand */
    --zofi-teal:        #00789E;
    --zofi-teal-dark:   #006080;
    --zofi-green:       #10B981;
    --zofi-green-dark:  #059669;

    /* Aliases used throughout templates */
    --zofi-purple:      #00789E;
    --zofi-purple-2:    #10B981;
    --zofi-blue:        #00789E;

    /* Text */
    --zofi-text:        #58595B;
    --zofi-muted:       #6b7280;

    /* Gradients */
    --zofi-grad:        linear-gradient(135deg, #00789E, #10B981);
    --zofi-grad-text:   linear-gradient(90deg, #00789E, #10B981);

    /* Shadows */
    --zofi-shadow-sm:   0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --zofi-shadow-md:   0 4px 16px rgba(0,0,0,.08), 0 2px 8px rgba(0,0,0,.04);
    --zofi-shadow-lg:   0 12px 40px rgba(0,120,158,.12);
}

/* ── Base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    background-color: var(--zofi-bg);
    color: var(--zofi-text);
    font-family: 'Inter', system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* ── Gradient text ─────────────────────────────────────────── */
.text-grad {
    background: var(--zofi-grad-text);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn-zofi {
    background: var(--zofi-teal);
    border: none;
    color: #fff;
    font-weight: 600;
    padding: .65rem 1.5rem;
    border-radius: 12px;
    transition: background .2s, transform .2s, box-shadow .2s;
    box-shadow: var(--zofi-shadow-md);
}
.btn-zofi:hover {
    background: var(--zofi-teal-dark);
    transform: translateY(-1px);
    box-shadow: var(--zofi-shadow-lg);
    color: #fff;
}

.btn-zofi-outline {
    background: transparent;
    border: 1px solid var(--zofi-border);
    color: var(--zofi-muted);
    font-weight: 600;
    padding: .65rem 1.5rem;
    border-radius: 12px;
    transition: all .2s;
}
.btn-zofi-outline:hover {
    background: var(--zofi-bg);
    border-color: var(--zofi-teal);
    color: var(--zofi-teal);
}

/* ── Navbar (dashboard + páginas legales) ──────────────────── */
.zofi-navbar {
    background: #ffffff;
    border-bottom: 1px solid var(--zofi-border);
    box-shadow: var(--zofi-shadow-sm);
    transition: box-shadow .3s;
}
.zofi-navbar .navbar-brand span { font-weight: 800; font-size: 1.4rem; }
.zofi-navbar .nav-link { color: var(--zofi-muted) !important; font-weight: 500; transition: color .2s; }
.zofi-navbar .nav-link:hover { color: var(--zofi-teal) !important; }

/* ── Footer (páginas legales) ──────────────────────────────── */
.zofi-footer {
    border-top: 1px solid var(--zofi-border);
    padding: 3rem 0;
    color: var(--zofi-muted);
    font-size: .9rem;
}

/* ── Dashboard navbar ──────────────────────────────────────── */
.dash-topbar {
    background: #ffffff;
    border-bottom: 1px solid var(--zofi-border);
    box-shadow: var(--zofi-shadow-sm);
}

/* ── Dashboard sidebar ─────────────────────────────────────── */
.dash-sidebar {
    width: 240px;
    min-height: calc(100vh - 60px);
    background: #ffffff;
    border-right: 1px solid var(--zofi-border);
    padding: 1.5rem 1rem;
    flex-shrink: 0;
}
.dash-nav-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .65rem 1rem;
    border-radius: 10px;
    color: var(--zofi-muted);
    font-size: .9rem;
    font-weight: 500;
    text-decoration: none;
    transition: background .2s, color .2s;
    margin-bottom: .25rem;
}
.dash-nav-link:hover {
    background: rgba(0,120,158,.07);
    color: var(--zofi-teal);
}
.dash-nav-link.active {
    background: var(--zofi-teal);
    color: #ffffff;
}
.dash-nav-link .bi { font-size: 1.05rem; }

/* El menú va partido por servicio: cada grupo se pliega, y «Cuenta» junta lo
   que usan los dos. Ver base_dashboard.html. */
.dash-nav-grupo,
.dash-nav-titulo {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin-top: 1rem;
    padding: .4rem 1rem;
    border: 0;
    background: none;
    color: var(--zofi-muted);
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.dash-nav-grupo { border-radius: 8px; cursor: pointer; transition: color .2s, background .2s; }
.dash-nav-grupo:hover { color: var(--zofi-teal); background: rgba(0,120,158,.05); }
.dash-nav-grupo > span { display: inline-flex; align-items: center; gap: .5rem; }
.dash-nav-flecha { font-size: .7rem; transition: transform .2s; }
.dash-nav-grupo.collapsed .dash-nav-flecha { transform: rotate(-90deg); }
/* Los ítems de un grupo cuelgan de una línea, como un árbol: se ve de quién
   son sin leer. Van más chicos que los de primer nivel. */
.dash-nav-grupo + .collapse,
.dash-nav-grupo + .collapsing {
    margin: .15rem 0 0 1.45rem;
    padding-left: .5rem;
    border-left: 1px solid var(--zofi-border);
}
.dash-nav-sub { padding: .5rem .75rem; font-size: .87rem; margin-bottom: .1rem; }
.dash-nav-sub .bi { font-size: .95rem; }

/* ── Dashboard stat cards ──────────────────────────────────── */
.dash-stat-card {
    background: var(--zofi-bg-card);
    border: 1px solid var(--zofi-border-soft);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: var(--zofi-shadow-sm);
    transition: border-color .2s, box-shadow .2s;
}
.dash-stat-card:hover {
    border-color: rgba(0,120,158,.2);
    box-shadow: var(--zofi-shadow-md);
}

/* ── Progress bar ──────────────────────────────────────────── */
.progress-zofi {
    height: 6px;
    border-radius: 50px;
    background: #f3f4f6;
    overflow: hidden;
}
.progress-zofi .progress-bar {
    border-radius: 50px;
    background: var(--zofi-grad);
    /* El .progress-bar de Bootstrap saca su altura del .progress padre, que acá
       no está: sin esto la barra tiene el ancho y el color bien, y 0px de alto
       — o sea, invisible. */
    height: 100%;
}

/* ── Chat ──────────────────────────────────────────────────────
   Una sola definición de "chat de zofi", que comparten el inbox
   (conversaciones reales) y el simulador de la pantalla del asistente.
   Vivían inline en messages.html; con dos pantallas pintando burbujas,
   dos copias divergen en la primera corrección que se haga a una sola.

   El color del saliente es una variable a propósito: en el inbox es el
   verde de WhatsApp porque eso ES un WhatsApp, y en el simulador es el
   gradiente de zofi porque no hay ningún canal del otro lado. */
.zofi-chat {
    --zofi-chat-out: linear-gradient(135deg, #1a7a45, #128C7E);
}
.zofi-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.zofi-chat-wrap {
    display: flex;
    flex-direction: column;
    max-width: 68%;
}
.zofi-chat-wrap.inbound  { align-self: flex-start; align-items: flex-start; }
.zofi-chat-wrap.outbound { align-self: flex-end;   align-items: flex-end; }
.zofi-chat-bubble {
    padding: 9px 14px;
    border-radius: 12px;
    font-size: .9rem;
    line-height: 1.45;
    word-break: break-word;
    white-space: pre-wrap;
    position: relative;
}
.zofi-chat-bubble.inbound {
    background: var(--zofi-bg-card, #ffffff);
    color: var(--zofi-text);
    border: 1px solid var(--zofi-border);
    box-shadow: 0 1px 1px rgba(0,0,0,.05);
    border-bottom-left-radius: 4px;
}
.zofi-chat-bubble.outbound {
    background: var(--zofi-chat-out);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.zofi-chat-time {
    font-size: .72rem;
    color: var(--zofi-muted);
    margin-top: 3px;
    padding: 0 2px;
}
/* Tres puntos mientras el agente piensa. Sin esto, una respuesta que tarda
   diez segundos se lee como que el botón no anduvo. */
.zofi-chat-typing {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    padding: 4px 2px;
}
.zofi-chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--zofi-muted);
    animation: zofi-chat-blink 1.2s infinite ease-in-out both;
}
.zofi-chat-typing span:nth-child(2) { animation-delay: .18s; }
.zofi-chat-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes zofi-chat-blink {
    0%, 80%, 100% { opacity: .25; }
    40%           { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
    .zofi-chat-typing span { animation: none; opacity: .6; }
}

/* ── Tablas que se vuelven tarjetas en mobile ──────────────────────────────
   Se opta por clase (.zofi-table-cards), NUNCA con un selector `table`
   global: las grillas de formset de los conectores (api_edit, sheets_edit)
   tienen que seguir siendo tablas con scroll horizontal, porque su JS clona
   filas y el layout de fila es parte del contrato.

   `data-label` en cada <td> repite el texto de su <th>: es lo que se ve como
   etiqueta cuando el encabezado desaparece. Si cambia uno, cambia el otro. */
@media (max-width: 767.98px) {
    .zofi-table-cards,
    .zofi-table-cards tbody,
    .zofi-table-cards tr,
    .zofi-table-cards td { display: block; width: 100%; }

    .zofi-table-cards thead,
    .zofi-table-cards tfoot { display: none; }

    .zofi-table-cards tr {
        border: 1px solid var(--zofi-border);
        border-radius: 12px;
        background: var(--zofi-bg-card);
        margin-bottom: .75rem;
        overflow: hidden;
    }
    .zofi-table-cards tr:last-child { margin-bottom: 0; }

    /* etiqueta a la izquierda, valor a la derecha */
    .zofi-table-cards td {
        display: grid;
        grid-template-columns: minmax(0, 32%) minmax(0, 1fr);
        gap: .35rem .75rem;
        align-items: start;
        justify-items: start;   /* un badge no se estira a todo el ancho */
        border: 0;
        border-bottom: 1px solid var(--zofi-border-soft);
        padding: .55rem .9rem !important;   /* gana a los px-4/py-3 inline */
        text-align: left !important;
    }
    .zofi-table-cards td:last-child { border-bottom: 0; }

    /* La etiqueta ocupa la columna 1 entera y TODO hijo del <td> va a la 2.
       Sin esto, una celda con más de un elemento (los badges de asistentes)
       reparte sus hijos como ítems sueltos y se escapan bajo la etiqueta. */
    .zofi-table-cards td::before {
        grid-column: 1;
        grid-row: 1 / -1;
        content: attr(data-label);
        font-size: .72rem;
        text-transform: uppercase;
        letter-spacing: .04em;
        color: var(--zofi-muted);
        line-height: 1.5;
    }

    .zofi-table-cards td > * { grid-column: 2; }

    /* la celda de acciones no lleva etiqueta y ocupa el ancho completo */
    .zofi-table-cards td.zofi-tc-actions {
        display: block;
        /* `justify-items` ya aplica en layout de bloque (Chrome): sin esto,
           el start de arriba se hereda acá y encoge la fila de botones. */
        justify-items: stretch;
        padding-top: .7rem !important;
    }
    .zofi-table-cards td.zofi-tc-actions::before { content: none; }
    .zofi-table-cards .zofi-tc-actions > .d-flex {
        flex-wrap: wrap;
        justify-content: stretch !important;
    }
    .zofi-table-cards .zofi-tc-actions form { flex: 1 1 auto; margin: 0; }
    .zofi-table-cards .zofi-tc-actions .btn {
        min-height: 44px;   /* objetivo tocable */
        width: 100%;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    /* lo destructivo va en su propia línea: no puede quedar pegado a Pausar */
    .zofi-table-cards .zofi-tc-actions form.zofi-tc-danger { flex: 1 0 100%; }

    /* nada de nowrap adentro de una tarjeta angosta */
    .zofi-table-cards td,
    .zofi-table-cards td * { white-space: normal !important; }
    .zofi-table-cards td code { word-break: break-all; }

    /* el contenedor ya no recorta nada, y no queremos tarjeta dentro de tarjeta */
    .zofi-card.zofi-table-cards-wrap {
        overflow: visible !important;
        border: 0 !important;
        background: transparent;
        border-radius: 0;
    }
    .zofi-table-cards-wrap .table-responsive { overflow: visible !important; }
    .zofi-table-cards { min-width: 0 !important; }
}

/* ── El chat de soporte con Zofi (dashboard/_soporte_widget.html) ──────────
   Un globo fijo abajo a la derecha y un panel encima. z-index por debajo del
   banner de cookies (9999), que se acepta una vez y desaparece, y por debajo
   del offcanvas del menú (1045) para no taparlo en el celular. */
.soporte-globo {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1030;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 0;
    background: var(--zofi-grad);
    color: #fff;
    font-size: 1.5rem;
    box-shadow: 0 6px 20px rgba(0, 120, 158, .35);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .15s ease;
}
.soporte-globo:hover { transform: scale(1.06); }
.soporte-globo.abierto { transform: scale(.9); opacity: .85; }
.soporte-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: #ef4444;
    color: #fff;
    font-size: .7rem;
    font-weight: 700;
    line-height: 20px;
    border: 2px solid #fff;
}
.soporte-panel {
    position: fixed;
    right: 20px;
    bottom: 88px;
    z-index: 1030;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 540px;
    max-height: calc(100vh - 110px);
    display: flex;
    flex-direction: column;
    background: var(--zofi-bg-card, #fff);
    border: 1px solid var(--zofi-border);
    border-radius: 16px;
    box-shadow: 0 16px 48px rgba(15, 23, 42, .22);
    overflow: hidden;
}
.soporte-panel.d-none { display: none !important; }
.soporte-cabecera {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .7rem .9rem;
    background: var(--zofi-grad);
    color: #fff;
}
.soporte-cabecera .btn-light { --bs-btn-padding-y: .2rem; --bs-btn-padding-x: .5rem; font-size: .8rem; }
.soporte-modo { font-size: .75rem; opacity: .9; }
.soporte-panel.manual .soporte-cabecera { background: linear-gradient(135deg, #b45309, #f59e0b); }
.soporte-mensajes {
    background: #f0f2f5;
    min-height: 0;
}
.soporte-vacio { color: var(--zofi-muted); }
.soporte-anteriores { text-align: center; }
.soporte-anteriores .btn-link { font-size: .78rem; }
.soporte-sistema {
    align-self: center;
    max-width: 90%;
    text-align: center;
    font-size: .76rem;
    color: #475569;
    background: #e2e8f0;
    border-radius: 10px;
    padding: 4px 10px;
}
.soporte-compositor {
    padding: .5rem;
    border-top: 1px solid var(--zofi-border);
    background: var(--zofi-bg-card, #fff);
}
.soporte-nota { color: var(--zofi-muted); font-size: .7rem; }
.soporte-error {
    background: #fef2f2;
    border-bottom: 1px solid #fecaca;
    color: #991b1b;
    font-size: .8rem;
}
.soporte-panel .wa-texto { white-space: pre-wrap; }
.soporte-panel .wa-hora {
    display: block;
    font-size: .68rem;
    opacity: .7;
    margin-top: 3px;
    text-align: right;
}
.soporte-panel .wa-autor { font-size: .75rem; font-weight: 600; color: var(--zofi-teal); margin-bottom: 1px; }
.soporte-panel .zofi-chat-bubble.humano { border-color: #f59e0b; }
.soporte-panel .zofi-chat-bubble.humano .wa-autor { color: #b45309; }
.soporte-panel .zofi-chat-bubble.pendiente { opacity: .55; }
.soporte-panel .zofi-chat-wrap { max-width: 85%; }

/* El saludo al ingresar: un globito arriba del botón, no un modal. */
.soporte-saludo {
    position: fixed;
    right: 20px;
    bottom: 88px;
    z-index: 1030;
    width: 280px;
    max-width: calc(100vw - 40px);
    background: var(--zofi-bg-card, #fff);
    border: 1px solid var(--zofi-border);
    border-radius: 14px 14px 4px 14px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .18);
    animation: soporte-saludo-entra .25s ease-out;
}
.soporte-saludo.d-none { display: none !important; }
.soporte-saludo::after {
    content: '';
    position: absolute;
    right: 22px;
    bottom: -7px;
    width: 12px;
    height: 12px;
    background: inherit;
    border-right: 1px solid var(--zofi-border);
    border-bottom: 1px solid var(--zofi-border);
    transform: rotate(45deg);
}
.soporte-saludo-cuerpo {
    display: block;
    width: 100%;
    border: 0;
    background: transparent;
    text-align: left;
    padding: .8rem 2rem .8rem .9rem;
    font-size: .84rem;
    line-height: 1.45;
    color: var(--zofi-text);
}
.soporte-saludo-cuerpo strong { display: block; margin-bottom: 2px; color: var(--zofi-teal); }
.soporte-saludo-cerrar {
    position: absolute;
    top: 4px;
    right: 4px;
    border: 0;
    background: transparent;
    color: var(--zofi-muted);
    font-size: 1.1rem;
    line-height: 1;
    padding: 4px;
}
@keyframes soporte-saludo-entra {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}

/* «Hablar con una persona» debajo de la respuesta del bot que no pudo. */
.soporte-ofrece {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
    margin-top: 4px;
    font-size: .78rem;
    color: #475569;
}
.soporte-ofrece.d-none { display: none !important; }
.soporte-ofrece .btn { --bs-btn-padding-y: .15rem; --bs-btn-padding-x: .5rem; font-size: .78rem; background: #fff; }

/* Las caritas al final de una consulta. */
.soporte-calif {
    align-self: center;
    width: 92%;
    background: #fff;
    border: 1px solid var(--zofi-border);
    border-radius: 12px;
    padding: .7rem .8rem;
    text-align: center;
}
.soporte-calif-titulo { font-size: .84rem; font-weight: 600; color: var(--zofi-text); margin-bottom: .4rem; }
.soporte-caritas { display: flex; justify-content: center; gap: .75rem; }
.soporte-caritas button {
    border: 1px solid var(--zofi-border);
    background: #f8fafc;
    border-radius: 50%;
    width: 46px;
    height: 46px;
    font-size: 1.5rem;
    line-height: 1;
    color: #64748b;
    transition: transform .12s ease, color .12s ease, border-color .12s ease;
}
.soporte-caritas button:hover:not(:disabled) { transform: scale(1.1); }
.soporte-caritas [data-valor="feliz"]:hover  { color: #16a34a; border-color: #16a34a; }
.soporte-caritas [data-valor="neutra"]:hover { color: #ca8a04; border-color: #ca8a04; }
.soporte-caritas [data-valor="triste"]:hover { color: #dc2626; border-color: #dc2626; }
.soporte-calif-omitir { font-size: .74rem; color: var(--zofi-muted); margin-top: .2rem; }
.soporte-calif textarea { font-size: .82rem; resize: none; }
.soporte-calif .btn-sm { font-size: .78rem; }
@media (max-width: 576px) {
    .soporte-panel {
        right: 0;
        bottom: 0;
        width: 100vw;
        max-width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
    .soporte-panel:not(.d-none) ~ .soporte-globo,
    .soporte-globo.abierto { display: none; }
}
