:root {
  --bg: #f7f8fa;
  --bg-image: none;
  --card-blur: 0px;
  --card: #ffffff;
  --text: #1f2937;
  --text-on-primary: #fff;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary: #e5e7eb;
  --accent: #2563eb;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --border: #e5e7eb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --touch-target: 44px;
  --mobile-nav-height: 48px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 16px;
  -webkit-text-size-adjust: 100%;
}

html,
body {
  max-width: 100%;
  height: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  scroll-padding-top: 16px;
  -webkit-tap-highlight-color: transparent;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg);
  background-image: var(--bg-image);
  background-attachment: fixed;
  min-height: 100vh;
  color: var(--text);
  line-height: 1.5;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px;
  /* Compact UI: ~75% scale for fonts, paddings and borders alike.
     Keep zoom off <body>: zoom makes an element the containing block for
     position:fixed descendants, which breaks viewport anchoring on mobile
     browsers. Fixed overlays therefore live outside this container. */
  zoom: 0.75;
}

/* Login screen reads too small at the compact 0.75 zoom — relax to 0.9
   (20% larger) while the auth card is visible; reverts once it is hidden. */
.container:has(#auth-section:not(.hidden)) {
  zoom: 0.9;
}

#auth-section {
  max-width: 480px;
  margin: 0 auto;
}

header {
  text-align: center;
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.language-switcher {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.header-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.header-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.lang-btn {
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 4px 14px;
  min-height: var(--touch-target);
  min-width: var(--touch-target);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.lang-btn.active {
  display: none;
}

button,
label,
input,
select,
h1,
h2,
p,
.list-item {
  min-width: 0;
}

p,
.list-item {
  overflow-wrap: anywhere;
  word-break: normal;
  hyphens: auto;
}

header h1 {
  margin: 0;
  font-size: 2rem;
}

.subtitle {
  color: var(--muted);
  margin: 2px 0 0;
}

.card {
  position: relative;
  overflow: hidden;
  background: var(--card);
  backdrop-filter: blur(var(--card-blur));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.card h2 {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 0;
  font-size: 1.25rem;
}

.section-icon {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  padding: 6px;
  border-radius: 9px;
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 13%, transparent);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.area-summary,
.area-target,
.area-add-meal,
.area-foods,
.area-meals {
  border-top: 3px solid var(--section-accent, var(--primary));
  background-image: radial-gradient(circle at 100% 0, color-mix(in srgb, var(--section-accent, var(--primary)) 12%, transparent), transparent 38%);
}

.area-summary {
  --section-accent: #3b82f6;
}

.area-target {
  --section-accent: #8b5cf6;
}

.area-add-meal {
  --section-accent: #10b981;
}

.area-foods {
  --section-accent: #14b8a6;
}

.area-meals {
  --section-accent: #f59e0b;
}

.area-summary .section-icon,
.area-target .section-icon,
.area-add-meal .section-icon,
.area-foods .section-icon,
.area-meals .section-icon {
  color: var(--section-accent);
  background: color-mix(in srgb, var(--section-accent) 14%, transparent);
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.tab {
  background: none;
  border: none;
  border-radius: 0;
  padding: 8px 16px;
  min-height: var(--touch-target);
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-weight: 500;
  font-size: 0.9rem;
}

input,
select {
  padding: 8px 12px;
  min-height: var(--touch-target);
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--card);
  color: var(--text);
}

button {
  cursor: pointer;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  min-height: var(--touch-target);
  min-width: var(--touch-target);
  font-size: 0.95rem;
  touch-action: manipulation;
}

.btn-primary {
  background: var(--primary);
  color: var(--text-on-primary);
}

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

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  flex-shrink: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--secondary);
  color: var(--text);
  cursor: pointer;
}

.action-icon {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-icon:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.user-area {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.user-area span {
  max-width: 320px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-stats {
  flex: none;
  font-size: 0.8rem;
  opacity: 0.8;
}

.user-stats:empty {
  display: none;
}

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

.btn-secondary:hover {
  background: var(--border);
}

.btn-danger {
  background: var(--danger);
  color: var(--text-on-primary);
  padding: 6px 12px;
  flex-shrink: 0;
}

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

button:disabled {
  opacity: 0.6;
  cursor: default;
}

.auth-form,
.inline-form,
.grid-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.inline-form {
  flex-direction: row;
  align-items: flex-end;
  flex-wrap: wrap;
}

#summary-date-form label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.inline-form label,
.grid-form label {
  flex: 1;
  min-width: 140px;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.grid-form button {
  grid-column: 1 / -1;
  justify-self: start;
}

.grid-form .form-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.grid-form .form-actions button {
  grid-column: auto;
}

#target-form {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  column-gap: 20px;
  align-items: start;
}

.target-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  grid-template-rows: auto var(--touch-target) auto;
  align-items: start;
  min-width: 0;
  gap: 4px 8px;
}

.target-row input {
  grid-column: 1;
  grid-row: 2;
  min-width: 0;
  width: 100%;
  height: var(--touch-target);
}

.target-row label {
  display: contents;
}

.target-row label > span {
  grid-column: 1 / -1;
  grid-row: 1;
}

.target-row .macro-grams {
  grid-column: 1 / -1;
  grid-row: 3;
}

.target-row .mode-toggle {
  grid-column: 2;
  grid-row: 2;
  align-self: stretch;
  margin: 0;
}

.mode-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  flex: none;
  height: var(--touch-target);
  align-self: flex-end;
  box-sizing: border-box;
}

.mode-toggle button {
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
  min-width: 0;
  min-height: 0;
  font: inherit;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.mode-toggle button.active {
  background: var(--primary);
  color: var(--text-on-primary);
}

.food-form-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.food-form-row label {
  flex: 1;
  min-width: 0;
}

.meal-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.meal-form-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  min-width: 0;
}

.meal-form-row label {
  min-width: 0;
}

.meal-form-row select,
.meal-form-row input {
  width: 100%;
}

.meal-food-field {
  flex: 1 1 auto;
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}

.meal-type-field {
  flex: 1 1 0;
  min-width: 136px;
}

.meal-quantity-field {
  flex: 0 1 96px;
}

.meal-form-secondary-row .btn-primary {
  flex: 0 0 auto;
  width: 34px;
  padding: 6px;
}

.food-search {
  display: flex;
  align-items: center;
  gap: 8px;
}

.food-search input {
  flex: 1;
}

#voice-toggle.active {
  background: var(--primary);
  color: var(--text-on-primary);
  border-color: var(--primary);
}

.voice-result-label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  width: 100%;
  cursor: pointer;
}

.voice-result-label input[type='checkbox'] {
  flex: 0 0 auto;
  width: auto;
  min-height: 0;
  margin: 0;
}

.voice-result-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.voice-result-name {
  font-weight: 600;
  line-height: 1.25;
}

.voice-result-meta {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.25;
}

.voice-result-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.section-header h2 {
  margin: 0;
}

#settings-section:not(.hidden) ~ #auth-section,
#settings-section:not(.hidden) ~ #dashboard-section {
  display: none;
}

.form-note {
  grid-column: 1 / -1;
  margin: 0;
}

.voice-settings {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.voice-settings h3 {
  margin-bottom: 8px;
}

.voice-settings form {
  margin-top: 12px;
}

#settings-section h3,
.foods-header h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 24px;
  margin-bottom: 12px;
}

.list-item.selectable {
  cursor: pointer;
}

.list-item.selectable:hover {
  border-color: var(--primary);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.summary-grid .summary-metric {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  align-items: center;
  min-height: 32px;
  overflow: hidden;
  background: var(--bg);
  border-radius: 8px;
  padding: 6px 8px;
  text-align: center;
  --metric-fill: 0%;
  --metric-color: var(--muted);
}

.summary-grid .metric-values {
  position: relative;
  z-index: 1;
  font-variant-numeric: tabular-nums;
}

.summary-grid .summary-metric.ok {
  --metric-color: #22c55e;
}

.summary-grid .summary-metric::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--metric-fill);
  background: color-mix(in srgb, var(--metric-color) 35%, transparent);
  content: '';
  transition: width 0.2s ease;
}

.summary-grid .summary-metric.warn {
  --metric-color: #f59e0b;
}

.summary-grid .summary-metric.over {
  --metric-color: var(--danger);
}

.summary-grid .summary-metric.has-floating-target::after {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--floating-target, 0%);
  width: 3px;
  margin-left: -1.5px;
  background: #7c3aed;
  content: '';
}

.summary-grid span {
  position: relative;
  z-index: 1;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.2;
}

.progress-bar {
  height: 12px;
  background: var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-bar div {
  height: 100%;
  width: 0%;
  background: var(--primary);
  transition: width 0.2s ease;
}

.progress-bar div.warn {
  background: #f59e0b;
}

.progress-bar div.over {
  background: var(--danger);
}

.progress-area {
  cursor: pointer;
}

.progress-area .expand-hint {
  display: block;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 4px;
}

.macro-progress {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 6px 20px;
  margin-top: 12px;
}

.macro-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.progress-area.expanded #progress-collapsed {
  display: none;
}

.progress-area.expanded .macro-progress {
  display: grid;
}

.progress-area.expanded #progress-text {
  display: block;
}

.progress-area #progress-text {
  display: none;
}

@media (max-width: 480px) {
  .macro-progress {
    grid-template-columns: 1fr;
  }
}

.macro-row {
  display: grid;
  grid-template-columns: 80px 48px 1fr 52px;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}

.macro-consumed {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.macro-target {
  text-align: left;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.macro-bar {
  margin-top: 0;
  height: 8px;
}

.macro-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 6px;
  background: var(--border);
  transition: width 0.2s ease;
}

.macro-fill.ok {
  background: #22c55e;
}

.macro-fill.warn {
  background: #f59e0b;
}

.macro-fill.over {
  background: var(--danger);
}

.macro-value.ok {
  color: #16a34a;
}

.macro-value.warn {
  color: #d97706;
}

.macro-value.over {
  color: var(--danger);
}

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

.list-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg);
  border-radius: 8px;
  padding: 12px;
}

.list-item > * {
  min-width: 0;
}

.list-item .btn-danger {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.45;
}

.list-item .btn-danger:hover,
.list-item .btn-danger:focus-visible {
  opacity: 1;
}

.list-item .btn-danger .action-icon {
  width: 14px;
  height: 14px;
  flex-basis: 14px;
}

.list-item .meal-actions-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  padding: 3px;
  border: none;
  background: transparent;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}

.list-item:hover .meal-actions-btn,
.list-item:focus-within .meal-actions-btn,
.list-item.actions-visible .meal-actions-btn {
  opacity: 0.8;
  pointer-events: auto;
}

.list-item .meal-actions-btn:hover,
.list-item .meal-actions-btn:focus-visible,
.list-item .meal-actions-btn[aria-expanded='true'] {
  opacity: 1;
}

.meal-menu {
  position: absolute;
  top: 34px;
  right: 4px;
  z-index: 20;
  min-width: 140px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.meal-menu.meal-menu-up {
  top: auto;
  bottom: 34px;
}

.meal-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  border: none;
  border-radius: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
}

.meal-menu-item:hover,
.meal-menu-item:focus-visible {
  background: color-mix(in srgb, var(--primary) 12%, transparent);
}

.meal-menu-item.meal-menu-delete {
  border-top: 1px solid var(--border);
  color: var(--danger);
}

.meal-menu-item.meal-menu-delete:hover,
.meal-menu-item.meal-menu-delete:focus-visible {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.meal-menu-item .action-icon {
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
}

@media (max-width: 767px) {
  #meals-list .list-item .muted {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.8rem;
  }

  #summary-date-form label span {
    display: none;
  }

  .meal-group-title {
    flex-wrap: wrap;
  }

  .meal-group-total {
    flex-basis: 100%;
  }
}

.list-item.vanishing {
  opacity: 0;
  transform: translateX(16px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.meal-group-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0 4px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--secondary);
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  user-select: none;
}

.meal-group-title:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

.meal-group-title .chevron {
  width: 14px;
  height: 14px;
  flex: none;
  transition: transform 0.2s ease;
}

.meal-group:not(.collapsed) .meal-group-title .chevron {
  transform: rotate(90deg);
}

.meal-group.collapsed .meal-group-body {
  display: none;
}

.meal-group-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.meal-group-total {
  font-weight: normal;
  text-transform: none;
  font-size: 0.8rem;
}

#food-search {
  width: 100%;
  margin-top: 12px;
  margin-bottom: 12px;
}

#food-form:not(.hidden) ~ #barcode-form,
#food-form:not(.hidden) ~ .food-search,
#food-form:not(.hidden) ~ .lists-scroll {
  display: none;
}

.lists-scroll {
  margin: 0 -8px;
  padding: 0 8px;
}

.scanner {
  border: none;
  border-radius: var(--radius);
  padding: 16px;
  background: var(--card);
  width: min(92vw, 420px);
}

.scanner::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.scanner-region {
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: calc(var(--radius) / 2);
  background: #000;
}

.scanner video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner .btn-secondary {
  margin-top: 12px;
  width: 100%;
}

.photo-modal {
  text-align: center;
}

.photo-scan-preview {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: #000;
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.photo-scan-result {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 6px 0;
  font-size: 14px;
}

.photo-scan-head {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  font-size: 16px;
}

.photo-scan-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
}

.photo-scan-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.photo-scan-actions .btn-secondary {
  margin-top: 0;
  width: auto;
  flex: 1;
}

.photo-scan-actions .btn-primary {
  flex: 1;
}

.lists-scroll > :first-child {
  margin-top: 0;
}

.lists-scroll > :last-child {
  margin-bottom: 0;
}

#food-list {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.macro {
  font-variant-numeric: tabular-nums;
}

.macro-kcal {
  color: #9333ea;
  font-weight: 700;
}

.macro-p {
  color: #2563eb;
}

.macro-f {
  color: #d97706;
}

.macro-c {
  color: #16a34a;
}

.micro-fiber {
  color: #0d9488;
}

.micro-salt {
  color: #64748b;
}

.micro-saturated {
  color: #b91c1c;
}

.micro-sugar {
  color: #db2777;
}

.voice-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.45);
}

.voice-card {
  background: var(--card);
  color: var(--text);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 32px;
  min-width: 260px;
  max-width: calc(100vw - 32px);
  text-align: center;
}

.voice-waves {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 48px;
  margin-bottom: 12px;
}

.voice-waves span {
  width: 6px;
  height: 12px;
  border-radius: 3px;
  background: var(--accent);
  animation: voice-wave 1.1s ease-in-out infinite;
}

.voice-waves span:nth-child(2) { animation-delay: 0.1s; }
.voice-waves span:nth-child(3) { animation-delay: 0.2s; }
.voice-waves span:nth-child(4) { animation-delay: 0.3s; }
.voice-waves span:nth-child(5) { animation-delay: 0.4s; }

@keyframes voice-wave {
  0%, 100% { height: 12px; }
  50% { height: 42px; }
}

.voice-overlay.processing .voice-waves span {
  animation: none;
  height: 12px;
}

.voice-status {
  margin: 0 0 8px;
  font-weight: 600;
}

.voice-transcript {
  margin: 0 0 16px;
  min-height: 1.2em;
  font-style: italic;
}

.meal-entry {
  display: inline;
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
}

.meal-entry:hover,
.meal-entry:focus-visible {
  color: var(--primary);
}

.meal-entry-input {
  width: 90px;
  font: inherit;
  color: var(--text);
  padding: 2px 6px;
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: var(--card);
}

.info-btn {
  display: inline-flex;
  vertical-align: middle;
  padding: 0;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.info-btn:hover,
.info-btn:focus-visible {
  color: var(--primary);
}

.info-btn .action-icon {
  width: 14px;
  height: 14px;
}

.hidden {
  display: none !important;
}

.toast.error {
  cursor: pointer;
}

.toast {
  position: fixed;
  bottom: 16px;
  right: 16px;
  max-width: calc(100vw - 32px);
  padding: 12px 20px;
  border-radius: 8px;
  background: var(--text);
  color: var(--text-on-primary);
  box-shadow: var(--shadow);
  z-index: 20;
}

.toast.error {
  background: var(--danger);
}

.toast-action {
  margin-left: 12px;
  padding: 4px 10px;
  border: 1px solid currentColor;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font-weight: 600;
  cursor: pointer;
}

.server-notice {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--primary);
  color: var(--text-on-primary);
  box-shadow: var(--shadow);
  z-index: 30;
  font-size: 0.9rem;
}

.theme-selector {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.theme-card {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  min-height: var(--touch-target);
  color: var(--text);
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-weight: 600;
}

.theme-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 30%, transparent);
}

.theme-preview {
  height: 56px;
  border-radius: 8px;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--border);
}

.theme-swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.2);
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.settings-head h2 {
  margin: 0;
}

.settings-head-side {
  display: flex;
  align-items: center;
  gap: 10px;
}

.settings-tabs {
  flex-wrap: wrap;
  margin-top: 8px;
}

.settings-pane {
  padding-top: 4px;
}

.about-release {
  font-weight: 600;
  margin: 12px 0 4px;
}

.about-items {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.about-items li {
  margin: 2px 0;
}

.photo-scan-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.photo-scan-item {
  display: flex;
  align-items: center;
  gap: 10px;
}

.photo-scan-item-label {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  font-weight: 600;
}

.photo-scan-item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.photo-scan-grams {
  width: 64px;
  flex-shrink: 0;
  padding: 4px 8px;
}

.photo-scan-kcal {
  min-width: 64px;
  flex-shrink: 0;
  text-align: right;
}

.dashboard-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.dashboard-col {
  display: contents;
}

.dashboard-grid .card {
  margin-bottom: 0;
}

.area-summary {
  order: 1;
}

.area-meals {
  order: 2;
}

.area-add-meal {
  order: 3;
}

.area-foods {
  order: 4;
}

.area-meals .list,
.area-foods #food-list {
  max-height: 60vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.mobile-nav {
  display: none;
}

@media (max-width: 767px) {
  .container {
    /* .container is zoomed 0.75 while the fixed nav is not, so reserve the
       real bar height divided by the zoom factor. */
    padding-bottom: calc((var(--mobile-nav-height) + env(safe-area-inset-bottom, 0px)) * 1.34 + 16px);
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .inline-form {
    flex-direction: column;
    align-items: stretch;
  }

  .food-form-row {
    flex-direction: column;
    align-items: stretch;
  }

  .inline-form:has(.btn-icon) {
    flex-direction: row;
    align-items: flex-end;
    flex-wrap: nowrap;
  }

  .inline-form:has(.btn-icon) label {
    min-width: 0;
  }

  .grid-form {
    grid-template-columns: 1fr;
  }

  .grid-form .mode-toggle button {
    width: auto;
  }

  .grid-form button,
  .inline-form button:not(.btn-icon),
  .auth-form button,
  .section-header button:not(.btn-icon) {
    width: 100%;
    justify-self: stretch;
  }

  .section-header button:not(.btn-icon) {
    flex-basis: 100%;
  }

  .area-meals .list,
  .area-foods #food-list {
    max-height: none;
    overflow-y: visible;
  }

  .toast {
    left: 16px;
    right: 16px;
    bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom, 0px) + 8px);
    max-width: none;
    text-align: center;
  }

  html,
  body {
    scroll-padding-top: 12px;
  }

  header {
    gap: 4px;
  }

  .header-controls {
    justify-content: center;
    row-gap: 4px;
  }

  .user-area {
    flex-basis: 100%;
    justify-content: center;
  }

  .mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    min-height: var(--mobile-nav-height);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0px));
    background: var(--card);
    backdrop-filter: blur(var(--card-blur));
    border-top: 1px solid var(--border);
    box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.08);
  }

  .mobile-nav-link {
    flex: 1 1 0;
    min-width: calc(var(--touch-target) * 0.75);
    min-height: calc(var(--mobile-nav-height) - 8px);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    padding: 3px 2px;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--muted);
    text-decoration: none;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-nav-link:hover,
  .mobile-nav-link:focus-visible {
    background: var(--bg);
    color: var(--text);
  }

  .mobile-nav-link.active {
    color: var(--primary);
    background: color-mix(in srgb, var(--primary) 12%, transparent);
  }
}

@media (min-width: 900px) {
  .container {
    max-width: 1200px;
    padding: 32px 24px;
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  main {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
  }

  #settings-section:not(.hidden) {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  #dashboard-section:not(.hidden) {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
  }

  .area-meals,
  .area-foods {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
  }

  .area-meals .list,
  .lists-scroll {
    flex: 1;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .area-foods #food-list {
    max-height: none;
    overflow: visible;
  }

  header {
    text-align: left;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
  }

  .header-text {
    display: flex;
    align-items: baseline;
    gap: 16px;
  }

  .dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 24px;
    align-items: stretch;
    height: 100%;
    min-height: 0;
  }

  .dashboard-col {
    display: flex;
    flex-direction: column;
    gap: 24px;
    min-height: 0;
  }
}

@media (min-width: 1280px) {
  .container {
    max-width: 1440px;
  }
}

.onboarding {
  width: min(680px, calc(100% - 24px));
  max-height: 90dvh;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
  box-sizing: border-box;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface, var(--bg));
  color: var(--text);
}
.onboarding::backdrop { background: rgba(0, 0, 0, 0.65); }
.onboarding-help { font-size: 0.875rem; line-height: 1.55; white-space: pre-line; }
.onboarding-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.onboarding .settings-pane { margin-top: 20px; }
.onboarding #onboarding-error { color: var(--danger, #dc2626); }
@media (max-width: 480px) {
  .onboarding { padding: 16px; }
  .onboarding .grid-form { grid-template-columns: 1fr; }
  .onboarding-actions button { flex: 1 1 auto; }
}

.onboarding form button[type="submit"] { display: none; }

.settings-head h2 { min-width: 0; overflow-wrap: anywhere; }
.settings-head-side { flex-wrap: wrap; min-width: 0; }
.settings-head-side #about-version,
.settings-head-side #settings-close { flex-shrink: 0; }
#onboarding-restart { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 600px) {
  .settings-head { align-items: stretch; }
  .settings-head h2 { flex-basis: 100%; }
  .settings-head-side { width: 100%; }
  #onboarding-restart { flex: 1 1 0; }
}

.onboarding .grid-form { grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.onboarding .grid-form > *,
.onboarding .inline-form > *,
.onboarding input,
.onboarding select { min-width: 0; max-width: 100%; }
.onboarding input,
.onboarding select { width: 100%; }
.onboarding #target-form { grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.onboarding .mode-toggle button { width: auto; }
.onboarding-actions button { white-space: normal; min-width: 0; max-width: 100%; }
.onboarding .form-note { grid-column: 1 / -1; }
.onboarding .onboarding-actions { position: sticky; bottom: -1px; padding: 12px 0; background: var(--card); }
.macro-grams { font-size: 0.8rem; min-height: 1.2em; }
.target-defaults-note { font-size: 0.8rem; line-height: 1.5; }
#target-recommendation { line-height: 1.5; }
@media (max-width: 480px) {
  .onboarding .grid-form { grid-template-columns: minmax(0, 1fr); }
  .onboarding-actions { gap: 8px; }
  .onboarding-actions button { font-size: 0.85rem; padding-inline: 10px; }
}

.google-auth { display: grid; gap: 12px; margin-bottom: 20px; min-width: 0; }
.google-auth h2, .google-auth p { margin: 0; }
#google-button { min-height: 44px; width: 100%; min-width: 0; }
#google-status { font-size: 0.85rem; }
#google-link-form { margin-top: 8px; }
#google-link-form[hidden], #google-retry[hidden] { display: none; }
#email-auth { border-top: 1px solid var(--border); padding-top: 16px; }
#email-auth summary { cursor: pointer; min-height: var(--touch-target); font-weight: 600; }
#email-auth .tabs { margin-bottom: 16px; }
