/* TheologIA — Theme & Layout */

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
    --bg-primary: #faf8f5;
    --bg-secondary: #f0ebe4;
    --bg-tertiary: #e8e0d6;
    --text-primary: #2c1810;
    --text-secondary: #5a4a3e;
    --text-muted: #8a7a6e;
    --accent: #8b1a2b;
    --accent-hover: #a62038;
    --gold: #c5961a;
    --gold-light: #d4a830;
    --border: #e0d5c8;
    --border-light: #ede7df;
    --shadow: rgba(44, 24, 16, 0.08);
    --radius: 10px;
    --radius-lg: 16px;
    --transition: 0.2s ease;
    --max-chat: 1020px;
    --sidebar-width: 280px;
    --header-height: 56px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1a1510;
        --bg-secondary: #241e17;
        --bg-tertiary: #2e2620;
        --text-primary: #e8ddd0;
        --text-secondary: #b8a898;
        --text-muted: #7a6a5e;
        --accent: #d4475a;
        --accent-hover: #e05a6c;
        --gold: #d4a830;
        --gold-light: #e0b840;
        --border: #3a3025;
        --border-light: #2e2620;
        --shadow: rgba(0, 0, 0, 0.3);
    }
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
}

/* === App Layout === */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* === Sidebar === */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}

.sidebar-header {
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-close-btn {
    display: none;
}

.sidebar-header #new-chat-btn { margin-left: auto; }

.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conv-item {
    padding: 10px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background var(--transition);
}

.conv-item:hover { background: var(--bg-tertiary); }
.conv-item.active { background: var(--bg-tertiary); color: var(--text-primary); font-weight: 500; }

.conv-item .conv-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conv-item .conv-delete {
    opacity: 0;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 2px 6px;
    border-radius: 4px;
}

.conv-item:hover .conv-delete { opacity: 1; }
.conv-item .conv-delete:hover { background: var(--accent); color: white; }

/* Sidebar footer (compte) */
.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-shrink: 0;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    overflow: hidden;
}

.sidebar-user span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-logout {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    transition: all var(--transition);
}

.sidebar-logout:hover {
    background: var(--accent);
    color: white;
}

/* === Main === */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* === Header === */
.header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-primary);
    gap: 8px;
    flex-shrink: 0;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 18px;
    flex: 1;
}

.brand-cross {
    color: var(--accent);
    font-size: 22px;
}

.brand-name {
    color: var(--text-primary);
}

.header-actions {
    display: flex;
    gap: 4px;
}

.header-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.header-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* === Chat Area === */
.chat-area {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* === Welcome === */
.welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
}

.welcome-icon {
    font-size: 56px;
    color: var(--accent);
    margin-bottom: 16px;
}

.welcome h1 {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.welcome p {
    color: var(--text-secondary);
    font-size: 16px;
}

.welcome-sub {
    margin-top: 8px;
    font-size: 14px !important;
    color: var(--text-muted) !important;
    max-width: 400px;
}

.welcome-examples {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 32px;
    justify-content: center;
}

.example-btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 10px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    transition: all var(--transition);
}

.example-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--gold);
    color: var(--text-primary);
}

/* === Input Area === */
.input-area {
    padding: 12px 16px 16px;
    border-top: 1px solid var(--border-light);
    background: var(--bg-primary);
    flex-shrink: 0;
}

.chat-form {
    max-width: var(--max-chat);
    margin: 0 auto;
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#chat-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    font-size: 15px;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-secondary);
    outline: none;
    max-height: 150px;
    line-height: 1.5;
    transition: border-color var(--transition);
}

#chat-input:focus {
    border-color: var(--gold);
}

#chat-input::placeholder {
    color: var(--text-muted);
}

.send-btn {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.send-btn svg {
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
}

.guest-banner {
    max-width: var(--max-chat);
    margin: 8px auto 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 13px;
    color: var(--text-muted);
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    gap: 6px;
}

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

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

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

.btn-accent:hover { background: var(--accent-hover); }

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
}

.btn-small:hover { background: var(--border); }

/* === Modal === */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 32px;
    max-width: 480px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px var(--shadow);
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
}

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

/* === Auth Modal === */
.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--border);
}

.auth-tab {
    flex: 1;
    padding: 10px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
}

.auth-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.auth-form { display: flex; flex-direction: column; gap: 16px; }

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-secondary);
    outline: none;
    transition: border-color var(--transition);
}

.form-group input:focus {
    border-color: var(--gold);
}

.form-error {
    color: var(--accent);
    font-size: 13px;
    padding: 8px 12px;
    background: rgba(139, 26, 43, 0.08);
    border-radius: var(--radius);
}

/* === Profile Modal === */
.profile-modal-content { max-width: 520px; }
.profile-modal-content h2 { margin-bottom: 20px; }

.profile-section {
    margin-bottom: 20px;
}

.profile-section h3 {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.profile-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.profile-btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition);
}

.profile-btn:hover {
    border-color: var(--gold);
    color: var(--text-primary);
}

.profile-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.profile-hint {
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 12px;
}

/* === Corpus Modal === */
.corpus-modal-content {
    max-width: 860px;
    max-height: 80vh;
}

.corpus-modal-content h2 { margin-bottom: 16px; }

.corpus-search {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-secondary);
    outline: none;
    margin-bottom: 16px;
}

.corpus-search:focus { border-color: var(--gold); }

.corpus-list {
    max-height: 55vh;
    overflow-y: auto;
}

.corpus-group {
    margin-bottom: 16px;
}

.corpus-group-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-light);
}

.corpus-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition);
}

.corpus-item:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.corpus-item .corpus-year {
    color: var(--text-muted);
    font-size: 12px;
    min-width: 40px;
}

.corpus-item .corpus-link {
    margin-left: auto;
    color: var(--gold);
    font-size: 12px;
    text-decoration: none;
}

.corpus-item .corpus-link:hover { text-decoration: underline; }

/* Hamburger masqué sur desktop */
#sidebar-toggle {
    display: none !important;
}

/* === Responsive === */
@media (max-width: 768px) {
    #sidebar-toggle:not([hidden]) {
        display: flex !important;
    }

    .sidebar-close-btn {
        display: flex !important;
    }

    .sidebar {
        position: fixed;
        z-index: 100;
        left: -100%;
        top: 0;
        bottom: 0;
        transition: left 0.3s ease;
    }

    .sidebar.open {
        left: 0;
    }

    .welcome-examples {
        flex-direction: column;
    }

    .modal-content {
        width: 95%;
        padding: 24px;
    }
}
