:root {
    --bg-main: #0b0c10;
    --bg-secondary: #1f2833;
    --primary: #66fcf1;
    --primary-dark: #45a29e;
    --text-main: #c5c6c7;
    --text-white: #ffffff;
    --error: #ff4d4f;
    --card-bg: rgba(31, 40, 51, 0.7);
    --border: rgba(102, 252, 241, 0.2);
    --bubble-sent: rgba(102, 252, 241, 0.15);
    --bubble-rcvd: rgba(255, 255, 255, 0.05);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    /* Optional sleek background effect */
    background: radial-gradient(circle at top right, #1f2833 0%, #0b0c10 100%);
}

.glassmorphism {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

/* Auth Pages */
.auth-page { padding: 20px; }
.auth-container {
    width: 100%;
    max-width: 400px;
    padding: 40px;
    text-align: center;
}

.auth-container h1 {
    color: var(--primary);
    margin-bottom: 10px;
    font-weight: 700;
}

.subtitle {
    margin-bottom: 30px;
    font-size: 0.9rem;
    color: #a0a0a0;
}

.input-group {
    margin-bottom: 20px;
    text-align: left;
}
.input-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.85rem;
    color: var(--text-main);
}
.input-group input {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.2);
    color: var(--text-white);
    outline: none;
    transition: all 0.3s ease;
}
.input-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 8px rgba(102, 252, 241, 0.3);
}

.btn {
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    display: inline-block;
}

.primary-btn {
    background-color: var(--primary);
    color: var(--bg-main);
}
.primary-btn:hover:not(:disabled) {
    background-color: var(--primary-dark);
    transform: translateY(-2px);
}
.primary-btn:disabled {
    background: #444;
    color: #888;
    cursor: not-allowed;
}

.warning-btn {
    background-color: #fca311;
    color: #14213d;
}
.warning-btn:hover { background-color: #e59310; transform: translateY(-2px); }

.secondary-btn {
    background-color: transparent;
    color: var(--text-main);
    border: 1px solid var(--border);
}
.secondary-btn:hover { background-color: rgba(255,255,255,0.1); }

.admin-link {
    display: inline-block;
    margin-top: 20px;
    color: var(--primary-dark);
    text-decoration: none;
    font-size: 0.85rem;
    transition: color 0.3s;
}
.admin-link:hover { color: var(--primary); }

.alert {
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 0.9rem;
}
.error { background: rgba(255, 77, 79, 0.2); color: var(--error); border: 1px solid rgba(255,77,79,0.3); }

.hidden { display: none !important; }

/* Admin Page */
.admin-page { align-items: flex-start; padding-top: 20px; flex-direction: column; width: 100%; }

.navbar {
    width: 95%;
    max-width: 1000px;
    margin: 0 auto 20px auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 30px;
    background: var(--card-bg);
    border-radius: 12px;
    border: 1px solid var(--border);
}
.navbar-brand { font-size: 1.2rem; font-weight: 700; color: var(--primary); }
.user-count { margin-right: 20px; font-weight: 500; }
.logout-btn { padding: 8px 16px; background: rgba(255,255,255,0.1); color: var(--text-white); width: auto; }
.logout-btn:hover { background: rgba(255,0,0,0.5); }

.main-admin-container {
    width: 95%; max-width: 1000px; margin: 0 auto;
}

.card-header {
    display: flex; justify-content: space-between; align-items: center; padding: 20px 30px;
    border-bottom: 1px solid var(--border);
}
.card-header h2 { font-size: 1.2rem; color: var(--text-white); }
.card-header .btn { width: auto; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 15px 30px; text-align: left; border-bottom: 1px solid rgba(255,255,255,0.05); }
th { font-weight: 600; color: var(--primary-dark); text-transform: uppercase; font-size: 0.85rem; }
td code { background: rgba(0,0,0,0.3); padding: 4px 8px; border-radius: 4px; color: var(--primary); }

.delete-btn { background: rgba(255, 77, 79, 0.1); color: var(--error); width: auto; padding: 6px 12px; font-size: 0.85rem;}
.delete-btn:hover { background: rgba(255, 77, 79, 0.4); color: white; }

.modal {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
    display: flex; justify-content: center; align-items: center; z-index: 1000;
}
.modal-content {
    padding: 30px; width: 400px;
}
.modal-content h3 { margin-bottom: 20px; color: var(--primary); }
.modal-actions { display: flex; gap: 10px; margin-top: 25px; }

/* Chat Page */
.chat-page { 
    height: 100vh; overflow: hidden; padding: 0; align-items: stretch;
}

.chat-container {
    width: 100%; max-width: 1200px; 
    margin: 20px auto; 
    display: flex; flex-direction: column;
    border-radius: 20px;
    height: calc(100vh - 40px);
}

.chat-header {
    padding: 15px 25px;
    border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
}

.user-info { display: flex; align-items: center; gap: 15px; }
.avatar {
    width: 45px; height: 45px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--bg-main); font-weight: 700; font-size: 1.2rem;
    display: flex; justify-content: center; align-items: center;
}
.user-info .details { display: flex; flex-direction: column; }
.user-info .name { font-weight: 600; color: var(--text-white); font-size: 1.1rem; }
.user-info .status { font-size: 0.8rem; color: #4ade80; }

.messages-area {
    flex: 1; overflow-y: auto; padding: 25px;
    display: flex; flex-direction: column; gap: 15px;
    scroll-behavior: smooth;
}
.messages-area::-webkit-scrollbar { width: 6px; }
.messages-area::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }

.message {
    display: flex; flex-direction: column;
    max-width: 70%;
    animation: fadeIn 0.3s ease forwards;
}
@keyframes fadeIn { from {opacity: 0; transform: translateY(10px);} to {opacity:1; transform: translateY(0);} }

.message.sent { align-self: flex-end; }
.message.rcvd { align-self: flex-start; }

.msg-sender { font-size: 0.75rem; color: #888; margin-bottom: 4px; margin-left: 5px; }
.message.sent .msg-sender { display: none; }

.msg-content {
    padding: 12px 18px;
    border-radius: 18px;
    font-size: 0.95rem; line-height: 1.4;
    word-break: break-word;
}
.message.sent .msg-content {
    background: var(--primary);
    color: var(--bg-main);
    border-bottom-right-radius: 4px;
}
.message.rcvd .msg-content {
    background: var(--bubble-rcvd);
    border: 1px solid rgba(255,255,255,0.1);
    border-bottom-left-radius: 4px;
}

/* Media styling inside messages */
.msg-content img, .msg-content video {
    max-width: 100%; border-radius: 10px; margin-top: 5px; cursor: pointer;
}
.msg-content audio {
    width: 250px; outline: none; margin-top: 5px;
}
.msg-timestamp {
    font-size: 0.7rem; color: #888; align-self: flex-end; margin-top: 5px;
}

.input-area {
    padding: 15px 25px;
    border-top: 1px solid var(--border);
    background: rgba(0,0,0,0.2);
    border-bottom-left-radius: 20px;
    border-bottom-right-radius: 20px;
    position: relative;
}

.chat-form {
    display: flex; align-items: center; gap: 10px;
}

#message-input {
    flex: 1; padding: 14px 20px;
    border-radius: 30px; border: 1px solid var(--border);
    background: rgba(255,255,255,0.05); color: white;
    outline: none; transition: border 0.3s;
}
#message-input:focus { border-color: var(--primary); }

.icon-btn {
    width: 45px; height: 45px; border-radius: 50%;
    background: rgba(255,255,255,0.05); color: var(--text-main);
    display: flex; justify-content: center; align-items: center;
    font-size: 1.2rem; cursor: pointer; border: 1px solid transparent;
}
.icon-btn:hover { background: rgba(255,255,255,0.1); border-color: var(--border); color: var(--primary); }

.send-btn { width: auto; padding: 12px 25px; border-radius: 30px; }

.pulse-record {
    color: #ff4d4f; font-weight: 600; font-size: 0.9rem;
    animation: pulsate 1s infinite alternate;
}
@keyframes pulsate { from {opacity: 1;} to {opacity: 0.3;} }

.file-preview-area {
    position: absolute; bottom: 85px; left: 25px;
    background: var(--card-bg); padding: 8px 15px;
    border-radius: 8px; border: 1px solid var(--primary);
    display: flex; align-items: center; gap: 10px; font-size: 0.85rem;
    z-index: 10;
}
#clear-preview {
    background: none; border: none; color: white; cursor: pointer; font-size: 1.2rem;
}

/* Overlay Loading */
#uploading-overlay {
    position: absolute; inset: 0;
    background: rgba(0,0,0,0.8); backdrop-filter: blur(5px);
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    border-radius: 20px; z-index: 50;
}
.spinner {
    width: 40px; height: 40px; border: 4px solid rgba(255,255,255,0.1);
    border-top-color: var(--primary); border-radius: 50%;
    animation: spin 1s linear infinite; margin-bottom: 15px;
}
@keyframes spin { to {transform: rotate(360deg);} }

/* Typing Indicator */
.typing-indicator {
    font-size: 0.8rem;
    color: var(--primary);
    margin-top: 5px;
    height: 15px;
    opacity: 0;
    transition: opacity 0.3s;
    font-style: italic;
    padding-left: 10px;
}
.typing-indicator.visible { opacity: 1; }

/* Responsive Fou Furieux */
@media (max-width: 768px) {
    .chat-container {
        margin: 0; border-radius: 0; height: 100vh;
        border: none;
    }
    .chat-header {
        padding: 10px 15px;
    }
    .messages-area {
        padding: 15px;
    }
    .message { max-width: 85%; }
    .input-area {
        padding: 10px 15px;
        border-radius: 0;
    }
    #message-input { padding: 10px 15px; }
    .icon-btn { width: 35px; height: 35px; font-size: 1rem; }
    .send-btn { padding: 8px 15px; font-size: 0.9rem; }
    .file-preview-area { bottom: 70px; }
    
    .navbar { flex-direction: column; gap: 10px; text-align: center; }
    .user-count { margin-right: 0; margin-bottom: 10px; display: block; }
    
    .modal-content { width: 90%; padding: 20px; }
    
    table, thead, tbody, th, td, tr { display: block; }
    thead tr { position: absolute; top: -9999px; left: -9999px; }
    tr { border: 1px solid var(--border); margin-bottom: 10px; border-radius: 8px; }
    td { border: none; position: relative; padding-left: 50%; text-align: right; }
    td:before { 
        position: absolute; top: 15px; left: 15px; width: 45%; padding-right: 10px; 
        white-space: nowrap; text-align: left; font-weight: 600; color: var(--primary-dark);
    }
    td:nth-of-type(1):before { content: "Nom"; }
    td:nth-of-type(2):before { content: "PIN"; }
    td:nth-of-type(3):before { content: "Actions"; }
}
@media (max-width: 480px) {
    .message { max-width: 95%; }
    .chat-form { gap: 5px; }
    .icon-btn { width: 30px; height: 30px; font-size: 0.9rem; }
}
