:root {
    --bg-0: #141326;
    --bg-1: #1d1b39;
    --bg-2: #262351;
    --accent: #7c5cff;
    --accent-2: #ff6b9d;
    --accent-3: #ffb84d;
    --gold: #ffd166;
    --green: #35e0a1;
    --text-0: #f4f2ff;
    --text-1: #b7b3d9;
    --text-2: #8783ad;
    --danger: #ff5c7a;
    --radius: 18px;
    --shadow: 0 10px 30px rgba(10, 8, 30, 0.45);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    padding: 0;
    background: radial-gradient(circle at 20% 0%, #2a2560 0%, var(--bg-0) 55%);
    color: var(--text-0);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    min-height: 100vh;
    overscroll-behavior-y: none;
}

body {
    padding-bottom: env(safe-area-inset-bottom);
}

button, input { font-family: inherit; }

/* ---------- Login ---------- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    padding-top: max(24px, env(safe-area-inset-top));
}
.login-wrap { width: 100%; max-width: 380px; }
.login-card {
    background: linear-gradient(160deg, var(--bg-2), var(--bg-1));
    border-radius: 24px;
    padding: 36px 28px;
    box-shadow: var(--shadow);
    text-align: center;
    border: 1px solid rgba(255,255,255,0.06);
}
.login-logo img { border-radius: 20px; box-shadow: 0 8px 24px rgba(124,92,255,0.45); }
.login-card h1 { margin: 18px 0 4px; font-size: 26px; letter-spacing: -0.5px; }
.login-sub { color: var(--text-1); margin: 0 0 24px; font-size: 14px; }
.login-error {
    background: rgba(255,92,122,0.15);
    color: var(--danger);
    border: 1px solid rgba(255,92,122,0.35);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 13px;
    margin-bottom: 16px;
}
.login-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-1); }
.login-form input {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 13px 14px;
    color: var(--text-0);
    font-size: 16px;
    outline: none;
}
.login-form input:focus { border-color: var(--accent); }
.btn-login { margin-top: 6px; }

.btn-primary {
    background: linear-gradient(135deg, var(--accent), #5c3fe0);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 13px 18px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(124,92,255,0.4);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn-primary:active { transform: scale(0.96); }
.btn-small { padding: 10px 14px; font-size: 14px; }

/* ---------- App shell ---------- */
.app {
    max-width: 480px;
    margin: 0 auto;
    padding: 16px;
    padding-top: max(16px, env(safe-area-inset-top));
    padding-bottom: 40px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 2px 8px;
}
.topbar-user { display: flex; align-items: center; gap: 12px; }
.topbar-avatar { width: 46px; height: 46px; border-radius: 14px; box-shadow: 0 4px 14px rgba(124,92,255,0.35); }
.topbar-name { font-weight: 700; font-size: 16px; }
.topbar-level { font-size: 12px; color: var(--accent-3); font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.btn-logout {
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 12px;
    background: rgba(255,255,255,0.06);
    color: var(--text-1);
    text-decoration: none;
}
.btn-logout svg { width: 18px; height: 18px; }

.card {
    background: linear-gradient(160deg, var(--bg-2), var(--bg-1));
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
    border: 1px solid rgba(255,255,255,0.05);
}

/* ---------- XP card ---------- */
.xp-card { padding: 20px; }
.xp-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.xp-row.small { font-size: 12px; color: var(--text-2); margin: 8px 0 0; }
.xp-total { font-size: 22px; font-weight: 800; background: linear-gradient(135deg, var(--gold), var(--accent-3)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.xp-next { font-size: 13px; color: var(--text-1); }

.progress-bar {
    width: 100%;
    height: 12px;
    background: rgba(255,255,255,0.08);
    border-radius: 999px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    border-radius: 999px;
    transition: width 0.6s cubic-bezier(.34,1.56,.64,1);
}
.goal-fill { background: linear-gradient(90deg, var(--green), #24c98a); }

/* ---------- Stats ---------- */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat-card { text-align: center; padding: 18px 10px; }
.stat-icon { font-size: 26px; }
.stat-value { font-size: 28px; font-weight: 800; margin-top: 4px; }
.streak-card .stat-value { color: var(--accent-3); }
.closed-card .stat-value { color: var(--gold); }
.stat-label { font-size: 12px; color: var(--text-1); margin-top: 2px; }
.stat-sub { font-size: 11px; color: var(--text-2); margin-top: 4px; }

/* ---------- Goal card ---------- */
.goal-header { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--text-1); margin-bottom: 10px; }
.goal-edit-btn {
    background: rgba(255,255,255,0.06);
    border: none;
    color: var(--text-1);
    width: 30px; height: 30px;
    border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
}
.goal-edit-btn svg { width: 15px; height: 15px; }
.goal-progress-row { font-size: 20px; font-weight: 800; margin-bottom: 8px; }
.goal-progress-row span { color: var(--green); }
.goal-form { display: flex; gap: 8px; margin-top: 12px; }
.goal-form.hidden { display: none; }
.goal-form input {
    flex: 1;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    padding: 10px 12px;
    color: var(--text-0);
    font-size: 15px;
}

/* ---------- Action buttons ---------- */
.actions-grid { display: flex; flex-direction: column; gap: 10px; }
.action-btn {
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    background: linear-gradient(160deg, var(--bg-2), var(--bg-1));
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 16px;
    padding: 16px;
    color: var(--text-0);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    overflow: hidden;
    transition: transform 0.1s ease;
}
.action-btn:active { transform: scale(0.97); }
.action-icon { width: 22px; height: 22px; flex-shrink: 0; color: var(--accent); }
.action-label { flex: 1; }
.action-xp { font-size: 12px; font-weight: 700; color: var(--text-2); }

.action-criar_lista .action-icon { color: #7c9cff; }
.action-enviar_mensagem .action-icon { color: #35e0a1; }
.action-enviar_followup .action-icon { color: #ffb84d; }
.action-enviar_demo .action-icon { color: #ff9de2; }

.action-fechar_site {
    background: linear-gradient(135deg, #7c5cff, #ff6b9d);
    border: none;
}
.action-fechar_site .action-icon { color: white; }
.action-fechar_site .action-xp { color: rgba(255,255,255,0.85); }

.action-btn.pop { animation: popAction 0.35s ease; }
@keyframes popAction {
    0% { transform: scale(1); }
    35% { transform: scale(0.94); }
    60% { transform: scale(1.03); }
    100% { transform: scale(1); }
}

.floating-xp {
    position: absolute;
    right: 16px;
    top: 50%;
    font-weight: 800;
    font-size: 15px;
    color: var(--gold);
    pointer-events: none;
    animation: floatUp 0.9s ease forwards;
}
@keyframes floatUp {
    0% { opacity: 0; transform: translate(0, 0) scale(0.8); }
    15% { opacity: 1; transform: translate(0, -6px) scale(1.1); }
    100% { opacity: 0; transform: translate(0, -46px) scale(1); }
}

/* ---------- Level up modal ---------- */
.levelup-modal {
    position: fixed;
    inset: 0;
    background: rgba(10, 8, 24, 0.82);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 20px;
}
.levelup-modal.hidden { display: none; }
.levelup-box {
    background: linear-gradient(160deg, #2c2760, #1a1740);
    border-radius: 24px;
    padding: 40px 28px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(124,92,255,0.5);
    max-width: 340px;
    width: 100%;
    animation: levelPop 0.5s cubic-bezier(.34,1.56,.64,1);
    border: 1px solid rgba(255,255,255,0.1);
}
@keyframes levelPop {
    0% { transform: scale(0.6); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}
.levelup-title {
    font-size: 13px;
    letter-spacing: 2px;
    color: var(--gold);
    font-weight: 800;
    margin-bottom: 10px;
}
.levelup-name {
    font-size: 26px;
    font-weight: 800;
    margin-bottom: 24px;
    background: linear-gradient(135deg, var(--gold), var(--accent-2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

/* ---------- Undo toast ---------- */
.undo-toast {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: max(16px, env(safe-area-inset-bottom));
    max-width: 448px;
    margin: 0 auto;
    background: linear-gradient(135deg, #26234f, #1c1a3d);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 14px;
    padding: 13px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.45);
    z-index: 70;
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    overflow: hidden;
}
.undo-toast.show { opacity: 1; transform: translateY(0); }
.undo-text { flex: 1; font-size: 13px; color: var(--text-1); }
.undo-text strong { color: var(--text-0); }
.undo-btn {
    background: rgba(124,92,255,0.2);
    color: var(--accent-3);
    border: 1px solid rgba(124,92,255,0.4);
    border-radius: 9px;
    padding: 8px 14px;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
}
.undo-btn:active { transform: scale(0.95); }
.undo-bar {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 3px;
    width: 100%;
    background: rgba(255,255,255,0.06);
}
.undo-bar-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    transition: width linear;
}

.confetti-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 60;
    overflow: hidden;
}
.confetti-piece {
    position: absolute;
    top: -20px;
    border-radius: 2px;
    animation: confettiFall linear forwards;
}
@keyframes confettiFall {
    to { transform: translateY(110vh) rotate(720deg); opacity: 0.9; }
}

@media (min-width: 540px) {
    .app { padding-top: 32px; }
}
