* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #1b7f8c;           /* لون رئيسي مائل للتركواز */
    --primary-light: #4fc3d0;
    --secondary: #0b3b5f;         /* أزرق داكن للعناوين */
    --success: #1e8b5c;
    --danger: #c0392b;
    --bg: #f0f5fa;               /* خلفية عامة فاتحة */
    --bg-light: #ffffff;         /* خلفية البطاقات */
    --text: #0b2a3b;             /* نص غامق */
    --text-muted: #4f6f7e;       /* نص مساعد */
    --border: #dce5ed;           /* حدود فاتحة */
    --shadow: rgba(0, 0, 0, 0.06);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
}

/* الرأس */
header {
    text-align: center;
    margin-bottom: 40px;
    padding: 30px 0;
    border-bottom: 2px solid var(--border);
}

header h1 {
    font-size: 2.5rem;
    background: linear-gradient(135deg, var(--secondary) 0%, var(--primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 10px;
}

header p {
    color: var(--text-muted);
    font-size: 1.1rem;
}

/* الإحصائيات */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.stat-item {
    background: var(--bg-light);
    border: 1px solid var(--border);
    padding: 20px;
    border-radius: 12px;
    text-align: center;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px var(--shadow);
}

.stat-item:hover {
    border-color: var(--primary);
    transform: translateY(-5px);
    box-shadow: 0 8px 24px rgba(27, 127, 140, 0.12);
}

.stat-label {
    display: block;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.stat-value {
    display: block;
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary);
}

/* الأقسام */
section {
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 0 4px 16px var(--shadow);
    transition: all 0.3s ease;
}

section:hover {
    border-color: var(--primary-light);
    box-shadow: 0 8px 32px rgba(27, 127, 140, 0.08);
}

section h2 {
    margin-bottom: 20px;
    color: var(--secondary);
    font-size: 1.5rem;
    border-right: 4px solid var(--primary);
    padding-right: 12px;
}

/* منطقة الرفع */
.upload-area {
    border: 2px dashed var(--primary);
    border-radius: 12px;
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: rgba(27, 127, 140, 0.04);
}

.upload-area:hover {
    background: rgba(27, 127, 140, 0.08);
    border-color: var(--primary-light);
}

.upload-area.dragover {
    background: rgba(79, 195, 208, 0.12);
    border-color: var(--primary);
    transform: scale(1.02);
}

.upload-area svg {
    margin-bottom: 10px;
    color: var(--primary);
}

.upload-area p {
    font-size: 1.1rem;
    margin-bottom: 5px;
}

.upload-area small {
    color: var(--text-muted);
}

/* حالة الرفع */
.upload-status {
    margin-top: 20px;
    padding: 15px;
    border-radius: 8px;
    display: none;
}

.upload-status.success {
    display: block;
    background: rgba(30, 139, 92, 0.08);
    color: var(--success);
    border-left: 4px solid var(--success);
}

.upload-status.error {
    display: block;
    background: rgba(192, 57, 43, 0.08);
    color: var(--danger);
    border-left: 4px solid var(--danger);
}

/* قائمة الملفات */
.file-list {
    margin-top: 20px;
}

.file-item {
    background: rgba(0, 0, 0, 0.02);
    padding: 12px 15px;
    border-radius: 8px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid var(--border);
}

.file-item .name {
    flex: 1;
}

.file-item .size {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* الأزرار */
.btn-primary, .btn-secondary, .btn-danger {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    width: 100%;
    margin-top: 15px;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(27, 127, 140, 0.3);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: rgba(27, 127, 140, 0.08);
    color: var(--primary);
    border: 1px solid var(--primary);
}

.btn-secondary:hover {
    background: rgba(27, 127, 140, 0.16);
}

.btn-danger {
    background: rgba(192, 57, 43, 0.08);
    color: var(--danger);
    border: 1px solid var(--danger);
    margin-top: 15px;
}

.btn-danger:hover {
    background: rgba(192, 57, 43, 0.16);
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
}

/* قسم الأسئلة والأجوبة */
.input-group {
    margin-bottom: 20px;
}

textarea {
    width: 100%;
    padding: 15px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: inherit;
    resize: vertical;
    transition: border-color 0.3s ease;
}

textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(27, 127, 140, 0.15);
}

/* الإجابة */
.answer-container {
    background: rgba(27, 127, 140, 0.04);
    border: 1px solid var(--primary);
    border-radius: 12px;
    padding: 20px;
    margin-top: 20px;
}

.answer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.answer-header h3 {
    color: var(--secondary);
}

.answer-text {
    background: rgba(0, 0, 0, 0.02);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
    line-height: 1.8;
    white-space: pre-wrap;
    word-wrap: break-word;
    border: 1px solid var(--border);
}

/* المصادر */
.sources {
    background: rgba(30, 139, 92, 0.06);
    border-left: 4px solid var(--success);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
}

.sources h4 {
    color: var(--success);
    margin-bottom: 10px;
}

.source-item {
    padding: 8px;
    background: rgba(0, 0, 0, 0.02);
    border-radius: 5px;
    margin-bottom: 8px;
    font-size: 0.95rem;
    border-bottom: 1px solid var(--border);
}

/* السجل */
.history-list {
    margin-bottom: 15px;
}

.history-item {
    background: rgba(0, 0, 0, 0.02);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 10px;
    border-left: 4px solid var(--primary);
    cursor: pointer;
    transition: all 0.3s ease;
    border: 1px solid var(--border);
}

.history-item:hover {
    background: rgba(27, 127, 140, 0.06);
}

.history-question {
    color: var(--secondary);
    font-weight: 600;
    margin-bottom: 5px;
}

.history-time {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Loading Spinner */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.85);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading p {
    margin-top: 20px;
    color: var(--text);
    font-size: 1.1rem;
}

/* التذييل */
footer {
    text-align: center;
    padding: 20px 0;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    margin-top: 40px;
}

footer p {
    margin: 5px 0;
    font-size: 0.95rem;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }

    header h1 {
        font-size: 1.8rem;
    }

    section {
        padding: 20px;
    }

    .stats {
        grid-template-columns: 1fr;
    }

    .upload-area {
        padding: 30px 20px;
    }
}