/* ========================================
   Raven - پیام‌رسان امن زاغ در سایه
   فاز 6.6 - نسخه اصلاح شده با بهبود نمایش و رفع باگ‌ها
   ======================================== */

/* ============== ریشه و متغیرها ============== */
:root {
    /* رنگ‌های اصلی - تم روشن */
    --primary: #667eea;
    --primary-dark: #5a67d8;
    --primary-light: #7f9cf5;
    --secondary: #764ba2;
    --secondary-dark: #6b3b9a;
    --success: #28a745;
    --success-dark: #1e7e34;
    --danger: #dc3545;
    --danger-dark: #bd2130;
    --warning: #ffc107;
    --warning-dark: #e0a800;
    --info: #17a2b8;
    --info-dark: #138496;
    --dark: #343a40;
    --light: #f8f9fa;
    --gray: #6c757d;
    --gray-light: #e9ecef;
    --gray-dark: #495057;
    
    /* فضای سفید و متن */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-muted: #adb5bd;
    --border: #dee2e6;
    
    /* سایه‌ها */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1);
    
    /* انیمیشن */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;
    
    /* border-radius */
    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-2xl: 1.5rem;
}

/* ============== تم تاریک ============== */
body.dark {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #1e1e2e;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --text-muted: #6c757d;
    --border: #2d2d3d;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.3);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.3);
}

/* ============== ریست و پایه ============== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'IRANSans', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    min-height: 100vh;
    padding: 16px;
    transition: background 0.3s ease;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    background: var(--bg-primary);
    border-radius: var(--radius-2xl);
    padding: 20px;
    box-shadow: var(--shadow-xl);
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

/* ============== صفحات ============== */
.page {
    display: none;
    animation: fadeIn 0.3s ease;
}

.page.active {
    display: block;
}

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

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

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

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

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

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* ============== تایپوگرافی ============== */
h1, h2, h3, h4, h5, h6 {
    margin-bottom: 15px;
    color: var(--text-primary);
    font-weight: 600;
}

h1 { font-size: 28px; }
h2 { font-size: 24px; }
h3 { font-size: 20px; }
h4 { font-size: 18px; }
h5 { font-size: 16px; }
h6 { font-size: 14px; }

p {
    color: var(--text-secondary);
    line-height: 1.5;
}

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

a:hover {
    color: var(--primary-dark);
}

/* ============== فرم‌ها ============== */
input, textarea, select {
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 12px;
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    font-size: 16px;
    font-family: inherit;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

input::placeholder, textarea::placeholder {
    color: var(--text-muted);
}

input:disabled, textarea:disabled, select:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ============== دکمه‌ها ============== */
button {
    width: 100%;
    padding: 12px 20px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    border: none;
    border-radius: var(--radius-lg);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

button:active {
    transform: scale(0.98);
}

button:disabled {
    opacity: 0.6;
    transform: none;
    cursor: not-allowed;
}

.btn-secondary {
    background: linear-gradient(135deg, var(--gray) 0%, var(--gray-dark) 100%);
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
    width: auto;
}

.btn-success {
    background: linear-gradient(135deg, var(--success) 0%, var(--success-dark) 100%);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger) 0%, var(--danger-dark) 100%);
}

.btn-warning {
    background: linear-gradient(135deg, var(--warning) 0%, var(--warning-dark) 100%);
    color: var(--dark);
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
}

.btn-outline:active {
    transform: scale(0.98);
}

/* ============== هدر ============== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

/* ============== تب‌ها ============== */
.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.tab-btn {
    flex: 1;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    padding: 10px;
    font-size: 14px;
    font-weight: 500;
    min-width: 70px;
}

.tab-btn.active {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
}

/* ============== محتوای تب‌ها ============== */
.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

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

/* ============== جداکننده ============== */
hr {
    margin: 20px 0;
    border: none;
    border-top: 1px solid var(--border);
}

/* ============== کد ============== */
code {
    background: var(--bg-secondary);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: var(--text-primary);
}

/* ============== قالب‌ها ============== */
.template-form {
    background: var(--bg-secondary);
    padding: 15px;
    border-radius: var(--radius-lg);
    margin: 15px 0;
    animation: slideDown 0.3s ease;
}

.template-header {
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--primary);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.template-icon {
    font-size: 24px;
}

.form-field {
    margin-bottom: 12px;
}

.form-field label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 13px;
}

.form-field input, 
.form-field textarea {
    width: 100%;
    padding: 10px;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 14px;
}

.form-field input:focus, 
.form-field textarea:focus {
    outline: none;
    border-color: var(--primary);
}

/* ============== دکمه گروه ============== */
.button-group {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.button-group button {
    flex: 1;
}

/* ============== پیش‌نویس‌ها ============== */
.draft-item {
    background: rgba(255, 193, 7, 0.1);
    padding: 12px;
    margin: 8px 0;
    border-radius: var(--radius-md);
    cursor: pointer;
    border-right: 4px solid var(--warning);
    transition: all var(--transition-fast);
}

.draft-item:hover {
    background: rgba(255, 193, 7, 0.2);
    transform: translateX(-5px);
}

.draft-item strong {
    color: var(--warning-dark);
}

/* ============== آمار ============== */
.stats {
    display: flex;
    gap: 8px;
    font-size: 12px;
    background: var(--bg-secondary);
    padding: 8px 12px;
    border-radius: var(--radius-lg);
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.stats span {
    background: var(--bg-primary);
    padding: 4px 10px;
    border-radius: var(--radius-md);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--text-primary);
}

/* ============== پیام‌ها - لیست ============== */
.message-item {
    background: var(--bg-secondary);
    padding: 16px;
    margin-bottom: 12px;
    border-radius: var(--radius-xl);
    border-right: 4px solid var(--primary);
    transition: all var(--transition-fast);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}

.message-item:hover {
    transform: translateX(-5px);
    box-shadow: var(--shadow-md);
}

.message-item.unread {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.08), rgba(118, 75, 162, 0.08));
    border-right-color: var(--danger);
    position: relative;
}

.message-item.unread::before {
    content: '';
    position: absolute;
    left: -4px;
    top: 0;
    width: 8px;
    height: 100%;
    background: var(--danger);
    border-radius: 4px 0 0 4px;
}

/* هدر پیام */
.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    flex-wrap: wrap;
    gap: 8px;
}

.message-sender {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sender-avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: white;
}

.sender-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
}

.message-time {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 4px 8px;
    border-radius: 20px;
}

/* خط موضوع */
.message-subject-line {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.message-subject-text {
    font-weight: 700;
    font-size: 15px;
    color: var(--text-primary);
    flex: 1;
    word-break: break-word;
}

/* خط پیش‌نمایش */
.message-preview-line {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.message-preview-text {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* بخش پایین پیام */
.message-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.message-status {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* بج وضعیت */
.status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 500;
}

.unread-badge {
    background: var(--danger);
    color: white;
    animation: pulse 1.5s infinite;
}

.read-badge {
    background: var(--success);
    color: white;
}

.pending-badge {
    background: var(--warning);
    color: var(--dark);
}

.sent-badge {
    background: var(--success);
    color: white;
}

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

.encrypted-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 10px;
    background: rgba(23, 162, 184, 0.15);
    color: var(--info);
}

/* بج قالب */
.template-badge-wrapper {
    display: inline-flex;
}

.template-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
}

.template-badge-icon {
    font-size: 12px;
}

.template-badge-name {
    font-size: 11px;
}

/* رنگ‌های قالب‌ها */
.template-default {
    background: rgba(102, 126, 234, 0.15);
    color: #667eea;
}

.template-official {
    background: rgba(40, 167, 69, 0.15);
    color: #28a745;
}

.template-quick {
    background: rgba(255, 193, 7, 0.15);
    color: #e0a800;
}

.template-task {
    background: rgba(23, 162, 184, 0.15);
    color: #17a2b8;
}

.template-invoice {
    background: rgba(220, 53, 69, 0.15);
    color: #dc3545;
}

.template-meeting {
    background: rgba(23, 162, 184, 0.15);
    color: #17a2b8;
}

.template-announcement {
    background: rgba(255, 193, 7, 0.15);
    color: #e0a800;
}

/* بج فایل */
.file-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--info);
    color: white;
    padding: 3px 8px;
    border-radius: 20px;
    font-size: 10px;
}

/* ============== نمایش بهینه مودال پیام ============== */
.message-detail-header {
    margin-bottom: 20px;
}

.message-meta-info {
    background: var(--bg-secondary);
    padding: 16px;
    border-radius: var(--radius-lg);
}

.meta-row {
    display: flex;
    margin-bottom: 12px;
    font-size: 14px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}

.meta-row:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.meta-label {
    width: 80px;
    font-weight: 600;
    color: var(--text-secondary);
}

.meta-value {
    flex: 1;
    color: var(--text-primary);
    word-break: break-word;
}

.template-badge-large {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 30px;
    font-size: 13px;
    font-weight: 500;
}

.message-detail-body {
    line-height: 1.8;
    min-height: 100px;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 14px;
    padding: 5px;
}

.message-field {
    margin-bottom: 16px;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    border-right: 4px solid var(--primary);
}

.message-field strong {
    display: block;
    margin-bottom: 8px;
    color: var(--primary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============== استایل‌های فایل‌ها ============== */
.files-section {
    margin-top: 20px;
    border-top: 1px solid var(--border);
    padding-top: 15px;
}

.files-header {
    font-weight: 600;
    margin-bottom: 12px;
    font-size: 14px;
    color: var(--text-primary);
}

.files-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-secondary);
    padding: 10px 12px;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.file-item:hover {
    background: var(--bg-tertiary);
}

.file-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.file-icon {
    font-size: 28px;
}

.file-details {
    display: flex;
    flex-direction: column;
}

.file-name {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
    word-break: break-all;
}

.file-size {
    font-size: 10px;
    color: var(--text-muted);
}

.file-pending {
    font-size: 11px;
    color: var(--warning);
    padding: 4px 8px;
    background: rgba(255, 193, 7, 0.1);
    border-radius: var(--radius-sm);
}

.download-btn {
    background: var(--success);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    transition: transform var(--transition-fast);
    width: auto;
}

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

/* ============== نودها ============== */
.node-item {
    background: var(--bg-secondary);
    padding: 12px;
    margin-bottom: 8px;
    border-radius: var(--radius-lg);
    border-right: 4px solid var(--success);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    transition: all var(--transition-fast);
}

.node-item:hover {
    transform: translateX(-5px);
    box-shadow: var(--shadow-md);
}

.node-info {
    flex: 1;
}

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

.node-actions button {
    padding: 6px 12px;
    font-size: 12px;
    width: auto;
}

.node-tag {
    display: inline-block;
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-size: 10px;
    margin-right: 4px;
    color: var(--text-secondary);
}

/* ============== جستجو ============== */
.search-box {
    margin-bottom: 15px;
    position: relative;
}

.search-box input {
    padding-right: 35px;
    margin-bottom: 0;
}

.search-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 18px;
    color: var(--text-muted);
}

/* ============== پیشنهادات جستجو ============== */
.suggestions-dropdown {
    position: absolute;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    width: 100%;
    box-shadow: var(--shadow-lg);
}

.suggestion-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background var(--transition-fast);
}

.suggestion-item:hover {
    background: var(--bg-secondary);
}

.suggestion-item code {
    display: block;
    font-size: 10px;
    color: var(--text-muted);
}

/* ============== هایلایت جستجو ============== */
mark {
    background: rgba(255, 193, 7, 0.4);
    padding: 0 2px;
    border-radius: var(--radius-sm);
    color: inherit;
}

/* ============== پیوست فایل ============== */
.attachment-section {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 15px;
    margin-top: 15px;
    border: 1px dashed var(--primary);
}

.attachment-wrapper {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

#file-attachment {
    flex: 2;
    padding: 8px;
    font-size: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    margin-bottom: 0;
    color: var(--text-primary);
}

#clear-attachment-btn {
    width: auto;
    background: var(--danger);
    padding: 8px 16px;
    display: none;
}

#attachment-info {
    background: rgba(40, 167, 69, 0.1);
    padding: 8px 12px;
    border-radius: var(--radius-md);
    margin-top: 10px;
    display: none;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

#attachment-list {
    width: 100%;
}

.attachment-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    margin-bottom: 5px;
    font-size: 12px;
}

.remove-attachment-btn {
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============== پروگرس بار ============== */
.progress-bar {
    width: 100%;
    height: 8px;
    background-color: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success), var(--info));
    width: 0%;
    transition: width 0.3s ease;
}

#file-progress {
    margin-top: 10px;
}

#file-progress-text {
    font-size: 12px;
    text-align: center;
    margin-top: 5px;
    color: var(--text-secondary);
}

/* ============== چک‌باکس ============== */
.message-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
    margin-top: 2px;
}

/* ============== لودینگ ============== */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.spinner {
    display: inline-block;
    width: 30px;
    height: 30px;
    border: 3px solid var(--border);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 10px;
}

/* ============== حالت خالی ============== */
.empty-state {
    text-align: center;
    padding: 50px 20px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 15px;
    opacity: 0.5;
}

/* ============== Toast ============== */
.toast-notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--dark);
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius-lg);
    z-index: 10000;
    font-size: 14px;
    animation: slideUp 0.3s ease;
    box-shadow: var(--shadow-lg);
    max-width: 90%;
    text-align: center;
    white-space: pre-line;
}

/* ============== Modal ============== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 20000;
    justify-content: center;
    align-items: center;
    padding: 16px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-primary);
    border-radius: var(--radius-xl);
    max-width: 500px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-muted);
    width: auto;
    padding: 0;
    line-height: 1;
}

.modal-close:hover {
    color: var(--danger);
}

.modal-body {
    line-height: 1.6;
    color: var(--text-primary);
}

/* ============== دکمه تغییر تم ============== */
.theme-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--bg-primary);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 9999;
    font-size: 24px;
    transition: all var(--transition-normal);
}

.theme-toggle:hover {
    transform: scale(1.1);
}

/* ============== اسکرول ============== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
}

::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: var(--radius-sm);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

/* ============== انتخاب متن ============== */
::selection {
    background: var(--primary);
    color: white;
}

::-moz-selection {
    background: var(--primary);
    color: white;
}

/* ============== واکنش‌گرا ============== */
@media (max-width: 600px) {
    body {
        padding: 8px;
    }
    
    .container {
        padding: 16px;
    }
    
    button {
        padding: 10px;
    }
    
    .tab-btn {
        font-size: 11px;
        padding: 8px;
    }
    
    h1 { font-size: 24px; }
    h2 { font-size: 20px; }
    h3 { font-size: 18px; }
    h4 { font-size: 16px; }
    
    .node-actions {
        width: 100%;
        margin-top: 10px;
    }
    
    .stats span {
        font-size: 10px;
        padding: 3px 8px;
    }
    
    .attachment-wrapper {
        flex-direction: column;
    }
    
    #clear-attachment-btn {
        width: 100%;
    }
    
    .button-group {
        flex-direction: column;
    }
    
    .tabs {
        gap: 5px;
    }
    
    .message-preview-line {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .message-preview-text {
        white-space: normal;
        word-break: break-word;
    }
    
    .message-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .message-subject-line {
        flex-wrap: wrap;
    }
    
    .message-footer {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .message-status {
        width: 100%;
        justify-content: space-between;
    }
    
    .meta-row {
        flex-direction: column;
        gap: 5px;
    }
    
    .meta-label {
        width: auto;
    }
    
    .file-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .download-btn {
        width: 100%;
        text-align: center;
    }
}

/* ============== پرینت ============== */
@media print {
    body {
        background: white;
        padding: 0;
    }
    
    .container {
        box-shadow: none;
        padding: 0;
    }
    
    button, .tab-btn, .node-actions, .theme-toggle, .search-box, .tabs, .header button {
        display: none;
    }
    
    .message-item {
        break-inside: avoid;
        page-break-inside: avoid;
        border: 1px solid #ddd;
        margin-bottom: 10px;
    }
}

/* ============== دسترسی ============== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}