:root {
    --primary: #1a1a1a;
    --secondary: #f4f4f4;
    --accent: #ff4757;
    --accent-dark: #e63946;
    --border: #e0e0e0;
    --text-primary: #1a1a1a;
    --text-secondary: #666;
    --text-light: #999;
    --bg-hover: #f9f9f9;
    --shadow: rgba(0, 0, 0, 0.08);
    --success: #2ecc71;
}

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

body {
    font-family: 'IBM Plex Sans', sans-serif;
    background: linear-gradient(135deg, #fafafa 0%, #f0f0f0 100%);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

.container {
    display: grid;
    grid-template-columns: 360px 1fr;
    height: 100vh;
    max-width: 1600px;
    margin: 0 auto;
    background: white;
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.1);
}

/* SIDEBAR */
.sidebar {
    background: linear-gradient(180deg, #ffffff 0%, #fafafa 100%);
    border-right: 2px solid var(--border);
    display: flex;
    flex-direction: column;
    position: relative;
    height: 100vh;
    max-height: 100vh;
}

.sidebar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, var(--accent), var(--accent-dark));
}

.header {
    padding: 28px 24px;
    border-bottom: 1px solid var(--border);
    background: white;
    flex-shrink: 0;
}

.header h1 {
    font-family: 'Playfair Display', serif;
    font-size: 28px;
    font-weight: 900;
    letter-spacing: -0.5px;
    color: var(--primary);
    margin-bottom: 4px;
}

.header .subtitle {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.search-box {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: white;
    flex-shrink: 0;
}

.search-box input {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 14px;
    transition: all 0.2s ease;
    background: var(--secondary);
}

.search-box input:focus {
    outline: none;
    border-color: var(--accent);
    background: white;
    box-shadow: 0 0 0 3px rgba(255, 71, 87, 0.1);
}

.conversations {
    flex: 1 1 0;
    overflow-y: scroll;
    overflow-x: hidden;
    padding: 8px 0;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

.conversation-item {
    padding: 16px 24px;
    cursor: pointer;
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
    position: relative;
    animation: slideIn 0.3s ease;
    min-height: 80px;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.conversation-item:hover {
    background: var(--bg-hover);
    border-left-color: var(--accent);
}

.conversation-item.active {
    background: linear-gradient(90deg, rgba(255, 71, 87, 0.08) 0%, transparent 100%);
    border-left-color: var(--accent);
}

.conversation-item.active::after {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 40%;
    background: var(--accent);
    border-radius: 10px 0 0 10px;
}

.conv-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 6px;
}

.conv-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--text-primary);
}

.conv-time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--text-light);
    letter-spacing: 0.5px;
}

.conv-preview {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.unread-badge {
    display: inline-block;
    background: var(--accent);
    color: white;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
    margin-top: 6px;
}

/* BOUTON RETOUR MOBILE */
.mobile-back-btn {
    display: none;
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 1000;
    background: white;
    border: 1.5px solid var(--border);
    padding: 6px 12px;
    border-radius: 8px;
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* MAIN CHAT AREA */
.chat-area {
    display: flex;
    flex-direction: column;
    background: white;
    position: relative;
    height: 100vh;
    max-height: 100vh;
}

#chatContainer {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    flex: 1;
}

.chat-header {
    flex-shrink: 0;
    padding: 24px 32px;
    border-bottom: 2px solid var(--border);
    background: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.chat-user-info h2 {
    font-family: 'Playfair Display', serif;
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 2px;
}

.chat-user-status {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--success);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.chat-actions {
    display: flex;
    gap: 8px;
}

.action-btn {
    background: none;
    border: 1.5px solid var(--border);
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.action-btn:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
}

.messages-container {
    flex: 1 1 0;
    overflow-y: scroll;
    overflow-x: hidden;
    padding: 32px;
    background: linear-gradient(180deg, #fafafa 0%, #ffffff 50%);
    position: relative;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

.messages-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 200px;
    background: linear-gradient(180deg, rgba(255, 71, 87, 0.02) 0%, transparent 100%);
    pointer-events: none;
}

.message {
    margin-bottom: 24px;
    display: flex;
    animation: messageIn 0.3s ease;
}

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

.message.received {
    justify-content: flex-start;
}

.message.sent {
    justify-content: flex-end;
}

.message-content {
    max-width: 65%;
    position: relative;
}

.message.received .message-bubble {
    background: white;
    border: 1.5px solid var(--border);
    border-radius: 0 16px 16px 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.message.sent .message-bubble {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    color: white;
    border-radius: 16px 0 16px 16px;
    box-shadow: 0 4px 12px rgba(255, 71, 87, 0.25);
}

.message-bubble {
    padding: 14px 18px;
    font-size: 14px;
    line-height: 1.6;
}

.message-time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--text-light);
    margin-top: 6px;
    letter-spacing: 0.5px;
}

.message.sent .message-time {
    color: rgba(255, 255, 255, 0.7);
    text-align: right;
}

.message-image {
    border-radius: 12px;
    max-width: 100%;
    max-height: 400px;
    object-fit: cover;
    margin-bottom: 8px;
    cursor: pointer;
    transition: transform 0.2s ease;
    display: block;
}

.message-image:hover {
    transform: scale(1.02);
}

.message-images-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
    margin-bottom: 8px;
}

.message-images-grid .message-image {
    width: 100%;
    height: 150px;
    object-fit: cover;
}

/* INPUT AREA */
.input-area {
    padding: 24px 32px;
    border-top: 2px solid var(--border);
    background: white;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.04);
    position: relative;
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.input-controls {
    display: flex;
    gap: 8px;
}

.input-controls button {
    width: 44px;
    height: 44px;
    border: 1.5px solid var(--border);
    background: white;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.input-controls button:hover {
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-2px);
}

.message-input-wrapper {
    flex: 1;
    position: relative;
}

.message-input {
    width: 100%;
    padding: 14px 18px;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 14px;
    resize: none;
    max-height: 120px;
    transition: all 0.2s ease;
    background: var(--secondary);
}

.message-input:focus {
    outline: none;
    border-color: var(--accent);
    background: white;
    box-shadow: 0 0 0 3px rgba(255, 71, 87, 0.1);
}

.send-button {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    border: none;
    border-radius: 10px;
    color: white;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(255, 71, 87, 0.3);
}

.send-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(255, 71, 87, 0.4);
}

.send-button:active {
    transform: translateY(0);
}

/* EMOJI PICKER */
.emoji-picker {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 12px;
    background: white;
    border: 2px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    padding: 16px;
    max-width: 90vw;
    width: 360px;
    animation: slideUp 0.2s ease;
    z-index: 100;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 8px;
    max-height: 250px;
    overflow-y: auto;
}

.emoji-item {
    font-size: 28px;
    padding: 8px;
    cursor: pointer;
    border-radius: 8px;
    text-align: center;
    transition: all 0.15s ease;
}

.emoji-item:hover {
    background: var(--bg-hover);
    transform: scale(1.2);
}

/* IMAGE PREVIEW */
.image-preview-container {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: white;
    border-top: 2px solid var(--border);
    padding: 16px;
    animation: slideUp 0.2s ease;
    max-height: 300px;
    overflow-y: auto;
}

.image-preview-wrapper {
    position: relative;
    display: inline-block;
    max-width: 100%;
}

#imagePreview {
    max-width: 100%;
    max-height: 200px;
    border-radius: 12px;
    object-fit: contain;
}

.image-preview-close {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--accent);
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.image-caption-input {
    width: 100%;
    margin-top: 12px;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 14px;
}

/* LIGHTBOX */
.lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 10000;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.2s ease;
}

.lightbox.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.lightbox-close {
    position: absolute;
    top: 24px;
    right: 24px;
    background: white;
    border: none;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    z-index: 10001;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

#lightboxImage {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    border-radius: 8px;
}

.lightbox-controls {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 12px;
}

.lightbox-controls button {
    background: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-family: 'IBM Plex Sans', sans-serif;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* EMPTY STATE */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 80px;
    margin-bottom: 24px;
    opacity: 0.3;
}

.empty-state h3 {
    font-family: 'Playfair Display', serif;
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.empty-state p {
    font-size: 14px;
    color: var(--text-light);
}

/* SCROLLBAR */
::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: #f5f5f5;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: #c0c0c0;
    border-radius: 10px;
    border: 2px solid #f5f5f5;
}

::-webkit-scrollbar-thumb:hover {
    background: #a0a0a0;
}

::-webkit-scrollbar-thumb:active {
    background: #808080;
}

/* Scrollbar pour Firefox */
* {
    scrollbar-width: auto;
    scrollbar-color: #c0c0c0 #f5f5f5;
}

/* FILE INPUT HIDDEN */
#fileInput {
    display: none;
}

/* RESPONSIVE MOBILE */
@media (max-width: 768px) {
    .container {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: relative;
    }

    .sidebar.hidden {
        display: none;
    }

    .chat-area.hidden {
        display: none;
    }

    .mobile-back-btn {
        display: block;
    }

    .header h1 {
        font-size: 24px;
    }

    .chat-header {
        padding: 16px;
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .chat-user-info {
        width: 100%;
        display: flex;
        align-items: center;
        gap: 12px;
    }

    .chat-user-info h2 {
        font-size: 18px;
        margin-left: 80px;
    }

    .chat-user-status {
        margin-left: 80px;
    }

    .chat-actions {
        gap: 4px;
        position: absolute;
        top: 16px;
        right: 16px;
    }

    .action-btn {
        padding: 8px 12px;
        font-size: 16px;
    }

    .messages-container {
        padding: 16px;
    }

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

    .input-area {
        padding: 16px;
    }

    .input-controls button {
        width: 40px;
        height: 40px;
    }

    .send-button {
        width: 40px;
        height: 40px;
    }

    .emoji-picker {
        width: calc(100vw - 32px);
    }

    .empty-state-icon {
        font-size: 60px;
    }

    .empty-state h3 {
        font-size: 22px;
    }
}

@media (max-width: 480px) {
    .header {
        padding: 20px 16px;
    }

    .search-box {
        padding: 12px 16px;
    }

    .conversation-item {
        padding: 12px 16px;
    }

    .input-wrapper {
        gap: 8px;
    }

    .input-controls {
        gap: 4px;
    }

    .emoji-item {
        font-size: 24px;
    }

    .chat-header {
        padding: 12px;
    }

    .chat-user-info h2 {
        font-size: 16px;
        margin-left: 75px;
    }

    .chat-user-status {
        font-size: 10px;
        margin-left: 75px;
    }

    .chat-actions {
        top: 12px;
        right: 12px;
    }

    .action-btn {
        padding: 6px 10px;
        font-size: 14px;
    }

    .messages-container {
        padding: 12px;
    }

    .input-area {
        padding: 12px;
    }

    .mobile-back-btn {
        top: 12px;
        left: 12px;
        padding: 5px 10px;
        font-size: 13px;
    }
}