:root {
    --primary: #4f46e5;
    --primary-light: rgba(79, 70, 229, 0.15);
    --primary-hover: #4338ca;
    --bg-main: #030712;
    --sidebar-bg: #0f172a;
    --card-bg: #111827;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #1e293b;
    --valid: #22c55e;
    --invalid: #ef4444;
    --warning: #f59e0b;
    --shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    --shadow-hover: 0 6px 25px rgba(0, 0, 0, 0.7);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    display: flex;
    height: 100vh;
    overflow: hidden;
    font-family: 'Tajawal', sans-serif;
    font-weight: 500;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--sidebar-bg);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 0;
    z-index: 100;
}

.logo-section {
    padding: 0 1.5rem 2.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-icon {
    width: 38px;
    height: 38px;
    background: var(--primary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.4rem;
    font-weight: 800;
}

.nav-group-label {
    padding: 1.5rem 1.5rem 0.5rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    font-weight: 700;
}

.nav-links {
    list-style: none;
    flex: 1;
    overflow-y: auto;
}

.nav-item {
    margin: 0.2rem 1rem;
    padding: 0.8rem 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 600;
    border-radius: 12px;
}

.nav-item span {
    font-size: 1.2rem;
}

.nav-item:hover {
    background: var(--bg-main);
    color: var(--primary);
}

.nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
}

/* Main Content */
.main-layout {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.top-bar {
    height: 70px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2.5rem;
    flex-shrink: 0;
}

.content-area {
    flex: 1;
    padding: 2.5rem;
    overflow-y: auto;
}

/* Dashboard Specifics */
.welcome-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 20px;
    border: 1px solid var(--border);
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}

.welcome-text h1 {
    font-size: 1.8rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
}

.welcome-text p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.refresh-dashboard-btn {
    background: var(--bg-main);
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    transition: 0.3s;
}

/* Warmer Feature Styles */
.warmer-dashboard {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.warmer-msg-list {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.warmer-msg-item {
    background: var(--bg-main);
    padding: 0.8rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: 0.2s;
}

.warmer-msg-item:hover {
    background: var(--border);
}

.remove-msg-btn {
    color: var(--invalid);
    cursor: pointer;
    font-size: 1.2rem;
    opacity: 0.6;
    transition: 0.2s;
}

.remove-msg-btn:hover {
    opacity: 1;
}

.warmer-devices-list {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.warmer-device-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.8rem;
    background: var(--bg-main);
    border-radius: 12px;
    border: 1px solid var(--border);
}

.warmer-device-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
}

.warmer-device-info {
    flex: 1;
}

.warmer-device-name {
    font-weight: 700;
    font-size: 0.9rem;
    display: block;
}

.warmer-device-status {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.stat-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 20px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    transition: transform 0.3s, box-shadow 0.3s;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-hover);
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 600;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 800;
    margin-top: 0.3rem;
}

.stat-icon-box {
    width: 45px;
    height: 45px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
}

.stat-icon-box.teal {
    background: rgba(49, 151, 149, 0.2);
    color: #38b2ac;
}

.stat-icon-box.green {
    background: rgba(56, 161, 105, 0.2);
    color: #48bb78;
}

.stat-icon-box.orange {
    background: rgba(221, 107, 32, 0.2);
    color: #ed8936;
}

.stat-icon-box.blue {
    background: rgba(49, 130, 206, 0.2);
    color: #63b3ed;
}

.mini-chart-container {
    height: 50px;
    width: 100%;
    margin-top: 1rem;
}

/* Main Row */
.dashboard-main-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.activity-section {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.section-header h3 {
    font-size: 1.3rem;
    font-weight: 800;
}

.section-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 0.3rem;
}

.main-chart-container {
    margin-top: 2rem;
    height: 350px;
}

.widgets-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.widget-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.widget-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.widget-header h3 {
    font-size: 1.1rem;
    font-weight: 800;
}

.widget-icon {
    font-size: 1.2rem;
    opacity: 0.5;
}

.unread-messages-status {
    text-align: center;
    padding: 1rem 0;
}

.status-icon.success-bg {
    width: 40px;
    height: 40px;
    background: var(--valid);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    font-size: 1.2rem;
}

.integration-card {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-top: 1rem;
}

.status-online {
    background: var(--primary-light);
    color: var(--primary);
    padding: 0.2rem 0.8rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
}

/* API Documentation Styles */
.api-doc-card {
    background: var(--card-bg);
    border-radius: 1.5rem;
    padding: 2.5rem;
    box-shadow: var(--shadow-sm);
    max-width: 900px;
    margin: 0 auto;
    direction: ltr;
    /* Force English direction for API docs */
    text-align: left;
}

.api-header {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 3rem;
}

.api-icon {
    width: 4rem;
    height: 4rem;
    background: rgba(22, 163, 74, 0.2);
    color: #4ade80;
    border-radius: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
}

.token-box {
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 2rem;
    margin-bottom: 2.5rem;
}

.token-box label {
    display: block;
    font-weight: 700;
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.token-box p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.token-input-group {
    display: flex;
    gap: 1rem;
}

.token-input-group input {
    flex: 1;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 0.75rem 1rem;
    font-family: monospace;
    font-size: 0.9rem;
    color: var(--text-main);
}

::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

.api-endpoint-box {
    margin-bottom: 2.5rem;
}

.endpoint-url {
    background: #0f172a;
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    font-family: monospace;
}

.endpoint-url .method {
    background: #16a34a;
    padding: 0.25rem 0.75rem;
    border-radius: 0.4rem;
    font-size: 0.8rem;
    font-weight: 700;
}

.api-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0 2.5rem;
}

.api-table th,
.api-table td {
    text-align: right;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.api-table th {
    background: var(--bg-main);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.85rem;
}

.api-example-box pre {
    background: #1e293b;
    color: #f8fafc;
    padding: 1.5rem;
    border-radius: 1rem;
    overflow-x: auto;
    direction: ltr;
}

.api-example-box code {
    font-family: 'Consolas', monospace;
    font-size: 0.9rem;
}

/* Chatbot Screen Styles */
.chatbot-container {
    padding: 1rem;
}

.chatbot-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: var(--shadow-sm);
}

.rules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.rule-card {
    background: var(--card-bg);
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: transform 0.2s;
}

.rule-card:hover {
    transform: translateY(-5px);
}

.rule-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.rule-keyword {
    background: rgba(22, 163, 74, 0.2);
    color: #4ade80;
    padding: 0.25rem 0.75rem;
    border-radius: 0.5rem;
    font-weight: 700;
    font-size: 0.9rem;
}

.rule-match-badge {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--border);
    padding: 0.2rem 0.5rem;
    border-radius: 0.3rem;
}

.rule-response {
    color: var(--text-main);
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--bg-main);
    border-radius: 0.5rem;
}

.rule-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-delete {
    background: rgba(220, 38, 38, 0.2);
    color: #f87171;
    border: none;
    padding: 0.5rem;
    border-radius: 0.5rem;
    cursor: pointer;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
}

.modal[style*="display: block"] {
    display: flex !important;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: var(--card-bg);
    margin: 0;
    max-height: 90vh;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 2.5rem;
    border-radius: 2rem;
    width: 90%;
    max-width: 550px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    animation: modalSlideUp 0.3s ease-out;
}

@keyframes modalSlideUp {
    from {
        transform: translateY(30px) scale(0.95);
        opacity: 0;
    }

    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
}

.modal-header h3 {
    font-size: 1.5rem;
    color: var(--text-main);
    font-weight: 800;
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.modal-body .form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.modal-body label {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.modal-body input,
.modal-body select,
.modal-body textarea {
    padding: 0.8rem 1rem;
    border: 2px solid var(--border);
    border-radius: 1rem;
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.2s;
}

.modal-body input:focus,
.modal-body select:focus,
.modal-body textarea:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.1);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 2.5rem;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.8rem 1.8rem;
    border-radius: 12px;
    font-family: 'Tajawal', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0, 168, 132, 0.25);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: transparent;
    color: var(--text-muted);
    border: 1.5px solid var(--border);
    padding: 0.8rem 1.5rem;
    border-radius: 12px;
    font-family: 'Tajawal', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border-color: #475569;
}

.close {
    font-size: 2rem;
    cursor: pointer;
    color: #94a3b8;
    line-height: 1;
    transition: color 0.2s;
}

.btn-copy {
    background: var(--border);
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: 0.5rem 1rem;
    border-radius: 0.75rem;
    cursor: pointer;
    font-weight: 600;
}

.endpoint-url-container {
    background: #0f172a;
    padding: 1rem;
    border-radius: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
}

.endpoint-url-container code {
    color: #10b981;
    font-family: monospace;
    font-size: 0.95rem;
}

.btn-copy-lite {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: none;
    padding: 0.4rem 0.8rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.8rem;
}

.btn-copy-lite:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Tabs */
.tabs-header {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid #f1f5f9;
}

.tab-btn {
    padding: 0.75rem 1.5rem;
    border: none;
    background: none;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.btn-setup-guide {
    background: rgba(37, 99, 235, 0.2);
    color: #60a5fa;
    border: 1px solid rgba(37, 99, 235, 0.3);
    padding: 0.6rem 1.2rem;
    border-radius: 0.75rem;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.9rem;
    margin-left: auto;
    transition: all 0.2s;
}

.btn-setup-guide:hover {
    background: rgba(37, 99, 235, 0.3);
}

.setup-step {
    margin-bottom: 2rem;
}

.setup-step h4 {
    color: var(--text-main);
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.env-sample-box {
    background: #0f172a;
    border-radius: 1rem;
    padding: 1.5rem;
    position: relative;
    margin-top: 1rem;
}

.env-sample-box pre {
    color: #e2e8f0;
    margin: 0;
    font-family: 'Consolas', monospace;
}

.btn-copy-env {
    position: absolute;
    right: 1rem;
    top: 1rem;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.3rem 0.7rem;
    border-radius: 0.4rem;
    font-size: 0.75rem;
    cursor: pointer;
}

.add-btn {
    background: var(--primary);
    padding: 0.8rem 1.5rem;
    border-radius: 12px;
}

.add-btn:hover {
    background: var(--primary-hover);
}

.session-grid {
    display: grid;
    gap: 1rem;
    margin-top: 1.5rem;
}

.session-card {
    background: var(--bg-main);
    border-radius: 16px;
    padding: 1.2rem 1.5rem;
    border: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.inbox-container {
    height: calc(100vh - 120px);
    display: flex;
    background: var(--card-bg);
    border-radius: 24px;
    border: 1px solid var(--border);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.chat-list {
    width: 350px;
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: var(--bg-main);
}

.chat-list-header {
    padding: 1.5rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
}

.search-box {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    background: var(--bg-main);
    padding: 0.7rem 1.2rem;
    border-radius: 12px;
}

.search-box input {
    border: none;
    background: transparent;
    width: 100%;
    outline: none;
    font-size: 0.9rem;
    color: var(--text-main);
}

.chat-items {
    flex: 1;
    overflow-y: auto;
}

.chat-item {
    padding: 1.2rem 1.5rem;
    display: flex;
    gap: 1rem;
    cursor: pointer;
    transition: 0.2s;
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
}

.chat-item:hover {
    background: var(--border);
}

.chat-item.active {
    background: var(--primary-light);
}

.chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: var(--primary-light);
    flex-shrink: 0;
}

.chat-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.chat-name-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.3rem;
    min-width: 0;
    gap: 0.5rem;
}

.chat-name {
    font-weight: 700;
    color: var(--text-main);
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1;
}

.chat-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.chat-preview {
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* Chat Filter Tabs */
.chat-filter-tabs {
    display: flex;
    gap: 0.5rem;
    padding: 0.8rem 0 0;
}

.chat-filter-tab {
    padding: 0.4rem 1rem;
    border: none;
    border-radius: 20px;
    background: var(--border);
    color: var(--text-muted);
    font-family: 'Tajawal', sans-serif;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    white-space: nowrap;
}

.chat-filter-tab:hover {
    background: var(--border);
    color: var(--text-main);
}

.chat-filter-tab.active {
    background: var(--primary);
    color: white;
}

/* Session Phone Badge (below message preview) */
.chat-session-phone {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin-top: 0.3rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--border);
    padding: 0.15rem 0.5rem;
    border-radius: 6px;
    direction: ltr;
    max-width: fit-content;
}

.chat-session-phone .phone-icon {
    font-size: 0.7rem;
    opacity: 0.7;
}

/* Unread badge on chat item */
.chat-unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0 5px;
    flex-shrink: 0;
}

/* Chat Window */
.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    position: relative;
}

.chat-header {
    padding: 1rem 2rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    height: 70px;
}

.chat-messages {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    background: var(--bg-main);
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.chat-input-area {
    padding: 1.5rem 2rem;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    display: flex;
    gap: 1rem;
    align-items: center;
}

.chat-input {
    flex: 1;
    padding: 0.9rem 1.5rem;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--bg-main);
    color: #ffffff;
    font-size: 1.1rem;
    font-weight: 500;
    outline: none;
    transition: 0.2s;
}

.chat-input:focus {
    border-color: var(--primary);
    background: var(--card-bg);
}

/* Empty State */
.chat-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 1.5rem;
    opacity: 0.2;
}

.chat-empty-state h2 {
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

/* Message Bubbles */
.msg-bubble {
    max-width: 70%;
    padding: 0.9rem 1.3rem;
    border-radius: 18px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    position: relative;
    font-size: 0.95rem;
    line-height: 1.5;
}

.msg-text {
    white-space: pre-wrap;
    word-wrap: break-word;
}

.msg-me {
    align-self: flex-start;
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.msg-other {
    align-self: flex-end;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.msg-time {
    font-size: 0.65rem;
    opacity: 0.7;
    margin-top: 0.4rem;
    display: block;
}

/* Connection Status Dots */
.status-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-connected {
    background: var(--valid);
}

.status-inactive {
    background: #94a3b8;
}

.status-connecting {
    background: #f59e0b;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.5;
        transform: scale(1.2);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* QR Code Styling */
#qr-section {
    text-align: center;
    padding: 2rem;
}

#qr-container {
    display: flex;
    justify-content: center;
    margin: 1.5rem 0;
}

.qr-code-img {
    max-width: 320px;
    width: 100%;
    border-radius: 16px;
    border: 8px solid var(--card-bg);
    box-shadow: var(--shadow-hover);
    transition: transform 0.3s ease;
}

.qr-code-img:hover {
    transform: scale(1.02);
}

/* --- Media Elements --- */
.msg-bubble {
    position: relative; /* For absolute positioning of reaction badge */
}

.msg-media-image {
    max-width: 300px;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 0.5rem;
    cursor: pointer;
}

.msg-media-image img {
    width: 100%;
    display: block;
    border-radius: 8px;
    transition: transform 0.2s;
}

.msg-media-image img:hover {
    transform: scale(1.02);
}

.msg-media-video {
    max-width: 300px;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.msg-media-video video {
    width: 100%;
    display: block;
    border-radius: 8px;
    background: #000;
}

.msg-media-audio {
    margin-bottom: 0.5rem;
}

.msg-media-audio audio {
    max-width: 100%;
    width: 280px;
    height: 40px;
    border-radius: 20px;
}

.msg-media-document {
    background: var(--bg-gray-700);
    border-radius: 6px;
    padding: 8px 12px;
    margin-bottom: 0.5rem;
}

.document-link {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: var(--text-primary);
    gap: 8px;
}

.document-link:hover {
    color: var(--primary);
}

.document-icon {
    font-size: 24px;
}

.document-name {
    font-size: 0.9rem;
    word-break: break-all;
}

.msg-sticker {
    max-width: 130px;
    background: transparent !important;
    padding: 0 !important;
    box-shadow: none !important;
    margin-bottom: 0.5rem;
}

.msg-reaction-badge {
    position: absolute;
    bottom: -10px;
    right: 15px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2px 6px;
    font-size: 0.85rem;
    box-shadow: var(--shadow-sm);
    z-index: 2;
}

.msg-me .msg-reaction-badge {
    right: auto;
    left: 15px;
}

.msg-edited-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-style: italic;
    margin-right: 0.5rem;
}

.msg-media-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 200px;
    height: 150px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.msg-media-loading::after {
    content: "⏳ جاري التحميل...";
}

/* --- Lightbox --- */
.lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: zoom-out;
    animation: fadeIn 0.2s ease-out;
}
.lightbox-img {
    max-width: 90%;
    max-height: 90%;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    cursor: default;
}
.lightbox-close {
    position: absolute;
    top: 20px;
    right: 30px;
    color: white;
    font-size: 30px;
    cursor: pointer;
    transition: transform 0.2s;
}
.lightbox-close:hover {
    transform: scale(1.1);
}
.lightbox-download {
    position: absolute;
    top: 20px;
    right: 80px;
    color: white;
    font-size: 26px;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.2s;
}
.lightbox-download:hover {
    transform: scale(1.1);
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* --- Media Attach & Voice Record --- */
.attach-btn {
    background: transparent;
    color: var(--primary);
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.attach-btn:hover {
    background: rgba(16, 185, 129, 0.1);
}

.attach-menu {
    position: absolute;
    bottom: 120%;
    left: 0;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-hover);
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-width: 150px;
    z-index: 100;
    animation: slideUpFade 0.2s ease-out;
}

@keyframes slideUpFade {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.attach-menu-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.8rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}
.attach-menu-item:hover {
    background: var(--border);
}
.attach-menu-item .icon {
    font-size: 1.2rem;
}
.attach-menu-item .label {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
}

.chat-actions {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    outline: none;
}

.action-btn.delete-btn {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
}
.action-btn.delete-btn:hover {
    background: rgba(16, 185, 129, 0.1);
}

.action-btn.send-btn {
    background: var(--primary);
    border: 1px solid var(--primary);
    color: #fff;
}
.action-btn.send-btn:hover {
    filter: brightness(1.1);
}

.voice-record-btn {
    background: transparent;
    color: #f87171;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.voice-record-btn:hover {
    transform: scale(1.1);
}
.voice-record-btn.recording {
    color: #ef4444;
    animation: pulseRecord 1.5s infinite;
}

@keyframes pulseRecord {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.recording-timer {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.9rem 1.5rem;
    border-radius: 14px;
    background: rgba(239, 68, 68, 0.05);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: #ef4444;
    font-weight: 700;
    font-family: monospace;
    font-size: 1.2rem;
}

.pulse-dot {
    width: 10px;
    height: 10px;
    background: #ef4444;
    border-radius: 50%;
    animation: pulseRecord 1.5s infinite;
}

.media-preview-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 1.5rem;
    background: rgba(16, 185, 129, 0.05);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
.media-preview-bar .preview-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: var(--text-main);
}
.media-preview-bar .cancel-preview-btn {
    background: transparent;
    color: var(--text-muted);
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.2rem 0.5rem;
    border-radius: 50%;
}
.media-preview-bar .cancel-preview-btn:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}
/* ========== MESSAGE CONTEXT MENU ========== */
.msg-context-menu {
    position: fixed;
    z-index: 10000;
    min-width: 200px;
    background: var(--card-bg, #1e293b);
    border: 1px solid var(--border, rgba(51, 65, 85, 0.5));
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 6px 0;
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 0.15s ease, transform 0.15s ease;
    pointer-events: none;
    font-family: 'Tajawal', sans-serif;
}

.msg-context-menu.visible {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}

.msg-context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    color: var(--text-main, #e2e8f0);
    font-size: 0.88rem;
    font-weight: 500;
    transition: background 0.15s ease;
    white-space: nowrap;
}

.msg-context-menu-item:hover {
    background: rgba(255, 255, 255, 0.06);
}

.msg-context-menu-item:first-child {
    border-radius: 12px 12px 0 0;
}

.msg-context-menu-item:last-child {
    border-radius: 0 0 12px 12px;
}

.msg-context-menu-item .ctx-icon {
    font-size: 1rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.msg-context-menu-item.danger {
    color: #f87171;
}

.msg-context-menu-item.danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

.msg-context-menu-separator {
    height: 1px;
    background: var(--border, rgba(51, 65, 85, 0.5));
    margin: 4px 0;
}