/* ========================================
   ERP Mobile — تصميم من الصفر (≤900px)
   يُحمَّل بعد odoo-theme.css
   ======================================== */

@media (max-width: 900px) {
  :root {
    --m-header: 52px;
    --m-bottom: 60px;
    --m-pad: 12px;
    --m-radius: 12px;
    --m-purple: #714B67;
    --m-teal: #00A09D;
    --m-bg: #f4f4f5;
    --m-card: #ffffff;
  }

  html.erp-odoo,
  body.erp-odoo {
    background: var(--m-bg) !important;
    overflow-x: hidden !important;
  }

  /* ---- إخفاء شريط Odoo الفرعي على الموبايل ---- */
  body.erp-odoo .odoo-subnav {
    display: none !important;
  }

  /* ---- رأس واحد مضغوط ---- */
  body.erp-odoo .odoo-navbar {
    height: var(--m-header) !important;
    padding: 0 8px 0 4px !important;
    gap: 4px !important;
  }

  body.erp-odoo .odoo-nav-apps {
    display: none !important;
  }

  body.erp-odoo .odoo-search {
    display: none !important;
  }

  body.erp-odoo .odoo-brand span:not(.odoo-brand-dot) {
    font-size: 16px;
  }

  body.erp-odoo .odoo-brand-logo {
    width: 24px;
    height: 24px;
  }

  body.erp-odoo .odoo-menu-toggle {
    display: grid !important;
    width: 44px;
    height: 44px;
    place-items: center;
  }

  /* عنوان الصفحة في الوسط */
  body.erp-odoo .odoo-navbar .odoo-mobile-title {
    display: block;
    flex: 1;
    text-align: center;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 4px;
  }

  /* ---- تخطيط الصفحة ---- */
  body.erp-odoo .app-layout {
    padding-top: var(--m-header) !important;
    padding-bottom: calc(var(--m-bottom) + env(safe-area-inset-bottom, 0px)) !important;
    min-height: 100dvh;
    display: block !important;
  }

  body.erp-odoo .main-content {
    margin: 0 !important;
    width: 100% !important;
    min-height: auto !important;
    background: var(--m-bg) !important;
  }

  body.erp-odoo .navbar {
    display: none !important;
  }

  body.erp-odoo .page-content {
    padding: var(--m-pad) !important;
    padding-bottom: 16px !important;
  }

  body.erp-odoo .page-header {
    margin-bottom: 12px !important;
    padding: 0 !important;
    border: 0 !important;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
  }

  body.erp-odoo .page-header h1 {
    font-size: 1.25rem !important;
    font-weight: 700 !important;
    margin: 0;
    flex: 1;
    min-width: 0;
  }

  /* ---- قائمة جانبية = درج كامل ---- */
  body.erp-odoo .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    top: 0 !important;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1100;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s;
  }

  body.erp-odoo .sidebar-overlay.visible,
  body.erp-odoo.sidebar-open .sidebar-overlay {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  body.erp-odoo .sidebar {
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    right: 0 !important;
    left: auto !important;
    width: min(300px, 86vw) !important;
    height: 100% !important;
    max-height: 100dvh !important;
    z-index: 1200 !important;
    transform: translateX(105%) !important;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
    background: #fff !important;
    border: none !important;
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.15) !important;
    padding-bottom: env(safe-area-inset-bottom, 0);
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  body.erp-odoo .sidebar.open,
  body.erp-odoo.sidebar-open .sidebar {
    transform: translateX(0) !important;
  }

  body.erp-odoo .sidebar-header {
    padding: 16px !important;
    padding-top: calc(12px + env(safe-area-inset-top, 0)) !important;
    background: var(--m-purple) !important;
    border: none !important;
  }

  body.erp-odoo .sidebar-header h2,
  body.erp-odoo .sidebar-header span,
  body.erp-odoo .sidebar-header #org-name {
    color: #fff !important;
  }

  body.erp-odoo .nav-item {
    min-height: 48px !important;
    padding: 12px 16px !important;
    margin: 2px 8px !important;
    border-radius: 10px !important;
    font-size: 15px !important;
  }

  body.erp-odoo .nav-item .icon {
    width: 24px;
    height: 24px;
  }

  body.erp-odoo .nav-item .icon svg {
    width: 20px;
    height: 20px;
  }

  /* ---- شريط سفلي ---- */
  .m-bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(var(--m-bottom) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: #fff;
    border-top: 1px solid #e8e8e8;
    z-index: 1000;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.06);
  }

  .m-bottom-nav a,
  .m-bottom-nav button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: 0;
    background: transparent;
    color: #888;
    font-size: 10px;
    font-weight: 600;
    font-family: inherit;
    text-decoration: none;
    padding: 6px 2px;
    min-height: var(--m-bottom);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .m-bottom-nav a svg,
  .m-bottom-nav button svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
  }

  .m-bottom-nav a.active,
  .m-bottom-nav button.active {
    color: var(--m-purple);
  }

  .m-bottom-nav a:active,
  .m-bottom-nav button:active {
    background: #f8f4f6;
  }

  /* ---- بطاقات وإحصائيات ---- */
  body.erp-odoo .stats-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
  }

  body.erp-odoo .stat-card {
    padding: 14px !important;
    border-radius: var(--m-radius) !important;
  }

  body.erp-odoo .stat-card .value {
    font-size: 1.35rem !important;
  }

  body.erp-odoo .stat-card .label {
    font-size: 11px !important;
  }

  body.erp-odoo .card {
    border-radius: var(--m-radius) !important;
    margin-bottom: 12px;
  }

  body.erp-odoo .card-header {
    padding: 12px 14px !important;
  }

  body.erp-odoo .card-body {
    padding: 12px 14px !important;
  }

  body.erp-odoo .rpt-grid,
  body.erp-odoo .dash-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  /* ---- أزرار وحقول لمس ---- */
  body.erp-odoo .btn {
    min-height: 44px !important;
    padding: 10px 16px !important;
    font-size: 14px !important;
    border-radius: 10px !important;
  }

  body.erp-odoo .btn-icon {
    min-width: 44px !important;
    min-height: 44px !important;
    border-radius: 10px !important;
  }

  body.erp-odoo input,
  body.erp-odoo select,
  body.erp-odoo textarea {
    min-height: 44px !important;
    font-size: 16px !important; /* يمنع زوم iOS */
    border-radius: 10px !important;
    padding: 10px 12px !important;
  }

  body.erp-odoo label {
    font-size: 12px !important;
    margin-bottom: 6px !important;
  }

  body.erp-odoo .form-group {
    margin-bottom: 14px;
  }

  body.erp-odoo .tabs {
    overflow-x: auto;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    gap: 0;
    margin-bottom: 12px;
  }

  body.erp-odoo .tab-btn {
    flex-shrink: 0;
    min-height: 44px;
    padding: 10px 16px !important;
    font-size: 14px !important;
  }

  /* ---- جداول: تمرير أفقي واضح ---- */
  body.erp-odoo .table-wrapper {
    margin: 0 calc(-1 * var(--m-pad));
    width: calc(100% + 2 * var(--m-pad));
    max-width: none;
    border-radius: 0;
    border-left: none;
    border-right: none;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: #fff;
  }

  body.erp-odoo .card .table-wrapper {
    margin: 0 -14px;
    width: calc(100% + 28px);
  }

  body.erp-odoo .table-wrapper table {
    min-width: 520px;
    width: max(100%, 520px);
  }

  body.erp-odoo .table-wrapper th,
  body.erp-odoo .table-wrapper td {
    padding: 12px 10px !important;
    font-size: 13px !important;
  }

  body.erp-odoo .table-wrapper td .btn-icon {
    min-width: 40px;
    min-height: 40px;
  }

  /* شريط تلميح التمرير */
  body.erp-odoo .table-wrapper::after {
    content: "↔ اسحب للتمرير";
    display: block;
    text-align: center;
    font-size: 11px;
    color: #999;
    padding: 6px;
    background: #fafafa;
    border-top: 1px solid #eee;
  }

  /* ---- نوافذ منبثقة ---- */
  body.erp-odoo .modal-overlay {
    align-items: flex-end !important;
    padding: 0 !important;
  }

  body.erp-odoo .modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 92dvh !important;
    border-radius: 16px 16px 0 0 !important;
    margin: 0 !important;
  }

  body.erp-odoo .modal-header,
  body.erp-odoo .modal-body,
  body.erp-odoo .modal-footer {
    padding: 14px 16px !important;
  }

  body.erp-odoo .modal-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0)) !important;
  }

  body.erp-odoo .modal-footer .btn {
    flex: 1;
    min-width: 120px;
  }

  /* ---- تحميل ---- */
  body.erp-odoo .ux-loading {
    min-height: 40vh;
  }

  /* إخفاء عناصر سطح المكتب الزائدة */
  body.erp-odoo .win-titlebar,
  body.erp-odoo .win-statusbar {
    display: none !important;
  }
}

/* شاشات صغيرة جداً */
@media (max-width: 400px) {
  body.erp-odoo .stats-grid {
    grid-template-columns: 1fr !important;
  }

  .m-bottom-nav a span,
  .m-bottom-nav button span {
    font-size: 9px;
  }
}

/* سطح المكتب: إخفاء شريط الموبايل */
@media (min-width: 901px) {
  .m-bottom-nav {
    display: none !important;
  }

  body.erp-odoo .odoo-navbar .odoo-mobile-title {
    display: none !important;
  }
}
