/* =====================================================================
   App-like look on phones and tablets (loaded after app.css).
   Everything is inside a max-width query: the computer screen layout is unchanged.
   The shell parts (tab bar, More sheet…) are made by js/mobile.js.
   ===================================================================== */
.tabbar, .sheet-back, .filter-btn { display: none; }

@media (max-width: 900px) {
  :root { --tabbar-h: 64px; --appbar-h: 58px; --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px); }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body { -webkit-tap-highlight-color: transparent; }
  body.sheet-open { overflow: hidden; }
  a, button, label, select, summary { touch-action: manipulation; }
  a:hover { text-decoration: none; }

  .sidebar, .scrim { display: none !important; }
  .app { grid-template-columns: minmax(0, 1fr); min-height: 100dvh; }
  .page { padding: 12px max(14px, env(safe-area-inset-right)) calc(var(--tabbar-h) + var(--safe-b) + 24px) max(14px, env(safe-area-inset-left)); }
  .page.page-in { animation: page-in .22s ease-out; }
  @keyframes page-in { from { opacity: 0; transform: translateY(10px); } }

  /* ---------- app bar ---------- */
  .topbar {
    gap: 10px; min-height: calc(var(--appbar-h) + var(--safe-t)); padding: var(--safe-t) 12px 0 14px;
    background: color-mix(in srgb, var(--surface) 90%, transparent);
    -webkit-backdrop-filter: saturate(1.6) blur(14px); backdrop-filter: saturate(1.6) blur(14px);
  }
  .topbar.with-back { padding-left: 4px; }
  .topbar .app-logo { width: 32px; height: 32px; flex: none; }
  .topbar.with-back .app-logo { display: none; }
  .app-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
  .topbar .app-title #top-title { font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
  .topbar .app-title .top-biz { display: block; max-width: none; font-size: 12px; }
  .topbar .app-title .top-biz:empty { display: none; }
  .topbar .app-btn, .app-btn {
    width: 42px; height: 42px; display: grid; place-items: center; flex: none; padding: 0; border: 0; border-radius: 50%;
    background: transparent; color: var(--text); cursor: pointer;
  }
  .app-btn svg { width: 22px; height: 22px; }
  .app-btn:active { background: var(--surface-2); }
  .app-btn.spinning svg { animation: spin .8s linear infinite; }
  .topbar .app-avatar {
    width: 36px; height: 36px; flex: none; padding: 0; border: 0; border-radius: 50%; cursor: pointer;
    background: var(--primary); color: #fff; font: inherit; font-weight: 700;
  }

  /* ---------- bottom tab bar ---------- */
  .tabbar {
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
    height: calc(var(--tabbar-h) + var(--safe-b)); padding: 0 max(4px, env(safe-area-inset-right)) var(--safe-b) max(4px, env(safe-area-inset-left));
    background: color-mix(in srgb, var(--surface) 94%, transparent); border-top: 1px solid var(--border);
    -webkit-backdrop-filter: saturate(1.6) blur(14px); backdrop-filter: saturate(1.6) blur(14px);
  }
  .tabbar > * {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0;
    background: none; border: 0; padding: 0; font: inherit; font-size: 11.5px; font-weight: 600; color: var(--muted); cursor: pointer;
  }
  .tabbar i { position: relative; display: grid; place-items: center; width: 56px; height: 30px; border-radius: 999px; transition: background .18s; }
  .tabbar svg { width: 22px; height: 22px; }
  .tabbar .active { color: var(--primary-text); }
  .tabbar .active i { background: var(--primary-soft); }
  .tabbar > *:active i { transform: scale(.93); }
  .tabbar .count, .sheet-grid .count {
    position: absolute; top: -3px; left: 50%; margin-left: 5px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
    display: grid; place-items: center; background: #ef4444; color: #fff; font-size: 10.5px; font-style: normal; font-weight: 700;
    box-shadow: 0 0 0 2px var(--surface);
  }

  /* ---------- "More" sheet ---------- */
  .sheet-back { display: flex; align-items: flex-end; position: fixed; inset: 0; z-index: 90; background: rgba(15, 17, 26, .45); animation: fade .15s; }
  .sheet {
    width: 100%; max-height: 90dvh; overflow-y: auto; background: var(--surface); border-radius: 22px 22px 0 0;
    padding: 8px 14px calc(16px + var(--safe-b)); box-shadow: var(--shadow-lg); animation: sheet-up .24s cubic-bezier(.2, .8, .2, 1);
  }
  @keyframes sheet-up { from { transform: translateY(100%); } }
  .sheet-grip { width: 40px; height: 4px; border-radius: 4px; background: var(--border-strong); margin: 0 auto 8px; }
  .sheet-user { display: flex; align-items: center; gap: 12px; padding: 6px 2px 14px; border-bottom: 1px solid var(--border); }
  .sheet-user .avatar { width: 44px; height: 44px; font-size: 18px; }
  .sheet-user > div:nth-child(2) { flex: 1; min-width: 0; }
  .sheet-user b { display: block; font-size: 16px; overflow-wrap: anywhere; }
  .sheet-user span { font-size: 12.5px; color: var(--muted); }
  .sheet-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 14px 0; }
  .sheet-grid a { display: flex; flex-direction: column; align-items: center; gap: 7px; padding: 10px 4px; border-radius: 14px; color: var(--text); font-size: 12.5px; font-weight: 600; text-align: center; line-height: 1.25; }
  .sheet-grid i { position: relative; display: grid; place-items: center; width: 52px; height: 52px; border-radius: 16px; background: var(--primary-soft); color: var(--primary-text); }
  .sheet-grid svg { width: 24px; height: 24px; }
  .sheet-grid a:active, .sheet-grid a.active { background: var(--surface-2); }
  .sheet-list { border-top: 1px solid var(--border); padding-top: 6px; }
  .sheet-list button { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 52px; padding: 0 8px; border: 0; border-radius: 12px; background: none; color: var(--text); font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; }
  .sheet-list button:active { background: var(--surface-2); }
  .sheet-list button.danger { color: var(--bad); }
  .sheet-list svg { width: 20px; height: 20px; }

  /* ---------- page head: the app bar already shows the title, keep only the actions ---------- */
  .page .page-head { margin-bottom: 12px; flex-wrap: nowrap; min-width: 0; }
  .page .page-head > div:first-child:not(.actions) { display: none; }
  .page .page-head:not(:has(.actions > *)) { display: none; }
  .page .page-head .actions { width: 100%; min-width: 0; gap: 8px; }
  .page .page-head .actions > * { flex: 1 1 auto; border-radius: 999px; }

  /* ---------- surfaces & controls ---------- */
  .card { border-radius: 16px; }
  .btn { border-radius: 12px; transition: transform .08s; }
  .btn.sm { border-radius: 10px; }
  .btn:active:not(:disabled) { transform: scale(.97); }
  a.kpi:active, tr.clickable:active { transform: scale(.99); }
  .btn.primary { box-shadow: 0 4px 12px color-mix(in srgb, var(--primary) 30%, transparent); }
  .btn.primary:disabled { box-shadow: none; }
  input:not([type="checkbox"]):not([type="radio"]), select, textarea { border-radius: 12px; min-height: 44px; }
  .toolbar input[type="search"], .scan-bar input { border-radius: 999px; padding-left: 16px; }
  .chip { min-height: 36px; padding: 6px 14px; }
  .chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
  .chip.active .n { background: rgba(255, 255, 255, .22); color: #fff; }

  /* tabs look like a segmented switch */
  .page .tabs, .modal .tabs { margin: 10px 10px 4px; padding: 4px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; scrollbar-width: none; }
  .page .tabs::-webkit-scrollbar, .modal .tabs::-webkit-scrollbar { display: none; }
  .page .tabs > button, .page .tabs > a, .modal .tabs > button { flex: 1 0 auto; justify-content: center; text-align: center; border: 0; border-radius: 10px; padding: 9px 12px; }
  .page .tabs > .active, .modal .tabs > .active { background: var(--surface); color: var(--primary-text); box-shadow: var(--shadow); }
  .modal .tabs { margin: 0 0 14px; }

  /* loading: grey placeholder cards instead of the word "Loading" */
  .page > .loading { height: 360px; padding: 0; font-size: 0; border-radius: 16px;
    background: linear-gradient(var(--surface) 0 0) 0 0 / 100% 96px no-repeat, linear-gradient(var(--surface) 0 0) 0 108px / 100% 120px no-repeat, linear-gradient(var(--surface) 0 0) 0 240px / 100% 120px no-repeat;
    animation: pulse 1.1s ease-in-out infinite alternate; }
  @keyframes pulse { to { opacity: .45; } }

  /* Product page: the app bar's arrow is the way back; keep only Previous / Next */
  .page .prod-nav > a:first-child { display: none; }
  .page .prod-nav:not(:has(.prod-steps)) { display: none; }
  .page .prod-nav .prod-steps { flex: 1; justify-content: space-between; flex-wrap: nowrap; }

  /* Dashboard: one seller account per card, swipe sideways */
  .page .sync-cards { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: min(84%, 340px); overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding: 0 14px; margin: 0 -14px 14px; padding: 2px 14px 6px; scrollbar-width: none; }
  .page .sync-cards::-webkit-scrollbar { display: none; }
  .page .sync-cards > * { scroll-snap-align: start; }
  .page .sync-cards > :only-child { grid-column: 1; }

  /* filters fold away behind one button */
  .toolbar .filter-btn { display: inline-flex; flex: none; border-radius: 999px; min-height: 44px; }
  .toolbar .filter-btn b { min-width: 20px; height: 20px; border-radius: 999px; display: grid; place-items: center; background: var(--primary); color: #fff; font-size: 11px; }
  .toolbar .filter-btn b.hidden { display: none; }
  .toolbar.filters input[type="search"] { flex: 1 1 calc(100% - 150px); max-width: none; order: -1; }
  .toolbar.filters .filter-btn { order: -1; }
  .toolbar.filters.open .filter-btn { background: var(--primary-soft); color: var(--primary-text); border-color: var(--primary); }
  .toolbar.filters:not(.open) > select, .toolbar.filters:not(.open) > .check { display: none; }
  .toolbar.filters.open > select { flex: 1 1 calc(50% - 4px); max-width: none; width: auto; }

  /* ---------- selection bar, pop-ups, messages: stay above the tab bar ---------- */
  .page .sel-bar { bottom: calc(var(--tabbar-h) + var(--safe-b) + 8px); box-shadow: var(--shadow-lg); }
  .page .sel-bar:not(:has(.btn:not(.hidden))) { position: static; box-shadow: none; } /* nothing to press: don't float over the list */
  .modal, .modal.wide { border-radius: 22px 22px 0 0; max-height: 94dvh; animation: sheet-up .24s cubic-bezier(.2, .8, .2, 1); }
  .modal-head { position: relative; padding-top: 18px; }
  .modal-head::before { content: ""; position: absolute; top: 7px; left: 50%; transform: translateX(-50%); width: 40px; height: 4px; border-radius: 4px; background: var(--border-strong); }
  .modal-head button { width: 40px; height: 40px; font-size: 26px; }
  .modal-foot .btn { min-height: 46px; }
  .toasts { left: 12px; right: 12px; bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px); }
  .toast { border-radius: 14px; text-align: center; }

  /* ---------- sign in ---------- */
  .login-wrap { min-height: 100dvh; align-content: end; justify-items: stretch; padding: 0; }
  .login-card { max-width: 520px; width: 100%; justify-self: center; border: 0; border-radius: 28px 28px 0 0; padding: 28px 22px calc(28px + var(--safe-b)); }
  .login-card .brand { flex-direction: column; text-align: center; padding-bottom: 22px; }
  .login-card .brand img { width: 64px; height: 64px; }
  .login-card .brand b { font-size: 20px; }
  .login-card .btn { min-height: 50px; font-size: 16px; }
}

/* ---------- table rows as separate cards (same width at which app.css turns tables into cards) ---------- */
@media (max-width: 720px) {
  .page .card:has(table.rtable) { background: transparent; border: 0; box-shadow: none; }
  .page .card:has(table.rtable) :is(.card-head, .toolbar, .stock-sync, .scan-bar, .table-foot) {
    background: var(--surface); border: 1px solid var(--border); border-radius: 16px; margin-bottom: 10px;
  }
  .page .card:has(table.rtable) .tabs { margin: 0 0 10px; background: var(--surface); }
  .page .card:has(table.rtable) .tabs > .active { background: var(--primary-soft); box-shadow: none; }
  .page .card:has(table.rtable) > .table-foot:last-child, .page .card:has(table.rtable) > div > .table-foot:last-child { margin-bottom: 0; }

  .page table.rtable tbody tr {
    position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
    margin-bottom: 10px; padding: 14px; box-shadow: var(--shadow);
  }
  .page table.rtable tbody tr:last-child { border-bottom: 1px solid var(--border); }
  .page table.rtable tbody tr:hover { background: var(--surface); }
  .page table.rtable td { background: transparent; }
  .page table.rtable tbody tr.selected { background: var(--primary-soft); border-color: var(--primary); }

  /* the tick box sits in the card's top corner instead of taking its own row */
  .page table.rtable tr > td:is(.chk, :has(> input[type="checkbox"]:only-child)) { position: absolute; top: 6px; right: 6px; width: auto; padding: 8px; z-index: 1; }
  .page table.rtable tr > td:is(.chk, :has(> input[type="checkbox"]:only-child)) input { display: block; width: 22px; height: 22px; border-radius: 6px; }
  .page table.rtable tr:has(> td.chk) > td:has(.cell-title, .lab-name) { padding-right: 34px; }

  .page table.rtable td .btn-row .btn.ghost { background: var(--surface-2); border-color: transparent; }

  /* Product List: numbers three to a row */
  .page table.plist.rtable tbody tr { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .page table.plist.rtable td:has(.pstocks) { grid-column: 1 / -1; }

  /* sync strip on Stock Check keeps its own small boxes */
  .page .sync-strip > .card { border-radius: 14px; }
}
