/* =========================================================
   Videochat — design sombre
   ========================================================= */

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

:root {
    --bg-page:      #0d0d0d;
    --bg-surface:   #1a1a1a;
    --bg-elevated:  #242424;
    --border:       #2e2e2e;
    --text-primary: #f0f0f0;
    --text-muted:   #888;
    --accent:       #4f8ef7;
    --accent-hover: #3a7ae0;
    --danger:       #e05454;
    --danger-hover: #c43c3c;
    --success:      #4caf7d;
    --radius:       8px;
    --font:         'Segoe UI', system-ui, sans-serif;
}

html, body {
    height: 100%;
    background: var(--bg-page);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
}

/* Layout ------------------------------------------------- */

.layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Topbar ------------------------------------------------- */

.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    height: 56px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.logo {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent);
    margin-right: auto;
}

.user-info {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Zone principale --------------------------------------- */

.content-area {
    display: flex;
    flex: 1;
    min-height: 0;
}

/* Colonne vidéos (gauche, 320 px fixe) ------------------- */

.video-col {
    width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: #000;
}

#remoteVideo {
    width: 320px;
    height: 240px;
    object-fit: cover;
    display: block;
    flex-shrink: 0;
}

#localVideo {
    width: 320px;
    height: 240px;
    object-fit: cover;
    display: block;
    flex-shrink: 0;
    border-top: 2px solid #111;
}

.local-label {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 4px 0 6px;
    background: #000;
    flex-shrink: 0;
}

/* Colonne droite (flexible) ------------------------------ */

.side-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    border-left: 1px solid var(--border);
}

/* Chat panel --------------------------------------------- */

.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--bg-surface);
}

.chat-panel__header {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.chat-messages::-webkit-scrollbar       { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.chat-msg {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-width: 90%;
    align-self: flex-start;
}

.chat-msg--self {
    align-self: flex-end;
    align-items: flex-end;
}

.chat-msg--system {
    align-self: center;
    max-width: 100%;
}

.chat-msg__meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    padding: 0 4px;
}

.chat-msg__bubble {
    background: var(--bg-elevated);
    color: var(--text-primary);
    padding: 6px 10px;
    border-radius: 10px;
    font-size: 0.88rem;
    line-height: 1.4;
    word-break: break-word;
    white-space: pre-wrap;
}

.chat-msg--self .chat-msg__bubble {
    background: var(--accent);
    color: #fff;
}

.chat-msg--system .chat-msg__bubble {
    background: transparent;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-style: italic;
    padding: 2px 0;
}

.chat-input-row {
    display: flex;
    gap: 6px;
    padding: 10px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-input-row input {
    flex: 1;
    padding: 8px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.88rem;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.15s;
    min-width: 0;
}

.chat-input-row input::placeholder { color: #555; }
.chat-input-row input:focus        { border-color: var(--accent); }
.chat-input-row input:disabled     { opacity: 0.4; cursor: not-allowed; }

.btn-send {
    padding: 8px 12px;
    font-size: 1rem;
    line-height: 1;
    flex-shrink: 0;
}

/* Status bar --------------------------------------------- */

.status-bar {
    padding: 8px 16px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
    color: var(--text-muted);
    text-align: center;
    flex-shrink: 0;
}

.status-bar.connecting { color: var(--accent); }
.status-bar.connected  { color: var(--success); }
.status-bar.error      { color: var(--danger); }

/* Controls ----------------------------------------------- */

.controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.controls-divider {
    width: 1px;
    height: 28px;
    background: var(--border);
    margin: 0 4px;
}

/* Barre badge en ligne ------------------------------------ */

.online-bar {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
    flex-shrink: 0;
}

/* Badge en ligne ----------------------------------------- */

.badge-online {
    font-size: 0.78rem;
    color: var(--success);
    background: rgba(76, 175, 125, 0.12);
    border: 1px solid rgba(76, 175, 125, 0.3);
    padding: 3px 10px;
    border-radius: 20px;
}

/* Boutons mobile-only — masqués sur desktop -------------- */

.btn-mobile-chat { display: none; }

.btn-close-chat {
    display: none;
    margin-left: auto;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1rem;
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
}
.btn-close-chat:hover { color: var(--text-primary); }

/* Buttons ------------------------------------------------ */

.btn {
    padding: 10px 28px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:not(:disabled):hover { background: var(--accent-hover); }

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border);
}
.btn-secondary:not(:disabled):hover { background: #2e2e2e; }

.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:not(:disabled):hover { background: var(--danger-hover); }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    text-decoration: none;
    font-size: 0.85rem;
    padding: 6px 14px;
    border-radius: var(--radius);
    display: inline-flex;
    align-items: center;
}
.btn-ghost:hover { color: var(--text-primary); border-color: #555; }

/* Bouton muted (micro/cam OFF) --------------------------- */

.btn-muted {
    background: var(--bg-elevated);
    color: var(--danger);
    border: 1px solid rgba(224, 84, 84, 0.4);
}
.btn-muted:not(:disabled):hover {
    background: rgba(224, 84, 84, 0.1);
}

/* =========================================================
   Mobile (≤ 768 px)
   ========================================================= */

@media (max-width: 768px) {

    /* Cacher la topbar — les vidéos prennent tout l'écran */
    .topbar { display: none; }

    /* Réduire content-area à 0 ; les enfants fixed restent visibles */
    .content-area {
        flex: 0 0 0;
        min-height: 0;
        overflow: visible;
    }

    /* Colonne vidéos : collapse, les vidéos passent en fixed */
    .video-col {
        width: 0;
        height: 0;
        overflow: visible;
    }

    .local-label { display: none; }

    /* Vidéo distante : plein écran */
    #remoteVideo {
        position: fixed;
        top: 0; left: 0;
        width: 100vw;
        height: 100vh;
        object-fit: cover;
        z-index: 1;
        border-top: none;
    }

    /* Vidéo locale : incrustation bas-droite */
    #localVideo {
        position: fixed;
        bottom: 80px;
        right: 10px;
        width: 120px;
        height: 90px;
        object-fit: cover;
        border-radius: 8px;
        border: 2px solid #fff;
        border-top: 2px solid #fff;
        z-index: 3;
    }

    /* Colonne droite : collapse, enfants fixed restent visibles */
    .side-col {
        width: 0;
        height: 0;
        overflow: visible;
        border: none;
    }

    /* Status bar et badge masqués sur mobile */
    #status-bar  { display: none; }
    .online-bar  { display: none; }

    /* Micro / Caméra masqués dans la barre mobile */
    #btnMic, #btnCam { display: none; }

    /* Barre de contrôles fixe en bas */
    .controls {
        position: fixed;
        bottom: 0; left: 0;
        width: 100%;
        min-height: 50px;
        height: auto;
        z-index: 4;
        background: rgba(0, 0, 0, 0.85);
        border-top: none;
        padding: 8px 10px;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-wrap: wrap;
        gap: 6px;
    }

    .controls .btn {
        padding: 10px 14px;
        font-size: 0.85rem;
    }

    .controls-divider { display: none; }

    /* Panel chat : overlay fixe, masqué par défaut */
    .chat-panel {
        position: fixed;
        bottom: 60px; left: 0;
        width: 100%;
        height: 40vh;
        z-index: 5;
        background: rgba(0, 0, 0, 0.85);
        display: none;
        flex-direction: column;
        border: none;
        border-top: 1px solid rgba(255, 255, 255, 0.12);
    }

    .chat-panel.open { display: flex; }

    /* Boutons mobile-only visibles */
    .btn-mobile-chat {
        display: inline-flex;
        align-items: center;
    }

    .btn-close-chat { display: inline-flex; }
}

/* =========================================================
   Page d'authentification
   ========================================================= */

body.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.auth-wrap {
    width: 100%;
    max-width: 400px;
}

.auth-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) * 1.5);
    padding: 36px 32px 32px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.auth-brand {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--accent);
    text-align: center;
    letter-spacing: -0.5px;
}

/* Onglets ------------------------------------------------ */

.auth-tabs {
    display: flex;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 3px;
    gap: 3px;
}

.tab-btn {
    flex: 1;
    padding: 8px;
    background: transparent;
    border: none;
    border-radius: calc(var(--radius) - 2px);
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.tab-btn.active {
    background: var(--bg-surface);
    color: var(--text-primary);
    box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.tab-btn:not(.active):hover {
    color: var(--text-primary);
}

/* Alerte ------------------------------------------------- */

.auth-alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 0.88rem;
    line-height: 1.4;
}

.auth-alert--error {
    background: rgba(224, 84, 84, 0.12);
    border: 1px solid rgba(224, 84, 84, 0.35);
    color: #f08080;
}

.auth-alert--success {
    background: rgba(76, 175, 125, 0.12);
    border: 1px solid rgba(76, 175, 125, 0.35);
    color: #7ecfa0;
}

/* Formulaire --------------------------------------------- */

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

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

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

.field label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.field input {
    padding: 10px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: var(--font);
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

.field input::placeholder {
    color: #555;
}

.field input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79, 142, 247, 0.15);
}

.field input:invalid:not(:placeholder-shown) {
    border-color: var(--danger);
}

/* Bouton pleine largeur ---------------------------------- */

.btn-full {
    width: 100%;
    padding: 11px;
    margin-top: 4px;
}

/* Auth responsive --------------------------------------- */

@media (max-width: 440px) {
    .auth-card { padding: 28px 20px 24px; }
}
