:root {
    --whatsapp-green: #25D366;
    --whatsapp-light-green: #DCF8C6;
    --whatsapp-dark-green: #128C7E;
    --whatsapp-teal-green: #075E54;
    --message-blue: #34B7F1;
    --gray-50: #f8f9fa;
    --gray-100: #f1f3f5;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-400: #ced4da;
    --gray-500: #adb5bd;
    --gray-600: #868e96;
    --gray-700: #495057;
    --gray-800: #343a40;
    --gray-900: #212529;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-full: 9999px;
    --safe-area-inset-top: env(safe-area-inset-top);
    --safe-area-inset-bottom: env(safe-area-inset-bottom);
    --safe-area-inset-left: env(safe-area-inset-left);
    --safe-area-inset-right: env(safe-area-inset-right);
}

/* Dark mode variables */
:root[data-theme="dark"] {
    --whatsapp-green: #25D366;
    --whatsapp-light-green: #056162;
    --whatsapp-dark-green: #075E54;
    --whatsapp-teal-green: #054D44;
    --gray-50: #1a1a1a;
    --gray-100: #2d2d2d;
    --gray-200: #404040;
    --gray-300: #545454;
    --gray-400: #686868;
    --gray-500: #7c7c7c;
    --gray-600: #8f8f8f;
    --gray-700: #a3a3a3;
    --gray-800: #b7b7b7;
    --gray-900: #ffffff;
}

/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    text-size-adjust: 100%;
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: var(--gray-900);
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    height: 100%;
    overflow: hidden;
    background: #fff;
    transition: background-color 0.3s ease;
}

/* Dark mode body */
body.dark-mode {
    background: #121212;
    color: #ffffff;
}

/* Login screen has gradient background */
#loginScreen {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    width: 100%;
    height: 100vh;
    height: -webkit-fill-available;
    height: calc(var(--vh, 1vh) * 100);
    display: flex;
    flex-direction: column;
    position: relative;
}

/* App screen has solid background */
#appScreen {
    background: var(--gray-50);
    width: 100%;
    height: 100vh;
    height: -webkit-fill-available;
    height: calc(var(--vh, 1vh) * 100);
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Dark mode app screen */
body.dark-mode #appScreen {
    background: #121212;
}

.hidden {
    display: none !important;
}

/* Login Screen */
.login-container {
    background: white;
    border-radius: var(--radius-lg);
    padding: 2rem;
    width: 95%;
    max-width: 400px;
    margin: auto;
    box-shadow: var(--shadow-lg);
    text-align: center;
    position: relative;
    z-index: 1;
}

/* Dark mode login container */
body.dark-mode .login-container {
    background: var(--gray-100);
    color: var(--gray-900);
}

.logo-container {
    margin-bottom: 2rem;
}

.logo {
    width: 80px;
    height: 80px;
    margin: 0 auto 1rem;
    border-radius: var(--radius-md);
    object-fit: cover;
    border: 3px solid var(--whatsapp-teal-green);
    background: white;
}

.logo-container h1 {
    color: var(--whatsapp-teal-green);
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    font-weight: 700;
}

.subtitle {
    color: var(--gray-600);
    font-size: 0.875rem;
    line-height: 1.4;
}

/* Dark mode subtitle */
body.dark-mode .subtitle {
    color: var(--gray-600);
}

/* User Selection - Optimized for iOS */
.user-selection {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
}

.user-option {
    display: flex;
    align-items: center;
    padding: 0.875rem;
    background: var(--gray-50);
    border-radius: var(--radius-md);
    cursor: pointer;
    border: 2px solid transparent;
    width: 100%;
    border: none;
    text-align: left;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    min-height: 70px;
    transition: all 0.2s;
    -webkit-appearance: none;
    appearance: none;
    touch-action: manipulation;
    position: relative;
    overflow: hidden;
}

.user-option:active {
    background: var(--gray-200);
    transform: scale(0.98);
}

.user-option:hover:not(:active) {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
    border-color: var(--whatsapp-teal-green);
    background: white;
}

/* Dark mode user option */
body.dark-mode .user-option {
    background: var(--gray-200);
    color: var(--gray-900);
}

body.dark-mode .user-option:active {
    background: var(--gray-300);
}

body.dark-mode .user-option:hover:not(:active) {
    background: var(--gray-100);
}

.user-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid white;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.user-info {
    flex: 1;
    text-align: left;
    padding-left: 1rem;
}

.user-info h3 {
    font-size: 1rem;
    color: var(--gray-900);
    margin-bottom: 0.25rem;
    font-weight: 600;
}

.user-status {
    font-size: 0.8125rem;
    color: var(--gray-600);
}

/* Password Section */
.password-section {
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.input-group {
    margin-bottom: 1.5rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--gray-700);
    font-weight: 500;
    font-size: 0.9375rem;
    text-align: left;
}

.password-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.login-input {
    width: 100%;
    padding: 0.875rem 1rem;
    padding-right: 3rem;
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 16px;
    transition: all 0.2s;
    background: white;
    -webkit-appearance: none;
    appearance: none;
    font-family: inherit;
    color: var(--gray-900);
}

/* Dark mode login input */
body.dark-mode .login-input {
    background: var(--gray-200);
    border-color: var(--gray-300);
    color: var(--gray-900);
}

.login-input:focus {
    outline: none;
    border-color: var(--whatsapp-dark-green);
    box-shadow: 0 0 0 3px rgba(18, 140, 126, 0.1);
}

.password-toggle-btn {
    position: absolute;
    right: 0.5rem;
    background: none;
    border: none;
    color: var(--gray-500);
    cursor: pointer;
    padding: 0.5rem;
    font-size: 1rem;
    transition: color 0.2s;
    -webkit-appearance: none;
    appearance: none;
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
    display: flex;
    align-items: center;
    justify-content: center;
}

.password-toggle-btn:active {
    color: var(--whatsapp-dark-green);
    transform: scale(0.95);
}

.password-hint {
    margin-top: 0.5rem;
    font-size: 0.8125rem;
    color: var(--gray-600);
    text-align: left;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.password-hint i {
    color: var(--whatsapp-dark-green);
    font-size: 0.875rem;
}

.login-actions {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.back-btn, .login-btn {
    flex: 1;
    padding: 0.875rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 44px;
    -webkit-appearance: none;
    appearance: none;
    touch-action: manipulation;
    font-family: inherit;
}

/* Active states for all buttons */
.back-btn:active, .login-btn:active, 
.header-btn:active, .input-btn:active,
.send-btn:active, .modal-btn:active {
    transform: scale(0.95);
}

.back-btn {
    background: var(--gray-200);
    color: var(--gray-700);
}

.back-btn:hover:not(:active) {
    background: var(--gray-300);
}

.login-btn {
    background: linear-gradient(135deg, var(--whatsapp-dark-green) 0%, var(--whatsapp-teal-green) 100%);
    color: white;
    border: none;
}

.login-btn:hover:not(:active) {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.app-info {
    border-top: 1px solid var(--gray-200);
    padding-top: 1rem;
    font-size: 0.8125rem;
    color: var(--gray-600);
}

.app-info p {
    margin: 0.5rem 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.app-info i {
    color: var(--whatsapp-dark-green);
    font-size: 0.875rem;
}

/* App Header - WhatsApp-like */
.app-header {
    background: var(--whatsapp-teal-green);
    color: white;
    padding: 0.75rem 1rem;
    padding-top: max(0.75rem, var(--safe-area-inset-top));
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
    min-height: 64px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
}

.header-left .back-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: background 0.2s;
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-left .back-btn:active {
    background: rgba(255, 255, 255, 0.2);
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.3);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.user-details {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.user-details h2 {
    font-size: 1.0625rem;
    font-weight: 600;
    margin-bottom: 0.125rem;
    line-height: 1.2;
}

.status {
    font-size: 0.8125rem;
    opacity: 0.9;
    font-weight: 400;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.header-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.125rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: background 0.2s;
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}

.header-btn:active {
    background: rgba(255, 255, 255, 0.2);
}

/* Chat Container - FIXED: No more blue wallpaper */
.chat-container {
    flex: 1;
    overflow-y: auto;
    background: #E5DDD5;
    padding: 0.75rem 0.5rem;
    padding-bottom: calc(1rem + var(--safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    position: relative;
}

/* Dark mode chat container */
body.dark-mode .chat-container {
    background: #0c1317;
}

/* WhatsApp pattern background */
.chat-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100%' height='100%'%3E%3Cdefs%3E%3Cpattern id='pattern' x='0' y='0' width='320' height='320' patternUnits='userSpaceOnUse'%3E%3Crect width='320' height='320' fill='%23E5DDD5'/%3E%3Cpath fill='%23D1C7BC' d='M0 0h160v160H0z'/%3E%3C/pattern%3E%3C/defs%3E%3Crect width='100%25' height='100%25' fill='url(%23pattern)' opacity='0.06'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 0;
}

/* Dark mode pattern */
body.dark-mode .chat-container::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100%' height='100%'%3E%3Cdefs%3E%3Cpattern id='pattern' x='0' y='0' width='320' height='320' patternUnits='userSpaceOnUse'%3E%3Crect width='320' height='320' fill='%230c1317'/%3E%3Cpath fill='%230a0f13' d='M0 0h160v160H0z'/%3E%3C/pattern%3E%3C/defs%3E%3Crect width='100%25' height='100%25' fill='url(%23pattern)' opacity='0.06'/%3E%3C/svg%3E");
}

.welcome-message {
    text-align: center;
    padding: 1.5rem 1rem;
    color: var(--gray-600);
    background: rgba(255, 255, 255, 0.92);
    border-radius: var(--radius-md);
    margin: 1rem;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.8);
    max-width: 85%;
    align-self: center;
    position: relative;
    z-index: 1;
}

/* Dark mode welcome message */
body.dark-mode .welcome-message {
    background: rgba(32, 44, 51, 0.92);
    color: #a3a3a3;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.welcome-message h3 {
    color: var(--whatsapp-teal-green);
    margin-bottom: 0.75rem;
    font-size: 1.125rem;
    font-weight: 600;
}

.welcome-message p {
    margin-bottom: 0.5rem;
    font-size: 0.9375rem;
    line-height: 1.4;
}

.welcome-sub {
    font-size: 0.8125rem !important;
    opacity: 0.7;
    font-style: italic;
}

/* Messages - WhatsApp-like bubbles */
.message {
    max-width: 85%;  /* Changed from 70% to 85% */
    margin-bottom: 0.375rem;
    animation: messageAppear 0.25s ease-out;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
    min-width: 60px; /* Minimum width for short messages */
}

/* Message bubble improvements */
.message-bubble {
    padding: 0.75rem 1rem;  /* Increased padding */
    border-radius: var(--radius-md);
    position: relative;
    word-wrap: break-word;
    word-break: break-word;  /* Better word breaking */
    line-height: 1.4;
    font-size: 16px;  /* Increased font size */
    max-width: 100%;
    box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
    min-height: 44px;  /* Minimum height for better touch */
    display: flex;
    flex-direction: column;
    justify-content: center;
}

@keyframes messageAppear {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message.sent {
    align-self: flex-end;
    margin-left: auto;
}

.message.received {
    align-self: flex-start;
    margin-right: auto;
}

.message-bubble {
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    position: relative;
    word-wrap: break-word;
    line-height: 1.35;
    font-size: 0.9375rem;
    max-width: 100%;
    box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
}

.message.sent .message-bubble {
    background: var(--whatsapp-light-green);
    border-top-right-radius: 4px;
    border-bottom-left-radius: var(--radius-md);
    border-bottom-right-radius: 4px;
    margin-left: auto;
}

.message.received .message-bubble {
    background: white;
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: var(--radius-md);
    margin-right: auto;
}

/* Dark mode message bubbles */
body.dark-mode .message.sent .message-bubble {
    background: #056162;
    color: #ffffff;
}

body.dark-mode .message.received .message-bubble {
    background: #202c33;
    color: #ffffff;
}

.message-time {
    font-size: 0.6875rem;
    color: rgba(0, 0, 0, 0.45);
    margin-top: 0.125rem;
    text-align: right;
    direction: ltr;
    letter-spacing: -0.3px;
    opacity: 0.8;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.125rem;
}

/* Dark mode message time */
body.dark-mode .message-time {
    color: rgba(255, 255, 255, 0.6);
}

/* Media Messages */
.media-message {
    border-radius: var(--radius-md);
    overflow: hidden;
    max-width: 220px;
    position: relative;
    border: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.media-preview {
    width: 100%;
    height: auto;
    display: block;
    max-height: 200px;
    object-fit: cover;
    cursor: pointer;
}

.video-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: 0.8125rem;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    backdrop-filter: blur(4px);
}

/* Message Input Area */
.message-input-area {
    background: #f0f0f0;
    padding: 0.5rem 0.75rem;
    padding-bottom: max(0.5rem, var(--safe-area-inset-bottom));
    position: relative;
    min-height: 60px;
    z-index: 10;
    border-top: 1px solid var(--gray-300);
}

/* Dark mode input area */
body.dark-mode .message-input-area {
    background: #1f2c33;
    border-top-color: #2a3942;
}

.input-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: relative;
}

.input-btn {
    background: none;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gray-600);
    cursor: pointer;
    font-size: 1.25rem;
    transition: all 0.2s;
    flex-shrink: 0;
    touch-action: manipulation;
    background: white;
    border: 1px solid var(--gray-300);
}

/* Dark mode input button */
body.dark-mode .input-btn {
    background: #2a3942;
    border-color: #3d4b54;
    color: #a6a6a6;
}

.input-btn:active {
    background: var(--gray-100);
    transform: scale(0.95);
}

body.dark-mode .input-btn:active {
    background: #374248;
}

.input-btn.active {
    color: var(--whatsapp-dark-green);
    background: var(--whatsapp-light-green);
    border-color: var(--whatsapp-dark-green);
}

body.dark-mode .input-btn.active {
    color: #00a884;
    background: #005c4b;
    border-color: #00a884;
}

.text-input-wrapper {
    flex: 1;
    position: relative;
}

#messageInput {
    width: 100%;
    padding: 0.75rem 1rem;
    padding-right: 3.5rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-full);
    font-size: 16px;
    background: white;
    transition: all 0.2s;
    font-family: inherit;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    color: var(--gray-900);
}

/* Dark mode message input */
body.dark-mode #messageInput {
    background: #2a3942;
    border-color: #3d4b54;
    color: #ffffff;
}

#messageInput:focus {
    outline: none;
    background: white;
    border-color: var(--whatsapp-dark-green);
    box-shadow: 0 0 0 2px rgba(18, 140, 126, 0.15);
}

body.dark-mode #messageInput:focus {
    background: #2a3942;
    border-color: #00a884;
    box-shadow: 0 0 0 2px rgba(0, 168, 132, 0.2);
}

.send-btn {
    background: var(--whatsapp-green);
    color: white;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    touch-action: manipulation;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.send-btn:active {
    background: var(--whatsapp-dark-green);
    transform: scale(0.95);
}

.file-upload-btn {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gray-600);
    cursor: pointer;
    transition: background 0.2s;
    touch-action: manipulation;
    background: white;
    border: 1px solid var(--gray-300);
}

/* Dark mode file upload button */
body.dark-mode .file-upload-btn {
    background: #2a3942;
    border-color: #3d4b54;
    color: #a6a6a6;
}

.file-upload-btn:active {
    background: var(--gray-100);
}

body.dark-mode .file-upload-btn:active {
    background: #374248;
}

.file-upload-btn input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    font-size: 100px;
}

/* Emoji Picker */
.emoji-picker {
    position: absolute;
    bottom: calc(100% + 0.25rem);
    left: 0.5rem;
    right: 0.5rem;
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    max-height: 280px;
    overflow-y: auto;
    z-index: 1000;
    border: 1px solid var(--gray-200);
    -webkit-overflow-scrolling: touch;
}

/* Dark mode emoji picker */
body.dark-mode .emoji-picker {
    background: #2a3942;
    border-color: #3d4b54;
}

.emoji-categories {
    display: flex;
    gap: 0.375rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
}

.emoji-category-btn {
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-full);
    background: white;
    font-size: 0.8125rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    min-height: 36px;
    touch-action: manipulation;
    font-family: inherit;
    color: var(--gray-900);
}

/* Dark mode emoji category button */
body.dark-mode .emoji-category-btn {
    background: #202c33;
    border-color: #3d4b54;
    color: #ffffff;
}

.emoji-category-btn:active {
    background: var(--gray-100);
    transform: scale(0.95);
}

body.dark-mode .emoji-category-btn:active {
    background: #374248;
}

.emoji-category-btn.active {
    background: var(--whatsapp-teal-green);
    color: white;
    border-color: var(--whatsapp-teal-green);
}

body.dark-mode .emoji-category-btn.active {
    background: #005c4b;
    border-color: #00a884;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 0.375rem;
}

.emoji-item {
    font-size: 1.375rem;
    text-align: center;
    padding: 0.375rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    user-select: none;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}

.emoji-item:active {
    background: var(--gray-100);
    transform: scale(0.9);
}

body.dark-mode .emoji-item:active {
    background: #374248;
}

/* File Preview */
.file-preview {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem;
    background: white;
    border-radius: var(--radius-sm);
    margin-top: 0.5rem;
    flex-wrap: wrap;
    max-height: 80px;
    overflow-y: auto;
    border: 1px solid var(--gray-200);
}

/* Dark mode file preview */
body.dark-mode .file-preview {
    background: #2a3942;
    border-color: #3d4b54;
}

.preview-item {
    position: relative;
    width: 50px;
    height: 50px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    flex-shrink: 0;
    border: 1px solid var(--gray-300);
}

.preview-item img, .preview-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remove-preview {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    touch-action: manipulation;
    line-height: 1;
}

.remove-preview:active {
    transform: scale(0.95);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 1rem;
    backdrop-filter: blur(4px);
    padding-top: var(--safe-area-inset-top);
    padding-bottom: var(--safe-area-inset-bottom);
}

.modal-content {
    background: white;
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    max-width: 400px;
    width: 100%;
    box-shadow: var(--shadow-lg);
    animation: modalAppear 0.3s ease-out;
    border: 1px solid var(--gray-200);
}

/* Dark mode modal */
body.dark-mode .modal-content {
    background: #2a3942;
    border-color: #3d4b54;
    color: #ffffff;
}

@keyframes modalAppear {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-content h3 {
    margin-bottom: 1rem;
    color: var(--whatsapp-teal-green);
    text-align: center;
    font-size: 1.25rem;
}

body.dark-mode .modal-content h3 {
    color: #00a884;
}

.modal-content p {
    margin-bottom: 0.75rem;
    color: var(--gray-700);
    line-height: 1.5;
    font-size: 0.9375rem;
}

body.dark-mode .modal-content p {
    color: #a6a6a6;
}

.modal-content strong {
    color: var(--gray-900);
}

body.dark-mode .modal-content strong {
    color: #ffffff;
}

.modal-buttons {
    display: flex;
    justify-content: center;
    margin-top: 1.5rem;
}

.modal-btn {
    padding: 0.75rem 2rem;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--whatsapp-teal-green);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 44px;
    min-width: 120px;
    touch-action: manipulation;
    font-family: inherit;
    font-size: 1rem;
}

.modal-btn:active {
    background: var(--whatsapp-dark-green);
    transform: scale(0.95);
}

body.dark-mode .modal-btn {
    background: #005c4b;
}

body.dark-mode .modal-btn:active {
    background: #004439;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* Dark mode scrollbar */
body.dark-mode ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}

body.dark-mode ::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Message Status */
.message-status {
    font-size: 0.6875rem;
    margin-left: 0.25rem;
    color: rgba(0, 0, 0, 0.45);
    display: inline-flex;
    align-items: center;
}

.message-status.delivered {
    color: var(--whatsapp-green);
}

.message-status.read {
    color: #34B7F1;
}

/* Dark mode message status */
body.dark-mode .message-status {
    color: rgba(255, 255, 255, 0.6);
}

/* Date Separator */
.date-separator {
    text-align: center;
    margin: 1rem 0;
    position: relative;
    align-self: center;
    z-index: 1;
}

.date-separator::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--gray-300);
    z-index: 1;
}

body.dark-mode .date-separator::before {
    background: #3d4b54;
}

.date-separator span {
    background: rgba(255, 255, 255, 0.9);
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    color: var(--gray-600);
    position: relative;
    z-index: 2;
    border: 1px solid var(--gray-300);
    backdrop-filter: blur(10px);
}

body.dark-mode .date-separator span {
    background: rgba(32, 44, 51, 0.9);
    color: #a6a6a6;
    border-color: #3d4b54;
}

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
    body, .screen {
        height: -webkit-fill-available;
    }
    
    .chat-container {
        -webkit-overflow-scrolling: touch;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    }
    
    body {
        overscroll-behavior-y: none;
    }
    
    @supports (height: 100svh) {
        .screen {
            height: 100svh;
        }
    }
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    z-index: 1000;
    animation: toastIn 0.3s ease;
    max-width: 85%;
    text-align: center;
    font-size: 14px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    pointer-events: none;
}

/* Dark mode toast */
body.dark-mode .toast {
    background: rgba(42, 57, 66, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    to {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
}

/* Network status indicator */
.network-status {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #ff6b6b;
    color: white;
    text-align: center;
    padding: 8px;
    font-size: 0.875rem;
    z-index: 10000;
    animation: slideDown 0.3s ease;
}

.network-status.online {
    background: var(--whatsapp-green);
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
    }
    to {
        transform: translateY(0);
    }
}

/* Mobile-specific styles */
@media (max-width: 768px) {
    .login-container {
        padding: 1.5rem;
        width: 100%;
        max-width: none;
        height: 100%;
        border-radius: 0;
        justify-content: center;
        display: flex;
        flex-direction: column;
        background: white;
    }
    
    body.dark-mode .login-container {
        background: #121212;
    }
    
    .logo {
        width: 70px;
        height: 70px;
    }
    
    .user-avatar {
        width: 45px;
        height: 45px;
    }
    
    .user-info h3 {
        font-size: 0.9375rem;
    }
    
    .emoji-grid {
        grid-template-columns: repeat(7, 1fr);
    }
    
    .message {
        max-width: 80%;
    }
    
    .media-message {
        max-width: 200px;
    }
    
    .app-header {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
    
    .message-input-area {
        padding-left: max(0.75rem, env(safe-area-inset-left));
        padding-right: max(0.75rem, env(safe-area-inset-right));
    }
    
    .chat-container {
        padding-left: max(0.5rem, env(safe-area-inset-left));
        padding-right: max(0.5rem, env(safe-area-inset-right));
    }
}

@media (max-width: 480px) {
    .emoji-grid {
        grid-template-columns: repeat(6, 1fr);
    }
    
    .message {
        max-width: 85%;
    }
    
    .header-btn {
        font-size: 1rem;
        padding: 0.375rem;
    }
    
    .app-header {
        padding: 0.5rem 0.75rem;
        padding-top: max(0.5rem, env(safe-area-inset-top));
    }
    
    .message-input-area {
        padding: 0.5rem;
        padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
    }
    
    .user-option {
        padding: 0.75rem;
    }
    
    .message-bubble {
        padding: 0.5rem 0.625rem;
        font-size: 0.9375rem;
    }
}

/* Height fixes for mobile */
@media (max-height: 700px) {
    .login-container {
        padding: 1.25rem;
        margin: 0.5rem auto;
    }
    
    .logo-container {
        margin-bottom: 1.5rem;
    }
    
    .user-selection {
        margin-bottom: 1.5rem;
    }
}

/* Offline indicator for messages */
.offline-indicator {
    font-size: 0.75rem;
    margin-left: 0.25rem;
    opacity: 0.7;
    display: inline-block;
}

/* Loading indicator */
.loading {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--gray-300);
    border-top: 2px solid var(--whatsapp-green);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 0.25rem;
}
/* Fix for iPhone input positioning */
.type-a-message {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: white;
    border-top: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    padding: 0 16px;
    z-index: 1000;
    box-sizing: border-box;
}

.type-a-message input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 16px;
    outline: none;
}

/* Adjust message container to not hide behind input */
.messages-container {
    padding-bottom: 80px !important;
}

/* Safe area for iPhone X and newer */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .type-a-message {
        padding-bottom: env(safe-area-inset-bottom);
        height: calc(60px + env(safe-area-inset-bottom));
    }
    
    .messages-container {
        padding-bottom: calc(80px + env(safe-area-inset-bottom)) !important;
    }
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Add at the end of the file: */

/* iPhone X and newer safe area improvements */
@supports (padding: max(0px)) {
    .app-header {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
    
    .message-input-area {
        padding-left: max(0.75rem, env(safe-area-inset-left));
        padding-right: max(0.75rem, env(safe-area-inset-right));
    }
    
    .chat-container {
        padding-left: max(0.5rem, env(safe-area-inset-left));
        padding-right: max(0.5rem, env(safe-area-inset-right));
    }
}


.message.sent .message-bubble {
    background: linear-gradient(135deg, #00D06B 0%, #00B95A 100%);
    color: white;
    border-bottom-right-radius: 0.5rem;
}

.message.received .message-bubble {
    background: white;
    color: #111;
    border-bottom-left-radius: 0.5rem;
}

/* Dark mode improvements */
body.dark-mode .message.received .message-bubble {
    background: #2A2F32;
    color: #E9EDEF;
}

/* Textarea styling */
#messageInput {
    resize: none;
    min-height: 44px;
    max-height: 120px;
    font-size: 16px;
    line-height: 1.4;
    padding: 0.75rem 1rem;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    border: 1px solid var(--gray-300);
    border-radius: 1.25rem;
    background: white;
}

body.dark-mode #messageInput {
    background: #2A2F32;
    border-color: #3D4347;
    color: white;
}

/* Reply feature styles */
.reply-bar {
    background: rgba(0, 180, 90, 0.1);
    border-radius: 0.75rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    border-left: 4px solid var(--whatsapp-green);
}

.reply-info {
    flex: 1;
}

.reply-sender {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--whatsapp-teal-green);
}

.reply-content {
    font-size: 0.875rem;
    color: var(--gray-700);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cancel-reply-btn {
    background: none;
    border: none;
    color: var(--gray-500);
    padding: 0.5rem;
    cursor: pointer;
    font-size: 1rem;
}

.reply-preview {
    border-left: 3px solid var(--whatsapp-green);
    padding-left: 0.75rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
}

.reply-sender-small {
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--whatsapp-teal-green);
}

.reply-text-small {
    font-size: 0.75rem;
    color: var(--gray-600);
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Context menu */
.message-context-menu {
    background: white;
    border-radius: 0.75rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    overflow: hidden;
    min-width: 160px;
}

.context-menu-item {
    width: 100%;
    padding: 0.875rem 1rem;
    border: none;
    background: none;
    text-align: left;
    font-size: 0.9375rem;
    color: var(--gray-800);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.context-menu-item:hover {
    background: var(--gray-50);
}

body.dark-mode .message-context-menu {
    background: #2A2F32;
    color: white;
}

body.dark-mode .context-menu-item {
    color: #E9EDEF;
}

body.dark-mode .context-menu-item:hover {
    background: #3D4347;
}

/* Typing indicator */
.typing-indicator {
    background: white;
    padding: 0.75rem 1rem;
    border-radius: 1.25rem;
    margin-bottom: 0.5rem;
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--gray-600);
}

.typing-dots {
    display: flex;
    gap: 0.25rem;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--gray-400);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* Better iOS button tap feedback */
button:active {
    opacity: 0.7;
    transform: scale(0.98);
}

/* Improved scrollbar for iOS */
.chat-container {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}
.admin-actions {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--gray-300);
    text-align: center;
}

.admin-btn {
    background: #dc3545;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    margin-bottom: 0.5rem;
    transition: all 0.2s;
    font-weight: 500;
}

.admin-btn:active {
    background: #c82333;
    transform: scale(0.98);
}

.admin-warning {
    font-size: 0.75rem;
    color: #dc3545;
    margin: 0;
    font-style: italic;
}

/* Message selection */
.message.selected .message-bubble {
    background: rgba(0, 180, 90, 0.2);
    border: 2px solid var(--whatsapp-green);
}