/* =========================================================
   Sistema visual común del panel (estilo WhatsApp Business).
   Lo cargan todas las páginas de admin/ ANTES de su CSS propio.

   - Tokens de color con tema claro y oscuro. El oscuro sigue al
     sistema salvo que el usuario elija uno con el botón
     (theme.js escribe data-theme en <html>).
   - Los nombres heredados (--red, --red-dark, --ink…) se
     conservan como alias: los usan estilos en línea y HTML que
     arma el JS, y renombrarlos rompería esas pantallas.
   ========================================================= */

:root {
    color-scheme: light;

    --accent:        #00a884;
    --accent-strong: #008069;
    --accent-ink:    #ffffff;
    --accent-soft:   #e7f8f2;
    --accent-ring:   rgba(0, 168, 132, .22);
    --brand-deep:    #075e54;
    /* Nombre del sistema «LagoBot»: un tono más profundo en el tema
       claro para que se lea sobre blanco. */
    --brand-lago:    #0284c7;
    --brand-bot:     #16a34a;

    --ink:      #111b21;
    --ink-2:    #3b4a54;
    --muted:    #667781;
    --line:     #e5e9eb;
    --line-2:   #d1d7db;
    --bg:       #f0f2f5;
    --card:     #ffffff;
    --surface:  #f7f9fa;
    --hover:    #f2f5f6;

    --ok:        #0b8a5f;  --ok-soft:   #e3f6ec;
    --warn:      #9a6a00;  --warn-soft: #fff4d6;
    --danger:    #d93a3a;  --danger-soft: #fdeceb;
    --info:      #1f6fd1;  --info-soft: #e8f1fd;
    --violet:    #6b46d4;  --violet-soft: #efeafd;
    --pink:      #b0279f;  --pink-soft: #fbe9f8;
    --slate:     #4a5560;  --slate-soft: #edf0f2;

    --bubble-me:   #d9fdd3;
    --bubble-bot:  #ffffff;
    --chat-bg:     #efeae2;
    --chat-dot:    rgba(17, 27, 33, .06);

    --radius:    16px;
    --radius-sm: 11px;
    --shadow:    0 1px 2px rgba(17, 27, 33, .05), 0 6px 20px rgba(17, 27, 33, .05);
    --shadow-lg: 0 2px 6px rgba(17, 27, 33, .06), 0 24px 60px rgba(17, 27, 33, .14);

    --ease:      cubic-bezier(.2, .8, .2, 1);
    --ease-out:  cubic-bezier(.16, 1, .3, 1);
    --font: "Inter", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;
    --mono: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;

    /* Alias heredados */
    --red:      var(--accent);
    --red-dark: var(--accent-strong);
    --red-soft: var(--accent-soft);
    --yellow:   #ffd279;
}

/* Tema oscuro: definido dos veces a propósito (preferencia del sistema
   cuando no hay elección manual, y elección manual explícita). */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --accent:        #00a884;
        --accent-strong: #21c094;
        --accent-ink:    #04140f;
        --accent-soft:   rgba(0, 168, 132, .14);
        --accent-ring:   rgba(0, 168, 132, .32);
        --brand-deep:    #0b3d36;
        --brand-lago:    #0ea5e9;
        --brand-bot:     #25d366;
        --ink:      #e9edef;
        --ink-2:    #c3cdd2;
        --muted:    #8696a0;
        --line:     #233138;
        --line-2:   #32444d;
        --bg:       #0b141a;
        --card:     #111b21;
        --surface:  #17232a;
        --hover:    #1c2a32;
        --ok:        #3ccf8e;  --ok-soft:   rgba(60, 207, 142, .13);
        --warn:      #f2c14e;  --warn-soft: rgba(242, 193, 78, .13);
        --danger:    #ff6b6b;  --danger-soft: rgba(255, 107, 107, .13);
        --info:      #6aa8ff;  --info-soft: rgba(106, 168, 255, .13);
        --violet:    #a98bff;  --violet-soft: rgba(169, 139, 255, .14);
        --pink:      #f17ce3;  --pink-soft: rgba(241, 124, 227, .13);
        --slate:     #9aa8b2;  --slate-soft: rgba(154, 168, 178, .12);
        --bubble-me:  #005c4b;
        --bubble-bot: #202c33;
        --chat-bg:    #0b141a;
        --chat-dot:   rgba(233, 237, 239, .045);
        --shadow:    0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
        --shadow-lg: 0 2px 8px rgba(0, 0, 0, .35), 0 28px 70px rgba(0, 0, 0, .5);
    }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --accent:        #00a884;
    --accent-strong: #21c094;
    --accent-ink:    #04140f;
    --accent-soft:   rgba(0, 168, 132, .14);
    --accent-ring:   rgba(0, 168, 132, .32);
    --brand-deep:    #0b3d36;
    --brand-lago:    #0ea5e9;
    --brand-bot:     #25d366;
    --ink:      #e9edef;
    --ink-2:    #c3cdd2;
    --muted:    #8696a0;
    --line:     #233138;
    --line-2:   #32444d;
    --bg:       #0b141a;
    --card:     #111b21;
    --surface:  #17232a;
    --hover:    #1c2a32;
    --ok:        #3ccf8e;  --ok-soft:   rgba(60, 207, 142, .13);
    --warn:      #f2c14e;  --warn-soft: rgba(242, 193, 78, .13);
    --danger:    #ff6b6b;  --danger-soft: rgba(255, 107, 107, .13);
    --info:      #6aa8ff;  --info-soft: rgba(106, 168, 255, .13);
    --violet:    #a98bff;  --violet-soft: rgba(169, 139, 255, .14);
    --pink:      #f17ce3;  --pink-soft: rgba(241, 124, 227, .13);
    --slate:     #9aa8b2;  --slate-soft: rgba(154, 168, 178, .12);
    --bubble-me:  #005c4b;
    --bubble-bot: #202c33;
    --chat-bg:    #0b141a;
    --chat-dot:   rgba(233, 237, 239, .045);
    --shadow:    0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --shadow-lg: 0 2px 8px rgba(0, 0, 0, .35), 0 28px 70px rgba(0, 0, 0, .5);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    font-family: var(--font);
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    font-feature-settings: "cv11", "ss01";
}
/* El cambio de tema se anima; theme.js pone la clase solo al hacer clic,
   para que la carga inicial no "parpadee" de un tema a otro. */
html.theme-anim, html.theme-anim *, html.theme-anim *::before, html.theme-anim *::after {
    transition: background-color .35s var(--ease), border-color .35s var(--ease), color .25s var(--ease) !important;
}

a { color: inherit; text-decoration: none; }
code {
    font-family: var(--mono);
    font-size: .86em;
    background: var(--surface);
    border: 1px solid var(--line);
    padding: 1px 5px;
    border-radius: 6px;
}
::selection { background: var(--accent-ring); }

/* Barras de desplazamiento discretas */
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Botón de tema ---------- */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--ink-2);
    font-family: inherit;
    font-size: .8rem;
    font-weight: 600;
    padding: 7px 11px;
    border-radius: 999px;
    cursor: pointer;
    transition: border-color .2s var(--ease), background .2s var(--ease), transform .15s var(--ease);
}
.theme-toggle:hover { border-color: var(--line-2); background: var(--hover); }
.theme-toggle:active { transform: scale(.96); }
.theme-toggle .tt-ico { display: inline-block; transition: transform .45s var(--ease-out); }
.theme-toggle:hover .tt-ico { transform: rotate(-20deg) scale(1.1); }

/* ---------- Animaciones compartidas ---------- */
@keyframes fade-up {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: none; }
}
@keyframes fade-in   { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in {
    from { opacity: 0; transform: translateY(6px) scale(.96); }
    to   { opacity: 1; transform: none; }
}
@keyframes slide-in-right {
    from { opacity: .4; transform: translateX(40px); }
    to   { opacity: 1; transform: none; }
}
@keyframes toast-in {
    from { opacity: 0; transform: translate(-50%, 14px) scale(.97); }
    to   { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes shimmer {
    from { background-position: -400px 0; }
    to   { background-position: 400px 0; }
}
@keyframes pulse-dot {
    0%   { box-shadow: 0 0 0 0 rgba(37, 211, 102, .55); }
    70%  { box-shadow: 0 0 0 9px rgba(37, 211, 102, 0); }
    100% { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0); }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Entrada escalonada: el contenedor marca a sus hijos directos. */
.stagger > * { animation: fade-up .55s var(--ease-out) both; }
.stagger > *:nth-child(1) { animation-delay: .02s; }
.stagger > *:nth-child(2) { animation-delay: .07s; }
.stagger > *:nth-child(3) { animation-delay: .12s; }
.stagger > *:nth-child(4) { animation-delay: .17s; }
.stagger > *:nth-child(5) { animation-delay: .22s; }
.stagger > *:nth-child(6) { animation-delay: .27s; }
.stagger > *:nth-child(n+7) { animation-delay: .32s; }

/* Esqueleto de carga */
.skeleton {
    display: block;
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg, var(--surface) 0%, var(--hover) 40%, var(--surface) 80%);
    background-size: 800px 100%;
    animation: shimmer 1.3s linear infinite;
}

/* ---------- Pantallas de acceso (login / setup) ---------- */
.auth {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px 16px;
    background:
        radial-gradient(900px 500px at 85% -10%, rgba(37, 211, 102, .22), transparent 60%),
        radial-gradient(700px 500px at -10% 110%, rgba(0, 168, 132, .18), transparent 60%),
        var(--bg);
    position: relative;
}
.auth-theme { position: absolute; top: 18px; right: 18px; }
.auth-card {
    width: min(380px, 100%);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: 34px 30px 30px;
    box-shadow: var(--shadow-lg);
    animation: pop-in .6s var(--ease-out) both;
}
.auth-logo {
    width: 54px; height: 54px;
    border-radius: 16px;
    display: grid; place-items: center;
    font-size: 1.5rem;
    margin-bottom: 18px;
    background: linear-gradient(135deg, #25d366, var(--accent-strong));
    box-shadow: 0 10px 24px rgba(0, 168, 132, .35);
}
.auth-card h1 { font-size: 1.3rem; margin: 0 0 4px; letter-spacing: -.01em; }
.auth-sub { font-size: .87rem; color: var(--muted); margin: 0 0 24px; }
.auth-card label { font-size: .8rem; font-weight: 600; color: var(--ink-2); display: block; margin-bottom: 6px; }
.auth-card input {
    width: 100%;
    padding: 12px 14px;
    margin-bottom: 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    font-size: .92rem;
    font-family: inherit;
    transition: border-color .2s var(--ease), box-shadow .2s var(--ease), background .2s var(--ease);
}
.auth-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); background: var(--card); }
.auth-card button[type=submit] {
    width: 100%;
    padding: 13px;
    margin-top: 4px;
    border: 0;
    border-radius: 12px;
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 700;
    font-size: .95rem;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(0, 168, 132, .3);
    transition: transform .15s var(--ease), box-shadow .2s var(--ease), filter .2s var(--ease);
}
.auth-card button[type=submit]:hover { transform: translateY(-1px); filter: brightness(1.05); box-shadow: 0 14px 30px rgba(0, 168, 132, .38); }
.auth-card button[type=submit]:active { transform: translateY(0) scale(.99); }
.auth-error {
    color: var(--danger);
    background: var(--danger-soft);
    font-size: .85rem;
    padding: 10px 12px;
    border-radius: 10px;
    margin-bottom: 16px;
    animation: fade-up .35s var(--ease-out) both;
}
.auth-note { font-size: .88rem; color: var(--ink-2); line-height: 1.55; margin: 0; }
.auth-note a { color: var(--accent-strong); font-weight: 600; }

/* ---------- Login dividido: presentación a la izquierda, acceso a la derecha ---------- */
.auth-split {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(400px, 1fr);
}
.auth-side { min-height: 100vh; }

/* La presentación es siempre oscura (color de marca), en ambos temas */
.auth-aside {
    position: relative;
    overflow: hidden;
    isolation: isolate;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 34px;
    padding: 40px 56px 44px;
    color: #fff;
    background:
        radial-gradient(rgba(255, 255, 255, .07) 1px, transparent 1px) 0 0 / 20px 20px,
        linear-gradient(150deg, #075e54 0%, #054a43 45%, #02231f 100%);
}
.aa-orb {
    position: absolute;
    z-index: -1;
    border-radius: 50%;
    filter: blur(60px);
    opacity: .55;
    animation: aa-drift 14s ease-in-out infinite alternate;
}
.aa-orb-1 { width: 420px; height: 420px; background: #25d366; top: -140px; right: -120px; }
.aa-orb-2 { width: 340px; height: 340px; background: #00a884; bottom: -120px; left: -100px; animation-delay: -5s; }
.aa-orb-3 { width: 220px; height: 220px; background: #53bdeb; top: 45%; left: 55%; opacity: .25; animation-delay: -9s; }
@keyframes aa-drift {
    from { transform: translate(0, 0) scale(1); }
    to   { transform: translate(40px, 30px) scale(1.12); }
}

/* Nombre del sistema: <b class="lb-name"><span class="lb-lago">Lago</span><span class="lb-bot">Bot</span></b> */
.lb-name { font-weight: 800; letter-spacing: -.02em; }
/* Dos clases para ganarle a `.brand-text span` (admin.css, gris y chico),
   que carga después y a igual especificidad ganaría. */
.lb-name .lb-lago,
.lb-name .lb-bot  { font-size: inherit; }
.lb-name .lb-lago { color: var(--brand-lago); }
.lb-name .lb-bot  { color: var(--brand-bot); }
/* El login va sobre fondo verde oscuro en cualquier tema: tonos claros
   para que «Bot» no se funda con el fondo. */
.aa-brand .lb-name .lb-lago { color: #38bdf8; }
.aa-brand .lb-name .lb-bot  { color: #86efac; }

.aa-brand { display: flex; align-items: center; gap: 12px; animation: fade-up .6s var(--ease-out) both; }
.aa-brand b { display: block; font-size: 1.05rem; }
.aa-brand small { color: rgba(255, 255, 255, .65); font-size: .78rem; }
.aa-logo {
    width: 44px; height: 44px;
    border-radius: 14px;
    display: grid; place-items: center;
    font-size: 1.3rem;
    background: rgba(255, 255, 255, .12);
    border: 1px solid rgba(255, 255, 255, .2);
    backdrop-filter: blur(8px);
}

.aa-hero { max-width: 520px; animation: fade-up .7s var(--ease-out) .1s both; }
.aa-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .1);
    border: 1px solid rgba(255, 255, 255, .18);
    color: #d8fff0;
}
.aa-badge .dot { width: 7px; height: 7px; border-radius: 50%; background: #25d366; animation: pulse-dot 2.2s infinite; }
.aa-hero h2 {
    font-size: clamp(1.9rem, 3.2vw, 2.8rem);
    line-height: 1.1;
    letter-spacing: -.03em;
    margin: 18px 0 14px;
}
.aa-hero h2 em {
    font-style: normal;
    background: linear-gradient(90deg, #25d366, #8af5c0, #25d366);
    background-size: 200% auto;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: aa-shine 5s linear infinite;
}
@keyframes aa-shine { to { background-position: 200% center; } }
.aa-hero p { color: rgba(255, 255, 255, .75); line-height: 1.6; margin: 0; font-size: .98rem; }

/* Teléfono de muestra */
.aa-phone {
    width: min(360px, 100%);
    border-radius: 26px;
    overflow: hidden;
    background: #0b141a;
    border: 1px solid rgba(255, 255, 255, .14);
    box-shadow: 0 30px 70px rgba(0, 0, 0, .45), 0 0 0 8px rgba(255, 255, 255, .04);
    animation: fade-up .8s var(--ease-out) .2s both, aa-float 7s ease-in-out 1s infinite;
}
@keyframes aa-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
.aa-phone-top {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: #202c33;
}
.aa-phone-top b { display: block; font-size: .88rem; }
.aa-phone-top small { color: #25d366; font-size: .72rem; }
.aa-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    display: grid; place-items: center;
    background: linear-gradient(135deg, #25d366, #00a884);
}
.aa-chat {
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-height: 250px;
    padding: 16px 14px;
    background: radial-gradient(rgba(233, 237, 239, .05) 1px, transparent 1px) 0 0 / 16px 16px, #0b141a;
}
.aa-msg, .aa-opts, .aa-typing { animation: pop-in .4s var(--ease-out) var(--d, 0s) both; }
.aa-msg {
    max-width: 82%;
    padding: 7px 11px;
    border-radius: 10px;
    font-size: .84rem;
    line-height: 1.4;
}
.aa-msg.bot { align-self: flex-start; background: #202c33; border-top-left-radius: 3px; transform-origin: bottom left; }
.aa-msg.me  { align-self: flex-end; background: #005c4b; border-top-right-radius: 3px; transform-origin: bottom right; }
.aa-opts { display: flex; flex-wrap: wrap; gap: 5px; }
.aa-opts span {
    font-size: .76rem;
    color: #53bdeb;
    background: #202c33;
    padding: 6px 10px;
    border-radius: 8px;
}
.aa-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 10px 12px;
    background: #202c33;
    border-radius: 10px;
    border-top-left-radius: 3px;
}
.aa-typing i {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #8696a0;
    animation: aa-dot 1.2s ease-in-out infinite;
}
.aa-typing i:nth-child(2) { animation-delay: .15s; }
.aa-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes aa-dot {
    0%, 60%, 100% { transform: translateY(0); opacity: .5; }
    30%           { transform: translateY(-4px); opacity: 1; }
}

.aa-features { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 10px; }
.aa-features li {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: .84rem;
    font-weight: 600;
    padding: 9px 14px;
    border-radius: 12px;
    background: rgba(255, 255, 255, .08);
    border: 1px solid rgba(255, 255, 255, .14);
    backdrop-filter: blur(8px);
    animation: fade-up .5s var(--ease-out) var(--d, 0s) both;
    transition: background .25s var(--ease), transform .25s var(--ease-out);
}
.aa-features li:hover { background: rgba(255, 255, 255, .14); transform: translateY(-2px); }

.auth-foot { margin: 18px 0 0; text-align: center; font-size: .78rem; color: var(--muted); }

/* Pantallas medianas: sin teléfono; pequeñas: solo el formulario */
@media (max-height: 760px), (max-width: 1100px) { .aa-phone { display: none; } }
@media (max-width: 860px) {
    .auth-split { grid-template-columns: 1fr; }
    .auth-aside { display: none; }
}

/* ---------- Simuladores: archivo enviado y «escribiendo…» (chat-preview.js) ---------- */
.cp-media {
    display: block;
    max-width: 100%;
    border-radius: 8px;
    margin: -2px -4px 6px;
    width: calc(100% + 8px);
    background: var(--surface);
}
.cp-image { max-height: 220px; object-fit: cover; }
.cp-audio { height: 40px; }
.cp-file {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: -2px -4px 6px;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    text-decoration: none;
    min-width: 200px;
    transition: background .2s var(--ease);
}
.cp-file[href]:hover { background: var(--hover); }
.cp-file-ico { font-size: 1.5rem; line-height: 1; }
.cp-file-name { font-size: .82rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Sin pie de foto la burbuja queda solo con el archivo */
.cp-only > .cp-media, .cp-only > .cp-file { margin-bottom: -2px; }

.cp-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 11px 13px;
    background: var(--bubble-bot);
    border-radius: 12px;
    border-top-left-radius: 4px;
    box-shadow: 0 1px .5px rgba(11, 20, 26, .13);
    animation: pop-in .25s var(--ease-out) both;
}
.cp-typing i {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--muted);
    animation: cp-dot 1.2s ease-in-out infinite;
}
.cp-typing i:nth-child(2) { animation-delay: .15s; }
.cp-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes cp-dot {
    0%, 60%, 100% { transform: translateY(0); opacity: .45; }
    30%           { transform: translateY(-4px); opacity: 1; }
}

/* ---------- Accesibilidad: movimiento reducido ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        animation-delay: 0s !important;
        transition-duration: .001ms !important;
        scroll-behavior: auto !important;
    }
}
