/* ============================================
   استایل سامانه پرسش و پاسخ — RTL فارسی
   ============================================ */
:root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --primary-light: #e8f0fe;
    --success: #0f9d58;
    --warning: #f4b400;
    --danger: #d93025;
    --bg: #f0f2f5;
    --card: #ffffff;
    --text: #202124;
    --text-secondary: #5f6368;
    --border: #dadce0;
    --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-sm: 8px;
}

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

body {
    font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.8;
    min-height: 100vh;
}

/* ============================================
   Navbar
   ============================================ */
.navbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
    direction: rtl;
}

.nav-brand {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 16px;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.nav-link:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.admin-link {
    background: var(--primary);
    color: white;
    font-weight: 500;
}

.admin-link:hover {
    background: var(--primary-dark);
    color: white;
}

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

.nav-badge {
    font-size: 12px;
    color: var(--text-secondary);
    padding: 4px 10px;
    background: var(--primary-light);
    border-radius: 20px;
}

/* ============================================
   Container / Cards
   ============================================ */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 16px;
}

.page-header {
    text-align: center;
    margin-bottom: 32px;
}

.page-header h1 {
    font-size: 28px;
    font-weight: 900;
    color: var(--text);
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 15px;
}

.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
}

.card-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text);
}

.card-desc {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 16px;
}

.card-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    flex-wrap: wrap;
}

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

.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    box-shadow: var(--shadow);
    border-right: 4px solid var(--primary);
}

.stat-number {
    font-size: 32px;
    font-weight: 900;
    color: var(--primary);
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ============================================
   Buttons
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

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

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

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

.btn-danger:hover {
    background: #c5221f;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-full {
    width: 100%;
    justify-content: center;
    padding: 14px;
    font-size: 16px;
}

/* ============================================
   Drop Zone
   ============================================ */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    background: #fafafa;
}

.drop-zone:hover, .drop-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.drop-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.drop-text {
    font-size: 18px;
    font-weight: 500;
    color: var(--text);
}

.drop-hint {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.upload-progress {
    margin-top: 16px;
}

.progress-bar {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--success));
    border-radius: 4px;
    transition: width 0.3s;
    width: 0%;
}

.progress-text {
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 8px;
}

.upload-result {
    margin-top: 12px;
    padding: 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    white-space: pre-wrap;
}

/* ============================================
   Table
   ============================================ */
.table-wrapper {
    overflow-x: auto;
}

.files-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.files-table th {
    background: var(--primary-light);
    color: var(--primary-dark);
    font-weight: 700;
    padding: 12px 16px;
    text-align: right;
    border-bottom: 2px solid var(--border);
}

.files-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.files-table tr:hover {
    background: #f8f9fa;
}

.file-name {
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.file-size {
    direction: ltr;
    text-align: left;
    font-variant-numeric: tabular-nums;
}

/* ============================================
   Badges
   ============================================ */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.badge-regulation { background: #e3f2fd; color: #1565c0; }
.badge-qa { background: #fce4ec; color: #c62828; }
.badge-process { background: #e8f5e9; color: #2e7d32; }
.badge-guest_transfer { background: #fff3e0; color: #e65100; }
.badge-admission { background: #f3e5f5; color: #6a1b9a; }
.badge-graduation { background: #e0f2f1; color: #00695c; }
.badge-other { background: #f5f5f5; color: #616161; }
.badge-assistant { background: #fbe9e7; color: #bf360c; }

/* ============================================
   Empty State
   ============================================ */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.empty-hint {
    font-size: 13px;
    margin-top: 8px;
    color: var(--text-secondary);
}

/* ============================================
   Toast
   ============================================ */
.toast-container {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    direction: rtl;
}

.toast {
    padding: 14px 24px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
    max-width: 500px;
    white-space: pre-wrap;
}

.toast-success { background: #e6f4ea; color: #1e7e34; border-right: 4px solid var(--success); }
.toast-error { background: #fce8e6; color: var(--danger); border-right: 4px solid var(--danger); }
.toast-info { background: #e8f0fe; color: var(--primary); border-right: 4px solid var(--primary); }

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

/* ============================================
   چت — LAYOUT
   ============================================ */
.chat-layout {
    display: flex;
    height: calc(100vh - 60px);
    direction: rtl;
}

/* ============================================
   سایدبار
   ============================================ */
.sidebar {
    width: 300px;
    background: var(--card);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.3s, padding 0.3s;
}

.sidebar.collapsed {
    width: 0;
    padding: 0;
    border: none;
}

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--primary-light);
}

.sidebar-header h3 {
    font-size: 16px;
    color: var(--primary-dark);
}

.sidebar-content {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

.guide-section {
    margin-bottom: 24px;
}

.guide-section h4 {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    font-weight: 700;
}

.sample-questions {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sample-questions li {
    padding: 10px 14px;
    background: var(--primary-light);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
    color: var(--primary);
    border-right: 3px solid transparent;
}

.sample-questions li:hover {
    background: var(--primary);
    color: white;
    border-right-color: var(--primary-dark);
    transform: translateX(-4px);
}

.tips-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tips-list li {
    font-size: 13px;
    color: var(--text-secondary);
    padding-right: 20px;
    position: relative;
}

.tips-list li::before {
    content: '•';
    position: absolute;
    right: 4px;
    color: var(--primary);
}

/* ============================================
   CHAT MAIN
   ============================================ */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

.chat-header {
    padding: 12px 20px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow);
}

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    display: none;
}

.sidebar-toggle:hover {
    background: var(--primary-light);
}

.chat-header h2 {
    font-size: 18px;
    font-weight: 700;
    flex: 1;
}

.status-badge {
    font-size: 13px;
    font-weight: 500;
    padding: 4px 12px;
    border-radius: 20px;
    background: var(--primary-light);
}

/* ============================================
   MESSAGES
   ============================================ */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    gap: 12px;
    max-width: 80%;
    animation: fadeIn 0.3s ease;
}

.message-user {
    align-self: flex-start;
    flex-direction: row-reverse;
}

.message-bot {
    align-self: flex-end;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.message-user .message-avatar {
    background: var(--primary);
    color: white;
}

.message-bot .message-avatar {
    background: var(--primary-light);
    color: var(--primary);
}

.message-content {
    background: var(--card);
    border-radius: var(--radius);
    padding: 14px 18px;
    box-shadow: var(--shadow);
}

.message-user .message-content {
    background: var(--primary);
    color: white;
    border-bottom-left-radius: 4px;
}

.message-bot .message-content {
    border-bottom-right-radius: 4px;
}

.message-text p {
    margin-bottom: 8px;
    font-size: 14px;
    line-height: 1.8;
}

.message-text p:last-child {
    margin-bottom: 0;
}

.message-hint {
    font-size: 12px;
    opacity: 0.8;
    font-style: italic;
}

.message-text a {
    color: inherit;
    text-decoration: underline;
}

.message-user .message-text a {
    color: #e8f0fe;
}

/* ============================================
   TYPING INDICATOR
   ============================================ */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 4px;
    align-items: center;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-10px); opacity: 1; }
}

/* ============================================
   Markdown inside messages
   ============================================ */
.message-text h1, .message-text h2, .message-text h3,
.message-text h4, .message-text h5, .message-text h6 {
    margin: 16px 0 8px;
    font-weight: 700;
    line-height: 1.4;
    color: var(--text);
}
.message-text h1 { font-size: 20px; }
.message-text h2 { font-size: 18px; }
.message-text h3 { font-size: 16px; }
.message-text h4 { font-size: 15px; }
.message-text h5, .message-text h6 { font-size: 14px; }

.message-text p {
    margin-bottom: 10px;
    font-size: 14px;
    line-height: 1.8;
}
.message-text p:last-child { margin-bottom: 0; }

.message-text ul, .message-text ol {
    margin: 8px 0;
    padding-right: 24px;
}
.message-text li {
    margin-bottom: 4px;
    font-size: 14px;
    line-height: 1.7;
}
.message-text li:last-child { margin-bottom: 0; }

.message-text blockquote {
    margin: 10px 0;
    padding: 8px 16px;
    border-right: 4px solid var(--primary);
    background: var(--primary-light);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 13px;
}
.message-text blockquote p { margin: 0; }

.message-text code {
    background: #f1f3f4;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: #d63384;
    direction: ltr;
    display: inline-block;
}

.message-text .code-block {
    margin: 10px 0;
    background: #1e1e1e;
    border-radius: 8px;
    overflow: hidden;
    direction: ltr;
}
.message-text .code-block pre {
    padding: 14px 16px;
    overflow-x: auto;
    margin: 0;
}
.message-text .code-block code {
    background: none;
    padding: 0;
    border-radius: 0;
    color: #d4d4d4;
    font-size: 13px;
    line-height: 1.6;
    display: block;
    white-space: pre;
    font-family: 'Courier New', monospace;
}

.message-text hr {
    border: none;
    border-top: 2px solid var(--border);
    margin: 12px 0;
}

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

.message-text strong {
    font-weight: 700;
}

.message-text em {
    font-style: italic;
}

.message-text .table-wrap {
    overflow-x: auto;
    margin: 10px 0;
}
.message-text table {
    border-collapse: collapse;
    width: 100%;
    font-size: 13px;
    direction: ltr;
}
.message-text th, .message-text td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: right;
}
.message-text th {
    background: var(--primary-light);
    font-weight: 700;
    color: var(--primary-dark);
}
.message-text tr:nth-child(even) {
    background: #f8f9fa;
}

/* ============================================
   Sources & Cost
   ============================================ */
.message-sources {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}
.sources-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 6px;
}
.sources-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.source-item {
    font-size: 12px;
    background: #f1f8e9;
    color: #33691e;
    padding: 3px 10px;
    border-radius: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
    direction: ltr;
}

/* ============================================
   FadeIn
   ============================================ */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================
   INPUT AREA
   ============================================ */
.input-area {
    padding: 16px 20px;
    background: var(--card);
    border-top: 1px solid var(--border);
}

.input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.input-wrapper textarea {
    flex: 1;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    font-family: inherit;
    font-size: 14px;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
    line-height: 1.6;
    min-height: 48px;
    max-height: 120px;
    background: var(--bg);
}

.input-wrapper textarea:focus {
    border-color: var(--primary);
    background: var(--card);
}

.send-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    height: 48px;
}

.send-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.send-icon {
    font-size: 16px;
}

/* ============================================
   LOGIN PAGE
   ============================================ */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1a73e8 0%, #0d47a1 100%);
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 20px;
}

.login-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 40px 32px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    text-align: center;
}

.login-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.login-title {
    font-size: 24px;
    font-weight: 900;
    color: var(--text);
    margin-bottom: 4px;
}

.login-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.login-form .form-group {
    margin-bottom: 20px;
    text-align: right;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text);
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    direction: ltr;
    text-align: left;
}

.form-group input:focus {
    border-color: var(--primary);
}

.login-footer {
    margin-top: 24px;
}

.text-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
}

.text-link:hover {
    color: var(--primary);
}

/* ============================================
   Alert
   ============================================ */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.alert-error {
    background: #fce8e6;
    color: var(--danger);
    border-right: 4px solid var(--danger);
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 60px;
        right: 0;
        bottom: 0;
        z-index: 50;
        width: 280px;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.collapsed {
        width: 0;
        transform: translateX(100%);
    }
    .sidebar-toggle {
        display: block;
    }
    .message {
        max-width: 95%;
    }
    .chat-header h2 {
        font-size: 15px;
    }
    .send-btn span:last-child {
        display: none;
    }
    .send-btn {
        padding: 12px 16px;
    }
    .stats-row {
        grid-template-columns: 1fr;
    }
    .login-container {
        padding: 12px;
    }
    .container {
        padding: 16px 8px;
    }
}
