/* ============================================================
   J&J Workshop — Shared Mobile Stylesheet
   Loaded on every page. Activates at <= 760px viewport.
   Preserves existing desktop aesthetic; adapts for phones.
   ============================================================ */

/* -------- Universal touch-friendliness (all sizes) -------- */
@media (hover: none) and (pointer: coarse) {
  /* iOS Safari: prevent auto-zoom on input focus by ensuring font-size >= 16px */
  input, select, textarea {
    font-size: 16px !important;
  }
  /* But keep small-caps Cinzel labels small */
  .form-group label,
  .kpi-label,
  label.upper {
    font-size: 0.6rem !important;
  }
}

/* ============================================================
   PHONE LAYOUT (<= 760px)
   ============================================================ */
@media (max-width: 760px) {

  /* -------- Body & root spacing -------- */
  body {
    -webkit-text-size-adjust: 100%;
  }

  /* -------- Buttons: enforce 44px minimum tap height -------- */
  .btn,
  button.btn,
  a.btn {
    min-height: 44px;
    padding: 0.7rem 1.1rem;
    font-size: 0.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .btn-sm {
    min-height: 38px;
    padding: 0.5rem 0.85rem;
    font-size: 0.7rem;
  }
  .btn-full {
    width: 100%;
  }

  /* -------- Toolbars: stack vertically, full width -------- */
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }
  .toolbar input,
  .toolbar select {
    min-width: 0 !important;
    width: 100%;
    padding: 0.75rem 0.85rem;
  }
  .toolbar .spacer {
    display: none;
  }
  .toolbar .btn {
    width: 100%;
  }

  /* -------- Headers (admin/maker/portal) -------- */
  .header {
    padding: 0.85rem 1rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
  }
  .header-title {
    text-align: center;
    font-size: 0.85rem;
  }
  .header-actions {
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.4rem;
  }
  .header-actions .btn {
    flex: 1 1 auto;
    min-width: 0;
  }

  /* -------- Tabs: scroll horizontally with bigger taps -------- */
  .tabs {
    padding: 0 0.5rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    padding: 0.95rem 1rem;
    font-size: 0.65rem;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  /* -------- Biz filter (maker.html) -------- */
  .biz-filter {
    padding: 0.6rem 0.75rem;
    justify-content: center;
    gap: 0.3rem;
  }
  .biz-pill {
    padding: 0.5rem 0.8rem;
    font-size: 0.6rem;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
  }

  /* -------- Content padding -------- */
  .content {
    padding: 1rem 0.75rem !important;
  }

  /* -------- Forms: single column, fuller inputs -------- */
  .form-row,
  .form-row.triple {
    grid-template-columns: 1fr !important;
    gap: 0.85rem;
  }
  .form-group input,
  .form-group select,
  .form-group textarea {
    padding: 0.85rem 0.9rem;
  }

  /* -------- Modals: full width on phone -------- */
  .modal-backdrop {
    padding: 0;
    align-items: flex-end;
  }
  .modal {
    padding: 1.25rem 1rem !important;
    max-width: 100% !important;
    width: 100% !important;
    max-height: 95vh !important;
    border-radius: 14px 14px 0 0;
    margin: 0;
  }
  .modal::before {
    inset: 4px;
  }
  .modal h3 {
    font-size: 1rem;
    padding-right: 2rem; /* room for close button if absolute */
  }
  .modal-actions {
    flex-direction: column-reverse;
    gap: 0.5rem;
    align-items: stretch;
  }
  .modal-actions .btn {
    width: 100%;
  }
  /* Add a swipe handle to suggest the modal slides up from bottom */
  .modal::after {
    content: '';
    position: absolute;
    top: 0.5rem;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: rgba(201, 169, 97, 0.3);
    pointer-events: none;
  }

  /* -------- KPI grids: 2 across on phone -------- */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.6rem;
  }
  .kpi {
    padding: 0.85rem 0.5rem;
  }
  .kpi-value {
    font-size: 1.3rem !important;
  }
  .kpi-label {
    font-size: 0.55rem;
  }

  /* -------- Section headers -------- */
  h2 {
    font-size: 1.2rem;
    letter-spacing: 0.08em;
  }

  /* -------- Toasts: full-width on phone, above iOS bottom bar -------- */
  .toast {
    bottom: max(1rem, env(safe-area-inset-bottom));
    right: 0.75rem;
    left: 0.75rem;
    max-width: none;
  }

  /* -------- Floating queue pill (maker labels) -------- */
  #matLabelQueuePill {
    bottom: max(1rem, env(safe-area-inset-bottom)) !important;
    right: 0.75rem !important;
    left: 0.75rem !important;
    text-align: center;
  }

  /* -------- Bulk action bars -------- */
  .bulk-bar,
  #matBulkBar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.5rem !important;
  }
  .bulk-bar .btn,
  #matBulkBar .btn {
    width: 100%;
  }

  /* -------- DATA TABLES → STACKED CARDS -------- */
  /* Default: wrap converts every .data-table into card-stack on phone.
     Pages that need true table layout can opt out with .data-table.keep-table */
  .data-table:not(.keep-table),
  .data-table:not(.keep-table) thead,
  .data-table:not(.keep-table) tbody,
  .data-table:not(.keep-table) tr,
  .data-table:not(.keep-table) td {
    display: block;
    width: 100%;
  }
  .data-table:not(.keep-table) thead {
    display: none; /* hide header row; we'll use data-label on cells */
  }
  .data-table:not(.keep-table) {
    background: transparent;
    border-collapse: separate;
  }
  .data-table:not(.keep-table) tbody tr {
    background: var(--ink-2, #1a1411);
    border: 1px solid rgba(201, 169, 97, 0.25);
    border-radius: 6px;
    padding: 0.85rem 1rem;
    margin-bottom: 0.65rem;
    position: relative;
  }
  .data-table:not(.keep-table) tbody tr:hover td {
    background: transparent;
  }
  .data-table:not(.keep-table) tbody td {
    border: none !important;
    padding: 0.3rem 0 !important;
    text-align: left !important;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
  }
  /* Show data-label as the row "key" on each cell */
  .data-table:not(.keep-table) tbody td::before {
    content: attr(data-label);
    font-family: 'Cinzel', serif;
    font-size: 0.6rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--gold, #c9a961);
    opacity: 0.75;
    flex-shrink: 0;
  }
  /* Cells with no data-label still display nicely (full-width content) */
  .data-table:not(.keep-table) tbody td:not([data-label])::before {
    content: none;
  }
  /* Numeric cells: still right-aligned within their flex row */
  .data-table:not(.keep-table) tbody td.num {
    font-variant-numeric: tabular-nums;
  }
  /* Actions row: full-width button strip */
  .data-table:not(.keep-table) tbody td.actions {
    margin-top: 0.65rem;
    padding-top: 0.6rem !important;
    border-top: 1px solid rgba(201, 169, 97, 0.15) !important;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 0.35rem;
  }
  .data-table:not(.keep-table) tbody td.actions::before {
    display: none;
  }
  .data-table:not(.keep-table) tbody td.actions .btn {
    flex: 0 1 auto;
    padding: 0.55rem 0.85rem;
    margin: 0 !important;
  }
  /* Empty-state message: keep centered, no key prefix */
  .data-table:not(.keep-table) tbody td.empty-msg {
    text-align: center !important;
    justify-content: center;
    padding: 2rem 0 !important;
  }
  .data-table:not(.keep-table) tbody td.empty-msg::before {
    display: none;
  }
  /* Checkbox cells should align left, no key prefix */
  .data-table:not(.keep-table) tbody td.check-cell,
  .data-table:not(.keep-table) tbody td:has(> input[type="checkbox"]:only-child) {
    justify-content: flex-start;
  }
  .data-table:not(.keep-table) tbody td.check-cell::before,
  .data-table:not(.keep-table) tbody td:has(> input[type="checkbox"]:only-child)::before {
    display: none;
  }

  .table-wrap {
    overflow-x: visible !important;
  }

  /* If a table truly needs to stay tabular on phone (use .keep-table), give it horizontal scroll comfort */
  .data-table.keep-table {
    font-size: 0.85rem;
  }
  .data-table.keep-table th,
  .data-table.keep-table td {
    padding: 0.55rem 0.5rem;
    white-space: nowrap;
  }

  /* -------- Login card: friendly on phone -------- */
  .login-card {
    padding: 2rem 1.25rem;
  }
  .login-card h1 {
    font-size: 1.25rem;
  }

  /* -------- Cart drawer (public site) -------- */
  .cart-drawer {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* -------- Admin: order cards & related -------- */
  .order-card {
    padding: 0.95rem !important;
  }
  .order-head {
    flex-direction: column;
    align-items: flex-start !important;
  }
  .order-total {
    font-size: 1.25rem !important;
  }
  .order-status-bar {
    width: 100%;
  }
  .stock-quick {
    flex-wrap: wrap;
    margin: 0.5rem 0 0.85rem !important;
  }
  .stock-quick input {
    width: 60px !important;
  }
  .ff-chip {
    padding: 0.6rem 0.85rem !important;
    font-size: 0.65rem !important;
    flex: 1 1 auto;
    min-width: 0;
  }

  /* ============================================================
     PUBLIC SITE NAVIGATION (hamburger pattern)
     Targets <nav> with .nav-inner > .nav-links structure
     ============================================================ */

  /* The hamburger button (added by mobile-nav.js for public pages) */
  .mobile-nav-toggle {
    display: flex !important;
    background: transparent;
    border: 1px solid var(--gold, #c9a961);
    color: var(--gold, #c9a961);
    padding: 0.55rem 0.7rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    border-radius: 3px;
  }
  .mobile-nav-toggle svg {
    width: 22px;
    height: 22px;
    display: block;
  }

  /* Hide horizontal text-link nav on phones; the hamburger replaces it */
  nav .nav-links,
  nav .nav-link-group {
    display: none !important;
  }

  /* Slide-out drawer markup (added by mobile-nav.js) */
  .mobile-nav-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(85vw, 320px);
    background: var(--ink-2, #1a1411);
    border-left: 1px solid var(--gold, #c9a961);
    z-index: 9999;
    transform: translateX(100%);
    transition: transform 0.28s ease;
    padding: 4.5rem 1.5rem 2rem;
    overflow-y: auto;
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.5);
  }
  .mobile-nav-drawer.open {
    transform: translateX(0);
  }
  .mobile-nav-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 9998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease;
  }
  .mobile-nav-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }
  .mobile-nav-drawer a {
    display: block;
    padding: 0.95rem 0.4rem;
    color: var(--parchment, #e8dcc4);
    text-decoration: none;
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 1.15rem;
    border-bottom: 1px solid rgba(201, 169, 97, 0.15);
    letter-spacing: 0.02em;
  }
  .mobile-nav-drawer a:hover,
  .mobile-nav-drawer a:active {
    color: var(--gold, #c9a961);
  }
  .mobile-nav-drawer .drawer-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: transparent;
    border: 1px solid var(--gold, #c9a961);
    color: var(--gold, #c9a961);
    width: 40px;
    height: 40px;
    cursor: pointer;
    font-size: 1.4rem;
    line-height: 1;
    border-radius: 3px;
  }
  body.nav-drawer-open {
    overflow: hidden;
  }

  /* Existing nav containers: reduce padding & make brand readable */
  nav {
    padding: 0.75rem 1rem !important;
  }
  .nav-brand img,
  .nav-logo {
    max-height: 32px;
    width: auto;
  }
  .nav-brand .back {
    display: none; /* "← The Workshop" text is too long on phones; logo suffices */
  }
  .nav-cta {
    padding: 0.55rem 0.85rem;
    font-size: 0.7rem;
  }

  /* -------- Public site: hero sections -------- */
  .hero h1 {
    font-size: clamp(2rem, 9vw, 3rem) !important;
  }
  .hero-sub,
  .lead {
    font-size: 1rem;
  }

  /* -------- Footer link grids -------- */
  .footer-links {
    flex-direction: column !important;
    align-items: center;
    gap: 0.75rem !important;
  }
}

/* ============================================================
   DESKTOP: hide hamburger button (only shown on phones)
   ============================================================ */
@media (min-width: 761px) {
  .mobile-nav-toggle,
  .mobile-nav-drawer,
  .mobile-nav-backdrop {
    display: none !important;
  }
}

/* ============================================================
   VERY SMALL PHONES (<= 380px) — extra tightening
   ============================================================ */
@media (max-width: 380px) {
  .content {
    padding: 0.85rem 0.6rem !important;
  }
  .kpi-grid {
    grid-template-columns: 1fr !important;
  }
  .biz-pill {
    font-size: 0.55rem;
    padding: 0.45rem 0.65rem;
  }
  .tab {
    padding: 0.85rem 0.75rem;
    font-size: 0.6rem;
  }
}
