:root {
    --bg-gradient: radial-gradient(circle at top left, #0b1a30, #144b68, #2e8b8b, #d96f42);
    --my-msg-color: #007aff;
}

* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
    font-family: system-ui, -apple-system, sans-serif; 
}

body { 
    background: var(--bg-gradient);
    background-size: cover;
    background-attachment: fixed;
    color: #ffffff; 
    display: flex; 
    flex-direction: column; 
    height: 100vh; 
    height: 100dvh; 
    overflow: hidden;
}

body.bg-dark { background: #121212; }
body.bg-matrix { background: #020202; border-top: 3px solid #00ff00; }
body.bg-purple { background: linear-gradient(135deg, #140526, #320d59); }

.hidden { display: none !important; }

#auth-screen { 
    display: flex; 
    flex-direction: column; 
    flex: 1; 
    justify-content: center; 
    align-items: center; 
    padding: 20px; 
    backdrop-filter: blur(10px);
}

#login-form { 
    background: rgba(11, 26, 48, 0.85); 
    padding: 40px 30px; 
    border-radius: 20px; 
    width: 100%; 
    max-width: 350px; 
    display: flex; 
    flex-direction: column; 
    gap: 15px; 
    box-shadow: 0 10px 30px rgba(0,0,0,0.5); 
    border: 1px solid rgba(255,255,255,0.1);
}

#login-form h2 { 
    text-align: center; 
    margin-bottom: 15px; 
    font-size: 22px;
}

input, select { 
    padding: 15px; 
    border-radius: 12px; 
    border: none; 
    background-color: rgba(255, 255, 255, 0.1); 
    color: #fff; 
    font-size: 15px; 
    outline: none; 
}

select option {
    background-color: #1e1e1e;
    color: #fff;
}

#login-form button, #save-settings-btn { 
    background-color: #007aff; 
    color: #fff; 
    padding: 15px; 
    border-radius: 12px; 
    border: none; 
    font-size: 16px; 
    font-weight: 700; 
    cursor: pointer; 
}

#delete-all-btn {
    background-color: #ff3b30; 
    color: #fff; 
    padding: 15px; 
    border-radius: 12px; 
    border: none; 
    font-size: 16px; 
    font-weight: 700; 
    cursor: pointer;
    margin-top: 5px;
}

#chat-screen { 
    display: flex; 
    flex-direction: column; 
    flex: 1; 
    height: 100%; 
}

header { 
    background: rgba(11, 26, 48, 0.9); 
    padding: 15px 20px; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.header-left { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 14px; }
.header-right { display: flex; align-items: center; gap: 10px; }

#settings-btn { background: transparent; border: none; font-size: 20px; cursor: pointer; }

#logout-btn { 
    background-color: #ff3b30; 
    color: #fff; 
    padding: 8px 16px; 
    border-radius: 20px; 
    font-size: 13px; 
    font-weight: bold;
    border: none;
    cursor: pointer;
}

#messages-container { 
    flex: 1; 
    overflow-y: auto; 
    padding: 20px; 
    display: flex; 
    flex-direction: column; 
    gap: 18px; 
}

.msg { 
    max-width: 75%; 
    padding: 12px 18px; 
    width: fit-content; 
    word-break: break-word; 
    line-height: 1.5; 
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    position: relative;
}

.msg.sent { 
    background-color: var(--my-msg-color); 
    align-self: flex-end; 
    border-radius: 20px 20px 4px 20px; 
    color: #fff; 
}

.msg.received { 
    background-color: #ffffff; 
    align-self: flex-start; 
    border-radius: 20px 20px 20px 4px; 
    color: #1c1c1e; 
}

.msg .sender { font-size: 12px; margin-bottom: 4px; font-weight: bold; color: #a9a9a9; }
.msg.received .sender { color: #007aff; }
.msg .time { font-size: 10px; opacity: 0.6; display: block; text-align: right; margin-top: 5px; }

.tag { background-color: rgba(255, 215, 0, 0.3); padding: 2px 4px; border-radius: 4px; font-weight: bold; }

.reply-quote {
    background: rgba(0, 0, 0, 0.1);
    border-left: 3px solid rgba(0, 0, 0, 0.3);
    padding: 5px 8px;
    margin-bottom: 8px;
    border-radius: 4px;
    font-size: 13px;
    opacity: 0.8;
}
.msg.sent .reply-quote { color: #eee; }

.msg-actions {
    display: flex;
    gap: 8px;
    position: absolute;
    top: -15px;
    background: #1e1e1e;
    padding: 4px 8px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 10;
}
.msg.sent .msg-actions { right: 10px; }
.msg.received .msg-actions { left: 10px; }
.msg:hover .msg-actions { opacity: 1; }

.action-btn { background: transparent; border: none; cursor: pointer; font-size: 12px; color: #fff; }

.reactions-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 5px;
}
.react-badge {
    background: rgba(255,255,255,0.2);
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 12px;
}
.msg.received .react-badge { background: rgba(0,0,0,0.05); color: #000; }

#input-container { padding: 15px; display: flex; flex-direction: column; gap: 8px; background: rgba(11,26,48,0.9); }

#reply-bar {
    background: #ffffff;
    color: #000;
    padding: 8px 15px;
    border-radius: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}
#cancel-reply-btn { background: transparent; border: none; cursor: pointer; font-weight: bold; }

#input-area { 
    background-color: #ffffff; 
    padding: 8px 10px 8px 15px; 
    display: flex; 
    gap: 10px; 
    border-radius: 30px;
    align-items: center;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
}

.input-icons { display: flex; gap: 10px; align-items: center; }
#message-input { flex: 1; background: transparent; border: none; color: #1c1c1e; padding: 10px 5px; width: 100%; }

#send-btn { 
    background-color: #007aff; 
    color: #fff; 
    padding: 10px 20px; 
    border-radius: 25px; 
    border: none;
    font-weight: bold;
    cursor: pointer;
}

.modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6); display: flex; justify-content: center; align-items: center; z-index: 100;
}
.modal-content {
    background: #1e1e1e; padding: 25px; border-radius: 20px; width: 90%; max-width: 400px;
    display: flex; flex-direction: column; gap: 12px; border: 1px solid rgba(255,255,255,0.1);
    max-height: 90vh; overflow-y: auto;
}
.modal-content label { font-size: 13px; color: #aaa; margin-top: 5px; }

@media (max-width: 600px) {
    #login-form { padding: 30px 20px; }
    header { padding: 10px 15px; }
    .msg { max-width: 90%; padding: 10px 14px; }
    #messages-container { padding: 15px 10px; }
    #input-container { padding: 10px; }
    #input-area { padding: 5px 8px 5px 10px; }
    .input-icons svg { width: 20px; height: 20px; }
    #send-btn { padding: 8px 15px; font-size: 14px; }
    .msg-actions { opacity: 1; background: rgba(0,0,0,0.5); top: -20px; }
}