/* CSS Variables */
:root {
    --primary-color: #1e4d6b;
    --primary-dark: #0d3a54;
    --primary-light: #2a6a8f;
    --secondary-color: #c4a44a;
    --secondary-light: #d4b85a;
    --accent-color: #8b5a2b;
    --background-color: #f5f2eb;
    --surface-color: #ffffff;
    --text-primary: #2c2c2c;
    --text-secondary: #5a5a5a;
    --text-light: #888888;
    --border-color: #e0dcd4;
    --error-color: #c0392b;
    --success-color: #27ae60;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.15);
    --radius: 8px;
    --radius-lg: 16px;
    --transition: 0.2s ease;
    --font-serif: 'Merriweather', Georgia, serif;
    --font-sans: 'Open Sans', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Section Colors */
    --bom-color: #1e4d6b;
    --ot-color: #8b4513;
    --nt-color: #4b0082;
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Base Styles */
html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Typography */
h1, h2, h3 {
    font-family: var(--font-serif);
    font-weight: 700;
    line-height: 1.3;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-dark);
}

.btn-secondary {
    background-color: transparent;
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

.btn-secondary:hover {
    background-color: var(--primary-color);
    color: white;
}

.btn-donate {
    background: linear-gradient(135deg, var(--secondary-color), var(--secondary-light));
    color: white;
    font-weight: 600;
}

.btn-donate:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow);
}

.btn-donate .donate-icon {
    animation: heartbeat 1.5s infinite;
}

@keyframes heartbeat {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.btn-full {
    width: 100%;
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.icon-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--primary-color);
}

/* Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.character-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid var(--primary-color);
    cursor: pointer;
    transition: transform var(--transition);
}

.character-avatar:hover {
    transform: scale(1.05);
}

.character-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.header-info h1 {
    font-size: 1.25rem;
    color: var(--primary-color);
}

.header-info p {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Chat Container */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    overflow-y: auto;
}

.chat-messages {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding-bottom: 1rem;
}

/* Messages */
.message {
    display: flex;
    gap: 0.75rem;
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-content {
    padding: 0.875rem 1rem;
    border-radius: var(--radius-lg);
    line-height: 1.5;
}

.message.character .message-content {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

.message.user .message-content {
    background-color: var(--primary-color);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-content p {
    margin-bottom: 0.5rem;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.scripture-reference {
    font-style: italic;
    color: var(--accent-color);
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px dashed var(--border-color);
    font-size: 0.9rem;
}

.message.user .scripture-reference {
    color: rgba(255, 255, 255, 0.8);
    border-top-color: rgba(255, 255, 255, 0.3);
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 1rem;
    background-color: var(--surface-color);
    border-radius: var(--radius-lg);
    width: fit-content;
    margin-left: 48px;
}

.typing-indicator.hidden {
    display: none;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background-color: var(--text-light);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.8); }
    40% { transform: scale(1.2); }
}

/* Input Area */
.chat-input-container {
    padding: 1rem 1.5rem;
    background-color: var(--surface-color);
    border-top: 1px solid var(--border-color);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    max-width: 800px;
    margin: 0 auto;
}

#message-input {
    flex: 1;
    padding: 0.875rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    font-family: var(--font-sans);
    font-size: 1rem;
    resize: none;
    max-height: 150px;
    transition: border-color var(--transition);
}

#message-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    background-color: var(--primary-color);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    transition: all var(--transition);
}

.send-btn:hover {
    background-color: var(--primary-dark);
    transform: scale(1.05);
}

.send-btn:disabled {
    background-color: var(--text-light);
    cursor: not-allowed;
    transform: none;
}

.disclaimer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 0.5rem;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    overflow-y: auto;
}

.modal.active {
    display: flex;
}

.modal-content {
    background-color: var(--surface-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.25rem;
    color: var(--primary-color);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-primary);
}

/* Auth Modal */
.auth-modal-content {
    text-align: center;
}

.auth-header {
    margin-bottom: 1.5rem;
}

.auth-logo {
    width: 80px;
    height: 80px;
    margin-bottom: 1rem;
}

.auth-header h2 {
    color: var(--primary-color);
    margin-bottom: 0.25rem;
}

.auth-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.auth-tabs {
    display: flex;
    margin-bottom: 1.5rem;
    border-radius: var(--radius);
    overflow: hidden;
    border: 2px solid var(--border-color);
}

.auth-tab {
    flex: 1;
    padding: 0.75rem;
    background: none;
    border: none;
    cursor: pointer;
    font-weight: 500;
    transition: all var(--transition);
}

.auth-tab.active {
    background-color: var(--primary-color);
    color: white;
}

.auth-form {
    text-align: left;
}

.auth-form.hidden {
    display: none;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.375rem;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 1rem;
    transition: border-color var(--transition);
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.auth-error {
    color: var(--error-color);
    font-size: 0.875rem;
    margin-top: 0.5rem;
    min-height: 1.25rem;
}

.guest-btn {
    margin-top: 1rem;
}

/* Recommendation Modal */
.recommendation-content {
    text-align: center;
    padding: 2rem;
}

.recommendation-header {
    margin-bottom: 1rem;
}

.greeting-icon {
    font-size: 3rem;
}

.recommendation-header h2 {
    color: var(--primary-color);
    margin-top: 0.5rem;
}

.recommendation-text {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
}

.recommendation-reason {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
}

.recommendation-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Settings Modal */
.settings-section {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.settings-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.settings-section h3 {
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.settings-desc {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

/* Toggle Switch */
.toggle {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-color);
    transition: var(--transition);
    border-radius: 28px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: var(--transition);
    border-radius: 50%;
}

.toggle input:checked + .toggle-slider {
    background-color: var(--primary-color);
}

.toggle input:checked + .toggle-slider:before {
    transform: translateX(22px);
}

/* Select */
select {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 1rem;
    background-color: white;
    cursor: pointer;
}

select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Character Modal */
.character-modal-content {
    max-width: 900px;
}

.section-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.section-tab {
    padding: 0.5rem 1rem;
    background: none;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 500;
    transition: all var(--transition);
}

.section-tab.active,
.section-tab:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.section-tab[data-section="book_of_mormon"].active { border-color: var(--bom-color); color: var(--bom-color); }
.section-tab[data-section="old_testament"].active { border-color: var(--ot-color); color: var(--ot-color); }
.section-tab[data-section="new_testament"].active { border-color: var(--nt-color); color: var(--nt-color); }

.characters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
}

.character-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    background-color: var(--background-color);
    border: 2px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
}

.character-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.character-card.active {
    border-color: var(--primary-color);
    background-color: rgba(30, 77, 107, 0.1);
}

.character-card img {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 0.5rem;
    border: 3px solid var(--border-color);
}

.character-card.active img {
    border-color: var(--primary-color);
}

.character-card h4 {
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

.character-card p {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.3;
}

/* Conversations List */
.conversations-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background-color: var(--background-color);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
}

.conversation-item:hover {
    background-color: rgba(30, 77, 107, 0.1);
}

.conversation-item img {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
}

.conversation-info {
    flex: 1;
}

.conversation-info h4 {
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.conversation-info p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.conversation-meta {
    text-align: right;
    font-size: 0.8rem;
    color: var(--text-light);
}

.no-conversations {
    text-align: center;
    color: var(--text-secondary);
    padding: 2rem;
}

/* User Stats */
#user-stats {
    background-color: var(--background-color);
    padding: 1rem;
    border-radius: var(--radius);
}

.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

.stat-item:last-child {
    border-bottom: none;
}

.stat-label {
    color: var(--text-secondary);
}

.stat-value {
    font-weight: 600;
    color: var(--primary-color);
}

/* Hidden utility */
.hidden {
    display: none !important;
}

/* Responsive Design */
@media (max-width: 768px) {
    .chat-header {
        padding: 0.75rem 1rem;
    }

    .header-info h1 {
        font-size: 1rem;
    }

    .header-info p {
        font-size: 0.75rem;
    }

    .btn-donate span:not(.donate-icon) {
        display: none;
    }

    .chat-container {
        padding: 0.75rem;
    }

    .message {
        max-width: 90%;
    }

    .chat-input-container {
        padding: 0.75rem 1rem;
    }

    .modal-content {
        padding: 1.25rem;
        max-height: 85vh;
    }

    .characters-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }

    .character-card img {
        width: 50px;
        height: 50px;
    }
}

@media (max-width: 480px) {
    .section-tabs {
        justify-content: center;
    }

    .section-tab {
        font-size: 0.85rem;
        padding: 0.4rem 0.75rem;
    }

    .recommendation-actions {
        flex-direction: column;
    }

    .recommendation-actions .btn {
        width: 100%;
    }
}

/* Print styles */
@media print {
    .chat-header,
    .chat-input-container,
    .modal {
        display: none !important;
    }

    .chat-container {
        max-width: 100%;
    }
}
