/* ===========================================
   GESTIOLEX - Mobile Responsive Styles
   Ottimizzazioni per dispositivi mobile
   =========================================== */

/* ===========================================
   VARIABILI MOBILE
   =========================================== */
:root {
  --mobile-padding: 12px;
  --touch-target-min: 44px;
  --mobile-font-base: 16px;
}

/* ===========================================
   GLOBAL MOBILE RULES (max-width: 767.98px)
   =========================================== */
@media (max-width: 767.98px) {
  
  /* --- BASE & TYPOGRAPHY --- */
  body {
    font-size: var(--mobile-font-base);
    -webkit-text-size-adjust: 100%;
  }
  
  /* Evita zoom su focus input iOS */
  input, select, textarea {
    font-size: 16px !important;
  }
  
  /* Padding ridotto per contenuto */
  .app-content {
    padding: var(--mobile-padding) !important;
  }
  
  .container-fluid {
    padding-left: var(--mobile-padding);
    padding-right: var(--mobile-padding);
  }
  
  /* --- TOUCH TARGETS --- */
  /* Pulsanti con dimensione minima touch-friendly */
  .btn {
    min-height: var(--touch-target-min);
    padding: 10px 16px;
  }
  
  .btn-sm {
    min-height: 38px;
    padding: 8px 12px;
  }
  
  .btn-lg {
    min-height: 52px;
  }
  
  /* Link e elementi cliccabili */
  .nav-link,
  .dropdown-item,
  .list-group-item-action {
    min-height: var(--touch-target-min);
    padding-top: 12px;
    padding-bottom: 12px;
  }
  
  /* --- CARDS --- */
  .card {
    margin-bottom: 12px;
    border-radius: 8px;
  }
  
  .card-header {
    padding: 12px;
  }
  
  .card-body {
    padding: 12px;
  }
  
  .card-footer {
    padding: 12px;
  }
  
  /* Stack cards verticalmente */
  .row > [class*="col-lg-"],
  .row > [class*="col-md-"] {
    margin-bottom: 12px;
  }
  
  /* --- HEADINGS --- */
  h1, .h1 { font-size: 1.75rem; }
  h2, .h2 { font-size: 1.5rem; }
  h3, .h3 { font-size: 1.25rem; }
  h4, .h4 { font-size: 1.1rem; }
  
  /* --- FORMS --- */
  .form-control {
    min-height: var(--touch-target-min);
    padding: 10px 12px;
    font-size: 16px;
  }
  
  .form-select {
    min-height: var(--touch-target-min);
    padding: 10px 12px;
    font-size: 16px;
  }
  
  .form-check {
    min-height: var(--touch-target-min);
    padding-top: 8px;
    padding-bottom: 8px;
  }
  
  .form-check-input {
    width: 20px;
    height: 20px;
    margin-top: 2px;
  }
  
  .form-label {
    margin-bottom: 6px;
    font-weight: 500;
  }
  
  /* Form layout: stack su mobile */
  .row.g-3 > [class*="col-"] {
    margin-bottom: 12px;
  }
  
  /* --- MODALS --- */
  .modal-dialog {
    margin: 8px;
    max-width: calc(100% - 16px);
  }
  
  .modal-header {
    padding: 12px 16px;
  }
  
  .modal-body {
    padding: 16px;
  }
  
  .modal-footer {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }
  
  .modal-footer .btn {
    flex: 1 1 auto;
    min-width: 120px;
  }
  
  /* --- ALERTS --- */
  .alert {
    padding: 12px;
    font-size: 0.9rem;
  }
  
  .alert-dismissible .btn-close {
    padding: 16px;
  }
  
  /* --- DROPDOWNS --- */
  .dropdown-menu {
    font-size: 0.95rem;
  }
  
  .dropdown-item {
    padding: 12px 16px;
  }
  
  /* --- BADGE --- */
  .badge {
    padding: 6px 10px;
    font-size: 0.8rem;
  }
}

/* ===========================================
   TABLET RULES (768px - 991.98px)
   =========================================== */
@media (min-width: 768px) and (max-width: 991.98px) {
  .app-content {
    padding: 1rem;
  }
  
  .btn {
    min-height: 40px;
  }
}

/* ===========================================
   NAVBAR MOBILE
   =========================================== */
@media (max-width: 767.98px) {
  /* Navbar più compatta */
  .navbar {
    padding: 8px 12px;
  }
  
  .navbar-brand {
    font-size: 1rem;
  }
  
  .navbar-brand img {
    height: 20px !important;
  }
  
  /* Badge notifiche più visibile */
  #notifications-badge {
    font-size: 0.6rem !important;
    padding: 3px 5px;
  }
  
  /* Dropdown notifiche full-width */
  .notifications-dropdown {
    position: fixed !important;
    top: 56px !important;
    left: 8px !important;
    right: 8px !important;
    width: auto !important;
    max-width: none !important;
    transform: none !important;
  }
  
  /* Menu navbar collassato */
  .navbar-collapse {
    max-height: calc(100vh - 56px);
    overflow-y: auto;
  }
  
  .navbar-nav {
    padding: 8px 0;
  }
  
  .navbar-nav .nav-link {
    padding: 12px 16px;
  }
  
  .navbar-nav .dropdown-menu {
    border: none;
    background: rgba(0,0,0,0.05);
    padding-left: 16px;
  }
}

/* ===========================================
   BREADCRUMB MOBILE
   =========================================== */
@media (max-width: 767.98px) {
  .breadcrumb-wrapper {
    margin-bottom: 12px;
    padding: 8px 0;
  }
  
  .breadcrumb {
    font-size: 0.8rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  
  .breadcrumb::-webkit-scrollbar {
    display: none;
  }
  
  .breadcrumb-item {
    flex-shrink: 0;
  }
  
  /* Nascondi livelli intermedi se troppo lunghi */
  .breadcrumb-item:not(:first-child):not(:last-child) {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* ===========================================
   FAB MOBILE
   =========================================== */
@media (max-width: 767.98px) {
  .fab-container {
    bottom: 16px;
    left: 16px;
  }
  
  .fab-main {
    width: 52px;
    height: 52px;
    font-size: 22px;
  }
  
  .fab-action-btn {
    width: 42px;
    height: 42px;
  }
  
  /* Menu espanso più visibile */
  .fab-container.open .fab-menu {
    gap: 8px;
  }
}

/* ===========================================
   DASHBOARD MOBILE
   =========================================== */
@media (max-width: 767.98px) {
  /* Saluto più compatto */
  .app-content > .row.g-3.mb-4:first-child h2 {
    font-size: 1.25rem;
  }
  
  /* Box riepilogo: 2 colonne invece di 4 */
  .app-content .col-6.col-md-3 {
    flex: 0 0 50%;
    max-width: 50%;
  }
  
  /* Azioni rapide: 2 colonne */
  .app-content .col-6.col-md-4 {
    flex: 0 0 50%;
    max-width: 50%;
  }
  
  /* Pulsanti azioni rapide più touch-friendly */
  .app-content .col-6.col-md-4 .btn {
    font-size: 0.85rem;
    padding: 10px 8px;
  }
}

/* ===========================================
   LISTE E ELENCHI MOBILE
   =========================================== */
@media (max-width: 767.98px) {
  .list-group-item {
    padding: 12px;
  }
  
  /* Pratiche/Persone list: layout verticale */
  .list-group-item .d-flex.justify-content-between {
    flex-direction: column;
    gap: 8px;
  }
  
  .list-group-item .btn-group {
    width: 100%;
    justify-content: flex-end;
  }
}

/* ===========================================
   SIDEBAR MOBILE (già in sidebar.css, rinforzo)
   =========================================== */
@media (max-width: 767.98px) {
  .app-sidebar {
    width: 85vw;
    max-width: 280px;
  }
  
  .sidebar-nav .nav-link {
    padding: 14px 16px;
    font-size: 1rem;
  }
  
  .sidebar-search {
    max-width: 100%;
    padding: 12px;
  }
  
  .sidebar-search input {
    font-size: 16px;
    padding: 10px 12px;
  }
}

/* ===========================================
   UTILITY CLASSES MOBILE
   =========================================== */
@media (max-width: 767.98px) {
  /* Nascondi su mobile */
  .d-mobile-none {
    display: none !important;
  }
  
  /* Mostra solo su mobile */
  .d-mobile-block {
    display: block !important;
  }
  
  .d-mobile-flex {
    display: flex !important;
  }
  
  /* Full width su mobile */
  .w-mobile-100 {
    width: 100% !important;
  }
  
  /* Stack verticale su mobile */
  .flex-mobile-column {
    flex-direction: column !important;
  }
  
  /* Gap ridotto su mobile */
  .gap-mobile-2 {
    gap: 0.5rem !important;
  }
  
  /* Text center su mobile */
  .text-mobile-center {
    text-align: center !important;
  }
  
  /* Margin/padding mobile */
  .mb-mobile-3 {
    margin-bottom: 1rem !important;
  }
  
  .p-mobile-2 {
    padding: 0.5rem !important;
  }
}

/* ===========================================
   TABELLE RESPONSIVE
   =========================================== */

/* Wrapper per scroll orizzontale */
.table-responsive-mobile {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 767.98px) {
  /* Tutte le tabelle diventano scrollabili */
  .table {
    min-width: 600px;
  }
  
  /* Container tabella con scroll */
  .table-responsive,
  .table-responsive-sm,
  .table-responsive-md {
    margin: 0 -12px;
    padding: 0 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Tabella più compatta */
  .table-sm th,
  .table-sm td {
    padding: 8px 6px;
    font-size: 0.85rem;
  }
  
  /* Pulsanti azioni più compatti */
  .table .btn-sm {
    padding: 4px 8px;
    font-size: 0.75rem;
    min-height: 32px;
  }
  
  .table .btn-group {
    flex-wrap: nowrap;
  }
  
  .table .btn-group .btn {
    white-space: nowrap;
  }
  
  /* Nascondi testo pulsanti, mostra solo icone */
  .table .btn-action-text {
    display: none;
  }
  
  /* Colonne con priorità (da nascondere su mobile) */
  .table .col-hide-mobile {
    display: none;
  }
  
  /* Header filtri più compatti */
  .table thead tr:nth-child(2) th {
    padding: 4px;
  }
  
  .table thead input.form-control,
  .table thead select.form-select {
    font-size: 0.8rem;
    padding: 4px 8px;
    min-height: 32px;
  }
  
  /* Indica scroll con ombra */
  .table-scroll-indicator {
    position: relative;
  }
  
  .table-scroll-indicator::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 20px;
    background: linear-gradient(to right, transparent, rgba(0,0,0,0.05));
    pointer-events: none;
  }
}

/* ===========================================
   CARD VIEW ALTERNATIVA PER TABELLE
   (usare classe .table-card-mobile)
   =========================================== */
@media (max-width: 575.98px) {
  .table-card-mobile {
    display: block;
    min-width: auto !important;
  }
  
  .table-card-mobile thead {
    display: none;
  }
  
  .table-card-mobile tbody {
    display: block;
  }
  
  .table-card-mobile tr {
    display: block;
    margin-bottom: 12px;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  }
  
  .table-card-mobile td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border: none;
    border-bottom: 1px solid #f0f0f0;
  }
  
  .table-card-mobile td:last-child {
    border-bottom: none;
    padding-top: 12px;
    justify-content: flex-end;
  }
  
  .table-card-mobile td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 0.8rem;
    color: #666;
    text-transform: uppercase;
    flex-shrink: 0;
    margin-right: 12px;
  }
  
  .table-card-mobile td:last-child::before {
    display: none;
  }
}

/* ===========================================
   AZIONI TABELLA MOBILE
   =========================================== */
@media (max-width: 767.98px) {
  /* Pulsanti azione in colonna quando troppi */
  .table-actions-mobile {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  
  .table-actions-mobile .btn {
    width: 100%;
    justify-content: center;
  }
  
  /* Dropdown azioni */
  .table .dropdown-toggle::after {
    margin-left: 4px;
  }
  
  .table .dropdown-menu {
    font-size: 0.9rem;
  }
  
  .table .dropdown-item {
    padding: 10px 16px;
  }
}

/* ===========================================
   PRINT - NASCONDI ELEMENTI NON NECESSARI
   =========================================== */
@media print {
  .app-sidebar,
  .navbar,
  .fab-container,
  .fab-overlay,
  #notifications-badge,
  .breadcrumb-wrapper,
  .btn-group,
  .sidebar-overlay {
    display: none !important;
  }
  
  .app-content {
    margin: 0 !important;
    padding: 0 !important;
  }
}
