/* ===== مُشَكِّل — نظام تصميم عصري RTL ===== */
:root {
  --bg: #f4f2ee;
  --bg-soft: #ebe8e2;
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --text: #1f2937;
  --text-soft: #6b7280;
  --primary: #8b4513;         /* البني التراثي — متسق مع أقواس المستند */
  --primary-soft: #a05a2c;
  --primary-glow: rgba(139, 69, 19, .12);
  --accent: #c00000;          /* أحمر العناوين */
  --accent-soft: #fef2f2;
  --success: #15803d;
  --success-soft: #f0fdf4;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --border: #e5e1da;
  --border-strong: #d6d1c7;
  --shadow-sm: 0 1px 2px rgba(31, 25, 18, .06);
  --shadow-md: 0 4px 16px -4px rgba(31, 25, 18, .1);
  --shadow-lg: 0 16px 40px -12px rgba(31, 25, 18, .18);
  --radius: 14px;
  --radius-sm: 9px;
  --font: 'IBM Plex Sans Arabic', 'Tajawal', 'Segoe UI', system-ui, sans-serif;
  --transition: .22s cubic-bezier(.4, 0, .2, 1);
}
[data-theme="dark"] {
  --bg: #141210;
  --bg-soft: #1c1916;
  --surface: #211d19;
  --surface-2: #2a2521;
  --text: #ece7df;
  --text-soft: #a39c90;
  --primary: #d29a63;
  --primary-soft: #e0b183;
  --primary-glow: rgba(210, 154, 99, .1);
  --accent: #ef8a8a;
  --accent-soft: #2c1a1a;
  --success: #6ee7a0;
  --success-soft: #16281d;
  --warn: #f5c56b;
  --warn-soft: #2a2214;
  --danger: #f28b8b;
  --danger-soft: #2c1a1a;
  --border: #35302a;
  --border-strong: #453e36;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.4);
  --shadow-md: 0 6px 20px -6px rgba(0,0,0,.5);
  --shadow-lg: 0 20px 50px -12px rgba(0,0,0,.6);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15.5px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  transition: background var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }

/* ---------- تخطيط التطبيق ---------- */
#app { min-height: 100vh; }
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex-shrink: 0; background: var(--surface);
  border-inline-start: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 6px 10px 22px; }
.brand-icon {
  width: 42px; height: 42px; border-radius: 12px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), var(--primary-soft));
  display: grid; place-items: center; font-size: 21px; color: #fff;
  box-shadow: var(--shadow-md);
}
.brand h1 { font-size: 1.25rem; font-weight: 800; letter-spacing: -.3px; }
.brand small { color: var(--text-soft); font-size: .72rem; display: block; margin-top: -4px; }
.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 10.5px 14px;
  border-radius: var(--radius-sm); color: var(--text-soft); font-weight: 600;
  font-size: .93rem; transition: all var(--transition);
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active {
  background: var(--primary-glow); color: var(--primary);
  box-shadow: inset -3px 0 0 var(--primary);
}
.nav a .ico { width: 20px; text-align: center; font-size: 1.05rem; }
.sidebar-footer { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px 10px; font-size: .85rem; color: var(--text-soft); }
.user-chip .avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--primary-glow);
  color: var(--primary); display: grid; place-items: center; font-weight: 800;
}

.main { flex: 1; padding: 30px 36px 60px; max-width: 1280px; margin-inline: auto; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 26px; flex-wrap: wrap; }
.page-head h2 { font-size: 1.55rem; font-weight: 800; letter-spacing: -.4px; }
.page-head p { color: var(--text-soft); font-size: .9rem; margin-top: 2px; }

/* ---------- مكونات ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 22px; transition: box-shadow var(--transition);
}
.card + .card { margin-top: 16px; }
.card.hover:hover { box-shadow: var(--shadow-md); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 18px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-weight: 700; font-size: .88rem; cursor: pointer; transition: all var(--transition);
  background: var(--surface-2); color: var(--text); white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active { transform: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none !important; box-shadow: none !important; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-soft); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border-strong); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 5.5px 12px; font-size: .8rem; border-radius: 8px; }
.btn-icon { padding: 7px 10px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 11px;
  border-radius: 99px; font-size: .74rem; font-weight: 700;
}
.badge-queued { background: var(--warn-soft); color: var(--warn); }
.badge-running { background: var(--primary-glow); color: var(--primary); }
.badge-done { background: var(--success-soft); color: var(--success); }
.badge-failed, .badge-canceled { background: var(--danger-soft); color: var(--danger); }
.badge-idle { background: var(--surface-2); color: var(--text-soft); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-strong); background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3.5px var(--primary-glow);
}
label { font-size: .84rem; font-weight: 700; color: var(--text-soft); display: block; margin-bottom: 6px; }
.field { margin-bottom: 15px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }

/* ---------- شريط التقدم ---------- */
.progress { height: 9px; background: var(--bg-soft); border-radius: 99px; overflow: hidden; }
.progress-bar {
  height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-soft));
  border-radius: 99px; transition: width .5s ease; position: relative;
}
.progress-bar.indeterminate {
  width: 35% !important; animation: slide 1.4s ease-in-out infinite alternate;
}
@keyframes slide { to { transform: translateX(-180%); } }

/* ---------- قائمة الملفات ---------- */
.file-row {
  display: flex; align-items: center; gap: 14px; padding: 14px 18px;
  border-bottom: 1px solid var(--border); transition: background var(--transition);
}
.file-row:last-child { border-bottom: none; }
.file-row:hover { background: var(--surface-2); }
.file-check { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0; }
.file-info { flex: 1; min-width: 0; }
.file-name { font-weight: 700; font-size: .93rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { font-size: .76rem; color: var(--text-soft); display: flex; gap: 12px; margin-top: 1px; flex-wrap: wrap; }
.file-actions { display: flex; gap: 7px; flex-shrink: 0; align-items: center; }
.group-pill {
  font-size: .72rem; font-weight: 700; padding: 2.5px 10px; border-radius: 99px;
  background: var(--primary-glow); color: var(--primary);
}
.list-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1.5px solid var(--border-strong); background: var(--surface-2);
  border-radius: var(--radius) var(--radius) 0 0; flex-wrap: wrap;
}
.list { border-radius: var(--radius); overflow: hidden; }

/* ---------- worker cards ---------- */
.workers-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.worker-card { position: relative; overflow: hidden; }
.worker-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.worker-title { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.02rem; }
.worker-avatar {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: var(--primary-glow); color: var(--primary); font-size: 19px;
}
.worker-card.running { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow), var(--shadow-md); }
.worker-empty { color: var(--text-soft); font-size: .88rem; text-align: center; padding: 18px 0; }
.log-box {
  margin-top: 14px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; font-size: .78rem; max-height: 190px; overflow-y: auto;
  font-family: 'Cascadia Code', 'Consolas', monospace; line-height: 1.9;
}
.log-box .l-warn { color: var(--warn); }
.log-box .l-error { color: var(--danger); }
.log-box .l-info { color: var(--text-soft); }

/* ---------- الإحصاءات ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 17px 19px; box-shadow: var(--shadow-sm);
}
.stat .num { font-size: 1.75rem; font-weight: 800; letter-spacing: -.5px; }
.stat .lbl { font-size: .78rem; color: var(--text-soft); font-weight: 600; }
.stat .ico { float: left; font-size: 1.35rem; opacity: .55; }

/* ---------- قرص المساحة ---------- */
.disk-wrap { display: flex; align-items: center; gap: 26px; flex-wrap: wrap; }
.disk-ring { position: relative; width: 130px; height: 130px; flex-shrink: 0; }
.disk-ring svg { transform: rotate(-90deg); }
.disk-ring .pct {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 1.45rem; font-weight: 800; letter-spacing: -.5px;
}
.disk-info { flex: 1; min-width: 220px; }
.disk-info .row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: .86rem; }
.disk-info .row:last-child { border: none; }
.disk-info .row span:first-child { color: var(--text-soft); }

/* ---------- مودال ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 12, 8, .45); backdrop-filter: blur(5px);
  display: grid; place-items: center; z-index: 100; padding: 22px; animation: fadeIn .2s ease;
}
.modal {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: 88vh; display: flex; flex-direction: column;
  animation: popIn .25s cubic-bezier(.34, 1.4, .64, 1);
}
.modal-lg { max-width: 780px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 19px 24px 0; }
.modal-head h3 { font-size: 1.13rem; font-weight: 800; }
.modal-body { padding: 18px 24px; overflow-y: auto; }
.modal-foot { display: flex; gap: 9px; justify-content: flex-start; padding: 0 24px 21px; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: scale(.94) translateY(9px); } }
.modal-close { background: none; border: none; font-size: 1.25rem; cursor: pointer; color: var(--text-soft); padding: 4px 8px; border-radius: 8px; }
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.text-preview {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 16px; max-height: 55vh; overflow-y: auto; white-space: pre-wrap;
  font-size: .9rem; line-height: 2.1;
}

/* ---------- توست ---------- */
#toast-container { position: fixed; bottom: 24px; inset-inline-start: 24px; z-index: 200; display: flex; flex-direction: column; gap: 9px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); padding: 13px 19px; min-width: 260px; max-width: 380px;
  display: flex; align-items: center; gap: 10px; font-size: .88rem; font-weight: 600;
  animation: toastIn .3s cubic-bezier(.34, 1.3, .64, 1);
}
.toast.success { border-inline-start: 3.5px solid var(--success); }
.toast.error { border-inline-start: 3.5px solid var(--danger); }
.toast.info { border-inline-start: 3.5px solid var(--primary); }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px); } }
.toast.hide { animation: toastOut .25s ease forwards; }
@keyframes toastOut { to { opacity: 0; transform: translateY(9px); } }

/* ---------- تسجيل الدخول ---------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background:
    radial-gradient(ellipse 60% 45% at 85% 8%, var(--primary-glow), transparent),
    radial-gradient(ellipse 50% 40% at 12% 95%, var(--primary-glow), transparent),
    var(--bg);
}
.login-card { width: 100%; max-width: 400px; }
.login-logo {
  width: 66px; height: 66px; border-radius: 19px; margin: 0 auto 18px;
  background: linear-gradient(135deg, var(--primary), var(--primary-soft));
  display: grid; place-items: center; font-size: 32px; color: #fff; box-shadow: var(--shadow-lg);
}
.login-card h1 { text-align: center; font-size: 1.5rem; font-weight: 800; margin-bottom: 4px; }
.login-card .sub { text-align: center; color: var(--text-soft); font-size: .87rem; margin-bottom: 26px; }

/* ---------- زر رفع ملفات ---------- */
.dropzone {
  border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 38px 20px;
  text-align: center; cursor: pointer; transition: all var(--transition); background: var(--surface-2);
  margin-bottom: 18px;
}
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: var(--primary-glow); }
.dropzone .ico { font-size: 2rem; margin-bottom: 8px; }
.dropzone p { font-weight: 700; }
.dropzone small { color: var(--text-soft); }

/* ---------- تبويبات الإعدادات ---------- */
.tabs { display: flex; gap: 5px; border-bottom: 1.5px solid var(--border-strong); margin-bottom: 22px; flex-wrap: wrap; }
.tabs button {
  background: none; border: none; padding: 10px 17px; font-weight: 700; cursor: pointer;
  color: var(--text-soft); border-bottom: 2.5px solid transparent; margin-bottom: -1.5px;
  transition: all var(--transition); font-size: .9rem;
}
.tabs button.active { color: var(--primary); border-color: var(--primary); }
.tabs button:hover { color: var(--text); }

.provider-card { display: flex; align-items: flex-start; gap: 13px; padding: 15px 17px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 11px; background: var(--surface-2); }
.provider-card .p-info { flex: 1; min-width: 0; }
.provider-card .p-name { font-weight: 800; font-size: .93rem; }
.provider-card .p-meta { font-size: .76rem; color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; }
.model-tag { display: inline-flex; align-items: center; gap: 5px; background: var(--surface); border: 1px solid var(--border); padding: 2px 9px; border-radius: 99px; font-size: .73rem; font-weight: 700; margin: 3px 2px; }

/* ---------- مجموعات ---------- */
.group-band {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--bg-soft); padding: 9px 18px; font-size: .85rem; font-weight: 700;
  border-bottom: 1px solid var(--border); position: sticky; top: 0;
}
.group-band.ungrouped { background: var(--surface); color: var(--text-soft); }

/* ---------- اختيار الموديل في المودال ---------- */
.model-picker-item {
  display: flex; align-items: center; gap: 11px; padding: 11px 14px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; margin-bottom: 8px; transition: all var(--transition);
}
.model-picker-item:hover { border-color: var(--primary-soft); }
.model-picker-item.selected { border-color: var(--primary); background: var(--primary-glow); }
.model-picker-item .mp-provider { font-size: .74rem; color: var(--text-soft); }
.radio-dot { width: 17px; height: 17px; border-radius: 50%; border: 2px solid var(--border-strong); flex-shrink: 0; display: grid; place-items: center; }
.model-picker-item.selected .radio-dot { border-color: var(--primary); }
.model-picker-item.selected .radio-dot::after { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }

/* ---------- سمة زر ---------- */
.theme-toggle { background: none; border: 1px solid var(--border-strong); width: 36px; height: 36px; border-radius: 10px; cursor: pointer; display: grid; place-items: center; font-size: 1rem; transition: all var(--transition); }
.theme-toggle:hover { border-color: var(--primary); }

.empty-state { text-align: center; padding: 48px 20px; color: var(--text-soft); }
.empty-state .ico { font-size: 2.4rem; margin-bottom: 10px; opacity: .6; }
.empty-state p { font-weight: 600; }

.fade-in { animation: fadeInUp .35s ease both; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(11px); } }

@media (max-width: 980px) {
  .workers-grid, .stats-grid { grid-template-columns: 1fr; }
  .sidebar { width: 74px; padding: 20px 9px; }
  .sidebar .brand h1, .sidebar .brand small, .nav a span.txt, .user-chip div { display: none; }
  .nav a { justify-content: center; }
  .main { padding: 22px 16px 50px; }
  .form-row { grid-template-columns: 1fr; }
}
