/* ============================================================
   Art direction: Chat espiritual inspirado nos Evangelhos
   Palette: quente/dourado, tons de areia e creme — paz e acolhimento
   Typography: Lora (display/serifa) + Inter (corpo UI)
   Density: confortável, espaçoso
   ============================================================ */

:root, [data-theme="light"] {
    --text-xs:   clamp(0.75rem,  0.7rem  + 0.25vw, 0.875rem);
    --text-sm:   clamp(0.875rem, 0.8rem  + 0.35vw, 1rem);
    --text-base: clamp(1rem,     0.95rem + 0.25vw, 1.125rem);
    --text-lg:   clamp(1.125rem, 1rem    + 0.75vw, 1.5rem);
    --text-xl:   clamp(1.5rem,   1.2rem  + 1.25vw, 2.25rem);

    --space-1: 0.25rem; --space-2: 0.5rem; --space-3: 0.75rem;
    --space-4: 1rem;    --space-5: 1.25rem; --space-6: 1.5rem;
    --space-8: 2rem;    --space-10: 2.5rem; --space-12: 3rem;
    --space-16: 4rem;

    /* Superfícies quentes */
    --color-bg:             #f5f1ea;
    --color-surface:        #faf7f2;
    --color-surface-2:      #ffffff;
    --color-surface-offset: #ede8df;
    --color-divider:        #ddd7cd;
    --color-border:         #ccc5b8;

    /* Texto */
    --color-text:           #2c2416;
    --color-text-muted:     #7a6f60;
    --color-text-faint:     #b8b0a4;
    --color-text-inverse:   #faf7f2;

    /* Dourado sagrado */
    --color-primary:        #8b5e2a;
    --color-primary-hover:  #6e4a1f;
    --color-primary-active: #4e3415;
    --color-primary-light:  #f0e4d0;

    /* Bolhas de chat */
    --bubble-jesus-bg:      #ffffff;
    --bubble-jesus-text:    #2c2416;
    --bubble-user-bg:       #8b5e2a;
    --bubble-user-text:     #faf7f2;

    /* UI */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1.25rem;
    --radius-full: 9999px;
    --radius-bubble: 1.125rem;

    --shadow-sm: 0 1px 3px oklch(0.25 0.04 60 / 0.08);
    --shadow-md: 0 4px 16px oklch(0.25 0.04 60 / 0.12);
    --shadow-lg: 0 12px 40px oklch(0.25 0.04 60 / 0.18);

    --transition: 180ms cubic-bezier(0.16, 1, 0.3, 1);

    --font-display: 'Lora', 'Georgia', serif;
    --font-body:    'Inter', 'Helvetica Neue', sans-serif;

    --header-h: 64px;
    --input-h:  80px;
}

[data-theme="dark"] {
    --color-bg:             #1a1610;
    --color-surface:        #221d15;
    --color-surface-2:      #2a2418;
    --color-surface-offset: #1e1912;
    --color-divider:        #332c20;
    --color-border:         #3d3526;
    --color-text:           #e8dfc8;
    --color-text-muted:     #9a8f7a;
    --color-text-faint:     #5a5244;
    --color-text-inverse:   #1a1610;
    --color-primary:        #c9894a;
    --color-primary-hover:  #e0a060;
    --color-primary-active: #f0b870;
    --color-primary-light:  #3a2e1e;
    --bubble-jesus-bg:      #2a2418;
    --bubble-jesus-text:    #e8dfc8;
    --bubble-user-bg:       #c9894a;
    --bubble-user-text:     #1a1610;
    --shadow-sm: 0 1px 3px oklch(0 0 0 / 0.25);
    --shadow-md: 0 4px 16px oklch(0 0 0 / 0.35);
    --shadow-lg: 0 12px 40px oklch(0 0 0 / 0.45);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --color-bg: #1a1610; --color-surface: #221d15; --color-surface-2: #2a2418;
        --color-surface-offset: #1e1912; --color-divider: #332c20; --color-border: #3d3526;
        --color-text: #e8dfc8; --color-text-muted: #9a8f7a; --color-text-faint: #5a5244;
        --color-text-inverse: #1a1610; --color-primary: #c9894a;
        --color-primary-hover: #e0a060; --color-primary-active: #f0b870;
        --color-primary-light: #3a2e1e;
        --bubble-jesus-bg: #2a2418; --bubble-jesus-text: #e8dfc8;
        --bubble-user-bg: #c9894a; --bubble-user-text: #1a1610;
        --shadow-sm: 0 1px 3px oklch(0 0 0 / 0.25);
        --shadow-md: 0 4px 16px oklch(0 0 0 / 0.35);
        --shadow-lg: 0 12px 40px oklch(0 0 0 / 0.45);
    }
}

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
    -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility; text-size-adjust: none;
    height: 100%;
}
body {
    font-family: var(--font-body); font-size: var(--text-base);
    color: var(--color-text); background: var(--color-bg);
    height: 100%; min-height: 100dvh; overflow: hidden;
}
img { display: block; max-width: 100%; }
button { cursor: pointer; background: none; border: none; font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }
::selection { background: oklch(from var(--color-primary) l c h / 0.2); color: var(--color-text); }
:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 3px; border-radius: var(--radius-sm); }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ── OVERLAY / POPUP ── */
.overlay {
    position: fixed; inset: 0; z-index: 100;
    background: oklch(0.15 0.04 60 / 0.75);
    backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center;
    padding: var(--space-4);
    animation: fadeIn 0.3s ease both;
}
.overlay.hide {
    animation: fadeOut 0.35s ease both;
    pointer-events: none;
}

@keyframes fadeIn  { from { opacity: 0 } to { opacity: 1 } }
@keyframes fadeOut { from { opacity: 1 } to { opacity: 0 } }

.popup {
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    padding: var(--space-10) var(--space-8);
    width: 100%; max-width: 420px;
    box-shadow: var(--shadow-lg);
    border: 1px solid oklch(from var(--color-border) l c h / 0.6);
    animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(24px) } to { opacity: 1; transform: none } }

.popup-icon {
    font-size: 2.5rem; text-align: center; margin-bottom: var(--space-4);
    color: var(--color-primary); line-height: 1;
}
.popup h1 {
    font-family: var(--font-display); font-size: var(--text-xl);
    text-align: center; margin-bottom: var(--space-2);
    color: var(--color-text); font-weight: 600;
}
.popup-subtitle {
    text-align: center; color: var(--color-text-muted);
    font-size: var(--text-sm); margin-bottom: var(--space-8);
    max-width: 32ch; margin-inline: auto;
}

.field-group {
    margin-bottom: var(--space-5);
}
.field-group label {
    display: block; font-size: var(--text-sm); font-weight: 500;
    color: var(--color-text-muted); margin-bottom: var(--space-2);
}
.field-group input[type="text"],
.field-group input[type="number"] {
    width: 100%; padding: var(--space-3) var(--space-4);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: var(--text-base); color: var(--color-text);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.field-group input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px oklch(from var(--color-primary) l c h / 0.15);
}
.field-error {
    display: block; font-size: var(--text-xs);
    color: #b91c1c; margin-top: var(--space-1);
    min-height: 1.2em;
}

/* Radio cards */
.radio-group {
    display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3);
}
.radio-card {
    display: flex; align-items: center; justify-content: center;
    gap: var(--space-2); padding: var(--space-3) var(--space-4);
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md); cursor: pointer;
    font-size: var(--text-sm); font-weight: 500;
    transition: border-color var(--transition), background var(--transition), color var(--transition);
    user-select: none;
}
.radio-card input[type="radio"] { display: none; }
.radio-card:has(input:checked) {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
    color: var(--color-primary);
}
.radio-card:hover:not(:has(input:checked)) {
    border-color: color-mix(in oklch, var(--color-primary) 40%, var(--color-border));
    background: oklch(from var(--color-primary) l c h / 0.05);
}

.btn-entrar {
    width: 100%; padding: var(--space-4);
    background: var(--color-primary); color: var(--color-text-inverse);
    border-radius: var(--radius-md); font-size: var(--text-base); font-weight: 600;
    display: flex; align-items: center; justify-content: center; gap: var(--space-2);
    margin-top: var(--space-6);
    transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
    box-shadow: var(--shadow-sm);
}
.btn-entrar:hover  { background: var(--color-primary-hover); box-shadow: var(--shadow-md); }
.btn-entrar:active { background: var(--color-primary-active); transform: scale(0.98); }

/* ── CHAT APP ── */
.chat-app {
    display: flex; flex-direction: column;
    height: 100dvh; width: 100%;
    max-width: 720px; margin-inline: auto;
    background: var(--color-bg);
}
.chat-app[hidden] { display: none; }

/* Header */
.chat-header {
    height: var(--header-h);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 var(--space-4);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-divider);
    box-shadow: var(--shadow-sm);
    flex-shrink: 0; position: sticky; top: 0; z-index: 10;
}
.chat-contact { display: flex; align-items: center; gap: var(--space-3); }

.avatar-wrap { position: relative; flex-shrink: 0; }
.avatar {
    width: 44px; height: 44px; border-radius: var(--radius-full);
    object-fit: cover; border: 2px solid var(--color-primary-light);
    background: var(--color-surface-offset);
}
.status-dot {
    position: absolute; bottom: 1px; right: 1px;
    width: 11px; height: 11px; border-radius: var(--radius-full);
    background: #22c55e;
    border: 2px solid var(--color-surface);
}

.contact-name  { display: block; font-weight: 600; font-size: var(--text-base); line-height: 1.2; }
.contact-status { display: block; font-size: var(--text-xs); color: var(--color-text-muted); }

.btn-theme {
    width: 40px; height: 40px; border-radius: var(--radius-full);
    display: flex; align-items: center; justify-content: center;
    color: var(--color-text-muted);
    transition: background var(--transition), color var(--transition);
}
.btn-theme:hover { background: var(--color-surface-offset); color: var(--color-text); }

/* Messages */
.chat-messages {
    flex: 1; overflow-y: auto; overflow-x: hidden;
    padding: var(--space-6) var(--space-4);
    display: flex; flex-direction: column; gap: var(--space-3);
    scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--color-divider); border-radius: var(--radius-full); }

/* Message row */
.msg-row {
    display: flex; gap: var(--space-2); max-width: 82%;
    animation: msgIn 0.28s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(10px) } to { opacity: 1; transform: none } }
.msg-row.user { margin-left: auto; flex-direction: row-reverse; }
.msg-row.jesus { margin-right: auto; }

.msg-avatar {
    width: 32px; height: 32px; border-radius: var(--radius-full);
    object-fit: cover; flex-shrink: 0; align-self: flex-end;
    border: 1.5px solid var(--color-primary-light);
    background: var(--color-surface-offset);
}
.msg-avatar-placeholder {
    width: 32px; height: 32px; border-radius: var(--radius-full);
    flex-shrink: 0; background: var(--color-primary-light);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.875rem; color: var(--color-primary); font-weight: 700;
    align-self: flex-end;
}

.bubble {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-bubble);
    font-size: var(--text-base); line-height: 1.6;
    max-width: 100%; word-break: break-word;
    position: relative;
}
.msg-row.jesus .bubble {
    background: var(--bubble-jesus-bg);
    color: var(--bubble-jesus-text);
    border-bottom-left-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    border: 1px solid oklch(from var(--color-border) l c h / 0.5);
}
.msg-row.user .bubble {
    background: var(--bubble-user-bg);
    color: var(--bubble-user-text);
    border-bottom-right-radius: var(--radius-sm);
}

.msg-time {
    font-size: 0.7rem; color: var(--color-text-faint);
    margin-top: var(--space-1); display: block;
    text-align: right;
}
.msg-row.jesus .msg-time { text-align: left; }

/* Typing indicator */
.typing-row {
    display: flex; gap: var(--space-2); align-items: flex-end;
    max-width: 82%; animation: msgIn 0.28s ease both;
}
.typing-bubble {
    background: var(--bubble-jesus-bg);
    border: 1px solid oklch(from var(--color-border) l c h / 0.5);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-bubble); border-bottom-left-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    display: flex; align-items: center; gap: 5px;
}
.typing-dot {
    width: 7px; height: 7px; border-radius: var(--radius-full);
    background: var(--color-text-faint); display: block;
    animation: typingBounce 1.2s ease infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* Input area */
.chat-input-area {
    flex-shrink: 0;
    padding: var(--space-3) var(--space-4) var(--space-4);
    background: var(--color-surface);
    border-top: 1px solid var(--color-divider);
}
.input-row {
    display: flex; gap: var(--space-2); align-items: flex-end;
}
.input-row textarea {
    flex: 1;
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    font-size: var(--text-base); line-height: 1.5;
    resize: none; max-height: 120px; overflow-y: auto;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.input-row textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px oklch(from var(--color-primary) l c h / 0.12);
}
.input-row textarea::placeholder { color: var(--color-text-faint); }

.btn-send {
    width: 46px; height: 46px; border-radius: var(--radius-full); flex-shrink: 0;
    background: var(--color-primary); color: var(--color-text-inverse);
    display: flex; align-items: center; justify-content: center;
    transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
    box-shadow: var(--shadow-sm);
}
.btn-send:hover  { background: var(--color-primary-hover); box-shadow: var(--shadow-md); }
.btn-send:active { background: var(--color-primary-active); transform: scale(0.94); }
.btn-send:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.disclaimer {
    font-size: var(--text-xs); color: var(--color-text-faint);
    text-align: center; margin-top: var(--space-2); line-height: 1.4;
}

/* ── RESPONSIVE ── */
@media (max-width: 480px) {
    .popup { padding: var(--space-8) var(--space-5); }
    .msg-row { max-width: 92%; }
    .chat-messages { padding: var(--space-4) var(--space-3); }
    .chat-input-area { padding: var(--space-3); }
}

/* ── TERMOS ── */
.termos-popup { max-width: 480px; }
.termos-icon { font-size: 2rem; color: var(--color-warning, #b06a00); background: none; }
.termos-popup h2 { font-family: 'Lora', Georgia, serif; font-size: var(--text-lg); margin-bottom: var(--space-4); color: var(--color-text); }
.termos-box { background: var(--color-surface-offset, #f3f0ec); border-radius: var(--radius-lg); padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-3); margin-bottom: var(--space-6); border: 1px solid oklch(from currentColor l c h / 0.1); }
.termos-box p { font-size: var(--text-sm); color: var(--color-text-muted, #6b6865); line-height: 1.7; max-width: 100%; }
.termos-box strong { color: var(--color-text, #28251d); font-weight: 600; }
.termos-destaque { font-style: italic; color: var(--color-text, #28251d) !important; font-weight: 500; border-top: 1px solid var(--color-divider, #dcd9d5); padding-top: var(--space-3); margin-top: var(--space-1); }
.termos-actions { display: flex; gap: var(--space-3); }
.btn-recusar { flex: 1; padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); border: 1px solid var(--color-border, #d4d1ca); background: transparent; color: var(--color-text-muted); font-size: var(--text-sm); font-weight: 500; cursor: pointer; transition: background 180ms, color 180ms; }
.btn-recusar:hover { background: var(--color-surface-offset, #f3f0ec); color: var(--color-text); }
.btn-aceitar { flex: 2; display: flex; align-items: center; justify-content: center; gap: var(--space-2); padding: var(--space-3) var(--space-5); border-radius: var(--radius-md); border: none; background: #5a7c3a; color: #fff; font-size: var(--text-sm); font-weight: 600; cursor: pointer; transition: background 180ms; }
.btn-aceitar:hover { background: #3f5a28; }
[data-theme="dark"] .termos-box { background: var(--color-surface-offset-2, #22211f); }
[data-theme="dark"] .btn-recusar { border-color: var(--color-border, #393836); }
