/* Design portato dall'app Expo: stessi colori, card bianche su fondo #eef2f4,
   header blu #0a7ea4, tab bar in basso. */

:root {
  --primary: #0a7ea4;
  --primary-dark: #086483;
  --bg: #eef2f4;
  --card: #ffffff;
  --text: #1a2b34;
  --muted: #6b7780;
  --light: #9aa5ad;
  --faint: #c2cad0;
  --border: #e2e8ec;
  --ok: #2e9e4f;
  --sopra: #d63a3a;
  --sotto: #e8920c;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
}

/* --- Header + tab bar (come l'app) ------------------------------------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--primary);
  color: #fff;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header h1 { font-size: 17px; font-weight: 700; }

.header-links { display: flex; align-items: center; gap: 4px; }

.header-link {
  color: #cde7f1;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 8px;
}

.header-link-active { background: rgba(255, 255, 255, 0.18); }

.impersonation-bar {
  position: sticky;
  top: 0;
  z-index: 9;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #fff3d6;
  color: #8a6100;
  font-size: 13px;
  padding: 8px 14px;
  border-bottom: 1px solid #f0dfae;
}

.impersonation-bar button {
  background: #8a6100;
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.app-main {
  max-width: 560px;
  margin: 0 auto;
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 82px);
}

/* Pagine larghe (es. tabella): su desktop usano tutto lo spazio disponibile. */
.app-main-wide { max-width: 1100px; }

.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  background: #fff;
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 6px;
  text-decoration: none;
  color: var(--light);
}

.tab-icon { font-size: 22px; line-height: 1; }
.tab-label { font-size: 11px; font-weight: 600; }
.tab-active { color: var(--primary); }

/* Pannello "Altro": <details> dentro la tab bar, così si apre e si chiude
   anche senza JavaScript. Il riquadro è ancorato al bordo alto della barra
   (bottom: 100% del suo padding box, safe-area compresa). */

.tab-more { position: static; }

.tab-more-summary {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  list-style: none;
}

.tab-more-summary::-webkit-details-marker { display: none; }
.tab-more[open] > .tab-more-summary { color: var(--primary); }

/* Velo dietro al pannello: copre tutto (header e barre comprese) tranne la tab
   bar, che sale a 21 quando il pannello e' aperto. */
body:has(#tab-more[open])::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(10, 30, 40, 0.32);
}

.tab-bar:has(#tab-more[open]) { z-index: 21; }

.more-sheet {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.12);
  padding: 6px 0;
  max-height: 60dvh;
  overflow-y: auto;
}

.more-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  text-decoration: none;
  color: var(--text);
}

.more-item:active { background: var(--bg); }

.more-icon { font-size: 20px; width: 24px; text-align: center; flex: none; }
.more-text { display: flex; flex-direction: column; min-width: 0; }
.more-label { font-size: 15px; font-weight: 600; }
.more-hint { font-size: 12px; color: var(--light); }

.more-item-active { background: #eaf5f9; }
.more-item-active .more-label { color: var(--primary); }

.more-item-quit {
  border-top: 1px solid var(--bg);
  margin-top: 4px;
  padding-top: 13px;
}

.more-item-quit .more-label { color: var(--sopra); }

/* Su schermi larghi il pannello non deve occupare tutta la riga. */
@media (min-width: 600px) {
  .more-sheet {
    left: auto;
    right: 8px;
    width: 300px;
    border-radius: 14px 14px 0 0;
    border: 1px solid var(--border);
  }
}

/* --- Elementi comuni ----------------------------------------------------- */

.card {
  background: var(--card);
  border-radius: 14px;
  padding: 14px;
  margin: 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.card-title { font-size: 15px; font-weight: 700; margin-bottom: 8px; }

.banner {
  background: #d8edf4;
  color: #0a5d78;
  margin: 12px 12px 0;
  border-radius: 10px;
  padding: 12px;
  font-size: 13px;
  line-height: 18px;
}

.banner-success { background: #ddf3e4; color: #1c6b38; }

.alert {
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}

.alert-error { background: #fbe3e3; color: #a32626; }
.alert-success { background: #ddf3e4; color: #1c6b38; }
.banner-error { background: #fbe3e3; color: #a32626; }

.btn-primary {
  display: block;
  width: 100%;
  background: var(--primary);
  color: #fff;
  border: 0;
  border-radius: 12px;
  padding: 14px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 18px;
}

.btn-primary:active { background: var(--primary-dark); }

.btn-delete {
  display: block;
  width: 100%;
  background: none;
  border: 0;
  color: var(--sopra);
  font-size: 14px;
  font-weight: 600;
  padding: 12px;
  margin-top: 4px;
  cursor: pointer;
}

.empty-state { text-align: center; padding: 64px 24px; }
.empty-icon { font-size: 44px; margin-bottom: 12px; }
.empty-text { font-size: 16px; font-weight: 600; }
.empty-hint { font-size: 14px; color: var(--light); margin-top: 4px; }

.swatch {
  width: 10px;
  height: 28px;
  border-radius: 3px;
  margin-right: 10px;
  flex: none;
}

/* --- Calendario ----------------------------------------------------------- */

.calendar { padding: 10px; }

.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
}

.cal-nav {
  font-size: 28px;
  line-height: 30px;
  color: var(--primary);
  text-decoration: none;
  padding: 2px 14px;
}

.cal-title { font-size: 17px; font-weight: 700; text-transform: capitalize; }

.cal-week { display: flex; }

.cal-weekday {
  flex: 1;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--light);
  padding: 6px 0;
}

.cal-cell {
  flex: 1;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 1px;
}

.cal-day { border-radius: 10px; text-decoration: none; }
.cal-day:hover { background: #f0f6f9; }

.cal-num { font-size: 15px; font-weight: 500; color: var(--text); }

.cal-today .cal-num { color: var(--primary); font-weight: 800; }

.cal-selected { background: var(--primary); }
.cal-selected:hover { background: var(--primary); }
.cal-selected .cal-num { color: #fff; font-weight: 700; }

.cal-dot {
  width: 6px;
  height: 6px;
  border-radius: 3px;
  margin-top: 3px;
  background: transparent;
}

.cal-dot-on { background: var(--ok); }

/* --- Form giornata ---------------------------------------------------------- */

.entry-form { padding: 16px; margin-bottom: 24px; }

.entry-title {
  font-size: 17px;
  font-weight: 700;
  text-transform: capitalize;
  margin-bottom: 14px;
}

.save-status {
  font-size: 12px;
  font-weight: 600;
  color: var(--light);
  text-transform: none;
  margin-left: 6px;
}

.save-status.saved { color: var(--ok); }
.save-status.error { color: var(--sopra); }

.entry-group { margin-bottom: 14px; }

.entry-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.measure-note-input {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 5px 2px 5px 20px;
  font-size: 12px;
  font-style: italic;
  font-family: inherit;
  color: var(--muted);
  background: transparent;
  margin-top: 2px;
}

.measure-note-input::placeholder { color: var(--faint); font-style: italic; }
.measure-note-input:focus { outline: none; border-bottom-color: var(--primary); }

.entry-label-wrap { display: flex; align-items: center; flex: 1; padding-right: 10px; }
.entry-labels { display: flex; flex-direction: column; }
.entry-label { font-size: 15px; font-weight: 600; }
.entry-hint { font-size: 11px; color: var(--light); margin-top: 1px; }
.entry-note-label { display: block; margin-top: 6px; }

.entry-input-wrap { display: flex; align-items: center; }

.num-input {
  width: 76px;
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  background: #fff;
}

.num-input::placeholder { color: var(--faint); }
.num-input:focus { outline: none; border-color: var(--primary); }
.num-input.status-ok { border-color: var(--ok); }
.num-input.status-sopra { border-color: var(--sopra); }
.num-input.status-sotto { border-color: var(--sotto); }

.entry-unit { width: 46px; margin-left: 6px; font-size: 12px; color: var(--light); }

.note-input {
  width: 100%;
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  min-height: 44px;
  margin-top: 6px;
  resize: vertical;
}

.note-input::placeholder { color: var(--faint); }
.note-input:focus { outline: none; border-color: var(--primary); }

/* --- Tabella ------------------------------------------------------------------ */

.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
}

.range-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.range-btn {
  padding: 7px 11px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}

.range-btn.range-active { background: var(--primary); border-color: var(--primary); color: #fff; }

.range-custom { display: flex; align-items: center; gap: 4px; }

.range-sep { color: var(--light); font-size: 12px; }

.date-input {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 5px 6px;
  font-size: 12px;
  font-family: inherit;
  color: var(--muted);
}

.date-input.range-active { border-color: var(--primary); color: var(--primary); font-weight: 600; }
.date-input:focus { outline: none; border-color: var(--primary); }

.export-count { font-weight: 400; color: var(--light); }

.btn-export {
  display: inline-block;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
}

.btn-export:active { background: var(--bg); }

/* La tabella è una card; lo scroll orizzontale compare solo se le colonne
   non ci stanno (in pratica solo su mobile: overflow-x auto non fa nulla
   quando il contenuto entra nel contenitore). */
.table-scroll {
  overflow-x: auto;
  background: #fff;
  margin: 0 12px 12px;
  border-radius: 14px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.data-table { border-collapse: collapse; width: 100%; }

.data-table tbody tr:last-child td { border-bottom: 0 !important; }

.data-table thead th {
  background: var(--primary);
  border-bottom: 1px solid var(--primary-dark);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 8px 4px;
  text-align: center;
  min-width: 86px;
}

.th-date { width: 90px; min-width: 70px !important; text-align: left !important; padding: 12px 8px !important; font-size: 13px !important; }

.th-swatch { display: block; width: 18px; height: 4px; border-radius: 2px; margin: 0 auto 2px; }
.th-label { display: block; }
.th-unit { display: block; color: #cde7f1; font-size: 9px; font-weight: 400; margin-top: 1px; }

.data-table td { padding: 14px 4px; text-align: center; }

.row-alt td { background: #f7fafb; }

tr.has-note td { padding-bottom: 4px; }

.td-date { text-align: left !important; padding: 14px 8px !important; }
.td-date a { font-size: 13px; font-weight: 600; color: var(--text); text-decoration: none; }
.td-val { font-size: 15px; font-weight: 700; }
.td-empty { color: var(--faint); font-weight: 400; }

.td-val-note {
  display: block;
  max-width: 110px;
  margin: 3px auto 0;
  font-size: 10px;
  font-weight: 400;
  font-style: italic;
  color: var(--muted);
  line-height: 1.3;
  overflow-wrap: break-word;
}

.td-note {
  text-align: left !important;
  font-size: 12px;
  font-style: italic;
  color: var(--muted);
  padding: 0 10px 10px !important;
  border-bottom: 1px solid var(--bg);
}

tr:not(.has-note) td { border-bottom: 1px solid var(--bg); }

/* --- Grafici -------------------------------------------------------------------- */

.period-row { display: flex; gap: 8px; padding: 12px 12px 0; }

.period-btn {
  flex: 1;
  text-align: center;
  padding: 8px 0;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
}

.period-active { background: var(--primary); border-color: var(--primary); color: #fff; }

.chart-wrap { position: relative; height: 220px; }
.chart-wrap-sm { height: 200px; }

.legend-row { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 6px; }
.legend-item { display: inline-flex; align-items: center; font-size: 12px; color: var(--muted); }
.legend-dot { width: 10px; height: 10px; border-radius: 5px; margin-right: 4px; }

.keto-avg { font-size: 13px; color: var(--sopra); font-weight: 600; margin-top: 8px; }
.peso-avg { font-size: 13px; color: #5c6bc0; font-weight: 600; margin-top: 8px; }

.stats-row { display: flex; justify-content: space-around; margin-top: 8px; }
.stat { display: flex; flex-direction: column; align-items: center; }
.stat-pct { font-size: 22px; font-weight: 800; }
.stat-label { font-size: 13px; font-weight: 600; margin-top: 2px; }
.stat-count { font-size: 11px; color: var(--light); }

/* --- Profilo / amministrazione ------------------------------------------------------ */

.profile-meta { font-size: 12px; color: var(--light); margin-bottom: 10px; }

.user-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid var(--bg);
}

.user-row:last-child { border-bottom: 0; }

.user-info { display: flex; flex-direction: column; }
.user-name { font-size: 15px; font-weight: 700; }
.user-you { font-size: 12px; font-weight: 400; color: var(--light); }
.user-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

.user-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.inline-form { display: flex; gap: 6px; align-items: center; }

.btn-small {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
  white-space: nowrap;
}

.btn-small:active { background: var(--bg); }
.btn-small-danger { color: var(--sopra); }

.input-small {
  width: 150px;
  padding: 6px 8px !important;
  font-size: 12px !important;
  border-width: 1px !important;
}

/* --- Richieste (appunti per il diabetologo) ------------------------------------------ */

.req-empty { font-size: 13px; color: var(--light); padding: 4px 0; }

.req-row { padding: 12px 0; border-bottom: 1px solid var(--bg); }
.req-row:last-child { border-bottom: 0; padding-bottom: 4px; }

.req-text { font-size: 15px; font-weight: 600; line-height: 1.35; overflow-wrap: break-word; }
.req-meta { font-size: 12px; color: var(--light); margin-top: 2px; }

.req-actions { display: flex; gap: 6px; align-items: center; margin-top: 8px; }

.req-close-form { display: flex; gap: 6px; align-items: center; flex: 1; }

.req-note-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
}

.req-note-input::placeholder { color: var(--faint); }
.req-note-input:focus { outline: none; border-color: var(--primary); }

.req-closed .req-text {
  color: var(--muted);
  font-weight: 500;
  text-decoration: line-through;
}

.req-closed-note {
  font-size: 13px;
  font-style: italic;
  color: var(--muted);
  margin-top: 4px;
  overflow-wrap: break-word;
}

/* --- Acqua (bevute e obiettivo giornaliero) ------------------------------------------ */

.acqua-progress {
  position: relative;
  height: 36px;
  background: var(--bg);
  border-radius: 18px;
  overflow: hidden;
  margin-top: 10px;
}

.acqua-progress-fill {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  background: #bfe0ee;
  transition: width 0.3s;
}

.acqua-progress-ok .acqua-progress-fill { background: #c9ecd5; }

.acqua-progress-text {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 15px;
  font-weight: 800;
  color: var(--primary-dark);
}

.acqua-progress-ok .acqua-progress-text { color: #1c6b38; }

.acqua-goal-msg {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--ok);
  margin-top: 8px;
}

.acqua-quick-row { display: flex; gap: 8px; margin-top: 12px; }
.acqua-quick-row form { flex: 1; }

.acqua-quick-btn {
  width: 100%;
  background: #f0f8fb;
  border: 1px solid #cde7f1;
  border-radius: 10px;
  padding: 10px 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  cursor: pointer;
  white-space: nowrap;
}

.acqua-quick-btn:active { background: #cde7f1; }

.acqua-add-form { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.acqua-select {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
}

.acqua-select:focus { outline: none; border-color: var(--primary); }

.acqua-ml-input {
  width: 80px;
  padding: 7px 8px;
  font-size: 14px;
  border-width: 1px;
}

.acqua-unit { font-size: 12px; color: var(--light); }

.bev-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--bg);
}

.bev-row:last-child { border-bottom: 0; }

.bev-icon { font-size: 22px; }
.bev-info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.bev-tipo { font-size: 14px; font-weight: 600; }
.bev-ora { font-size: 12px; color: var(--light); }
.bev-ml { font-size: 15px; font-weight: 700; }

.bev-del {
  background: none;
  border: 0;
  font-size: 15px;
  cursor: pointer;
  padding: 4px 6px;
}

/* Giorni del calendario Acqua: verde = obiettivo raggiunto, rosso = sotto. */
.cal-goal-ok { background: #ddf3e4; }
.cal-goal-ok .cal-num { color: #1c6b38; font-weight: 700; }
.cal-goal-ok .cal-ml { color: #1c6b38; }
.cal-goal-no { background: #fbe3e3; }
.cal-goal-no .cal-num { color: #a32626; }
.cal-goal-no .cal-ml { color: #a32626; }

.cal-ml { font-size: 9px; font-weight: 600; color: var(--light); margin-top: 1px; }
.cal-selected .cal-ml { color: #cde7f1; }

.acqua-legend { display: flex; gap: 14px; justify-content: center; padding: 8px 0 4px; }

.acqua-goal-hint { font-size: 12px; color: var(--light); margin-top: 8px; }

/* --- Login / registrazione -------------------------------------------------------- */

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px 16px;
}

.auth-card {
  background: var(--card);
  border-radius: 14px;
  padding: 28px 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
  text-align: center;
}

.auth-logo { font-size: 44px; margin-bottom: 8px; }
.auth-title { font-size: 22px; font-weight: 800; color: var(--primary); }
.auth-subtitle { font-size: 13px; color: var(--muted); margin: 6px 0 20px; }

.auth-form { text-align: left; }

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin: 12px 0 4px;
}

.text-input {
  width: 100%;
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  color: var(--text);
}

.text-input:focus { outline: none; border-color: var(--primary); }

.auth-alt { font-size: 13px; color: var(--muted); margin-top: 18px; }
.auth-alt a { color: var(--primary); font-weight: 600; }

/* --- Timer -------------------------------------------------------------------- */

.timer-card { padding: 22px 16px; text-align: center; }

.timer-countdown {
  font-size: 54px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: 1px;
  /* Cifre a larghezza fissa: il countdown non "balla" mentre scala. */
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum';
  line-height: 1.1;
}

.timer-sub { font-size: 13px; color: var(--muted); margin-top: 8px; }
.timer-card-expired .timer-countdown { color: var(--sopra); }

.timer-alert {
  background: #fbe3e3;
  border: 2px solid var(--sopra);
  border-radius: 14px;
  padding: 18px 16px;
  margin-bottom: 12px;
  text-align: center;
  animation: timer-pulse 1.2s ease-in-out 3;
}

.timer-alert-title { font-size: 22px; font-weight: 800; color: #a32626; }
.timer-alert-text { font-size: 14px; color: #7d2020; margin: 6px 0 14px; }

@keyframes timer-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(214, 58, 58, 0); }
  50% { box-shadow: 0 0 0 8px rgba(214, 58, 58, 0.18); }
}

.timer-form { display: flex; flex-direction: column; gap: 10px; }

.timer-field { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.timer-duration { display: flex; align-items: center; gap: 6px; }

.timer-num {
  width: 62px;
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 9px 8px;
  font-size: 17px;
  font-weight: 700;
  font-family: inherit;
  text-align: center;
  color: var(--text);
  background: #fff;
}

.timer-num:focus { outline: none; border-color: var(--primary); }
.timer-unit { font-size: 13px; color: var(--muted); margin-right: 4px; }

/* Scorciatoie sotto il pulsante: riempiono la durata con un tocco solo. */
.timer-presets { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }

/* Ritocchi al timer in corso: "+15 min", "-5 min". */
.timer-adjust {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin: 14px 0 4px;
}

.timer-status { font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.timer-status-ok { color: var(--ok); font-weight: 600; }
.timer-status-warn { color: var(--sotto); }

.timer-hint { font-size: 12px; color: var(--light); margin-top: 10px; line-height: 1.5; }
.timer-hint-warn { color: var(--sotto); }
.timer-hint code { background: var(--bg); padding: 1px 4px; border-radius: 4px; }

.timer-history-row {
  display: flex;
  gap: 10px;
  padding: 7px 0;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.timer-history-row:first-of-type { border-top: none; }
.timer-history-when { color: var(--light); white-space: nowrap; }
.timer-history-what { color: var(--muted); }

/* Barra di avviso in cima a tutte le pagine quando un timer è scaduto. */
.timer-bar {
  position: sticky;
  top: 0;
  z-index: 9;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #fbe3e3;
  color: #a32626;
  font-size: 13px;
  padding: 10px 14px;
  border-bottom: 1px solid #f0c2c2;
  text-decoration: none;
}

.timer-bar-go { font-weight: 700; white-space: nowrap; }

/* --- Alimenti (catalogo personale) --------------------------------------- */

.ali-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.ali-toolbar .card-title { margin: 0; flex: 1; min-width: 0; }

.btn-add {
  flex: none;
  background: var(--primary);
  color: #fff;
  border: 0;
  border-radius: 9px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.btn-add:active { background: var(--primary-dark); }

.ali-search {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

.ali-search-icon { font-size: 14px; flex: none; }

.ali-search-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  -webkit-appearance: none;
}

.ali-search-input::placeholder { color: var(--faint); }
.ali-search-input:focus { outline: none; border-color: var(--primary); }

.ali-search .btn-small { text-decoration: none; display: inline-block; }

.ali-empty { font-size: 13px; color: var(--light); padding: 4px 0; }

.ali-row { padding: 11px 0; border-bottom: 1px solid var(--bg); }
.ali-row:last-child { border-bottom: 0; padding-bottom: 4px; }

.ali-head { display: flex; align-items: baseline; gap: 6px; }

.ali-nome {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.ali-badges {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
}

/* Matita in fondo alla riga del nome: sta sempre nello stesso punto, qualunque
   sia la lunghezza del nome o il numero di pastiglie. */
.ali-edit-btn {
  position: relative;
  flex: none;
  align-self: center;
  display: flex;
  padding: 2px 0 2px 6px;
  color: var(--primary);
  text-decoration: none;
}

.ali-edit-btn svg { width: 17px; height: 17px; display: block; }

/* L'icona da sola sarebbe un bersaglio da 17px: l'area toccabile la allargo
   con uno pseudo-elemento, così non fa crescere la riga. */
.ali-edit-btn::after {
  content: '';
  position: absolute;
  inset: -13px -12px -13px -10px;
}

.ali-edit-btn:active { color: var(--primary-dark); }

.ali-badge {
  background: #eaf5f9;
  color: var(--primary);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

/* Gli zuccheri sono una quota dei carboidrati: pastiglia più tenue, così si
   legge come un dettaglio del valore accanto e non come un secondo totale. */
.ali-badge-zuc {
  background: var(--bg);
  color: var(--muted);
  font-weight: 600;
}

.ali-desc {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
  margin-top: 3px;
  overflow-wrap: anywhere;
}

/* --- Modale alimento (stesso form per inserire e modificare) --------------- */

.ali-modal {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: none;
  max-height: none;
}

/* Aperto: centrato e fisso. Vale sia per showModal() sia per il <dialog open>
   servito dal server quando JavaScript non c'è. */
.ali-modal[open] {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 12px;
  overflow: hidden;
}

.ali-modal::backdrop { background: rgba(10, 30, 40, 0.45); }

/* Senza showModal() il backdrop non esiste: lo disegno con un velo interno. */
.ali-modal[open]::before {
  content: '';
  position: fixed;
  inset: 0;
  background: rgba(10, 30, 40, 0.45);
}

.ali-modal:modal::before { content: none; }

.ali-modal-form {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 440px;
  max-height: 100%;
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.ali-modal-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--bg);
}

.ali-modal-head h2 { font-size: 16px; font-weight: 700; flex: 1; }

.ali-modal-x {
  flex: none;
  font-size: 16px;
  line-height: 1;
  color: var(--light);
  text-decoration: none;
  padding: 6px 8px;
  border-radius: 8px;
}

.ali-modal-x:active { background: var(--bg); }

.ali-modal-body { padding: 12px 14px 14px; overflow-y: auto; }

.ali-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin: 12px 0 5px;
}

.ali-modal-body > .ali-label:first-of-type { margin-top: 0; }
.ali-label span { font-weight: 500; color: var(--light); }

.ali-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
}

.ali-input::placeholder { color: var(--faint); }
.ali-input:focus { outline: none; border-color: var(--primary); }

.ali-textarea { resize: vertical; line-height: 1.4; }

.ali-nutri { display: flex; gap: 12px; }
.ali-nutri-campo { flex: 1; min-width: 0; }
.ali-nutri-campo .ali-label { margin-top: 14px; }

.ali-nutri-input { display: flex; align-items: center; gap: 6px; }
.ali-input-num { width: 100%; min-width: 0; text-align: center; }
.ali-unita { font-size: 11px; color: var(--light); white-space: nowrap; }

.ali-nutri-nota {
  font-size: 12px;
  color: var(--light);
  line-height: 1.4;
  margin-top: 8px;
}

.ali-modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--bg);
  background: #fbfcfd;
}

.ali-modal-spazio { flex: 1; }
.ali-modal-actions .btn-small { text-decoration: none; }

.btn-modal-salva {
  background: var(--primary);
  color: #fff;
  border: 0;
  border-radius: 9px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.btn-modal-salva:active { background: var(--primary-dark); }

/* Su schermi molto stretti l'etichetta "g / 100 g" va sotto al campo. */
@media (max-width: 359px) {
  .ali-nutri-input { flex-direction: column; align-items: stretch; gap: 3px; }
  .ali-unita { text-align: center; }
}
