:root {
    --bg-color: #000000;
    --chat-bg: #000000;
    --text-primary: #ffffff;
    --text-secondary: #8e8e93;
    --msg-out-bg: #3699ff;
    --msg-out-bg-grad: #3699ff;
    --msg-out-text: #ffffff;
    --msg-in-bg: #1c1c1e;
    --msg-in-text: #ffffff;
    --header-bg: #111111;
    --input-bg: #111111;
    --border-color: rgba(255, 255, 255, 0.1);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    --modal-bg: rgba(0,0,0,0.8);
}

@media (prefers-color-scheme: dark) {
    /* Same theme for dark and light since 3x-ui is dark-only */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body, html {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Roboto", "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    height: 100%;
    width: 100%;
}
body {
    display: flex;
    justify-content: center;
    align-items: center;
}

.screen {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
    box-shadow: var(--shadow);
}

@media (min-width: 768px) {
    body {
        background-color: #0a0a0a;
    }
    .screen {
        max-width: 600px;
        height: 95vh;
        border-radius: 12px;
        overflow: hidden;
        border: 1px solid var(--border-color);
        box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    }
}

.screen {
    /* Safe areas moved to absolute elements */
}

.hidden { display: none !important; }

/* Buttons */
button {
    font-family: inherit;
    cursor: pointer;
}
.secondary-btn {
    background: var(--input-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 500;
}
.icon-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.2rem;
    padding: 8px;
}

/* Modals */
.modal {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--modal-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 1rem;
}
.modal-content {
    background: var(--chat-bg);
    padding: 1.5rem;
    border-radius: 16px;
    width: 100%;
    max-width: 320px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    text-align: center;
}
.modal-content h3 { margin-bottom: 1rem; }
.modal-content input[type="text"] {
    width: 100%;
    padding: 10px;
    margin-bottom: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--input-bg);
    color: var(--text-primary);
}
.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: space-between;
}
.modal-actions button {
    flex: 1;
    padding: 10px;
    border-radius: 8px;
    border: none;
}
#save-profile-btn {
    background: var(--msg-out-bg-grad);
    color: #fff;
    font-weight: 600;
}

.avatar-upload {
    width: 80px; height: 80px;
    border-radius: 50%;
    background: var(--input-bg);
    margin: 0 auto 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    overflow: hidden;
    position: relative;
    border: 2px solid var(--border-color);
}
.avatar-upload img {
    width: 100%; height: 100%; object-fit: cover;
}
#upload-avatar-btn { margin-bottom: 1rem; font-size: 0.85rem; }

/* Login */
.login-container {
    margin: auto;
    width: 100%;
    max-width: 360px;
    background: #111111;
    padding: 2.5rem 2rem;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.8);
    text-align: center;
    border: 1px solid rgba(255,255,255,0.1);
}
.login-container h2 {
    font-size: 1.8rem;
    font-weight: 600;
    margin-bottom: 2rem;
    color: var(--text-primary);
}
.login-container input {
    width: 100%;
    padding: 14px 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-primary);
    font-size: 16px; /* Must be 16px to prevent iOS zoom */
    margin-bottom: 1.5rem;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.login-container input:focus {
    border-color: var(--msg-out-bg);
    box-shadow: 0 0 0 2px rgba(54, 153, 255, 0.2);
}
.login-container button {
    width: 100%;
    padding: 14px;
    border-radius: 8px;
    border: none;
    background: var(--msg-out-bg);
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}
.login-container button:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}
.login-container button:active {
    transform: scale(0.95);
}
.login-container .secondary-btn {
    background: var(--msg-in-bg);
    color: var(--text-secondary);
}
.login-container .secondary-btn:hover {
    filter: brightness(1.2);
}

/* Header */
.chat-header {
    height: 60px;
    background-color: var(--header-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: env(safe-area-inset-top) 1rem 0 1rem;
    box-sizing: content-box;
    flex-shrink: 0;
}
.header-content { display: flex; align-items: center; gap: 10px; }
.avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: linear-gradient(135deg, #cfd9df, #e2ebf0);
    display: flex; justify-content: center; align-items: center;
    color: #333; font-weight: 600; font-size: 1.2rem; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
@media (prefers-color-scheme: dark) {
    .avatar { background: linear-gradient(135deg, #434343, #000000); color: #fff; }
}
.header-info h2 { font-size: 1rem; font-weight: 600; }
#status-indicator { font-size: 0.75rem; color: var(--text-secondary); }

/* Chat Main */
#chat-container {
    flex: 1; overflow-y: auto;
    padding: 1rem 1rem 10px 1rem;
    display: flex; flex-direction: column; scroll-behavior: smooth;
}
#messages {
    display: flex; flex-direction: column; gap: 8px;
    min-height: min-content; justify-content: flex-end;
}
.message {
    max-width: 80%; padding: 10px 14px; border-radius: 12px;
    font-size: 15px; line-height: 1.4; word-wrap: break-word;
    position: relative; animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.message img.msg-image {
    max-width: 100%; border-radius: 8px; margin-bottom: 5px;
}
.message img.msg-sticker {
    width: 120px; height: 120px; object-fit: contain; background: transparent;
}
.message.sticker {
    background: transparent !important; padding: 0; border: none; box-shadow: none;
}
@keyframes popIn {
    0% { opacity: 0; transform: scale(0.8) translateY(10px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}
.message.in {
    align-self: flex-start; background-color: var(--msg-in-bg);
    color: var(--msg-in-text); border-bottom-left-radius: 4px;
}
.message.out {
    align-self: flex-end; background: var(--msg-out-bg-grad);
    color: var(--msg-out-text); border-bottom-right-radius: 4px;
}
.message-time {
    font-size: 11px; color: var(--text-secondary); margin-top: 2px; text-align: right; display: block;
}
.message.out .message-time {
    color: rgba(255, 255, 255, 0.7);
}

/* Typing */
#typing-indicator {
    align-self: flex-start; background-color: var(--msg-in-bg);
    padding: 12px 16px; border-radius: 20px; border-bottom-left-radius: 4px;
    margin-top: 8px; display: flex; gap: 4px;
}
#typing-indicator span {
    width: 6px; height: 6px; background-color: var(--text-secondary);
    border-radius: 50%; animation: bounce 1.4s infinite ease-in-out both;
}
#typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
#typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

/* Footer */
.chat-footer {
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom)) 10px;
    background-color: var(--header-bg); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}
.input-wrapper {
    display: flex; align-items: flex-end; background: var(--input-bg);
    border: 1px solid var(--border-color); border-radius: 24px; padding: 4px 8px; gap: 4px;
}
.attachment-btn, #send-btn, #mic-btn, #cancel-record-btn, #send-record-btn {
    background: none; border: none; color: var(--text-secondary);
    width: 40px; height: 40px; border-radius: 50%; display: flex;
    justify-content: center; align-items: center; cursor: pointer;
    flex-shrink: 0; margin-bottom: 2px; font-size: 1.2rem;
    transition: transform 0.15s ease, color 0.2s ease;
}
.attachment-btn:active, #send-btn:active, #mic-btn:active, #cancel-record-btn:active, #send-record-btn:active {
    transform: scale(0.85);
}
#send-btn {
    color: var(--msg-out-bg-grad); 
}
#send-btn.hidden, #mic-btn.hidden {
    display: none;
}
#message-input {
    flex: 1; background: var(--bg-color); border: 1px solid var(--border-color); padding: 10px 14px;
    font-size: 16px; color: var(--text-primary); outline: none; font-family: inherit; border-radius: 18px;
}
#message-input:focus { border-color: var(--msg-out-bg); }

/* Stickers Panel */
.stickers-content { max-width: 400px; height: 80%; display: flex; flex-direction: column; }
.stickers-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.stickers-import { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.stickers-grid {
    flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(4, 1fr);
    gap: 10px; padding: 10px 0;
}
.sticker-item {
    width: 100%; aspect-ratio: 1; object-fit: contain; cursor: pointer;
    transition: transform 0.1s;
}
.sticker-item:active { transform: scale(0.9); }

/* V6 New Styles */
@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}
.recording-pulse {
    animation: pulse 1s infinite;
    color: #ff3b30 !important;
}
.edited-badge {
    opacity: 0.7;
    font-style: italic;
}
.msg-gallery img {
    border-radius: 8px;
    cursor: pointer;
}


@keyframes slideUpFade {
    0% { transform: translateY(10px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}
.slide-up-arrow {
    animation: slideUpFade 1.5s infinite;
}
