/* CRM System Styles - Minimalist Design */

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --success-color: #16a34a;
    --warning-color: #d97706;
    --danger-color: #dc2626;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-color: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Prevent horizontal scroll on mobile */
html {
    overflow-x: hidden;
}

/* Improve touch targets on mobile */
@media (max-width: 768px) {
    button, a, input[type="submit"], input[type="button"] {
        min-height: 44px;
        min-width: 44px;
    }

    /* Better scroll behavior on iOS */
    * {
        -webkit-overflow-scrolling: touch;
    }

    /* Remove tap highlight on iOS */
    * {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    }
}

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

a {
    color: var(--primary-color);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Navbar */
.navbar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-brand a {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-color);
}

.navbar-menu {
    display: flex;
    gap: 1.5rem;
}

.navbar-menu a {
    color: var(--text-muted);
    font-weight: 500;
}

.navbar-menu a:hover {
    color: var(--primary-color);
    text-decoration: none;
}

.navbar-menu .logout {
    color: var(--danger-color);
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* Login Page */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: var(--bg-color);
}

.login-box {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    margin-bottom: 1.5rem;
    text-align: center;
    font-size: 1.5rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

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

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group small {
    display: block;
    margin-top: 0.25rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
    text-decoration: none;
}

.btn:hover {
    text-decoration: none;
}

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

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

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-large {
    padding: 1rem 3rem;
    font-size: 1.125rem;
}

.btn-secondary {
    background: #f1f5f9;
    color: var(--text-color);
}

.btn-secondary:hover {
    background: #e2e8f0;
}

.btn-block {
    display: block;
    width: 100%;
    text-align: center;
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.alert-error {
    background: #fef2f2;
    color: var(--danger-color);
    border: 1px solid #fecaca;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border-color);
}

.tab-btn {
    padding: 0.75rem 1.5rem;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-muted);
    transition: all 0.2s;
}

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

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Messages Page */
.messages-page {
    margin-bottom: 1.5rem;
}

.messages-filters {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.filter-group label {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.filter-group input,
.filter-group select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.875rem;
}

.messages-container {
    margin-bottom: 1rem;
}

.messages-table {
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.messages-table table {
    width: 100%;
    border-collapse: collapse;
}

.messages-table th,
.messages-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.messages-table th {
    background: #f1f5f9;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

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

.messages-table .loading,
.messages-table .no-messages,
.messages-table .error {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}

.messages-table .error {
    color: var(--danger-color);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-success {
    background: #dcfce7;
    color: #166534;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.text-muted {
    color: var(--text-muted);
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-top: 1.5rem;
}

.pagination span {
    color: var(--text-muted);
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* =============================================================================
   Messenger Layout
   ============================================================================= */

.messenger-layout {
    background: #f0f2f5;
    min-height: 100vh;
}

.messenger-container {
    display: flex;
    height: calc(100vh - 56px);
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 380px;
    background: #ffffff;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #e0e0e0;
    background: #fafafa;
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: #1a1a1a;
    margin: 0;
}

.sidebar-filters {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #e0e0e0;
    background: #fafafa;
}

.filters-top-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
    padding: 1rem 1.25rem;
    background: #fafafa;
    border-bottom: 1px solid #e0e0e0;
}

.filters-top-bar .filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 150px;
}

.filters-top-bar .filter-group label {
    font-size: 0.7rem;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filters-top-bar .filter-group select,
.filters-top-bar .filter-group input {
    padding: 0.5rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.875rem;
    background: #fff;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.filters-top-bar .filter-group select:focus,
.filters-top-bar .filter-group input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.filters-top-bar .search-group {
    flex: 1;
    min-width: 200px;
}

.filters-top-bar .search-group input {
    width: 100%;
}

.filters-top-bar .filter-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: auto;
}

.filters-top-bar .users-count {
    font-size: 0.75rem;
    color: #666;
    font-weight: 500;
    white-space: nowrap;
}

/* Sidebar Actions */
.sidebar-actions {
    padding: 1rem 1.25rem;
    border-top: 1px solid #e0e0e0;
    background: #fafafa;
}

/* Users List */
.sidebar-list {
    flex: 1;
    overflow-y: auto;
}

.sidebar-list-container {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.sidebar-list-container.hidden {
    display: none;
}

.users-list {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.user-item {
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background-color 0.15s;
}

.user-item:hover {
    background: #f5f5f5;
}

.user-item.active {
    background: #e3f2fd;
    border-left: 3px solid #2563eb;
}

.user-item-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.user-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: #1a1a1a;
    flex: 1;
}

.user-status-badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border-radius: 10px;
    font-weight: 600;
}

.status-active {
    background: #dcfce7;
    color: #166534;
}

.status-muted {
    background: #fef3c7;
    color: #92400e;
}

.status-banned {
    background: #fee2e2;
    color: #991b1b;
}

.status-new {
    background: #e0e7ff;
    color: #3730a3;
}

.user-item-details {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    margin-left: 1.5rem;
}

.user-id {
    color: #888;
    font-family: monospace;
    font-size: 0.75rem;
}

.user-last-msg {
    color: #666;
    font-size: 0.75rem;
    font-style: italic;
}

.users-list .loading,
.users-list .no-users,
.users-list .error {
    padding: 2rem;
    text-align: center;
    color: #666;
}

.users-list .error {
    color: #dc2626;
}

/* Infinite Scroll */
.infinite-scroll-trigger {
    padding: 1rem;
    text-align: center;
}

.scroll-end {
    color: #888;
    font-size: 0.75rem;
    font-style: italic;
}

/* Main Content */
.messenger-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #f5f5f5;
}

/* Chat Panel */
.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #f0f2f5;
}

.chat-placeholder {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.placeholder-content {
    text-align: center;
    padding: 2rem;
    color: #666;
}

.placeholder-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.placeholder-content h2 {
    font-size: 1.25rem;
    color: #1a1a1a;
    margin-bottom: 0.5rem;
}

.placeholder-content p {
    font-size: 0.875rem;
    color: #666;
}

/* Chat Container */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #f5f5f5;
}

.chat-header {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
    gap: 0.75rem;
}

.chat-header .chat-user-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1;
    min-width: 0;
}

.chat-header .chat-user-info h3 {
    margin: 0;
    font-size: 1rem;
    color: #1a1a1a;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header .user-status {
    font-size: 0.75rem;
    color: #666;
}

/* User details in chat header */
.chat-user-details {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    padding-left: 1.5rem;
    border-left: 1px solid #e0e0e0;
    min-width: 200px;
    max-width: 280px;
}

.user-details-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
}

.user-details-row .detail-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    min-width: 55px;
}

.user-details-row .detail-value {
    color: #1a1a1a;
    font-weight: 500;
}

.user-details-row .detail-value code {
    background: #f1f5f9;
    padding: 0.125rem 0.375rem;
    border-radius: 3px;
    font-size: 0.7rem;
}

.detail-badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 10px;
    font-size: 0.65rem;
    font-weight: 600;
}

.detail-badge.status-active {
    background: #dcfce7;
    color: #166534;
}

.detail-badge.status-muted {
    background: #fef3c7;
    color: #92400e;
}

.detail-badge.status-banned {
    background: #fee2e2;
    color: #991b1b;
}

.detail-badge.status-new {
    background: #f1f5f9;
    color: #64748b;
}

.detail-badge.banned {
    background: #fee2e2;
    color: #991b1b;
}

.detail-badge.muted {
    background: #fef3c7;
    color: #92400e;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 1px;
    background: #f5f5f5;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* Message Bubbles - Ultra Compact */
.message {
    display: flex;
    max-width: 80%;
    position: relative;
    justify-content: flex-start;
    width: fit-content;
    margin: 0;
    padding: 0;
}

.message-in,
.message-out {
    align-self: flex-start;
    width: fit-content;
}

.message-content {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
    word-break: break-word;
    position: relative;
    text-align: left;
    display: inline-block;
    width: fit-content;
    max-width: 500px;
    box-sizing: border-box;
}

.message-content > span:not(.message-time) {
    display: inline;
    word-break: break-word;
    white-space: normal;
    line-height: 1.4;
    font-size: 15px;
    margin: 0;
    padding: 0;
}

/* Incoming message - white bubble */
.message-in .message-content {
    background: #ffffff;
    color: #000000;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 4px;
}

/* Outgoing message - green bubble */
.message-out .message-content {
    background: #dcf8c6;
    color: #000000;
    border: 1px solid #c8e6c9;
    border-bottom-right-radius: 4px;
}

.message-time {
    font-size: 12px;
    color: #999999;
    display: inline-block;
    white-space: nowrap;
    line-height: 1;
    margin-left: 8px;
    vertical-align: baseline;
    flex-shrink: 0;
}

.message-out .message-time {
    color: #4caf50;
}

/* Group ID badge */
.group-badge {
    display: inline-block;
    font-size: 10px;
    color: #666;
    background: #f0f0f0;
    padding: 2px 6px;
    border-radius: 4px;
    margin-right: 6px;
    font-family: monospace;
    vertical-align: baseline;
}

.message-media {
    margin-top: 0;
    max-width: 200px;
    overflow: hidden;
}

.message-media img {
    max-width: 100%;
    max-height: 150px;
    border-radius: 4px;
    display: block;
    object-fit: cover;
}

.message-attachment {
    font-size: 11px;
    color: #666666;
    padding: 1px 4px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    margin-top: 0;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    line-height: 1;
    height: auto;
}

.message-attachment a {
    color: var(--primary-color);
    text-decoration: none;
}

.message-attachment a:hover {
    text-decoration: underline;
}

/* Media attachments */
.message-media {
    margin-top: 4px;
    cursor: pointer;
    position: relative;
}

.message-media img {
    max-width: 250px;
    max-height: 200px;
    border-radius: 8px;
    object-fit: cover;
    display: block;
    transition: transform 0.2s;
}

.message-media img:hover {
    transform: scale(1.02);
}

.message-media video {
    display: block;
    border-radius: 8px;
}

.message-media audio {
    display: block;
    margin-top: 4px;
}

.media-duration {
    font-size: 11px;
    color: #999;
    margin-top: 2px;
}

.media-title {
    font-size: 12px;
    color: #666;
    margin-top: 2px;
    font-weight: 500;
}

.sticker-emoji {
    position: absolute;
    bottom: 4px;
    right: 4px;
    font-size: 20px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    padding: 2px 6px;
}

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

.media-modal-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
}

.media-modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 24px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.media-modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Chat Tabs */
.chat-tabs {
    display: flex;
    gap: 0;
    background: #f5f5f5;
    border-bottom: 1px solid #e0e0e0;
    padding: 0;
}

.chat-tab-btn {
    flex: 1;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: #666;
    transition: all 0.2s;
}

.chat-tab-btn:hover {
    background: rgba(37, 99, 235, 0.05);
    color: var(--primary-color);
}

.chat-tab-btn.active {
    background: #fff;
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

/* Group message style */
.message-group {
    max-width: 90%;
}

.message-group .message-content {
    background: #f0f7ff;
    border: 1px solid #d0e3f7;
    border-bottom-left-radius: 4px;
}

/* Group name badge */
.group-name-badge {
    display: inline-block;
    font-size: 11px;
    color: var(--primary-color);
    background: rgba(37, 99, 235, 0.1);
    padding: 2px 8px;
    border-radius: 4px;
    margin-bottom: 4px;
    font-weight: 500;
}

/* Deleted message style */
.message-deleted .message-content {
    background: #fff0f0;
    border: 1px solid #ffd0d0;
    opacity: 0.85;
}

.message-deleted-badge {
    display: inline-block;
    font-size: 11px;
    color: #dc2626;
    background: rgba(220, 38, 38, 0.1);
    padding: 2px 8px;
    border-radius: 4px;
    margin-bottom: 4px;
    font-weight: 500;
}

.no-messages {
    text-align: center;
    color: #666;
    padding: 2rem;
    font-size: 0.9rem;
}

/* Chat Input */
.chat-input {
    padding: 0.75rem 1.5rem;
    background: #fff;
    border-top: 1px solid #e0e0e0;
}

.chat-input #message-form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.chat-input #message-text {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.875rem;
    resize: vertical;
    font-family: inherit;
    min-height: 60px;
}

.chat-input #message-text:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.chat-input .input-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.chat-input .file-upload {
    font-size: 0.75rem;
    padding: 0.375rem 0.625rem;
    background: #f1f5f9;
    border-radius: 4px;
    cursor: pointer;
}

.chat-input .file-upload:hover {
    background: #e5e5e5;
}

.chat-input #file-name {
    font-size: 0.7rem;
    color: #666;
    font-style: italic;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Message Status */
.message-status {
    font-size: 0.75rem;
    padding: 6px 12px;
    border-radius: 6px;
    margin-top: 8px;
    text-align: center;
}

.message-status.sending {
    background: #e3f2fd;
    color: #1565c0;
}

.message-status.success {
    background: #e8f5e9;
    color: #2e7d32;
}

.message-status.error {
    background: #ffebee;
    color: #c62828;
}

/* =============================================================================
   Broadcast Page
   ============================================================================= */

.broadcast-page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 0;
}

.broadcast-header {
    margin-bottom: 2rem;
}

.back-link {
    color: #666;
    font-size: 0.875rem;
    text-decoration: none;
    transition: color 0.2s;
}

.back-link:hover {
    color: #2563eb;
    text-decoration: underline;
}

.broadcast-container {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.broadcast-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    padding: 2rem;
}

.broadcast-column {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.broadcast-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.section-title {
    font-size: 1rem;
    font-weight: 700;
    color: #1a1a1a;
    margin: 0;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid #e0e0e0;
}

.filter-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.filter-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.filter-field.full-width {
    grid-column: 1 / -1;
}

.filter-field label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filter-field select,
.filter-field input {
    padding: 0.625rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.875rem;
    background: #fff;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.filter-field select:focus,
.filter-field input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.filter-field small {
    display: block;
    margin-top: 0.25rem;
    color: #666;
    font-size: 0.75rem;
}

.selected-users-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: #e8f4fd;
    border-radius: 6px;
    font-size: 0.875rem;
    color: #1e40af;
    font-weight: 500;
}

.selected-users-info .info-icon {
    font-weight: 700;
}

/* Preview Panel */
.broadcast-preview {
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: 300px;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: #e9ecef;
    border-bottom: 1px solid #dee2e6;
    font-size: 0.875rem;
    font-weight: 600;
}

.preview-count {
    background: #2563eb;
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
}

.preview-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.preview-user {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    margin-bottom: 0.25rem;
    background: #fff;
    border: 1px solid #e0e0e0;
}

.preview-name {
    font-size: 0.875rem;
    color: #1a1a1a;
    font-weight: 500;
}

.preview-empty,
.preview-more {
    text-align: center;
    padding: 1.5rem;
    color: #666;
    font-size: 0.875rem;
}

.preview-more {
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
    font-weight: 600;
    color: #2563eb;
}

/* Info Box */
.broadcast-info-box {
    background: #f8f9ff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 1rem;
}

.broadcast-info-box h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: #1a1a1a;
    margin: 0 0 0.75rem 0;
}

.broadcast-info-box ul {
    margin: 0;
    padding-left: 1.25rem;
    color: #666;
    font-size: 0.875rem;
    line-height: 1.6;
}

.broadcast-info-box li {
    margin-bottom: 0.25rem;
}

/* Footer */
.broadcast-footer {
    border-top: 1px solid #e0e0e0;
    padding: 1.5rem 2rem;
    background: #fafafa;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.broadcast-status {
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    min-width: 300px;
    text-align: center;
}

.broadcast-status.sending {
    background: #dbeafe;
    color: #1e40af;
}

.broadcast-status.success {
    background: #dcfce7;
    color: #166534;
}

.broadcast-status.error {
    background: #fee2e2;
    color: #991b1b;
}

/* Loading & Error States */
.loading,
.error {
    text-align: center;
    padding: 1rem;
    color: #666;
    font-size: 0.9rem;
}

.error {
    color: #dc2626;
}

/* =============================================================================
   Mobile Responsive Styles
   ============================================================================= */

/* Tablet (≤768px) */
@media (max-width: 768px) {
    /* Global improvements */
    -webkit-tap-highlight-color: transparent;

    body {
        font-size: 14px;
        overflow-x: hidden;
    }

    .container {
        padding: 1rem;
        max-width: 100%;
    }

    /* Navbar mobile */
    .navbar {
        padding: 0.5rem 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .navbar-brand a {
        font-size: 1.1rem;
    }

    .navbar-menu {
        gap: 0.75rem;
        font-size: 0.875rem;
        flex-wrap: wrap;
    }

    .navbar-menu button.logout {
        padding: 0.25rem 0.5rem;
    }

    /* Messenger layout - show sidebar only by default */
    .messenger-container {
        flex-direction: column;
        height: calc(100vh - 48px);
        position: relative;
    }

    .sidebar {
        width: 100%;
        height: 100%;
        border-right: none;
        border-bottom: none;
        display: flex;
        position: absolute;
        top: 0;
        left: 0;
        z-index: 10;
        transition: transform 0.3s ease;
    }

    .sidebar.hidden {
        display: none;
    }

    .sidebar-header {
        padding: 0.75rem 1rem;
    }

    .sidebar-header h2 {
        font-size: 1.1rem;
    }

    .sidebar-filters {
        padding: 0.75rem 1rem;
    }

    .sidebar-list {
        flex: 1;
    }

    /* Filters on mobile */
    .filters-top-bar {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.75rem 1rem;
        width: 100%;
    }

    .filters-top-bar .filter-group {
        min-width: 100%;
        width: 100%;
    }

    .filters-top-bar .search-group {
        min-width: 100%;
        width: 100%;
    }

    .filters-top-bar .filter-actions {
        width: 100%;
        justify-content: space-between;
        margin-left: 0;
    }

    /* Sidebar filters wrapper on mobile */
    .sidebar-filters {
        padding: 0.75rem 1rem;
        width: 100%;
        overflow-x: hidden;
    }

    /* Users list mobile */
    .user-item {
        padding: 0.75rem 1rem;
    }

    .user-name {
        font-size: 0.875rem;
    }

    .user-status-badge {
        font-size: 0.65rem;
        padding: 0.15rem 0.4rem;
    }

    .user-id {
        font-size: 0.7rem;
    }

    .user-last-msg {
        font-size: 0.7rem;
    }

    /* Chat panel mobile - full screen when active */
    .messenger-main {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        right: 0;
        z-index: 20;
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }

    .messenger-main.active {
        transform: translateX(0);
    }

    .chat-panel {
        width: 100%;
    }

    /* Chat header mobile */
    .chat-header {
        padding: 0.5rem 0.75rem;
        flex-wrap: wrap;
        gap: 0.5rem;
        position: sticky;
        top: 0;
        z-index: 5;
        background: #f8f9fa;
    }

    .btn-back {
        padding: 0.4rem 0.6rem;
        font-size: 0.75rem;
        flex-shrink: 0;
    }

    .chat-header .chat-user-info {
        flex: 1;
        min-width: 0;
        overflow: hidden;
    }

    .chat-header .chat-user-info h3 {
        font-size: 0.9rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .user-details-toggle {
        flex-shrink: 0;
        padding: 0.4rem 0.5rem;
        font-size: 1.1rem;
        line-height: 1;
    }

    .chat-user-details {
        display: none; /* Hide by default on mobile, show via modal */
    }

    /* Chat messages mobile */
    .message {
        max-width: 90%;
    }

    .message-content {
        padding: 10px 14px;
        font-size: 14px;
        max-width: 100%;
    }

    .message-content > span:not(.message-time) {
        font-size: 14px;
    }

    .message-time {
        font-size: 11px;
    }

    .message-media img {
        max-width: 200px;
        max-height: 150px;
    }

    .message-media video {
        max-width: 200px;
        max-height: 150px;
    }

    /* Chat input mobile */
    .chat-input {
        padding: 0.5rem 0.75rem;
    }

    .chat-input #message-text {
        padding: 0.4rem;
        font-size: 0.875rem;
        min-height: 50px;
    }

    .chat-input .input-actions {
        flex-wrap: wrap;
        gap: 0.375rem;
    }

    .chat-input .file-upload {
        padding: 0.3rem 0.5rem;
        font-size: 0.7rem;
    }

    /* Chat tabs mobile */
    .chat-tabs {
        padding: 0;
    }

    .chat-tab-btn {
        padding: 0.6rem 0.75rem;
        font-size: 0.8rem;
    }

    /* Modal improvements */
    .media-modal-close {
        width: 44px;
        height: 44px;
        top: 10px;
        right: 10px;
        font-size: 28px;
    }

    /* Messages page mobile */
    .messages-page h1 {
        font-size: 1.25rem;
    }

    .tabs {
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .tab-btn {
        padding: 0.6rem 1rem;
        font-size: 0.875rem;
    }

    .messages-filters {
        flex-direction: column;
        gap: 0.5rem;
    }

    /* Wrap tables in scrollable container */
    .messages-table {
        border-radius: 6px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .messages-table table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        min-width: 600px;
    }

    .messages-table th,
    .messages-table td {
        padding: 0.75rem 0.5rem;
        font-size: 0.8rem;
    }

    .pagination {
        gap: 0.5rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    .pagination .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }

    /* Broadcast page mobile */
    .broadcast-page {
        padding: 1rem 0;
    }

    .broadcast-header {
        margin-bottom: 1rem;
        padding: 0 1rem;
    }

    .broadcast-header h1 {
        font-size: 1.4rem;
    }

    .broadcast-container {
        border-radius: 8px;
        margin: 0 0.5rem;
    }

    .broadcast-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
        padding: 1rem;
    }

    .broadcast-column {
        gap: 1.5rem;
    }

    .section-title {
        font-size: 0.9rem;
        padding-bottom: 0.5rem;
    }

    .filter-row {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .filter-field select,
    .filter-field input {
        padding: 0.5rem 0.625rem;
        font-size: 0.8rem;
    }

    .btn-large {
        padding: 0.75rem 2rem;
        font-size: 1rem;
        width: 100%;
    }

    .broadcast-footer {
        padding: 1rem;
        flex-direction: column;
        align-items: stretch;
    }

    .broadcast-status {
        min-width: auto;
        width: 100%;
        font-size: 0.8rem;
        padding: 0.5rem 1rem;
    }

    .broadcast-preview {
        max-height: 250px;
    }

    .broadcast-info-box {
        padding: 0.75rem;
    }

    .broadcast-info-box h4 {
        font-size: 0.85rem;
    }

    .broadcast-info-box ul {
        font-size: 0.8rem;
        padding-left: 1rem;
    }

    /* Login page mobile */
    .login-box {
        padding: 1.5rem;
        margin: 1rem;
    }

    .login-box h1 {
        font-size: 1.25rem;
    }

    /* Buttons mobile */
    .btn {
        padding: 0.625rem 1.25rem;
        font-size: 0.875rem;
    }

    .btn-sm {
        padding: 0.4rem 0.75rem;
        font-size: 0.8rem;
    }

    .btn-block {
        padding: 0.75rem;
    }

    /* Sidebar actions mobile */
    .sidebar-actions {
        padding: 0.75rem 1rem;
    }

    .sidebar-actions .btn-block {
        font-size: 0.875rem;
        padding: 0.625rem;
    }

    /* User details toggle button */
    .user-details-toggle {
        padding: 0.4rem 0.5rem;
        font-size: 1rem;
        line-height: 1;
    }
}

/* Phone (≤480px) */
@media (max-width: 480px) {
    body {
        font-size: 13px;
        overflow-x: hidden;
    }

    .container {
        padding: 0.75rem;
        max-width: 100%;
    }

    /* Navbar extra compact */
    .navbar {
        padding: 0.4rem 0.75rem;
    }

    .navbar-brand a {
        font-size: 1rem;
    }

    .navbar-menu {
        gap: 0.5rem;
        font-size: 0.8rem;
    }

    .navbar-menu a,
    .navbar-menu button {
        font-size: 0.8rem;
        min-height: auto;
    }

    /* Prevent zoom on input focus on iOS */
    input,
    select,
    textarea {
        font-size: 16px !important;
    }

    /* Sidebar header */
    .sidebar-header {
        padding: 0.5rem 0.75rem;
    }

    .sidebar-header h2 {
        font-size: 1rem;
    }

    /* Users extra compact */
    .user-item {
        padding: 0.625rem 0.75rem;
    }

    .user-name {
        font-size: 0.8rem;
    }

    .user-item-details {
        margin-left: 1.25rem;
    }

    .user-id {
        font-size: 0.65rem;
    }

    .user-last-msg {
        font-size: 0.65rem;
    }

    /* Chat messages extra compact */
    .message {
        max-width: 95%;
    }

    .message-content {
        padding: 8px 12px;
        font-size: 13px;
    }

    .message-content > span:not(.message-time) {
        font-size: 13px;
    }

    .message-time {
        font-size: 10px;
    }

    .message-media img,
    .message-media video {
        max-width: 180px;
        max-height: 130px;
    }

    .chat-input {
        padding: 0.4rem 0.5rem;
    }

    .chat-input #message-text {
        min-height: 45px;
        font-size: 16px; /* Prevent zoom on iOS */
    }

    .chat-input .file-upload {
        padding: 0.3rem 0.4rem;
        font-size: 0.65rem;
    }

    /* Chat tabs extra compact */
    .chat-tab-btn {
        padding: 0.5rem 0.5rem;
        font-size: 0.75rem;
    }

    /* Messages page extra compact */
    .messages-page h1 {
        font-size: 1.1rem;
    }

    .tab-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }

    .messages-table {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .messages-table table {
        min-width: 550px;
    }

    .messages-table th,
    .messages-table td {
        padding: 0.5rem 0.375rem;
        font-size: 0.75rem;
    }

    /* Broadcast extra compact */
    .broadcast-header h1 {
        font-size: 1.2rem;
    }

    .broadcast-grid {
        padding: 0.75rem;
        gap: 1rem;
    }

    .section-title {
        font-size: 0.85rem;
    }

    .broadcast-info-box {
        padding: 0.75rem;
    }

    .broadcast-info-box h4 {
        font-size: 0.8rem;
    }

    .broadcast-info-box ul {
        font-size: 0.8rem;
    }

    .preview-list {
        max-height: 200px;
    }

    /* Forms extra compact */
    .form-group {
        margin-bottom: 0.75rem;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 0.625rem;
        font-size: 16px; /* Prevent zoom on iOS */
    }

    .form-group label {
        font-size: 0.8rem;
    }

    /* Login box extra compact */
    .login-box {
        padding: 1.25rem;
        margin: 0.75rem;
    }

    .login-box h1 {
        font-size: 1.1rem;
    }
}

/* Legacy responsive (keep for fallback) */
@media (max-width: 900px) and (min-width: 769px) {
    .messenger-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: 50%;
        border-right: none;
        border-bottom: 1px solid #e0e0e0;
    }

    .broadcast-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .filter-row {
        grid-template-columns: 1fr;
    }
}
