/* ============================================
   Auth Gate Modal - Meelion Design System
   CSS auto-contido usando design tokens Meelion/Bulma.
   Escopo: .auth-gate-modal (sem conflito com Bootstrap)
   ============================================ */

/* Design tokens (fallback quando Bulma não está carregada) */
.auth-gate-modal {
    --ag-primary: #005a78;
    --ag-primary-hover: #004d66;
    --ag-primary-light: rgba(0, 90, 120, 0.08);
    --ag-link: #C3F53C;
    --ag-dark: #2D3335;
    --ag-text: #262626;
    --ag-text-weak: #737373;
    --ag-text-strong: #1a1a1a;
    --ag-border: #dbdbdb;
    --ag-border-hover: #b5b5b5;
    --ag-bg: #fff;
    --ag-danger: #f14668;
    --ag-danger-light: #feecf0;
    --ag-success: #48c78e;
    --ag-success-light: #effaf5;
    --ag-radius: 6px;
    --ag-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Modal overlay */
.auth-gate-modal {
    position: fixed;
    inset: 0;
    z-index: 1000040;
    display: none;
    align-items: center;
    justify-content: center;
    font-family: var(--ag-family);
    padding: 1rem;
    box-sizing: border-box;
}

.auth-gate-modal.is-active {
    display: flex;
}

/* Backdrop */
.auth-gate-modal .modal-background {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 10, 0.6);
    z-index: 1;
}

/* Card container */
.auth-gate-modal .modal-card {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: row;
    background: var(--ag-bg);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 860px;
    width: 100%;
    max-height: 90vh;
    animation: agSlideIn 0.25s ease-out;
}

@keyframes agSlideIn {
    from { opacity: 0; transform: translateY(16px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Close button (Bulma .delete) */
.auth-gate-modal .ag-delete {
    appearance: none;
    background-color: rgba(10, 10, 10, 0.2);
    border: none;
    border-radius: 9999px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0;
    height: 28px;
    width: 28px;
    outline: none;
    position: absolute;
    top: 12px;
    right: 14px;
    z-index: 5;
    transition: background-color 0.2s;
}

.auth-gate-modal .ag-delete::before,
.auth-gate-modal .ag-delete::after {
    background-color: #fff;
    content: "";
    display: block;
    left: 50%;
    position: absolute;
    top: 50%;
    transform: translateX(-50%) translateY(-50%) rotate(45deg);
    transform-origin: center center;
}

.auth-gate-modal .ag-delete::before { height: 2px; width: 50%; }
.auth-gate-modal .ag-delete::after  { height: 50%; width: 2px; }
.auth-gate-modal .ag-delete:hover   { background-color: rgba(10, 10, 10, 0.35); }

/* ============================================
   Painel Esquerdo - Contexto
   ============================================ */

.auth-gate-context {
    flex: 0 0 390px;
    background: var(--ag-primary);
    color: #fff;
    padding: 2.5rem 2rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.auth-gate-context-title {
    font-size: 1.4rem;
    font-weight: 700;
    line-height: 1.3;
    margin: 0 0 1.75rem 0;
    color: #fff;
}

.auth-gate-benefits {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.auth-gate-benefit {
    display: flex;
    gap: 0.85rem;
    align-items: flex-start;
}

.auth-gate-benefit-icon {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    color: var(--ag-link);
}

.auth-gate-benefit-icon svg {
    width: 22px;
    height: 22px;
    stroke: var(--ag-link);
    fill: none;
}

.auth-gate-benefit strong {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 3px;
    color: #fff;
}

.auth-gate-benefit p {
    margin: 0;
    font-size: 0.8rem;
    line-height: 1.45;
    color: rgba(255, 255, 255, 0.72);
}

.auth-gate-context-footer {
    margin-top: 2rem;
    padding-top: 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.auth-gate-context-footer p {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.7);
    margin: 0 0 6px 0;
}

.auth-gate-context-footer a {
    color: var(--ag-link);
    font-weight: 600;
    font-size: 0.85rem;
    text-decoration: none;
}

/* ============================================
   Estado de Redirect
   ============================================ */

.auth-gate-redirecting {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    gap: 1rem;
}

.auth-gate-redirect-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--ag-border);
    border-right-color: var(--ag-primary);
    border-top-color: var(--ag-primary);
    border-radius: 9999px;
    animation: agSpin 0.6s infinite linear;
}

.auth-gate-redirect-text {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--ag-text-strong);
}

/* ============================================
   Painel Direito - Formulário
   ============================================ */

.auth-gate-form {
    flex: 1;
    padding: 2.25rem 2.25rem 1.5rem;
    overflow-y: auto;
    position: relative;
    color: var(--ag-text);
}

.auth-gate-form h2 {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--ag-text-strong);
    margin: 0 0 4px 0;
    font-family: var(--ag-family);
}

.auth-gate-form .ag-subtitle {
    font-size: 0.85rem;
    color: var(--ag-text-weak);
    margin: 0 0 1rem 0;
}

/* Tabs (Bulma style) */
.auth-gate-tabs {
    display: flex;
    border-bottom: 1px solid var(--ag-border);
    margin-bottom: 1.25rem;
}

.auth-gate-tabs button {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    padding: 0.5rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--ag-text-weak);
    cursor: pointer;
    font-family: var(--ag-family);
    transition: color 0.15s, border-color 0.15s;
}

.auth-gate-tabs button:hover { color: var(--ag-text-strong); }

.auth-gate-tabs button.is-active {
    color: var(--ag-primary);
    border-bottom-color: var(--ag-primary);
    font-weight: 600;
}

/* Notification (Bulma style) */
.auth-gate-notification {
    padding: 0.75rem 1rem;
    border-radius: var(--ag-radius);
    font-size: 0.84rem;
    margin-bottom: 1rem;
    position: relative;
    display: none;
}

.auth-gate-notification.is-visible { display: block; }

.auth-gate-notification.is-success {
    background: var(--ag-success-light);
    color: #257953;
}

.auth-gate-notification.is-danger {
    background: var(--ag-danger-light);
    color: #cc0f35;
}

.auth-gate-notification .ag-delete-sm {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(10,10,10,0.15);
    border: none;
    border-radius: 9999px;
    width: 20px;
    height: 20px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.auth-gate-notification .ag-delete-sm::before,
.auth-gate-notification .ag-delete-sm::after {
    background-color: currentColor;
    content: "";
    display: block;
    left: 50%;
    position: absolute;
    top: 50%;
    transform: translateX(-50%) translateY(-50%) rotate(45deg);
}
.auth-gate-notification .ag-delete-sm::before { height: 2px; width: 50%; }
.auth-gate-notification .ag-delete-sm::after  { height: 50%; width: 2px; }

/* Google button slot */
.auth-gate-google-slot {
    min-height: 44px;
    margin-bottom: 4px;
}

/* Divider */
.auth-gate-divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 1.15rem 0;
    color: var(--ag-text-weak);
    font-size: 0.8rem;
}

.auth-gate-divider::before,
.auth-gate-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--ag-border);
}

/* Fields (Bulma style) */
.auth-gate-field {
    margin-bottom: 0.75rem;
}

.auth-gate-field label.ag-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--ag-text-strong);
    margin-bottom: 0.35rem;
    font-family: var(--ag-family);
}

.auth-gate-field .ag-input,
.auth-gate-field .ag-select {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--ag-border);
    border-radius: var(--ag-radius);
    font-size: 0.9rem;
    color: var(--ag-text);
    background: var(--ag-bg);
    font-family: var(--ag-family);
    box-shadow: inset 0 0.0625em 0.125em rgba(10,10,10,0.05);
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
    appearance: none;
    -webkit-appearance: none;
}

.auth-gate-field .ag-input:focus,
.auth-gate-field .ag-select:focus {
    outline: none;
    border-color: var(--ag-primary);
    box-shadow: 0 0 0 0.125em rgba(0, 90, 120, 0.2);
}

.auth-gate-field .ag-input.is-danger {
    border-color: var(--ag-danger);
}

.auth-gate-field .ag-input.is-danger:focus {
    box-shadow: 0 0 0 0.125em rgba(241, 70, 104, 0.2);
}

.auth-gate-field .ag-help {
    font-size: 0.75rem;
    margin-top: 0.25rem;
    color: var(--ag-text-weak);
}

.auth-gate-field .ag-help.is-danger {
    color: var(--ag-danger);
}

/* Select wrapper (Bulma-like arrow) */
.auth-gate-select-wrap {
    position: relative;
}

.auth-gate-select-wrap::after {
    content: "";
    border: 2px solid var(--ag-primary);
    border-right: 0;
    border-top: 0;
    display: block;
    height: 0.5em;
    width: 0.5em;
    pointer-events: none;
    position: absolute;
    top: 50%;
    right: 1rem;
    transform: translateY(-65%) rotate(-45deg);
}

/* Password toggle */
.auth-gate-pw-wrap {
    position: relative;
}

.auth-gate-pw-wrap .ag-input {
    padding-right: 2.5rem;
}

.auth-gate-pw-toggle {
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    width: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--ag-text-weak);
    cursor: pointer;
    font-size: 0.9rem;
}

.auth-gate-pw-toggle:hover { color: var(--ag-text); }

/* Forgot link */
.auth-gate-forgot {
    float: right;
    font-size: 0.75rem;
    color: var(--ag-primary);
    text-decoration: none;
}

.auth-gate-forgot:hover {
    text-decoration: underline;
    color: var(--ag-primary);
}

/* Phone row */
.auth-gate-phone-row {
    display: flex;
    gap: 0.5rem;
}

.auth-gate-phone-row .ag-ddd { flex: 0 0 70px; }
.auth-gate-phone-row .ag-phone { flex: 1; }

/* Checkbox (Bulma style) */
.auth-gate-checkbox {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.auth-gate-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin-top: 2px;
    flex-shrink: 0;
    accent-color: var(--ag-primary);
    cursor: pointer;
}

.auth-gate-checkbox label {
    font-size: 0.78rem;
    color: var(--ag-text);
    line-height: 1.4;
    cursor: pointer;
}

.auth-gate-checkbox label a {
    color: var(--ag-primary);
    text-decoration: underline;
}

/* Button primary (Bulma style) */
.auth-gate-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0.65rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--ag-radius);
    font-size: 0.95rem;
    font-weight: 600;
    font-family: var(--ag-family);
    cursor: pointer;
    transition: background-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
    line-height: 1.5;
    text-align: center;
    white-space: nowrap;
}

.auth-gate-btn.is-primary {
    background-color: var(--ag-primary);
    color: #fff;
    border-color: transparent;
}

.auth-gate-btn.is-primary:hover {
    background-color: var(--ag-primary-hover);
}

.auth-gate-btn.is-primary:active {
    transform: scale(0.99);
}

.auth-gate-btn.is-primary:disabled,
.auth-gate-btn.is-loading {
    opacity: 0.65;
    cursor: not-allowed;
}

.auth-gate-btn.is-loading {
    color: transparent !important;
    pointer-events: none;
    position: relative;
}

.auth-gate-btn.is-loading::after {
    content: "";
    position: absolute;
    width: 1em;
    height: 1em;
    border: 2px solid #fff;
    border-right-color: transparent;
    border-top-color: transparent;
    border-radius: 9999px;
    animation: agSpin 0.5s infinite linear;
}

@keyframes agSpin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* Switch link */
.auth-gate-switch {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.82rem;
    color: var(--ag-text-weak);
}

.auth-gate-switch a {
    color: var(--ag-primary);
    font-weight: 600;
    text-decoration: none;
}

.auth-gate-switch a:hover { text-decoration: underline; }

/* Back link */
.auth-gate-back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.82rem;
    color: var(--ag-primary);
    text-decoration: none;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    margin-bottom: 1rem;
    font-family: var(--ag-family);
}

.auth-gate-back:hover { text-decoration: underline; }

/* Scroll lock */
html.auth-gate-open {
    overflow: hidden !important;
}

/* Pagination button loading (fake feedback pós-login) */
.pagination .page-link.ag-pagination-loading {
    color: transparent !important;
    -webkit-text-fill-color: transparent !important;
    text-shadow: none !important;
    position: relative;
    /* Esconde o texto do link (número/seta); páginas com .page-link { color: !important } precisam de override local */
    font-size: 0 !important;
    line-height: 0 !important;
    overflow: hidden !important;
}

.pagination .page-link.ag-pagination-loading::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    z-index: 1;
    border: 2px solid rgba(0, 90, 120, 0.2);
    border-right-color: #005a78;
    border-top-color: #005a78;
    border-radius: 9999px;
    animation: agSpin 0.6s infinite linear;
    /* Independente de font-size:0 no pai */
    font-size: 0;
}

/* Overlay real é injetado em auth-gate.js (.ag-auth-sort-overlay) — estilos em comparar-investimentos.css */

/* ============================================
   Responsividade
   ============================================ */

@media (max-width: 768px) {
    .auth-gate-modal {
        padding: 0;
        align-items: flex-end;
    }

    .auth-gate-modal .modal-card {
        flex-direction: column;
        border-radius: 12px 12px 0 0;
        max-height: 95vh;
    }

    .auth-gate-context {
        flex: none;
        padding: 1.5rem 1.25rem 1rem;
    }

    .auth-gate-context-title {
        font-size: 1.1rem;
        margin-bottom: 1rem;
    }

    .auth-gate-benefit p { display: none; }

    .auth-gate-form {
        padding: 1.25rem 1rem 1rem;
    }
}

@media (max-width: 480px) {
    .auth-gate-benefit-icon { display: none; }
    .auth-gate-form { padding: 1rem 0.85rem 0.85rem; }
}
