/* ==========================================================
   fg_mobile.css - visualizzazione mobile/tablet per tutto il gestionale
   ========================================================== */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
input, textarea, select, button, a, label, summary { touch-action: manipulation; -webkit-tap-highlight-color: rgba(31,157,85,.15); }
input, textarea, select { -webkit-user-select: text; user-select: text; }

@media (max-width: 900px), (pointer: coarse) {
  /* campi: 16px = nessuno zoom automatico, altezza comoda per il pollice */
  input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=hidden]):not([type=color]):not([type=file]),
  select, textarea { font-size: 16px !important; min-height: 46px; padding-top: 10px; padding-bottom: 10px; max-width: 100%; box-sizing: border-box; }
  textarea { min-height: 90px; }
  input[type=checkbox], input[type=radio] { width: 22px; height: 22px; flex: 0 0 22px; }
  label { cursor: pointer; }
  button, .btn, .btn-primary, .btn-secondary, .btn-danger, .btn-action, [type=submit], [type=button] { min-height: 44px; }
}

@media (max-width: 768px) {
  body { overflow-x: hidden; }
  .main-content, main, .content, .container { padding-left: 12px !important; padding-right: 12px !important; max-width: 100% !important; }
  h1 { font-size: 22px !important; line-height: 1.2; } h2 { font-size: 19px !important; } h3 { font-size: 17px !important; }
  .card, .panel, .box { padding: 14px !important; border-radius: 12px; }

  /* barre di strumenti e righe flessibili: vanno a capo invece di uscire dallo schermo */
  .main-content div[style*="display:flex"], .main-content div[style*="display: flex"],
  .page-header, .header-actions, .toolbar, .filters, .filter-bar, .search-wrapper, .actions, .btn-group, .dt-buttons { flex-wrap: wrap !important; gap: 8px; }
  .page-header, .header-actions, .search-wrapper { align-items: stretch !important; }
  .page-header > *, .header-actions > * { max-width: 100%; }
  .search-wrapper { justify-content: stretch !important; }
  .custom-search, .search-wrapper input { width: 100% !important; }
  [style*="width:300px"], [style*="width: 300px"], [style*="width:250px"], [style*="width: 250px"], [style*="width:200px"], [style*="width: 200px"] { max-width: 100% !important; }
  .btn, .btn-primary, .btn-secondary, .btn-danger { white-space: normal; }
  .dt-buttons { display: flex; width: 100%; } .dt-buttons .dt-button { flex: 1 1 30%; min-height: 42px; }

  /* DataTables: ricerca e paginazione a tutta larghezza */
  .dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_paginate { float: none !important; text-align: center !important; display: block; margin: 6px 0; }
  .dataTables_wrapper .dataTables_paginate .paginate_button { padding: 10px 14px !important; }

  /* tabelle -> schede: ogni riga diventa un riquadro con etichetta + valore */
  table.fg-cards { display: block !important; width: 100% !important; border: 0 !important; }
  table.fg-cards thead { display: none !important; }
  table.fg-cards tbody, table.fg-cards tfoot { display: block !important; width: 100%; }
  table.fg-cards tr { display: block !important; width: 100%; box-sizing: border-box; margin: 0 0 12px; padding: 6px 10px; background: #fff; border: 1px solid #e3e8e4 !important; border-radius: 12px; box-shadow: 0 1px 4px rgba(0,0,0,.05); }
  table.fg-cards td { display: flex !important; justify-content: space-between; align-items: center; gap: 12px; width: 100% !important; box-sizing: border-box; padding: 8px 4px !important; border: 0 !important; border-bottom: 1px dashed #eee !important; text-align: right !important; word-break: break-word; }
  table.fg-cards td:last-child { border-bottom: 0 !important; }
  table.fg-cards td::before { content: attr(data-label); flex: 0 0 38%; max-width: 45%; text-align: left; font-weight: 700; font-size: 12px; color: #6b7c72; text-transform: uppercase; letter-spacing: .02em; }
  table.fg-cards td[data-label=""]::before, table.fg-cards td:not([data-label])::before { display: none; }
  table.fg-cards td[colspan] { justify-content: center; text-align: center !important; }
  table.fg-cards td input, table.fg-cards td select { max-width: 60%; }
  table.fg-cards td .btn, table.fg-cards td button, table.fg-cards td a.btn { margin-left: 6px; }
  table.fg-cards td.text-right, table.fg-cards td:last-child { flex-wrap: wrap; }

  /* finestre (modal): a tutto schermo, scorrevoli, con pulsanti raggiungibili */
  .modal-content, .modal-box, .modal-content-small, .modal-dialog { width: 100% !important; max-width: 100% !important; height: auto; max-height: 94vh !important; margin: 0 auto !important; border-radius: 14px 14px 0 0 !important; overflow-y: auto !important; -webkit-overflow-scrolling: touch; box-sizing: border-box; }
  .modal.active, .modal.show, .modal[style*="display: flex"], .modal[style*="display:flex"] { align-items: flex-end !important; }
  .form-grid, .form-row, .row, .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr !important; }
  .form-row, .row { flex-direction: column !important; }
  .form-group { margin-bottom: 12px; }
  iframe { max-width: 100%; }
  img { max-width: 100%; height: auto; }
  pre, code { white-space: pre-wrap; word-break: break-word; }
}

/* quando la tastiera e' aperta lascio spazio sotto i campi */
body.kb-aperta { padding-bottom: 25vh !important; }
@supports (padding: max(0px)) { body { padding-left: max(0px, env(safe-area-inset-left)); padding-right: max(0px, env(safe-area-inset-right)); } }
@media (max-width: 768px) {
  table.fg-cards td button, table.fg-cards td a.btn, table.fg-cards td .btn-action, table.fg-cards td .btn-icon { min-width: 48px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  table.fg-cards td:last-child { justify-content: flex-end; gap: 8px; }
}
