/* ==========================================================
   مُوكِّل — Design System v3
   Modern SaaS — Inspired by Stripe, Linear, Notion
   ========================================================== */

/* ============ 1) الألوان ============ */
:root {
  /* Neutral Palette */
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-600: #4B5563;
  --gray-700: #374151;
  --gray-800: #1F2937;
  --gray-900: #111827;

  /* Primary */
  --primary-50: #EEF2FF;
  --primary-100: #E0E7FF;
  --primary-500: #6366F1;
  --primary-600: #4F46E5;
  --primary-700: #4338CA;

  /* Success */
  --success-50: #ECFDF5;
  --success-500: #10B981;
  --success-600: #059669;

  /* Danger */
  --danger-50: #FEF2F2;
  --danger-500: #EF4444;
  --danger-600: #DC2626;

  /* Warning */
  --warning-50: #FFFBEB;
  --warning-500: #F59E0B;
  --warning-600: #D97706;

  /* Semantic Aliases */
  --bg: var(--gray-50);
  --bg-soft: var(--gray-100);
  --surface: #FFFFFF;
  --border: var(--gray-200);
  --border-soft: var(--gray-100);

  --text: var(--gray-900);
  --text-soft: var(--gray-600);
  --text-muted: var(--gray-400);

  --primary: var(--primary-500);
  --primary-hover: var(--primary-600);
  --primary-light: var(--primary-50);

  --success: var(--success-500);
  --success-light: var(--success-50);

  --danger: var(--danger-500);
  --danger-light: var(--danger-50);

  --warning: var(--warning-500);
  --warning-light: var(--warning-50);

  /* ✅ Aliases للتوافق مع الكود القديم */
  --ok: var(--success);
  --bad: var(--danger);
  --ink: var(--text);
  --ink-soft: var(--text-soft);
  --paper: var(--bg);
  --raised: var(--surface);
  --line: var(--border);
  --brass: var(--primary);
  --brass-deep: var(--primary-hover);
  --wa: #25D366;

  /* Shadows */
  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.08), 0 1px 2px -1px rgb(0 0 0 / 0.06);
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-md: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.05);
  --shadow-xl: 0 25px 50px -12px rgb(0 0 0 / 0.15);

  /* Radii */
  --radius-sm: 6px;
  --radius: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --transition-fast: 150ms var(--ease);
  --transition: 200ms var(--ease);
  --transition-slow: 300ms var(--ease);

  /* Typography */
  --font-sans: 'IBM Plex Sans Arabic', 'Cairo', system-ui, -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Menlo', monospace;
}

/* ============ 2) Reset ============ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  font-weight: 500;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  letter-spacing: -0.011em;
}

[hidden] { display: none !important; }

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: var(--primary-hover); }

/* ============ 3) Typography ============ */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.3;
  color: var(--text);
  letter-spacing: -0.02em;
}

h1 { font-size: 28px; font-weight: 800; }
h2 { font-size: 22px; font-weight: 800; }
h3 { font-size: 17px; font-weight: 700; }
h4 { font-size: 15px; font-weight: 700; }
h5 { font-size: 13.5px; font-weight: 700; }

p { line-height: 1.7; }

.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-muted { color: var(--text-muted); }
.text-soft { color: var(--text-soft); }
.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }

.mono {
  font-family: var(--font-mono);
  font-weight: 500;
  letter-spacing: -0.02em;
}

/* ============ 4) Buttons ============ */
button,
.btn,
.button {
  font-family: var(--font-sans) !important;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.01em;
  cursor: pointer;
  border: none;
  background: none;
  transition: all var(--transition);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn,
button.primary,
button.ghost,
button.wa {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-family: var(--font-sans) !important;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: all var(--transition);
}

.btn:active,
button.primary:active,
button.ghost:active {
  transform: scale(0.97);
}

.btn-primary,
button.primary {
  background: var(--primary);
  color: white;
  box-shadow: var(--shadow-xs), 0 1px 2px 0 rgb(99 102 241 / 0.2);
}
.btn-primary:hover,
button.primary:hover {
  background: var(--primary-hover);
  box-shadow: var(--shadow-sm), 0 4px 12px 0 rgb(99 102 241 / 0.3);
  transform: translateY(-1px);
}

.btn-secondary,
button.ghost {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover,
button.ghost:hover {
  background: var(--gray-50);
  border-color: var(--gray-300);
  color: var(--text);
}

.btn-success {
  background: var(--success);
  color: white;
  box-shadow: var(--shadow-xs);
}
.btn-success:hover {
  background: var(--success-600);
  box-shadow: var(--shadow-sm), 0 4px 12px 0 rgb(16 185 129 / 0.3);
  transform: translateY(-1px);
}

.btn-danger {
  background: var(--danger);
  color: white;
  box-shadow: var(--shadow-xs);
}
.btn-danger:hover {
  background: var(--danger-600);
  box-shadow: var(--shadow-sm), 0 4px 12px 0 rgb(239 68 68 / 0.3);
  transform: translateY(-1px);
}

.btn-wa,
button.wa {
  background: #25D366;
  color: white;
  box-shadow: var(--shadow-xs);
}
.btn-wa:hover,
button.wa:hover {
  background: #128C7E;
  box-shadow: var(--shadow-sm), 0 4px 12px 0 rgb(37 211 102 / 0.3);
  transform: translateY(-1px);
}

.btn-sm {
  padding: 7px 12px;
  font-size: 12.5px;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 14px 24px;
  font-size: 15px;
  border-radius: var(--radius-md);
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
}

.btn-block {
  width: 100%;
  display: flex;
  justify-content: center;
}

.btn:disabled,
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* ============ 5) Inputs ============ */
input,
select,
textarea,
.input {
  width: 100%;
  padding: 11px 14px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: all var(--transition-fast);
  letter-spacing: -0.01em;
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--gray-300);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

textarea {
  min-height: 100px;
  resize: vertical;
  line-height: 1.6;
}

/* ============ 6) Cards ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--transition), border-color var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-sm);
  border-color: var(--border);
}

.card h3 {
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 var(--space-4);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  justify-content: space-between;
  align-items: center;
  letter-spacing: -0.01em;
}

/* ============ 7) Badges ============ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.4;
}

.badge.active, .badge-success {
  background: var(--success-50);
  color: var(--success-600);
}

.badge.trial, .badge-warning {
  background: var(--warning-50);
  color: var(--warning-600);
}

.badge.suspended, .badge-danger {
  background: var(--danger-50);
  color: var(--danger-600);
}

.badge-gray, .badge-info {
  background: var(--gray-100);
  color: var(--gray-600);
}

.badge-late {
  display: inline-flex;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11.5px;
  font-weight: 700;
  background: var(--danger-50);
  color: var(--danger-600);
}

/* ============ 8) Stats ============ */
.stat {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  text-align: center;
  box-shadow: var(--shadow-xs);
  transition: all var(--transition);
}

.stat:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
  border-color: var(--border);
}

.stat .n {
  font-size: 26px;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--text);
  line-height: 1.2;
  letter-spacing: -0.03em;
}

.stat .l {
  font-size: 12.5px;
  color: var(--text-soft);
  margin-top: var(--space-2);
  font-weight: 600;
}

/* ============ 9) Items ============ */
.item {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  transition: all var(--transition);
}

.item:hover {
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}

.item .top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.item .name {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.item .num {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--primary);
}

.item .meta {
  font-size: 12.5px;
  color: var(--text-soft);
  margin-top: var(--space-1);
  line-height: 1.6;
}

.item .acts {
  margin-top: var(--space-3);
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ============ 10) Empty ============ */
.empty {
  text-align: center;
  padding: var(--space-12) var(--space-4);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
}

/* ============ 11) Section Header ============ */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border-soft);
  gap: var(--space-3);
}

.section-header h3 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  padding: 0;
  border: none;
  letter-spacing: -0.01em;
}

.section-header button {
  padding: 8px 14px;
  font-size: 12.5px;
}

/* ============ 12) Info Grid ============ */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.info-item {
  padding: var(--space-3) var(--space-4);
  background: var(--gray-50);
  border-radius: var(--radius);
  border: 1px solid var(--border-soft);
}

.info-label {
  font-size: 12px;
  color: var(--text-soft);
  margin-bottom: 4px;
  font-weight: 600;
}

.info-value {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

/* ============ 13) Acts Row ============ */
.acts-row {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-soft);
}

/* ============ 14) Progress ============ */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--gray-100);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin: var(--space-3) 0;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--success));
  border-radius: var(--radius-full);
  transition: width var(--transition-slow);
}

/* ============ 15) Filter Tabs ============ */
.filter-tabs {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
  flex-wrap: wrap;
}

.filter-tabs button {
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-soft);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.filter-tabs button:hover {
  background: var(--gray-50);
  color: var(--text);
  border-color: var(--gray-300);
}

.filter-tabs button.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* ============ 16) Toast ============ */
.toast-host {
  position: fixed;
  top: calc(var(--space-4) + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 420px;
}

.toast {
  background: var(--gray-900);
  color: white;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in 0.25s var(--ease-out);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  letter-spacing: -0.01em;
}

.toast.ok { background: var(--success); }
.toast.bad { background: var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-12px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============ 17) Skeleton ============ */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--gray-100) 0%,
    var(--gray-200) 50%,
    var(--gray-100) 100%
  );
  background-size: 200% 100%;
  animation: sk 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
  height: 16px;
  margin: var(--space-2) 0;
}

@keyframes sk {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============ 18) Modal ============ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  opacity: 0;
  transition: opacity var(--transition);
}

.modal-backdrop.open { opacity: 1; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  transform: translateY(20px) scale(0.96);
  transition: transform var(--transition);
}

.modal-backdrop.open .modal {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5);
  border-bottom: 1px solid var(--border-soft);
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
  padding: 0;
  border: none;
  letter-spacing: -0.01em;
}

.modal-close {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  color: var(--text-soft);
  font-size: 18px;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  background: none;
}

.modal-close:hover {
  background: var(--gray-100);
  color: var(--text);
}

.modal-body {
  padding: var(--space-5);
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border-soft);
}

/* ============ 19) Animations ============ */
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in { animation: fade-in var(--transition-slow); }
.animate-fade-up { animation: fade-up var(--transition-slow); }

/* ============ 20) Scrollbar ============ */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--gray-300);
  border-radius: var(--radius-full);
  border: 2px solid var(--bg);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--gray-400);
}

/* ============ 21) Responsive ============ */
@media (max-width: 640px) {
  h1 { font-size: 22px; }
  h2 { font-size: 19px; }
  h3 { font-size: 16px; }

  .card { padding: var(--space-4); }
  .stat { padding: var(--space-4); }
  .stat .n { font-size: 22px; }
  .info-grid { grid-template-columns: 1fr; }
}