/* ============================================================
   المُنظِّم | AL-MUNAZZIM — Components
   مكتبة مكوّنات بصرية عامة يُعاد استخدامها عبر كل الصفحات
   ============================================================ */

/* ---------- الأزرار ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 0.95rem;
  transition: transform var(--duration-fast) var(--ease-standard),
              background-color var(--duration-fast) var(--ease-standard),
              box-shadow var(--duration-fast) var(--ease-standard);
  white-space: nowrap;
}
.btn:active {
  transform: scale(0.97);
}
.btn-primary {
  background: var(--accent-primary);
  color: var(--text-on-accent);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
  background: var(--accent-primary-hover);
  box-shadow: var(--shadow-md);
}
.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1.5px solid var(--border-default);
}
.btn-secondary:hover {
  border-color: var(--accent-primary);
}
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: var(--bg-sunken);
  color: var(--text-primary);
}
.btn-danger {
  background: transparent;
  color: var(--danger);
}
.btn-full {
  width: 100%;
}
.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: var(--radius-full);
}
.btn-icon svg {
  width: 20px;
  height: 20px;
}

/* ---------- حقول الإدخال ---------- */
.form-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.form-row-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}
.form-row label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
}
.form-row input[type="text"],
.form-row input[type="number"],
.form-row input[type="email"],
.form-row select {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-default);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 1rem;
  transition: border-color var(--duration-fast) var(--ease-standard);
}
.form-row input:focus,
.form-row select:focus {
  border-color: var(--accent-primary);
  outline: none;
}
.form-row select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23857a6d' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left var(--space-3) center;
  padding-inline-start: var(--space-10);
}
html[dir="rtl"] .form-row select {
  background-position: left var(--space-3) center;
}
html[dir="ltr"] .form-row select {
  background-position: right var(--space-3) center;
  padding-inline-start: var(--space-4);
  padding-inline-end: var(--space-10);
}

/* ---------- عنصر تحكم مقسّم (Segmented Control) ---------- */
.segmented-control {
  display: grid;
  grid-auto-flow: column;
  background: var(--bg-sunken);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 4px;
}
.segment {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-secondary);
  transition: background-color var(--duration-fast) var(--ease-standard),
              color var(--duration-fast) var(--ease-standard);
}
.segment.active {
  background: var(--bg-elevated);
  color: var(--accent-primary);
  box-shadow: var(--shadow-sm);
}

/* ---------- المفتاح (Toggle Switch) ---------- */
.toggle-switch {
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--stone-300);
  transition: background-color var(--duration-fast) var(--ease-standard);
  flex-shrink: 0;
}
.toggle-switch::after {
  content: '';
  position: absolute;
  top: 3px;
  inset-inline-start: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration-base) var(--ease-out-expo);
}
.toggle-switch.on {
  background: var(--accent-primary);
}
.toggle-switch.on::after {
  transform: translateX(20px);
}
html[dir="rtl"] .toggle-switch.on::after {
  transform: translateX(-20px);
}

/* ---------- البطاقة ---------- */
.card {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-subtle);
}

/* ---------- شارة (Badge) ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-3);
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--olive-100);
  color: var(--olive-700);
}
[data-theme="dark"] .badge {
  background: var(--olive-800);
  color: var(--olive-200);
}
.badge-accent {
  background: var(--copper-100);
  color: var(--copper-700);
}
[data-theme="dark"] .badge-accent {
  background: var(--copper-800);
  color: var(--copper-200);
}

/* ---------- حلقة/مؤشر تقدم دائري ---------- */
.progress-ring {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.progress-ring svg {
  transform: rotate(-90deg);
}
.progress-ring circle {
  fill: none;
  stroke-width: 8;
}
.progress-ring .ring-track {
  stroke: var(--bg-sunken);
}
.progress-ring .ring-fill {
  stroke: var(--accent-primary);
  stroke-linecap: round;
  transition: stroke-dashoffset var(--duration-slow) var(--ease-out-expo);
}
.progress-ring-label {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ---------- مؤشر تقدم خطي (يتماشى مع لغة "الشبكة الهندسية") ---------- */
.progress-bar-track {
  width: 100%;
  height: 8px;
  background: var(--bg-sunken);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent-primary);
  border-radius: var(--radius-full);
  transition: width var(--duration-slow) var(--ease-out-expo);
}
.progress-bar-fill.accent-copper {
  background: var(--accent-secondary);
}

/* ---------- حالة فارغة ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-10) var(--space-5);
  color: var(--text-tertiary);
}
.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: var(--space-3);
  opacity: 0.5;
}
.empty-state p {
  font-size: 0.9rem;
}

/* ---------- عنصر توست (إشعار طافي) ---------- */
.toast-container {
  position: fixed;
  bottom: calc(72px + var(--space-4));
  inset-inline: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  pointer-events: none;
  z-index: 200;
  padding: 0 var(--space-4);
}
.toast {
  background: var(--stone-900);
  color: #fff;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  max-width: 400px;
}
[data-theme="dark"] .toast {
  background: var(--stone-100);
  color: var(--stone-900);
}
.toast-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* ---------- شريحة (Chip) قابلة للإزالة — لعناصر المكونات المضافة للوجبة ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-sunken);
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
}
.chip-remove {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--stone-300);
  flex-shrink: 0;
}
.chip-remove svg {
  width: 10px;
  height: 10px;
}

/* ---------- نافذة منبثقة (Modal/Sheet) ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.4);
  z-index: 300;
  display: flex;
  align-items: flex-end;
}
.sheet {
  background: var(--bg-elevated);
  width: 100%;
  max-height: 85vh;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--space-5);
  padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom));
  overflow-y: auto;
}
.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border-default);
  border-radius: var(--radius-full);
  margin: 0 auto var(--space-4);
}
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}
.sheet-header h3 {
  font-size: 1.1rem;
}

/* ---------- شبكة الأدوات ---------- */
.tool-tile {
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  transition: transform var(--duration-fast) var(--ease-standard),
              box-shadow var(--duration-fast) var(--ease-standard),
              border-color var(--duration-fast) var(--ease-standard);
}
.tool-tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent-primary);
}
.tool-tile-icon {
  width: 36px;
  height: 36px;
  color: var(--accent-primary);
}
.tool-tile-name {
  font-weight: 700;
  font-size: 0.9rem;
}
.tool-tile.disabled {
  opacity: 0.5;
  cursor: default;
}
.tool-tile.disabled:hover {
  transform: none;
  box-shadow: none;
  border-color: var(--border-subtle);
}
