/* ASTROLOG-IA — Área de Miembros */
:root {
    --primary: #6a0dad;
    --accent:  #ffd700;
    --bg:      #1a1a2e;
    --card:    #16213e;
    --text:    #ffffff;
    --muted:   #ccc;
    --blue:    #4fc3f7;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Poppins', sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100dvh;
    overflow: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { opacity: .8; }

/* ── Estrellas (igual que frontend) ──────────────────────── */
#star-container {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.star {
    position: absolute;
    background: white;
    border-radius: 50%;
    opacity: 0;
    animation: twinkle infinite ease-in-out;
    box-shadow: 0 0 2px rgba(255,255,255,.8);
}

@keyframes twinkle {
    0%, 100% { opacity: .2; transform: scale(.8); }
    50%       { opacity: 1;  transform: scale(1.2); box-shadow: 0 0 4px rgba(255,255,255,1); }
}

/* ── Portal: layout principal ────────────────────────────── */
.portal {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 760px;
    margin: 0 auto;
}

/* ── Header ──────────────────────────────────────────────── */
.portal-header {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 16px 21px;
    border-bottom: 1px solid rgba(255,215,0,.1);
    background: rgba(26,26,46,.85);
    backdrop-filter: blur(12px);
    gap: 8px;
}

.portal-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
}

.portal-actions {
    display: flex;
    gap: 6px;
    justify-content: center;
    flex-wrap: wrap;
}

.btn-action {
    padding: 5px 12px;
    border-radius: 6px;
    font-size: .75rem;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: background .2s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn-download {
    color: #ffd700;
    border: 1px solid rgba(255,215,0,.5);
    background: rgba(255,215,0,.07);
}
.btn-download:hover  { background: rgba(255,215,0,.16); }
.btn-download:active { background: rgba(255,215,0,.26); }

.btn-delete {
    color: #ff3333;
    border: 1px solid rgba(255,40,40,.55);
    background: rgba(255,40,40,.07);
}
.btn-delete:hover  { background: rgba(255,40,40,.16); }
.btn-delete:active { background: rgba(255,40,40,.28); }

.btn-cuenta {
    color: #22c55e;
    border: 1px solid rgba(34,197,94,.5);
    background: rgba(34,197,94,.07);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}
.btn-cuenta:hover  { background: rgba(34,197,94,.16); opacity: 1; }
.btn-cuenta:active { background: rgba(34,197,94,.26); }

.btn-cerrar {
    color: #4fc3f7;
    border: 1px solid rgba(79,195,247,.5);
    background: rgba(79,195,247,.07);
}
.btn-cerrar:hover  { background: rgba(79,195,247,.16); }
.btn-cerrar:active { background: rgba(79,195,247,.26); }
.btn-cerrar:disabled { opacity: .4; cursor: default; }

.portal-title {
    font-family: 'Poppins', sans-serif;
    font-size: 2.6rem;
    font-weight: 700;
    letter-spacing: 4px;
    color: #4fc3f7;
    -webkit-text-stroke: 1px rgba(255,255,255,.85);
    text-shadow:
        0 0 6px rgba(79,195,247,.6),
        0 0 20px rgba(79,195,247,.35);
    white-space: nowrap;
    line-height: 1;
}

.portal-subtitle {
    font-size: .92rem;
    color: #ffffff;
    opacity: .85;
    letter-spacing: .5px;
    margin-top: 3px;
}

.btn-logout {
    padding: 5px 12px;
    border-radius: 6px;
    font-size: .78rem;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    color: rgba(255,153,153,.8);
    border: 1px solid rgba(255,80,80,.2);
    background: transparent;
    transition: background .2s;
    flex-shrink: 0;
}
.btn-logout:hover { background: rgba(255,80,80,.1); opacity: 1; }

/* ── Mensajes ─────────────────────────────────────────────── */
.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: .75rem;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.chat-messages::-webkit-scrollbar { width: 3px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,.55); border-radius: 4px; }

.msg {
    display: flex;
    flex-direction: column;
    max-width: calc(78% + 15px);
    gap: .2rem;
}

.msg.user      { align-self: flex-end;   align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; max-width: calc(78% + 20px); }

.msg-bubble {
    padding: .7rem 1rem;
    border-radius: 14px;
    font-size: .98rem;
    line-height: 1.65;
    word-break: break-word;
    white-space: pre-wrap;
}

/* Markdown renderizado en burbujas del asistente */
.msg.assistant .msg-bubble {
    white-space: normal;
    max-height: 260px;
    overflow: hidden;
    position: relative;
    transition: max-height .3s ease;
}
.msg.assistant .msg-bubble.expanded {
    max-height: none;
    overflow: visible;
}

/* Fade gradient + botón expandir */
.bubble-fade {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 64px;
    background: linear-gradient(transparent, rgba(22,33,62,.97));
    pointer-events: none;
    border-radius: 0 0 14px 14px;
}
.bubble-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-self: flex-start;
    margin-top: 3px;
}

.btn-expand {
    padding: 5px 12px;
    background: #0f172a;
    border: 1px solid rgba(79,195,247,.35);
    border-radius: 6px;
    color: var(--blue);
    font-size: .85rem;
    font-family: inherit;
    cursor: pointer;
    touch-action: manipulation;
    transition: background .2s;
    white-space: nowrap;
}
.btn-expand:hover { background: #1e2d4a; }

.btn-whatsapp {
    display: none;
    padding: 5px 12px;
    background: #0a1f12;
    border: 1px solid rgba(37,211,102,.4);
    border-radius: 6px;
    color: #25d366;
    font-size: .85rem;
    font-family: inherit;
    cursor: pointer;
    touch-action: manipulation;
    transition: background .2s;
    white-space: nowrap;
}
.btn-whatsapp:hover { background: #112b18; }

@media (max-width: 640px) {
    .btn-whatsapp { display: inline-flex; align-items: center; }
}
.msg.assistant .msg-bubble p  { margin: 0 0 .5rem; }
.msg.assistant .msg-bubble p:last-child { margin-bottom: 0; }
.msg.assistant .msg-bubble strong { color: var(--accent); font-weight: 600; }
.msg.assistant .msg-bubble em     { color: #b0c4de; font-style: italic; }
.msg.assistant .msg-bubble h1,
.msg.assistant .msg-bubble h2,
.msg.assistant .msg-bubble h3 {
    font-family: 'Poppins', sans-serif;
    font-size: .92rem;
    font-weight: 600;
    color: var(--blue);
    margin: .7rem 0 .3rem;
}
.msg.assistant .msg-bubble ul,
.msg.assistant .msg-bubble ol {
    margin: .3rem 0 .5rem 1.2rem;
    padding: 0;
}
.msg.assistant .msg-bubble li { margin-bottom: .2rem; }
.msg.assistant .msg-bubble a {
    color: var(--blue);
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-all;
}
.msg.assistant .msg-bubble a:hover { color: var(--accent); }
.msg.assistant .msg-bubble code {
    background: rgba(255,255,255,.08);
    border-radius: 4px;
    padding: .1rem .35rem;
    font-size: .82rem;
    font-family: monospace;
}
.msg.assistant .msg-bubble pre {
    background: rgba(0,0,0,.35);
    border-radius: 8px;
    padding: .7rem 1rem;
    overflow-x: auto;
    margin: .5rem 0;
}
.msg.assistant .msg-bubble pre code {
    background: none;
    padding: 0;
    font-size: .82rem;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Botón SALIR que aparece bajo la burbuja de despedida */
.btn-salir-chat {
    padding: 7px 28px;
    background: #1a0a0e;
    border: 1px solid rgba(255,105,135,.45);
    border-radius: 6px;
    color: #ffb3c1;
    font-family: inherit;
    font-size: .9rem;
    font-weight: 700;
    letter-spacing: .5px;
    cursor: pointer;
    touch-action: manipulation;
    transition: background .2s;
    margin-top: 4px;
}
.btn-salir-chat:hover { background: #2a1018; }

/* Bloque de mensaje WhatsApp compartible (TERMINAR) */
.wa-share {
    cursor: pointer;
    transition: opacity .15s;
}
.wa-share:hover { opacity: .78; }

/* Enlace fallback "Copiar y compartir" generado por JS */
.wa-share-link {
    display: inline-block;
    margin: .5rem 0 .25rem;
    color: #25d366;
    text-decoration: underline;
    text-underline-offset: 2px;
    font-size: .84rem;
    cursor: pointer;
}
.wa-share-link:hover { opacity: .8; color: #25d366; }

.msg.user .msg-bubble {
    background: linear-gradient(135deg, #5a0aaa, #3a0070);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.msg.assistant .msg-bubble {
    background: #111827;
    border: 1px solid rgba(255,255,255,.25);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.msg-time {
    font-size: .78rem;
    color: var(--muted);
    opacity: .4;
    padding: 0 .3rem;
}

/* Typing indicator */
.typing-dots { display: inline-flex; gap: 4px; padding: .1rem .2rem; }
.typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
    animation: dot-bounce .9s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }

@keyframes dot-bounce {
    0%, 100% { transform: translateY(0); opacity: .4; }
    50%       { transform: translateY(-5px); opacity: 1; }
}

/* ── Input ───────────────────────────────────────────────── */
.chat-input-area {
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    border-top: 1px solid rgba(255,215,0,.1);
    padding: 10px 16px calc(14px + env(safe-area-inset-bottom));
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: rgba(26,26,46,.95);
    backdrop-filter: blur(12px);
    z-index: 10;
}

#chat-input {
    flex: 1;
    background: rgba(90,10,170,.12);
    border: 1px solid rgba(90,10,170,.55);
    border-radius: 14px;
    padding: 10px 14px;
    color: #fff;
    font-size: 16px; /* ≥16px evita zoom automático en iOS */
    font-family: inherit;
    resize: none;
    min-height: 44px;
    max-height: 120px;
    outline: none;
    line-height: 1.5;
    transition: border-color .2s, box-shadow .2s;
    touch-action: manipulation;
    -webkit-appearance: none;
}
#chat-input::placeholder { color: rgba(200,180,255,.35); }
#chat-input:focus {
    border-color: rgba(140,80,220,.8);
    box-shadow: 0 0 0 3px rgba(90,10,170,.18);
}

.btn-send {
    height: 44px;
    padding: 0 18px;
    border-radius: 14px;
    background: linear-gradient(135deg, #5a0aaa, #3a0070);
    border: 1px solid rgba(140,80,220,.5);
    color: #fff;
    font-family: inherit;
    font-size: .85rem;
    font-weight: 700;
    letter-spacing: .5px;
    cursor: pointer;
    flex-shrink: 0;
    white-space: nowrap;
    transition: opacity .2s, box-shadow .2s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.btn-send:hover:not(:disabled) {
    opacity: .88;
    box-shadow: 0 3px 14px rgba(90,10,170,.45);
}
.btn-send:disabled { opacity: .3; cursor: not-allowed; }

.chat-limit-msg {
    flex-shrink: 0;
    text-align: center;
    padding: 12px 16px 16px;
    font-size: .82rem;
    color: #fcd34d;
    background: rgba(245,158,11,.08);
    border-top: 1px solid rgba(245,158,11,.2);
}


/* ── Login page ──────────────────────────────────────────── */
.login-page {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100dvh;
    padding: 0 20px 40px;
    overflow-y: auto;
}

.login-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 32px;
    text-align: center;
}

.login-brand {
    font-family: 'Poppins', sans-serif;
    font-size: 2.8rem;
    font-weight: 700;
    letter-spacing: 4px;
    color: #4fc3f7;
    -webkit-text-stroke: 1px rgba(255,255,255,.85);
    text-shadow:
        0 0 6px rgba(79,195,247,1),
        0 0 18px rgba(79,195,247,.9),
        0 0 40px rgba(79,195,247,.7),
        0 0 80px rgba(79,195,247,.4);
    margin: 0 0 4px;
    line-height: 1;
}

.login-avatar {
    width: 200px;
    height: 200px;
    object-fit: contain;
    margin: 8px 0 4px;
    filter: drop-shadow(0 0 20px rgba(79,195,247,.35));
}

.login-tagline {
    font-family: 'Poppins', sans-serif;
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: #ffffff;
    margin: 4px 0 0;
    line-height: 1.2;
}

.login-sub {
    font-family: 'Caveat', cursive;
    font-size: 1.5rem;
    font-weight: 600;
    color: #ffffff;
    margin: 6px 0 0;
    font-style: normal;
}

.login-form-wrap {
    width: 100%;
    max-width: 400px;
    margin-top: 24px;
    background: rgba(22,33,62,.85);
    border: 1px solid rgba(255,215,0,.18);
    border-radius: 14px;
    padding: 1.8rem 1.6rem;
    backdrop-filter: blur(12px);
}

/* ── Auth shared (setup page uses these) ─────────────────── */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: 1.5rem;
    position: relative;
    z-index: 1;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: rgba(22,33,62,.95);
    border: 1px solid rgba(255,215,0,.18);
    border-radius: 14px;
    padding: 2.5rem 2rem;
    backdrop-filter: blur(10px);
}

.auth-logo { text-align: center; margin-bottom: 2rem; }
.auth-logo h1 {
    font-family: 'Poppins', sans-serif;
    font-size: 1.9rem;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--blue);
    text-shadow: 0 0 8px rgba(79,195,247,1), 0 0 20px rgba(79,195,247,.7);
    margin: 0;
}
.auth-logo p { font-size: .85rem; color: var(--muted); margin-top: .3rem; }

.auth-form { display: flex; flex-direction: column; gap: 1rem; }

.field { display: flex; flex-direction: column; gap: .4rem; }
.field label { font-size: .82rem; color: var(--muted); }

.field input {
    background: rgba(255,255,255,.05);
    border: 1px solid rgba(255,215,0,.2);
    border-radius: 6px;
    padding: 10px 14px;
    color: #fff;
    font-size: .88rem;
    font-family: inherit;
    outline: none;
    transition: border-color .2s;
}
.field input:focus { border-color: var(--accent); }

.btn-primary {
    margin-top: .5rem;
    padding: 11px 16px;
    background: linear-gradient(135deg, var(--primary), #4a0080);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: .9rem;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: .5px;
    transition: opacity .2s, box-shadow .2s;
}
.btn-primary:hover { opacity: .9; box-shadow: 0 4px 18px rgba(106,13,173,.4); }

.auth-hint {
    margin-top: 1.2rem;
    font-size: .78rem;
    color: var(--muted);
    text-align: center;
    line-height: 1.5;
}

/* ── Alerts ──────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: 8px; font-size: .85rem; margin-bottom: 1rem; }
.alert-error { background: rgba(239,68,68,.1);  border: 1px solid rgba(239,68,68,.3);  color: #fca5a5; }
.alert-warn  { background: rgba(255,215,0,.08); border: 1px solid rgba(255,215,0,.3);  color: #fcd34d; }
.alert-ok    { background: rgba(34,197,94,.1);  border: 1px solid rgba(34,197,94,.3);  color: #86efac; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 640px) {
    .portal-title       { font-size: 1.9rem; letter-spacing: 3px; }
    .portal-header      { padding: 8px 12px 13px; }
    .chat-messages      { padding: 12px 10px; }
    .chat-input-area    { padding: 8px 12px 12px; }
    .msg                { max-width: calc(90% + 15px); }
    .msg.assistant      { max-width: calc(90% + 20px); }
    .auth-card          { padding: 2rem 1.3rem; }
    .login-brand        { font-size: 2.2rem; letter-spacing: 3px; }
    .login-avatar       { width: 160px; height: 160px; }
    .login-tagline      { font-size: 1.3rem; letter-spacing: 2px; }
    .login-form-wrap    { padding: 1.4rem 1.2rem; }
    .btn-action         { font-size: .72rem; padding: 4px 10px; }
}

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.65);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    padding: 20px;
}
.modal-overlay[hidden] { display: none; }

.modal-box {
    background: var(--card);
    border-radius: 12px;
    padding: 1.8rem 1.6rem;
    max-width: 320px;
    width: 100%;
    text-align: center;
    border: 1px solid rgba(239,68,68,.3);
    box-shadow: 0 8px 40px rgba(0,0,0,.6);
}
.modal-box p {
    font-size: .9rem;
    color: #fca5a5;
    margin-bottom: 1.4rem;
    line-height: 1.5;
}
.modal-box small { font-size: .78rem; opacity: .7; }

.modal-btns {
    display: flex;
    gap: 10px;
    justify-content: center;
}
.btn-modal-yes {
    padding: 8px 32px;
    background: rgba(239,68,68,.85);
    border: none;
    border-radius: 6px;
    color: #fff;
    font-family: inherit;
    font-size: .88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s;
}
.btn-modal-yes:hover:not(:disabled) { background: rgba(239,68,68,1); }
.btn-modal-yes:disabled { opacity: .5; cursor: default; }

.btn-modal-no {
    padding: 8px 32px;
    background: transparent;
    border: 1px solid rgba(255,255,255,.2);
    border-radius: 6px;
    color: var(--muted);
    font-family: inherit;
    font-size: .88rem;
    cursor: pointer;
    transition: background .2s;
}
.btn-modal-no:hover { background: rgba(255,255,255,.05); }

/* ── Print (Descargar PDF) ────────────────────────────────── */
@media print {
    body {
        background: #fff !important;
        color: #000 !important;
        overflow: visible !important;
        font-size: 11pt;
    }
    #star-container,
    .portal-header,
    .chat-input-area,
    .chat-limit-msg,
    .bubble-fade,
    .bubble-actions,
    .btn-expand,
    .btn-whatsapp,
    .btn-continuar,
    #typing-indicator { display: none !important; }

    .portal {
        height: auto !important;
        max-width: 100% !important;
    }
    .chat-messages {
        overflow: visible !important;
        height: auto !important;
        min-height: unset !important;
        padding: 0 !important;
        gap: .8rem;
        display: flex;
        flex-direction: column;
    }
    .msg { max-width: 85% !important; page-break-inside: avoid; }
    .msg.user      { align-self: flex-end; }
    .msg.assistant { align-self: flex-start; }
    .msg.user .msg-bubble {
        background: #e8e0f0 !important;
        color: #000 !important;
        border: 1px solid #c0a0d0 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .msg.assistant .msg-bubble {
        background: #f2f2f2 !important;
        color: #000 !important;
        border: 1px solid #ccc !important;
        max-height: none !important;
        overflow: visible !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .msg.assistant .msg-bubble strong { color: #5a0a9d !important; }
    .msg.assistant .msg-bubble a { color: #0056b3 !important; }
    .msg-time { opacity: .5; font-size: 9pt; }
}
