/* Calorific on the web. Palette from Website/src/static/site.css, which follows the app's Theme.swift. */

:root {
  --bg: #080913;
  --surface: rgba(255, 255, 255, 0.05);
  --surface-solid: #12131f;
  --surface-hover: rgba(255, 255, 255, 0.08);
  --line: rgba(255, 255, 255, 0.1);
  --text: #f3f3f9;
  --text-mid: #b9bacb;
  --text-dim: #8b8da6;
  --violet: #8066ff;
  --cyan: #1ad9fa;
  --magenta: #ff409e;
  --coral: #ff6b5c;
  --amber: #ffb833;
  --lime: #8cf266;
  --link: #9fe9fb;
  --track: rgba(255, 255, 255, 0.08);
  --aurora: 0.3;
  --btn-bg: #f3f3f9;
  --btn-text: #080913;
  --danger: #ff6b5c;
  --round: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --radius: 18px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f4f9;
    --surface: rgba(255, 255, 255, 0.8);
    --surface-solid: #ffffff;
    --surface-hover: rgba(8, 9, 19, 0.04);
    --line: rgba(8, 9, 19, 0.1);
    --text: #0c0d1a;
    --text-mid: #41435a;
    --text-dim: #63657e;
    --link: #0a6c86;
    --track: rgba(8, 9, 19, 0.08);
    --aurora: 0.16;
    --btn-bg: #0c0d1a;
    --btn-text: #ffffff;
    --danger: #d2392b;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: var(--link); }
h1, h2, h3 { font-family: var(--round); line-height: 1.2; margin: 0; }
p { margin: 0; }
.muted { color: var(--text-dim); }
.small { font-size: 0.85rem; }
.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; }

.aurora {
  position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: var(--aurora);
  background:
    radial-gradient(40% 35% at 15% 0%, var(--violet), transparent 70%),
    radial-gradient(35% 30% at 90% 10%, var(--cyan), transparent 70%),
    radial-gradient(40% 30% at 70% 100%, var(--magenta), transparent 70%);
  filter: blur(40px);
}

.wordmark {
  font: 800 2rem/1 var(--round);
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--violet), var(--cyan));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.wordmark.small { font-size: 1.3rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

/* --- Controls --- */

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; opacity: 0.5; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

label { display: grid; gap: 6px; font-size: 0.9rem; color: var(--text-mid); }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-hover);
  color: var(--text);
  font-size: 16px; /* 16px stops iOS zooming into a field */
}
textarea { resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--cyan); }
input[type=date], input[type=time] { min-width: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface-hover); color: var(--text);
  font-weight: 600; white-space: nowrap;
  transition: transform 120ms var(--ease-out), background-color 150ms;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn.primary { background: var(--btn-bg); color: var(--btn-text); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.apple { background: #000; color: #fff; border-color: #000; }
@media (prefers-color-scheme: dark) { .btn.apple { background: #fff; color: #000; } .btn.apple img { filter: invert(1); } }
.btn.wide { width: 100%; }
@media (hover: hover) {
  .btn:hover:not(:disabled) { background: var(--surface); }
  .btn.primary:hover:not(:disabled) { background: var(--btn-bg); opacity: 0.9; }
}

.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 999px;
  border: 0; background: transparent; color: var(--text);
  font-size: 1.4rem; line-height: 1;
}
.icon-btn.small { width: 32px; height: 32px; font-size: 0.9rem; color: var(--text-dim); }
@media (hover: hover) { .icon-btn:hover { background: var(--surface-hover); } }

.chip {
  min-height: 32px; padding: 4px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; color: var(--text-mid);
  font-size: 0.85rem; font-weight: 600;
}
@media (hover: hover) { .chip:hover { background: var(--surface-hover); color: var(--text); } }

.link-btn { border: 0; background: none; color: var(--link); padding: 4px 0; font-size: 0.9rem; justify-self: start; }

.notice { padding: 10px 14px; border-radius: 12px; font-size: 0.9rem; background: rgba(26, 217, 250, 0.1); border: 1px solid rgba(26, 217, 250, 0.25); }
.notice.warn { background: rgba(255, 184, 51, 0.1); border-color: rgba(255, 184, 51, 0.35); }
.error { color: var(--danger); font-size: 0.9rem; }
.warning { color: var(--amber); font-size: 0.85rem; }
@media (prefers-color-scheme: light) { .warning { color: #a86500; } }

.demo-banner {
  padding: 8px 16px; text-align: center; font-size: 0.85rem;
  background: var(--amber); color: #1a1200;
}
.demo-banner a { color: inherit; font-weight: 700; }

/* --- Sign in --- */

.center-view { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.signin { width: min(400px, 100%); padding: 32px 28px; display: grid; gap: 16px; }
.signin form { display: grid; gap: 14px; }
.other-signin { display: grid; gap: 10px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--text-dim); font-size: 0.85rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.fine { font-size: 0.85rem; color: var(--text-dim); }

/* --- Day --- */

.day-view { min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-left)) 10px max(16px, env(safe-area-inset-right));
  padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 75%, transparent);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--line);
}
.day-nav { display: flex; align-items: center; gap: 4px; justify-self: center; }
.day-title { position: relative; display: block; padding: 6px 10px; border-radius: 10px; font: 700 1.1rem/1.2 var(--round); color: var(--text); cursor: pointer; text-align: center; min-width: 9ch; }
.day-title input { position: absolute; inset: 0; opacity: 0; cursor: pointer; min-height: 0; padding: 0; }
.day-title input::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: auto; height: auto; opacity: 0; cursor: pointer; }
@media (hover: hover) { .day-title:hover { background: var(--surface-hover); } }
.topbar-end { display: flex; align-items: center; gap: 8px; justify-self: end; }

.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px; z-index: 30;
  display: grid; padding: 8px; border-radius: 14px;
  background: var(--surface-solid); border: 1px solid var(--line); box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}
.menu-panel p { padding: 8px 10px; overflow-wrap: anywhere; }
.menu-panel a, .menu-panel button {
  display: block; text-align: left; padding: 10px; border-radius: 8px; border: 0;
  background: none; color: var(--text); text-decoration: none; font-size: 0.95rem;
}
@media (hover: hover) { .menu-panel a:hover, .menu-panel button:hover { background: var(--surface-hover); } }

.day-main {
  max-width: 1080px; margin: 0 auto; padding: 20px 16px 120px;
  display: grid; gap: 16px;
}
@media (min-width: 880px) {
  .day-main { grid-template-columns: 320px 1fr; align-items: start; gap: 24px; padding-top: 28px; }
  .totals { position: sticky; top: 84px; }
  #day-error { grid-column: 2; }
}

.totals { padding: 20px; display: grid; gap: 14px; }
.kcal-row { display: flex; justify-content: space-between; align-items: end; gap: 16px; }
.big { font: 800 2.8rem/1 var(--round); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.totals.over .big { color: var(--coral); }
.kcal-facts { display: grid; gap: 4px; margin: 0; text-align: right; }
.kcal-facts div { display: flex; gap: 10px; justify-content: end; }
.kcal-facts dt { color: var(--text-dim); font-size: 0.85rem; }
.kcal-facts dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }

.bar { height: 10px; border-radius: 999px; background: var(--track); overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--violet), var(--cyan)); transition: width 400ms var(--ease-out); }
.totals.over .bar span { background: linear-gradient(90deg, var(--amber), var(--coral)); }
.bar.thin { height: 6px; }

.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.macro { display: grid; gap: 4px; }
.macro-label { font-size: 0.8rem; color: var(--text-dim); }
.macro-value { font-weight: 600; font-variant-numeric: tabular-nums; font-size: 0.95rem; white-space: nowrap; }
.macro-value .muted { font-weight: 400; font-size: 0.8rem; }
.macro.p .bar span { background: var(--magenta); }
.macro.c .bar span { background: var(--amber); }
.macro.f .bar span { background: var(--lime); }

.meals { display: grid; gap: 14px; }
.meal { padding: 6px 6px 8px; }
.meal-head { display: flex; align-items: center; gap: 10px; padding: 10px 10px 6px 14px; }
.meal-head h2 { font-size: 1.15rem; }
.meal-kcal { margin-left: auto; color: var(--text-dim); font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.empty { padding: 6px 14px 10px; font-size: 0.9rem; }

.items, .results, .group-foods, .basket { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.item {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border: 0; border-radius: 12px;
  background: transparent; color: inherit; text-align: left;
}
@media (hover: hover) { .item:hover { background: var(--surface-hover); } }
.item:active { background: var(--surface-hover); }
.item-main { display: grid; min-width: 0; flex: 1; }
.item-name { font-weight: 600; overflow-wrap: anywhere; }
.item-sub { font-size: 0.85rem; }
.item-kcal { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.item-kcal small { font-weight: 400; color: var(--text-dim); }
.item.group .item-name::before {
  content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 8px; vertical-align: 2px;
  border-radius: 2px; background: linear-gradient(135deg, var(--violet), var(--cyan));
}
.chev, .add-plus { color: var(--text-dim); font-size: 1.2rem; }
.add-plus { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 999px; border: 1px solid var(--line); font-size: 1rem; }

.fab {
  position: fixed; right: max(20px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 999px; border: 0;
  background: linear-gradient(135deg, var(--violet), var(--cyan)); color: #fff;
  font-size: 2rem; line-height: 1; box-shadow: 0 10px 30px rgba(128, 102, 255, 0.45);
  transition: transform 140ms var(--ease-out);
}
.fab:active { transform: scale(0.94); }
@media (min-width: 880px) { .fab { display: none; } }
@media (max-width: 879px) { .add-desktop { display: none; } }
@media (max-width: 520px) {
  .topbar { grid-template-columns: auto 1fr auto; }
  .wordmark.small { display: none; }
  .topbar { grid-template-columns: 1fr auto; }
  .day-nav { justify-self: start; }
}

/* --- Sheets (dialogs) --- */

dialog.sheet {
  width: min(560px, calc(100vw - 24px));
  max-height: min(88dvh, 860px);
  padding: 0; border: 1px solid var(--line); border-radius: 22px;
  background: var(--surface-solid); color: var(--text);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
  display: none; flex-direction: column; overflow: hidden;
}
dialog.sheet[open] { display: flex; animation: sheet-in 220ms var(--ease-out); }
dialog.wide-sheet { width: min(680px, calc(100vw - 24px)); }
dialog.small-sheet { width: min(400px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(4, 5, 12, 0.6); backdrop-filter: blur(3px); }
@keyframes sheet-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } }
@media (max-width: 600px) {
  dialog.sheet, dialog.wide-sheet {
    width: 100vw; max-width: 100vw; max-height: 92dvh;
    margin: auto 0 0; border-radius: 22px 22px 0 0; border-bottom: 0;
  }
  dialog.sheet[open] { animation-name: sheet-up; }
  dialog.small-sheet { margin: auto; width: calc(100vw - 32px); border-radius: 22px; border-bottom: 1px solid var(--line); }
  @keyframes sheet-up { from { transform: translateY(40px); opacity: 0.6; } }
}
@media (prefers-reduced-motion: reduce) { dialog.sheet[open] { animation: none; } .bar span { transition: none; } }

.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 16px 8px 20px; }
.sheet-head h2 { font-size: 1.25rem; overflow-wrap: anywhere; }
.sheet-body { padding: 8px 20px 16px; overflow-y: auto; display: grid; gap: 16px; overscroll-behavior: contain; }
.sheet-body h3 { font-size: 1rem; }
.sheet-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.sheet-foot .muted { font-size: 0.85rem; font-variant-numeric: tabular-nums; }
#basket-total strong { color: var(--text); font-weight: 600; }
@media (max-width: 480px) { #basket-total .macro-line { display: none; } }
.small-sheet .sheet-body { padding-top: 22px; gap: 8px; }

.when-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; align-items: end; }
.when-day { grid-column: 1 / -1; }

.tabs { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--track); }
.tabs button { flex: 1; min-height: 38px; border: 0; border-radius: 10px; background: transparent; color: var(--text-mid); font-weight: 600; }
.tabs button[aria-selected=true] { background: var(--surface-solid); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2); }

#form-describe, #form-photo { display: grid; gap: 12px; }
#form-describe .btn, #form-photo .btn { justify-self: end; }
#pane-search { display: grid; gap: 8px; }
.results { max-height: 320px; overflow-y: auto; }
.results .empty, .results .error { padding: 10px 14px; }
[aria-busy=true] { opacity: 0.6; transition: opacity 200ms; }

.drop {
  display: grid; place-items: center; gap: 10px; min-height: 160px; padding: 16px;
  border: 1.5px dashed var(--line); border-radius: 16px; cursor: pointer; text-align: center; color: var(--text-mid);
}
.drop.over { border-color: var(--cyan); background: var(--surface-hover); }
.drop img { max-width: 100%; max-height: 240px; border-radius: 12px; object-fit: contain; }
.drop:focus-within { outline: 2px solid var(--cyan); outline-offset: 2px; }

.basket-wrap { display: grid; gap: 8px; }
.basket { gap: 8px; }
.basket-item { display: grid; gap: 8px; padding: 12px; border-radius: 14px; background: var(--surface-hover); }
.basket-top { display: flex; align-items: center; gap: 10px; }
.basket-top .item-name { flex: 1; min-width: 0; }
.portion { display: grid; grid-template-columns: 96px 1fr; gap: 8px; }
.portion-row { display: grid; gap: 6px; }
.portion-row .label { font-size: 0.9rem; color: var(--text-mid); }

#form-entry, #form-group { display: grid; gap: 14px; }
.nutrition { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.nutrition legend { font-size: 0.9rem; color: var(--text-mid); margin-bottom: 6px; padding: 0; }
@media (max-width: 480px) { .nutrition { grid-template-columns: repeat(2, 1fr); } }
.group-foods { border: 1px solid var(--line); border-radius: 14px; padding: 4px; }

.toast {
  position: fixed; left: 50%; bottom: max(96px, calc(env(safe-area-inset-bottom) + 96px)); transform: translateX(-50%);
  z-index: 50; max-width: min(520px, calc(100vw - 32px));
  padding: 12px 18px; border-radius: 14px;
  background: var(--btn-bg); color: var(--btn-text); font-weight: 600; font-size: 0.95rem;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
  animation: toast-in 220ms var(--ease-out);
}
.toast.warn { background: var(--amber); color: #1a1200; }
@media (min-width: 880px) { .toast { bottom: 32px; } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
