/* ---------------------------------------------------------------------------
 * Reusable components: cards, buttons, badges, tables, modal, toast,
 * timeline, combobox, and the loading / empty / error states.
 * ------------------------------------------------------------------------ */

/* ==================== CARD ==================== */

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.card-header h3 { font-size: var(--fs-md); font-weight: 700; }
.card-header .spacer { flex: 1; }
.card-body { padding: 18px; }
.card-body.tight { padding: 12px; }

.section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: var(--space-4);
  overflow: hidden;
}
.section > h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-base);
  color: var(--text-secondary);
  font-weight: 700;
}
.section > .section-body { padding: 16px; }

/* ==================== STAT CARD ==================== */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.stat-val {
  font-family: var(--font-en);
  font-size: var(--fs-2xl);
  font-weight: 800;
  color: var(--text-heading);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  direction: ltr;
  text-align: start;
}
.stat-label { font-size: var(--fs-sm); color: var(--text-secondary); font-weight: 600; margin-top: 2px; }
.stat.clickable { cursor: pointer; transition: border-color var(--transition), box-shadow var(--transition); }
.stat.clickable:hover { border-color: var(--accent-border); box-shadow: var(--shadow-sm); }

/* ==================== BUTTONS ==================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-base);
  font-weight: 700;
  font-family: var(--font-ar);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

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

.btn-secondary { background: var(--panel); color: var(--text); border-color: var(--input-border); }
.btn-secondary:hover:not(:disabled) { background: var(--panel-2); }

.btn-success { background: var(--success-bg); color: var(--success-fg); border-color: var(--success-border); }
.btn-success:hover:not(:disabled) { background: var(--success); color: #fff; }

.btn-danger { background: var(--danger-bg); color: var(--danger-fg); border-color: var(--danger-border); }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--panel-2); color: var(--text); }

.btn-sm { padding: 5px 11px; font-size: var(--fs-sm); }
.btn-icon { padding: 7px; width: 34px; height: 34px; }

.btn-whatsapp {
  background: var(--success-bg);
  color: var(--success-fg);
  border-color: var(--success-border);
}
.btn-whatsapp:hover:not(:disabled) { background: #d1fae5; }

/* ==================== BADGE ==================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 700;
  border: 1px solid transparent;
  white-space: nowrap;
  line-height: 1.8;
}
.badge-success { background: var(--success-bg); color: var(--success-fg); border-color: var(--success-border); }
.badge-warning { background: var(--warning-bg); color: var(--warning-fg); border-color: var(--warning-border); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger-fg);  border-color: var(--danger-border); }
.badge-info    { background: var(--info-bg);    color: var(--info-fg);    border-color: var(--info-border); }
.badge-purple  { background: var(--purple-bg);  color: var(--purple-fg);  border-color: var(--purple-border); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral-fg); border-color: var(--neutral-border); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-border);
  padding: 2px 9px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-xs);
  font-weight: 700;
}

/* ==================== TOOLBAR / FILTERS ==================== */

.toolbar {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: var(--space-4);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.toolbar .field { margin-bottom: 0; }
.toolbar .grow { flex: 1; min-width: 200px; }
.toolbar .narrow { min-width: 150px; }
.toolbar label { font-size: var(--fs-xs); color: var(--text-secondary); margin-bottom: 4px; }

.search-wrap { position: relative; }
.search-wrap input { padding-inline-start: 34px; }
.search-wrap .icon {
  position: absolute;
  inset-inline-start: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

/* ==================== TABLE ==================== */

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table.data {
  width: 100%;
  border-collapse: collapse;
}
table.data thead th {
  position: sticky;
  top: 0;
  background: var(--panel-2);
  padding: 10px 14px;
  text-align: start;
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  z-index: 1;
}
table.data tbody td {
  padding: 11px 14px;
  font-size: var(--fs-base);
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--panel-2); }
table.data tbody tr.clickable { cursor: pointer; }
table.data tfoot td {
  padding: 10px 14px;
  font-weight: 700;
  background: var(--panel-2);
  border-top: 1px solid var(--border);
}
table.data td.num, table.data th.num { text-align: start; }

.cell-title { font-weight: 700; color: var(--text-heading); }
.cell-sub { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 1px; }
.cell-id {
  font-family: var(--font-en);
  font-weight: 700;
  font-size: var(--fs-sm);
  color: var(--accent);
  direction: ltr;
  display: inline-block;
}

.table-footer {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--panel-2);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}
.table-footer .spacer { flex: 1; }

/* ==================== STATES ==================== */

.state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-secondary);
}
.state .icon-wrap {
  width: 60px;
  height: 60px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  opacity: 0.55;
}
.state .title { font-size: var(--fs-md); font-weight: 700; color: var(--text-secondary); margin-bottom: 4px; }
.state .desc { font-size: var(--fs-base); color: var(--text-muted); max-width: 340px; margin: 0 auto 14px; }
.state.error .icon-wrap { color: var(--danger); opacity: 0.8; }
.state.error .title { color: var(--danger-fg); }

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto;
}
.spinner.sm { width: 15px; height: 15px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, var(--panel-2) 25%, var(--panel-3) 50%, var(--panel-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
  border-radius: var(--radius-sm);
  height: 14px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ==================== ALERT ==================== */

.alert {
  display: flex;
  gap: 10px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-base);
  font-weight: 600;
  border: 1px solid transparent;
  margin-bottom: var(--space-4);
  align-items: flex-start;
}
.alert .icon { flex-shrink: 0; margin-top: 2px; }
.alert ul { margin-top: 6px; }
.alert li { position: relative; padding-inline-start: 14px; font-weight: 500; }
.alert li::before {
  content: '•';
  position: absolute;
  inset-inline-start: 2px;
}
.alert-danger  { background: var(--danger-bg);  color: var(--danger-fg);  border-color: var(--danger-border); }
.alert-warning { background: var(--warning-bg); color: var(--warning-fg); border-color: var(--warning-border); }
.alert-info    { background: var(--info-bg);    color: var(--info-fg);    border-color: var(--info-border); }
.alert-success { background: var(--success-bg); color: var(--success-fg); border-color: var(--success-border); }

/* ==================== MODAL ==================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.18s ease;
}
.modal.wide { max-width: 900px; }
.modal.narrow { max-width: 420px; }
@keyframes modalIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.modal-header h3 { flex: 1; font-size: var(--fs-lg); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: var(--space-2);
  justify-content: flex-start;
  flex-direction: row-reverse;
}

/* ==================== TOAST ==================== */

.toast-stack {
  position: fixed;
  inset-block-end: 20px;
  inset-inline-start: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
  max-width: 400px;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  font-size: var(--fs-base);
  font-weight: 600;
  animation: toastIn 0.2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.toast .icon { flex-shrink: 0; margin-top: 2px; }
/* `pre-line` so a multi-line error (message plus its list of reasons) keeps
   its line breaks instead of running together. */
.toast .msg { flex: 1; white-space: pre-line; }
.toast-success { border-inline-start: 4px solid var(--success); }
.toast-error   { border-inline-start: 4px solid var(--danger); }
.toast-warning { border-inline-start: 4px solid var(--warning); }
.toast-info    { border-inline-start: 4px solid var(--accent); }
.toast-success .icon { color: var(--success); }
.toast-error .icon   { color: var(--danger); }
.toast-warning .icon { color: var(--warning); }
.toast-info .icon    { color: var(--accent); }

/* ==================== TIMELINE ==================== */

.timeline { position: relative; padding-inline-start: 22px; }
.timeline::before {
  content: '';
  position: absolute;
  inset-block: 6px 6px;
  inset-inline-start: 5px;
  width: 2px;
  background: var(--border);
}
.timeline-item { position: relative; padding-bottom: 16px; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-dot {
  position: absolute;
  inset-inline-start: -22px;
  top: 5px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--panel);
  border: 3px solid var(--accent);
}
.timeline-item.done .timeline-dot { border-color: var(--success); }
.timeline-item.danger .timeline-dot { border-color: var(--danger); }
.timeline-item.muted .timeline-dot { border-color: var(--border-strong); }
.timeline-title { font-size: var(--fs-base); font-weight: 700; color: var(--text-heading); }
.timeline-meta {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 1px;
}
.timeline-note { font-size: var(--fs-sm); color: var(--text-secondary); margin-top: 3px; }

/* ==================== COMBOBOX ==================== */

.combobox { position: relative; }
.combobox-list {
  position: absolute;
  inset-inline: 0;
  top: calc(100% + 4px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  max-height: 300px;
  overflow-y: auto;
  z-index: 50;
}
.combobox-item {
  padding: 9px 12px;
  cursor: pointer;
  font-size: var(--fs-base);
  border-bottom: 1px solid var(--border-light);
}
.combobox-item:last-child { border-bottom: none; }
.combobox-item:hover,
.combobox-item.highlight { background: var(--accent-soft); }
.combobox-item .t { font-weight: 700; color: var(--text-heading); }
.combobox-item .s { font-size: var(--fs-xs); color: var(--text-muted); }
.combobox-empty { padding: 14px; text-align: center; color: var(--text-muted); font-size: var(--fs-sm); }

/* ==================== KEY/VALUE LIST ==================== */

.kv { display: grid; gap: 0; }
.kv-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border-light);
}
.kv-row:last-child { border-bottom: none; }
.kv-key { color: var(--text-secondary); font-size: var(--fs-sm); }
.kv-val { color: var(--text-heading); font-size: var(--fs-base); font-weight: 700; text-align: end; }

/* ==================== TABS ==================== */

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-4);
  overflow-x: auto;
}
.tab {
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-ar);
  font-size: var(--fs-base);
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 700; }

/* ==================== PROGRESS BAR (reports) ==================== */

.bar-row { margin-bottom: 11px; }
.bar-top { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; font-size: var(--fs-sm); }
.bar-track { background: var(--border-light); border-radius: 4px; height: 7px; overflow: hidden; }
.bar-fill { height: 7px; border-radius: 4px; background: var(--accent); transition: width 0.5s ease; }

/* ==================== LOGIN ==================== */

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}
.login-page::before,
.login-page::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}
.login-page::before {
  top: -140px;
  inset-inline-end: -140px;
  width: 420px;
  height: 420px;
  background: radial-gradient(circle, rgba(37, 99, 235, 0.09) 0%, transparent 70%);
}
.login-page::after {
  bottom: -100px;
  inset-inline-start: -100px;
  width: 340px;
  height: 340px;
  background: radial-gradient(circle, rgba(37, 99, 235, 0.06) 0%, transparent 70%);
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 42px 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-md);
  text-align: center;
  position: relative;
  z-index: 1;
  animation: modalIn 0.4s ease;
}
.login-mark {
  width: 68px;
  height: 68px;
  border-radius: 18px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  margin: 0 auto 14px;
}
.login-brand {
  font-size: 21px;
  font-weight: 800;
  color: var(--text-heading);
  letter-spacing: 1.5px;
  font-family: var(--font-en);
}
.login-sub { color: var(--text-secondary); font-size: var(--fs-md); font-weight: 600; }
.login-rule { width: 46px; height: 3px; background: var(--accent); border-radius: 2px; margin: 18px auto 26px; }
.login-form { text-align: start; display: flex; flex-direction: column; gap: 16px; }
.login-foot { margin-top: 22px; font-size: 10px; color: var(--text-muted); }

.shake { animation: shake 0.4s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* Inline action buttons inside a table row. Flex keeps them on one line and
   the gap stays symmetric under RTL, unlike a physical margin. */
.row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
}
