@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700;800&display=swap');

:root {
  --brand: #0f9d58;
  --brand-dark: #0b7a44;
  --brand-soft: #e6f6ee;
  --accent: #ffb300;
  --ink: #1d2433;
  --muted: #6b7385;
  --line: #e4e7ee;
  --bg: #f4f6fa;
  --card: #ffffff;
  --danger: #e53935;
  --info: #1e88e5;
  --radius: 14px;
  --shadow: 0 4px 18px rgba(20, 30, 60, .07);
}

* { box-sizing: border-box; }
body {
  margin: 0; font-family: 'Cairo', Tahoma, sans-serif; background: var(--bg);
  color: var(--ink); direction: rtl; font-size: 15px;
}
button, input, select, textarea { font-family: inherit; font-size: 15px; }
a { color: var(--brand); }
[hidden] { display: none !important; }

/* ---------- عام */
.topbar {
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; padding: 10px 18px; gap: 10px;
}
.logo { font-weight: 800; font-size: 20px; color: var(--brand); display: flex; align-items: center; gap: 6px; }
.logo small { color: var(--muted); font-weight: 600; font-size: 13px; }
.container { max-width: 1100px; margin: 0 auto; padding: 18px 16px 90px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 14px; }
h1, h2, h3 { margin: 0 0 12px; }
h2 { font-size: 20px; } h3 { font-size: 17px; }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }

.btn {
  border: 0; border-radius: 10px; padding: 10px 16px; cursor: pointer; font-weight: 700;
  background: var(--brand); color: #fff; transition: .15s;
}
.btn:hover { background: var(--brand-dark); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--bg); }
.btn.danger { background: var(--danger); }
.btn.info { background: var(--info); }
.btn.warn { background: var(--accent); color: #332200; }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

label { display: block; font-weight: 600; font-size: 13px; margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
textarea { min-height: 80px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }

.badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; background: var(--bg); }
.st-pending { background: #fff4d6; color: #8a6100; }
.st-requested { background: #fde7f3; color: #a0336e; }
.st-accepted { background: #e3f0fd; color: #1565c0; }
.st-on_way { background: #ede7f6; color: #5e35b1; }
.st-in_progress { background: #e0f7fa; color: #00838f; }
.st-completed { background: var(--brand-soft); color: var(--brand-dark); }
.st-cancelled { background: #fdecea; color: #c62828; }
.st-active { background: var(--brand-soft); color: var(--brand-dark); }
.st-blocked { background: #fdecea; color: #c62828; }

/* ---------- صفحة البداية */
.hero { text-align: center; padding: 40px 16px 10px; }
.hero h1 { font-size: 30px; }
.hero p { color: var(--muted); max-width: 560px; margin: 0 auto 24px; }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; max-width: 720px; margin: 0 auto; }
@media (max-width: 600px) { .choice { grid-template-columns: 1fr; } }
.choice .opt {
  background: var(--card); border: 2px solid var(--line); border-radius: 18px; padding: 26px 18px; cursor: pointer;
  text-align: center; transition: .2s; box-shadow: var(--shadow);
}
.choice .opt:hover { border-color: var(--brand); transform: translateY(-3px); }
.choice .opt .ico { font-size: 46px; }
.choice .opt h3 { margin: 8px 0 4px; }
.auth-box { max-width: 620px; margin: 20px auto; }
.tabs { display: flex; gap: 6px; background: var(--bg); padding: 4px; border-radius: 12px; margin-bottom: 14px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 9px; cursor: pointer; font-weight: 700; color: var(--muted); }
.tabs button.on { background: var(--card); color: var(--brand); box-shadow: var(--shadow); }
.steps { display: flex; gap: 6px; margin-bottom: 14px; }
.steps span { flex: 1; height: 5px; border-radius: 5px; background: var(--line); }
.steps span.on { background: var(--brand); }

/* ---------- صور البطاقة الوطنية */
.id-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.id-drop {
  display: grid; place-items: center; height: 150px; border: 2px dashed var(--line); border-radius: 12px; cursor: pointer;
  background: var(--bg); overflow: hidden; color: var(--muted); text-align: center; font-weight: 600; margin: 0;
}
.id-drop:hover { border-color: var(--brand); }
.id-drop.ok { border-style: solid; border-color: var(--brand); }
.id-drop img { width: 100%; height: 100%; object-fit: cover; }
.id-drop span { font-size: 13px; line-height: 1.8; }
.id-drop span b { font-size: 30px; }
.id-img { width: 100%; max-width: 100%; border-radius: 10px; border: 1px solid var(--line); cursor: zoom-in; display: block; }
.id-grid > .big { grid-column: 1 / -1; }
.id-grid > .big .id-img { cursor: zoom-out; }

/* ---------- تفاصيل المستخدم في الإدارة */
.modal.wide { max-width: 760px; }
.info-sec { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; }
.info-sec h4 { margin: 0 0 8px; font-size: 15px; }
.info-row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; font-size: 14px; border-bottom: 1px dashed var(--line); }
.info-row span { color: var(--muted); white-space: nowrap; }
.info-row b { font-weight: 600; text-align: left; }
.modal-actions { position: sticky; bottom: -20px; background: var(--card); padding: 12px 0; margin-top: 14px; border-top: 1px solid var(--line); }

/* ---------- شريط إشعار التحديث */
#updateBar {
  position: fixed; left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--ink); color: #fff; border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow);
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-weight: 600; font-size: 14px;
}
#updateBar span { flex: 1; min-width: 150px; }
#updateBar .btn.ghost { color: #fff; border-color: #ffffff55; }

/* ---------- تطبيق الهاتف */
html, body { overscroll-behavior-y: none; }
body { -webkit-tap-highlight-color: transparent; }
.topbar { padding-top: max(10px, env(safe-area-inset-top)); }
.bottom-nav { padding-bottom: max(6px, env(safe-area-inset-bottom)); }
.container { padding-bottom: calc(90px + env(safe-area-inset-bottom)); }
/* فوق خياري "أطلب خدمة" و"أقدّم خدمة"، وبنفس عرضهما */
.install-card { border: 1px solid #cdeedb; background: linear-gradient(135deg, #e6f6ee, #ffffff); max-width: 720px; margin: 0 auto 16px; }
@media (display-mode: standalone) { .topbar { box-shadow: 0 1px 0 var(--line); } }

/* ---------- شريط تنبيهات الهاتف (واطئ حتى لا يزاحم الخدمات) */
.push-bar {
  display: flex; align-items: center; gap: 8px; margin-bottom: 12px; padding: 7px 12px;
  border: 1px solid #f3dca6; border-radius: 12px; background: #fff8e8; font-size: 13px;
}
.push-bar.on { border-color: #cdeedb; background: #eef8f2; }
.push-bar .ico { font-size: 16px; flex-shrink: 0; }
.push-bar .txt { flex: 1; min-width: 0; color: var(--muted); line-height: 1.45; }
.push-bar.on .txt { color: var(--text); font-weight: 600; }
.btn.xs { padding: 4px 10px; font-size: 12px; border-radius: 8px; flex-shrink: 0; }

/* ---------- الجلسة المحفوظة + الدعم */
.remember { margin-top: 10px; font-size: 13px; color: var(--brand-dark); font-weight: 700; background: var(--brand-soft); border-radius: 20px; padding: 4px 10px; display: inline-block; }
.thread { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; max-height: 45vh; overflow-y: auto; }
.msg { padding: 10px 12px; border-radius: 12px; max-width: 85%; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.msg.me { background: var(--brand-soft); align-self: flex-start; }
.msg.them { background: var(--bg); border: 1px solid var(--line); align-self: flex-end; }
.msg b { display: block; font-size: 12px; margin-bottom: 2px; }
.msg span { display: block; font-size: 11px; margin-top: 4px; }
.ticket-row { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 10px 0; cursor: pointer; }
.ticket-row:hover { border-color: var(--brand); }
.side .count { position: static; margin-inline-start: 6px; }

/* ---------- تأكيد رقم الهاتف */
.otp-box { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 14px 0; background: var(--bg); }
.otp-ok { color: var(--brand-dark); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-weight: 600; }

/* ---------- المدراء والصلاحيات */
.perm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.perm { margin: 0; font-weight: 600; background: var(--bg); padding: 8px 10px; border-radius: 8px; cursor: pointer; }
@media (max-width: 600px) { .perm-grid { grid-template-columns: 1fr; } }

/* ---------- السيرفر والنشر */
.check-row { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.check-row > span { font-size: 18px; }
.code-wrap { position: relative; margin: 8px 0; }
.code { direction: ltr; text-align: left; background: #0f172a; color: #e2e8f0; padding: 12px; padding-top: 38px; border-radius: 10px;
  overflow-x: auto; font-family: Consolas, 'Courier New', monospace; font-size: 13px; white-space: pre; margin: 0; }
.code-wrap .copy { position: absolute; top: 6px; left: 6px; background: #1e293b; color: #e2e8f0; border-color: #334155; }
.guide { padding-inline-start: 20px; }
.guide li { margin-bottom: 12px; line-height: 1.9; }
details summary { cursor: pointer; margin-top: 10px; }

/* ---------- الإيقافات */
.stop-note { background: #fdecea; color: #8e1c1c; border-radius: 12px; padding: 10px 12px; margin: 10px 0; font-size: 14px; line-height: 1.8; }
.stop-note .muted { color: #a65b5b; }
.cat.stopped { opacity: .75; }

/* ---------- محادثة الطلب */
.chat-thread { min-height: 200px; max-height: 55vh; padding: 4px 2px; }
.chat-form { display: flex; gap: 8px; align-items: flex-end; }
.chat-form textarea { flex: 1; min-height: 44px; max-height: 120px; resize: vertical; margin: 0; }
.chat-badge {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-inline-start: 4px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}
.prov .btn + .btn { margin-inline-start: 6px; }

/* ---------- المساومة على المبلغ */
.price-box {
  margin-top: 10px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid #f3c98a; background: #fff6e8;
}
.price-box.wait { border-color: var(--line); background: var(--bg); color: var(--muted); font-size: 13.5px; }

/* ---------- الموقع الجغرافي */
.loc-box { border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
#locMap { height: 260px; border-radius: 10px; margin-top: 8px; direction: ltr; }

/* ---------- التصنيفات */
.cat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; cursor: pointer;
  text-align: center; transition: .15s;
}
.cat:hover, .cat.on { border-color: var(--brand); background: var(--brand-soft); }
.cat .ico { font-size: 32px; }
.cat b { display: block; margin-top: 4px; }

/* شبكة خدمات الزبون: ثلاثة بكل صف وبحجم أصغر */
.cat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.cat-grid .cat { padding: 10px 6px; border-radius: 14px; }
.cat-grid .cat .ico { font-size: 26px; line-height: 1.2; }
.cat-grid .cat b { margin-top: 2px; font-size: 12.5px; line-height: 1.35; }
@media (max-width: 380px) { .cat-grid { gap: 8px; } .cat-grid .cat b { font-size: 11.5px; } }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 20px; padding: 6px 14px; cursor: pointer; font-weight: 600; font-size: 14px; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }

.svc-pick { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; }
.svc-pick .row > * { flex: 1; min-width: 120px; }

/* ---------- الطلبات */
.order { border-right: 4px solid var(--brand); }
.order .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.order .meta { display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--muted); font-size: 13px; margin: 8px 0; }
.timeline { display: flex; gap: 4px; margin: 10px 0; }
.timeline div { flex: 1; text-align: center; font-size: 11px; color: var(--muted); }
.timeline div::before { content: ''; display: block; height: 5px; border-radius: 4px; background: var(--line); margin-bottom: 4px; }
.timeline div.done { color: var(--brand-dark); font-weight: 700; }
.timeline div.done::before { background: var(--brand); }
.prov { display: flex; gap: 12px; align-items: center; }
.avatar {
  width: 48px; height: 48px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-dark);
  display: grid; place-items: center; font-weight: 800; font-size: 20px; flex-shrink: 0;
}
.stars { color: var(--accent); letter-spacing: 1px; }
.rate-stars span { font-size: 30px; cursor: pointer; color: var(--line); }
.rate-stars span.on { color: var(--accent); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: #bbb; }
.dot.on { background: #2ecc71; box-shadow: 0 0 0 3px #2ecc7133; }

/* ---------- الشريط السفلي */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; background: var(--card); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; padding: 6px 0; z-index: 20;
}
/* أربعة أزرار: الرئيسية/طلباتي/الدعم/حسابي — نضغط الحشو حتى تتسع بالشاشات الضيقة */
.bottom-nav button { border: 0; background: none; cursor: pointer; color: var(--muted); font-weight: 700; font-size: 12px; padding: 4px 6px; position: relative; flex: 1; min-width: 0; }
.bottom-nav button i { display: block; font-style: normal; font-size: 21px; }
.bottom-nav button.on { color: var(--brand); }
.count { position: absolute; top: 0; left: 6px; background: var(--danger); color: #fff; border-radius: 10px; font-size: 10px; padding: 0 5px; }

/* ---------- الإدارة */
.admin-wrap { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 57px); }
.side { background: #16213a; color: #cfd6e6; padding: 14px 10px; }
.side button { display: block; width: 100%; text-align: right; background: none; border: 0; color: inherit; padding: 11px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; }
.side button.on, .side button:hover { background: #24345a; color: #fff; }
.admin-main { padding: 18px; overflow-x: hidden; min-width: 0; }
.admin-main .card, .form-grid > * { min-width: 0; }
@media (max-width: 800px) {
  .admin-wrap { grid-template-columns: 1fr; }
  .side { display: flex; overflow-x: auto; padding: 8px; gap: 4px; }
  .side button { white-space: nowrap; width: auto; }
}
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat b { font-size: 26px; display: block; }
.stat span { color: var(--muted); font-size: 13px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: var(--bg); font-size: 13px; color: var(--muted); }
.bar { height: 10px; background: var(--brand); border-radius: 5px; }

/* ---------- نوافذ وتنبيهات */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 15, 30, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--card); border-radius: 18px; padding: 20px; width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; }
#toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 10px 20px; border-radius: 12px; z-index: 99; font-weight: 600; box-shadow: var(--shadow);
}
#toast.err { background: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* ---------- تدفق التثبيت التلقائي */
.install-flow { position: relative; text-align: center; padding: 60px 20px; min-height: 70vh; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.install-flow h2 { margin: 16px 0 4px; }
.install-flow .spinner { width: 34px; height: 34px; margin-top: 18px; border: 4px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 0.9s linear infinite; }
.install-flow .install-arrow { font-size: 34px; margin-top: 14px; animation: bounce 1.2s ease-in-out infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(10px); } }
.empty .ico { font-size: 42px; }
