/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #007bff;
    --primary-hover: #0056b3;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --background: #f5f5f5;
    --surface: #ffffff;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --border-color: #dee2e6;
    --sent-message: #007bff;
    --received-message: #e9ecef;
    --shadow: 0 2px 4px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 6px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
}

/* Login Page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 40px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

.login-logo {
    text-align: center;
    margin-bottom: 20px;
}

.login-logo img {
    max-width: 150px;
    height: auto;
    display: block;
    margin: 0 auto;
}

.login-card h1 {
    text-align: center;
    color: var(--primary-color);
    margin-bottom: 10px;
    font-size: 2rem;
}

.login-card h2 {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 30px;
    font-size: 1.2rem;
    font-weight: normal;
}

.login-footer {
    position: fixed;
    bottom: 12px;
    left: 0;
    right: 0;
    text-align: center;
    color: #e9ecef;
    font-size: 0.9rem;
}

.error-message {
    background-color: #fee;
    color: var(--danger-color);
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 20px;
    border: 1px solid #fcc;
}

/* App Container */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
/* Drawer Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 320px;
    background: var(--surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 1200;
}

.sidebar.open {
    transform: translateX(0);
}

.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.25);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1100;
}

.drawer-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

.app-logo {
    text-align: center;
    margin-bottom: 15px;
}

.app-logo img {
    max-width: 120px;
    height: auto;
    display: block;
    margin: 0 auto;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.username {
    font-weight: 600;
    color: var(--text-primary);
}

.admin-badge {
    background: var(--primary-color);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.sidebar-actions {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: visible; /* Allow buttons to display properly */
    min-width: 0; /* Prevent flex items from overflowing */
    width: 100%; /* Ensure full width within sidebar */
    box-sizing: border-box; /* Include padding in width calculation */
}

.chat-list-container {
    flex: 1;
    overflow: visible; /* allow accordions to control their own scroll */
    padding: 10px;
}

.chat-list-container h3 {
    padding: 10px 15px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chat-list-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
}

.chat-list-section-header h3 {
    padding: 0;
    margin: 0;
}

.btn-link-small {
    background: none;
    border: none;
    color: var(--primary-color);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 4px 8px;
    text-decoration: none;
}

.btn-link-small:hover {
    text-decoration: underline;
}

.hidden-chats-section {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.hidden-chats-section.accordion {
    border-top: 1px solid var(--border-color);
}

.accordion-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s;
    border-radius: 6px;
}

.accordion-header:hover {
    background-color: #f8f9fa;
}

.accordion-header h4 {
    margin: 0;
    padding: 0;
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.unread-total-badge {
    background: #e11d48;
    color: #fff;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 0.7rem;
    margin-left: 8px;
    vertical-align: middle;
}

.accordion-icon {
    color: var(--text-secondary);
    transition: transform 0.3s ease;
}

.accordion-actions {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.sidebar .accordion.expanded .accordion-content {
    max-height: 50vh; /* responsive height for mobile */
}

/* Ensure Conversations content is always visible inside the drawer */
#conversationsSection .accordion-content {
    max-height: 50vh;
    overflow-y: auto;
}

.accordion.expanded .accordion-icon {
    transform: rotate(180deg);
}

.accordion-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    opacity: 0;
    pointer-events: none;
}

.hidden-chats-section.accordion.expanded .accordion-content {
    max-height: 400px;
    overflow-y: auto;
    opacity: 1;
}

/* When any accordion is expanded, make its content interactive and visible */
.accordion.expanded .accordion-content {
    opacity: 1;
    pointer-events: auto;
}

.hidden-chats-section.accordion .chat-list {
    padding: 10px 0;
}

.hidden-chat-item {
    opacity: 0.7;
}

.btn-unhide {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-unhide:hover {
    background: var(--primary-hover);
}

.chat-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
    color: var(--text-primary);
}

.chat-item {
    padding: 12px 15px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    min-height: 44px; /* ensure visible height */
    position: relative;
    z-index: 1;
    background-color: #ffffff;
    border: 1px solid #eef1f5;
    font-size: 14px;
    line-height: 1.2;
}

.chat-item:hover {
    background-color: #f8f9fa;
}

.chat-item.active {
    background-color: #e7f3ff;
    border-left: 3px solid var(--primary-color);
}

.chat-item-name {
    font-weight: 500;
    color: var(--text-primary) !important;
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-block;
}

.status-dot.online {
    background-color: #16a34a;
    box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.2);
}

.status-dot.offline {
    background-color: #dc2626;
    box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.2);
}

.chat-item-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Ensure chat list text is always visible */
.chat-item, .chat-item * {
    opacity: 1 !important;
    visibility: visible !important;
}

.chat-item-preview { color: #6c757d !important; font-size: 0.85rem; margin-top: 2px; }

.unread-badge {
    background: #e11d48;
    color: #fff;
    border-radius: 999px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
}

.sidebar-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
}

.sidebar-footer-icons {
    display: flex;
    align-items: center;
    gap: 10px;
}

.icon-link {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 6px;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.icon-link:hover { background: #f5f6f7; color: var(--text-primary); }

.footer-sep { color: var(--border-color); }

/* Main Chat Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--background);
    position: relative;
    min-height: 0; /* Allow flex scrolling */
    overflow: hidden; /* Prevent overflow on main container */
}

/* Header menu button */
.btn-menu {
    background: none;
    border: none;
    color: var(--text-primary);
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
}

.btn-menu:hover { background: #f0f2f4; }

.floating-menu-btn {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1300;
    box-shadow: var(--shadow);
    background: var(--surface);
}

.hidden {
    display: none !important;
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px;
}

.empty-state-content {
    text-align: center;
    color: var(--text-secondary);
}

.empty-state-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}

.empty-state-logo img {
    width: 180px;
    max-width: 40vw;
    height: auto;
}

.empty-state-footer {
    position: absolute;
    bottom: 12px;
    left: 0;
    right: 0;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.empty-state-content h2 {
    margin-bottom: 10px;
    color: var(--text-primary);
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0; /* Allow flex children to shrink below content size */
    overflow: hidden; /* Prevent container from growing */
}

.chat-header {
    background: var(--surface);
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
}

.chat-header-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-header-info h3 {
    margin-bottom: 0;
    margin-top: 0;
    color: var(--text-primary);
}

.chat-status {
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: block;
}

.chat-status.online { color: #16a34a; }
.chat-status.offline { color: #dc2626; }

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.typing-dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--text-secondary);
    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;
}

/* Typing bubble message (like Messenger/iMessage) */
.typing-message {
    opacity: 1;
    animation: fadeInTyping 0.3s ease;
}

@keyframes fadeInTyping {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.typing-bubble {
    background-color: var(--received-message);
    padding: 12px 16px;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    min-width: 50px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.typing-bubble .typing-dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}

.typing-bubble .typing-dots span {
    width: 8px;
    height: 8px;
    background-color: var(--text-secondary);
    border-radius: 50%;
    animation: typingBubble 1.4s infinite;
}

.typing-bubble .typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-bubble .typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBubble {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-4px);
    }
}

.typing-text {
    font-style: italic;
}

.chat-actions {
    display: flex;
    gap: 10px;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0; /* Required for flex scrolling */
}

.message {
    display: flex;
    max-width: 70%;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

.message.received {
    align-self: flex-start;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    word-break: break-word;
    white-space: normal; /* Normal whitespace handling - <br> tags will create line breaks */
    position: relative;
    line-height: 1.5;
}

.message.sent .message-bubble {
    background-color: var(--sent-message);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.received .message-bubble {
    background-color: var(--received-message);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

/* Message links */
.message-link {
    color: inherit;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 2px;
    cursor: pointer;
    word-break: break-all;
    transition: opacity 0.2s;
}

.message.sent .message-link {
    color: rgba(255, 255, 255, 0.9);
    text-decoration-color: rgba(255, 255, 255, 0.7);
}

.message.sent .message-link:hover {
    color: rgba(255, 255, 255, 1);
    text-decoration-color: rgba(255, 255, 255, 1);
}

.message.received .message-link {
    color: var(--primary-color);
    text-decoration-color: var(--primary-color);
}

.message.received .message-link:hover {
    opacity: 0.8;
}

.message-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    padding: 0 4px;
    gap: 8px;
}

.btn-delete-message {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.2s, background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.message:hover .btn-delete-message {
    opacity: 1;
}

.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
    margin-bottom: 4px;
}

.reaction-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--received-message);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.reaction-badge:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
    transform: scale(1.05);
}

.reaction-badge.user-reacted {
    background: rgba(59, 130, 246, 0.15);
    border-color: var(--primary-color);
}

.reaction-emoji {
    font-size: 0.9rem;
}

.reaction-count {
    font-size: 0.75rem;
    font-weight: 500;
}

.btn-react {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s, transform 0.2s;
    font-size: 0.9rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    pointer-events: auto;
    z-index: 10;
    touch-action: manipulation; /* Prevent double-tap zoom on iOS */
    -webkit-tap-highlight-color: transparent; /* Remove iOS tap highlight */
}

/* Show on hover (desktop only - use :hover which only works on devices that support hover) */
@media (hover: hover) and (pointer: fine) {
    .message:hover .btn-react {
        opacity: 1;
        visibility: visible;
    }
}

/* On mobile/touch devices, show button when message is touched */
@media (hover: none) or (pointer: coarse) {
    .btn-react {
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.2s, visibility 0.2s;
        pointer-events: none; /* Prevent clicks when hidden */
    }
    
    /* Show button when message has touched class */
    .message.touched .btn-react {
        opacity: 1;
        visibility: visible;
        pointer-events: auto; /* Enable clicks when visible */
    }
    
    /* Also show on active state as fallback */
    .message:active .btn-react,
    .message-wrapper:active .btn-react {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }
}

.btn-react:hover {
    transform: scale(1.1);
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.reaction-picker {
    display: flex;
    gap: 4px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 6px 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 10000;
    touch-action: manipulation; /* Prevent iOS touch issues */
    -webkit-tap-highlight-color: transparent;
    pointer-events: auto;
}

.reaction-picker-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px;
    border-radius: 8px;
    transition: transform 0.2s, background-color 0.2s;
    line-height: 1;
    touch-action: manipulation; /* Prevent iOS touch issues */
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

.reaction-picker-btn:hover {
    transform: scale(1.3);
    background-color: rgba(0,0,0,0.05);
}

.btn-delete-message:hover {
    background-color: rgba(220, 53, 69, 0.1);
    color: var(--danger-color);
}

.chat-input-container {
    background: var(--surface);
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
}

.message-form {
    display: flex;
    gap: 8px;
    align-items: center;
    position: relative;
    min-height: 56px;
}

#messageInput {
    flex: 1 1 auto;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 24px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
    min-height: 44px;
    max-height: 120px;
    min-width: 0; /* allow flexbox to shrink on small screens */
    resize: none;
    overflow-y: auto;
    font-family: inherit;
    line-height: 1.4;
}

#messageInput:focus {
    border-color: var(--primary-color);
}

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

.btn-send:hover {
    background: var(--primary-hover);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Chat Images */
.chat-image {
    max-width: 300px;
    max-height: 300px;
    border-radius: 12px;
    cursor: pointer;
    display: block;
    object-fit: cover;
}

.message-bubble img.chat-image {
    margin: 0;
    padding: 0;
    background: transparent;
}

/* Remove padding when bubble contains an image */
.message .message-bubble.has-image {
    padding: 0;
    background: transparent;
}

/* Emoji Picker */
.emoji-picker {
    position: absolute;
    bottom: 70px;
    left: 0;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 15px;
    max-width: 300px;
    max-height: 250px;
    overflow-y: auto;
    display: none;
    grid-template-columns: repeat(8, 1fr);
    gap: 8px;
    z-index: 100;
}

.emoji-picker.active {
    display: grid;
}

.emoji-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: background-color 0.2s;
}

.emoji-btn:hover {
    background-color: #f8f9fa;
}

/* Button Icons */
.btn-icon-emoji,
.btn-icon-attach {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
}

.btn-icon-emoji:hover,
.btn-icon-attach:hover {
    background-color: #f8f9fa;
    color: var(--text-primary);
}

/* Image Modal */
.modal-image .modal-content {
    max-width: 90vw;
}

/* Toasts */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1400;
}

.toast {
    background: var(--surface);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    border-radius: 8px;
    padding: 12px 14px;
    min-width: 240px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    animation: fadeSlideIn 0.25s ease;
}

.toast.success { border-left: 4px solid #16a34a; }
.toast.error { border-left: 4px solid #dc2626; }
.toast.info { border-left: 4px solid var(--primary-color); }

@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Confirm Modal (lightweight) */
.confirm-modal .modal-content { max-width: 420px; }
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 10px; }

@media (max-width: 768px) {
    .toast-container { top: auto; right: 50%; bottom: 16px; transform: translateX(50%); }
}

.modal-image .modal-body {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.modal-image img {
    max-width: 100%;
    max-height: 80vh;
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

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

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

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

.btn-secondary:hover {
    background-color: #545b62;
}

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

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

.btn-link {
    background: none;
    color: var(--primary-color);
    text-decoration: none;
    padding: 8px 0;
}

.btn-link:hover {
    text-decoration: underline;
}

.btn-block {
    width: 100%;
    min-width: 0; /* Prevent overflow */
    box-sizing: border-box; /* Ensure padding is included in width */
}

/* Update button style - distinct from secondary button */
.btn-update {
    background-color: #0dcaf0;
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px; /* Ensure consistent padding */
}

.btn-update:hover {
    background-color: #0aa2c0;
}

.btn-update svg {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
}

.btn-update span {
    flex-shrink: 0;
    white-space: nowrap; /* Prevent text wrapping */
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background-color: #f8f9fa;
    color: var(--text-primary);
}

.btn-home-topright {
    position: absolute;
    right: 16px;
    top: 20px;
    background: none;
    border: 1px solid #eee;
    border-radius: 6px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    cursor: pointer;
}

.btn-home-topright:hover { background: #f8f9fa; color: var(--text-primary); }

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--primary-color);
}

.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

.btn { white-space: nowrap; }

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

.modal-header h3 {
    margin: 0;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.modal-close:hover {
    background-color: #f8f9fa;
}

.modal-body {
    padding: 20px;
}

/* User Search */
#userSearchInput {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 15px;
    font-size: 1rem;
}

.user-search-results {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.user-search-item {
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.user-search-item:hover {
    background-color: #f8f9fa;
}

.user-search-item-name {
    font-weight: 500;
    color: var(--text-primary);
}

.user-search-item-email {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Users List */
.users-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 15px;
}

.user-item {
    padding: 15px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.user-item-info {
    flex: 1;
}

.user-item-name {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.user-item-email {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.user-item-role {
    font-size: 0.75rem;
    background: var(--secondary-color);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    display: inline-block;
    margin-left: 8px;
}

.user-item-role.admin {
    background: var(--primary-color);
}

.user-item-actions {
    display: flex;
    gap: 8px;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .app-container { flex-direction: column; }
    .chat-list-container { max-height: none; }
    
    .message {
        max-width: 85%;
    }
    
    .modal-content {
        width: 95%;
        max-height: 85vh;
    }
    
    .sidebar-actions {
        flex-direction: column; /* Keep vertical stack on mobile for better fit */
        gap: 8px; /* Slightly smaller gap on mobile */
    }
    
    .btn-block {
        width: 100%; /* Full width on mobile */
        min-width: 0; /* Prevent overflow */
    }
    
    .btn-update span {
        font-size: 0.9rem; /* Slightly smaller text on mobile if needed */
    }
}

/* Admin Panel - App Settings Styles */
.color-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.color-group input[type="color"] {
    width: 60px;
    height: 40px;
    padding: 2px;
    cursor: pointer;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.color-group input[type="text"] {
    flex: 1;
}

.logo-preview {
    margin-top: 10px;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--background);
    display: inline-block;
}

.logo-preview img {
    max-width: 120px;
    max-height: 120px;
    display: block;
}

.theme-preview {
    margin-top: 15px;
    padding: 15px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--background);
}

.theme-preview-item {
    display: inline-block;
    padding: 8px 16px;
    margin: 4px;
    border-radius: 4px;
    color: white;
    font-size: 14px;
    font-weight: 500;
}

/* Loading Spinner - Uses logo image, customizable for whitelabel */
.loading-spinner {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--background, #f5f5f5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 1;
    transition: opacity 0.3s ease-out;
}

.loading-spinner.hidden {
    opacity: 0;
    pointer-events: none;
    display: none;
}

.spinner-container {
    position: relative;
    width: 120px;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.spinner-logo {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: contain;
    z-index: 2;
    animation: logoPulse 2s ease-in-out infinite;
}

.spinner-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 4px solid var(--border-color, #dee2e6);
    border-top-color: var(--primary-color, #007bff);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

@keyframes logoPulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(0.95);
    }
}

/* Hide spinner on mobile for better performance */
@media (max-width: 480px) {
    .spinner-container {
        width: 100px;
        height: 100px;
    }
    
    .spinner-logo {
        width: 70px;
        height: 70px;
    }
}

@media (max-width: 480px) {
    .login-card {
        padding: 30px 20px;
    }
    
    .chat-header {
        padding: 12px 15px;
    }
    
    .messages-container {
        padding: 15px;
    }
    
    .chat-input-container {
        padding: 12px 15px calc(12px + env(safe-area-inset-bottom));
    }
    .btn-send { width: 52px; height: 52px; flex-basis: 52px; }
    #messageInput { min-height: 46px; }
    .btn-icon-emoji, .btn-icon-attach { width: 34px; height: 34px; padding: 6px; }
    
    .message {
        max-width: 90%;
    }
}

/* Lock Screen */
.lock-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.lock-screen.hidden {
    display: none;
}

.lock-screen-content {
    background: var(--surface);
    border-radius: 20px;
    padding: 35px 30px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    text-align: center;
}

.lock-screen-logo {
    margin-bottom: 15px;
}

.lock-screen-logo img {
    width: 80px;
    height: 80px;
    object-fit: contain;
}

.lock-screen-content h2 {
    margin: 0 0 8px 0;
    color: var(--text-primary);
    font-size: 1.8rem;
    font-weight: 600;
}

.lock-screen-message {
    color: var(--text-secondary);
    margin-bottom: 20px;
    font-size: 0.9rem;
}

.lock-screen-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 15px;
}

.lock-screen-form input {
    padding: 14px 18px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
    background: var(--surface);
    color: var(--text-primary);
}

.lock-screen-form input:focus {
    border-color: var(--primary-color);
}

.lock-screen-hint {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin: 15px 0 12px 0;
    text-align: center;
}

/* Button block styling for lock screen / login */
.btn-block {
    width: 100%;
    padding: 14px;
    font-size: 1rem;
    font-weight: 500;
}

#lockScreenPasscode {
    -webkit-text-security: disc;
    text-security: disc;
    letter-spacing: 4px;
    font-size: 1.2rem;
    text-align: center;
}

@media (max-width: 480px) {
    .lock-screen-content {
        padding: 30px 20px;
    }
    
    .lock-screen-logo img {
        width: 60px;
        height: 60px;
    }
}

/* Reply Feature Styles */
.reply-preview {
    background: var(--surface);
    border-top: 1px solid var(--border-color);
    padding: 10px 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border-left: 3px solid var(--primary-color);
}

.reply-preview-content {
    flex: 1;
    min-width: 0;
}

.reply-preview-info {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    font-size: 0.85rem;
    color: var(--primary-color);
    font-weight: 500;
}

.reply-preview-icon {
    font-size: 1rem;
}

.reply-preview-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reply-preview-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.btn-cancel-reply {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s, color 0.2s;
    flex-shrink: 0;
}

.btn-cancel-reply:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.btn-reply {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
    opacity: 0;
    visibility: hidden;
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 10;
}

.message:hover .btn-reply,
.message:active .btn-reply,
.message.touched .btn-reply {
    opacity: 1;
    visibility: visible;
}

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

.message-quote {
    background: rgba(0, 0, 0, 0.05);
    border-left: 3px solid var(--primary-color);
    padding: 8px 12px;
    margin-bottom: 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
    max-width: 100%;
    overflow: hidden;
}

.message.sent .message-quote {
    background: rgba(255, 255, 255, 0.2);
    border-left-color: rgba(255, 255, 255, 0.5);
}

.message-quote:hover {
    background: rgba(0, 0, 0, 0.1);
}

.message.sent .message-quote:hover {
    background: rgba(255, 255, 255, 0.3);
}

.message-quote-info {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--primary-color);
}

.message.sent .message-quote-info {
    color: rgba(255, 255, 255, 0.9);
}

.message-quote-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.4;
}

.message.sent .message-quote-text {
    color: rgba(255, 255, 255, 0.8);
}

/* Separator between quoted message and reply */
.message-quote-separator {
    height: 1px;
    border-top: 1px dashed rgba(0, 0, 0, 0.15);
    margin: 10px 0;
    width: 100%;
}

.message.sent .message-quote-separator {
    border-top-color: rgba(255, 255, 255, 0.3);
}

/* Message Options Menu */
.message-options-menu {
    position: absolute;
    top: -45px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    gap: 4px;
    padding: 4px;
    z-index: 1000;
    white-space: nowrap;
    animation: slideDownFade 0.2s ease-out;
    min-width: 200px;
    max-width: calc(100vw - 20px); /* Prevent overflow off screen */
    justify-content: center;
    flex-wrap: nowrap;
    overflow-x: visible;
    overflow-y: visible;
}

.message.sent .message-options-menu {
    background: rgba(255, 255, 255, 0.95);
}

/* Position menu below if near top of screen */
.message-wrapper {
    position: relative;
}

@keyframes slideDownFade {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.message-option-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 0.85rem;
    transition: background-color 0.2s, color 0.2s;
    white-space: nowrap;
    flex-shrink: 0; /* Prevent buttons from shrinking */
    min-width: fit-content;
}

.message-option-btn:hover {
    background: var(--hover-bg);
    color: var(--primary-color);
}

.message-option-btn svg {
    flex-shrink: 0;
}

/* Mobile-friendly message options menu */
@media (max-width: 768px) {
    .message-options-menu {
        min-width: auto;
        gap: 8px;
        padding: 6px;
    }
    
    .message-option-btn {
        padding: 10px 14px;
        font-size: 0.9rem;
        min-height: 44px; /* iOS tap target size */
    }
    
    .message-option-btn span:last-child {
        display: none; /* Hide text labels on mobile, show only icons */
    }
    
    .message-option-btn {
        flex-direction: column;
        gap: 4px;
    }
}

/* Hide old reply and react buttons - now in menu */
.btn-reply,
.btn-react {
    display: none !important;
}

/* Message edited indicator */
.message-edited-indicator {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-style: italic;
    opacity: 0.7;
    margin-left: 4px;
}

/* Deleted message placeholder */
.message-deleted-placeholder {
    font-style: italic;
    opacity: 0.85;
    color: var(--text-primary);
    padding: 8px;
    font-weight: 500;
}

.message[data-deleted="true"] .message-bubble {
    opacity: 0.6;
    background-color: var(--border-color, #e0e0e0) !important;
    cursor: default;
}

.message[data-deleted="true"].sent .message-bubble {
    background-color: var(--border-color, #e0e0e0) !important;
}

.message[data-deleted="true"].received .message-bubble {
    background-color: var(--border-color, #e0e0e0) !important;
}

/* Message edit input */
.message-edit-input {
    width: 100%;
    min-height: 60px;
    padding: 8px;
    border-radius: 8px;
    border: 2px solid var(--primary-color, #007bff);
    font-size: inherit;
    font-family: inherit;
    resize: vertical;
    background: var(--surface);
    color: var(--text-primary);
}

/* Update Notification */
.update-notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    max-width: 90%;
    width: 400px;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.update-notification-content {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.update-notification-content span {
    flex: 1;
    color: var(--text-primary);
    font-weight: 500;
    min-width: 150px;
}

.btn-update-now,
.btn-update-later {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

.btn-update-now {
    background: var(--primary-color);
    color: white;
}

.btn-update-now:hover {
    background: var(--primary-hover);
}

.btn-update-later {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-update-later:hover {
    background: var(--background);
    color: var(--text-primary);
}

@media (max-width: 480px) {
    .update-notification {
        width: calc(100% - 40px);
        max-width: none;
    }
    
    .update-notification-content {
        flex-direction: column;
        align-items: stretch;
    }
    
    .update-notification-content span {
        text-align: center;
        margin-bottom: 8px;
    }
    
    .btn-update-now,
    .btn-update-later {
        width: 100%;
    }
}
