/* ============================================================
   نظام تصميم مطابق لمنصة إعارة (موظفات واتساب)
   الألوان والحواف والخط مأخوذة من التطبيق المرجعي.
   ============================================================ */

:root {
  --color-primary: #2b3691;
  --color-primary-dark: #1f2870;
  --color-primary-light: #eef0fb;
  --color-accent: #6fa23a;
  --color-accent-light: #8ab24d;
  --color-accent-soft: #f5f9ee;
  --color-whatsapp: #25d366;

  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;

  --red-50: #fef2f2;
  --red-200: #fecaca;
  --red-600: #dc2626;
  --red-700: #b91c1c;
  --red-800: #991b1b;

  --amber-50: #fffbeb;
  --amber-200: #fde68a;
  --amber-700: #b45309;
  --amber-800: #92400e;

  --emerald-50: #ecfdf5;
  --emerald-200: #a7f3d0;
  --emerald-600: #059669;
  --emerald-700: #047857;

  --radius-card: 0.75rem;
  --radius-control: 0.375rem;
  --radius-lg: 0.5rem;

  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.12), 0 2px 4px -2px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--slate-50);
  color: var(--slate-900);
  font-family: Cairo, "Cairo Fallback", "Segoe UI", Tahoma, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }

.muted { color: var(--slate-500); }
.small { font-size: 0.8125rem; }
.tiny { font-size: 0.75rem; }

button {
  font-family: inherit;
  cursor: pointer;
}

textarea, input {
  font-family: inherit;
}

/* ---------- Header ---------- */
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--slate-200);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-badge {
  width: 38px;
  height: 38px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary-light);
  border-radius: var(--radius-lg);
  font-size: 20px;
}

.brand h1 {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--slate-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand p {
  font-size: 0.75rem;
  color: var(--slate-500);
  white-space: nowrap;
}

/* ---------- Layout ---------- */
.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px;
}

.groups-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 640px) {
  .groups-grid { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 1024px) {
  .groups-grid { grid-template-columns: 1fr 1fr 1fr; }
}

/* ---------- Card ---------- */
.card {
  background: #fff;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}

.group-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.group-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.group-card-head h2 {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--slate-900);
}

.group-card-meta { display: flex; flex-direction: column; gap: 2px; margin-bottom: 4px; }

.group-card-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0 10px;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
}

.badge-primary { background: var(--color-primary-light); color: var(--color-primary); }
.badge-slate { background: var(--slate-100); color: var(--slate-600); }
.badge-success { background: var(--emerald-50); color: var(--emerald-700); border: 1px solid var(--emerald-200); }
.badge-warning { background: var(--amber-50); color: var(--amber-700); border: 1px solid var(--amber-200); }
.badge-idle { background: var(--slate-100); color: var(--slate-500); }
.badge-whatsapp { background: #e9fbf0; color: #148a3d; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--radius-control);
  padding: 10px 18px;
  font-size: 0.9375rem;
  font-weight: 600;
  border: 1px solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  min-height: 42px;
}

.btn-block { width: 100%; }

.btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}
.btn-primary:hover { background: var(--color-primary-dark); border-color: var(--color-primary-dark); }
.btn-primary:disabled { background: var(--slate-300); border-color: var(--slate-300); color: var(--slate-500); cursor: not-allowed; }

.btn-outline {
  background: #fff;
  border-color: var(--slate-300);
  color: var(--slate-700);
}
.btn-outline:hover { background: var(--slate-50); border-color: var(--slate-400); }
.btn-outline:disabled { color: var(--slate-400); cursor: not-allowed; }

.btn-danger-outline {
  background: #fff;
  border-color: var(--red-200);
  color: var(--red-700);
}
.btn-danger-outline:hover { background: var(--red-50); }

.btn-sm { padding: 6px 12px; font-size: 0.8125rem; min-height: 34px; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--slate-500);
  font-size: 1.375rem;
  line-height: 1;
  padding: 6px;
  border-radius: var(--radius-control);
}
.icon-btn:hover { background: var(--slate-100); color: var(--slate-700); }

.link-btn {
  background: none;
  border: none;
  color: var(--color-primary);
  font-weight: 600;
  font-size: 0.875rem;
  padding: 6px 2px;
}
.link-btn:hover { text-decoration: underline; }

/* ---------- Inputs ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }

.field label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--slate-700);
}

.field input[type="text"],
.field textarea {
  background: #fff;
  border: 1px solid var(--slate-300);
  border-radius: var(--radius-control);
  padding: 8px 12px;
  font-size: 0.875rem;
  color: var(--slate-900);
  width: 100%;
}

.field input[type="text"]:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

textarea.import-textarea {
  min-height: 260px;
  resize: vertical;
  font-family: ui-monospace, "Cairo", monospace;
  font-size: 0.8125rem;
  line-height: 1.6;
  direction: rtl;
}

/* ---------- Alerts ---------- */
.alert {
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  font-size: 0.8125rem;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.alert-success { background: var(--emerald-50); color: var(--emerald-700); border: 1px solid var(--emerald-200); }
.alert-warning { background: var(--amber-50); color: var(--amber-800); border: 1px solid var(--amber-200); }
.alert-danger { background: var(--red-50); color: var(--red-800); border: 1px solid var(--red-200); }
.alert-info { background: var(--color-primary-light); color: var(--color-primary-dark); border: 1px solid #d7dbf5; }

/* ---------- Modal / Drawer ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 0;
}

@media (min-width: 640px) {
  .overlay { align-items: center; padding: 20px; }
}

.modal-panel {
  background: #fff;
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow-md);
  padding: 18px 16px 24px;
}

@media (min-width: 640px) {
  .modal-panel { border-radius: var(--radius-card); padding: 22px; }
}

.modal-panel.modal-sm { max-width: 420px; }

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--slate-100);
}

.modal-head h2 { font-size: 1.125rem; font-weight: 700; }

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

/* ---------- Group detail ---------- */
.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

@media (min-width: 480px) {
  .action-grid { grid-template-columns: repeat(4, 1fr); }
}

.action-grid .btn { font-size: 0.8125rem; padding: 10px 8px; white-space: nowrap; }

.members-list {
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--slate-100);
  background: #fff;
}
.member-row:last-child { border-bottom: none; }
.member-row.is-read { background: var(--emerald-50); }

.member-part {
  flex: none;
  min-width: 34px;
  text-align: center;
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--color-primary);
  background: var(--color-primary-light);
  border-radius: var(--radius-control);
  padding: 3px 4px;
}

.member-name {
  flex: 1;
  font-size: 0.9375rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-toggle {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--slate-200);
  background: var(--slate-50);
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.status-toggle.done {
  background: var(--emerald-50);
  border-color: var(--emerald-200);
}

/* ---------- Settings ---------- */
.settings-panel {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--slate-200);
}

.settings-section-title {
  font-size: 0.9375rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.member-edit-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.member-edit-row .order-badge {
  flex: none;
  min-width: 30px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--slate-500);
  font-weight: 600;
}

.member-edit-row input[type="text"] {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--slate-300);
  border-radius: var(--radius-control);
  padding: 7px 10px;
  font-size: 0.875rem;
}

.reorder-btns { display: flex; flex-direction: column; gap: 1px; }
.reorder-btns button {
  background: var(--slate-100);
  border: none;
  width: 22px;
  height: 16px;
  font-size: 0.625rem;
  color: var(--slate-600);
  line-height: 1;
}
.reorder-btns button:first-child { border-radius: 4px 4px 0 0; }
.reorder-btns button:last-child { border-radius: 0 0 4px 4px; }

/* ---------- Import preview ---------- */
.import-result-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--slate-200);
  margin-bottom: 8px;
  font-size: 0.8125rem;
}
.import-result-item.ok { border-color: var(--emerald-200); background: var(--emerald-50); }
.import-result-item.bad { border-color: var(--red-200); background: var(--red-50); }

.import-result-item .title { font-weight: 700; margin-bottom: 4px; }
.import-result-item ul { margin: 4px 0 0; padding-inline-start: 18px; }

/* ---------- Confirm dialog ---------- */
.confirm-message { font-size: 0.9375rem; color: var(--slate-700); margin-bottom: 4px; }
.confirm-sub { font-size: 0.8125rem; color: var(--slate-500); margin-top: 6px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--slate-900);
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 6px;
}

.toast[hidden] { display: none; }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--slate-500);
}

.hidden { display: none !important; }

.warn-banner {
  margin-bottom: 12px;
}
