/* Database & Q&A Styles */

/* Upload Area */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    padding: 40px 20px;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
    background: var(--card-bg);
    margin-bottom: 24px;
}

.upload-area:hover {
    border-color: var(--primary-color);
    background: var(--primary-light);
}

.upload-area.dragover {
    border-color: var(--primary-color);
    background: var(--primary-light);
    transform: scale(1.02);
}

.upload-area .upload-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 16px;
    color: var(--text-muted);
}

.upload-area h4 {
    margin: 0 0 8px;
    color: var(--text-primary);
}

.upload-area p {
    margin: 0;
    color: var(--text-muted);
    font-size: 14px;
}

.upload-area input[type="file"] {
    display: none;
}

/* File List */
.file-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.file-item {
    display: flex;
    align-items: center;
    padding: 16px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    gap: 16px;
}

.file-item .file-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-light);
    border-radius: 8px;
    color: var(--primary-color);
    flex-shrink: 0;
}

.file-item .file-info {
    flex: 1;
    min-width: 0;
}

.file-item .file-name {
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-item .file-meta {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

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

/* Q&A Form */
.qa-form {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
}

.qa-form h3 {
    margin: 0 0 20px;
    font-size: 16px;
    color: var(--text-primary);
}

.qa-form .form-group {
    margin-bottom: 16px;
}

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

.qa-form textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
    background: var(--input-bg);
    color: var(--text-primary);
    min-height: 80px;
}

.qa-form textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.qa-form .btn-add {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

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

.qa-form .btn-add:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Q&A List */
.qa-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.qa-item {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
}

.qa-item .qa-question {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 12px;
    padding-right: 8px;
    border-right: 3px solid var(--primary-color);
}

.qa-item .qa-answer {
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 16px;
    white-space: pre-wrap;
}

.qa-item .qa-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.qa-item .qa-date {
    font-size: 13px;
    color: var(--text-muted);
}

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

/* Stats Cards */
.db-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.db-stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
}

.db-stat-card .stat-value {
    font-size: 28px;
    font-weight: 600;
    color: var(--primary-color);
}

.db-stat-card .stat-label {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 4px;
}

/* Section Tabs */
.db-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

.db-tab {
    padding: 12px 24px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 8px 8px 0 0;
    font-weight: 500;
    transition: all 0.2s;
}

.db-tab:hover {
    color: var(--text-primary);
    background: var(--hover-bg);
}

.db-tab.active {
    color: var(--primary-color);
    background: var(--primary-light);
}

/* Loading */
.db-loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.db-loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Empty State */
.db-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.db-empty svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.db-empty h4 {
    margin: 0 0 8px;
    color: var(--text-primary);
}

.db-empty p {
    margin: 0;
}

/* Edit Dialog */
.qa-edit-dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.qa-edit-dialog.hidden {
    display: none;
}

.qa-edit-content {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.qa-edit-content h3 {
    margin: 0 0 20px;
    color: var(--text-primary);
}

.qa-edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 20px;
}

/* ===================== Q&A with Branches ===================== */

/* Q&A Item with branches */
.qa-item.has-branches {
    border-right: 4px solid #10b981;
}

.qa-item .qa-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.qa-item .qa-question {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.branch-badge {
    font-size: 16px;
}

.qa-branches-preview {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #f0fdf4;
    border-radius: 8px;
    margin-top: 12px;
}

.branches-label {
    font-size: 13px;
    color: #059669;
    font-weight: 500;
}

.btn-xs {
    padding: 4px 12px;
    font-size: 12px;
}

.btn-outline {
    background: transparent;
    border: 1px solid currentColor;
    color: #059669;
}

.btn-outline:hover {
    background: #d1fae5;
}

/* Branch Preview */
.branch-preview-content {
    margin-top: 16px;
    padding: 16px;
    background: var(--hover-bg);
    border-radius: 8px;
}

.branch-preview-item {
    padding: 8px 0;
}

.branch-preview-item + .branch-preview-item {
    border-top: 1px dashed var(--border-color);
    margin-top: 8px;
    padding-top: 16px;
}

.branch-condition {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.branch-arrow {
    color: var(--primary-color);
    font-weight: bold;
}

.condition-text {
    font-size: 13px;
    color: #6366f1;
    font-weight: 500;
}

.branch-response {
    font-size: 13px;
    color: var(--text-secondary);
    padding-right: 24px;
}

/* ===================== Q&A Modal ===================== */

.qa-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    backdrop-filter: blur(4px);
}

.qa-modal.show {
    display: flex;
}

.qa-modal-content {
    background: var(--card-bg);
    border-radius: 16px;
    width: 100%;
    max-width: 700px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

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

.qa-modal-header h3 {
    margin: 0;
    font-size: 18px;
    color: var(--text-primary);
}

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

.qa-modal-close:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.qa-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.qa-modal-body .form-group {
    margin-bottom: 20px;
}

.qa-modal-body label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-primary);
}

.qa-modal-body input[type="text"],
.qa-modal-body textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    background: var(--input-bg);
    color: var(--text-primary);
    transition: all 0.2s;
}

.qa-modal-body input:focus,
.qa-modal-body textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.form-hint {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}

.qa-modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* ===================== Branches Section ===================== */

.branches-section {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.branches-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.branches-header h4 {
    margin: 0;
    font-size: 15px;
    color: var(--text-primary);
}

.branches-hint {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
    padding: 12px 16px;
    background: #eff6ff;
    border-radius: 8px;
    line-height: 1.5;
}

.no-branches {
    text-align: center;
    padding: 32px;
    background: var(--hover-bg);
    border-radius: 8px;
    color: var(--text-muted);
}

.no-branches p {
    margin: 0 0 4px;
}

.no-branches small {
    font-size: 12px;
}


/* =============== Simple Branch Styles =============== */
.branch-item {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
}

.branch-item .branch-item {
    margin-right: 24px;
    background: #fff;
    border-color: #cbd5e1;
}

.branch-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.branch-num {
    font-weight: 600;
    color: #6366f1;
    font-size: 14px;
}

.branch-btns {
    display: flex;
    gap: 6px;
}

.branch-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: #e2e8f0;
    color: #475569;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.branch-btn:hover {
    background: #cbd5e1;
}

.branch-btn-del {
    background: #fee2e2;
    color: #dc2626;
}

.branch-btn-del:hover {
    background: #fecaca;
}

.branch-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.branch-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    box-sizing: border-box;
}

.branch-input:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.branch-check {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: linear-gradient(135deg, #ede9fe, #ddd6fe);
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: #5b21b6;
}

.branch-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #6366f1;
}

.branch-check span {
    font-weight: 500;
}

.sub-branches {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed #e2e8f0;
}

/* =============== Action Box Styles =============== */
.action-box {
    margin: 16px 0;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    overflow: hidden;
}

.action-box-header {
    padding: 12px 16px;
    background: linear-gradient(135deg, #f0fdf4, #dcfce7);
}

.action-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 14px;
    color: #166534;
    font-weight: 500;
}

.action-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #16a34a;
}

.action-box-body {
    padding: 12px 16px;
    background: #f8fafc;
}

.action-box-body textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    box-sizing: border-box;
}

/* Branch Action Styles */
.branch-action {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: #f0fdf4;
    border-radius: 6px;
    margin: 4px 0;
}

.action-toggle-sm {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 12px;
    color: #166534;
    white-space: nowrap;
}

.action-toggle-sm input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: #16a34a;
}

.branch-input-sm {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 12px;
    font-family: inherit;
}

/* Action Type Select */
.action-type-select {
    margin-bottom: 10px;
}
.action-type-select label {
    display: block;
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
}
.action-type-select select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
}
.action-order-info {
    background: #fef3c7;
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 10px;
}
.action-order-info small {
    color: #92400e;
}

/* Branch Action Select */
.branch-select-sm {
    padding: 4px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 11px;
    margin-right: 6px;
}

/* ========== Actions Section ========== */
.actions-section {
    margin: 15px 0;
    padding: 15px;
    background: #f8fafc;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
}
.actions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.actions-header h4 {
    margin: 0;
    font-size: 14px;
    color: #334155;
}
.actions-hint {
    font-size: 11px;
    color: #94a3b8;
    margin-bottom: 12px;
}
.no-actions {
    text-align: center;
    padding: 20px;
    color: #94a3b8;
    font-size: 13px;
}

/* Action Item */
.action-item {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 8px;
    overflow: hidden;
}
.action-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #f1f5f9;
    border-bottom: 1px solid #e2e8f0;
}
.action-num {
    width: 24px;
    height: 24px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
}
.action-controls {
    display: flex;
    gap: 4px;
}
.action-btn {
    width: 26px;
    height: 26px;
    border: 1px solid #d1d5db;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    color: #64748b;
    transition: all 0.15s;
}
.action-btn:hover:not(:disabled) {
    background: #f1f5f9;
    border-color: #94a3b8;
}
.action-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.action-btn-del {
    color: #ef4444;
}
.action-btn-del:hover {
    background: #fef2f2 !important;
    border-color: #fca5a5 !important;
}

/* Action Item Body */
.action-item-body {
    padding: 12px;
    display: flex;
    gap: 10px;
}
.action-select {
    width: 180px;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
    background: white;
}
.action-prompt {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
}
.action-prompt::placeholder {
    color: #94a3b8;
}

/* Branch Actions Button */
.branch-actions-row {
    margin: 8px 0;
}
.branch-actions-btn {
    padding: 6px 12px;
    border: 1px dashed #d1d5db;
    background: #f8fafc;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    color: #64748b;
    transition: all 0.15s;
}
.branch-actions-btn:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
}
.branch-actions-btn.has-actions {
    background: linear-gradient(135deg, #ede9fe, #ddd6fe);
    border: 1px solid #a78bfa;
    color: #6d28d9;
}

/* Branch Actions Modal */
.branch-actions-modal {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.bam-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #e2e8f0;
}
.bam-header h4 {
    margin: 0;
    font-size: 16px;
}
.bam-close {
    width: 32px;
    height: 32px;
    border: none;
    background: #f1f5f9;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
}
.bam-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}
.bam-hint {
    font-size: 12px;
    color: #94a3b8;
    margin-bottom: 15px;
}
.bam-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 15px 20px;
    border-top: 1px solid #e2e8f0;
}

/* ==================== استایل دکمه لینک ==================== */
.link-button {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    background: linear-gradient(135deg, #eff6ff 0%, #e0f2fe 100%);
    color: #2563eb;
    border-radius: 6px;
    text-decoration: none;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid #bfdbfe;
    transition: all 0.2s ease;
    vertical-align: middle;
    margin: 0 2px;
    direction: ltr;
    unicode-bidi: embed;
}
.link-button:hover {
    background: linear-gradient(135deg, #dbeafe 0%, #bae6fd 100%);
    border-color: #93c5fd;
    color: #1d4ed8;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.15);
}
.link-button:active {
    transform: translateY(0);
}
.link-button svg {
    flex-shrink: 0;
    opacity: 0.8;
}
