/* Calorie tracker styles: mobile first, RTL-safe logical properties, dark mode via prefers-color-scheme. */
:root {
  --green: #2e7d32;
  --link: #1b5e20;
  --bg: #f5f7f5;
  --card: #ffffff;
  --text: #1d1d1d;
  --muted: #5f6b61;
  --line: #d6dcd7;
  --danger: #b71c1c;
  --radius: 12px;
  --focus: #1565c0;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --link: #81c784;
    --bg: #121412;
    --card: #1e221f;
    --text: #eef2ee;
    --muted: #a9b5ab;
    --line: #3a423c;
    --danger: #ef9a9a;
    --focus: #90caf9;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --link: #81c784;
  --bg: #121412;
  --card: #1e221f;
  --text: #eef2ee;
  --muted: #a9b5ab;
  --line: #3a423c;
  --danger: #ef9a9a;
  --focus: #90caf9;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

body {
  margin: 0;
  padding-bottom: 72px;
  font-family: system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 12px 16px;
  background: var(--green);
  color: #fff;
}

.app-header h1 {
  margin: 0;
  font-size: 1.25rem;
}

.banner {
  margin: 12px 16px 0;
  padding: 12px;
  border-radius: var(--radius);
  background: #fff3cd;
  color: #5d4037;
}

.tab {
  display: grid;
  gap: 16px;
  max-width: 640px;
  margin-inline: auto;
  padding: 16px;
}

/* Cards and headings */
.card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}

.card h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
}

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

.card-head h2 {
  margin: 0 0 12px;
}

.hint,
.muted {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.preview {
  margin: 0;
  padding: 10px;
  border-radius: 10px;
  background: var(--bg);
}

.error {
  margin: 0;
  color: var(--danger);
}

.empty {
  padding: 8px 0;
  color: var(--muted);
  list-style: none;
}

.link-btn {
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--link);
  text-decoration: underline;
}

/* Buttons */
button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--green);
  border-radius: 10px;
  background: var(--green);
  color: #fff;
  font: inherit;
  cursor: pointer;
}

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

.btn-secondary {
  background: transparent;
  color: var(--green);
}

.btn-small {
  min-height: 44px;
  padding: 6px 12px;
}

.btn-small.danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}

.btn-round {
  width: 56px;
  height: 56px;
  padding: 0;
  border-radius: 50%;
  font-size: 1.6rem;
}

.btn-block {
  width: 100%;
}

/* Forms */
label {
  display: grid;
  gap: 4px;
  font-size: 0.95rem;
  color: var(--muted);
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px;
  margin-bottom: 12px;
}

.inline-form label {
  flex: 1 1 120px;
}

.inline-form label.grow {
  flex: 2 1 180px;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  color: var(--text);
}

.check input {
  width: 20px;
  min-height: 20px;
}

.manual summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  color: var(--link);
  cursor: pointer;
}

.manual .form-grid {
  margin-top: 12px;
}

.file-label:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Diary */
.date-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.date-label {
  flex: 1 1 160px;
  margin: 0;
  text-align: center;
  font-weight: 700;
}

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

.summary > div {
  padding: 8px;
  border-radius: 10px;
  background: var(--bg);
}

.summary dt {
  font-size: 0.85rem;
  color: var(--muted);
}

.summary dd {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
}

.summary .key {
  grid-column: 1 / -1;
  background: var(--green);
  color: #fff;
}

.summary .key dt {
  color: #e8f5e9;
}

.summary .key dd {
  color: #fff;
}

.macro {
  display: grid;
  grid-template-columns: 64px 1fr;
  align-items: center;
  gap: 4px 8px;
  margin-top: 8px;
}

.macro .muted {
  grid-column: 2;
}

progress {
  width: 100%;
  height: 12px;
  accent-color: var(--green);
}

.entries,
.result-list {
  display: grid;
  gap: 4px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.entry-main {
  display: grid;
  min-width: 0;
}

.entry-name {
  overflow-wrap: anywhere;
  font-weight: 600;
}

.entry-actions {
  display: flex;
  flex-shrink: 0;
  gap: 6px;
}

.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.stepper-value {
  min-width: 110px;
  margin: 0;
  font-size: 1.2rem;
  text-align: center;
}

/* Progress */
.chart {
  display: block;
  width: 100%;
  height: 200px;
  margin-top: 8px;
  border-radius: 10px;
  background: #fff;
}

.segmented {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--green);
  border-radius: 10px;
}

.segmented button {
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--green);
}

.segmented [aria-pressed="true"],
.segmented [aria-selected="true"] {
  background: var(--green);
  color: #fff;
}

.streak {
  margin: 0;
  text-align: center;
  font-weight: 700;
}

/* Bottom tab bar */
.tabbar {
  position: fixed;
  bottom: 0;
  inset-inline: 0;
  z-index: 3;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--line);
  background: var(--card);
}

.tabbar button {
  flex: 1;
  min-height: 56px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}

.tabbar button[aria-current="page"] {
  color: var(--green);
  box-shadow: inset 0 3px 0 var(--green);
}

.toast {
  position: fixed;
  bottom: 80px;
  inset-inline: 16px;
  z-index: 5;
  max-width: 480px;
  margin-inline: auto;
  padding: 12px 16px;
  border-radius: 10px;
  background: #323832;
  color: #fff;
  text-align: center;
}

/* Add food dialog */
.food-dialog {
  width: min(100% - 32px, 520px);
  max-height: calc(100vh - 32px);
  padding: 16px;
  overflow: auto;
  border: 0;
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
}

.food-dialog::backdrop {
  background: rgb(0 0 0 / 0.5);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.dialog-head h2 {
  margin: 0;
  font-size: 1.2rem;
}

.food-tabs {
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.pane,
.food-dialog form {
  display: grid;
  gap: 12px;
}

.food-dialog form[hidden] {
  display: none;
}

.dialog-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.quick-qty {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.4rem 0;
}

.result-list {
  max-height: 50vh;
  overflow: auto;
}

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

.choice {
  flex: 1;
  min-width: 0;
  flex-direction: column;
  align-items: flex-start;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  text-align: start;
}

.choice .muted {
  color: var(--muted);
}

@media (min-width: 600px) {
  .summary {
    grid-template-columns: repeat(5, 1fr);
  }

  .summary .key {
    grid-column: auto;
  }
}

.photo-list .photo-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  align-items: end;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.photo-row input[name="name"] {
  grid-column: 1 / -1;
}

.photo-row input,
.photo-row select {
  width: 100%;
  min-width: 0;
}

.photo-row [aria-invalid="true"] {
  outline: 2px solid #c62828;
}

#photo-totals {
  font-weight: 600;
}
