/* ═══════════════════════════════════════════
   RESET
═══════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

/* ═══════════════════════════════════════════
   DESIGN TOKENS – Light mode
═══════════════════════════════════════════ */
:root {
  --bg:        #f1f5f9;
  --card:      #ffffff;
  --input-bg:  #ffffff;
  --primary:   #2563eb;
  --pri-h:     #1d4ed8;
  --danger:    #ef4444;
  --dan-h:     #dc2626;
  --text:      #1e293b;
  --muted:     #64748b;
  --border:    #e2e8f0;
  --radius:    12px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
}

/* ═══════════════════════════════════════════
   DESIGN TOKENS – Dark mode
═══════════════════════════════════════════ */
[data-theme="dark"] {
  --bg:        #0f172a;
  --card:      #1e293b;
  --input-bg:  #0f172a;
  --primary:   #60a5fa;
  --pri-h:     #3b82f6;
  --danger:    #f87171;
  --dan-h:     #ef4444;
  --text:      #f1f5f9;
  --muted:     #94a3b8;
  --border:    #334155;
  --shadow:    0 1px 3px rgba(0,0,0,.35), 0 1px 2px rgba(0,0,0,.25);
}

/* ═══════════════════════════════════════════
   BASE
═══════════════════════════════════════════ */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  transition: background .2s, color .2s;
}

/* ═══════════════════════════════════════════
   HEADER
═══════════════════════════════════════════ */
header {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
  color: #fff;
  padding: 20px 32px;
}

.header-inner {
  max-width: 1080px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

header h1 { font-size: 1.75rem; font-weight: 800; letter-spacing: -.5px; }
header p  { margin-top: 4px; opacity: .75; font-size: .88rem; }

.theme-btn {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 8px;
  color: #fff;
  padding: 7px 14px;
  cursor: pointer;
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .03em;
  line-height: 1;
  transition: background .15s;
  flex-shrink: 0;
}
.theme-btn:hover { background: rgba(255,255,255,.28); }

/* ── Header actions cluster (lang toggle + theme btn) ── */
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.ui-lang-toggle {
  display: inline-flex;
  gap: 2px;
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 999px;
  padding: 2px;
}
.ui-lang-btn {
  border: none;
  background: transparent;
  color: rgba(255,255,255,.78);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .04em;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  line-height: 1;
  transition: background .15s, color .15s;
}
.ui-lang-btn:hover { color: #fff; background: rgba(255,255,255,.10); }
.ui-lang-btn.active {
  background: #fff;
  color: #1e3a8a;
}

/* ═══════════════════════════════════════════
   LAYOUT
═══════════════════════════════════════════ */
main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  transition: background .2s;
}

.card-title {
  font-size: .75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 14px;
}

.card-toggle {
  cursor: pointer;
  user-select: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-toggle::after {
  content: '';
  display: inline-block;
  width: .42em;
  height: .42em;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform .2s, opacity .15s;
  flex-shrink: 0;
  opacity: .45;
  margin-bottom: .1em;
}
.card-toggle:hover::after {
  opacity: 1;
}
.card.collapsed .card-toggle {
  margin-bottom: 0;
}
.card.collapsed .card-toggle::after {
  transform: rotate(-45deg);
  margin-bottom: 0;
}
.card.collapsed .card-body {
  display: none;
}

/* ═══════════════════════════════════════════
   BUTTONS
═══════════════════════════════════════════ */
.btn {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background .15s, transform .1s;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }

.btn-primary          { background: var(--primary); color: #fff; }
.btn-primary:hover    { background: var(--pri-h); }

.btn-secondary        { background: var(--bg); color: var(--text); border: 1.5px solid var(--border); }
.btn-secondary:hover  { background: var(--border); }

.btn-danger           { background: var(--danger); color: #fff; }
.btn-danger:hover     { background: var(--dan-h); }

.btn-ghost            { background: none; color: var(--muted); border: 1.5px solid var(--border); }
.btn-ghost:hover      { background: var(--bg); color: var(--text); }
.btn-ghost:disabled   { opacity: .4; cursor: not-allowed; pointer-events: none; }

.btn-sm               { padding: 5px 10px; font-size: .78rem; border-radius: 6px; }

.btn-edit             { padding: 4px 10px; font-size: .78rem; border-radius: 6px;
                        background: #eff6ff; color: #2563eb; border: 1px solid #bfdbfe; }
.btn-edit:hover       { background: #dbeafe; }

.btn-remove           { padding: 4px 10px; font-size: .78rem; border-radius: 6px;
                        background: #fef2f2; color: #ef4444; border: 1px solid #fecaca; }
.btn-remove:hover     { background: #fee2e2; }

[data-theme="dark"] .btn-edit          { background: #1e3a5f; color: #93c5fd; border-color: #1e40af; }
[data-theme="dark"] .btn-edit:hover    { background: #1e3a8a; }
[data-theme="dark"] .btn-remove        { background: #3b1c1c; color: #f87171; border-color: #7f1d1d; }
[data-theme="dark"] .btn-remove:hover  { background: #4c2020; }

/* ═══════════════════════════════════════════
   SEARCH BAR
═══════════════════════════════════════════ */
.search-bar { display: flex; gap: 10px; margin-bottom: 14px; }
.search-bar input {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: .9rem;
  color: var(--text);
  background: var(--input-bg);
  transition: border-color .15s;
}
.search-bar input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

/* ═══════════════════════════════════════════
   PRESET CHIPS
═══════════════════════════════════════════ */
.section-label {
  font-size: .7rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin: 12px 0 7px;
  display: block;
}
.section-label:first-child { margin-top: 0; }

.presets-grid { display: flex; flex-wrap: wrap; gap: 7px; }

.preset-category { margin: 10px 0 2px; }
.preset-category:first-child { margin-top: 0; }
.preset-category > summary {
  font-size: .7rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .5px;
  cursor: pointer; user-select: none; list-style: none;
  display: flex; align-items: center; gap: 4px;
  margin-bottom: 7px;
}
.preset-category > summary::-webkit-details-marker { display: none; }
.preset-category > summary::before { content: '▼'; font-size: .5rem; opacity: .6; }
.preset-category:not([open]) > summary::before { content: '▶'; }
.preset-category:not([open]) > summary { margin-bottom: 0; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--card);
  font-size: .82rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: border-color .15s, background .15s, color .15s;
}
.chip:hover { border-color: var(--primary); background: #eff6ff; color: var(--primary); }
[data-theme="dark"] .chip:hover { background: #1e3a5f; color: #93c5fd; }

.chip.custom { border-style: dashed; border-color: #c4b5fd; background: #faf5ff; color: #7c3aed; }
.chip.custom:hover { border-color: #7c3aed; background: #ede9fe; }
[data-theme="dark"] .chip.custom       { background: #2e1c57; color: #c4b5fd; border-color: #5b21b6; }
[data-theme="dark"] .chip.custom:hover { background: #3b2378; }

.chip-del {
  width: 15px; height: 15px;
  border-radius: 50%;
  background: #ddd6fe; color: #7c3aed;
  border: none; cursor: pointer;
  font-size: 10px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; padding: 0;
}
.chip-del:hover { background: #c4b5fd; }

.expand-btn { margin-top: 8px; }
.empty-state { color: var(--muted); font-size: .88rem; padding: 8px 0; }

/* ── Custom presets management row ── */
.custom-section-hd {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 8px;
}
.custom-section-hd .section-label { margin: 0; }
.custom-section-actions { display: flex; gap: 6px; margin-left: auto; }

.custom-empty { font-size: .82rem; color: var(--muted); padding: 4px 0 2px; }

.storage-notice {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: .76rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  margin-top: 12px;
  line-height: 1.5;
}

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

.food-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--bg);
  border: 1.5px solid var(--border);
}
.food-swatch { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.food-name   { font-weight: 600; font-size: .9rem; flex: 1; min-width: 0;
               overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.food-amount-wrap { display: flex; align-items: center; gap: 3px; flex-shrink: 0; }
.food-amount-unit { font-size: .82rem; color: var(--muted); }
.food-amount-input {
  width: 58px;
  text-align: right;
  border: 1.5px solid transparent;
  border-radius: 6px;
  padding: 2px 4px;
  font-size: .82rem;
  font-family: inherit;
  color: var(--muted);
  background: transparent;
  -moz-appearance: textfield;
  appearance: textfield;
}
.food-amount-input::-webkit-outer-spin-button,
.food-amount-input::-webkit-inner-spin-button { -webkit-appearance: none; appearance: none; }
.food-amount-input:hover { border-color: var(--border); background: var(--input-bg); color: var(--text); }
.food-amount-input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--input-bg);
  color: var(--text);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.food-btns   { display: flex; gap: 6px; flex-shrink: 0; }

/* ═══════════════════════════════════════════
   CHART
═══════════════════════════════════════════ */
.chart-wrapper { position: relative; }
.ri-hint { font-size: .74rem; color: var(--muted); margin-top: 10px; }

/* ═══════════════════════════════════════════
   SUMMARY TABLE
═══════════════════════════════════════════ */
.summary-table { width: 100%; border-collapse: collapse; font-size: .875rem; }

.summary-table th {
  padding: 8px 12px; text-align: left;
  font-size: .7rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 2px solid var(--border);
  background: var(--bg);
}
.summary-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.summary-table tr:last-child td { border-bottom: none; }

.pct-row   { display: flex; align-items: center; gap: 10px; }
.pct-track { flex: 1; height: 7px; background: var(--border); border-radius: 4px; overflow: hidden; }
.pct-fill  { height: 100%; border-radius: 4px; transition: width .3s; }
.pct-label { min-width: 46px; text-align: right; font-weight: 700; font-size: .83rem; }

.c-ok   { color: #16a34a; }
.c-warn { color: #d97706; }
.c-over { color: var(--danger); }
[data-theme="dark"] .c-ok   { color: #4ade80; }
[data-theme="dark"] .c-warn { color: #fbbf24; }

/* ═══════════════════════════════════════════
   ACTIONS
═══════════════════════════════════════════ */
.actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* ═══════════════════════════════════════════
   DIALOG
═══════════════════════════════════════════ */
dialog {
  position: fixed;
  inset: 0;
  margin: auto;
  border: none;
  border-radius: 16px;
  padding: 0;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 25px 60px rgba(0,0,0,.25);
  max-width: 540px;
  width: calc(100vw - 32px);
  max-height: 92vh;
  overflow: hidden;
}
dialog[open] {
  display: flex;
  flex-direction: column;
}
dialog::backdrop { background: rgba(15,23,42,.6); backdrop-filter: blur(2px); }
[data-theme="dark"] dialog { box-shadow: 0 25px 60px rgba(0,0,0,.6); }

.dlg-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 16px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.dlg-header h2 { font-size: 1.05rem; font-weight: 700; }

.dlg-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 20px 24px;
  min-height: 0;
}

.dlg-close {
  width: 30px; height: 30px; border-radius: 7px; border: none;
  background: var(--bg); color: var(--muted); cursor: pointer; font-size: .95rem;
  display: flex; align-items: center; justify-content: center;
}
.dlg-close:hover { background: var(--border); color: var(--text); }

/* Form grid */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.span2, .form-grid > details { grid-column: 1 / -1; }

label { font-size: .7rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

input[type="text"],
input[type="number"] {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: .9rem;
  color: var(--text);
  background: var(--input-bg);
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
input::placeholder { color: #94a3b8; }

/* Inline error */
.dlg-error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: .84rem;
  margin-bottom: 14px;
}
[data-theme="dark"] .dlg-error { background: #3b1c1c; color: #fca5a5; border-color: #7f1d1d; }

/* Amount quick-select */
.amount-presets { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.amount-btn {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font-size: .75rem;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.amount-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Collapsible nutrients */
.form-grid > details > summary {
  font-size: .7rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .5px;
  cursor: pointer; user-select: none;
  padding: 10px 0 2px;
  list-style: none;
}
.form-grid > details > summary::-webkit-details-marker { display: none; }
.form-grid > details > summary::before { content: '▶\00a0'; font-size: .6rem; }
.form-grid > details[open] > summary::before { content: '▼\00a0'; }
.nutrient-sub-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px;
}

.dlg-footer {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; flex-shrink: 0;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--card);
}
.dlg-footer-btns { display: flex; gap: 8px; flex-shrink: 0; }

/* ═══════════════════════════════════════════
   FOOTER
═══════════════════════════════════════════ */
footer {
  max-width: 1080px;
  margin: 4px auto 32px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: .76rem;
  color: var(--muted);
}
.footer-links { display: flex; gap: 10px; align-items: center; flex-shrink: 0; }
.footer-links a { color: var(--muted); text-decoration: none; }
.footer-links a:hover { color: var(--text); text-decoration: underline; }
.footer-version { color: var(--muted); font-size: .8rem; }

/* ═══════════════════════════════════════════
   TOAST
═══════════════════════════════════════════ */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: #0f172a; color: #fff;
  padding: 11px 18px; border-radius: 8px;
  font-size: .84rem; font-weight: 500;
  opacity: 0; transform: translateY(6px);
  transition: opacity .2s, transform .2s;
  pointer-events: none; z-index: 9999;
}
.toast.show { opacity: 1; transform: translateY(0); }
[data-theme="dark"] .toast { background: #e2e8f0; color: #0f172a; }

/* ═══════════════════════════════════════════
   NUTRIENT TOGGLES
═══════════════════════════════════════════ */
.nutrient-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}
.n-toggle {
  padding: 3px 10px;
  border-radius: 999px;
  border: 1.5px solid var(--primary);
  background: var(--primary);
  color: #fff;
  font-size: .8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s, opacity .15s;
  line-height: 1.5;
}
.n-toggle.off {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
  opacity: .7;
}
.n-toggle:hover { opacity: .85; }

/* ═══════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════ */
@media (max-width: 580px) {
  header          { padding: 18px 16px 16px; }
  header h1       { font-size: 1.4rem; }
  .card           { padding: 16px; }
  .form-grid      { grid-template-columns: 1fr; }
  .nutrient-sub-grid { grid-template-columns: 1fr; }
  footer          { flex-direction: column; align-items: flex-start; gap: 8px; }
}

/* ═══════════════════════════════════════════
   LEGAL PAGES (impressum / datenschutz)
═══════════════════════════════════════════ */
.back-nav {
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 24px 0;
}
.back-nav a {
  font-size: .85rem;
  color: var(--muted);
  text-decoration: none;
}
.back-nav a:hover { color: var(--text); }
.legal-content h3,
.legal-content h4,
.legal-content h5 { margin: 1.4em 0 .4em; color: var(--text); }
.legal-content h3 { font-size: 1.1rem; }
.legal-content h4 { font-size: 1rem; }
.legal-content h5 { font-size: .9rem; }
.legal-content p  { margin: 0 0 .8em; line-height: 1.6; }
.legal-content ul { margin: 0 0 .8em 1.4em; line-height: 1.6; }
.legal-content a  { color: var(--primary); }

/* On very narrow screens the mini progress bar is too small to be useful */
/* Prevent iOS Safari from zooming on input focus (requires font-size >= 16px) */
@media (hover: none) {
  input, select, textarea { font-size: 16px !important; }
}

@media (max-width: 480px) {
  .pct-track { display: none; }
  .summary-table th,
  .summary-table td { padding: 7px 6px; }
  .food-item { flex-wrap: wrap; align-items: center; }
  .food-name { min-width: calc(100% - 22px); }
  .food-amount-wrap { flex-shrink: 0; }
  .food-amount-input { width: 42px; }
  .food-btns { flex: 1; justify-content: flex-end; }
  .dlg-footer { flex-wrap: wrap; padding: 12px 16px; gap: 10px; }
  .dlg-footer-btns { width: 100%; justify-content: flex-end; }
  dialog { top: 50px; bottom: auto; max-height: calc(100dvh - 100px); }
}
