/* ═══════════════════════════════════════════════
   DIARIO ALIMENTARE — Francesco Longo
   main.css · Design tokens + Layout globale
   ═══════════════════════════════════════════════ */

/* ── TOKENS LIGHT ── */
[data-theme="light"] {
  --bg: #f7f4ef;
  --surface: #ffffff;
  --surface2: #f0ede6;
  --border: #e2ddd5;
  --text: #1c1a16;
  --muted: #8a8379;
  --accent: #3d6b4f;
  --accent-light: #eaf3ee;
  --accent2: #c4773b;
  --accent2-light: #fdf3eb;
  --red: #c0392b;
  --red-light: #fdf0ee;
  --blue: #2a6b7c;
  --blue-light: #e6f4f7;
  --yellow: #7a6b20;
  --yellow-light: #f9f6e6;
  --green: #4a5e2f;
  --green-light: #eef3e7;
  --purple: #6b3fa0;
  --purple-light: #f3eef9;
  --today: #2d7a85;
  --today-light: #dff0f3;
  --switch-bg: #d4cfc7;
  --switch-knob: #ffffff;
}

/* ── TOKENS DARK ── */
[data-theme="dark"] {
  --bg: #141210;
  --surface: #1e1c18;
  --surface2: #272420;
  --border: #353129;
  --text: #ede9e1;
  --muted: #6b6760;
  --accent: #5a9e72;
  --accent-light: #1a3326;
  --accent2: #d4884a;
  --accent2-light: #3a2210;
  --red: #e05c4b;
  --red-light: #3a1510;
  --blue: #4a9bb0;
  --blue-light: #0f2d35;
  --yellow: #b09a3a;
  --yellow-light: #2a2508;
  --green: #6a8a45;
  --green-light: #1a2810;
  --purple: #9b6fd0;
  --purple-light: #25183a;
  --today: #5ba8b3;
  --today-light: #0e2f33;
  --switch-bg: #5a9e72;
  --switch-knob: #ffffff;
}

/* ── RESET ── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body {
  font-family: "DM Sans", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition:
    background 0.25s,
    color 0.25s;
}

/* ── HEADER ── */
header {
  padding: 1.25rem 2rem 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  transition:
    background 0.25s,
    border-color 0.25s;
}
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  padding-bottom: 1rem;
}
.header-left h1 {
  font-family: "DM Serif Display", serif;
  font-size: 1.75rem;
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.header-left h1 span {
  font-style: italic;
  color: var(--accent);
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-logo {
  width: 30px;
  height: 30px;
  color: var(--accent);
  flex-shrink: 0;
}
.header-user {
  display: flex;
  align-items: center;
  gap: 8px;
}
.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--accent);
}
.user-avatar-initial {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.85rem;
}
.user-greeting {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
}
.user-menu {
  position: relative;
}
.user-menu summary {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  list-style: none;
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  min-width: 120px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  z-index: 100;
}
.logout-btn {
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--red);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}
.logout-btn:hover {
  background: var(--surface2);
}
.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

/* ── THEME SWITCH ── */
.theme-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}
.switch-track {
  width: 40px;
  height: 22px;
  border-radius: 11px;
  background: var(--switch-bg);
  position: relative;
  transition: background 0.25s;
  flex-shrink: 0;
}
.switch-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--switch-knob);
  transition: transform 0.25s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
[data-theme="dark"] .switch-knob {
  transform: translateX(18px);
}
.switch-icon {
  font-size: 0.85rem;
}

/* ── TABS ── */
.tabs {
  display: flex;
  gap: 6px;
  border-top: 1px solid var(--border);
  padding: 9px 0;
}
.tab {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
  letter-spacing: 0.02em;
  font-family: "DM Sans", sans-serif;
}
.tab:hover {
  color: var(--text);
  background: var(--surface2);
}
.tab.active {
  background: var(--accent);
  color: #fff;
}

/* ── MAIN LAYOUT ── */
.main {
  padding: 1.5rem 2rem;
  overflow-x: auto;
}
.section {
  display: none;
}
.section.active {
  display: block;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* ── WEEK NAV ── */
.week-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.week-nav h2 {
  font-family: "DM Serif Display", serif;
  font-size: 1.05rem;
  font-weight: 400;
}
.week-range {
  font-size: 0.73rem;
  color: var(--muted);
}
.week-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.76rem;
  cursor: pointer;
  color: var(--text);
  transition: all 0.15s;
  font-family: "DM Sans", sans-serif;
}
.week-btn:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}
.week-progress {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
  color: var(--muted);
}
.week-progress-bar {
  width: 80px;
  height: 6px;
  border-radius: 3px;
  background: var(--surface2);
  overflow: hidden;
}
.week-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s ease;
}

/* ── TABLE ── */
table {
  width: 100%;
  max-width: 1500px;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0 7px;
  min-width: 900px;
}
thead th {
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 6px 9px 5px;
  text-align: left;
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
}
thead th:first-child {
  width: 130px;
}
thead th:last-child {
  width: 130px;
}
tbody tr {
  background: var(--surface);
  transition: background 0.25s;
}
tbody tr td {
  vertical-align: top;
}
tbody tr td:first-child {
  border-radius: 14px 0 0 14px;
  width: 130px;
  min-width: 130px;
}
tbody tr td:last-child {
  border-radius: 0 14px 14px 0;
}

/* ── DAY ROW COLORS ── */
tbody tr.day-row-0 td:first-child { border-left: 3px solid #3D6B4F; }
tbody tr.day-row-1 td:first-child { border-left: 3px solid #4878A0; }
tbody tr.day-row-2 td:first-child { border-left: 3px solid #7B5EA8; }
tbody tr.day-row-3 td:first-child { border-left: 3px solid #B07B3A; }
tbody tr.day-row-4 td:first-child { border-left: 3px solid #3A8F6A; }
tbody tr.day-row-5 td:first-child,
tbody tr.day-row-6 td:first-child { border-left: 3px solid #9C6060; }

tbody tr.day-row-0 .day-name { color: #3D6B4F; }
tbody tr.day-row-1 .day-name { color: #4878A0; }
tbody tr.day-row-2 .day-name { color: #7B5EA8; }
tbody tr.day-row-3 .day-name { color: #B07B3A; }
tbody tr.day-row-4 .day-name { color: #3A8F6A; }
tbody tr.day-row-5 .day-name,
tbody tr.day-row-6 .day-name { color: #9C6060; }

[data-theme="dark"] tbody tr.day-row-0 .day-name { color: #6DB88C; }
[data-theme="dark"] tbody tr.day-row-1 .day-name { color: #74A8D4; }
[data-theme="dark"] tbody tr.day-row-2 .day-name { color: #A98ED4; }
[data-theme="dark"] tbody tr.day-row-3 .day-name { color: #D4A566; }
[data-theme="dark"] tbody tr.day-row-4 .day-name { color: #66C49A; }
[data-theme="dark"] tbody tr.day-row-5 .day-name,
[data-theme="dark"] tbody tr.day-row-6 .day-name { color: #C48888; }

/* ── DAY CELL ── */
.day-cell {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.day-name {
  font-family: "DM Serif Display", serif;
  font-size: 0.95rem;
  line-height: 1;
}
.day-date-input {
  font-size: 0.68rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 6px;
  color: var(--muted);
  background: var(--bg);
  cursor: pointer;
  width: 100%;
  font-family: "DM Sans", sans-serif;
  transition:
    border-color 0.15s,
    background 0.25s,
    color 0.25s;
}
.day-date-input:focus {
  outline: none;
  border-color: var(--accent);
}
.day-flags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.flag-btn {
  font-size: 0.62rem;
  padding: 2px 7px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  color: var(--muted);
  font-family: "DM Sans", sans-serif;
}
.flag-btn.active-sintomi {
  background: var(--red-light);
  border-color: var(--red);
  color: var(--red);
}
.flag-btn.active-wc {
  background: var(--green-light);
  border-color: var(--green);
  color: var(--green);
  font-weight: 500;
}
.wc-wrap {
  display: flex;
  align-items: center;
  gap: 3px;
}
.wc-reset-btn {
  padding: 2px 5px;
  font-size: 0.62rem;
  line-height: 1;
  opacity: 0.65;
}
.wc-reset-btn:hover {
  opacity: 1;
  background: var(--red-light);
  border-color: var(--red);
  color: var(--red);
}
.day-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: auto;
}
.save-day-btn {
  font-size: 0.64rem;
  font-weight: 500;
  padding: 3px 0;
  border-radius: 20px;
  border: none;
  background: var(--accent);
  cursor: pointer;
  color: #fff;
  transition: all 0.15s;
  font-family: "DM Sans", sans-serif;
  width: 100%;
  text-align: center;
  letter-spacing: 0.04em;
}
.save-day-btn:hover {
  filter: brightness(1.1);
}
.note-toggle {
  font-size: 0.62rem;
  padding: 2px 7px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  color: var(--muted);
  transition: all 0.15s;
  font-family: "DM Sans", sans-serif;
  width: 100%;
  text-align: center;
}
.note-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}
/* ── WEEK LEGEND ── */
.week-legend {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 1rem;
  font-size: 0.7rem;
  color: var(--muted);
}
.wl-grp { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.wl-title {
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.6rem;
}
.wl-item { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.wl-sw { width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }
.wl-dt { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.wl-sep { width: 1px; height: 16px; background: var(--border); }
.wl-c  { background: var(--yellow-light); border: 1px solid var(--yellow); }
.wl-p  { background: var(--blue-light);   border: 1px solid var(--blue); }
.wl-v  { background: var(--green-light);  border: 1px solid var(--green); }
.wl-f  { background: var(--accent2-light); border: 1px solid var(--accent2); }
.wl-l  { background: var(--purple-light); border: 1px solid var(--purple); }
.wl-man  { background: var(--accent); }
.wl-mcp  { background: var(--accent2); }
.wl-none { background: var(--border); }

/* ── ACTIONS CELL (icon buttons) ── */
.actions-cell {
  padding: 5px 6px;
  vertical-align: top;
}
.day-actions-icons {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}
.day-actions-icons.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}
.day-actions-icons.grid .ibtn {
  width: 100%;
  min-width: 0;
}
.ibtn {
  min-width: 28px;
  height: 26px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.82rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  font-family: "DM Sans", sans-serif;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.ibtn:hover { background: var(--surface2); }
.ibtn .ibtn-cnt { font-size: 0.62rem; font-weight: 700; }
.ibtn.sint-on { background: var(--red-light); border-color: var(--red); color: var(--red); }
.ibtn.wc-on   { background: var(--green-light); border-color: var(--green); color: var(--green); }
.ibtn.save    { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
.ibtn.lock    { background: var(--surface); cursor: default; }
.ibtn.lock:hover { background: var(--surface); }

/* ── MEAL CELL ── */
.meal-cell {
  padding: 5px 4px;
  vertical-align: top;
}
.meal-btn {
  width: 100%;
  min-height: 52px;
  border: 1.5px dashed var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  padding: 8px;
  padding-right: 16px;
  text-align: left;
  transition: all 0.18s ease;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  font-family: "DM Sans", sans-serif;
  overflow: hidden;
}
.meal-btn:hover {
  border-color: var(--accent);
  background: var(--accent-light);
  transform: translateY(-1px);
}
.meal-btn.filled {
  border-style: solid;
  border-color: var(--border);
  background: var(--surface);
}
.meal-btn.filled:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}
.meal-tag {
  font-size: 0.72rem;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: 20px;
  display: inline-block;
  line-height: 1.35;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tag-carbo {
  background: var(--yellow-light);
  color: var(--yellow);
}
.tag-proteina {
  background: var(--blue-light);
  color: var(--blue);
}
.tag-verdura {
  background: var(--green-light);
  color: var(--green);
}
.tag-frutta {
  background: var(--accent2-light);
  color: var(--accent2);
}
.tag-libero {
  background: var(--purple-light);
  color: var(--purple);
}
.meal-empty {
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
  padding: 10px 0;
  width: 100%;
  align-self: center;
}
.edit-icon {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 0.58rem;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.15s;
}
.meal-btn:hover .edit-icon {
  opacity: 1;
}

/* ── NOTE ROW ── */
.note-row {
  display: none;
}
.note-row.open {
  display: table-row;
}
.note-row td {
  padding: 0 12px 9px;
  border-radius: 0 0 14px 14px;
  background: var(--surface);
  transition: background 0.25s;
}
.note-textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 11px;
  font-family: "DM Sans", sans-serif;
  font-size: 0.78rem;
  color: var(--text);
  background: var(--bg);
  resize: vertical;
  min-height: 58px;
  transition:
    border-color 0.15s,
    background 0.25s,
    color 0.25s;
}
.note-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── MODAL ── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.overlay.open {
  display: flex;
}
.modal {
  background: var(--surface);
  border-radius: 20px;
  padding: 1.6rem;
  width: 100%;
  max-width: 490px;
  max-height: 92vh;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
  transition: background 0.25s;
}
@keyframes slideUp {
  from {
    transform: translateY(14px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.1rem;
}
.modal-title {
  font-family: "DM Serif Display", serif;
  font-size: 1.25rem;
  font-weight: 400;
}
.modal-sub {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 2px;
}
.modal-close {
  background: var(--surface2);
  border: none;
  border-radius: 50%;
  width: 29px;
  height: 29px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.modal-close:hover {
  background: var(--border);
}
.modal-note {
  font-size: 0.7rem;
  color: var(--muted);
  background: var(--surface2);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 0.9rem;
  font-style: italic;
}
.field-group {
  margin-bottom: 0.9rem;
}
.field-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 5px;
}
.field-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
select,
textarea,
input[type="text"] {
  width: 100%;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-family: "DM Sans", sans-serif;
  font-size: 0.82rem;
  color: var(--text);
  transition:
    border-color 0.15s,
    background 0.25s,
    color 0.25s;
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='11' viewBox='0 0 24 24' fill='none' stroke='%238A8379' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  cursor: pointer;
}
select:focus,
textarea:focus,
input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}
textarea {
  resize: vertical;
  min-height: 65px;
}
.free-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  margin-bottom: 0.9rem;
  cursor: pointer;
  color: var(--muted);
}
.free-toggle input {
  accent-color: var(--accent);
  width: 13px;
  height: 13px;
  cursor: pointer;
}
.free-section {
  display: none;
}
.free-section.show {
  display: block;
}
.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 1.1rem;
}
.btn-save {
  flex: 1;
  padding: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: "DM Sans", sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-save:hover {
  filter: brightness(1.1);
}
.btn-clear {
  padding: 10px 13px;
  background: none;
  color: var(--muted);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: "DM Sans", sans-serif;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-clear:hover {
  border-color: #d44;
  color: #d44;
}

/* ── STORICO ── */
.storico-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.storico-toolbar label {
  font-size: 0.73rem;
  color: var(--muted);
}
.storico-toolbar input[type="date"] {
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: "DM Sans", sans-serif;
  font-size: 0.75rem;
  background: var(--surface);
  color: var(--text);
  transition:
    background 0.25s,
    color 0.25s,
    border-color 0.25s;
}
.export-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: "DM Sans", sans-serif;
  font-size: 0.76rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  margin-left: auto;
}
.export-btn:hover {
  filter: brightness(1.1);
}
.export-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.storico-empty {
  text-align: center;
  padding: 3rem;
  color: var(--muted);
  font-size: 0.83rem;
}
.storico-entry {
  background: var(--surface);
  border-radius: 14px;
  padding: 1.1rem 1.4rem;
  margin-bottom: 9px;
  border: 1px solid var(--border);
  transition:
    background 0.25s,
    border-color 0.25s;
}
.storico-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 9px;
  flex-wrap: wrap;
  gap: 7px;
}
.storico-date {
  font-family: "DM Serif Display", serif;
  font-size: 1rem;
}
.storico-badges {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-top: 3px;
}
.storico-badge {
  font-size: 0.65rem;
  padding: 2px 7px;
  border-radius: 20px;
}
.storico-meals {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-bottom: 7px;
}
.storico-meal {
  background: var(--surface2);
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 0.7rem;
  min-width: 95px;
  max-width: 160px;
  transition: background 0.25s;
}
.storico-meal-name {
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 2px;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.storico-note {
  font-size: 0.72rem;
  color: var(--muted);
  font-style: italic;
  border-top: 1px solid var(--border);
  padding-top: 7px;
  margin-top: 4px;
}
.storico-del {
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 0.66rem;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
  font-family: "DM Sans", sans-serif;
}
.storico-del:hover {
  border-color: #d44;
  color: #d44;
}

/* ── GESTIONE LISTE ── */
.lists-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}
.list-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 1.1rem;
  border: 1px solid var(--border);
  transition:
    background 0.25s,
    border-color 0.25s;
}
.list-card h3 {
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 9px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.list-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.list-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 9px;
  max-height: 240px;
  overflow-y: auto;
}
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  padding: 4px 7px;
  background: var(--bg);
  border-radius: 5px;
  transition: background 0.25s;
}
.list-item-del {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.88rem;
  padding: 0 2px;
  transition: color 0.15s;
  line-height: 1;
}
.list-item-del:hover {
  color: #d44;
}
.list-add {
  display: flex;
  gap: 4px;
}
.list-add input {
  flex: 1;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-family: "DM Sans", sans-serif;
  font-size: 0.75rem;
  background: var(--bg);
  color: var(--text);
  transition:
    background 0.25s,
    color 0.25s,
    border-color 0.25s;
}
.list-add input:focus {
  outline: none;
  border-color: var(--accent);
}
.list-add button {
  padding: 5px 9px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.75rem;
  font-family: "DM Sans", sans-serif;
  transition: all 0.15s;
}
.list-add button:hover {
  filter: brightness(1.1);
}

/* ── FOOTER ── */
footer {
  text-align: center;
  padding: 1.1rem;
  font-size: 0.66rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
}
.footer-meta {
  display: block;
  margin-top: 5px;
  opacity: 0.6;
  font-size: 0.6rem;
}

/* ── RESPONSIVE ── */
@media (max-width: 600px) {
  header,
  .main {
    padding: 1rem;
  }
  .tab {
    padding: 0.6rem 0.8rem;
    font-size: 0.7rem;
  }
}

/* ── Giorni bloccati ────────────────────────────────────────────── */
.day-cell.locked { opacity: 0.85; }
tbody tr.today { background: var(--today-light); }
tbody tr.today td:first-child { box-shadow: inset 2px 0 0 var(--today); }
.today-badge {
  font-size: 0.55rem;
  font-weight: 600;
  color: #fff;
  background: var(--today);
  border-radius: 10px;
  padding: 1px 7px;
  align-self: flex-start;
  letter-spacing: 0.04em;
}

.locked-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
}

.meal-btn.locked-meal { cursor: default; }
.meal-btn.locked-meal:hover { background: var(--surface); }

/* ── MCP indicators ── */
.corner-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  pointer-events: none;
}
.corner-dot.mcp    { background: var(--accent2); }
.corner-dot.manual { background: var(--accent); }

.day-indicator-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 3px 0;
}
.dots-row {
  display: flex;
  gap: 4px;
  align-items: center;
}
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}
.dot.mcp    { background: var(--accent2); }
.dot.manual { background: var(--accent); }

.indicator-help-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.indicator-help-btn {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border);
  font-size: 0.55rem;
  color: var(--muted);
  cursor: default;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  line-height: 1;
  user-select: none;
}
.indicator-tooltip {
  display: none;
  position: absolute;
  left: 0;
  top: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  z-index: 100;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  pointer-events: none;
}
.indicator-help-wrap:hover .indicator-tooltip { display: block; }
.indicator-tooltip-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--muted);
  padding: 2px 0;
}
.indicator-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── AUTOCOMPLETE ──────────────────────────────────────────────── */
.autocomplete-wrap {
  position: relative;
}
.autocomplete-input {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: "DM Sans", sans-serif;
  font-size: 0.85rem;
  transition:
    border-color 0.15s,
    background 0.25s;
}
.autocomplete-input:focus {
  outline: none;
  border-color: var(--accent);
}
.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}
.autocomplete-item {
  padding: 7px 10px;
  cursor: pointer;
  font-size: 0.83rem;
  color: var(--text);
  transition: background 0.1s;
}
.autocomplete-item:hover,
.autocomplete-item.ac-active {
  background: var(--surface2);
}
.autocomplete-add {
  color: var(--accent);
  border-top: 1px solid var(--border);
  font-style: italic;
}

/* -- EXPORT SECTION ────────────────────────────────────────────── */
.export-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  margin-bottom: 1.25rem;
}
.export-section h3 {
  font-family: "DM Serif Display", serif;
  font-size: 0.9rem;
  font-weight: 400;
  margin-top: 0;
  margin-bottom: 10px;
  color: var(--text);
}
.export-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.export-controls label {
  font-size: 0.8rem;
  color: var(--muted);
}
.export-controls input[type="date"] {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.8rem;
  background: var(--bg);
  color: var(--text);
  font-family: "DM Sans", sans-serif;
}

/* ── STATISTICHE ───────────────────────────────────────────────── */
.stats-range-btns {
  display: flex;
  gap: 8px;
  margin-bottom: 1.5rem;
}
.stats-range-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 14px;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--text);
  font-family: "DM Sans", sans-serif;
  transition: all 0.15s;
}
.stats-range-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.stats-section {
  margin-bottom: 2rem;
}
.stats-section h3 {
  font-family: "DM Serif Display", serif;
  font-size: 1rem;
  font-weight: 400;
  margin-top: 0;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.stats-legend {
  font-family: "DM Sans", sans-serif;
  font-size: 0.72rem;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.stats-days-chart {
  max-height: 320px;
  overflow-y: auto;
}
.stats-day-row {
  display: grid;
  grid-template-columns: 70px 16px 1fr 28px;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}
.stats-day-label {
  font-size: 0.73rem;
  color: var(--muted);
  text-align: right;
}
.stats-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}
.stats-dot.ok {
  background: var(--green);
}
.stats-dot.sintomi {
  background: var(--red);
}
.stats-wc-bar-wrap {
  background: var(--surface2);
  border-radius: 4px;
  height: 10px;
  overflow: hidden;
}
.stats-wc-bar {
  height: 100%;
  background: var(--blue);
  border-radius: 4px;
  transition: width 0.3s;
}
.stats-wc-count {
  font-size: 0.7rem;
  color: var(--muted);
}
.stats-foods-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
}
@media (max-width: 600px) {
  .stats-foods-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
.stats-foods-col-title {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  margin-bottom: 10px;
  display: inline-block;
}
.stats-food-row {
  margin-bottom: 8px;
}
.stats-food-name {
  font-size: 0.75rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.stats-food-bar-wrap {
  background: var(--surface2);
  border-radius: 3px;
  height: 6px;
  overflow: hidden;
  margin-bottom: 2px;
}
.stats-food-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
}
.stats-food-count {
  font-size: 0.68rem;
  color: var(--muted);
}
.stats-empty-col {
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
 