/* GearRoom mobile: phone-first overrides. Loads after style.css, polish.css and
   calendar.css, before motion.css. Tokens only, so light and dark both work. */

/* Outside the phone query: PWA / iOS Safari niceties. */
html { -webkit-text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: transparent; }
.tabbar { display: none; }

@media (display-mode: standalone) {
  body { overscroll-behavior-y: none; }
}

@media (max-width: 860px) {
  /* 1. Bottom tab bar (markup from tabBar in app.js) */
  .tabbar {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    height: calc(60px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--panel) 86%, transparent);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
    backdrop-filter: blur(18px) saturate(160%);
    border-top: 1px solid var(--line);
  }
  .tabbar a, .tabbar button {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; color: var(--muted); font-size: 11px; font-weight: 600;
    border: 0; background: none; text-decoration: none; cursor: pointer; padding: 4px 0;
  }
  .tabbar a.active { color: var(--accent); }
  .tabbar .tab-icon svg { width: 24px; height: 24px; }
  .tab-scan .tab-icon {
    width: 46px; height: 46px; border-radius: 50%;
    background: var(--accent); color: #fff; margin-top: -18px;
    display: grid; place-items: center;
    box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 45%, transparent);
  }
  .tab-scan .tab-icon svg { width: 26px; height: 26px; }
  .tab-scan .tab-label { font-size: 0; }

  /* 2. Content clears the tab bar; topbar sits under the notch */
  .content { padding: 14px 14px calc(84px + env(safe-area-inset-bottom)); }
  .topbar {
    padding-top: env(safe-area-inset-top);
    position: sticky; top: 0; z-index: 20;
    background: color-mix(in srgb, var(--panel) 86%, transparent);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
    backdrop-filter: blur(18px) saturate(160%);
    border-bottom: 1px solid var(--line);
  }

  /* 3. Topbar: search takes the remaining width (New text already hidden via .hide-sm) */
  .topbar .search { flex: 1; min-width: 0; }
  .topbar .search input { min-height: 40px; }
  .topbar .search input::placeholder { color: var(--muted); }

  /* 4. Drawer: narrower, with a dim backdrop behind it */
  .shell > .side { width: min(84vw, 320px); z-index: 70; padding-bottom: env(safe-area-inset-bottom); }
  .shell.open::after {
    content: ""; position: fixed; inset: 0;
    background: rgba(0, 0, 0, .35); z-index: 65;
  }

  /* 5. Bigger touch targets; 16px text stops iOS auto-zoom */
  .btn { min-height: 44px; }
  .btn.sm { min-height: 36px; }
  input, select { font-size: 16px; min-height: 44px; }
  textarea { font-size: 16px; }

  /* 6. Page head stacks; actions scroll sideways instead of wrapping */
  .page-head { flex-direction: column; align-items: stretch; gap: 10px; }
  .page-head h1 { font-size: 22px; }
  .page-head .actions {
    display: flex; gap: 8px; overflow-x: auto; flex-wrap: nowrap;
    scrollbar-width: none; -ms-overflow-style: none;
  }
  .page-head .actions::-webkit-scrollbar { display: none; }
  .page-head .actions .btn { flex: none; }

  /* 7. Multi-column layouts collapse to one */
  .split { grid-template-columns: 1fr; }
  .grid.two, .grid.three { grid-template-columns: 1fr; }
  .sticky-side { position: static; }
  .kv { grid-template-columns: 110px 1fr; }

  /* 8. Tables become stacked cards */
  .table-wrap { overflow: visible; }
  .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table tr {
    display: block; background: var(--panel);
    border: 1px solid var(--line); border-radius: 12px;
    margin: 0 0 10px; padding: 10px 12px;
  }
  .table tbody tr.click:hover td { background: transparent; }
  .table td {
    display: flex; justify-content: space-between; align-items: center;
    gap: 12px; padding: 6px 0; border: 0; text-align: right;
  }
  .table td::before {
    content: attr(data-label); color: var(--muted); font-size: 12.5px;
    text-align: left; flex: none;
  }
  .table td[data-label=""]::before { display: none; }
  .table td[data-label=""] { justify-content: flex-start; text-align: left; }
  .table .num { text-align: right; }
  .card.flush:has(> .table-wrap) { background: transparent; border: 0; box-shadow: none; padding: 0; }

  /* 9. Modals become bottom sheets */
  .overlay { align-items: end; padding: 0; }
  .modal, .modal.wide {
    width: 100%; max-height: 92vh;
    border-radius: 18px 18px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .modal::before {
    content: ""; display: block; width: 36px; height: 5px;
    border-radius: 999px; background: var(--line); margin: 8px auto 0;
  }
  .modal-foot {
    position: sticky; bottom: 0; background: var(--panel);
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }
  .modal-foot .btn { flex: 1; }

  /* 10. Toasts go to the top, full width */
  #toasts { top: calc(10px + env(safe-area-inset-top)); bottom: auto; left: 12px; right: 12px; }
  .toast { width: 100%; max-width: none; }

  /* 11. Two-up photo grid */
  .gear-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .gcard-body { padding: 10px 10px 2px; }
  .gcard-title { font-size: 13.5px; }
  .gcard-foot { padding: 6px 10px 10px; }

  /* 12. Filters scroll sideways */
  .filters { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; -ms-overflow-style: none; }
  .filters::-webkit-scrollbar { display: none; }
  .filters input, .filters select { min-width: 150px; flex: none; }
  .filters input[type="search"] { min-width: 200px; flex: none; }

  /* 13. Cart bar sits above the tab bar */
  .cart-bar { position: fixed; bottom: calc(70px + env(safe-area-inset-bottom)); left: 12px; right: 12px; z-index: 40; }

  /* 14. Dashboard stats in two columns */
  .grid.stats { grid-template-columns: repeat(2, 1fr); }

  /* Misc phone tightening */
  .search-results { max-height: 60vh; }
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) and (orientation: landscape) {
  .tabbar { height: calc(50px + env(safe-area-inset-bottom)); }
  .tab-scan .tab-icon { width: 40px; height: 40px; margin-top: -8px; }
  .content { padding-bottom: calc(74px + env(safe-area-inset-bottom)); }
}

@media (max-width: 860px) {
  /* Calendar toolbar: arrows + title on one row, view switch and filters below. */
  .toolbar { gap: 8px; }
  .toolbar h2 { flex: 1; min-width: 0; margin: 0 4px; font-size: 18px; }
  .toolbar .seg { order: 3; width: 100%; margin-left: 0; }
  .toolbar .seg button { flex: 1; justify-content: center; }
  .toolbar select { order: 4; flex: 1; min-width: 0; }
  .seg button { min-height: 36px; }
}

@media (max-width: 860px) {
  /* Month view on a phone: each booking is a slim coloured bar; tap the day to see the list. */
  .cal-month .cal-ev { font-size: 0; height: 5px; padding: 0; border: 0; border-radius: 3px; background: var(--ev); margin-top: 2px; }
  .cal-month .cal-ev .cal-time { display: none; }
  .cal-month .cal-more { font-size: 10.5px; padding: 0; }
  .cal-month .cal-day { padding: 4px; }
  .cal-month .cal-num { font-size: 12.5px; min-width: 22px; height: 22px; }
  .cal-month { grid-template-rows: auto repeat(6, minmax(58px, 1fr)); height: auto; min-height: 0; }
}

@media (max-width: 860px) {
  /* Booking cart on phones: hidden until something is added, never taller than half the screen. */
  .cart-bar.is-empty { display: none; }
  .cart-bar { max-height: 52vh; overflow: auto; overscroll-behavior: contain; }
  .portal-pad, .content:has(.cart-bar:not(.is-empty)) { padding-bottom: calc(52vh + 90px); }
}
