:root {
    /* Color Palette - Modern Indigo Theme */
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #e0e7ff;
    
    --bg-app: #f3f4f6;
    --bg-surface: #ffffff;
    --bg-sidebar: #ffffff;
    
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --text-light: #9ca3af;
    
    --border-color: #e5e7eb;
    --divider-color: #f3f4f6;
    
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    
    --message-out-bg: #effdde;
    --message-out-text: #000000;
    --message-in-bg: #ffffff;
    --message-in-text: #1f2937;
    
    /* Dimensions */
    --sidebar-width: 320px;
    --header-height: 64px;
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --app-height: 100dvh;
}

/* --- Fonts & Reset --- */
@font-face {
    font-family: 'Vazirmatn';
    src: url('fonts/Vazirmatn-Regular.woff2') format('woff2');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Vazirmatn';
    src: url('fonts/Vazirmatn-Bold.woff2') format('woff2');
    font-weight: bold;
    font-style: normal;
    font-display: swap;
}

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

body {
    font-family: 'Vazirmatn', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
    line-height: 1.5;
    min-height: 100vh;
    height: var(--app-height);
    overflow: hidden;
}

img {
    max-width: 100%;
    display: block;
}

button, input, textarea, select, option {
    font-family: inherit;
}

a {
    text-decoration: none;
    color: inherit;
}

/* --- Layout --- */
.app-container {
    display: flex;
    min-height: 100vh;
    height: var(--app-height);
    width: 100vw;
    background-color: var(--bg-app);
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 20;
    flex-shrink: 0;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
    height: var(--header-height);
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--divider-color);
    background: var(--primary-color);
    color: white;
}

.app-title {
    font-size: 1.25rem;
    font-weight: 800;
    color: white;
    letter-spacing: -0.5px;
}

.app-slogan {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.8);
}

.user-profile-summary {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.2s;
    background: rgba(255,255,255,0.1);
}

.user-profile-summary:hover {
    background-color: rgba(255,255,255,0.2);
}

.user-name {
    font-weight: 600;
    font-size: 0.9rem;
    max-width: 100px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: white;
}

/* Friends Search & List */
.friends-search {
    padding: 1rem;
    border-bottom: 1px solid var(--divider-color);
}

.friends-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.friend-item {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    margin-bottom: 0.25rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.friend-item:hover {
    background-color: var(--bg-app);
}

.friend-item.active {
    background-color: var(--primary-light);
    border-color: rgba(79, 70, 229, 0.1);
}

.friend-item.active .friend-name {
    color: var(--primary-color);
}

.friend-info {
    flex: 1;
    margin-right: 0.75rem;
    min-width: 0;
}

.friend-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-main);
    display: block;
    margin-bottom: 0.125rem;
}

.friend-status {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--divider-color);
    background-color: var(--bg-surface);
    display: flex;
    gap: 0.5rem;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #8faec4; /* Telegram default bg color approximation */
    background-image: url("data:image/svg+xml,%3Csvg width='400' height='400' xmlns='http://www.w3.org/2000/svg'%3E%3Cdefs%3E%3Cpattern id='bg' patternUnits='userSpaceOnUse' width='400' height='400' fill-opacity='0.1'%3E%3Cpath d='M100 100a10 10 0 1 0 0-20 10 10 0 0 0 0 20zm200 0a10 10 0 1 0 0-20 10 10 0 0 0 0 20zM100 300a10 10 0 1 0 0-20 10 10 0 0 0 0 20zm200 0a10 10 0 1 0 0-20 10 10 0 0 0 0 20z' fill='%23fff'/%3E%3C/pattern%3E%3C/defs%3E%3Crect width='100%25' height='100%25' fill='url(%23bg)'/%3E%3C/svg%3E");
    position: relative;
    min-width: 0;
}

/* Fallback for background if SVG is too complex or just use a nice gradient/color */
.chat-area {
    background-color: #e5ddd5; /* WhatsApp/Telegram light theme beige-ish */
    background-image: linear-gradient(rgba(255,255,255,0.5) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.5) 1px, transparent 1px);
    background-size: 20px 20px;
}

.chat-header {
    height: var(--header-height);
    background-color: var(--bg-surface);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--divider-color);
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.chat-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
    height: 100%;
}

.placeholder-content {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    padding: 3rem 2rem;
    border-radius: 20px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
    max-width: 450px;
    border: 1px solid rgba(255, 255, 255, 0.8);
    transition: transform 0.3s;
}

.placeholder-content:hover {
    transform: translateY(-5px);
}

.placeholder-content h2 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    font-size: 1.75rem;
    font-weight: 800;
}

.placeholder-content p {
    color: var(--text-muted);
    font-size: 1.1rem;
    line-height: 1.6;
}

.chat-contact-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.chat-name {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-main);
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

.messages-container {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem; /* Reduced gap between messages */
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    /* Telegram-like Background Pattern - Neutral Theme */
    background-color: #f0f2f5; /* Light neutral gray */
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm-43-7c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm63 31c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM34 90c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm56-76c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM12 86c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm28-65c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm23-11c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-6 60c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm29 22c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zM32 63c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm57-13c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-9-21c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM60 91c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM35 41c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM12 60c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2z' fill='%239ca3af' fill-opacity='0.08' fill-rule='evenodd'/%3E%3C/svg%3E");
}

/* Message Bubbles - Telegram Style */
.message-wrapper {
    display: flex;
    max-width: 75%;
    position: relative;
    margin-bottom: 2px;
}

/* 
   RTL Context:
   align-self: flex-start -> Right Side
   align-self: flex-end -> Left Side
   
   User Request:
   Sender (Me) -> Right Side
   Receiver (Other) -> Left Side
*/

.message-wrapper.sent {
    align-self: flex-start; /* Move to Right */
    flex-direction: row-reverse;
}

.message-wrapper.received {
    align-self: flex-end; /* Move to Left */
    flex-direction: row; /* Ensure default direction */
}

.message-bubble {
    padding: 6px 10px 8px 12px;
    border-radius: 12px;
    position: relative;
    font-size: 0.95rem;
    line-height: 1.5;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15); /* Slightly darker shadow for better visibility */
    word-wrap: break-word;
    min-width: 80px;
    z-index: 1; /* Ensure bubble is above background */
}

.message-wrapper.sent .message-bubble {
    background-color: var(--message-out-bg);
    color: var(--message-out-text);
    border-radius: 12px 12px 0 12px; /* Tail on Bottom-Right (Sender Side) */
    opacity: 1; /* Force opacity */
}

.message-wrapper.received .message-bubble {
    background-color: var(--message-in-bg);
    color: var(--message-in-text);
    border-radius: 12px 12px 12px 0; /* Tail on Bottom-Left (Receiver Side) */
    opacity: 1; /* Force opacity */
}

.message-content {
    margin-bottom: 2px;
}

.message-meta {
    float: right;
    margin-left: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    height: 14px;
    margin-top: 6px;
    position: relative;
    top: 2px;
}

/* Clear float */
.message-bubble::after {
    content: "";
    display: table;
    clear: both;
}

.message-time {
    font-size: 0.7rem;
    opacity: 0.6;
}

.message-wrapper.sent .message-time {
    color: #559c43;
}

.message-wrapper.received .message-time {
    color: #a0a0a0;
}

.message-ticks {
    font-size: 0.75rem;
    display: inline-flex;
}

.tick-seen {
    color: #4fae4e;
}
.tick-sent {
    color: #559c43;
}

/* Chat Input Area */
.chat-input-area {
    background-color: var(--bg-surface);
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--divider-color);
    display: flex;
    align-items: center;
    gap: 1rem;
}

#message-form {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 0.75rem;
    background: var(--bg-app);
    padding: 0.5rem;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-color);
    transition: border-color 0.2s;
}

#message-form:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.1);
}

#message-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 0.5rem 1rem;
    outline: none;
    font-size: 0.95rem;
    color: var(--text-main);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
    font-size: 0.9rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    border: none;
    box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-hover), var(--primary-color));
    box-shadow: 0 6px 15px rgba(79, 70, 229, 0.4);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: white;
    border-color: var(--border-color);
    color: var(--text-main);
}

.btn-secondary:hover {
    background-color: var(--bg-app);
    border-color: var(--text-muted);
}

.btn-danger {
    background-color: white;
    border-color: var(--danger-color);
    color: var(--danger-color);
}

.btn-danger:hover {
    background-color: #fef2f2;
}

.btn-logout {
    flex: 1;
    text-align: center;
    padding: 0.6rem;
    background-color: #fee2e2;
    color: var(--danger-color);
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.btn-logout:hover {
    background-color: #fecaca;
}

.btn-block {
    width: 100%;
    display: flex;
}

.btn-icon {
    background: transparent;
    border: none;
    padding: 0.5rem;
    border-radius: 50%;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
}

.btn-icon:hover {
    background-color: var(--bg-app);
    color: var(--primary-color);
}

.btn-header-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: white;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1.1rem;
}

.btn-header-icon:hover {
    background: var(--bg-app);
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-send {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s;
}

.btn-send:active {
    transform: scale(0.95);
}

/* Avatars */
.avatar-small {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid white;
    box-shadow: 0 0 0 1px var(--border-color);
}

.avatar-large {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid white;
    box-shadow: var(--shadow-md);
}

/* Call Modal */
.call-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.call-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.call-avatar {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 4px solid rgba(255,255,255,0.2);
    margin-bottom: 1.5rem;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.call-name {
    font-size: 1.5rem;
    font-weight: 800;
    color: white;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.call-status {
    font-size: 1rem;
    color: rgba(255,255,255,0.8);
    margin-bottom: 3rem;
}

.call-actions {
    display: flex;
    gap: 2rem;
}

.btn-call-action {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.btn-call-action:hover {
    transform: scale(1.1);
}

.btn-call-accept {
    background-color: #22c55e;
    color: white;
}

.btn-call-reject, .btn-call-end {
    background-color: #ef4444;
    color: white;
}

.btn-call-mute {
    background-color: white;
    color: #1f2937;
}

.video-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    display: none; /* Hidden by default for voice calls */
}

.video-container.active {
    display: block;
}

#remote-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#local-video {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 120px;
    height: 160px;
    object-fit: cover;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    border: 2px solid rgba(255,255,255,0.2);
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: white;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 450px;
    padding: 0;
    box-shadow: var(--shadow-lg);
    transform: translateY(20px);
    transition: transform 0.3s;
    overflow: hidden;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--divider-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8fafc;
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    background: #f8fafc;
    border-top: 1px solid var(--divider-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

.btn-close {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-muted);
}

/* Login/Register Pages */
.login-page {
    background: linear-gradient(135deg, #4f46e5 0%, #818cf8 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-container {
    background: white;
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.logo-container {
    display: flex;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.app-logo-lg {
    max-width: 120px;
    height: auto;
    object-fit: contain;
}

.sidebar-logo {
    width: 40px;
    height: 40px;
    object-fit: contain;
    border-radius: var(--radius-sm);
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.login-container {
    background: white;
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-container h1 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    font-size: 2rem;
}

.login-container .btn {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    border-radius: var(--radius-md);
    justify-content: center;
}

.form-group {
    margin-bottom: 1.25rem;
    text-align: right;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-main);
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    transition: all 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.error-message {
    background-color: #fef2f2;
    color: var(--danger-color);
    padding: 0.75rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    border: 1px solid #fee2e2;
}

.success-message {
    background-color: #ecfdf5;
    color: var(--success-color);
    padding: 0.75rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    border: 1px solid #d1fae5;
}

/* Helpers */
.hidden { display: none !important; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.mb-3 { margin-bottom: 0.75rem; }
.text-danger { color: var(--danger-color) !important; }
.text-success { color: var(--success-color) !important; }
.center-text { text-align: center; }

/* Message Actions - Hidden by default, show on hover */
.message-actions {
    position: absolute;
    left: -30px; /* Position to the left of the bubble */
    top: 0;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 10;
}

.message-wrapper.sent .message-actions {
    left: auto;
    right: -30px; /* Position to the right for sent messages */
}

.message-wrapper:hover .message-actions {
    opacity: 1;
}

/* On mobile, maybe always show or use a different trigger? For now, hover/tap works */
@media (max-width: 768px) {
    .message-actions {
        opacity: 1; /* Always show on mobile since no hover */
        position: relative;
        left: auto;
        right: auto;
        top: auto;
        margin-right: 0.5rem;
    }
}

.action-btn {
    background: rgba(255, 255, 255, 0.8);
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-muted);
    box-shadow: var(--shadow-sm);
}

.action-menu {
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: none;
    flex-direction: column;
    min-width: 120px;
    z-index: 20;
    overflow: hidden;
}

.message-wrapper.sent .action-menu {
    left: auto;
    right: 0;
}

.action-menu.active {
    display: flex;
}

.action-menu button {
    background: none;
    border: none;
    padding: 0.5rem 1rem;
    text-align: right;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-main);
    width: 100%;
}

.action-menu button:hover {
    background-color: var(--bg-app);
}

.action-menu .delete-btn {
    color: var(--danger-color);
}

/* Message Media Styles */
.message-image {
    width: 280px;
    height: 280px;
    max-width: 100%;
    border-radius: var(--radius-md);
    cursor: pointer;
    margin-bottom: 0.25rem;
    object-fit: cover; /* Ensures all images are same size/ratio without distortion */
    background: rgba(0,0,0,0.05);
    display: block;
}

.message-file {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 0.8rem;
    border-radius: var(--radius-md);
    border: 1px solid rgba(0,0,0,0.08);
    background: rgba(255,255,255,0.75);
    color: var(--text-main);
    text-decoration: none;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 
.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    margin-left: 0.5rem;
    align-self: flex-end;
    border: 2px solid white;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
} 
*/

/* Audio Player Customization */
audio {
    width: 100%;
    min-width: 200px; /* Ensure it's not too squashed */
    height: 40px;
    border-radius: 20px;
    margin-top: 0.25rem;
    outline: none;
}

/* Specific fix for audio inside sent messages */
.message-wrapper.sent audio {
    opacity: 1;
    background: #ffffff; /* Solid white background for sent audio */
    border: 1px solid rgba(0,0,0,0.1);
}

.message-wrapper.received audio {
    background: #f1f3f5;
    border: 1px solid rgba(0,0,0,0.1);
}

/* Responsive Design */
.mobile-back-btn {
    display: none;
}

@media (max-width: 768px) {
    input, textarea, select {
        font-size: 16px;
    }

    .app-container {
        position: relative;
    }

    .sidebar {
        position: absolute;
        top: 0;
        right: 0;
        height: 100%;
        width: 100%;
        transform: translateX(0);
        z-index: 50;
    }

    /* When chat is open, hide sidebar (or move it out) */
    body.chat-open .sidebar {
        transform: translateX(100%); /* Slide out to right */
    }

    .chat-area {
        width: 100%;
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        transform: translateX(-100%); /* Hidden by default */
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 40;
    }

    body.chat-open .chat-area {
        transform: translateX(0); /* Slide in */
    }

    .mobile-back-btn {
        display: flex;
        margin-left: 0.5rem;
    }

    .message-wrapper {
        max-width: 85%;
    }
    
    .chat-input-area {
        position: sticky;
        bottom: 0;
        padding: 0.75rem;
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    }

    .chat-header {
        padding: 0 1rem;
        padding-top: env(safe-area-inset-top);
        height: calc(var(--header-height) + env(safe-area-inset-top));
    }

    .messages-container {
        padding: 1rem;
        padding-bottom: 5.5rem;
    }

    .btn-icon,
    .btn-header-icon,
    .btn-send {
        width: 44px;
        height: 44px;
    }

    .sidebar-footer {
        flex-direction: column;
    }

    .modal-overlay {
        align-items: flex-end;
    }

    .modal {
        width: 100%;
        max-width: none;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        max-height: calc(var(--app-height) - env(safe-area-inset-top));
    }

    .modal-body {
        overflow: auto;
        max-height: calc(var(--app-height) - 160px);
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 480px) {
    #message-form {
        padding: 0.4rem;
        gap: 0.5rem;
    }

    #message-input {
        padding: 0.5rem 0.75rem;
        font-size: 1rem;
    }

    .message-wrapper {
        max-width: 92%;
    }
}

/* --- Admin Panel Styles --- */
.admin-container {
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
    overflow-x: auto;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: white;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    margin-bottom: 2rem;
}

.data-table thead {
    background-color: #f8fafc;
}

.data-table th {
    padding: 1rem;
    text-align: right;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--divider-color);
}

.data-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--divider-color);
    vertical-align: middle;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover {
    background-color: #f8fafc;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    font-weight: 500;
}

.status-active {
    background-color: #ecfdf5;
    color: var(--success-color);
}

.status-disabled {
    background-color: #fef2f2;
    color: var(--danger-color);
}

.admin-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Responsive Table */
@media (max-width: 768px) {
    .admin-container {
        padding: 1rem;
    }
    
    .data-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}

.admin-form-container {
    margin: 0 auto 2rem auto;
    text-align: right;
    max-width: 800px;
    background: white;
    padding: 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.admin-section-title {
    margin-top: 0;
    margin-bottom: 1.5rem;
    font-size: 1.25rem;
    color: var(--text-main);
    font-weight: 700;
    border-bottom: 2px solid var(--primary-light);
    padding-bottom: 0.75rem;
    display: inline-block;
}

.admin-add-user-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: end;
}

.admin-add-user-form .form-group {
    margin-bottom: 0;
}

.admin-add-user-form button[type="submit"] {
    height: 46px; /* Align with inputs */
    grid-column: span 2; /* Full width button */
    font-size: 1rem;
    font-weight: 600;
    margin-top: 0.5rem;
}

/* Responsive Form */
@media (max-width: 768px) {
    .admin-add-user-form {
        grid-template-columns: 1fr;
    }
    
    .admin-add-user-form button[type="submit"] {
        grid-column: span 1;
    }
}

.form-group select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    background-color: white;
    transition: all 0.2s;
    appearance: none; /* Remove default arrow */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236b7280'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 0.75rem center;
    background-size: 1rem;
}

.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
