/* 2026-11-07 owner: "make the web page mobile friendly, specially for someone who wants to edit an item price, printout, or create items and upload directly".
   Phone rules for the whole cloud web. Everything is inside one media query, so a PC / tablet layout is not touched at all.
   Works together with wwwroot/js/mobile.js, which tags the wide lists and tables (data-m="...") and copies each column title into data-l="..." so a row can be shown as a card:
     data-m="head"   the grey title row of a grid list (hidden on a phone, its words become the small labels inside each card)
     data-m="row"    a row of a grid list -> a card with label / value pairs
     data-mcards     a <table> shown as one card per row (set on the table in Razor; used by Item Pricing and Item Printout)
     data-m="bar"    the Save / Cancel bar of an edit form: stays on top while the form is scrolled
   Fixed-width grids written inline in a page (1fr 1fr 1fr 1fr ...) are folded to 2 columns and then 1 column on a narrow phone. */
.m-only { display: none; }
@media (max-width: 760px) {
  .m-only { display: flex; }

  /* --- never a sideways page --- */
  html, body { overflow-x: hidden; }
  .app-content { padding: 14px 12px 28px; }
  .app-content [style*="padding:20px"] { padding: 12px !important; }
  .app-content [style*="padding:22px"] { padding: 14px !important; }
  /* the "Choose File" button of an upload box: big enough for a finger, and the Import button under it takes the width */
  .app-content input[type=file]::file-selector-button { min-height: 44px; padding: 0 14px; margin-right: 10px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text); font-family: inherit; font-weight: 700; cursor: pointer; }
  .app-content img, .app-content video, .app-content canvas { max-width: 100%; height: auto; }

  /* --- fingers: 16px text so the phone does not zoom in when a box is tapped; 44px tall boxes and buttons --- */
  .app-content input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]),
  .app-content select,
  .app-content textarea,
  .app-content .field-value { font-size: 16px !important; min-height: 44px; box-sizing: border-box; max-width: 100%; }
  .app-content textarea { min-height: 88px; }
  .app-content button, .app-content .btn-accent, .app-content .toolbar-btn, .app-content .tab-2 { min-height: 42px; }
  .app-content button[style*="border-radius:50%"] { min-height: 32px; min-width: 32px; }   /* the small round "i" buttons */
  .app-content input[type=checkbox], .app-content input[type=radio] { width: 20px; height: 20px; }
  .app-content input[type=file] { max-width: 100%; font-size: 14px; }

  /* boxes the pages gave a fixed pixel width (width:260px ...) use the whole row instead */
  .app-content [style*="width:200px"], .app-content [style*="width:220px"], .app-content [style*="width:240px"],
  .app-content [style*="width:260px"], .app-content [style*="width:320px"], .app-content [style*="width:90px"],
  .app-content [style*="width:140px"], .app-content [style*="width:280px"], .app-content [style*="width:300px"], .app-content [style*="width:340px"],
  .app-content [style*="width:360px"], .app-content [style*="width:380px"], .app-content [style*="width:400px"] { width: 100% !important; max-width: 100% !important; }
  .app-content [style*="max-width:1040px"], .app-content [style*="max-width:720px"], .app-content [style*="max-width:640px"],
  .app-content [style*="max-width:420px"], .app-content [style*="max-width:320px"] { max-width: 100% !important; }

  /* --- grids written inline in the pages: 4 / 3 columns -> 2, then 1 on a very small phone --- */
  .app-content [style*="grid-template-columns:1fr 1fr 1fr 1fr"],
  .app-content [style*="grid-template-columns:1fr 1fr 1fr;"],
  .app-content [style*="grid-template-columns:1fr 1fr 1fr "],
  .app-content [style*="grid-template-columns:repeat(3"],
  .app-content [style*="grid-template-columns:repeat(4"] { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .app-content [style*="grid-template-columns:1fr 2fr"],
  .app-content [style*="grid-template-columns:1.4fr 90px 2fr"] { grid-template-columns: minmax(0, 1fr) !important; }
  .app-content [style*="display:grid"] > * { min-width: 0; }

  /* a flex row of buttons / filters wraps instead of running off the side */
  .app-content [style*="display:flex"][style*="gap"]:not([style*="border:1px"]):not([style*="flex-direction:column"]) { flex-wrap: wrap; }
  .app-content [style*="width:1px"][style*="height:22px"] { display: none; }
  .app-content [style*="display:flex"][style*="overflow-x:auto"] { flex-wrap: nowrap; }   /* the tab strips keep scrolling sideways */

  /* the title of a page + its buttons (Save, Back to ...): the title on its own line, the buttons under it sharing the width */
  .app-content > [style*="justify-content:space-between"] { flex-wrap: wrap !important; gap: 10px !important; align-items: flex-start !important; }
  .app-content > [style*="justify-content:space-between"] > :first-child { flex: 1 1 100%; min-width: 0; }
  .app-content > [style*="justify-content:space-between"] > :last-child:not(:first-child) { flex: 1 1 100%; justify-content: center; }
  .app-content > [style*="justify-content:space-between"] > div:last-child:not(:first-child) { display: flex; flex-wrap: wrap; gap: 8px; }
  .app-content > [style*="justify-content:space-between"] > div:last-child:not(:first-child) > * { flex: 1 1 auto; justify-content: center; text-align: center; }

  /* a search box with an icon inside: keeps the icon beside the text */
  .app-content [style*="border:1px solid var(--border)"][style*="display:flex"] > input { min-height: 0 !important; flex: 1 1 auto; min-width: 0; }

  /* tab strips (Item Setup | Pictures | ...): easy to swipe */
  .app-content .tab-2 { white-space: nowrap; flex: 0 0 auto; padding-left: 14px; padding-right: 14px; }

  /* --- dialogs: the whole screen width, scroll inside --- */
  .app-content [style*="position:fixed"][style*="inset:0"] > div { width: calc(100vw - 20px) !important; max-width: calc(100vw - 20px) !important; max-height: 90vh !important; box-sizing: border-box; }

  /* --- the Save / Cancel bar of a form stays on top while the form is scrolled --- */
  [data-m="bar"] { position: sticky; top: 0; z-index: 30; background: var(--surface); flex-wrap: wrap; row-gap: 8px; padding: 10px 12px !important; box-shadow: 0 2px 10px rgba(0,0,0,0.08); }
  [data-m="bar"] > div:first-child { flex: 1 1 100%; font-size: 14px !important; }
  [data-m="bar"] > div:last-child { flex: 1 1 100%; justify-content: stretch; }
  [data-m="bar"] > div:last-child > button { flex: 1 1 0; }

  /* --- a grid list (title row + rows) shown as cards --- */
  [data-m="head"] { display: none !important; }
  [data-m="row"] {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 6px 14px !important;
    padding: 12px 14px !important;
    position: relative;
    border-bottom: 1px solid var(--border) !important;
  }
  [data-m="row"] > * { min-width: 0; overflow-wrap: anywhere; }
  /* a pill (Function: Revenue) or a coloured cell becomes plain text with its label, so the label is not inside a stretched pill */
  [data-m="row"] > [data-l]:not(:first-child) { display: block !important; background: transparent !important; padding: 0 !important; border-radius: 0 !important; }
  [data-m="row"] > [data-l]:not([data-l=""])::before {
    content: attr(data-l);
    display: block;
    font-size: 10px; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; color: var(--text-3);
    margin-bottom: 1px;
  }
  /* the first cell is the name of the thing: the whole width, bigger, and no label */
  [data-m="row"] > :first-child { grid-column: 1 / -1; font-size: 15px !important; padding-right: 30px; }
  [data-m="row"] > :first-child::before { display: none !important; }
  /* the pencil / arrow at the end of the row sits at the top right corner of the card */
  [data-m="row"] > [data-l=""]:last-child { position: absolute; top: 12px; right: 12px; }
  [data-m="row"] > [data-l=""]:not(:last-child) { grid-column: 1 / -1; }

  /* --- a table shown as one card per row (Item Pricing, Item Printout) --- */
  table[data-mcards] { display: block; width: 100% !important; white-space: normal !important; }
  table[data-mcards] thead { display: none; }
  table[data-mcards] tbody { display: block; }
  table[data-mcards] tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; padding: 12px 14px; border-bottom: 1px solid var(--border) !important; }
  table[data-mcards="3"] tr { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 8px; }
  table[data-mcards="3"] td input { padding: 8px 6px !important; font-size: 15px !important; }
  /* the grey "Default" values of another branch come after the editable ones, smaller */
  table[data-mcards] td[data-ro] { order: 5; }
  table[data-mcards] td:not([data-ro]) { order: 1; }
  table[data-mcards] td:first-child { order: 0; }
  table[data-mcards] td { display: block; padding: 0 !important; border: 0 !important; min-width: 0; position: static !important; background: transparent !important; }
  table[data-mcards] td::before {
    content: attr(data-l); display: block;
    font-size: 10px; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; color: var(--text-3); margin-bottom: 2px;
  }
  table[data-mcards] td:first-child { grid-column: 1 / -1; font-size: 15px; font-weight: 700; }
  table[data-mcards] td:first-child::before { display: none; }
  table[data-mcards] td[data-g]::before { color: var(--text-3); }
  /* the read-only "Default" values of a branch are small and grey, the editable ones are normal */
  table[data-mcards] td[data-ro] { font-size: 12.5px; color: var(--text-2); }
  table[data-mcards] td[data-ro]::before { content: attr(data-l); }
  table[data-mcards] td input, table[data-mcards] td select { width: 100% !important; }
  table[data-mcards] .pager-row, table[data-mcards] tr:has(> td[colspan]) { display: block; }

  /* --- the Browse tree (category / division / group) above the list: a short scrolling strip, not half the screen --- */
  .hb-tree { max-height: 200px; overflow-y: auto; }
  .hb-grid { grid-template-columns: minmax(0, 1fr) !important; }

  /* --- bars with the search box + filters --- */
  .app-content [style*="margin:18px 0 16px"] > .toolbar-btn, .app-content [style*="margin:18px 0 16px"] > button { flex: 1 1 auto; }
}

@media (max-width: 420px) {
  .app-content [style*="grid-template-columns:1fr 1fr;"],
  .app-content [style*="grid-template-columns:1fr 1fr "],
  .app-content [style*="grid-template-columns:repeat(2"] { grid-template-columns: minmax(0, 1fr) !important; }
}
