/* ==========================================================================
   components.css — مكتبة المكوّنات
   كل مكوّن مستقل ولا يعتمد على مكانه في الصفحة.
   ========================================================================== */

/* ---------- البطاقة ---------- */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-5);
}
.card--flat  { border-radius: var(--r-md); padding: var(--s-4); }
.card--quiet { background: var(--surface-2); border-color: transparent; }
.card--link  { transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease); }
.card--link:hover { border-color: var(--line-strong); transform: translateY(-2px); }

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-3); margin-bottom: var(--s-4);
}
.card-title { font-size: var(--fs-md); font-weight: 700; }

/* ---------- العنوان الفرعي (Eyebrow) ---------- */
.eyebrow {
  font-size: var(--fs-xs); font-weight: 600; color: var(--muted);
  letter-spacing: .06em; text-transform: uppercase;
}

/* ---------- الأزرار ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--s-2);
  min-height: 44px;                 /* هدف لمس مريح على الهاتف */
  padding: 0 var(--s-5);
  border-radius: var(--r-md);
  font-size: var(--fs-base); font-weight: 600;
  border: 1px solid transparent;
  transition: background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              transform var(--dur-fast) var(--ease);
  white-space: nowrap;
}
.btn:active { transform: scale(.985); }
.btn[disabled] { opacity: .45; pointer-events: none; }

.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-hover); color: #fff; }

.btn--outline { background: var(--paper); border-color: var(--line-strong); color: var(--ink); }
.btn--outline:hover { border-color: var(--ink); color: var(--ink); }

.btn--ghost { background: transparent; color: var(--muted); }
.btn--ghost:hover { background: var(--surface-2); color: var(--ink); }

.btn--soft { background: var(--accent-soft); color: var(--accent); }
.btn--soft:hover { background: var(--accent-line); color: var(--accent-hover); }

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

.btn--sm  { min-height: 36px; padding: 0 var(--s-3); font-size: var(--fs-sm); }
.btn--lg  { min-height: 52px; padding: 0 var(--s-8); font-size: var(--fs-md); }
.btn--block { width: 100%; }

/* ---------- الشارات ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: var(--r-full);
  font-size: var(--fs-xs); font-weight: 600; line-height: 1.7;
  background: var(--surface-2); color: var(--muted);
  white-space: nowrap;
}
.badge--accent  { background: var(--accent-soft); color: var(--accent); }
.badge--warn    { background: var(--warn-soft);   color: var(--warn); }
.badge--danger  { background: var(--danger-soft); color: var(--danger); }
.badge--solid   { background: var(--ink); color: #fff; }
.badge--outline { background: transparent; border: 1px solid var(--line-strong); }

.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.dot--live {
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(14,107,69,.45);
  animation: livePulse 1.9s infinite;
}
@keyframes livePulse {
  70%  { box-shadow: 0 0 0 8px rgba(14,107,69,0); }
  100% { box-shadow: 0 0 0 0 rgba(14,107,69,0); }
}

/* ---------- الصورة الرمزية ---------- */
.avatar {
  width: 40px; height: 40px; border-radius: var(--r-full); flex: none;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--ink-2);
  font-weight: 700; font-size: var(--fs-sm);
  border: 1px solid var(--line);
}
.avatar--lg { width: 64px; height: 64px; font-size: var(--fs-md); }
.avatar--sm { width: 32px; height: 32px; font-size: var(--fs-xs); }
.avatar--accent { background: var(--accent); color: #fff; border-color: transparent; }

/* ---------- شريط التقدّم ---------- */
.progress {
  height: 6px; background: var(--surface-2);
  border-radius: var(--r-full); overflow: hidden;
}
.progress__bar {
  height: 100%; background: var(--accent);
  border-radius: var(--r-full);
  transition: width .5s var(--ease);
}
.progress--thick { height: 10px; }

/* الحلقة الدائرية للتقدّم */
.ring { position: relative; width: 84px; height: 84px; flex: none; }
.ring svg { transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 7; stroke-linecap: round; }
.ring .ring__track { stroke: var(--surface-2); }
.ring .ring__value { stroke: var(--accent); transition: stroke-dashoffset .7s var(--ease); }
.ring__label {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: var(--font-num); font-weight: 700; font-size: var(--fs-md);
}

/* ---------- الإحصائية ---------- */
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat__value { font-family: var(--font-num); font-size: var(--fs-xl); font-weight: 700; line-height: 1.1; }
.stat__label { font-size: var(--fs-sm); color: var(--muted); }
.stat__delta { font-size: var(--fs-xs); font-weight: 600; }
.stat__delta--up   { color: var(--accent); }
.stat__delta--down { color: var(--danger); }

/* ---------- التبويبات ---------- */
.tabs {
  display: flex; gap: var(--s-1); overflow-x: auto;
  border-bottom: 1px solid var(--line);
  margin-bottom: var(--s-5); scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: var(--s-3) var(--s-4);
  font-size: var(--fs-sm); font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color var(--dur-fast) var(--ease);
  white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--ink); border-bottom-color: var(--accent); }

/* ---------- رقائق الفلترة ---------- */
.chips { display: flex; gap: var(--s-2); overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  padding: 7px var(--s-4); border-radius: var(--r-full);
  border: 1px solid var(--line); background: var(--paper);
  font-size: var(--fs-sm); font-weight: 600; color: var(--muted);
  white-space: nowrap; transition: all var(--dur-fast) var(--ease);
}
.chip:hover { border-color: var(--line-strong); color: var(--ink); }
.chip.is-active { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ---------- الحقول ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--s-4); }
.label { font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); }
.input, .select, .textarea {
  width: 100%; min-height: 44px;
  padding: 10px var(--s-4);
  background: var(--paper);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  transition: border-color var(--dur-fast) var(--ease);
}
.textarea { min-height: 110px; resize: vertical; line-height: 1.7; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); }
.input::placeholder, .textarea::placeholder { color: var(--muted-2); }
.hint { font-size: var(--fs-xs); color: var(--muted); }

/* ---------- الجدول ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--paper); }
.table { width: 100%; border-collapse: collapse; min-width: 560px; }
.table th {
  text-align: right; font-size: var(--fs-xs); font-weight: 600; color: var(--muted);
  padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--line);
  background: var(--surface); white-space: nowrap;
}
.table td { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--line); font-size: var(--fs-sm); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface); }

/* ---------- الحالة الفارغة ---------- */
.empty { text-align: center; padding: var(--s-12) var(--s-4); color: var(--muted); }
.empty__icon { font-size: 30px; margin-bottom: var(--s-3); opacity: .5; }
.empty__title { font-weight: 700; color: var(--ink); margin-bottom: 4px; }

/* ---------- التنبيه المنبثق ---------- */
.toast-host {
  position: fixed; z-index: var(--z-toast);
  bottom: calc(var(--bottomnav-h) + var(--s-4)); inset-inline: var(--s-4);
  display: flex; flex-direction: column; gap: var(--s-2); align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--ink); color: #fff;
  padding: var(--s-3) var(--s-5); border-radius: var(--r-full);
  font-size: var(--fs-sm); font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: riseIn .3s var(--ease);
  max-width: 460px;
}
.toast--accent { background: var(--accent); }
@media (min-width: 900px) {
  .toast-host { bottom: var(--s-6); }
}

/* ---------- النافذة والورقة السفلية ---------- */
.overlay {
  position: fixed; inset: 0; z-index: var(--z-modal);
  background: rgba(11,12,14,.45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn var(--dur) var(--ease);
  backdrop-filter: blur(2px);
}
.sheet {
  background: var(--paper); width: 100%; max-width: 560px;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: var(--s-5); max-height: 88vh; overflow-y: auto;
  animation: sheetUp .3s var(--ease);
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
.sheet__grip {
  width: 38px; height: 4px; background: var(--line-strong);
  border-radius: var(--r-full); margin: 0 auto var(--s-4);
}
@media (min-width: 700px) {
  .overlay { align-items: center; padding: var(--s-4); }
  .sheet { border-radius: var(--r-lg); animation: riseIn .25s var(--ease); }
  .sheet__grip { display: none; }
}

/* ---------- قائمة العناصر ---------- */
.list { display: flex; flex-direction: column; }
.list__item {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) 0; border-bottom: 1px solid var(--line);
  text-align: start; width: 100%;
}
.list__item:last-child { border-bottom: 0; }
.list__item--btn { transition: opacity var(--dur-fast) var(--ease); }
.list__item--btn:hover { opacity: .68; }

/* ---------- شريط اليوم (العنصر المميّز) ---------- */
.rail { position: relative; padding-inline-start: var(--s-6); }
.rail::before {
  content: ""; position: absolute; inset-block: 6px;
  inset-inline-start: 7px; width: 2px; background: var(--line);
}
.rail__item { position: relative; padding-bottom: var(--s-5); }
.rail__item:last-child { padding-bottom: 0; }
.rail__node {
  position: absolute; inset-inline-start: calc(-1 * var(--s-6) + 2px); top: 5px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--paper); border: 2px solid var(--line-strong);
}
.rail__item--done  .rail__node { background: var(--line-strong); border-color: var(--line-strong); }
.rail__item--now   .rail__node { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.rail__time { font-family: var(--font-num); font-size: var(--fs-xs); color: var(--muted); font-weight: 600; }
.rail__title { font-weight: 600; font-size: var(--fs-base); }
.rail__item--done .rail__title { color: var(--muted); }

/* ---------- محادثة المساعد ---------- */
.chat { display: flex; flex-direction: column; gap: var(--s-3); }
.bubble {
  max-width: 84%; padding: var(--s-3) var(--s-4);
  border-radius: var(--r-lg); font-size: var(--fs-base); line-height: 1.8;
  animation: riseIn .25s var(--ease); white-space: pre-wrap;
}
.bubble--ai   { background: var(--surface-2); border-start-start-radius: 4px; align-self: flex-start; }
.bubble--me   { background: var(--accent); color: #fff; border-start-end-radius: 4px; align-self: flex-end; }
.bubble__meta { font-size: var(--fs-xs); color: var(--muted); margin-bottom: 4px; }

.typing { display: inline-flex; gap: 4px; padding: var(--s-3) var(--s-4); }
.typing i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted-2);
  animation: blink 1.3s infinite;
}
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%,60%,100% { opacity: .25; } 30% { opacity: 1; } }

/* ---------- خيارات الأسئلة ---------- */
.option {
  display: flex; align-items: center; gap: var(--s-3);
  width: 100%; text-align: start;
  padding: var(--s-4); margin-bottom: var(--s-2);
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  background: var(--paper);
  transition: all var(--dur-fast) var(--ease);
}
.option:hover { border-color: var(--ink); }
.option__key {
  width: 28px; height: 28px; border-radius: var(--r-sm); flex: none;
  display: grid; place-items: center;
  background: var(--surface-2); font-family: var(--font-num);
  font-size: var(--fs-sm); font-weight: 700;
}
.option.is-picked { border-color: var(--accent); background: var(--accent-soft); }
.option.is-picked .option__key { background: var(--accent); color: #fff; }
.option.is-right  { border-color: var(--accent); background: var(--accent-soft); }
.option.is-wrong  { border-color: var(--danger); background: var(--danger-soft); }

/* ---------- الشبكات ---------- */
.grid { display: grid; gap: var(--s-4); }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 860px) {
  .grid--3, .grid--4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  .grid--3, .grid--4 { grid-template-columns: 1fr 1fr; }
  .grid--2 { grid-template-columns: 1fr; }
  .grid--keep2 { grid-template-columns: 1fr 1fr; }
}

/* ---------- فاصل ---------- */
.divider { height: 1px; background: var(--line); margin: var(--s-5) 0; }
