/* ==========================================================================
   نظام — طبقة الموبايل
   بتتحمّل بعد app.css والثيم، وبتخلي كل الشاشات تشتغل بالإصبع على الموبايل
   ========================================================================== */

:root {
  --m-bar-h: 58px;
  --m-safe: env(safe-area-inset-bottom, 0px);
}

/* الشريط السفلي مخفي على الديسكتوب */
.tabbar { display: none; }

/* منع أي خروج أفقي */
html, body { max-width: 100%; overflow-x: hidden; }
.shell { max-width: 100%; }
.main { min-width: 0; width: 100%; }
.content { max-width: 100%; }

/* إخفاء عناصر الديسكتوب على الموبايل */
@media (max-width: 900px) {

  html { -webkit-text-size-adjust: 100%; }
  body {
    padding-bottom: calc(var(--m-bar-h) + var(--m-safe) + 6px);
    overscroll-behavior-y: contain;
  }

  /* ---------- الهيدر ---------- */
  .topbar {
    position: sticky; top: 0; z-index: 60;
    padding: 7px 10px 6px !important;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
    background: var(--bg, #0b0d11);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(8px);
  }
  .topbar .only-mobile { order: 1; }
  .page-head { order: 2; flex: 1 1 auto; min-width: 0; }
  .page-title {
    font-size: 16px !important; margin: 0 !important; line-height: 1.35;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .page-sub { display: none !important; }   /* الشرح الطويل بيكسر الهيدر */
  .topbar-actions {
    order: 3; flex: 1 1 100%;
    gap: 6px; justify-content: space-between;
    overflow-x: auto; padding-top: 3px;
    scrollbar-width: none;
  }
  .topbar-actions::-webkit-scrollbar { display: none; }
  .topbar-actions .btn { flex: 0 0 auto; }
  .topbar .no-edit { display: none !important; }   /* محرر الشكل مش للموبايل */
  .icon-btn { width: 40px; height: 40px; flex: 0 0 40px; }

  /* ---------- المحتوى ---------- */
  .content { padding: 12px 10px 16px !important; }
  .panel { padding: 10px !important; border-radius: 14px; }
  .panel-head h3 { font-size: 13.5px; }
  h2, .h2 { font-size: 17px; }

  /* ---------- الأزرار والحقول ---------- */
  .btn { min-height: 42px; padding: 9px 14px; font-size: 13.5px; }
  .btn.sm { min-height: 38px; font-size: 12.5px; }
  input, select, textarea, .input { font-size: 16px !important; min-height: 42px; }  /* 16px يمنع تكبير iOS */
  .filter-bar { flex-wrap: wrap; gap: 6px; }
  .filter-bar .search { flex: 1 1 100%; }
  .filter-bar .btn { flex: 1 1 auto; }

  /* ---------- الشبكات ---------- */
  .kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important; margin-bottom: 12px !important;
  }
  .kpi { padding: 10px !important; gap: 8px !important; min-height: 0; }
  .kpi-txt strong { font-size: 16px !important; }
  .kpi-txt small { font-size: 10.5px !important; }
  .kpi-ic { width: 34px !important; height: 34px !important; }
  .market-grid { grid-template-columns: 1fr !important; }
  .market-grid > * { min-width: 0 !important; }
  .filter-bar .search { min-width: 0 !important; width: 100% !important; }
  .filter-bar .search input { width: 100% !important; }
  .table-wrap, .panel, .market-grid, section { max-width: 100% !important; }
  .tabbar { display: flex !important; }
  .grid-2, .grid-3, .row2, .kv, .cm { grid-template-columns: 1fr !important; }

  /* ---------- صفحة المناقصة: المحطات تحت بعض ---------- */
  .ws-grid { display: block !important; overflow: visible !important; }
  .ws-col {
    width: 100% !important; flex: none !important;
    max-height: none !important;
    margin-bottom: 10px;
  }
  .ws-chat { max-height: 300px; }

  /* ---------- الجداول تبقى كروت ---------- */
  table.table, table.table-orders {
    display: block; border: 0 !important; background: transparent !important;
    width: 100% !important; table-layout: auto !important;
  }
  table.table thead, table.table-orders thead { display: none !important; }
  table.table tbody, table.table-orders tbody { display: block; }

  table.table tr, table.table-orders tr {
    display: block;
    margin: 0 0 9px;
    border: 1px solid #26313f !important;
    border-radius: 12px;
    overflow: hidden;
    background: #101823 !important;
  }
  table.table tr:hover td, table.table-orders tr:hover td { background: transparent !important; }

  table.table td, table.table-orders td {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: auto !important;
    padding: 8px 11px !important;
    font-size: 13px !important;
    border: 0 !important;
    border-bottom: 1px solid rgba(255, 255, 255, .07) !important;
    background: transparent !important;
    text-align: end;
  }
  table.table td:last-child, table.table-orders td:last-child { border-bottom: 0 !important; }

  table.table td::before, table.table-orders td::before {
    content: attr(data-th);
    flex: 0 0 38%;
    color: #93a5bd;
    font-size: 11.5px;
    font-weight: 700;
    text-align: start;
    white-space: normal;
  }
  table.table td:not([data-th]), table.table-orders td:not([data-th]) { justify-content: flex-end; }
  table.table td[data-th=""]::before { display: none; }

  /* خلية الاسم تبقى عنوان الكارت */
  table.table td:first-child, table.table-orders td:first-child {
    display: block !important;
    background: #16202d !important;
    font-size: 14px !important;
    font-weight: 700;
    padding: 10px 11px !important;
  }
  table.table td:first-child::before, table.table-orders td:first-child::before { display: none; }

  /* الأعمدة الزيادة تتخبى ورا «المزيد» */
  table.table td.m-hide, table.table-orders td.m-hide { display: none !important; }
  tr.m-open td.m-hide { display: flex !important; }
  .m-more {
    display: block; width: 100%;
    background: #16202d; border: 0; border-top: 1px solid rgba(255, 255, 255, .07);
    color: #7dd3fc; font-family: inherit; font-size: 12px; font-weight: 700;
    padding: 9px; cursor: pointer;
  }

  /* ---------- كروت الشهور ---------- */
  .month-block-head { padding: 10px 11px !important; }
  .mb-title { font-size: 13.5px; }

  /* ---------- شريط التنقل السفلي ---------- */
  .tabbar {
    display: flex;
    position: fixed; inset-inline: 0; bottom: 0; z-index: 80;
    height: calc(var(--m-bar-h) + var(--m-safe));
    padding-bottom: var(--m-safe);
    background: rgba(10, 12, 16, .97);
    border-top: 1px solid #1b2735;
    backdrop-filter: blur(12px);
  }
  .tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; color: #7f8ea3; text-decoration: none; font-size: 10px; font-weight: 700;
    padding: 6px 2px; position: relative; -webkit-tap-highlight-color: transparent;
  }
  .tabbar a svg { width: 21px; height: 21px; }
  .tabbar a.is-active { color: #7dd3fc; }
  .tabbar a.is-active::before {
    content: ''; position: absolute; top: 0; inset-inline: 26%;
    height: 2.5px; border-radius: 0 0 3px 3px; background: #7dd3fc;
  }
  .tabbar .tab-badge {
    position: absolute; top: 4px; inset-inline-start: 50%; margin-inline-start: 6px;
    background: #ef4444; color: #fff; font-size: 9px; line-height: 14px;
    min-width: 14px; padding: 0 3px; border-radius: 8px; text-align: center;
  }

  /* غطاء السايدبار */
  .m-overlay {
    display: none; position: fixed; inset: 0; z-index: 89;
    background: rgba(0, 0, 0, .55); backdrop-filter: blur(2px);
  }
  .m-overlay.on { display: block; }
  .sidebar { width: min(84vw, 320px) !important; padding-bottom: 20px; overflow-y: auto; }
  .sidebar .nav-item { padding: 11px 12px !important; font-size: 13.5px; }

  /* عارض الملفات ملء الشاشة */
  .viewer-frame, .viewer-img, .viewer-text, .viewer-docx, .viewer-sheet { max-height: none !important; height: auto !important; }
  .viewer-frame { height: calc(100vh - 150px) !important; }
}


@media (max-width: 900px) {
  /* ---------- صفحة الدخول ---------- */
  .auth-wrap { display: block !important; padding: 12px !important; min-height: 100vh; }
  .auth-side { display: none !important; }
  .auth-card {
    width: 100% !important; max-width: 100% !important;
    padding: 18px 16px !important; border-radius: 18px;
  }
  .auth-brand img { max-height: 70px; width: auto; }
  .auth-card .btn, .auth-card button[type=submit] { width: 100%; }
}

/* شاشات صغيرة جدًا */
@media (max-width: 420px) {
  .page-title { font-size: 15px !important; }
  .content { padding: 10px 8px 16px !important; }
  .table td::before, .table-orders td::before { flex: 0 0 42%; }
}

