:root{
  --dashboard-bg-color:#f5f7fa;
  --dashboard-text-color:#1f2937;
  --dashboard-card-bg:#ffffff;
  --dashboard-border-color:#e5e7eb;
  --dashboard-primary:#667eea;
  --dashboard-primary-hover:#764ba2;
  --dashboard-muted-text:#6b7280;
  --dashboard-card-shadow:0 8px 24px rgba(0,0,0,.06);
  --radius:20px;
  --safe-bottom:env(safe-area-inset-bottom);
}

/* نظام الصناديق */
*, *::before, *::after { box-sizing: border-box; }

/* اتجاه RTL للتطبيق فقط */
.medical-translator-app {
  direction: rtl;
  color: var(--dashboard-text-color);
  font-family: 'IBM Plex Sans Arabic', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

.dashboard {
  display:flex;
  flex-direction:column;
  min-height:100dvh;
  background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);
}

.main-content {
  flex:1;
  padding:16px;
  padding-bottom:calc(150px + var(--safe-bottom));
}
@media (min-width:768px){
  .main-content { padding:32px; padding-bottom:140px; }
}

/* شريط سفلي */
.bottom-nav {
  position:fixed; bottom:0; left:0; right:0;
  background:rgba(255,255,255,.98);
  backdrop-filter:blur(10px);
  box-shadow:0 -2px 10px rgba(0,0,0,.1);
  z-index:1000; display:flex; justify-content:space-around;
  padding:10px 0; padding-bottom:calc(10px + var(--safe-bottom));
}
.bottom-nav .nav-item {
  flex:1; display:flex; flex-direction:column; align-items:center;
  padding:8px; cursor:pointer; transition:.2s ease; color:#999;
  min-height:44px; /* هدف لمسي مناسب */
}
.bottom-nav .nav-item.active { color:#764ba2; }
.bottom-nav .nav-icon { font-size:24px; margin-bottom:5px; }
.bottom-nav .nav-label { font-size:12px; font-weight:700; }

/* رأس التطبيق */
.app-header {
  background:rgba(255,255,255,.98);
  backdrop-filter:blur(10px);
  padding:12px 16px;
  box-shadow:0 2px 10px rgba(0,0,0,.1);
  position:sticky; top:0; z-index:1000;
  border-radius:var(--radius); margin-bottom:16px;
}
.app-header .header-content {
  display:flex; justify-content:space-between; align-items:center; gap:10px;
  max-width:1200px; margin:0 auto; flex-wrap:wrap;
}
.app-logo { display:flex; align-items:center; gap:10px; font-size:20px; font-weight:800; color:#764ba2; }
.user-info { display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.user-avatar {
  width:40px; height:40px; border-radius:50%;
  background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);
  display:flex; align-items:center; justify-content:center; color:#fff; font-weight:700;
}
.subscription-badge { padding:5px 12px; border-radius:20px; font-size:12px; font-weight:700; background:#4CAF50; color:#fff; }
.subscription-badge.inactive { background:#f44336; }
.usage-badge {
  padding:5px 12px; border-radius:20px; font-size:12px; font-weight:800;
  background:#eef2ff; color:#4338ca; border:1px solid #c7d2fe;
}
.cycle-note { font-size:12px; color:#6b7280; }

/* المحتوى */
.app-content { max-width:1200px; margin:0 auto; }
.tab-content { display:none; animation:fadeIn .25s ease; }
.tab-content.active { display:block; }
@keyframes fadeIn { from{opacity:0; transform:translateY(10px);} to{opacity:1; transform:translateY(0);} }
@media (prefers-reduced-motion: reduce){
  .tab-content { animation:none !important; }
}

.translation-card {
  background:#fff; border-radius:var(--radius);
  padding:16px; margin-bottom:16px; box-shadow:0 5px 20px rgba(0,0,0,.08);
}
.card-header { display:flex; align-items:center; gap:12px; margin-bottom:16px; padding-bottom:12px; border-bottom:2px solid #f5f5f5; }
.card-icon {
  width:48px; height:48px; border-radius:14px;
  background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);
  display:flex; align-items:center; justify-content:center; color:#fff; font-size:22px;
}
.card-title h2 { font-size:18px; font-weight:800; color:#333; margin:0 0 4px; }
.card-subtitle { font-size:13px; color:#999; }

.input-tabs { display:flex; gap:8px; margin-bottom:12px; flex-wrap:wrap; }
.input-tab {
  padding:10px 16px; border-radius:10px; background:#f5f5f5; border:none;
  font-size:14px; font-weight:800; cursor:pointer; transition:.2s ease;
  min-height:40px;
}
.input-tab.active { background:linear-gradient(135deg,#667eea 0%,#764ba2 100%); color:#fff; }

.text-input {
  width:100%; min-height:150px; padding:12px;
  border:2px solid #f5f5f5; border-radius:12px; font-size:16px; resize:vertical; transition:.2s ease;
}
.text-input:focus { outline:none; border-color:#764ba2; }

.file-upload-area {
  border:2px dashed #ddd; border-radius:12px; padding:16px; text-align:center; cursor:pointer; transition:.2s ease; display:none;
}
.file-upload-area.active { display:block; }
.file-upload-area:hover { border-color:#764ba2; background:#fafafa; }
.upload-icon { font-size:36px; color:#764ba2; margin-bottom:6px; }
.upload-text { font-size:14px; color:#666; }
.file-input { display:none; }

/* المعاينة */
.preview { margin-top:10px; max-height:380px; overflow:auto; }
.preview img {
  max-width:100%; max-height:360px; width:auto; height:auto; object-fit:contain;
  border-radius:12px; box-shadow:0 4px 12px rgba(0,0,0,.08);
}

/* أزرار الإجراءات */
.action-buttons { display:flex; gap:10px; margin-top:16px; flex-wrap:wrap; }
.btn {
  padding:12px 20px; border:none; border-radius:10px; font-size:16px; font-weight:800;
  cursor:pointer; display:flex; gap:8px; align-items:center; justify-content:center; transition:.15s ease; text-decoration:none;
  min-height:44px;
}
.btn:disabled { opacity:.6; cursor:not-allowed; }
.btn-primary {
  background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);
  color:#fff; flex:1;
}
.btn-primary:hover:not(:disabled) { transform:translateY(-2px); box-shadow:0 5px 20px rgba(118,75,162,.3); }
.btn-secondary { background:#f5f5f5; color:#666; }

/* النتائج */
.result-section { margin-top:24px; padding:16px; background:#f9f9f9; border-radius:12px; display:none; }
.result-section.active { display:block; }
.result-header { display:flex; justify-content:space-between; align-items:center; margin-bottom:12px; gap:10px; flex-wrap:wrap; }
.result-title { font-size:18px; font-weight:800; }
.result-actions { display:flex; gap:8px; }
.result-btn { padding:8px 14px; border-radius:8px; border:none; background:#fff; color:#666; font-size:14px; cursor:pointer; min-height:40px; }
.result-btn:hover { background:#764ba2; color:#fff; }
.result-content { background:#fff; padding:16px; border-radius:10px; font-size:16px; line-height:1.8; overflow:visible !important; }

/* بطاقات إحصاءات */
.stats-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:12px; margin-bottom:24px; }
.stat-card { background:#fff; border-radius:12px; padding:16px; text-align:center; box-shadow:0 2px 10px rgba(0,0,0,.05); }
.stat-value { font-size:28px; font-weight:800; color:#764ba2; }
.stat-label { font-size:13px; color:#999; }

.history-list { display:flex; flex-direction:column; gap:12px; }
.history-item { background:#fff; border-radius:12px; padding:12px; box-shadow:0 2px 10px rgba(0,0,0,.05); cursor:pointer; transition:.15s ease; }
.history-item:hover { transform:translateX(4px); box-shadow:0 5px 20px rgba(0,0,0,.1); }
.history-date { font-size:12px; color:#999; margin-bottom:4px; }

/* تنبيهات */
.alert { padding:12px; border-radius:10px; margin-bottom:16px; display:flex; align-items:center; gap:10px; font-weight:700; }
.alert-warning { background:#fff3cd; color:#856404; }
.alert-success { background:#d4edda; color:#155724; }
.alert-error   { background:#f8d7da; color:#721c24; }

/* ===== ألوان/حالات النتائج ===== */
.mild-abnormal     { background-color:#fff3cd !important; color:#856404; }
.moderate-abnormal { background-color:#ffe4b5 !important; color:#8a5700; }
.critical-abnormal { background-color:#f8d7da !important; color:#721c24; font-weight:600; }
.low-abnormal      { background-color:#d1ecf1 !important; color:#004085; }

.mild-abnormal td,
.moderate-abnormal td,
.critical-abnormal td,
.low-abnormal td {
  border-color: rgba(0,0,0,0.125);
  padding:8px;
}

/* فقرات ملوّنة */
p.critical-abnormal,
p.moderate-abnormal,
p.mild-abnormal,
p.low-abnormal {
  padding:10px; border-radius:5px; margin:10px 0;
}
.critical-abnormal::before { content:"⚠️ "; font-size:1.2em; }

.image-quality-notice { background-color:#ffeaa7; padding:8px; border-radius:4px; margin-bottom:15px; }

/* ===== الجداول (أساس) ===== */
table { width:100%; border-collapse:collapse; margin:15px 0; }
th    { background-color:#f8f9fa; font-weight:700; text-align:right; padding:10px; }
td    { padding:8px; border-bottom:1px solid #dee2e6; }

/* تأثير hover */
tr:hover { background-color: rgba(0,0,0,0.02); }
tr.critical-abnormal:hover { background-color:#f5c6cb !important; }
tr.moderate-abnormal:hover { background-color:#ffd4a3 !important; }
tr.mild-abnormal:hover     { background-color:#ffeeba !important; }
tr.low-abnormal:hover      { background-color:#bee5eb !important; }

/* ===== الجداول المتجاوبة (mobile-cards) ===== */
.table-responsive { width:100%; overflow-x:auto; }

/* على الشاشات الصغيرة نحول الصف إلى "بطاقة" */
@media (max-width: 640px){

  .mobile-cards thead { 
    /* إخفاء رؤوس الأعمدة لأننا سنعرضها داخل كل خلية عبر data-label */
    display:none;
  }

  .mobile-cards,
  .mobile-cards tbody,
  .mobile-cards tr,
  .mobile-cards td {
    display:block;
    width:100%;
  }

  .mobile-cards tr {
    background:#fff;
    border:1px solid #eee;
    border-radius:12px;
    padding:10px;
    margin:10px 0;
    box-shadow:0 2px 8px rgba(0,0,0,.04);
  }

  .mobile-cards td {
    display:flex;
    align-items:flex-start;
    justify-content:space-between;
    gap:10px;
    border:none;
    border-bottom:1px solid #f1f1f1;
    padding:8px 4px;
    text-align:right;
  }

  .mobile-cards td:last-child {
    border-bottom:none;
    padding-bottom:0;
  }

  /* نعرض اسم العمود من data-label قبل القيمة */
  .mobile-cards td::before {
    content: attr(data-label);
    font-weight:700;
    color:#374151;
    flex:0 0 auto;
    max-width:50%;
  }

  .mobile-cards td { direction: rtl; }

  /* نحافظ على ألوان الحالات للبطاقات أيضاً */
  .mobile-cards tr.mild-abnormal     { background-color:#fff7da !important; }
  .mobile-cards tr.moderate-abnormal { background-color:#ffedd6 !important; }
  .mobile-cards tr.critical-abnormal { background-color:#fde2e2 !important; }
  .mobile-cards tr.low-abnormal      { background-color:#e9f7fb !important; }
}

/* مؤشر تحميل صغير */
@keyframes spin { to { transform: rotate(360deg);} }
.loading-spinner {
  display:inline-block; width:18px; height:18px;
  border:3px solid rgba(255,255,255,.3); border-top-color:#fff;
  border-radius:50%; animation:spin 1s linear infinite;
}

/* إخفاء الهيدر في صفحة الداشبورد فقط */
body.dashboard-body .header,
body.dashboard-body .site-header { display:none !important; }

/* ===================== */
/* إضافات صغيرة للجداول  */
/* ===================== */

/* تمرير سلس للجداول داخل نتائج التحليل */
.result-content section.table-responsive{
  width:100%;
  overflow-x:auto;
  -webkit-overflow-scrolling: touch;
}

/* كسر الكلمات الطويلة داخل الخلايا لمنع تمدد العرض */
.result-content table th,
.result-content table td{
  word-break: break-word;
  overflow-wrap: anywhere;
}
