/* ============================================
   MON ÉQUIPE TRANQUILLE — style.css
   Thème sombre, inspiration FaceTime / iMessage
   ============================================ */

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

/* --- Variables --- */
:root {
    --bg-app: #000000;
    --bg-sidebar: #1c1c1e;
    --bg-chat: #000000;
    --bg-avatar: #0a0a0a;
    --bg-input: #1c1c1e;
    --bg-bubble-user: #0b84fe;
    --bg-bubble-contact: #26252a;
    --bg-hover: #2c2c2e;

    --text-primary: #ffffff;
    --text-secondary: #8e8e93;
    --text-muted: #636366;

    --border: #2c2c2e;
    --accent: #7C6DAF;

    --sidebar-w: 280px;
    --avatar-w: 380px;
    --header-h: 56px;

    --radius-bubble: 18px;
    --transition: 0.2s ease;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-app);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ============================================
   LAYOUT PRINCIPAL
   ============================================ */

#app {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ============================================
   SIDEBAR
   ============================================ */

#sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

#sidebar-header {
    height: var(--header-h);
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.sidebar-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 2px;
}

#btn-close-sidebar {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
}

#contacts-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

/* --- Contact item --- */
.contact-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    gap: 12px;
    cursor: pointer;
    transition: background var(--transition);
    border-left: 3px solid transparent;
}

.contact-item:hover {
    background: var(--bg-hover);
}

.contact-item.active {
    background: rgba(124, 109, 175, 0.12);
    border-left-color: var(--accent);
}

.contact-avatar-small {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 17px;
    color: #ffffff;
    flex-shrink: 0;
    position: relative;
}

.sidebar-status-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    background: #30d158;
    border-radius: 50%;
    border: 2px solid var(--bg-sidebar);
    transition: background 0.3s;
}

.sidebar-status-dot.absent {
    background: #FFD60A;
}

.contact-info {
    flex: 1;
    min-width: 0;
}

.contact-name {
    font-size: 15px;
    font-weight: 600;
}

.contact-role {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 1px;
}

.contact-preview {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- Version --- */
#app-version {
    padding: 12px 16px;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.6);
    text-align: left;
    flex-shrink: 0;
}

/* ============================================
   ZONE PRINCIPALE
   ============================================ */

#main {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* ============================================
   ZONE CHAT
   ============================================ */

#chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* --- Header chat --- */
#chat-header {
    height: var(--header-h);
    padding: 0 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-chat);
    flex-shrink: 0;
}

#btn-menu {
    display: none;
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    padding: 4px;
}

#chat-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    color: #ffffff;
    flex-shrink: 0;
}

#chat-header-info {
    display: flex;
    flex-direction: column;
}

#chat-header-name {
    font-size: 15px;
    font-weight: 600;
}

#chat-header-status {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0;
}

.status-dot {
    width: 7px;
    height: 7px;
    background: #30d158;
    border-radius: 50%;
    display: inline-block;
    margin-right: 5px;
    transition: background 0.3s;
}

.status-dot.absent {
    background: #FFD60A;
}

/* --- Messages --- */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.message-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
    position: relative;
}

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

.message-wrapper.contact {
    align-self: flex-start;
}

.btn-delete-msg {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
    flex-shrink: 0;
}

.message-wrapper:hover .btn-delete-msg {
    opacity: 1;
}

.btn-delete-msg:hover {
    color: #ff453a;
}

.message {
    max-width: 65%;
    padding: 10px 14px;
    border-radius: var(--radius-bubble);
    font-size: 15px;
    line-height: 1.45;
    word-wrap: break-word;
    animation: msgIn 0.2s ease;
}

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

.message.user {
    background: var(--bg-bubble-user);
    color: #ffffff;
    border-bottom-right-radius: 6px;
}

.message.contact {
    background: var(--bg-bubble-contact);
    color: var(--text-primary);
    border-bottom-left-radius: 6px;
}

/* Espacement entre groupes de messages */
.message-wrapper.user + .message-wrapper.contact,
.message-wrapper.contact + .message-wrapper.user {
    margin-top: 10px;
}

/* --- Typing indicator --- */
.typing-indicator {
    align-self: flex-start;
    padding: 14px 18px;
    background: var(--bg-bubble-contact);
    border-radius: var(--radius-bubble);
    border-bottom-left-radius: 6px;
    display: flex;
    gap: 5px;
    animation: msgIn 0.2s ease;
}

.typing-dot {
    width: 7px;
    height: 7px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
}

/* --- Welcome --- */
.welcome-message {
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    padding: 60px 20px 20px;
    line-height: 1.7;
}

/* --- Date separator --- */
.date-separator {
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    padding: 12px 0 6px;
}

/* --- Error --- */
.error-message {
    text-align: center;
    color: #ff453a;
    font-size: 13px;
    padding: 10px 16px;
    background: rgba(255, 69, 58, 0.08);
    border-radius: 12px;
    margin: 8px auto;
    max-width: 85%;
}

/* --- Zone de saisie --- */
#input-area {
    padding: 10px 16px 14px;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    border-top: 1px solid var(--border);
    background: var(--bg-chat);
    flex-shrink: 0;
}

#message-input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 10px 18px;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
    outline: none;
    transition: border-color var(--transition);
}

#message-input:focus {
    border-color: var(--accent);
}

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

#btn-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity var(--transition), transform var(--transition);
}

#btn-send:hover:not(:disabled) {
    opacity: 0.85;
}

#btn-send:active:not(:disabled) {
    transform: scale(0.92);
}

#btn-send:disabled {
    opacity: 0.3;
    cursor: default;
}

/* ============================================
   ZONE AVATAR (panneau droit)
   ============================================ */

#resize-handle {
    width: 6px;
    cursor: col-resize;
    background: transparent;
    flex-shrink: 0;
    transition: background 0.15s;
    position: relative;
    z-index: 10;
}

#resize-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 40px;
    border-radius: 1px;
    background: var(--border);
    transition: background 0.15s, height 0.15s;
}

#resize-handle:hover::after,
#resize-handle.dragging::after {
    background: var(--accent);
    height: 60px;
}

#avatar-area {
    width: var(--avatar-w);
    min-width: 200px;
    background: var(--bg-avatar);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
}

#avatar-frame {
    width: 100%;
    max-width: 420px;
    aspect-ratio: 3 / 4;
    border-radius: 24px;
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.4s ease;
}

#avatar-image {
    font-size: 90px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.85);
    user-select: none;
}

#avatar-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 50px 16px 20px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.75) 0%, transparent 100%);
    text-align: center;
}

#avatar-display-name {
    display: block;
    font-size: 22px;
    font-weight: 600;
    color: #ffffff;
}

#avatar-display-role {
    display: block;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.65);
    margin-top: 4px;
}

/* ============================================
   SCROLLBAR
   ============================================ */

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

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

/* Écrans moyens */
@media (max-width: 1100px) {
    :root {
        --avatar-w: 280px;
        --sidebar-w: 240px;
    }
    #avatar-image { font-size: 70px; }
}

/* Tablette : masquer avatar + resize */
@media (max-width: 900px) {
    #avatar-area { display: none; }
    #resize-handle { display: none; }
}

/* Mobile */
@media (max-width: 768px) {
    :root {
        --sidebar-w: 100%;
    }

    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    #sidebar.open {
        transform: translateX(0);
    }

    #btn-close-sidebar {
        display: block;
    }

    #btn-menu {
        display: block;
    }

    #avatar-area {
        display: none;
    }

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