/* ------------------------------------------------------------------
   mobile.css — phone/tablet layer for the Invoicing app
   Loaded after responsive.css. Everything is scoped to screen <=767px so the
   desktop layout is byte-for-byte unchanged.
   ------------------------------------------------------------------ */

@media screen and (max-width: 767px) {

  /* ---- 1. Comfortable tap targets (WCAG 2.5.5 / 44px) ------------- */
  .form-control,
  .select2-container--bootstrap .select2-selection,
  .select2-container--bootstrap .select2-search--dropdown .select2-search__field,
  .sm-select2 .select2-container--bootstrap .select2-selection {
    height: 44px !important;
    font-size: 16px !important;      /* 16px stops iOS auto-zoom on focus */
    line-height: 1.4 !important;
    padding: 10px 12px !important;
  }
  textarea.form-control { height: auto !important; min-height: 88px !important; }

  .btn { min-height: 44px; padding: 11px 16px; font-size: 15px; }
  .btn-xs, .btn-sm { min-height: 38px; padding: 8px 12px; font-size: 14px; }

  /* icon-only action buttons in list rows */
  td a > i.fa, td button > i.fa { padding: 8px; font-size: 17px; }

  /* ---- 2. Data tables become cards -------------------------------- */
  /* mobile-cards is added by mobile-enhance.js only to real data tables */
  table.mobile-cards,
  table.mobile-cards tbody,
  table.mobile-cards tr,
  table.mobile-cards td { display: block; width: auto !important; }

  table.mobile-cards thead { display: none; }

  table.mobile-cards tr {
    margin: 0 0 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: #fff;
    padding: 6px 10px;
    box-shadow: 0 1px 2px rgba(0,0,0,.06);
  }

  table.mobile-cards td {
    border: none !important;
    border-bottom: 1px solid #f2f2f2 !important;
    padding: 9px 0 !important;
    text-align: right;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    min-height: 40px;
    white-space: normal !important;
    word-break: break-word;
  }
  table.mobile-cards td:last-child { border-bottom: none !important; }

  /* the label injected from <thead> */
  table.mobile-cards td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #666;
    text-align: left;
    flex: 0 0 42%;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .3px;
  }
  /* cells with no header get no label and go full width */
  table.mobile-cards td[data-label=""]::before { content: none; }

  /* hide empty cells so cards stay short */
  table.mobile-cards td.mc-empty { display: none; }

  /* Action cells (edit / delete / print icons) each arrive as their own <td>.
     Make them inline so they sit together as one toolbar at the foot of the
     card instead of one stacked row each. */
  table.mobile-cards td.mc-actions {
    display: inline-flex !important;
    width: auto !important;
    border-bottom: none !important;
    padding: 4px 2px !important;
    margin-right: 4px;
    min-height: 0;
  }
  table.mobile-cards td.mc-actions a,
  table.mobile-cards td.mc-actions button {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 44px; min-height: 44px;
  }
  /* the row-select checkbox: keep it, but inline and unlabelled */
  table.mobile-cards td.mc-check {
    display: inline-flex !important;
    width: auto !important;
    border-bottom: none !important;
    padding: 4px 8px 4px 0 !important;
    min-height: 0;
  }
  table.mobile-cards td.mc-check::before { content: none; }
  table.mobile-cards td.mc-check input[type=checkbox] { width: 20px; height: 20px; }

  /* slightly denser rows so a card fits more on screen */
  table.mobile-cards td { padding: 7px 0 !important; min-height: 34px; }
  table.mobile-cards tr { padding: 8px 10px; }

  /* kill the horizontal scroller once rows are cards */
  .table-responsive { overflow-x: visible !important; border: none !important; }

  /* ---- 3. Modals use the full screen ------------------------------ */
  .modal-dialog { margin: 0 !important; width: 100% !important; max-width: 100% !important; }
  .modal-content { border-radius: 0; border: none; min-height: 100vh; }
  .modal-header { position: sticky; top: 0; z-index: 5; background: #fff; border-bottom: 1px solid #e5e5e5; }
  .modal-title { font-size: 17px; }
  .modal-body { padding: 12px; }
  .modal-footer {
    position: sticky; bottom: 0; background: #fff;
    border-top: 1px solid #e5e5e5; padding: 10px 12px;
    display: flex; gap: 10px;
  }
  .modal-footer .btn { flex: 1; margin: 0 !important; }

  /* Data-entry grids (invoice line items) keep their table shape - cards
     would break column alignment - so give them a proper touch scroller
     with a hint that there is more to the right. */
  .modal .table-responsive,
  table[data-mc-skip="1"]:not(.mobile-cards) {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid #e5e5e5;
    border-radius: 4px;
  }
  .modal .table-responsive > table { min-width: 560px; margin-bottom: 0; }
  .modal .table-responsive td, .modal .table-responsive th { white-space: nowrap; }
  /* the "add item" control sits above the grid, full width */
  .modal .select2-container { width: 100% !important; margin-bottom: 8px; }

  /* ---- 4. Forms stack ------------------------------------------- */
  .form-horizontal .control-label { text-align: left; margin-bottom: 4px; font-weight: 600; }
  .col-xs-6.text-right, .col-xs-6.text-left { width: 100%; text-align: left !important; }
  .row > [class*="col-"] { margin-bottom: 10px; }

  /* ---- 5. Misc ---------------------------------------------------- */
  .select2-container { width: 100% !important; }
  .select2-dropdown { z-index: 11001; }
  .dataTables_wrapper .row > div { width: 100%; text-align: left !important; }
  .page-title, h1 { font-size: 20px; }

  /* stop long unbroken strings (item codes, arabic names) blowing layout */
  body { overflow-wrap: break-word; }

  /* ---- 6. Document previews --------------------------------------
     Invoice / quotation / delivery note / receipt previews are the
     printed document, not a list. Card layout would show the operator
     something that bears no resemblance to what comes out of the
     printer, so keep the real layout and let the page scroll sideways.
     .doc-preview is applied by mobile-enhance.js to any modal that
     contains .inv-print-title. ------------------------------------- */
  .doc-preview .modal-body {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 10px;
  }
  /* every block of the document keeps its real width; the body scrolls */
  .doc-preview .modal-body > h4,
  .doc-preview .modal-body > div { min-width: 660px; }

  /* these previews are never carded, so undo the phone table rules */
  .doc-preview .table-responsive {
    overflow-x: visible !important;
    border: none !important;
    display: block;
    width: auto;
    border-radius: 0;
  }
  .doc-preview .table-responsive.box-bdr { border: 1px solid #f1f1f1 !important; }
  .doc-preview .table-responsive > table { min-width: 0; margin-bottom: 0; }
  .doc-preview .table-responsive td,
  .doc-preview .table-responsive th { white-space: normal !important; }

  /* the header holds Print / Arabic / Download / Email / Close - let them
     wrap onto a second line instead of pushing the title off-screen */
  .doc-preview .modal-header { padding: 8px 10px; }
  .doc-preview .modal-header .btn { min-height: 36px; padding: 7px 10px; font-size: 13px; margin-bottom: 4px; }
  .doc-preview .modal-footer { display: block; }
}
