/* BabylonCare — تجربة الهاتف (≤ 720px)
 *
 * يُحمَّل بعد styles.css ويغلب قواعده على الشاشات الصغيرة فقط: شريط علوي
 * مضغوط، شريط تنقّل سفلي ثابت بأيقونات، الجداول بطاقات، النوافذ أوراق سفلية،
 * وحقول وأزرار بحجم الإصبع (44px+). لا يمسّ سطح المكتب.
 */
@media (max-width: 720px) {
  :root { --nav-h: 66px; --dock-gap: 10px; --sa-b: env(safe-area-inset-bottom, 0px); --sa-t: env(safe-area-inset-top, 0px); }
  html { -webkit-text-size-adjust: 100%; }
  /* clip لا hidden: overflow-x:hidden على body يكسر position:fixed في سفاري آيفون فيختفي الدوك */
  html, body { overflow-x: clip; max-width: 100%; }
  body { padding-bottom: calc(var(--nav-h) + var(--dock-gap) + var(--sa-b) + 18px); }
  .wrap { width: calc(100% - 20px); }

  /* ───────── الشريط العلوي ───────── */
  /* بلا تمويه على الشريط في الهاتف: backdrop-filter يجعل الشريط مرجعاً للدوك الثابت فيقفز الدوك إلى الأعلى */
  .topbar { padding-top: var(--sa-t); backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(12, 16, 40, .9); }
  .topbar-inner { flex-wrap: nowrap; justify-content: space-between; gap: 8px; padding: 10px 0; }
  .guard-bar { margin-inline-start: auto; }
  .brand { gap: 8px; min-width: 0; }
  .brand-logo { width: 36px; height: 36px; border-radius: 9px; padding: 4px; }
  .brand strong { font-size: 16px; }
  .brand small { display: none; }
  .btn-install { display: none !important; }
  .guard-bar { width: auto; gap: 4px; padding: 3px; order: 2; }
  .guard-tab { padding: 8px 10px; font-size: 0; gap: 0; min-width: 40px; height: 38px; justify-content: center; }
  .guard-tab .tab-ic { display: block; width: 19px; height: 19px; margin: 0; }
  .guard-tab .tab-badge { font-size: 11px; position: absolute; transform: translate(-14px, -12px); }
  .guard-tab { position: relative; }
  .bell-btn { padding: 6px 7px; height: 36px; margin-inline-start: 0; position: relative; font-size: 16px; }
  .guard-tab { min-width: 36px; height: 36px; padding: 6px 8px; }
  .guard-bar { gap: 3px; }
  /* الشاشات الضيقة: الشعار وحده يكفي — الأيقونات صارت ستّاً */
  @media (max-width: 430px) { .brand strong { display: none; } }
  .bell-btn .tab-badge { position: absolute; top: -6px; inset-inline-start: -4px; font-size: 11px; }

  /* ───────── شريط التنقّل السفلي ───────── */
  /* الدوك السفلي: عائم بحواف منحنية كدوك آيفون، زجاج مموّه */
  .tabs {
    position: fixed; inset-inline: var(--dock-gap); bottom: calc(var(--dock-gap) + var(--sa-b)); z-index: 45;
    width: auto; margin: 0; padding: 7px 6px; overflow: visible; flex: none;
    border-radius: 30px; background: rgba(18, 22, 52, .68); border: 1px solid rgba(255,255,255,.18);
    box-shadow: 0 12px 40px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.14);
    backdrop-filter: blur(22px) saturate(170%); -webkit-backdrop-filter: blur(22px) saturate(170%);
    display: flex; gap: 2px; order: 9;
    transform: translateZ(0);   /* طبقة مستقلة: يمنع اختفاء العنصر الثابت المموّه في سفاري */
    animation: dockIn .5s var(--ease-out);
  }
  @keyframes dockIn { from { opacity: 0; } to { opacity: 1; } }
  .tab {
    flex: 1 1 0 !important; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    padding: 6px 2px; border-radius: 22px; color: var(--ink-soft); font-size: 10.5px; font-weight: 700; line-height: 1.15; text-align: center;
    position: relative; min-height: 52px; transition: background .25s var(--ease-out), color .2s, transform .2s var(--ease-spring);
  }
  .tab .tab-ic { display: block; width: 23px; height: 23px; margin: 0; stroke-width: 1.8; transition: transform .3s var(--ease-spring); }
  .tab.is-active .tab-ic { transform: translateY(-1px) scale(1.12); stroke-width: 2.1; }
  .tab:hover { background: transparent; color: var(--ink-soft); }
  .tab.is-active { background: rgba(255,255,255,.16); color: #fff; box-shadow: inset 0 1px 0 rgba(255,255,255,.18); }
  .tab .tab-badge { position: absolute; top: 2px; inset-inline-end: 8px; font-size: 10.5px; min-width: 17px; height: 17px; line-height: 17px; padding: 0 4px; }
  /* أسماء أقصر للأيقونات */
  .tab[data-view=lookup] { font-size: 0; }
  .tab[data-view=lookup]::after { content: 'التحقق'; font-size: 10.5px; }
  .tab[data-view=tracking] { font-size: 0; }
  .tab[data-view=tracking]::after { content: 'المتابعة'; font-size: 10.5px; }
  .tab[data-view=admin] { font-size: 0; }
  .tab[data-view=admin]::after { content: 'الموظفون'; font-size: 10.5px; }
  .tab[data-view=register] { font-size: 0; }
  .tab[data-view=register]::after { content: 'تسجيل'; font-size: 10.5px; }

  /* ───────── البطاقات والنصوص ───────── */
  .card { padding: 16px 14px; border-radius: 14px; }
  .card-head h1 { font-size: 18px; }
  .card-head p { font-size: 13px; margin-bottom: 14px; }
  .head-with-switch { flex-direction: column; align-items: stretch; }
  .head-with-switch > div { flex: none; }
  .btn-switch { width: 100%; justify-content: center; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stages { width: 100%; }
  .brand small { display: none; }
  .stat { padding: 12px; }
  .stat dd { font-size: 22px; }
  .stat dt { font-size: 12px; }

  /* ───────── الحقول والأزرار بحجم الإصبع ───────── */
  input[type=text], input[type=tel], input[type=date], input[type=search], input[type=password], input[type=number], select, textarea, .combo-input {
    font-size: 16px; padding: 13px 14px; min-height: 48px;
  }
  .btn { min-height: 46px; padding: 11px 16px; font-size: 15px; }
  .btn-sm { min-height: 42px; font-size: 14px; }
  .btn-icon { min-height: 42px; padding: 9px 12px; font-size: 13.5px; }
  .chip { min-height: 38px; padding: 8px 12px; }
  .switch { padding: 12px; }
  .switch-track { width: 48px; height: 28px; }
  .switch-track::after { width: 22px; height: 22px; }
  .switch input:checked + .switch-track::after { transform: translateX(-20px); }
  .dial-btn { min-height: 48px; }
  .field > span { font-size: 14px; }

  /* ───────── شريط الأدوات ───────── */
  .toolbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .toolbar > input { width: 100%; min-width: 0; }
  .toolbar .spacer { display: none; }
  .toolbar .btn { width: 100%; justify-content: center; }
  .toolbar .check-all { min-height: 40px; }
  .filters { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; scrollbar-width: none; width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box; }
  .filters::-webkit-scrollbar { display: none; }
  .filters .chip { white-space: nowrap; flex: none; }
  .fee-form { width: 100%; }
  .fee-form input { flex: 1; width: auto; }

  /* ───────── الجداول → بطاقات ───────── */
  .table-scroll { overflow: visible; }
  .table, .table tbody, .table tr, table[id$="-table"] { display: block; width: 100% !important; min-width: 0 !important; }
  .table thead { display: none; }
  .table tr { border: 1px solid var(--line); border-radius: 16px; padding: 12px; margin-bottom: 12px; background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.15), inset 0 1px 0 rgba(255,255,255,.06); transition: border-color .25s, box-shadow .3s var(--ease-out), background .25s; }
  .table td {
    display: block; position: relative; padding: 7px 0 7px 0; padding-inline-start: 32%;
    border: 0; text-align: start; width: auto; min-width: 0; white-space: normal; font-size: 14px; line-height: 1.5;
    border-bottom: 1px dashed var(--line-soft);
  }
  .table td:last-child { border-bottom: 0; }
  .table td::before {
    content: attr(data-label); position: absolute; inset-inline-start: 0; top: 9px; width: 30%;
    font-size: 12px; font-weight: 700; color: var(--ink-soft); line-height: 1.4;
  }
  .table td:not([data-label]) { padding-inline-start: 0; }
  .table td:not([data-label])::before { display: none; }
  .table td code { font-size: 13px; }
  /* خلايا الأرقام: العنوان يمين والرقم بترتيبه الطبيعي */
  .table td[dir=ltr] { text-align: right; }
  .table td[dir=ltr]::before { inset-inline-start: auto; right: 0; }
  .table td[dir=ltr] { padding-inline-start: 0; padding-right: 32%; }
  /* خانة التحديد: صف صغير أعلى البطاقة */
  .table td:first-child:not([data-label]) { padding: 0 0 6px; border-bottom: 1px dashed var(--line-soft); }
  .table td:first-child input[type=checkbox] { width: 22px; height: 22px; }
  /* الأفعال: شبكة أزرار عريضة */
  .table td.row-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px 0 0; }
  .table td.row-actions::before { position: static; width: auto; grid-column: 1 / -1; }
  .table td.empty-cell { padding-inline-start: 0; text-align: center; }

  /* ───────── البطاقة مطويّة افتراضياً: رقم الوصل + الهاتف + العنوان، وتنفتح بالنقر ───────── */
  .table tr { cursor: pointer; padding: 10px 12px; position: relative; }
  .table tr:not(.is-open) td { display: none; }
  .table tr:not(.is-open) td:first-child:not([data-label]),
  .table tr:not(.is-open) td[data-label="رقم الوصل"],
  .table tr:not(.is-open) td[data-label="الطلب"],
  .table tr:not(.is-open) td[data-label="المعرّف"],
  .table tr:not(.is-open) td[data-label="الهاتف"],
  .table tr:not(.is-open) td[data-label="العنوان"],
  .table tr:not(.is-open) td.empty-cell { display: block; }
  /* جداول بلا خلية هاتف مستقلة (المتابعة، الموظفون): نُظهر خلية الزبون لأن الهاتف فيها */
  .table tr:not(.is-open):not(:has(td[data-label="الهاتف"])) td[data-label="الزبون"] { display: block; }
  .table tr:not(.is-open) td { padding: 3px 0; padding-inline-start: 0; border-bottom: 0; }
  .table tr:not(.is-open) td::before { display: none; }
  .table tr:not(.is-open) td[dir=ltr] { padding-right: 0; text-align: right; }
  .table tr:not(.is-open) td[data-label="رقم الوصل"], .table tr:not(.is-open) td[data-label="الطلب"], .table tr:not(.is-open) td[data-label="المعرّف"] { font-weight: 800; }
  .table tr:not(.is-open) td[data-label="العنوان"] { color: var(--ink-soft); font-size: 13px; }
  .table tr:not(.is-open) td[data-label="العنوان"] br { display: none; }
  .table tr:not(.is-open) td[data-label="العنوان"] .loc-badge, .table tr:not(.is-open) td[data-label="العنوان"] .loc-missing { display: none; }
  .table tr:not(.is-open) td:first-child:not([data-label]) { position: absolute; top: 10px; inset-inline-end: 12px; width: auto; padding: 0; border: 0; }
  .table tr:not(.is-open) td:first-child:not([data-label]) + td { padding-inline-end: 34px; }
  .table tr::after { content: '▾'; position: absolute; bottom: 8px; inset-inline-start: 12px; color: var(--ink-faint); font-size: 14px; transition: transform .15s; }
  .table tr:has(.empty-cell)::after { display: none; }
  .table tr:has(.empty-cell) { cursor: default; }
  .table tr.is-open::after { transform: rotate(180deg); }
  .table tr.is-open { border-color: var(--brand); background: rgba(255,255,255,.09); box-shadow: 0 10px 30px rgba(0,0,0,.35), 0 0 0 1px rgba(34,211,238,.25); }
  .table td.row-actions > * { width: 100%; justify-content: center; text-align: center; margin: 0; }
  .table td.row-actions .btn { padding-inline: 8px; }
  .table td.row-actions > span.muted { grid-column: 1 / -1; text-align: center; }
  .table td.row-actions .btn-danger.btn-sm { grid-column: 1 / -1; }
  .table td.empty-cell { justify-content: center; }
  .table td.empty-cell::before { display: none; }
  tr.is-wa { background: var(--ok-bg) !important; }
  tr.is-received { background: var(--ok-bg) !important; }
  tr.is-due { background: var(--gold-bg) !important; }
  .pager { flex-wrap: wrap; justify-content: center; }

  /* ───────── النوافذ: أوراق سفلية ───────── */
  .modal { align-items: flex-end; padding: 0; }
  .modal-box {
    width: 100%; max-width: none; max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px);
    border-radius: 24px 24px 0 0; padding: 18px 16px calc(16px + var(--sa-b)); overflow-y: auto; animation: sheet .42s var(--ease-out);
    background: rgba(23, 27, 58, .96);
  }
  .modal-box::before { content: ''; display: block; width: 44px; height: 5px; border-radius: 5px; background: rgba(255,255,255,.28); margin: -6px auto 12px; }
  .modal-box h2 { font-size: 18px; }
  .modal-foot { position: sticky; bottom: calc(-16px - var(--sa-b)); background: rgba(23, 27, 58, .96); padding: 12px 0 calc(6px + var(--sa-b)); margin: 8px -16px -16px; padding-inline: 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
  .modal-foot .btn { flex: 1 1 45%; justify-content: center; }
  .form-foot { flex-wrap: wrap; }
  .form-foot .btn { width: 100%; justify-content: center; }
  @keyframes sheet { from { transform: translateY(100%); } to { transform: none; } }

  /* ───────── تفاصيل صغيرة ───────── */
  .kv { grid-template-columns: 1fr; }
  .presets { gap: 6px; }
  .presets button { min-height: 38px; }
  .search-row { flex-wrap: wrap; }
  .search-row input { flex: 1 1 100%; }
  .search-row .btn { flex: 1; }
  .mode-box { padding: 14px; }
  .notes-list { max-height: 45vh; }
  .courier-box .toolbar .btn { width: 100%; }
  .foot { padding-bottom: 8px; }
  .offline-banner, .queue-card { margin-top: 10px; }
  .delivery-actions { flex-direction: column; }
  .delivery-actions .btn { width: 100%; justify-content: center; }
  .delivery-actions .spacer { display: none; }
  .route-bar { flex-direction: column; align-items: stretch; }
  .route-bar .btn { width: 100%; justify-content: center; }
}

/* ───────── لوحة المندوب على الهاتف ───────── */
@media (max-width: 720px) {
  .courier-topbar .tabs { position: fixed; }
  .courier-topbar .tab[data-view=fresh]::before { content: '🆕'; }
  .courier-topbar .tab[data-view=active]::before { content: '🚚'; }
  .courier-topbar .tab[data-view=money]::before { content: '💵'; }
  .courier-topbar .tab[data-view=fresh] { font-size: 0; }
  .courier-topbar .tab[data-view=fresh]::after { content: 'جديدة'; font-size: 11px; }
  .courier-topbar .tab[data-view=active] { font-size: 0; }
  .courier-topbar .tab[data-view=active]::after { content: 'قيد التوصيل'; font-size: 11px; }
  .courier-topbar .tab[data-view=money] { font-size: 0; }
  .courier-topbar .tab[data-view=money]::after { content: 'التحصيل'; font-size: 11px; }
  .courier-topbar .guard-bar { background: transparent; padding: 0; }
  .courier-topbar #logout { min-height: 38px; padding: 6px 10px; }
  .ocard { padding: 14px; border-radius: 16px; }
  .ocard-name { font-size: 20px; }
  .ocard-row { font-size: 15px; }
  .ocard-row b { min-width: 64px; }
  .ocard-price { font-size: 24px; }
  .ocard-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .ocard-actions .btn { width: 100%; min-height: 48px; }
  .ocard-actions .btn-primary { grid-column: 1 / -1; }
  .ocard-maps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .ocard-maps a { width: 100%; justify-content: center; text-align: center; padding-inline: 4px; font-size: 13px; }
  .status-opt { min-height: 52px; font-size: 16px; }
  .scard-nums { gap: 10px; }
  .push-bar { flex-direction: column; align-items: stretch; }
  .push-bar .btn { width: 100%; }
}
