/* ============================================================
   Aistamine.com — Main Stylesheet
   © VisualSense.it — Tutti i diritti riservati
   Palette: Blu #1B4F8A (primario) — Professionale
   ============================================================ */

:root {
  --primary:       #1B4F8A;
  --primary-dark:  #153E6E;
  --primary-light: #E8F0FA;
  --primary-mid:   #3D6FA8;
  --text-dark:     #1A1A2E;
  --text-mid:      #4A5568;
  --text-light:    #718096;
  --text-muted:    #A0ADB8;
  --bg-white:      #FFFFFF;
  --bg-light:      #F5F8FC;
  --bg-surface:    #EEF3FA;
  --border:        #D8E4F0;
  --border-mid:    #B8CDE0;
  /* Stato */
  --success:       #2E7D32;
  --warning:       #E65100;
  --danger:        #C62828;
  --info:          #0277BD;
  --radius-sm:     6px;
  --radius-md:     10px;
  --radius-lg:     16px;
  --shadow-sm:     0 1px 4px rgba(27,79,138,.08);
  --shadow-md:     0 4px 16px rgba(27,79,138,.12);
  --transition:    all .2s ease;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; overflow-x: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-dark);
  background: var(--bg-light);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  width: 100%;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; display: block; }
ul, ol { list-style: none; }

/* ============ LAYOUT ============ */
.container { max-width: 1200px; margin: 0 auto; padding: 0 24px; }
.container-sm { max-width: 720px; margin: 0 auto; padding: 0 24px; }
.page-wrapper { display: flex; min-height: 100vh; }

/* ============ NAVBAR ============ */
.navbar {
  background: var(--primary);
  padding: 0 24px;
  display: flex;
  align-items: center;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
}
.navbar-brand { display: flex; align-items: center; gap: 10px; }
.navbar-brand img { height: 34px; }
.navbar-logo {
  height: 38px;
  width: auto;
  display: block;
  max-width: 230px;
  object-fit: contain;
}
.navbar-brand span { color: #fff; font-size: 18px; font-weight: 700; letter-spacing: -.3px; }
.navbar-nav { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.navbar-nav a {
  color: rgba(255,255,255,.85);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  transition: var(--transition);
}
.navbar-nav a:hover { background: rgba(255,255,255,.12); text-decoration: none; color: #fff; }
.navbar-nav a.active { background: rgba(255,255,255,.2); color: #fff; font-weight: 500; }
.navbar-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: #fff;
  cursor: pointer;
}

/* ── Language switcher (home only) ─────────────────── */
.lang-switcher {
  position: relative;
  margin-left: 8px;
}
.lang-switcher-btn {
  display: flex;
  align-items: center;
  gap: 2px;
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 20px;
  padding: 4px 10px 4px 8px;
  cursor: pointer;
  transition: background .15s;
}
.lang-switcher-btn:hover { background: rgba(255,255,255,.25); }
.lang-switcher-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
  overflow: hidden;
  min-width: 150px;
  z-index: 500;
}
.lang-switcher.open .lang-switcher-menu { display: block; }
.lang-switcher-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  font-size: 13px;
  color: #1A1A2E;
  text-decoration: none;
  transition: background .1s;
}
.lang-switcher-item:hover { background: #F5F8FC; }
.lang-switcher-item.current { font-weight: 700; color: #1B4F8A; background: #E8F0FA; }

/* ============ SIDEBAR (Dashboard) ============ */
.sidebar {
  width: 240px;
  min-height: calc(100vh - 60px);
  background: var(--bg-white);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  flex-shrink: 0;
}
.sidebar-section { padding: 4px 12px; margin-bottom: 4px; }
.sidebar-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  padding: 8px 12px 4px;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-mid);
  transition: var(--transition);
  cursor: pointer;
}
.sidebar-link:hover { background: var(--bg-surface); color: var(--primary); text-decoration: none; }
.sidebar-link.active { background: var(--primary-light); color: var(--primary); font-weight: 500; }
.sidebar-link-cycle,
.sidebar-link-cycle:hover,
.sidebar-link-cycle:focus,
.sidebar-link-cycle.active { color: #BE185D !important; background: #FDF2F8 !important; }
.sidebar-link-cycle svg { stroke: #BE185D !important; }
.sidebar-link svg { width: 17px; height: 17px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 1.8; }
.main-content { flex: 1; padding: 28px 32px; min-width: 0; }

/* ============ CARDS ============ */
.card {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
}
.card-title { font-size: 15px; font-weight: 600; color: var(--text-dark); margin-bottom: 16px; }
.card-sm { padding: 14px 16px; border-radius: var(--radius-md); }

/* ============ METRIC CARDS ============ */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 14px; }
.metric-card {
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  padding: 16px;
}
.metric-label { font-size: 11px; color: var(--text-light); font-weight: 500; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; }
.metric-value { font-size: 26px; font-weight: 700; color: var(--text-dark); line-height: 1; }
.metric-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 20px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  border: 1.5px solid transparent;
  line-height: 1.4;
  text-decoration: none;
}
.btn svg { width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 1.8; }
.btn-primary   { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); text-decoration: none; color: #fff; }
.btn-secondary { background: var(--bg-white); color: var(--primary); border-color: var(--border-mid); }
.btn-secondary:hover { background: var(--primary-light); border-color: var(--primary); text-decoration: none; }
.btn-danger    { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #A82222; text-decoration: none; color: #fff; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-lg { padding: 13px 28px; font-size: 16px; }
.btn-block { width: 100%; justify-content: center; }
.btn-google {
  background: #fff;
  color: #444;
  border: 1.5px solid var(--border-mid);
  font-weight: 500;
}
.btn-google:hover { background: #f5f5f5; text-decoration: none; }
.btn-google img { width: 18px; height: 18px; }

/* ============ FORMS ============ */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--text-mid); margin-bottom: 6px; }
.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 16px; /* Minimo 16px per evitare auto-zoom su iOS Safari */
  color: var(--text-dark);
  background: #fff;
  transition: var(--transition);
  outline: none;
  appearance: none;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(27,79,138,.12); }
.form-control::placeholder { color: var(--text-muted); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* Checkbox / Radio */
.form-check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.form-check input[type=checkbox],
.form-check input[type=radio] { width: 16px; height: 16px; accent-color: var(--primary); flex-shrink: 0; margin-top: 2px; }
.form-check-label { font-size: 13px; color: var(--text-mid); line-height: 1.5; }

/* Range slider */
input[type=range] {
  width: 100%;
  accent-color: var(--primary);
  height: 4px;
  cursor: pointer;
}

/* ============ ALERTS ============ */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 2px; stroke: currentColor; fill: none; stroke-width: 2; }
.alert-danger  { background: #FFEBEE; border: 1px solid #FFCDD2; color: var(--danger); }
.alert-success { background: #E8F5E9; border: 1px solid #C8E6C9; color: var(--success); }
.alert-warning { background: #FFF3E0; border: 1px solid #FFE0B2; color: var(--warning); }
.alert-info    { background: var(--primary-light); border: 1px solid #B8D0F0; color: var(--primary); }

/* ============ SEMAFORO BADGE ============ */
.badge-tolerance {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-A { background: var(--tol-a-bg);   color: var(--tol-a-text); }
.badge-B { background: var(--tol-b-bg);   color: var(--tol-b-text); }
.badge-C { background: var(--tol-c-bg);   color: var(--tol-c-text); }
.badge-D { background: var(--tol-d-bg);   color: var(--tol-d-text); }
.badge-E { background: var(--tol-e-bg);   color: var(--tol-e-text); }
.badge-\? { background: #E5E7EB;           color: #9CA3AF; }

/* Dot semaforo inline */
.dot-tolerance { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-A { background: var(--tol-a-bg); }
.dot-B { background: var(--tol-b-bg); }
.dot-C { background: var(--tol-c-bg); }
.dot-D { background: var(--tol-d-bg); }
.dot-E { background: var(--tol-e-bg); }

/* ============ FOOD TAG ============ */
.food-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  margin: 2px;
  cursor: default;
  max-width: 100%;
  word-break: break-word;
  flex-shrink: 1;
  min-width: 0;
}
.food-tag-A { background: var(--tol-a-tag-bg); color: var(--tol-a-tag-text); }
.food-tag-B { background: var(--tol-b-tag-bg); color: var(--tol-b-tag-text); }
.food-tag-C { background: var(--tol-c-tag-bg); color: var(--tol-c-tag-text); }
.food-tag-D { background: var(--tol-d-tag-bg); color: var(--tol-d-tag-text); }
.food-tag-E { background: var(--tol-e-tag-bg); color: var(--tol-e-tag-text); }

/* ============ DIARIO ============ */
.diary-day-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.diary-day-nav button {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-mid);
  transition: var(--transition);
}
.diary-day-nav button:hover { border-color: var(--primary); color: var(--primary); }
.diary-date { font-size: 16px; font-weight: 600; color: var(--text-dark); }
.today-badge {
  font-size: 11px;
  background: var(--primary-light);
  color: var(--primary);
  padding: 2px 10px;
  border-radius: 20px;
  font-weight: 600;
}
.meal-block {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 10px;
  background: var(--bg-white);
  transition: var(--transition);
}
.meal-block:hover { border-color: var(--border-mid); }
.meal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.meal-type-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-mid);
}
.meal-type-label svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.8; }

/* ============ SINTOMI ============ */
.symptom-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.symptom-row:last-child { border-bottom: none; }
.symptom-name { flex: 0 0 140px; color: var(--text-mid); font-size: 13px; }
.intensity-bar { flex: 1; height: 5px; background: var(--bg-surface); border-radius: 3px; overflow: hidden; }
.intensity-fill { height: 100%; border-radius: 3px; }
.intensity-val { flex: 0 0 36px; text-align: right; font-size: 12px; color: var(--text-muted); }

/* ============ AI BOX ============ */
.ai-panel {
  background: #E8F0FA;
  border: 1px solid #B5D4F4;
  border-radius: var(--radius-md);
  padding: 14px 16px;
}
.ai-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 8px;
}
.ai-panel-header svg { width: 14px; height: 14px; stroke: var(--primary); fill: none; stroke-width: 2; }
.ai-text { font-size: 13px; color: #185FA5; line-height: 1.6; }
.ai-input-row { display: flex; gap: 8px; margin-top: 10px; }
.ai-input-row input {
  flex: 1;
  padding: 8px 12px;
  font-size: 13px;
  border: 1px solid #B5D4F4;
  border-radius: var(--radius-md);
  background: #fff;
  color: var(--text-dark);
  outline: none;
}
.ai-input-row input:focus { border-color: var(--primary); }
.ai-input-row button {
  padding: 8px 16px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}
.ai-input-row button:hover { background: var(--primary-dark); }

/* ============ TABELLE ============ */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; padding: 10px 14px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-light); border-bottom: 2px solid var(--border); }
td { padding: 11px 14px; border-bottom: 1px solid var(--border); color: var(--text-dark); vertical-align: middle; }
tr:hover td { background: var(--bg-light); }
tr:last-child td { border-bottom: none; }

/* ============ SEARCH BAR ============ */
.search-bar {
  position: relative;
  max-width: 480px;
}
.search-bar svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  stroke: var(--text-muted);
  fill: none;
  stroke-width: 2;
}
.search-bar input {
  width: 100%;
  padding: 10px 14px 10px 40px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  outline: none;
  background: #fff;
  transition: var(--transition);
}
.search-bar input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(27,79,138,.1); }

/* ============ COOKIE BANNER ============ */
.cookie-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 2px solid var(--primary);
  padding: 16px 24px;
  z-index: 9999;
  box-shadow: 0 -4px 20px rgba(0,0,0,.1);
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}
.cookie-banner-text { flex: 1; font-size: 13px; color: var(--text-mid); min-width: 260px; }
.cookie-banner-actions { display: flex; gap: 10px; flex-shrink: 0; }
#cookie-banner { display: none; }
#cookie-banner.show { display: flex; }

/* ============ GDPR / LEGAL ============ */
.legal-content { max-width: 760px; margin: 0 auto; padding: 40px 24px; }
.legal-content h1 { font-size: 26px; font-weight: 700; color: var(--primary); margin-bottom: 8px; }
.legal-content h2 { font-size: 18px; font-weight: 600; color: var(--text-dark); margin: 28px 0 10px; }
.legal-content p, .legal-content li { font-size: 14px; color: var(--text-mid); line-height: 1.8; margin-bottom: 10px; }
.legal-content ul { list-style: disc; padding-left: 20px; }

/* ============ TOAST ============ */
#toast {
  display: none;
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1A1A2E;
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 13px;
  font-weight: 500;
  z-index: 2000;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  pointer-events: none;
  max-width: calc(100vw - 48px);
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============ FOOTER ============ */
.footer {
  background: var(--primary);
  color: rgba(255,255,255,.75);
  text-align: center;
  padding: 18px 24px;
  font-size: 12px;
  margin-top: auto;
}
.footer a { color: rgba(255,255,255,.9); }
.footer a:hover { color: #fff; }
.footer-links { display: flex; justify-content: center; gap: 16px; margin-bottom: 6px; flex-wrap: wrap; }

/* ============ UTILITIES ============ */
.text-primary { color: var(--primary); }
.text-muted   { color: var(--text-muted); }
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.text-sm      { font-size: 13px; }
.text-xs      { font-size: 11px; }
.fw-600       { font-weight: 600; }
.mt-4         { margin-top: 4px; }
.mt-8         { margin-top: 8px; }
.mt-16        { margin-top: 16px; }
.mt-24        { margin-top: 24px; }
.mb-16        { margin-bottom: 16px; }
.mb-24        { margin-bottom: 24px; }
.d-flex       { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8        { gap: 8px; }
.gap-12       { gap: 12px; }
.gap-16       { gap: 16px; }
.w-100        { width: 100%; }
.hidden       { display: none !important; }

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-content { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .navbar-nav .nav-text { display: none; }
  .cookie-banner { flex-direction: column; }
  /* Prevent iOS Safari auto-zoom on input focus (requires font-size >= 16px) */
  input, select, textarea, .form-control { font-size: 16px !important; }
}
@media (max-width: 480px) {
  .metric-grid { grid-template-columns: 1fr; }
  .btn-lg { padding: 11px 20px; font-size: 15px; }
}

/* ============================================================
   MOBILE FIRST — Ottimizzazione smartphone completa
   ============================================================ */

/* Hamburger button */
.navbar-hamburger {
  display: none;
  flex-direction: column;
  gap: 5px;
  cursor: pointer;
  padding: 6px;
  margin-left: auto;
  background: none;
  border: none;
}
.navbar-hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: var(--transition);
}

/* Mobile nav overlay */
.mobile-nav {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
}
.mobile-nav.open { display: block; }
.mobile-nav-panel {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 280px;
  background: #fff;
  overflow-y: auto;
  box-shadow: 4px 0 24px rgba(0,0,0,.15);
  transform: translateX(-100%);
  transition: transform .25s ease;
}
.mobile-nav.open .mobile-nav-panel { transform: translateX(0); }
.mobile-nav-header {
  background: var(--primary);
  padding: 20px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.mobile-nav-header span { color: #fff; font-size: 17px; font-weight: 700; }
.mobile-nav-close {
  color: rgba(255,255,255,.8);
  font-size: 22px;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0 4px;
  line-height: 1;
}
.mobile-nav-body { padding: 12px 0; }
.mobile-nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 20px;
  font-size: 15px;
  color: var(--text-mid);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  transition: var(--transition);
}
.mobile-nav-link:hover,
.mobile-nav-link.active { background: var(--primary-light); color: var(--primary); text-decoration: none; }
.mobile-nav-link svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; flex-shrink: 0; }
.mobile-nav-section {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text-muted);
  padding: 14px 20px 4px;
}

/* Bottom navigation bar (mobile) */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid var(--border);
  z-index: 100;
  padding: 0;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav-inner {
  display: flex;
  justify-content: space-around;
  align-items: stretch;
}
.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 4px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
  gap: 3px;
  transition: var(--transition);
  border: none;
  background: none;
  cursor: pointer;
}
.bottom-nav-item svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.bottom-nav-item.active,
.bottom-nav-item:hover { color: var(--primary); }
.bottom-nav-item.active svg { stroke: var(--primary); }

@media (max-width: 768px) {
  /* Nascondi sidebar desktop */
  .sidebar { display: none !important; }

  /* Hamburger visibile */
  .navbar-hamburger { display: flex; }

  /* Navbar più compatta */
  .navbar { padding: 0 16px; height: 54px; }
  .navbar-brand img { height: 28px; }
  .navbar-logo { height: 30px; max-width: 180px; }
  .navbar-brand span { font-size: 16px; }

  /* Nascondi link desktop nella navbar */
  .navbar-nav > a,
  .navbar-nav > .navbar-avatar,
  .navbar-nav > a[href*="logout"] { display: none; }

  /* Mostra bottom nav */
  .bottom-nav { display: block; }

  /* Spazio per bottom nav */
  .main-content { 
    padding: 16px 14px 80px; 
    min-height: calc(100vh - 54px);
  }
  /* Il footer è in flusso DOPO il main-content: la bottom-nav fixed lo coprirebbe.
     Aggiungiamo spazio pari all'altezza della nav + safe-area (notch/gesture bar). */
  .footer {
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
  }
  .page-wrapper { flex-direction: column; }

  /* Griglie 2 colonne → 1 colonna su mobile */
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  [style*="grid-template-columns:2fr 1fr"],
  [style*="grid-template-columns: 2fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  [style*="grid-template-columns:260px 1fr"],
  [style*="grid-template-columns: 260px 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Metric grid 2 col su mobile */
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 10px; }

  /* Form row → 1 colonna */
  .form-row { grid-template-columns: 1fr !important; }

  /* Card padding ridotto */
  .card { padding: 14px 16px; }

  /* Titoli più piccoli */
  h1[style*="font-size:20px"] { font-size: 17px !important; }

  /* Bottoni full width dove ha senso */
  .btn-block-mobile { width: 100% !important; justify-content: center !important; }

  /* Diary nav */
  .diary-day-nav { gap: 8px; justify-content: space-between; }
  .diary-date { font-size: 14px; }

  /* Search bar full width */
  .search-bar { max-width: 100% !important; }

  /* AI panel input */
  .ai-input-row { flex-direction: row; }
  .ai-input-row input { font-size: 16px; }

  /* Nascondi colonna ordine ricette su mobile */
  .recipe-detail { display: block !important; }

  /* Table scroll orizzontale */
  .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 500px; }

  /* Toast posizione mobile */
  #toast {
    left: 16px !important;
    right: 16px !important;
    bottom: 72px !important;
    transform: none !important;
    white-space: normal !important;
    word-break: break-word;
    text-align: center;
    max-width: calc(100vw - 32px) !important;
  }

  /* Modal full screen su mobile */
  [id$="-modal"] > div {
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    border-radius: 20px 20px 0 0 !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    max-height: 92vh !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    padding: 20px 14px !important;
    box-sizing: border-box !important;
  }

  /* Food entries non escono dal viewport */
  [id^="meal-"][id$="-foods"] > div {
    flex-wrap: wrap;
    max-width: 100%;
    overflow: hidden;
  }
  .food-tag {
    max-width: calc(100vw - 120px);
    font-size: 11px;
    padding: 3px 10px;
  }

  /* Barcode result non esce dal viewport */
  #barcode-result { overflow-x: hidden; word-break: break-word; }
  #barcode-result div { max-width: 100% !important; }
  #barcode-result [style*="display:flex"] { flex-wrap: wrap !important; gap: 5px !important; }
  #barcode-result [style*="font-size:16px"] { font-size: 14px !important; }
  #barcode-result [style*="font-size:13px"] { font-size: 12px !important; }
  #barcode-result [style*="padding:14px"] { padding: 10px !important; }

  /* Input nel modale: previene zoom iOS */
  #add-food-modal input[type="text"],
  #add-food-modal input[type="number"],
  #add-food-modal select {
    font-size: 16px !important;
  }

  /* Cookie banner */
  .cookie-banner { flex-direction: column; gap: 12px; padding: 14px 16px; }
  .cookie-banner-actions { width: 100%; justify-content: space-between; }

  /* Legal pages */
  .legal-content { padding: 20px 16px 80px; }
  .legal-content h1 { font-size: 20px; }
}

@media (max-width: 380px) {
  .metric-grid { grid-template-columns: 1fr; }
  .navbar-brand span { display: none; }
  .navbar-logo { height: 26px; max-width: 155px; }
}

/* Legal pages */
.legal-content { max-width: 780px; margin: 0 auto; padding: 40px 24px 60px; }
.legal-content h1 { font-size: 26px; font-weight: 800; color: #1B4F8A; margin-bottom: 4px; }
.legal-date { color: #A0ADB8; font-size: 13px; margin-bottom: 28px; }
.legal-content h2 { font-size: 17px; font-weight: 700; color: #1A202C; margin-top: 32px; margin-bottom: 10px; padding-bottom: 6px; border-bottom: 1px solid #EDF2F7; }
.legal-content h3 { font-size: 14px; font-weight: 600; color: #4A5568; margin-top: 18px; margin-bottom: 8px; }
.legal-content p, .legal-content li { font-size: 14px; color: #4A5568; line-height: 1.7; }
.legal-content ul { padding-left: 20px; margin-bottom: 16px; }
.legal-content li { margin-bottom: 6px; }
.legal-content a { color: #1B4F8A; }
.legal-box { background: #F5F8FC; border: 1px solid #E2E8F0; border-radius: 8px; padding: 16px 20px; font-size: 14px; color: #4A5568; line-height: 1.7; margin: 12px 0 20px; }
.legal-table { width: 100%; border-collapse: collapse; margin: 12px 0 20px; font-size: 13px; }
.legal-table th { background: #F5F8FC; color: #1A202C; font-weight: 600; text-align: left; padding: 10px 12px; border: 1px solid #E2E8F0; }
.legal-table td { padding: 10px 12px; border: 1px solid #E2E8F0; color: #4A5568; }
@media (max-width: 600px) { .legal-content { padding: 24px 16px 40px; } .legal-table { font-size: 12px; } }


/* ── Fix overflow orizzontale mobile ──────────────────────────
   Approccio chirurgico: fix solo gli elementi problematici noti
   senza rompere i layout desktop.                              */

/* Regola base: tabelle scrollabili orizzontalmente */
table { max-width: 100%; }
.table-wrapper, .an-table { overflow-x: auto; -webkit-overflow-scrolling: touch; display: block; }

@media (max-width: 768px) {
  /* Nessun elemento supera il viewport */
  .main-content > * { max-width: 100%; overflow-x: hidden; }

  /* Search bar */
  .search-bar { max-width: 100% !important; width: 100% !important; }
  #level-filter { width: 100% !important; }

  /* Cookie banner: in colonna su mobile */
  #cookie-banner > div { flex-direction: column !important; }

  /* Flex row che contengono bottoni: wrap */
  .btn-row, .action-row { flex-wrap: wrap !important; }

  /* Onboarding e modali: max 100% viewport */
  .ob-row { grid-template-columns: 1fr !important; }

  /* Analytics: barre max width */
  .an-bar { max-width: 80px !important; }
  .funnel-fill { max-width: calc(100% - 100px) !important; }

  /* Griglia metriche biometrics e altri */
  .stats-grid, .bio-grid { grid-template-columns: 1fr 1fr !important; }

  /* Bottoni action nelle card: sempre wrap */
  .card-actions { flex-wrap: wrap !important; gap: 8px !important; }

  /* Prevenzione overflow da testo lungo */
  p, span, div, td, th, li { word-break: break-word; overflow-wrap: break-word; }

  /* Code e pre: scroll invece di overflow */
  pre, code { overflow-x: auto; white-space: pre-wrap; word-break: break-all; }
}

@media (max-width: 480px) {
  /* Su schermi molto piccoli: griglia a 1 colonna */
  .metric-grid { grid-template-columns: 1fr !important; }
  .ob-form .form-row { grid-template-columns: 1fr !important; }
}
