/*
 * crm-responsive.css — CRM Medicale
 * Iniettato automaticamente in tutte le pagine via after_request.
 * Mobile-first, sovrascrive Bootstrap 5.3 dove necessario.
 * ---------------------------------------------------------------
 * Breakpoint di riferimento (Bootstrap):
 *   xs  < 576px   → telefoni portrait
 *   sm  ≥ 576px   → telefoni landscape / piccoli tablet
 *   md  ≥ 768px   → tablet portrait
 *   lg  ≥ 992px   → tablet landscape / laptop
 *   xl  ≥ 1200px  → desktop
 */

/* ═══════════════════════════════════════════════════════════════
   0. VARIABILI COLORE — usabili in tutto il progetto
   ═══════════════════════════════════════════════════════════════ */
:root {
  --crm-blu:     #1b1f3b;
  --crm-blu-mid: #13233a;
  --crm-blu-lt:  #2a2e5a;
  --crm-oro:     #d4af37;
  --crm-oro-lt:  #ffd700;
  --crm-oro-dim: rgba(212, 175, 55, 0.55);
  --crm-oro-bg:  rgba(212, 175, 55, 0.08);
  --crm-text:    #f0e6c8;
  --crm-muted:   rgba(212, 175, 55, 0.45);
  --crm-border:  rgba(212, 175, 55, 0.2);
  --crm-danger:  #f8a0a8;
  --crm-success: #75d9a6;
  --crm-radius:  12px;
}

/* ═══════════════════════════════════════════════════════════════
   1. RESET & BASE
   ═══════════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  background-color: var(--crm-blu) !important;
  color: var(--crm-oro) !important;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  /* Supporto iPhone notch */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

img { max-width: 100%; height: auto; }

/* ═══════════════════════════════════════════════════════════════
   2. TIPOGRAFIA RESPONSIVE
   ═══════════════════════════════════════════════════════════════ */
h1 { font-size: clamp(1.35rem, 4vw, 2rem); }
h2 { font-size: clamp(1.15rem, 3.5vw, 1.6rem); }
h3 { font-size: clamp(1rem, 3vw, 1.3rem); }
h4 { font-size: clamp(.95rem, 2.5vw, 1.15rem); }

/* ═══════════════════════════════════════════════════════════════
   3. NAVBAR RESPONSIVE (sovrascrive custom .topbar e navbar Bootstrap)
   ═══════════════════════════════════════════════════════════════ */

/* --- CRM Navbar Bootstrap --- */
.crm-navbar,
nav.navbar {
  background: linear-gradient(90deg, #1b1f3b 0%, #13233a 100%) !important;
  border-bottom: 1px solid var(--crm-border) !important;
  padding: .5rem 1rem;
  position: sticky;
  top: 0;
  z-index: 1030;
}

.crm-navbar .navbar-brand,
nav.navbar .navbar-brand {
  color: var(--crm-oro) !important;
  font-weight: 700;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: .4rem;
}

.crm-navbar .nav-link,
nav.navbar .nav-link {
  color: rgba(212,175,55,.80) !important;
  transition: color .15s;
  padding: .4rem .7rem;
  border-radius: 8px;
}

.crm-navbar .nav-link:hover,
nav.navbar .nav-link:hover,
.crm-navbar .nav-link.active,
nav.navbar .nav-link.active { color: var(--crm-oro) !important; background: var(--crm-oro-bg); }

.crm-toggler,
.navbar-toggler {
  border: 1px solid var(--crm-border) !important;
  color: var(--crm-oro) !important;
  padding: .25rem .45rem;
}

.navbar-toggler-icon {
  filter: invert(75%) sepia(50%) saturate(400%) hue-rotate(5deg);
}

/* Dropdown dark */
.crm-dropdown,
.dropdown-menu {
  background-color: #13233a !important;
  border: 1px solid var(--crm-border) !important;
  border-radius: var(--crm-radius) !important;
}

.dropdown-item {
  color: var(--crm-oro) !important;
  font-size: .88rem;
  padding: .45rem 1rem;
}

.dropdown-item:hover { background: var(--crm-oro-bg) !important; }
.dropdown-divider { border-color: var(--crm-border) !important; }

/* Navbar mobile: collapse aperto */
@media (max-width: 991.98px) {
  .navbar-collapse {
    background: #13233a;
    border-top: 1px solid var(--crm-border);
    margin: .4rem -1rem -.5rem;
    padding: .5rem 1rem .75rem;
    border-radius: 0 0 var(--crm-radius) var(--crm-radius);
  }
  .navbar-nav .dropdown-menu {
    background: rgba(255,255,255,.03) !important;
    border: none !important;
    padding-left: 1rem;
  }
}

/* --- Custom .topbar (es: itinerari.html) --- */
.topbar {
  display: flex !important;
  align-items: center !important;
  flex-wrap: wrap !important;
  gap: .5rem !important;
  padding: .65rem 1rem !important;
  background: rgba(0,0,0,.35);
  border-bottom: 1px solid var(--crm-border);
}

.topbar h2 { flex: 1; min-width: 0; margin: 0; }

@media (max-width: 575.98px) {
  .topbar { padding: .5rem !important; }
  .topbar h2 { width: 100%; font-size: 1rem; }
}

/* ═══════════════════════════════════════════════════════════════
   4. CONTAINER & LAYOUT
   ═══════════════════════════════════════════════════════════════ */
.container,
.container-fluid {
  padding-left: 1rem !important;
  padding-right: 1rem !important;
}

/* Rimpiazza .mt-5 aggressivo su mobile */
@media (max-width: 767.98px) {
  .container.mt-5,
  .container-fluid.mt-5 { margin-top: 1rem !important; }
  .mt-5 { margin-top: 1.5rem !important; }
}

.page-wrap {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.25rem 1rem;
}

@media (max-width: 575.98px) { .page-wrap { padding: .75rem .5rem; } }

/* ═══════════════════════════════════════════════════════════════
   5. TABELLE — il problema più critico su mobile
   ═══════════════════════════════════════════════════════════════ */

/* Wrapper con scroll orizzontale — applicato automaticamente */
.table-container,
.table-responsive,
.table-responsive-crm {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--crm-radius);
}

/* Tutti i .table senza wrapper: aggiunge scroll inline */
.table-container .table { min-width: 500px; }

/* Stile colori tabella */
.table,
.table th,
.table td {
  background-color: var(--crm-blu) !important;
  color: var(--crm-oro) !important;
  border-color: var(--crm-border) !important;
  vertical-align: middle;
}

.table thead th {
  background-color: var(--crm-blu-mid) !important;
  font-size: .82rem;
  white-space: nowrap;
  padding: .55rem .75rem;
}

.table tbody td { padding: .5rem .75rem; font-size: .88rem; }

.table-striped > tbody > tr:nth-of-type(odd) > * {
  background-color: rgba(255,255,255,.025) !important;
  color: var(--crm-oro) !important;
}

.table-hover > tbody > tr:hover > * {
  background-color: rgba(212,175,55,.06) !important;
  color: var(--crm-oro) !important;
}

/* Filter input dentro <th> */
.filter-input,
thead input[type="text"] {
  display: block;
  width: 100%;
  margin-top: .3rem;
  padding: .2rem .4rem;
  font-size: .75rem;
  background: rgba(255,255,255,.06);
  border: 1px solid var(--crm-border);
  border-radius: 6px;
  color: var(--crm-text);
  min-width: 0;
}

.filter-input:focus,
thead input[type="text"]:focus {
  outline: none;
  border-color: var(--crm-oro);
  background: rgba(255,255,255,.09);
}

.filter-input::placeholder,
thead input[type="text"]::placeholder { color: var(--crm-muted); }

/* Bottoni filtro regione dentro <th> */
.filter-buttons { display: flex; gap: .25rem; flex-wrap: wrap; margin-top: .3rem; }
.filter-buttons button {
  font-size: .7rem;
  padding: .1rem .4rem;
  background: var(--crm-blu-lt);
  border: 1px solid var(--crm-border);
  color: var(--crm-oro);
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
}
.filter-buttons button:hover { background: var(--crm-oro-bg); }

/* Colonna azioni — non si schiaccia mai */
.action-buttons,
.col-icone {
  white-space: nowrap;
  text-align: center;
  min-width: 80px;
}

.action-buttons a,
.action-buttons button,
.col-icone a,
.col-icone button {
  font-size: 1.1rem;
  padding: .15rem .2rem;
  margin: 0 .1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform .1s;
}

.action-buttons a:hover { transform: scale(1.15); }

/* Layout card su schermi molto piccoli */
@media (max-width: 575.98px) {
  .table-card-sm thead { display: none; }
  .table-card-sm tbody tr {
    display: block;
    border: 1px solid var(--crm-border);
    border-radius: 10px;
    margin-bottom: .75rem;
    padding: .5rem .75rem;
    background: rgba(255,255,255,.03);
  }
  .table-card-sm tbody td {
    display: flex;
    align-items: baseline;
    gap: .5rem;
    border: none !important;
    padding: .2rem 0;
    font-size: .84rem;
  }
  .table-card-sm tbody td[data-label]::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--crm-muted);
    min-width: 110px;
    font-size: .75rem;
    flex-shrink: 0;
  }
  .table-card-sm .action-buttons {
    justify-content: flex-start;
    padding-top: .35rem;
    border-top: 1px solid var(--crm-border);
    margin-top: .35rem;
  }
}

/* ═══════════════════════════════════════════════════════════════
   6. FORM — input, select, textarea
   ═══════════════════════════════════════════════════════════════ */
.form-control,
.form-select,
input[type="text"],
input[type="email"],
input[type="date"],
input[type="number"],
input[type="tel"],
input[type="password"],
input[type="search"],
textarea,
select {
  background-color: rgba(255,255,255,.06) !important;
  border-color: var(--crm-border) !important;
  color: var(--crm-text) !important;
  border-radius: 8px !important;
  transition: border-color .2s, background .2s;
}

.form-control:focus,
.form-select:focus,
input:focus,
textarea:focus,
select:focus {
  background-color: rgba(255,255,255,.10) !important;
  border-color: var(--crm-oro) !important;
  box-shadow: 0 0 0 3px rgba(212,175,55,.15) !important;
  color: #fff !important;
  outline: none !important;
}

.form-control::placeholder { color: var(--crm-muted) !important; }

label,
.form-label {
  color: rgba(212,175,55,.80) !important;
  font-size: .85rem;
  font-weight: 500;
  margin-bottom: .3rem;
  display: block;
}

/* Su mobile: input full-width */
@media (max-width: 575.98px) {
  .row.g-2, .row.g-3 { --bs-gutter-x: .5rem; }
  .form-control, .form-select, input, textarea, select { width: 100% !important; }
}

/* ═══════════════════════════════════════════════════════════════
   7. BOTTONI
   ═══════════════════════════════════════════════════════════════ */
.btn-custom,
.btn-g {
  background-color: transparent !important;
  border: 1px solid rgba(212,175,55,.5) !important;
  color: var(--crm-oro) !important;
  border-radius: 8px !important;
  padding: .35rem .75rem !important;
  font-size: .88rem !important;
  transition: all .15s !important;
  text-decoration: none !important;
  white-space: nowrap;
  cursor: pointer;
}

.btn-custom:hover, .btn-g:hover {
  background: var(--crm-oro-bg) !important;
  border-color: var(--crm-oro) !important;
  color: var(--crm-oro) !important;
}

.btn-gold,
.btn-login,
.btn-primary {
  background: linear-gradient(135deg, #d4af37, #b8963e) !important;
  border: none !important;
  color: var(--crm-blu) !important;
  font-weight: 700 !important;
  border-radius: 8px !important;
  transition: opacity .15s !important;
}

.btn-gold:hover, .btn-login:hover, .btn-primary:hover { opacity: .9 !important; color: var(--crm-blu) !important; }

/* Gruppo bottoni responsive */
.btn-group-responsive {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  align-items: center;
}

@media (max-width: 575.98px) {
  .btn-group-responsive { gap: .3rem; }
  .btn-group-responsive .btn,
  .btn-group-responsive a { font-size: .8rem !important; padding: .3rem .6rem !important; }
}

/* Agent glow button */
.btn-agent-glow {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .35rem .8rem;
  border-radius: 14px;
  border: 1px solid rgba(212,175,55,.55) !important;
  background: linear-gradient(145deg, rgba(212,175,55,.18), rgba(255,215,0,.06)) !important;
  box-shadow: 0 0 18px rgba(212,175,55,.22);
  color: var(--crm-oro) !important;
  font-size: .85rem;
  transition: all .15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-agent-glow:hover {
  border-color: rgba(255,215,0,.75) !important;
  box-shadow: 0 0 30px rgba(255,215,0,.30);
  color: var(--crm-oro) !important;
}

.btn-outline-gold {
  background: transparent !important;
  border: 1px solid rgba(212,175,55,.5) !important;
  color: var(--crm-oro) !important;
  border-radius: 8px;
  font-size: .82rem;
  padding: .28rem .65rem;
  text-decoration: none;
  transition: all .15s;
}

.btn-outline-gold:hover { background: var(--crm-oro-bg) !important; color: var(--crm-oro) !important; }

/* ═══════════════════════════════════════════════════════════════
   8. CARD
   ═══════════════════════════════════════════════════════════════ */
.card {
  background: rgba(255,255,255,.04) !important;
  border: 1px solid var(--crm-border) !important;
  border-radius: var(--crm-radius) !important;
  color: var(--crm-oro) !important;
}

.card-header {
  background: rgba(255,255,255,.04) !important;
  border-bottom: 1px solid var(--crm-border) !important;
  color: var(--crm-oro) !important;
  font-weight: 600;
}

/* ═══════════════════════════════════════════════════════════════
   9. MODAL — full-screen su mobile
   ═══════════════════════════════════════════════════════════════ */

/* Modal Bootstrap */
.modal-content {
  background: #1b1f3b !important;
  border: 1px solid var(--crm-border) !important;
  border-radius: var(--crm-radius) !important;
  color: var(--crm-oro) !important;
}

.modal-header {
  border-bottom: 1px solid var(--crm-border) !important;
}

.modal-footer {
  border-top: 1px solid var(--crm-border) !important;
}

.modal-title { color: var(--crm-oro); font-weight: 700; }
.btn-close { filter: invert(75%) sepia(50%) saturate(400%) hue-rotate(5deg) !important; }

@media (max-width: 575.98px) {
  .modal-dialog {
    margin: 0 !important;
    max-width: 100% !important;
  }
  .modal-content {
    border-radius: 0 !important;
    min-height: 100dvh;
  }
}

/* Modal custom (fixed position) */
[id$="Modal"]:not(.modal) {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 1050;
  display: none;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 1rem;
}

[id$="Modal"]:not(.modal) > div {
  max-width: 920px;
  width: 100%;
  margin: 0 auto;
}

@media (max-width: 575.98px) {
  [id$="Modal"]:not(.modal) {
    padding: 0;
    align-items: flex-start;
  }
  [id$="Modal"]:not(.modal) > div {
    padding: 0 !important;
    max-width: 100%;
  }
  [id$="Modal"]:not(.modal) > div > div {
    border-radius: 0 !important;
    min-height: 100dvh;
  }
}

/* Modal overlay custom */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  z-index: 1050;
  display: none;
  align-items: center;
  justify-content: center;
  padding: .75rem;
}

.modal-overlay.open { display: flex; }

.modal-box {
  background: #1b1f3b;
  border: 1px solid var(--crm-border);
  border-radius: 14px;
  padding: 1.5rem;
  width: min(520px, 100%);
  max-height: 90dvh;
  overflow-y: auto;
}

@media (max-width: 575.98px) {
  .modal-box {
    border-radius: 12px 12px 0 0;
    padding: 1rem;
    max-height: 92dvh;
  }
}

/* ═══════════════════════════════════════════════════════════════
   10. ALERT / FLASH
   ═══════════════════════════════════════════════════════════════ */
.alert { border-radius: 8px !important; font-size: .88rem; }

.alert-danger  { background: rgba(220,53,69,.15)  !important; border-color: rgba(220,53,69,.4)  !important; color: #f8a0a8 !important; }
.alert-warning { background: rgba(255,193,7,.1)   !important; border-color: rgba(255,193,7,.3)  !important; color: #ffd470 !important; }
.alert-info    { background: rgba(13,202,240,.1)  !important; border-color: rgba(13,202,240,.3) !important; color: #7ee8f8 !important; }
.alert-success { background: rgba(25,135,84,.15)  !important; border-color: rgba(25,135,84,.4)  !important; color: #75d9a6 !important; }

/* ═══════════════════════════════════════════════════════════════
   11. BADGE & STATO
   ═══════════════════════════════════════════════════════════════ */
.badge { font-weight: 600; border-radius: 20px; }

/* ═══════════════════════════════════════════════════════════════
   12. TOOLBAR E GRIGLIE INTERNE
   ═══════════════════════════════════════════════════════════════ */
.toolbar {
  display: flex;
  gap: .65rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1rem;
}

@media (max-width: 575.98px) {
  .toolbar { gap: .4rem; }
  .toolbar .srch-input,
  .toolbar input,
  .toolbar select { min-width: 100%; }
}

/* Grid auto-fill (es: itinerari) */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
@media (max-width: 575.98px) { .grid { grid-template-columns: 1fr !important; } }

/* ═══════════════════════════════════════════════════════════════
   13. HEADER PAGINA — h1 + azioni allineati
   ═══════════════════════════════════════════════════════════════ */
.page-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem 1rem;
  margin-bottom: 1.25rem;
}

.page-header h1,
.page-header h2 { margin: 0; flex: 1; min-width: 0; }

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  align-items: center;
}

@media (max-width: 575.98px) {
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-actions { width: 100%; }
}

/* ═══════════════════════════════════════════════════════════════
   14. FOOTER
   ═══════════════════════════════════════════════════════════════ */
.crm-footer {
  text-align: center;
  padding: 1rem;
  font-size: .75rem;
  color: var(--crm-muted);
  border-top: 1px solid var(--crm-border);
  margin-top: 2rem;
}

/* ═══════════════════════════════════════════════════════════════
   15. USER BADGE (navbar)
   ═══════════════════════════════════════════════════════════════ */
.user-badge,
.user-badge-lg {
  color: var(--crm-muted);
  font-size: .8rem;
  display: flex;
  align-items: center;
  gap: .25rem;
  white-space: nowrap;
}

.navbar-icon { font-size: 1.2rem; }

/* ═══════════════════════════════════════════════════════════════
   16. SCROLLBAR PERSONALIZZATA (Chrome/Edge/Safari)
   ═══════════════════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: var(--crm-blu); }
::-webkit-scrollbar-thumb { background: rgba(212,175,55,.3); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(212,175,55,.55); }

/* ═══════════════════════════════════════════════════════════════
   17. PRINT — senza colori di sfondo
   ═══════════════════════════════════════════════════════════════ */
@media print {
  body { background: #fff !important; color: #000 !important; }
  .crm-navbar, nav.navbar, .topbar { display: none !important; }
  .table, .table th, .table td { background: #fff !important; color: #000 !important; border-color: #ccc !important; }
  .btn, button { display: none !important; }
}
