/* ===== CSS Variables ===== */
:root {
    --primary-color: #4F46E5;
    --primary-hover: #4338CA;
    --primary-light: #EEF2FF;

    --accent-primary: #4F46E5;
    --accent-hover: #4338CA;
    --accent-light: #EEF2FF;
    --secondary-color: #64748B;
    --success-color: #10B981;
    --error-color: #EF4444;
    --warning-color: #F59E0B;

    --bg-primary: #FFFFFF;
    --bg-secondary: #F8FAFC;
    --bg-tertiary: #F1F5F9;
    --bg-hover: #E2E8F0;

    --text-primary: #0F172A;
    --text-secondary: #64748B;
    --text-tertiary: #94A3B8;

    --border-color: #E2E8F0;
    --border-radius: 12px;
    --border-radius-sm: 8px;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);

    --sidebar-width: 320px;
    --header-height: 70px;

    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: -webkit-fill-available;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-secondary);
    overflow: hidden;
    min-height: 100dvh;
    min-height: -webkit-fill-available;
}

button {
    font-family: inherit;
    cursor: pointer;
}

input, textarea, select {
    font-family: inherit;
}

/* ===== Auth Container ===== */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-card {
    background: var(--bg-primary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 400px;
    padding: 40px;
    animation: fadeInUp 0.4s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.auth-logo {
    font-size: 48px;
    margin-bottom: 16px;
}

.auth-header h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}

.auth-subtitle {
    color: var(--text-secondary);
    font-size: 14px;
}

.auth-form {
    margin-bottom: 24px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 13px;
    color: var(--text-primary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-size: 14px;
    transition: all var(--transition-fast);
    background: var(--bg-primary);
}

.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 var(--primary-light);
}

.form-hint {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-tertiary);
}

.error-message {
    padding: 12px;
    margin-bottom: 16px;
    background: #FEE2E2;
    color: #991B1B;
    border-radius: var(--border-radius-sm);
    font-size: 13px;
    display: none;
}

.error-message:not(:empty) {
    display: block;
}

.success-message {
    padding: 12px;
    margin-bottom: 16px;
    background: #D1FAE5;
    color: #065F46;
    border-radius: var(--border-radius-sm);
    font-size: 13px;
}

.auth-footer {
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
}

.auth-footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

.auth-footer a:hover {
    text-decoration: underline;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: var(--border-radius-sm);
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition-fast);
    position: relative;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-hover);
}

.btn-block {
    width: 100%;
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: 50%;
    font-size: 18px;
    transition: all var(--transition-fast);
}

.btn-icon:hover {
    background: var(--bg-hover);
}

.btn-icon-sm {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    border-radius: 50%;
    font-size: 14px;
    transition: all var(--transition-fast);
}

.btn-icon-sm:hover {
    background: var(--bg-hover);
}

.btn-send {
    color: var(--primary-color);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-send:not(:disabled):hover {
    background: var(--primary-light);
}

.btn-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 50%;
    transition: all var(--transition-fast);
}

.btn-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-loader,
.spinner {
    display: inline-block;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== App Container ===== */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
    position: relative; /* positioning context for the mobile sidebar overlay */
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-normal);
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    overflow: hidden;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-avatar-fallback {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-light);
    color: var(--primary-color);
    font-size: 20px;
}

.user-info {
    flex: 1;
}

.user-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
}

.user-status {
    font-size: 12px;
    color: var(--text-secondary);
}

.user-status.online::before {
    content: "●";
    color: var(--success-color);
    margin-right: 4px;
}

.sidebar-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.tab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 500;
    position: relative;
    transition: all var(--transition-fast);
}

.tab-btn:hover {
    background: var(--bg-hover);
}

.tab-btn.active {
    color: var(--primary-color);
}

.tab-btn.active::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary-color);
}

.tab-icon {
    font-size: 18px;
}

.badge {
    background: var(--error-color);
    color: white;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
}

.tab-content {
    display: none;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.tab-content.active {
    display: flex;
}

.search-bar {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-primary);
}

.search-icon {
    font-size: 16px;
    color: var(--text-tertiary);
}

.search-bar input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 14px;
    outline: none;
}

.chat-list,
.module-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.chat-item,
.module-item {
    padding: 12px;
    margin-bottom: 4px;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-item:hover,
.module-item:hover {
    background: var(--bg-secondary);
}

.chat-item.active {
    background: var(--primary-light);
    color: var(--primary-color);
}

.chat-item-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    overflow: hidden;
}

.chat-item-content {
    flex: 1;
    min-width: 0;
}

.chat-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.chat-item-name {
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-time {
    font-size: 11px;
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.chat-item-preview {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-unread {
    display: inline-block;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: var(--primary-color);
    color: white;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    line-height: 20px;
}

.module-item-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--border-radius-sm);
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.module-item-content {
    flex: 1;
    min-width: 0;
}

.module-item-name {
    font-weight: 500;
    font-size: 14px;
    margin-bottom: 2px;
}

.module-item-format {
    font-size: 12px;
    color: var(--text-tertiary);
}

.sidebar-actions {
    padding: 12px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ===== Chat Container ===== */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
}

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    text-align: center;
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h2 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--text-secondary);
    font-size: 16px;
}

.chat-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Use dynamic viewport height for mobile browser chrome */
}

.chat-header {
    height: var(--header-height);
    padding: 0 20px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 16px;
}

.chat-header-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.chat-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 2px;
}

.chat-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
}

.chat-header-actions {
    display: flex;
    gap: 8px;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    position: relative;
}

.messages {
    max-width: 900px;
    margin: 0 auto;
}

.message {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    animation: messageIn 0.2s ease;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.message-content {
    flex: 1;
    max-width: 70%;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.message-sender {
    font-weight: 600;
    font-size: 13px;
}

.message-time {
    font-size: 11px;
    color: var(--text-tertiary);
}

.message-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    background: var(--bg-primary);
    box-shadow: var(--shadow-sm);
    word-wrap: break-word;
}

.message.sent {
    flex-direction: row-reverse;
}

.message.sent .message-content {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}


.message.sent .message-bubble {
    background: var(--primary-color);
    color: white;
}

.message.highlight-flash {
    animation: highlightFlash 2s ease-out;
}
@keyframes highlightFlash {
    0%, 20% { background: rgba(79, 70, 229, 0.15); }
    100% { background: transparent; }
}

.message img {
    max-width: 100%;
    border-radius: var(--border-radius-sm);
    margin-top: 4px;
}

.message audio,
.message video {
    max-width: 100%;
    margin-top: 4px;
}

.download-link {
    display: inline-block;
    margin-top: 6px;
    font-size: 12px;
    color: var(--primary-color);
    text-decoration: none;
    opacity: 0.85;
}
.download-link:hover {
    opacity: 1;
    text-decoration: underline;
}
.message.sent .download-link {
    color: rgba(255, 255, 255, 0.9);
}

/* scroll-bottom-btn — styled below */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.input-container {
    padding: 16px 20px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    max-width: 900px;
    margin: 0 auto;
}

.input-wrapper textarea {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    outline: none;
    font-size: 14px;
    max-height: 120px;
    min-height: 24px;
}

.input-hint {
    max-width: 900px;
    margin: 8px auto 0;
    text-align: center;
    font-size: 12px;
    color: var(--text-tertiary);
}

.input-hint kbd {
    padding: 2px 6px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    font-family: monospace;
    font-size: 11px;
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.modal-content {
    position: relative;
    background: var(--bg-primary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-xl);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 32px;
    animation: scaleIn 0.2s ease;
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-header {
    margin-bottom: 24px;
}

.modal-header h3 {
    font-size: 20px;
    font-weight: 600;
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    justify-content: flex-end;
}

/* ===== Toast Notifications ===== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toast {
    background: var(--bg-primary);
    padding: 16px 20px;
    border-radius: var(--border-radius-sm);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    animation: slideInRight 0.3s ease;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.toast.success {
    border-left: 4px solid var(--success-color);
}

.toast.error {
    border-left: 4px solid var(--error-color);
}

.toast.warning {
    border-left: 4px solid var(--warning-color);
}

.toast-icon {
    font-size: 20px;
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
}

.toast-message {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ===== Loading Overlay ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(4px);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-spinner {
    text-align: center;
}

.loading-spinner .spinner {
    width: 40px;
    height: 40px;
    border-width: 4px;
    border-color: var(--border-color);
    border-top-color: var(--primary-color);
    margin: 0 auto 16px;
}

.loading-spinner p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ===== Mobile Styles ===== */
.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    :root {
        --sidebar-width: 100%;
        --header-height: 60px;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 100%;
        z-index: 200;
        transform: translateX(-100%);
        overflow-y: auto;
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .mobile-only {
        display: flex;
    }

    .mobile-only.btn {
        display: inline-flex;
    }

    .chat-header {
        padding: 0 12px;
    }

    .messages-container {
        padding: 12px;
    }

    .input-container {
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        position: sticky;
        bottom: 0;
        z-index: 100;
    }

    .message-content {
        max-width: calc(100% - 48px);
        min-width: 0;
    }

    .message-bubble {
        word-wrap: break-word;
        overflow-wrap: break-word;
        word-break: break-word;
        max-width: 100%;
    }

    .messages {
        max-width: 100%;
        overflow-x: hidden;
    }

    .messages-container {
        overflow-x: hidden;
    }

    .auth-card {
        padding: 28px;
    }

    .modal-content {
        padding: 24px;
    }

    /* Media panel: full-width slide-in overlay on mobile */
    .media-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: min(100%, 320px);
        border-left: none;
        box-shadow: var(--shadow-xl);
        z-index: 300;
        display: flex !important;
        transform: translateX(100%);
    }
    .media-panel:not(.hidden) {
        transform: translateX(0);
    }
    .media-panel.hidden {
        transform: translateX(100%);
    }
    #media-panel-backdrop.active {
        display: block;
    }
    /* Show the panel close button only on mobile */
    #media-panel-close {
        display: flex !important;
    }
}

/* ===== Scrollbar Styling ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* ===== User Picker ===== */
.user-picker-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 280px;
    overflow-y: auto;
}

.user-picker-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.user-picker-item:hover {
    background: var(--bg-hover);
}

.user-picker-checkbox {
    cursor: pointer;
}

.user-picker-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

/* ===== Admin Panel ===== */
.admin-req-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    margin-bottom: 8px;
}

.admin-req-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.admin-req-info small {
    color: var(--text-secondary);
    font-size: 12px;
}

.admin-req-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

/* ===== Utility Classes ===== */
.text-center {
    text-align: center;
}

.hidden {
    display: none !important;
    pointer-events: none !important;
}

.divider {
    height: 1px;
    background: var(--border-color);
    margin: 16px 0;
}

/* ===== Dark Theme ===== */
[data-theme="dark"] {
    --primary-color: #6366F1;
    --primary-hover: #4F46E5;
    --primary-light: #1E1B4B;

    --accent-primary: #6366F1;
    --accent-hover: #4F46E5;
    --accent-light: #1E1B4B;

    --bg-primary: #1E1E2E;
    --bg-secondary: #181825;
    --bg-tertiary: #313244;
    --bg-hover: #45475A;

    --text-primary: #CDD6F4;
    --text-secondary: #BAC2DE;
    --text-tertiary: #6C7086;

    --border-color: #313244;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .loading-overlay {
    background: rgba(30, 30, 46, 0.9);
}

[data-theme="dark"] .form-group input,
[data-theme="dark"] .form-group select,
[data-theme="dark"] .form-group textarea {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

[data-theme="dark"] .auth-container {
    background: linear-gradient(135deg, #312e81 0%, #1e1b4b 100%);
}

/* ===== Settings Modal Tabs ===== */
.settings-tabs-nav {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.settings-tab-btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 13px;
    cursor: pointer;
    position: relative;
    transition: all var(--transition-fast);
}

.settings-tab-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.settings-tab-btn.active {
    color: var(--primary-color);
    font-weight: 600;
}

.settings-tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary-color);
}

.settings-tab-pane {
    display: none;
}

.settings-tab-pane.active {
    display: block;
}

/* ===== Avatar Preview ===== */
.avatar-preview-container {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
    border: 2px solid var(--border-color);
}

.avatar-preview-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-upload-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition-fast);
    color: var(--text-primary);
}

.avatar-upload-label:hover {
    background: var(--bg-hover);
}

/* Profile summary in settings Profile tab */
.profile-summary {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.profile-summary-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--accent-primary);
    color: #fff;
    font-size: 22px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.profile-summary-avatar .avatar-img {
    width: 52px;
    height: 52px;
    object-fit: cover;
}

.profile-summary-name {
    font-weight: 600;
    font-size: 16px;
    color: var(--text-primary);
}

.profile-summary-nick {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Profile modal textarea */
#pf-bio {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
}

#pf-bio:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(37,99,235,0.15);
}

/* User info modal (read-only) */
.user-info-fields {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
}

.user-info-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

.user-info-row:last-child {
    border-bottom: none;
}

.user-info-label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 13px;
    min-width: 72px;
    flex-shrink: 0;
}

.user-info-value {
    color: var(--text-primary);
    font-size: 14px;
    word-break: break-word;
}

/* ── Scroll-to-bottom button ── */
.scroll-bottom-btn {
    position: absolute;
    bottom: 80px;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    right: 20px;
    z-index: 50;
    width: 44px;
    height: 44px;
    background: var(--accent-primary);
    color: #fff;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    font-size: 18px;
    box-shadow: 0 2px 10px rgba(0,0,0,.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, transform .1s;
    -webkit-tap-highlight-color: transparent;
}

.scroll-bottom-btn:hover {
    background: var(--accent-hover, #1d4ed8);
    transform: scale(1.08);
}

/* ── Message action buttons ── */
.message-actions {
    display: flex;
    gap: 4px;
    margin-top: 4px;
}

.msg-action-btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    cursor: pointer;
    font-size: 12px;
    padding: 3px 8px;
    border-radius: 6px;
    color: var(--text-secondary);
    transition: background .15s, color .15s;
    line-height: 1.4;
}

.msg-action-btn:hover {
    background: var(--accent-primary);
    color: #fff;
    border-color: var(--accent-primary);
}

/* ── Edit bar above input ── */
.edit-bar {
    padding: 6px 16px;
    background: var(--accent-light, #eff6ff);
    color: var(--accent-primary);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-top: 1px solid var(--border-color);
}

.btn-link {
    background: none;
    border: none;
    color: var(--accent-primary);
    cursor: pointer;
    font-size: 13px;
    text-decoration: underline;
    padding: 0;
}

/* ── Scheduled messages list ── */
.sm-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
    gap: 8px;
}

.sm-item:last-child { border-bottom: none; }

.sm-item-content {
    font-size: 14px;
    color: var(--text-primary);
    word-break: break-word;
}

.sm-item-meta {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.sm-item-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

/* ===== Avatar Images ===== */
.avatar-img {
    object-fit: cover;
    border-radius: 50%;
    display: block;
    flex-shrink: 0;
}

.letter-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background-color: var(--primary-color, #4F46E5);
    color: white;
    font-weight: 700;
    text-align: center;
    flex-shrink: 0;
    user-select: none;
}

/* ===== PWA / Mobile UX ===== */

/* Safe-area padding for notch/home-bar devices */
body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

.input-container {
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
}

/* Minimum 44px touch targets */
button, .btn, .tab-btn, .btn-icon, .btn-icon-sm {
    min-height: 44px;
}

.tab-btn {
    min-width: 44px;
}

/* Prevent double-tap zoom on buttons */
button, .btn, a {
    touch-action: manipulation;
}

/* Smooth momentum scrolling on message list */
.messages-container {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* On very small screens, expand the message input tap target */
@media (max-width: 640px) {
    .message-content {
        max-width: 92%;
    }

    .input-container {
        padding: 8px;
    }
}

/* ===== CHAT BODY FLEX (for media panel) ===== */
.chat-body-flex { display: flex; flex-direction: column; flex: 1; overflow: hidden; min-height: 0; }
.chat-body-flex .chat-body-row { display: flex; flex: 1; overflow: hidden; min-height: 0; }
.chat-body-flex .messages-container { flex: 1; overflow-y: auto; }

/* ===== MEDIA PANEL ===== */
.media-panel { width: 260px; border-left: 1px solid var(--border-color); display: flex; flex-direction: column; background: var(--bg-primary); transition: transform var(--transition-normal); }
.media-panel.hidden { display: none; }

/* ===== MEDIA PANEL BACKDROP (mobile) ===== */
#media-panel-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 299;
    touch-action: none;
}
.media-tabs { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--border-color); flex-shrink: 0; }
.media-tab { padding: 4px 8px; border-radius: 6px; border: none; cursor: pointer; background: transparent; color: var(--text-secondary); font-size: 13px; }
.media-tab.active { background: var(--primary-color); color: white; }
#media-list { flex: 1; overflow-y: auto; padding: 8px; }
#media-preview { min-height: 140px; border-top: 1px solid var(--border-color); padding: 8px; overflow: hidden; }
#media-preview img { max-width: 100%; max-height: 120px; border-radius: 6px; object-fit: contain; }
.media-item { display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: 6px; cursor: pointer; margin-bottom: 4px; }
.media-item:hover { background: var(--bg-secondary); }
.media-item-icon { font-size: 20px; flex-shrink: 0; }
.media-item-info { min-width: 0; }
.media-item-name { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-item-meta { font-size: 11px; color: var(--text-secondary); }

/* ===== CHAT SEARCH BAR ===== */
.chat-search-bar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: var(--bg-secondary); border-bottom: 1px solid var(--border-color); flex-shrink: 0; }
.chat-search-bar input { flex: 1; padding: 6px 10px; border: 1px solid var(--border-color); border-radius: 6px; background: var(--bg-primary); color: var(--text-primary); font-size: 13px; outline: none; }
.search-count { font-size: 12px; color: var(--text-secondary); white-space: nowrap; }
.message-search-highlight { outline: 2px solid var(--primary-color); border-radius: 8px; }
.message-search-current { outline: 2px solid #f59e0b; border-radius: 8px; }

/* ===== EMOJI PICKER ===== */
.emoji-picker { position: fixed; z-index: 1000; background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: 12px; padding: 8px; box-shadow: 0 4px 20px rgba(0,0,0,.2); width: 320px; bottom: 80px; }
.emoji-picker.hidden { display: none; }
.emoji-category-tabs { display: flex; gap: 4px; margin-bottom: 6px; flex-wrap: wrap; }
.emoji-cat-btn { padding: 3px 8px; border-radius: 6px; border: none; cursor: pointer; background: transparent; font-size: 18px; }
.emoji-cat-btn.active { background: var(--bg-secondary); }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; max-height: 180px; overflow-y: auto; }
.emoji-btn-item { font-size: 20px; cursor: pointer; padding: 4px; border-radius: 4px; text-align: center; border: none; background: transparent; }
.emoji-btn-item:hover { background: var(--bg-secondary); }

/* ===== BOT TYPING INDICATOR ===== */
@keyframes typing-dot { 0%,60%,100%{opacity:.3;transform:translateY(0)} 30%{opacity:1;transform:translateY(-4px)} }
#bot-typing-indicator .message-bubble { display:flex; gap:4px; align-items:center; }
#bot-typing-indicator .message-bubble span { display:inline-block; font-size:18px; animation:typing-dot 1.2s infinite; }
#bot-typing-indicator .message-bubble span:nth-child(2) { animation-delay:.2s; }
#bot-typing-indicator .message-bubble span:nth-child(3) { animation-delay:.4s; }

/* ===== AUDIO RECORDING ===== */
@keyframes pulse-red { 0%,100%{box-shadow:0 0 0 0 rgba(239,68,68,.4)} 50%{box-shadow:0 0 0 6px rgba(239,68,68,0)} }
#btn-record.recording { background: #ef4444 !important; color: white !important; animation: pulse-red 1.5s infinite; border-radius: 50%; }

/* ===== DROPDOWN MENU ===== */
.dropdown-menu { position: absolute; right: 0; top: 100%; background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.15); z-index: 200; min-width: 160px; padding: 4px; }
.dropdown-item { display: block; width: 100%; padding: 8px 12px; text-align: left; border: none; background: transparent; color: var(--text-primary); font-size: 13px; cursor: pointer; border-radius: 6px; }
.dropdown-item:hover { background: var(--bg-secondary); }

/* ===== FOLDERS SIDEBAR ===== */
.folder-group { margin-bottom: 2px; }
.folder-header { display: flex; align-items: center; padding: 6px 12px; cursor: pointer; font-weight: 600; font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .05em; border-radius: 6px; user-select: none; }
.folder-header:hover { background: var(--bg-secondary); }
.folder-toggle { margin-right: 6px; display: inline-block; transition: transform .2s; }
.folder-toggle.collapsed { transform: rotate(-90deg); }
.chat-list-inner { padding-left: 0; }
.folder-delete-btn { margin-left: auto; opacity: 0; background: transparent; border: none; cursor: pointer; color: var(--text-secondary); font-size: 14px; padding: 2px 4px; border-radius: 4px; }
.folder-header:hover .folder-delete-btn { opacity: 1; }
.folder-delete-btn:hover { color: var(--danger-color, #ef4444); background: var(--bg-tertiary, rgba(0,0,0,.05)); }


/* ===== FEDERATION BADGE ===== */
.fed-badge { font-size: 11px; background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: 4px; padding: 1px 4px; margin-left: 4px; vertical-align: middle; }

/* ===== MEDIA VIEWER OVERLAY ===== */
.media-viewer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    z-index: 2500;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.2s ease;
}
.media-viewer-overlay.hidden { display: none; }
.media-viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    color: #fff;
}
.media-viewer-title { font-size: 14px; opacity: 0.8; }
.media-viewer-actions { display: flex; gap: 8px; }
.media-viewer-actions .btn-icon { color: #fff; font-size: 20px; }
.media-viewer-actions .btn-icon:hover { background: rgba(255,255,255,0.15); }
.media-viewer-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow: auto;
}
.media-viewer-content img {
    max-width: 95%;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
}
.media-viewer-content video {
    max-width: 95%;
    max-height: 90vh;
    border-radius: 8px;
}
.media-viewer-content audio {
    min-width: 300px;
}

/* ===== CONFERENCE OVERLAY ===== */
.conference-overlay { position: fixed; inset: 0; background: #111; z-index: 2000; display: flex; flex-direction: column; }
.conference-overlay.hidden { display: none; }
#conference-videos { flex: 1; display: grid; gap: 8px; padding: 16px; overflow: hidden; }
#conference-videos video { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; background: #000; }
#conference-controls { display: flex; justify-content: center; gap: 16px; padding: 16px; background: rgba(0,0,0,.5); }
#conference-controls button { padding: 12px 24px; border-radius: 24px; font-size: 16px; border: none; cursor: pointer; background: #374151; color: #fff; }
#conf-end-btn { background: #ef4444; color: #fff; }
#conf-mute-btn.muted, #conf-video-btn.stopped { background: #6b7280; }

/* ===== MESSAGE FORWARDING & PINNING ===== */
.forwarded-header { font-size: 12px; color: var(--text-tertiary); border-left: 3px solid var(--accent-color, #6366f1); padding-left: 6px; margin-bottom: 4px; }
.pinned-badge { font-size: 13px; margin: 0 4px; vertical-align: middle; }
/* ===== PINNED BAR WITH NAVIGATION ===== */
.pinned-bar { display: flex; align-items: center; padding: 6px 16px; background: var(--bg-secondary); border-bottom: 1px solid var(--border-color); font-size: 13px; color: var(--text-secondary); gap: 8px; user-select: none; cursor: pointer; position: relative; z-index: 10; }
.pinned-bar.hidden { display: none; }
.pinned-bar:hover { background: var(--bg-tertiary, rgba(0,0,0,.04)); }
.pinned-bar-nav { background: none; border: none; cursor: pointer; padding: 2px 6px; font-size: 11px; color: var(--text-secondary); border-radius: 4px; flex-shrink: 0; }
.pinned-bar-nav:hover { background: var(--bg-hover); color: var(--text-primary); }
#pinned-bar-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pinned-bar-counter { font-size: 11px; color: var(--text-tertiary); flex-shrink: 0; white-space: nowrap; }

/* ===== FORWARD MODAL (CENTERED + BLUR) ===== */
.forward-modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 3000; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.45); backdrop-filter: blur(6px); animation: fadeIn 0.15s ease; }
.forward-modal-overlay.hidden { display: none; }
.forward-modal-dialog { background: var(--bg-primary); border-radius: var(--border-radius); box-shadow: var(--shadow-xl); max-width: 400px; width: 90%; max-height: 80vh; overflow-y: auto; animation: scaleIn 0.2s ease; }
.forward-modal-dialog .modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 12px; border-bottom: 1px solid var(--border-color); }
.forward-modal-dialog .modal-header h3 { font-size: 16px; font-weight: 600; margin: 0; }
.forward-modal-dialog .modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-secondary); padding: 4px 8px; border-radius: 4px; }
.forward-modal-dialog .modal-close:hover { background: var(--bg-hover); }
.forward-modal-dialog .modal-body { padding: 12px 20px; }
.forward-modal-dialog .modal-footer { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px 16px; border-top: 1px solid var(--border-color); }
.forward-chat-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.forward-chat-item:hover { background: var(--bg-secondary); }
.forward-chat-item input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; }

/* ===== FLOATING MULTI-SELECT BAR ===== */
.multiselect-bar-floating { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 2500; display: flex; align-items: center; gap: 10px; padding: 10px 20px; background: var(--accent-color, #6366f1); color: #fff; font-size: 13px; border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,0.25); animation: fadeInUp 0.2s ease; }
.multiselect-bar-floating.hidden { display: none; }
.multiselect-bar-floating .btn-sm { padding: 6px 14px; border: none; border-radius: 8px; cursor: pointer; background: rgba(255,255,255,0.2); color: #fff; font-size: 13px; font-weight: 500; }
.multiselect-bar-floating .btn-sm:hover { background: rgba(255,255,255,0.35); }
.multiselect-bar-floating .btn-danger { background: rgba(239,68,68,0.7); }
.multiselect-bar-floating .btn-danger:hover { background: rgba(239,68,68,0.9); }
.message.msg-selected { outline: 2px solid var(--accent-color, #6366f1); border-radius: 8px; background: rgba(99,102,241,0.08); }

/* ===== MESSAGE REACTIONS ===== */
.message-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction-chip { display: inline-flex; align-items: center; gap: 3px; padding: 2px 8px; border-radius: 12px; font-size: 13px; cursor: pointer; border: 1px solid var(--border-color); background: var(--bg-secondary); transition: all var(--transition-fast); user-select: none; }
.reaction-chip:hover { background: var(--bg-hover); }
.reaction-chip.mine { border-color: var(--primary-color); background: var(--primary-light); }
.reaction-chip .reaction-count { font-size: 11px; color: var(--text-secondary); min-width: 8px; text-align: center; }
.reaction-add-btn { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 12px; font-size: 13px; cursor: pointer; border: 1px dashed var(--border-color); background: none; color: var(--text-tertiary); }
.reaction-add-btn:hover { background: var(--bg-secondary); color: var(--text-primary); }
.reaction-picker { position: absolute; bottom: 100%; left: 0; background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: 8px; box-shadow: var(--shadow-lg); padding: 8px; display: flex; gap: 4px; flex-wrap: wrap; max-width: 200px; z-index: 100; }
.reaction-picker span { cursor: pointer; font-size: 18px; padding: 2px 4px; border-radius: 4px; }
.reaction-picker span:hover { background: var(--bg-hover); }

/* ===== READ RECEIPTS ===== */
.message-status { display: inline-flex; align-items: center; margin-left: 4px; font-size: 12px; }
.message-status .status-icon { color: var(--text-tertiary); }
.message-status .status-icon.read { color: var(--primary-color); }

/* ===== CHAT INFO MODAL ===== */
.chat-info-field { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border-color); font-size: 13px; }
.chat-info-field:last-child { border-bottom: none; }
.chat-info-label { color: var(--text-secondary); }
.chat-info-value { font-weight: 500; }
.chat-info-member-item { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 13px; }
.chat-info-member-item .member-role { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--bg-tertiary); color: var(--text-secondary); margin-left: auto; }
.chat-info-member-item .member-role.owner { background: #fef3c7; color: #92400e; }
.chat-info-member-item .member-role.admin { background: #dbeafe; color: #1e40af; }

/* ===== LEFT PANEL SCROLLBAR FOR FOLDER LIST ===== */
#folder-list { overflow-y: auto; flex: 1; min-height: 0; }
#tab-chats { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }
.sidebar-actions { flex-shrink: 0; }
