/* =============================================================
   Atypi Chat — Feuille de style responsive (mobile-first)
   Mobile → Tablet → Desktop. Même balisage, layout adaptatif.
   ============================================================= */

:root {
    --primary-color: #6c5ce7;
    --primary-dark: #5649c0;
    --secondary-color: #a29bfe;
    --bg-color: #dfe6e9;
    --chat-bg: #ffffff;
    --text-color: #2d3436;
    --muted: #636e72;
    --message-sent: #6c5ce7;
    --message-received: #f1f2f6;
    --danger: #d63031;
    --border: #e2e8f0;
    --radius: 14px;
    --shadow: 0 12px 30px rgba(45, 52, 54, 0.12);
    --maxw-mobile: 500px;
    --maxw-tablet: 620px;
    --maxw-desktop: 980px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background:
        radial-gradient(circle at 15% 15%, rgba(108, 92, 231, 0.15), transparent 45%),
        radial-gradient(circle at 85% 85%, rgba(162, 155, 254, 0.18), transparent 45%),
        var(--bg-color);
    background-attachment: fixed;
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 100vh;
}

/* ============ Conteneur principal (chat + auth) ============ */
.container {
    width: 100%;
    max-width: var(--maxw-mobile);
    margin: 20px auto;
    background: var(--chat-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: calc(90vh - 60px);
}

/* ============ Header ============ */
header {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
}

header h1 {
    font-size: 1.3rem;
    font-weight: 700;
}

/* Ligne d'actions du header en haut du chat */
.header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    align-items: center;
}

.header-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 6px;
}

.header-brand img {
    width: 64px;
    height: 64px;
}

.header-brand .brand-name {
    font-size: 1.8rem;
    font-weight: bold;
    letter-spacing: 1px;
    line-height: 1;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.82rem;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: white;
    border-radius: 7px;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
    white-space: nowrap;
}

.btn-sm:hover {
    background: rgba(255, 255, 255, 0.32);
}

.btn-sm:active {
    transform: scale(0.96);
}

/* ============ Boutons génériques / formulaires (auth) ============ */
.auth-form {
    padding: 40px 28px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    border-radius: 6px;
    font-size: 1rem;
    overflow-y: auto;
    justify-content: center;
}

.auth-form h2 {
    text-align: center;
    margin-bottom: 8px;
    color: var(--primary-color);
}

input,
textarea {
    padding: 13px 14px;
    border: 1px solid var(--border);
    border-radius: 9px;
    font-size: 1rem;
    width: 100%;
    background: #fcfcfd;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    outline: none;
}

input:focus,
textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.15);
    background: #fff;
}

button {
    padding: 13px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 9px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
}

button:hover {
    background: var(--primary-dark);
}

button:active {
    transform: scale(0.98);
}

.link {
    text-align: center;
    font-size: 0.9rem;
}

.link a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

.link a:hover {
    text-decoration: underline;
}

.error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
    padding: 12px;
    border-radius: 8px;
    font-size: 0.9rem;
}

.success {
    background: #dcfce7;
    color: #14532d;
    border: 1px solid #bbf7d0;
    padding: 12px;
    border-radius: 8px;
    font-size: 0.9rem;
}

/* ============ UI du chat ============ */
#chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

#messages {
    flex: 1;
    padding: 18px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    background:
        linear-gradient(rgba(255,255,255,0.6), rgba(255,255,255,0.6)),
        repeating-linear-gradient(45deg, #f7f8fa 0, #f7f8fa 10px, #fbfbfc 10px, #fbfbfc 20px);
}

.message {
    max-width: 78%;
    padding: 10px 15px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.45;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    animation: msgIn 0.18s ease;
}

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

.message.sent {
    align-self: flex-end;
    background: var(--message-sent);
    color: white;
    border-bottom-right-radius: 5px;
}

.message.received {
    align-self: flex-start;
    background: var(--message-received);
    color: var(--text-color);
    border-bottom-left-radius: 5px;
}

.system-message {
    align-self: center;
    background: rgba(0, 0, 0, 0.06);
    color: var(--muted);
    font-size: 0.82rem;
    padding: 6px 14px;
    border-radius: 14px;
    text-align: center;
    max-width: 90%;
}

#input-area {
    padding: 14px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
    background: #fff;
    flex-shrink: 0;
}

#input-area input {
    flex: 1;
    border-radius: 24px;
    padding-left: 18px;
    padding-right: 18px;
}

#input-area button {
    border-radius: 24px;
    padding-left: 22px;
    padding-right: 22px;
}

#controls {
    padding: 10px;
    background: #f8f9fa;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #eee;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-danger {
    background: var(--danger);
}

.btn-danger:hover {
    background: #b02525;
}

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

/* Boutons du header à contours */
.btn-outline {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.55);
    color: white;
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.18);
}

.admin-btn {
    background: var(--secondary-color);
    border: 1px solid white;
}

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

/* ============ Footer ============ */
.site-footer {
    width: 100%;
    padding: 18px 20px;
    margin-top: auto;
    background-color: #f5f6fa;
    text-align: center;
    font-size: 0.88rem;
    color: var(--muted);
    border-top: 1px solid var(--border);
}

.site-footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.site-footer a:hover {
    text-decoration: underline;
}

.site-footer p {
    margin: 4px 0;
}

/* =============================================================
   RESPONSIVE
   ============================================================= */

/* --- Tablette (>= 500px) : container en carte arrondie --- */
@media (min-width: 500px) {
    .container {
        max-width: var(--maxw-tablet);
        height: calc(92vh - 60px);
    }

    header {
        padding: 18px 24px;
    }
}

/* --- Desktop (>= 768px) : vraie interface élargie --- */
@media (min-width: 768px) {
    body {
        padding: 12px;
    }

    .container {
        max-width: var(--maxw-desktop);
        height: calc(94vh - 80px);
        border-radius: 18px;
    }

    /* Header desktop : marque à gauche, actions à droite */
    header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 16px;
        padding: 16px 28px;
    }

    .header-brand {
        flex-direction: row;
        align-items: center;
        gap: 14px;
        text-align: left;
    }

    .header-brand img {
        width: 52px;
        height: 52px;
        margin-bottom: 0 !important;
    }

    .header-brand .brand-name {
        font-size: 1.6rem;
        margin-bottom: 0 !important;
    }

    .header-actions {
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 8px;
    }

    .btn-sm {
        font-size: 0.85rem;
        padding: 7px 14px;
    }

    /* Messages : largeur plus raisonnable sur grand écran */
    .message {
        max-width: 55%;
        font-size: 1rem;
    }

    #messages {
        padding: 24px 28px;
    }

    .auth-form {
        padding: 50px 44px;
    }
}

/* --- Très grand écran (>= 1200px) : centrage large mais pas étiré --- */
@media (min-width: 1200px) {
    .container {
        max-width: 1040px;
    }

    .message {
        max-width: 50%;
    }
}

/* --- Hauteur réduite (landscape / écrans courts) : éviter le débordement --- */
@media (max-height: 560px) and (min-width: 500px) {
    .container {
        height: calc(100vh - 40px);
    }
    .header-brand img { width: 40px; height: 40px; }
    .header-brand .brand-name { font-size: 1.3rem; }
}

/* --- Réductions mobiles : bord à bord (garde le style PWA actuel) --- */
@media (max-width: 499px) {
    .container {
        height: calc(100vh - 70px);
        min-height: auto;
        border-radius: 0;
        margin: 0 auto;
        max-width: 100%;
    }

    body {
        justify-content: flex-start;
        padding: 0;
    }

    header {
        padding: 14px;
    }

    .header-actions {
        gap: 6px;
    }
}
