/* EliteScript Admin — mobile-first layout (مرتب 100%) */

:root {
  --mob-top: 52px;
  --mob-bottom: 58px;
  --mob-pad: 1rem;
}

/* منع التمدد العرضي العشوائي */
html {
  -webkit-text-size-adjust: 100%;
}

body.admin-app {
  overflow-x: hidden;
  max-width: 100vw;
}

/* تخطيط عمودي للجوال فقط — انظر @media 768px */

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.layout-stack {
  align-items: stretch;
}

/* ── شريط علوي ── */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--mob-top);
  padding: 0 0.75rem;
  padding-top: env(safe-area-inset-top, 0);
  align-items: center;
  gap: 0.65rem;
  background: linear-gradient(180deg, #4a443e 0%, #1b1816 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 300;
  box-shadow: 0 4px 16px rgba(27, 24, 22, 0.22);
}

.mob-menu-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  color: #f5f0ea;
  font-size: 1.2rem;
  cursor: pointer;
  flex-shrink: 0;
}

.mob-title {
  flex: 1;
  min-width: 0;
  font-size: 0.92rem;
  font-weight: 800;
  color: #f5f0ea;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(27, 24, 22, 0.6);
  backdrop-filter: blur(3px);
  z-index: 250;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.sidebar-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding-bottom: env(safe-area-inset-bottom, 0);
  background: #1b1816;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 300;
  grid-template-columns: repeat(4, 1fr);
  box-shadow: 0 -6px 20px rgba(27, 24, 22, 0.3);
}

.mob-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 0.45rem 0.2rem;
  min-height: var(--mob-bottom);
  border: none;
  background: none;
  color: rgba(245, 240, 234, 0.5);
  font-family: 'Tajawal', sans-serif;
  font-size: 0.6rem;
  font-weight: 700;
  cursor: pointer;
}

.mob-nav-btn svg {
  width: 21px;
  height: 21px;
}

.mob-nav-btn.on {
  color: #f5f0ea;
}

/* المحتوى الرئيسي */
body.admin-app #app.is-active .main {
  flex: 1;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.page {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.page > * {
  max-width: 100%;
}

.card {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.card:last-child {
  margin-bottom: 0;
}

/* أشرطة أدوات */
.toolbar-wrap,
.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
  margin-bottom: 1rem;
}

.toolbar-wrap .search-wrap,
.toolbar-row .search-wrap {
  flex: 1 1 200px;
  min-width: 0;
  margin: 0;
}

.toolbar-wrap select,
.toolbar-row select {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
}

.add-client-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.add-client-bar .btn {
  flex: 1 1 auto;
}

.add-client-bar #newCodeDisplay {
  flex: 1 1 100%;
  text-align: center;
  word-break: break-all;
}

.sales-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.sales-stats .card {
  margin-bottom: 0;
  text-align: center;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--rs);
}

/* سلة */
.salla-guide {
  font-size: 0.8rem;
  line-height: 1.65;
  color: var(--text2);
}

.salla-guide h4 {
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--text);
  margin: 1rem 0 0.4rem;
}

.salla-guide h4:first-child {
  margin-top: 0;
}

.salla-guide ul {
  margin: 0.35rem 0 0.5rem;
  padding-right: 1.1rem;
}

.salla-url-box {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.65rem 0;
}

.salla-url-box code {
  padding: 0.65rem 0.75rem;
  background: var(--bg);
  border: 1.5px solid var(--brd);
  border-radius: var(--rs);
  font-size: 0.68rem;
  word-break: break-all;
  direction: ltr;
  text-align: left;
}

.salla-url-box .btn {
  width: 100%;
}

.salla-tag {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  margin: 0.2rem 0 0.2rem 0.2rem;
  border-radius: 2rem;
  font-size: 0.67rem;
  font-weight: 700;
  background: var(--bg);
  border: 1px solid var(--brd);
  font-family: 'IBM Plex Mono', monospace;
}

.salla-warn,
.salla-ok {
  padding: 0.65rem 0.85rem;
  border-radius: var(--rs);
  font-size: 0.75rem;
  margin-top: 0.65rem;
}

.salla-warn {
  background: var(--warnB);
  color: var(--warn);
}

.salla-ok {
  background: var(--okB);
  color: var(--ok);
}

.sidebar .user-name {
  color: #f5f0ea !important;
}

/* ═══════════════════════════════════════
   جداول → بطاقات على الجوال
   ═══════════════════════════════════════ */
@media (max-width: 768px) {
  .mobile-topbar {
    display: flex;
  }

  .mobile-bottom-nav {
    display: grid;
  }

  body.admin-app #app.is-active {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    padding-top: calc(var(--mob-top) + env(safe-area-inset-top, 0));
    padding-bottom: calc(var(--mob-bottom) + env(safe-area-inset-bottom, 0));
  }

  body.admin-app .sidebar {
    top: calc(var(--mob-top) + env(safe-area-inset-top, 0));
    height: calc(100dvh - var(--mob-top) - env(safe-area-inset-top, 0));
    width: min(300px, 92vw);
    right: -105%;
    z-index: 280;
    padding-top: 1rem;
    box-shadow: -16px 0 48px rgba(0, 0, 0, 0.4);
  }

  body.admin-app .sidebar.open {
    right: 0;
  }

  .sidebar-backdrop {
    display: block;
  }

  body.admin-app #app.is-active .main {
    margin-right: 0 !important;
    padding: var(--mob-pad);
    padding-bottom: 0.5rem;
  }

  /* عنوان الصفحة داخل الشريط العلوي */
  .page-hdr {
    display: none;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
    margin-bottom: 1rem;
  }

  .stat-card {
    padding: 0.9rem;
  }

  .stat-card:hover {
    transform: none;
  }

  .stat-val {
    font-size: 1.45rem;
    -webkit-text-fill-color: var(--text);
    background: none;
  }

  .grid-2,
  .row2,
  .row3 {
    grid-template-columns: 1fr !important;
    gap: 0;
  }

  .grid-2 > .card,
  .layout-stack > .card {
    margin-bottom: 0.75rem;
  }

  .card {
    padding: 1rem;
    margin-bottom: 0.85rem;
  }

  .card h3 {
    font-size: 0.88rem;
    margin-bottom: 0.85rem;
    flex-wrap: wrap;
  }

  .form-group {
    margin-bottom: 0.75rem;
  }

  input,
  textarea,
  select,
  .btn,
  .btn-login {
    font-size: 16px; /* يمنع zoom iOS */
    min-height: 44px;
  }

  .btn-sm {
    min-height: 40px;
    padding: 0.45rem 0.65rem;
  }

  .toolbar-wrap,
  .toolbar-row {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-wrap .search-wrap,
  .toolbar-row .search-wrap,
  .toolbar-wrap select,
  .toolbar-row select,
  .toolbar-wrap .btn,
  .toolbar-row .btn {
    width: 100%;
    flex: none;
  }

  .add-client-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .add-client-bar .btn,
  .add-client-bar #copyCodeBtn {
    width: 100%;
    justify-content: center;
  }

  .sales-stats {
    grid-template-columns: 1fr;
  }

  .toggle-wrap {
    flex-wrap: wrap;
  }

  .info-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
  }

  .info-row .val {
    word-break: break-word;
    max-width: 100%;
  }

  .act-item {
    flex-direction: column;
    gap: 0.25rem;
  }

  .act-time {
    margin-right: 0;
  }

  .code-val {
    font-size: 1.35rem;
    letter-spacing: 3px;
  }

  /* Toast فوق الشريط السفلي */
  body.admin-app .toast {
    bottom: calc(var(--mob-bottom) + 12px + env(safe-area-inset-bottom, 0));
    white-space: normal;
    max-width: calc(100vw - 2rem);
    text-align: center;
  }

  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal-box {
    width: 100%;
    max-width: 100%;
    max-height: 92dvh;
    border-radius: var(--rl) var(--rl) 0 0;
    margin: 0;
  }

  .modal-footer {
    flex-direction: column;
  }

  .modal-footer .btn {
    width: 100%;
    justify-content: center;
  }

  /* جدول عادي (سكريبتات) — تمرير أفقي فقط */
  .table-scroll-only .table-wrap {
    margin: 0 -0.25rem;
  }

  .table-scroll-only table {
    min-width: 520px;
  }

  /* جدول بطاقات */
  .table-mobile-cards {
    min-width: 0 !important;
  }

  .table-mobile-cards thead {
    display: none;
  }

  .table-mobile-cards tbody tr.client-row,
  .table-mobile-cards tbody tr.sale-row {
    display: block;
    background: var(--bg);
    border: 1px solid var(--brd);
    border-radius: var(--r);
    margin-bottom: 0.7rem;
    padding: 0;
    overflow: hidden;
  }

  .table-mobile-cards tbody tr.client-row:hover td,
  .table-mobile-cards tbody tr.sale-row:hover td {
    background: transparent;
  }

  .table-mobile-cards tbody td {
    display: grid;
    grid-template-columns: 5.8rem 1fr;
    gap: 0.25rem 0.65rem;
    align-items: start;
    padding: 0.5rem 0.85rem;
    border-bottom: 1px solid var(--brd);
    font-size: 0.8rem;
    min-width: 0;
  }

  .table-mobile-cards tbody td:last-child {
    border-bottom: none;
  }

  .table-mobile-cards tbody td::before {
    content: attr(data-label);
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--ink3);
    font-family: 'IBM Plex Mono', monospace;
    text-transform: uppercase;
    letter-spacing: 0.02em;
  }

  .table-mobile-cards tbody td.td-actions {
    display: block;
    padding: 0.65rem 0.85rem 0.85rem;
    background: rgba(27, 24, 22, 0.04);
  }

  .table-mobile-cards tbody td.td-actions::before {
    content: 'إجراءات';
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--ink3);
    font-family: 'IBM Plex Mono', monospace;
  }

  .table-mobile-cards .cell-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
  }

  .table-mobile-cards .cell-actions .btn {
    width: 100%;
    justify-content: center;
    margin: 0 !important;
    padding: 0.5rem 0.35rem !important;
    font-size: 0.72rem !important;
  }

  .table-mobile-cards tbody tr.tr-empty td {
    display: block;
    text-align: center;
    padding: 2rem 1rem;
    grid-template-columns: 1fr;
    color: var(--ink3);
  }

  .table-mobile-cards tbody tr.tr-empty td::before {
    display: none;
  }
}

@media (max-width: 420px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .table-mobile-cards .cell-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1024px) and (min-width: 769px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .main {
    padding: 1.35rem 1.15rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar {
    transition: none;
  }
}
