/* =========================================================================
   ASIA-CON Invoice System - Mobile responsive layer
   -------------------------------------------------------------------------
   EVERYTHING here is wrapped in a max-width media query, so on tablets/PC
   (>= 768px) nothing below applies and the existing desktop view is 100%
   unchanged. These rules only shape the "mobile view" on phones.
   ========================================================================= */

@media (max-width: 767px) {

  /* Let content use the full width; AdminLTE already off-canvases the sidebar. */
  .content-wrapper,
  .right-side,
  .main-footer {
    margin-left: 0 !important;
  }

  .content-wrapper > .content,
  section.content {
    padding: 8px 10px !important;
  }

  /* Comfortable base font + avoid iOS focus zoom jumping around. */
  body {
    font-size: 15px;
  }
  .content-wrapper .form-control,
  .content-wrapper input,
  .content-wrapper select,
  .content-wrapper textarea {
    font-size: 16px !important;
  }

  /* ---- Stack the fixed xs grid the forms use --------------------------- */
  /* Bootstrap 3 col-xs-* never stack on their own; on phones we make the
     app's form columns full width so fields aren't crammed 3-across.       */
  .content-wrapper [class*="col-xs-"] {
    float: none !important;
    width: 100% !important;
    left: auto !important;
    right: auto !important;
  }
  /* Drop the desktop offsets (e.g. invoice totals col-xs-offset-5). */
  .content-wrapper [class*="col-xs-offset-"] {
    margin-left: 0 !important;
  }

  /* Panels / headings tighter on small screens. */
  .content-wrapper .panel-body {
    padding: 10px;
  }
  .content-wrapper .panel-heading h4 {
    font-size: 1.05rem;
  }
  h1 {
    font-size: 1.5rem;
  }

  /* ---- Wide DATA tables (list/report pages) scroll horizontally -------- */
  /* pwa.js wraps standalone data tables in .table-responsive. The invoice
     product table and attachment table are deliberately left untouched so the
     critical add/edit UI is never affected — they just fit the screen. */
  .content-wrapper .table-responsive {
    width: 100%;
    margin-bottom: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 0;
  }
  #data-table {
    min-width: 560px;
  }

  /* Inline fixed-width fields (e.g. the notes textarea) must not overflow. */
  .content-wrapper textarea,
  .content-wrapper input,
  .content-wrapper select {
    max-width: 100% !important;
  }
  .content-wrapper textarea[style] {
    width: 100% !important;
  }

  /* ---- Bigger, easier tap targets ------------------------------------- */
  .content-wrapper .btn {
    padding: 9px 14px;
  }
  /* Full-width primary action buttons so they're easy to hit. */
  .content-wrapper .btn.float-right,
  .content-wrapper #action_edit_invoice,
  .content-wrapper #submit_attach,
  .content-wrapper #action_create_invoice {
    float: none !important;
    display: block;
    width: 100%;
    margin-top: 6px;
  }
  .content-wrapper .btn-group.float-right {
    float: none !important;
    width: 100%;
  }

  /* Invoice totals block: left-align instead of the desktop right offset. */
  #invoice_totals.text-right {
    text-align: left !important;
  }
  #invoice_totals #rate_usd {
    display: inline-block;
    width: auto;
    max-width: 160px;
  }

  /* Invoice preview / print area and attachment iframes fit the screen. */
  .print_area,
  .invoice-container,
  .page-content.container {
    width: 100% !important;
    max-width: 100% !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
  }
  .print_area iframe,
  #attachFrame {
    height: 60vh !important;
  }

  /* DataTables toolbar wraps instead of overflowing. */
  .dataTables_wrapper .row > div {
    width: 100%;
    text-align: left !important;
    margin-bottom: 6px;
  }
  .dataTables_filter input {
    width: 100%;
  }

  /* ---- Login page (index.php) ----------------------------------------- */
  .vertical-offset-100 {
    padding-top: 30px !important;
  }
  .login-panel {
    margin: 0 8px;
  }

  /* Respect notches / rounded corners on modern phones. */
  .main-header,
  .main-sidebar {
    padding-left: env(safe-area-inset-left);
  }
}

/* Small phones: tighten padding a touch. */
@media (max-width: 480px) {
  #data-table {
    min-width: 480px;
  }
  .content-wrapper section.content,
  .content-wrapper > .content {
    padding: 6px !important;
  }
}

/* -------------------------------------------------------------------------
   Installed-PWA nicety (applies on any screen size): a small "Install app"
   button that pwa.js reveals only when the browser says it's installable.
   Hidden by default so it never shows in normal desktop browsing.
   ------------------------------------------------------------------------- */
#pwaInstallBtn {
  display: none;
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 2000;
  background: #1e374b;
  color: #fff;
  border: 0;
  border-radius: 24px;
  padding: 10px 18px;
  font-size: 14px;
  box-shadow: 0 6px 18px rgba(16, 45, 63, .3);
  cursor: pointer;
}
#pwaInstallBtn.show {
  display: inline-block;
}
