/* ============================================================
   styles.css — mobile-first, neutral, big touch targets.
   One-handed use at a kitchen bench: clarity over decoration.
   ============================================================ */
:root {
  --bg: #101418;
  --surface: #191f26;
  --surface-2: #232b34;
  --text: #eef2f6;
  --muted: #9aa7b4;
  --border: #313b46;
  --accent: #3d8bfd;
  --accent-text: #ffffff;
  --error: #ff6b6b;
  --success: #4ecb8b;
  --radius: 14px;
  --tap: 52px; /* minimum touch target */
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-2: #eef1f4;
    --text: #16202b;
    --muted: #5b6b7a;
    --border: #d7dee5;
    --accent: #1f6feb;
    --accent-text: #ffffff;
  }
}

* {
  box-sizing: border-box;
}

/* The `hidden` attribute must always win over the display rules below
   (.view and .modal set display:flex, which otherwise overrides the UA
   `[hidden] { display:none }` and leaves every screen/modal stacked). */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px
    max(16px, env(safe-area-inset-bottom));
}

.view {
  min-height: 100dvh;
  display: flex;
  align-items: center;
}

.card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
}
.card.narrow {
  max-width: 400px;
  margin: 0 auto;
}

h1 {
  font-size: 1.5rem;
  margin: 0 0 4px;
}

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

/* ---- forms ---- */
label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 14px 0 6px;
}

input,
select {
  width: 100%;
  min-height: var(--tap);
  padding: 0 14px;
  font-size: 1.05rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  appearance: none;
}
select {
  padding-right: 40px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 16px center, right 11px center;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}
input:focus,
select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  min-height: var(--tap);
  padding: 0 18px;
  font-size: 1.05rem;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
}
button.big {
  width: 100%;
  margin-top: 20px;
}
button.primary {
  background: var(--accent);
  color: var(--accent-text);
}
button.primary:disabled {
  opacity: 0.55;
  cursor: default;
}
button.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}

/* ---- status lines ---- */
.status {
  margin: 14px 0 0;
  font-size: 0.92rem;
}
.status[data-kind="error"] {
  color: var(--error);
}
.status[data-kind="success"] {
  color: var(--success);
}
.status[data-kind="info"] {
  color: var(--muted);
}

/* ---- summary ---- */
.target-hero {
  text-align: center;
  padding: 8px 0 14px;
}
.target-number {
  font-size: 3.4rem;
  font-weight: 700;
  line-height: 1;
}
.target-unit {
  color: var(--muted);
  margin-top: 4px;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 18px 0;
}
.stats > div {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 12px;
}
.stats dt {
  color: var(--muted);
  font-size: 0.78rem;
}
.stats dd {
  margin: 2px 0 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.inline-form {
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.row {
  display: flex;
  gap: 10px;
  align-items: center;
}
.row.spread {
  justify-content: space-between;
  margin-top: 18px;
}
.row input {
  flex: 1;
}

/* ---- utilities ---- */
.small {
  font-size: 0.82rem;
}
.muted.small {
  color: var(--muted);
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 12px;
}

/* Top-aligned app views (scrollable content, room for the tab bar). */
.view.top {
  align-items: flex-start;
  min-height: auto;
  padding-bottom: 84px;
}

/* ---- bottom tab bar ---- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}
.tabbar button {
  flex: 1;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}
.tabbar button {
  padding: 0 2px;
}
.tabbar button span {
  font-size: 1.3rem;
  line-height: 1;
}
.tabbar button.active {
  color: var(--accent);
}

/* ---- foods tab ---- */
.add-actions {
  display: grid;
  gap: 10px;
  margin: 4px 0 16px;
}
button.tall {
  width: 100%;
  min-height: 58px;
  font-size: 1rem;
}
#foods-search {
  margin-bottom: 12px;
}
.foods-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}
.food-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.food-main {
  flex: 1;
  min-width: 0;
}
.food-name {
  font-weight: 600;
}
.food-meta {
  margin-top: 2px;
}
.food-right {
  text-align: right;
  flex-shrink: 0;
}
.food-kcal {
  font-weight: 700;
}

/* ---- source badge ---- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}
.badge.warn {
  background: color-mix(in srgb, var(--error) 18%, transparent);
  color: var(--error);
  border-color: color-mix(in srgb, var(--error) 40%, transparent);
}
.badge.small {
  margin-top: 4px;
}

/* ---- modal / bottom sheet (food editor) ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
}
.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  border: 1px solid var(--border);
  padding: 20px 18px calc(18px + env(safe-area-inset-bottom));
}
.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sheet-head h2 {
  margin: 0;
  font-size: 1.2rem;
}
.sheet-actions {
  margin-top: 20px;
}

/* ---- scanner overlay ---- */
.modal.dark {
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 16px;
  background: #000;
  padding: 20px;
}
.scanner-box {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: 60dvh;
  overflow: hidden;
  border-radius: var(--radius);
  background: #111;
}
.scanner-box video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.scanner-frame {
  position: absolute;
  inset: 22% 12%;
  border: 3px solid rgba(255, 255, 255, 0.85);
  border-radius: 12px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.25);
}
.scanner-status {
  color: #fff;
  text-align: center;
  margin: 0;
}
.scanner-manual {
  display: flex;
  gap: 8px;
}
.scanner-manual input {
  flex: 1;
}
button.ghost.light {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.4);
}
button.ghost.danger {
  color: var(--error);
  border-color: color-mix(in srgb, var(--error) 40%, transparent);
}

/* ---- meal editor ---- */
.section-head {
  font-size: 0.9rem;
  margin: 20px 0 8px;
  color: var(--muted);
}
.ing-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
}
.ing-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.ing-info {
  flex: 1;
  min-width: 0;
}
.ing-name {
  font-weight: 600;
}
.qty {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
button.step {
  min-height: 40px;
  width: 40px;
  padding: 0;
  font-size: 1.2rem;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
}
button.step.rm {
  color: var(--error);
  font-size: 0.95rem;
}
.qty-input {
  width: 52px;
  min-height: 40px;
  padding: 0 6px;
  text-align: center;
  font-size: 1rem;
}
.ing-results {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 6px;
}
.ing-result {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  text-align: left;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-weight: 500;
}
.ing-results .pad {
  padding: 8px 4px;
}
.meal-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding: 14px;
  background: var(--surface-2);
  border-radius: 10px;
}
.preview-kcal {
  font-size: 1.2rem;
  font-weight: 700;
}
.pad {
  padding: 10px 4px;
}

/* ---- log tab ---- */
.log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.log-date {
  font-size: 1.25rem;
  font-weight: 700;
}
.head-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.icon-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 0;
  font-size: 1.3rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  line-height: 1;
}
.pill {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  border: 1px solid var(--border);
  color: var(--muted);
  background: var(--surface-2);
}
.pill[data-kind="ok"] {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 40%, transparent);
}
.pill[data-kind="pending"],
.pill[data-kind="sync"] {
  color: #e0a53d;
  border-color: color-mix(in srgb, #e0a53d 45%, transparent);
}
.pill[data-kind="off"] {
  color: var(--error);
  border-color: color-mix(in srgb, var(--error) 45%, transparent);
}

.progress-block {
  margin-bottom: 18px;
}
.progress-nums {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.progress-total {
  font-size: 2.6rem;
  font-weight: 700;
  line-height: 1;
}
.progress-of {
  font-size: 1rem;
}
.progress-track {
  height: 12px;
  margin: 12px 0 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}
.progress-fill[data-over="1"] {
  background: var(--error);
}
.progress-remaining {
  font-size: 0.9rem;
  font-weight: 600;
}

.quick-form {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.quick-form input {
  flex: 1;
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}
.chip {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  max-width: 150px;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
}
.chip-name {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 128px;
}
.chip-kcal {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 700;
}

.entry-list {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
}
.entry-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 2px;
  border-bottom: 1px solid var(--border);
}
.entry-row.pending {
  opacity: 0.6;
}
.entry-main {
  flex: 1;
  min-width: 0;
}
.entry-name {
  font-weight: 600;
}
.entry-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.entry-kcal {
  font-weight: 700;
}

/* ---- dashboard ---- */
.range-toggle {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
}
.range-toggle button {
  min-height: 36px;
  padding: 0 14px;
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 8px;
  font-size: 0.9rem;
}
.range-toggle button.active {
  background: var(--accent);
  color: var(--accent-text);
}
.chart-box {
  width: 100%;
  margin: 4px 0 8px;
}
.chart {
  width: 100%;
  height: auto;
  display: block;
}
.chart .bar-under {
  fill: var(--accent);
}
.chart .bar-over {
  fill: var(--error);
}
.chart .bar-empty {
  fill: var(--surface-2);
}
.chart .target-line {
  stroke: var(--muted);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}
.chart .wline {
  stroke: var(--accent);
  stroke-width: 2;
}
.chart .pt {
  fill: var(--accent);
}
.chart .lbl {
  fill: var(--muted);
  font-size: 9px;
  font-family: inherit;
}

/* ---- log picker ---- */
.picker-results {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 55dvh;
  overflow-y: auto;
  margin: 8px 0;
}
.picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
}
.picker-info {
  flex: 1;
  min-width: 0;
}
.picker-add {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.picker-add .primary {
  min-height: 40px;
  padding: 0 14px;
}

/* ---- shopping list ---- */
.shop-list {
  list-style: none;
  margin: 6px 0 14px;
  padding: 0;
}
.shop-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 2px;
  border-bottom: 1px solid var(--border);
}
.shop-check {
  width: 26px;
  height: 26px;
  min-height: 26px;
  flex-shrink: 0;
  accent-color: var(--accent);
}
.shop-main {
  flex: 1;
  min-width: 0;
}
.shop-name {
  font-weight: 600;
}
.shop-row.done .shop-name {
  text-decoration: line-through;
  color: var(--muted);
  font-weight: 500;
}
