/* The dashboard keeps its table layout on larger screens. On phones each row is a card. */
.mi-install[hidden], .mi-install-login[hidden] { display: none !important; }
.mi-install-login { margin: 0 0 10px; }
.mi-install-dialog {
  width: min(390px, calc(100vw - 28px));
  padding: 25px;
  border: 1px solid var(--mi-line);
  border-radius: 18px;
  color: var(--mi-ink);
  background: #fff;
  box-shadow: 0 24px 65px rgba(0,0,0,.18);
  font-family: YekanBakhnum, Tahoma, sans-serif;
  text-align: right;
}
.mi-install-dialog::backdrop { background: rgba(12,28,22,.5); }
.mi-install-dialog h2 { margin: 0 0 8px; font-size: 19px; }
.mi-install-dialog p { margin: 0; color: var(--mi-muted); line-height: 1.9; }
.mi-install-dialog button { min-height: 44px; margin-top: 19px; padding: 0 20px; border: 0; border-radius: 10px; color: #fff; background: var(--mi-green); font: inherit; font-weight: 800; cursor: pointer; }
@media (max-width: 782px) {
  html, body { overflow-x: clip; }
  .mi-app {
    width: 100%;
    margin: 0;
    padding: 0 max(12px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }
  .mi-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    padding: 18px 0 16px;
  }
  .mi-header-brand {
    min-width: 0;
    padding: 18px;
    border: 1px solid #e8e5e7;
    border-radius: 18px;
    background: linear-gradient(135deg, #fff 45%, #fff2f6);
    box-shadow: var(--mi-shadow);
  }
  .mi-header-brand .mi-brand-logo { width: min(255px, 100%); max-height: 65px; }
  .mi-header-brand p { margin-top: 9px; font-size: 11px; line-height: 1.8; }
  .mi-header-actions {
    width: 100%;
    min-width: 0;
    flex-wrap: nowrap !important;
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 1px 0 8px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }
  .mi-header-actions::-webkit-scrollbar, .mi-tabs::-webkit-scrollbar, .mi-quick::-webkit-scrollbar { display: none; }
  .mi-header-actions > * { flex: none; scroll-snap-align: start; }
  .mi-header-actions .mi-user { align-self: center; white-space: nowrap; }
  .mi-sync, .mi-logout { min-height: 44px; white-space: nowrap; }
  .mi-sync span, .mi-live span { display: inline; }
  .mi-live { min-height: 44px; white-space: nowrap; padding-inline: 12px; }
  .mi-toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: end;
    gap: 10px;
    padding: 12px;
  }
  .mi-date-field { min-width: 0; }
  .mi-date-field input { height: 44px; min-width: 0; font-size: 13px; }
  .mi-quick { grid-column: 1 / -1; width: 100%; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .mi-quick button { flex: 1 0 auto; min-height: 44px; padding-inline: 13px; }
  .mi-toolbar .mi-primary { min-width: 0; min-height: 44px; }
  .mi-toolbar .mi-icon-btn { width: 100%; min-height: 44px; }
  .mi-tabs {
    position: sticky;
    top: 0;
    z-index: 35;
    gap: 7px;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    margin: 14px -12px 13px;
    padding: 9px 12px;
    border: 0;
    background: rgba(243, 247, 244, .96);
    backdrop-filter: blur(10px);
  }
  .mi-tabs button {
    flex: none;
    min-height: 44px;
    padding: 8px 15px;
    border: 1px solid var(--mi-line);
    border-radius: 12px;
    background: #fff;
    scroll-snap-align: start;
  }
  .mi-tabs button.active { background: var(--mi-green); border-color: var(--mi-green); color: #fff; }
  .mi-tabs button.active::after { display: none; }
  .mi-grid, .mi-grid-main, .mi-grid-halves { grid-template-columns: minmax(0, 1fr); }
  .mi-card, .mi-kpi, .mi-sub-kpi { min-width: 0; }
  .mi-card-head { gap: 10px; padding: 15px; align-items: flex-start; }
  .mi-card-head > strong { text-align: left; font-size: 14px; }
  .mi-section-head { min-width: 0; }
  .mi-section-head h2 { font-size: 18px; }
  .mi-search { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
  .mi-search input { min-width: 0; }
  .mi-search button, .mi-product-filters button, .mi-fin-filters button, .mi-bi-filters button { min-height: 44px; }
  .mi-sales-chart { padding-inline: 12px; }
  .mi-ranking, .mi-mini-orders, .mi-statuses { padding-inline: 14px; }
  .mi-rank { grid-template-columns: 28px minmax(0, 1fr); }
  .mi-rank > strong { grid-column: 2; white-space: normal; }
  .mi-mini-order { grid-template-columns: auto minmax(0, 1fr); }
  .mi-mini-order > strong { grid-column: 2; }
  .mi-modal-card { width: 100%; height: 100dvh; }
  .mi-modal-card > header { padding: 14px 16px; }
  .mi-modal-body { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
  .mi-toast { left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); max-width: none; }
  .mi-platform-footer { margin-top: 18px; }
  .mi-admin-app .mi-header { padding-top: 20px; }
  .mi-admin-app .mi-header > div:first-child { min-width: 0; }
  .mi-admin-app .mi-header h1 { font-size: 23px; }
  .mi-admin-app .mi-header-actions { justify-content: flex-start; }
  .mi-login-page { padding: 16px; }
  .mi-login-card { border-radius: 19px; padding: 25px 21px; }
  .mi-login-card h1 { font-size: 22px; }
  .mi-settings-preview { padding: 20px; }
}

@media (max-width: 600px) {
  .mi-kpis, .mi-sub-kpis, .mi-fin-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .mi-kpis > :first-child, .mi-sub-kpis > :first-child { grid-column: 1 / -1; }
  .mi-kpi, .mi-sub-kpi { padding: 12px; border-radius: 13px; }
  .mi-kpi strong, .mi-sub-kpi strong { font-size: clamp(15px, 4.2vw, 20px); overflow-wrap: anywhere; }
  .mi-kpi small, .mi-sub-kpi small { font-size: 10px; }
  .mi-kpi footer { flex-wrap: wrap; }
  .mi-customer-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .mi-mobile-table { overflow: visible; }
  .mi-mobile-table table, .mi-mobile-table .mi-products-table, .mi-fin-ledger .mi-mobile-table table {
    display: block;
    width: 100%;
    min-width: 0 !important;
  }
  .mi-mobile-table thead { display: none; }
  .mi-mobile-table .mi-products-table thead:has(input:not([hidden])) { display: block; }
  .mi-mobile-table .mi-products-table thead tr { display: block; }
  .mi-mobile-table .mi-products-table thead th:not(:first-child) { display: none; }
  .mi-mobile-table .mi-products-table thead th:first-child {
    display: flex;
    align-items: center;
    gap: 9px;
    width: auto;
    min-height: 44px;
    padding: 8px 22px;
    text-align: right;
    background: #fff;
  }
  .mi-mobile-table .mi-products-table thead th:first-child::after { content: 'انتخاب همهٔ محصولات صفحه'; }
  .mi-mobile-table tbody { display: grid; gap: 10px; padding: 10px; }
  .mi-mobile-table tbody tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 12px;
    min-width: 0;
    padding: 13px;
    border: 1px solid var(--mi-line);
    border-radius: 13px;
    background: #fff;
    box-shadow: 0 6px 18px rgba(25,55,43,.05);
  }
  .mi-mobile-table tbody td {
    display: block;
    min-width: 0;
    padding: 0;
    border: 0;
    font-size: 12px;
    overflow-wrap: anywhere;
  }
  .mi-mobile-table tbody td::before {
    display: block;
    margin-bottom: 2px;
    color: var(--mi-muted);
    font-size: 10px;
    font-weight: 700;
  }
  .mi-mobile-table tbody td .mi-product { min-width: 0; align-items: flex-start; }
  .mi-mobile-table tbody td .mi-product > div { min-width: 0; }
  .mi-mobile-table tbody td .mi-product b { white-space: normal; overflow-wrap: anywhere; }
  .mi-mobile-table .mi-empty { grid-column: 1 / -1; }
  .mi-mobile-table .mi-empty::before { display: none; }
  .mi-pager { flex-wrap: wrap; }
  #miOrdersBody td:nth-child(1)::before { content: 'سفارش'; }
  #miOrdersBody td:nth-child(2)::before { content: 'تاریخ'; }
  #miOrdersBody td:nth-child(3)::before { content: 'مشتری'; }
  #miOrdersBody td:nth-child(4)::before { content: 'اقلام'; }
  #miOrdersBody td:nth-child(5)::before { content: 'وضعیت'; }
  #miOrdersBody td:nth-child(6)::before { content: 'پرداخت'; }
  #miOrdersBody td:nth-child(7)::before { content: 'مبلغ'; }
  #miOrdersBody tr {
    grid-template-columns: minmax(92px, .7fr) minmax(0, 1.3fr);
    grid-template-areas:
      "order customer"
      "date status"
      "items payment"
      "amount amount";
  }
  #miOrdersBody td:nth-child(1) { grid-area: order; }
  #miOrdersBody td:nth-child(2) { grid-area: date; }
  #miOrdersBody td:nth-child(3) { grid-area: customer; }
  #miOrdersBody td:nth-child(4) { grid-area: items; }
  #miOrdersBody td:nth-child(5) { grid-area: status; }
  #miOrdersBody td:nth-child(6) { grid-area: payment; }
  #miOrdersBody td:nth-child(7) { grid-area: amount; }
  #miOrdersBody td:nth-child(1), #miOrdersBody td:nth-child(3) {
    align-self: stretch;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--mi-line);
  }
  #miOrdersBody td:nth-child(1) .mi-text-button { padding: 0; line-height: 1.6; }
  #miOrdersBody td:nth-child(3) b { line-height: 1.6; }
  #miOrdersBody td:nth-child(3) small { overflow-wrap: anywhere; }
  #miOrdersBody .mi-empty { grid-area: 1 / 1 / -1 / -1; border: 0; }
  #miOrdersBody td:nth-child(7) { padding-top: 8px; border-top: 1px solid var(--mi-line); }
  #miProductsBody tr {
    position: relative;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 14px;
  }
  #miProductsBody td { min-width: 0; overflow-wrap: normal; }
  #miProductsBody td:nth-child(1) {
    position: absolute;
    inset-inline-start: 14px;
    top: 17px;
    width: 20px;
    padding: 0;
    text-align: right;
  }
  #miProductsBody td:nth-child(1)::before, #miProductsBody td:nth-child(2)::before { content: ''; }
  #miProductsBody td:nth-child(2) {
    grid-column: 1 / -1;
    padding: 0 34px 12px 0;
    border-bottom: 1px solid var(--mi-line);
  }
  #miProductsBody tr:not(:has(.mi-product-select)) td:nth-child(1) { display: none; }
  #miProductsBody tr:not(:has(.mi-product-select)) td:nth-child(2) { padding-inline-start: 0; }
  #miProductsBody td:nth-child(2) .mi-product { min-width: 0; }
  #miProductsBody td:nth-child(2) .mi-product-img,
  #miProductsBody td:nth-child(2) .mi-product-placeholder { flex: none; }
  #miProductsBody td:nth-child(3),
  #miProductsBody td:nth-child(4),
  #miProductsBody td:nth-child(7),
  #miProductsBody td:nth-child(10),
  #miProductsBody td:nth-child(11) { grid-column: 1 / -1; }
  #miProductsBody td:nth-child(5), #miProductsBody td:nth-child(8) { grid-column: 1; }
  #miProductsBody td:nth-child(6), #miProductsBody td:nth-child(9) { grid-column: 2; }
  #miProductsBody td:nth-child(3)::before { content: 'دسته و برند'; }
  #miProductsBody td:nth-child(4)::before { content: 'قیمت'; }
  #miProductsBody td:nth-child(5)::before { content: 'تخفیف فعال'; }
  #miProductsBody td:nth-child(6)::before { content: 'زمان ثبت'; }
  #miProductsBody td:nth-child(7)::before { content: 'موجودی'; }
  #miProductsBody td:nth-child(8)::before { content: 'تعداد فروش'; }
  #miProductsBody td:nth-child(9)::before { content: 'سفارش'; }
  #miProductsBody td:nth-child(10)::before { content: 'درآمد بازه'; }
  #miProductsBody td:nth-child(11)::before { content: 'عملیات'; }
  #miProductsBody td:nth-child(n+4):nth-child(-n+10) {
    padding: 9px 11px;
    border: 1px solid var(--mi-line);
    border-radius: 10px;
    background: var(--mi-bg);
  }
  #miProductsBody td:nth-child(n+4):nth-child(-n+10)::before {
    margin-bottom: 4px;
    white-space: nowrap;
  }
  #miProductsBody td:nth-child(5) .mi-badge { white-space: nowrap; }
  #miProductsBody td:nth-child(10) > b { white-space: normal; }
  #miProductsBody td:nth-child(10) > b small { display: inline; margin: 0; font-size: 10px; }
  #miProductsBody .mi-view-price, #miProductsBody .mi-view-stock { min-width: 0; white-space: normal; font-size: 14px; }
  #miProductsBody .mi-quick-pair, #miProductsBody .mi-quick-stock { min-width: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #miProductsBody .mi-quick-pair input, #miProductsBody .mi-quick-stock input, #miProductsBody .mi-quick-stock select { width: 100%; min-width: 0; }
  #miProductsBody .mi-row-actions { min-width: 0; flex-direction: row; flex-wrap: wrap; }
  #miProductsBody .mi-row-actions button { flex: 1 1 auto; min-height: 44px; }
  #miCustomersBody td:nth-child(1) { grid-column: 1 / -1; }
  #miCustomersBody td:nth-child(1)::before { content: 'مشتری'; }
  #miCustomersBody td:nth-child(2)::before { content: 'نوع'; }
  #miCustomersBody td:nth-child(3)::before { content: 'تماس'; }
  #miCustomersBody td:nth-child(4)::before { content: 'سفارش موفق'; }
  #miCustomersBody td:nth-child(5)::before { content: 'کل خرید'; }
  #miCustomersBody td:nth-child(6)::before { content: 'میانگین خرید'; }
  #miCustomersBody td:nth-child(7)::before { content: 'آخرین سفارش'; }
  #miCustomersBody td:nth-child(5) { grid-column: 1 / -1; padding-top: 8px; border-top: 1px solid var(--mi-line); }
  #miFinBody td:nth-child(1)::before { content: 'رویداد'; }
  #miFinBody td:nth-child(2)::before { content: 'تاریخ'; }
  #miFinBody td:nth-child(3)::before { content: 'سفارش و مشتری'; }
  #miFinBody td:nth-child(4)::before { content: 'روش و شناسه'; }
  #miFinBody td:nth-child(5)::before { content: 'فروش ناخالص'; }
  #miFinBody td:nth-child(6)::before { content: 'تخفیف'; }
  #miFinBody td:nth-child(7)::before { content: 'ارسال'; }
  #miFinBody td:nth-child(8)::before { content: 'مالیات'; }
  #miFinBody td:nth-child(9)::before { content: 'مبلغ رویداد'; }
  #miFinBody td:nth-child(3), #miFinBody td:nth-child(4), #miFinBody td:nth-child(9) { grid-column: 1 / -1; }
  #miFinBody td:nth-child(9) { padding-top: 8px; border-top: 1px solid var(--mi-line); }
}

@media (max-width: 360px) {
  .mi-kpis, .mi-sub-kpis, .mi-fin-kpis { grid-template-columns: minmax(0, 1fr); }
  .mi-header-brand .mi-brand-logo { width: min(215px, 100%); }
  .mi-mobile-table tbody { padding: 8px; }
  .mi-mobile-table tbody tr { padding: 11px; }
}
