/* التصميم المشترك للمنصة: الألوان، الأزرار، الحقول، الجداول، النوافذ */

:root {
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --brand-soft: #e6f4f2;
  --accent: #c2410c;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f5;
  --ink: #15191e;
  --ink-2: #4a5563;
  --muted: #7a8494;
  --line: #e3e6ea;
  --ok: #15803d;   --ok-soft: #e7f6ec;
  --warn: #b45309; --warn-soft: #fdf3e2;
  --bad: #c62828;  --bad-soft: #fdecec;
  --info: #1d4ed8; --info-soft: #e8efff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 2px 8px rgba(16, 24, 40, .05);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, .18);
  --font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, "Noto Sans Arabic", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.3; margin: 0 0 .5em; font-weight: 700; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
.ltr { direction: ltr; unicode-bidi: embed; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.strike { text-decoration: line-through; color: var(--muted); }

/* ------------ تخطيط ------------ */
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.row-end { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }
.stack > * + * { margin-top: 14px; }
.grid { display: grid; gap: 14px; }
.grid-2 { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-3 { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grow { flex: 1; }
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.narrow { max-width: 440px; width: 100%; }

/* ------------ بطاقات ------------ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 14px; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-title h2, .card-title h3 { margin: 0; }

/* ------------ أزرار ------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 16px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font: inherit; font-weight: 600; font-size: .95rem;
  cursor: pointer; text-decoration: none !important; white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-soft { background: var(--brand-soft); color: var(--brand); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-wa { background: #1fa855; color: #fff; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: .85rem; }
.btn-block { width: 100%; }
.btn-icon { min-height: 36px; width: 36px; padding: 0; }
.link-btn { background: none; border: 0; padding: 0; color: var(--brand); font: inherit; cursor: pointer; }
.link-btn.danger { color: var(--bad); }

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  display: inline-block; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* ------------ حقول ------------ */
.field { display: block; }
.field + .field { margin-top: 14px; }
.field > span, .label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.field small, .hint { display: block; color: var(--muted); font-size: .8rem; margin-top: 4px; }
.input, .field input:not([type=checkbox]):not([type=radio]):not([type=file]), .field select, .field textarea, select.input, textarea.input {
  width: 100%; min-height: 44px;
  padding: 9px 12px;
  font: inherit; color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea.input, .field textarea { min-height: 90px; resize: vertical; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
.input-group { display: flex; align-items: stretch; direction: ltr; }
.input-group input { border-radius: var(--radius-sm) 0 0 var(--radius-sm) !important; }
.input-group .addon {
  display: grid; place-items: center; padding: 0 12px;
  background: var(--surface-2); border: 1px solid var(--line); border-inline-start: 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--muted); font-size: .9rem; white-space: nowrap;
}
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; min-height: 40px; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.form-error { color: var(--bad); font-size: .9rem; margin-top: 10px; min-height: 1.2em; }

/* مفتاح تشغيل */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch i { width: 42px; height: 24px; background: #cfd5dc; border-radius: 20px; position: relative; transition: background .2s; flex: none; }
.switch i::after { content: ""; position: absolute; top: 3px; right: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + i { background: var(--brand); }
.switch input:checked + i::after { transform: translateX(-18px); }
.switch input:focus-visible + i { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ------------ شارات ------------ */
.badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-brand { background: var(--brand-soft); color: var(--brand); }
.badge-muted { background: var(--surface-2); color: var(--muted); }

.alert { padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: .92rem; }
.alert-warn { background: var(--warn-soft); color: #7c3a06; }
.alert-bad { background: var(--bad-soft); color: #8e1c1c; }
.alert-info { background: var(--info-soft); color: #1e3a8a; }
.alert-ok { background: var(--ok-soft); color: #14532d; }

/* ------------ جداول ------------ */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: 10px 12px; text-align: start; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .8rem; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: #fafbfc; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty h3 { color: var(--ink); }

/* ------------ نوافذ ------------ */
.modal-wrap {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 20, 25, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 5vh 12px; overflow-y: auto;
  animation: fade .15s;
}
.modal {
  position: relative; width: 100%; max-width: 480px;
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg);
  padding: 22px;
}
.modal-wide { max-width: 760px; }
.modal-x {
  position: absolute; top: 10px; left: 10px; width: 34px; height: 34px;
  border: 0; border-radius: 50%; background: var(--surface-2); font-size: 22px; line-height: 1; cursor: pointer; color: var(--ink-2);
}
.modal h2 { padding-left: 36px; }
.confirm-msg { font-size: 1.02rem; margin: 6px 0 0; }
@keyframes fade { from { opacity: 0; } }

/* ------------ تنبيهات ------------ */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: grid; gap: 8px; width: max-content; max-width: calc(100vw - 32px); }
.toast { padding: 11px 18px; border-radius: 10px; color: #fff; background: #1f2937; box-shadow: var(--shadow-lg); font-weight: 500; text-align: center; transition: opacity .3s, transform .3s; }
.toast-ok { background: #166534; }
.toast-bad { background: #b91c1c; }
.toast-warn { background: #92400e; }
.toast.out { opacity: 0; transform: translateY(8px); }

/* ------------ رفع الصور ------------ */
.uploader { display: flex; flex-wrap: wrap; gap: 10px; }
.uploader .thumb {
  position: relative; width: 92px; height: 92px; border-radius: 10px; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--line);
}
.uploader .thumb img { width: 100%; height: 100%; object-fit: cover; }
.uploader .thumb button {
  position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; font-size: 15px; line-height: 1;
}
.uploader .thumb .main-tag { position: absolute; bottom: 0; inset-inline: 0; background: rgba(0,0,0,.55); color: #fff; font-size: .7rem; text-align: center; }
.uploader label.add {
  width: 92px; height: 92px; border-radius: 10px; border: 2px dashed var(--line);
  display: grid; place-items: center; cursor: pointer; color: var(--muted); font-size: .8rem; text-align: center;
}
.uploader label.add:hover { border-color: var(--brand); color: var(--brand); }
.uploader input[type=file] { display: none; }

/* ------------ متفرقات ------------ */
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: .82rem; font-weight: 500; margin: 0; }
.kpi .value { font-size: 1.45rem; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi.warn .value { color: var(--warn); }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 7px 14px; border-radius: 20px; background: var(--surface); border: 1px solid var(--line); cursor: pointer; white-space: nowrap; font: inherit; font-size: .88rem; color: var(--ink-2); }
.tab.active { background: var(--ink); border-color: var(--ink); color: #fff; }

.copy-box { display: flex; gap: 8px; align-items: center; background: var(--surface-2); border-radius: var(--radius-sm); padding: 6px 6px 6px 12px; }
.copy-box code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; text-align: left; font-size: .9rem; }

.logo-mark { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.2rem; color: var(--ink); text-decoration: none !important; }
.logo-mark svg { width: 30px; height: 30px; }

@media (max-width: 640px) {
  body { font-size: 15px; }
  .card { padding: 14px; }
  .modal { padding: 18px; }
}
@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
}
