*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg:            white;
  --bg-surface:    white;
  --bg-subtle:     #fafafa;
  --bg-hover:      #f5f5f5;
  --text:          #333;
  --text-muted:    #767676;
  --border:        #949494;
  --border-subtle: #d1d5db;
  --shadow-sm:     rgba(0,0,0,0.08);
  --shadow-md:     rgba(0,0,0,0.12);
  --slider-empty:  #e5e7eb;
  --nav-active:    #333;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg:            #1a1a1a;
  --bg-surface:    #242424;
  --bg-subtle:     #2c2c2c;
  --bg-hover:      #2e2e2e;
  --text:          #e0e0e0;
  --text-muted:    #8a8a8a;
  --border:        #3d3d3d;
  --border-subtle: #333333;
  --shadow-sm:     rgba(0,0,0,0.4);
  --shadow-md:     rgba(0,0,0,0.5);
  --slider-empty:  #3a3a3a;
  --nav-active:    #1d6ab3;
}

body {
  margin: 0;
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  line-height: 1.5;
}

/* ── Nav ── */
nav {
  display: flex;
  justify-content: flex-start;
  align-items: stretch;
  gap: 0;
  padding: 0 2rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
}

nav a {
  padding: 0.8rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

nav a.active { color: var(--nav-active); border-bottom-color: var(--nav-active); }

/* ── Gear icon (settings) ── */
.nav-gear-wrap {
  position: absolute;
  right: 1rem;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
}

.nav-gear-wrap a {
  padding: 0.5rem;
  font-size: 1.15rem;
  color: var(--text-muted);
  text-decoration: none;
  line-height: 1;
  display: flex;
  align-items: center;
  border-bottom: 2px solid transparent;
}

.nav-gear-wrap a.active { color: var(--nav-active); border-bottom-color: var(--nav-active); }

/* ── Unit toggle (in settings) ── */
.unit-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: fit-content;
}
.unit-toggle button:first-child { border-radius: 5px 0 0 5px; }
.unit-toggle button:last-child  { border-radius: 0 5px 5px 0; }
.unit-toggle button + button    { border-left: 1px solid var(--border); }

.unit-toggle button {
  background: none;
  border: none;
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
}

.unit-toggle button.active { background: #333; color: white; }
[data-theme="dark"] .unit-toggle button.active { background: #1d6ab3; color: white; }

[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  font-size: 0.7rem;
  font-weight: 400;
  white-space: nowrap;
  padding: 0.3rem 0.55rem;
  border-radius: 5px;
  pointer-events: none;
  opacity: 0;
}

/* ── Pages ── */
.page { display: none; }
.page.active { display: block; }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
}

/* ── Typography ── */
h2 {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 0 0 0.75rem;
}

/* ── Grids ── */
.grid3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

input, select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.55rem 0.65rem;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg-surface);
  width: 100%;
  transition: border-color 0.15s;
  appearance: none;
}

input:focus, select:focus { outline: none; border-color: #1d6ab3; }

.saved-badge {
  font-size: 0.7rem;
  color: var(--text-muted);
  align-self: flex-end;
  padding-bottom: 0.1rem;
  opacity: 0;
  transition: opacity 0.3s;
}

.saved-badge.show { opacity: 1; }

/* ── Submit button ── */
.submit-btn {
  grid-column: 1 / -1;
  background: #333;
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0.65rem;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
}

[data-theme="dark"] .submit-btn { background: #1d6ab3; color: white; }

/* ── Chart tooltip ── */
.chart-tooltip {
  position: absolute;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem;
  box-shadow: 0 4px 16px var(--shadow-md);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s;
  text-align: center;
  transform: translate(-50%, calc(-100% - 14px));
  z-index: 50;
  min-width: 90px;
}
.chart-tooltip-photo { width: 100px; height: 100px; object-fit: cover; border-radius: 5px; display: block; margin: 0 auto 0.4rem; }
.chart-tooltip-date  { font-size: 0.7rem; color: var(--text-muted); margin-bottom: 0.2rem; }
.chart-tooltip-val   { font-size: 0.85rem; font-weight: 500; color: var(--text); line-height: 1.4; }
.chart-tooltip-bf    { color: #1d6ab3; }

/* ── Stats cards ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem 1rem;
}

.stat-card .stat-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.stat-card .stat-value {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
}

.stat-card .stat-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.stat-card.highlight { border-color: #333; background: #333; }
.stat-card.highlight .stat-label { color: #666; }
.stat-card.highlight .stat-value { color: white; }
.stat-card.highlight .stat-sub   { color: #666; }

.stat-card.editable { cursor: pointer; }


/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fade-in 0.1s ease;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-surface);
  border-radius: 12px;
  padding: 1.5rem;
  width: 280px;
  box-shadow: 0 8px 32px var(--shadow-md);
  animation: slide-up 0.15s ease;
}

@keyframes slide-up { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-meal-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.modal-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0;
  width: fit-content;
}
.modal-meal-color-btn {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  display: block;
}
.log-modal-label-edit {
  outline: none;
  border-bottom: 1.5px solid #1d6ab3;
  color: var(--text);
  cursor: text;
  text-transform: none;
  letter-spacing: normal;
  min-width: 3em;
}

.modal input, .modal select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.55rem 0.65rem;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg-surface);
  width: 100%;
  appearance: none;
  outline: none;
  transition: border-color 0.15s;
  margin-bottom: 1rem;
}

.modal input:focus, .modal select:focus { border-color: #1d6ab3; }

.modal-actions {
  display: flex;
  gap: 0.5rem;
}

.modal-save {
  flex: 1;
  background: #1d6ab3;
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0.6rem;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
}

.modal-cancel {
  flex: 1;
  background: none;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
}

.modal-primary { background: #333; color: white; border-color: #333; }
[data-theme="dark"] .modal-primary { background: #1d6ab3; color: white; border-color: #1d6ab3; }

.modal-danger {
  flex: 1;
  background: none;
  color: #be3030;
  border: 1px solid #be3030;
  border-radius: 6px;
  padding: 0.6rem;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
}

.danger-btn {
  background: none;
  color: #be3030;
  border: 1px solid #be3030;
  border-radius: 6px;
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
}

.delete-account-body {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0 0 1rem;
  line-height: 1.5;
}

/* ── Breakdown rows ── */
.bd-rows { margin-bottom: 0.75rem; }

.pace-option {
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.pace-selected { border-width: 2.5px; }

/* ── Range slider ── */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 8px;
  border-radius: 4px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  background: inherit;
  height: 8px;
  border-radius: 4px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -7px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 2.5px solid var(--text);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
input[type="range"]::-moz-range-track {
  background: inherit;
  height: 8px;
  border-radius: 4px;
}
input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 2.5px solid var(--text);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.bd-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.3rem 0;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text);
}

.bd-row.bd-muted { color: var(--text-muted); font-weight: 400; font-size: 0.9rem; }

.bd-divider {
  border-top: 1px solid var(--border);
  margin: 0.35rem 0;
}

.bd-goal {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 0.5rem;
}

.stats-empty {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 2rem;
}

/* ── Chart ── */
.chart-wrap { margin-bottom: 1.5rem; }

/* ── History table ── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

thead th {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  text-align: left;
  padding: 0 0 0.6rem;
  border-bottom: 1px solid var(--border);
}

tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody td { padding: 0.65rem 0; color: var(--text); }

.delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 0;
  line-height: 1;
}

.log-cell-editable {
  cursor: pointer;
}
.log-inline-edit {
  outline: none;
  border-bottom: 1.5px solid #1d6ab3;
  cursor: text;
}

.month-header {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding-top: 1.25rem;
  padding-bottom: 0.4rem;
}

.mini-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.mini-chart-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 0.75rem 0.5rem;
  min-width: 0;
}

.mini-chart-wrap canvas {
  display: block;
  height: 110px !important;
}

.mini-chart-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.empty {
  color: var(--text-muted);
  font-size: 0.95rem;
  padding: 1.5rem 0;
}

/* ── Food log ── */
.page-heading-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.page-heading-row h2 { margin: 0; flex: 1; }
.page-heading-unit-toggle { margin-left: auto; font-size: 0.8rem; }

.log-date-nav {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}
.log-date-nav-inner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.log-date-nav h2 { margin: 0; }
.log-unit-toggle { margin-left: auto; font-size: 0.8rem; }
.log-nav-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
  padding: 0 0.1rem;
  display: flex;
  align-items: center;
  align-self: center;
  transform: translateY(-0.1em);
}

.log-day-total {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
  margin: -0.25rem 0 0.75rem;
}

.log-day-goal {
  font-size: 1.15rem;
  font-weight: 600;
}

.log-chart-section {
  position: relative;
  padding-top: 1.4rem;
  margin-bottom: 0;
}

.log-chart-wrap {
  display: flex;
  height: 24px;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.log-bar-seg { height: 100%; }

.log-goal-zone {
  position: absolute;
  top: 0;
  height: calc(1.4rem + 24px);
  pointer-events: none;
}
.log-goal-zone::after {
  content: '';
  position: absolute;
  inset: 0;
  border-left: 1.5px dashed var(--text);
  border-right: 1.5px dashed var(--text);
  z-index: 2;
  pointer-events: none;
}
.log-goal-zone--in   { background: #1a8944; }
.log-goal-zone--over { background: #be3030; }

.log-overflow-zone {
  position: absolute;
  top: 0;
  height: calc(1.4rem + 24px);
  background: rgba(190, 48, 48, 0.5);
  border-bottom-right-radius: 6px;
  pointer-events: none;
}


.log-bar-axis {
  position: relative;
  height: 2.5rem;
  margin-bottom: 1.25rem;
}

.log-bar-tick {
  position: absolute;
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
}


.log-bar-axis-label {
  position: absolute;
  top: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.log-summary {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  margin-top: 1.5rem;
  margin-bottom: 1.25rem;
}

.log-summary-kcal {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
}

.log-summary-unit,
.log-summary-goal {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.log-col-qty   { color: var(--text-muted); font-size: 0.9rem; }
.log-col-kcal  { text-align: right; }
.log-col-emoji {
  cursor: pointer;
  font-size: 1.1rem;
  width: 1.6rem;
  text-align: center;
}

#food-log-table td,
#food-log-table th { padding-left: 0; padding-right: 1.5rem; }
#food-log-table td:first-child,
#food-log-table th:first-child { padding-right: 0.4rem; }
#food-log-table td:last-child,
#food-log-table th:last-child { padding-right: 0; text-align: right; }
#food-log-table th:nth-child(4) { text-align: right; }

.emoji-picker-popup {
  position: absolute;
  z-index: 300;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  padding: 0.35rem;
  display: flex;
  flex-wrap: wrap;
  width: 224px;
  max-height: 192px;
  overflow-y: auto;
}
.emoji-picker-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.25rem;
  width: 2rem;
  height: 2rem;
  border-radius: 4px;
  line-height: 1;
}

.food-total-row td {
  font-weight: 600;
  border-top: 1px solid var(--border);
  padding-top: 0.65rem;
}

.qty-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.qty-unit-toggle {
  width: 100%;
}

.qty-unit-toggle button {
  flex: 1;
}

.food-name-wrap {
  position: relative;
}

.food-search-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  max-height: 280px;
  overflow-y: auto;
}

.food-dd-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border-subtle);
}

.food-dd-item:last-child { border-bottom: none; }
.food-dd-item--saved { background: var(--bg-subtle); }
.food-dd-item--saved .food-dd-name::before {
  content: '\2605  ';
  font-size: 0.7em;
  color: #1d6ab3;
}

.food-dd-name {
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.food-dd-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.food-dd-loading {
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.food-dd-loading::after {
  content: '';
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: #1d6ab3;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.log-meal-modal {
  width: min(560px, 95vw);
  max-height: 85vh;
  overflow-y: auto;
}

.log-meals-grid {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.log-meal-btn {
  display: block;
  position: relative;
  width: 100%;
  background: #333;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 0.85rem 1rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
}
.log-meal-btn[data-meal="breakfast"] { background: #e06e1a; border-color: #e06e1a; }
.log-meal-btn[data-meal="lunch"]     { background: #1a8944; border-color: #1a8944; }
.log-meal-btn[data-meal="snack"]     { background: #4d8ec8; border-color: #4d8ec8; }
.log-meal-btn[data-meal="dinner"]    { background: #3d1a80; border-color: #3d1a80; }

.log-meal-btn-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: rgba(255,255,255,0.6);
  margin-bottom: 0.3rem;
  cursor: pointer;
  width: fit-content;
}
.log-meal-label-edit {
  outline: none;
  border-bottom: 1.5px solid rgba(255,255,255,0.7);
  color: white;
  cursor: text;
  text-transform: none;
  letter-spacing: normal;
  min-width: 3em;
}
.log-meal-btn-value {
  display: block;
  font-size: 1.15rem;
  font-weight: 600;
  color: white;
  line-height: 1.2;
}

.log-meal-actions {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.log-meal-remove-btn {
  font-size: 0.9rem;
  line-height: 1;
  color: rgba(255,255,255,0.4);
  cursor: pointer;
  padding: 0 0.05rem;
}
.log-meal-color-btn {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.45);
  cursor: pointer;
  display: block;
  flex-shrink: 0;
}
.log-add-meal-btn {
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}
.log-trash-bin {
  display: flex;
  align-items: center;
  padding: 0.2rem;
  color: var(--text-muted);
  opacity: 0;
  transition: color 0.15s, opacity 0.2s, transform 0.15s;
}
body.log-dragging .log-trash-bin { opacity: 0.4; }
body.log-dragging .log-trash-bin.log-trash-active {
  color: #be3030;
  opacity: 1;
  transform: scale(1.25);
}
.log-meal-btn[draggable="true"] { cursor: grab; }
.log-meal-btn[draggable="true"]:active { cursor: grabbing; }
.log-meal-dragging { opacity: 0.35; }
.log-meal-drop-above { box-shadow: 0 -3px 0 0 rgba(255,255,255,0.8); }
.log-meal-drop-below { box-shadow: 0  3px 0 0 rgba(255,255,255,0.8); }

.log-history-section { margin-top: 2rem; }
.log-history-section h2 { margin-bottom: 0.5rem; }
.log-history-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.55rem 0 0.55rem 1.5rem;
  border: none;
  border-bottom: 1px solid var(--border-subtle);
  background: none;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.log-history-entry:last-child { border-bottom: none; }
.log-history-entry-day { color: var(--text-muted); }
.log-history-total { font-weight: 500; }
.log-history-total--in   { color: #1a8944; }
.log-history-total--over { color: #be3030; }

.meal-color-popup {
  position: absolute;
  z-index: 300;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  padding: 0.4rem;
  display: flex;
  gap: 0.35rem;
}
.meal-color-option {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
  flex-shrink: 0;
}
.meal-color-option.active  { border-color: var(--text); }

.add-food-form {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 0.5rem;
  align-items: end;
}

@media (max-width: 500px) {
  .add-food-form {
    grid-template-columns: 1fr 1fr;
  }
  .add-food-form .food-name-wrap,
  .add-food-form .submit-btn { grid-column: 1 / -1; }
}

.dashboard-empty-prompt {
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  text-align: center;
  margin-bottom: 2rem;
}

.dashboard-empty-prompt p {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.dashboard-empty-prompt button {
  background: #333;
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0.55rem 1.25rem;
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
}

[data-theme="dark"] .dashboard-empty-prompt button { background: #1d6ab3; color: white; }

/* ── History accordion ── */
details.history-year {
  border-bottom: 1px solid var(--border);
}

details.history-year > summary,
details.history-month > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  user-select: none;
}

details.history-year > summary::-webkit-details-marker,
details.history-month > summary::-webkit-details-marker { display: none; }
details.history-year > summary::marker,
details.history-month > summary::marker { display: none; }

details.history-year > summary {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0.75rem 0;
}

details.history-month > summary {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  padding: 0.45rem 0 0.45rem 0.75rem;
}

details.history-year > summary::after,
details.history-month > summary::after {
  content: '›';
  margin-left: auto;
  color: var(--border);
  font-size: 1.1rem;
  line-height: 1;
  transition: transform 0.15s;
  display: inline-block;
}

details.history-year[open] > summary::after,
details.history-month[open] > summary::after {
  transform: rotate(90deg);
}

.history-entry {
  display: flex;
  align-items: center;
  padding: 0.55rem 0 0.55rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.95rem;
}

.history-entry:last-child { border-bottom: none; }

.history-header {
  display: flex;
  align-items: center;
  padding: 0 0 0.4rem 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.25rem;
}
.history-header span {
  flex: 1;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}
.history-header span:nth-child(2),
.history-header span:nth-child(3),
.history-header span:nth-child(4) { text-align: center; }
.history-header span:last-child { text-align: right; }

.entry-day   { flex: 1; color: var(--text-muted); font-size: 0.9rem; }
.entry-wt    { flex: 1; text-align: center; color: var(--text); }
.entry-bf    { flex: 1; text-align: center; color: var(--text-muted); font-size: 0.9rem; }
.entry-photo { flex: 1; display: flex; justify-content: center; }
.entry-photo img { width: 28px; height: 28px; object-fit: cover; border-radius: 3px; cursor: pointer; display: block; }
.entry-del   { flex: 1; text-align: right; }

/* ── Photo upload field ── */
.photo-upload {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1.5px dashed var(--border);
  border-radius: 6px;
  padding: 0.75rem;
  min-height: 3rem;
  background: var(--bg-surface);
}
.photo-camera-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  color: var(--text);
  line-height: 1;
  display: flex;
}
.photo-upload-menu {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 300;
  align-items: center;
  justify-content: center;
}
.photo-upload-menu.open { display: flex; }
.photo-upload-popup {
  background: var(--bg-surface);
  border-radius: 12px;
  overflow: hidden;
  min-width: 200px;
  box-shadow: 0 8px 32px var(--shadow-md);
}
.photo-upload-popup label {
  display: block;
  padding: 0.9rem 1.5rem;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text);
  text-align: center;
}
.photo-upload-popup label + label { border-top: 1px solid var(--border-subtle); }
.photo-preview { display: none; max-height: 160px; max-width: 100%; border-radius: 4px; object-fit: contain; cursor: pointer; }
.photo-clear-btn {
  display: none;
  position: absolute;
  top: 0.3rem;
  right: 0.3rem;
  background: rgba(0,0,0,0.55);
  color: white;
  border: none;
  border-radius: 50%;
  width: 1.4rem;
  height: 1.4rem;
  font-size: 1rem;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  line-height: 1;
  z-index: 1;
}
.photo-upload.has-photo .photo-camera-btn { display: none; }
.photo-upload.has-photo .photo-clear-btn  { display: flex; }
.photo-upload.has-photo .photo-preview    { display: block; }

/* ── Photo viewer modal ── */
.photo-viewer-backdrop { background: rgba(0,0,0,0.8); }
.photo-viewer { background: transparent; padding: 0; box-shadow: none; max-width: min(90vw, 700px); width: auto; }
.photo-viewer img { max-width: 100%; max-height: 85vh; border-radius: 8px; display: block; }

/* ── Login overlay ── */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.login-card {
  width: 100%;
  max-width: 340px;
  margin: 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 4px 24px var(--shadow-md);
}

.login-title {
  margin: 0 0 1.5rem;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  text-align: center;
}

.auth-tabs {
  display: flex;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.auth-tab {
  flex: 1;
  padding: 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  font-family: inherit;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
}

.auth-tab.active { background: #333; color: white; }
[data-theme="dark"] .auth-tab.active { background: #1d6ab3; color: white; }

/* Both forms share one grid cell so the card height is always the taller (register) form */
.login-forms              { display: grid; }
.login-forms > form       { grid-area: 1 / 1; display: flex; flex-direction: column; gap: 0.75rem; }
.login-forms > form.auth-hidden { visibility: hidden; pointer-events: none; }
.login-card .field        { gap: 0.3rem; }
.login-card .submit-btn   { margin-top: 0.25rem; }

.auth-error {
  font-size: 0.78rem;
  color: #be3030;
  min-height: 1.1em;
}

/* ── Dark mode: highlight stat card flips to blue ── */
[data-theme="dark"] .stat-card.highlight                     { background: #1d6ab3; border-color: #1d6ab3; }
[data-theme="dark"] .stat-card.highlight .stat-label         { color: rgba(255,255,255,0.65); }
[data-theme="dark"] .stat-card.highlight .stat-value         { color: white; }
[data-theme="dark"] .stat-card.highlight .stat-sub           { color: rgba(255,255,255,0.65); }
