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

:root {
    --bg: #EEF8F6;
    --bg2: #FFFFFF;
    --bg3: #d8efeb;
    --border: #CFE8E3;
    --text: #0D4A4A;
    --text2: #2A8A7A;
    --accent: #2A8A7A;
    --accent-hover: #1E6E5E;
    --radius: 8px;
}

body { font-family: 'Segoe UI', Arial, sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }

/* Auth */
.auth-container { display: flex; align-items: center; justify-content: center; height: 100vh; }
.auth-box { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 2.5rem; width: 100%; max-width: 400px; }
.auth-box h1 { font-size: 1.5rem; margin-bottom: 0.25rem; }
.auth-box .subtitle { color: var(--text2); margin-bottom: 1.5rem; font-size: 0.9rem; }
.auth-box input { display: block; width: 100%; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); padding: 0.75rem 1rem; margin-bottom: 0.75rem; font-size: 0.95rem; }
.auth-box input:focus { outline: none; border-color: var(--accent); }
.auth-box button { width: 100%; background: var(--accent); color: white; border: none; border-radius: var(--radius); padding: 0.75rem; font-size: 1rem; cursor: pointer; margin-top: 0.5rem; }
.auth-box button:hover { background: var(--accent-hover); }
.auth-link { margin-top: 1.25rem; text-align: center; font-size: 0.875rem; color: var(--text2); }
.auth-link a { color: var(--accent); text-decoration: none; }
.error { background: #3a1a1a; border: 1px solid #6b2c2c; border-radius: var(--radius); padding: 0.75rem; margin-bottom: 1rem; font-size: 0.875rem; color: #ff9999; }

/* Layout chat */
.app { display: flex; height: 100vh; }

/* Sidebar */
.sidebar { width: 260px; background: var(--bg2); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-header { padding: 1rem; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.app-name { font-weight: 600; font-size: 0.95rem; }
.btn-new { background: var(--accent); color: white; border: none; border-radius: var(--radius); padding: 0.4rem 0.75rem; font-size: 0.8rem; cursor: pointer; white-space: nowrap; }
.btn-new:hover { background: var(--accent-hover); }
.sessions-list { flex: 1; overflow-y: auto; padding: 0.5rem; }
.session-item { display: flex; align-items: center; justify-content: space-between; padding: 0.6rem 0.75rem; border-radius: var(--radius); cursor: pointer; text-decoration: none; color: var(--text); font-size: 0.875rem; margin-bottom: 2px; }
.session-item:hover { background: var(--bg3); }
.session-item.active { background: var(--bg3); border-left: 2px solid var(--accent); }
.session-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-delete { background: none; border: none; color: var(--text2); cursor: pointer; padding: 0 0.25rem; font-size: 0.75rem; opacity: 0; flex-shrink: 0; }
.session-item:hover .btn-delete { opacity: 1; }
.btn-delete:hover { color: var(--accent); }
.sidebar-footer { padding: 0.75rem 1rem; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.user-email { font-size: 0.75rem; color: var(--text2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.btn-logout { font-size: 0.75rem; color: var(--text2); text-decoration: none; margin-left: 0.5rem; flex-shrink: 0; }
.btn-logout:hover { color: var(--text); }

/* Chat main */
.chat-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.chat-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text2); text-align: center; padding: 2rem; }
.chat-empty h2 { font-size: 1.5rem; color: var(--text); margin-bottom: 0.5rem; }
.messages { flex: 1; overflow-y: auto; padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.message { max-width: 75%; padding: 0.875rem 1rem; border-radius: var(--radius); line-height: 1.6; font-size: 0.925rem; white-space: pre-wrap; }
.message.user { background: var(--accent); color: white; align-self: flex-end; border-bottom-right-radius: 2px; }
.message.assistant { background: var(--bg2); border: 1px solid var(--border); align-self: flex-start; border-bottom-left-radius: 2px; }

/* Input */
.chat-input-area { padding: 1rem 1.5rem 1.25rem; border-top: 1px solid var(--border); }
#chat-form { display: flex; gap: 0.75rem; align-items: flex-end; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem; }
#chat-form:focus-within { border-color: var(--accent); }
#msg-input { flex: 1; background: none; border: none; color: var(--text); font-size: 0.95rem; resize: none; outline: none; font-family: inherit; line-height: 1.5; max-height: 200px; }
#send-btn { background: var(--accent); color: white; border: none; border-radius: 6px; padding: 0.5rem 1rem; cursor: pointer; font-size: 0.875rem; flex-shrink: 0; }
#send-btn:hover:not(:disabled) { background: var(--accent-hover); }
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Topbar (mobile) */
.chat-topbar { display: none; align-items: center; gap: 0.75rem; padding: 0.6rem 1rem; background: var(--bg2); border-bottom: 1px solid var(--border); padding-top: calc(0.6rem + env(safe-area-inset-top)); }
.btn-burger { background: none; border: none; font-size: 1.4rem; color: var(--text); cursor: pointer; padding: 0.25rem 0.5rem; }
.topbar-title { font-weight: 600; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-overlay { display: none; }

/* Compte */
.section-title { font-size: 1rem; margin: 1.5rem 0 0.75rem; }
.danger-title { color: #a33; }
.btn-danger { background: #a33 !important; }
.btn-danger:hover { background: #822 !important; }
.notice { background: var(--bg3); border: 1px solid var(--accent); border-radius: var(--radius); padding: 0.75rem; margin-bottom: 1rem; font-size: 0.875rem; }

/* ===== Mobile-first (PWA) ===== */
@media (max-width: 768px) {
    .chat-topbar { display: flex; }
    .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 30; transform: translateX(-100%); transition: transform 0.25s ease; width: 80vw; max-width: 320px; box-shadow: 2px 0 12px rgba(0,0,0,0.15); padding-top: env(safe-area-inset-top); }
    body.drawer-open .sidebar { transform: translateX(0); }
    .drawer-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 20; opacity: 0; pointer-events: none; transition: opacity 0.25s; }
    body.drawer-open .drawer-overlay { display: block; opacity: 1; pointer-events: auto; }
    .messages { padding: 1rem; }
    .message { max-width: 88%; font-size: 1rem; }
    .btn-delete { opacity: 1; font-size: 1rem; padding: 0.25rem 0.5rem; }
    .session-item { padding: 0.85rem 0.75rem; }
    .chat-input-area { padding-bottom: calc(0.75rem + env(safe-area-inset-bottom)); }
    #send-btn { min-width: 48px; min-height: 44px; font-size: 1.2rem; }
    #msg-input { font-size: 1rem; }
    body { height: 100dvh; }
    .app { height: 100dvh; }
}

/* Bouton installation PWA */
.btn-install { margin: 0.5rem; padding: 0.7rem; background: var(--accent); color: white; border: none; border-radius: var(--radius); font-size: 0.9rem; cursor: pointer; }
.btn-install:hover { background: var(--accent-hover); }

/* Bouton installation : pleine largeur, grande cible tactile sur mobile */
@media (max-width: 768px) {
    .btn-install { margin: 0.75rem; padding: 1rem; font-size: 1.05rem; min-height: 52px; font-weight: 600; }
}
