:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #eff6ff;
  --success: #16a34a;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 4px 12px rgba(0,0,0,.08);
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: 'Inter', Arial, sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── HEADER ─────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.header-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  font-size: 2rem;
  line-height: 1;
}

.brand-name {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
  margin-top: 1px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.icon-btn:hover {
  background: var(--bg);
  border-color: #d1d5db;
}

/* ── SETTINGS PANEL ─────────────────────────────────── */
.settings-panel {
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
}

.settings-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 14px 20px;
}

.settings-inner label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.settings-row {
  display: flex;
  gap: 8px;
}

.settings-row input {
  flex: 1;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: white;
}

.settings-row input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

.settings-row button {
  height: 40px;
  padding: 0 18px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

.settings-row button:hover { background: var(--accent-hover); }

/* ── CATEGORY SETTINGS ──────────────────────────────── */
.category-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.cat-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-light);
  border: 1px solid #bfdbfe;
  border-radius: 99px;
  padding: 3px 10px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--accent);
}

.cat-del {
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 99px;
  background: #fee2e2;
  color: var(--danger);
  font-size: 0.7rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.cat-del:hover { background: #fecaca; }

.emoji-pick-btn {
  flex: 0 0 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: white;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0;
}

.emoji-pick-btn:hover { background: var(--bg); }

.emoji-picker {
  position: absolute;
  top: 48px;
  left: 0;
  z-index: 300;
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px;
  width: 280px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.emoji-picker span {
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  line-height: 1;
  user-select: none;
}

.emoji-picker span:hover { background: var(--bg); }

/* ── OVERLAY RICETTE ─────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 60px 16px 24px;
  overflow-y: auto;
}

.overlay-panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 760px;
  padding: 24px;
}

.overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.overlay-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
}

.recipes-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.recipe-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 16px;
}

.recipe-img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  margin: -16px -16px 12px;
  width: calc(100% + 32px);
  display: block;
}

.recipe-card h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.recipe-meta {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.recipe-missing {
  font-size: 0.82rem;
  color: var(--muted);
  font-style: italic;
  margin-bottom: 10px;
}

.recipe-card ol {
  padding-left: 18px;
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text);
}

/* ── MAIN ────────────────────────────────────────────── */
.main {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 20px 100px;
}

/* ── TABS ────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px;
  box-shadow: var(--shadow-sm);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 6px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
  position: relative;
}

.tab:hover { background: var(--bg); color: var(--text); }

.tab.active {
  background: var(--accent);
  color: white;
}

.tab-icon { font-size: 1.3rem; line-height: 1; }
.tab-label { white-space: nowrap; }

.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 99px;
  background: rgba(0,0,0,.12);
  color: inherit;
  font-size: 0.72rem;
  font-weight: 700;
}

.tab.active .tab-badge { background: rgba(255,255,255,.25); }

/* ── FOOD LIST ───────────────────────────────────────── */
.food-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.food-row {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.row-top {
  display: flex;
  gap: 8px;
  align-items: center;
}

.row-bottom {
  display: flex;
  gap: 8px;
  align-items: center;
}

.food-row input,
.food-row select {
  font: inherit;
  font-size: 0.9rem;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  padding: 4px 8px;
  height: 34px;
  transition: border-color 0.15s, background 0.15s;
}

.food-row input:hover,
.food-row select:hover { border-color: var(--line); background: var(--bg); }
.food-row input:focus,
.food-row select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; background: white; }

.name-input { flex: 1; font-weight: 600; min-width: 0; }
.category-input { flex: 0 0 150px; font-size: 0.85rem; }

.qty-group {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.qty-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background 0.1s;
}

.qty-btn:hover { background: #e5e7eb; }

.quantity-input { width: 58px; text-align: center; }
.unit-input { flex: 1; min-width: 0; }
.container-input { font-size: 0.82rem; flex: 0 0 130px; }

.row-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  margin-left: auto;
}

.delete-button {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.delete-button { background: var(--danger-light); color: var(--danger); }
.delete-button:hover { background: #fecaca; }

.empty-state {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 40px 0;
}

/* ── ADD CARD ────────────────────────────────────────── */
.add-card {
  position: sticky;
  top: 69px; /* altezza header */
  z-index: 50;
  margin-bottom: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.add-label {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 10px;
}

.add-label strong { color: var(--accent); }

.add-form { display: flex; flex-direction: column; gap: 8px; }

.add-row1,
.add-row2 {
  display: flex;
  gap: 8px;
  align-items: center;
}

.add-row1 input,
.add-row1 select,
.add-row2 input,
.add-row2 select {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: white;
  min-width: 0;
}

.add-row1 input:focus,
.add-row1 select:focus,
.add-row2 input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

.field-name     { flex: 1; }
.field-category { flex: 0 0 150px; }
.field-qty      { flex: 0 0 72px; text-align: center; }
.field-unit     { flex: 1; }

.add-btn {
  height: 42px;
  padding: 0 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s;
}

.add-btn:hover { background: var(--accent-hover); }

/* ── STATUS BAR ─────────────────────────────────────── */
.status-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 10px 16px;
  min-height: 40px;
  transition: color 0.2s;
}

.status-bar.error { color: var(--danger); }

/* ── RESPONSIVE ─────────────────────────────────────── */
@media (max-width: 640px) {
  .brand-sub { display: none; }

  .tab-label { display: none; }
  .tab { padding: 10px 4px; }
  .tab-icon { font-size: 1.5rem; }

  .field-category { flex: 1; }

  .container-input { display: none; }
  .add-btn { flex: 0 0 auto; }
}
