/* stockpot web UI: the foundation every screen shares. Mobile first, light and dark
   (prefers-color-scheme), system font, one accent. Screens add their own file
   (inventory.css, ...) through base.html's `styles` block. No inline styles anywhere:
   the CSP allows only this origin's stylesheets. */

:root {
  color-scheme: light dark;
  --accent: #b5462d;
  --accent-strong: #973620;
  --accent-ink: #ffffff;
  --accent-soft: #f9ebe5;
  --bg: #f6f2ed;
  --surface: #ffffff;
  --surface-2: #efe9e2;
  --ink: #221c18;
  --ink-2: #5f5650;
  /* Every ink is at least 4.5:1 on every background of its scheme (bg, surface,
     surface-2): tests/webui/test_foundation.py checks it. */
  --ink-3: #6f6660;
  --line: #e4dcd4;
  --line-strong: #cfc4b9;
  --soon: #8a5300;
  --soon-bg: #fdf0d7;
  --soon-line: #e9b64a;
  --bad: #b3261e;
  --bad-bg: #fce6e3;
  --bad-line: #e48a80;
  --ok: #2f6b3f;
  --shadow: 0 1px 2px rgb(60 40 30 / 0.06), 0 4px 16px rgb(60 40 30 / 0.06);
  --shadow-lg: 0 -8px 40px rgb(30 20 15 / 0.18);
  --radius: 14px;
  --radius-sm: 10px;
  --tap: 44px;
  --gutter: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --nav-height: 58px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #e3815f;
    --accent-strong: #f0997a;
    --accent-ink: #1c0f0a;
    --accent-soft: #3b231b;
    --bg: #171412;
    --surface: #221e1b;
    --surface-2: #2c2723;
    --ink: #f2ece6;
    --ink-2: #c3b9b0;
    --ink-3: #a39990;
    --line: #36302b;
    --line-strong: #4a423c;
    --soon: #f2bf62;
    --soon-bg: #3a2c12;
    --soon-line: #8a6420;
    --bad: #ff9d92;
    --bad-bg: #3d1e1b;
    --bad-line: #8f3b33;
    --ok: #8fd19e;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 4px 16px rgb(0 0 0 / 0.25);
    --shadow-lg: 0 -8px 40px rgb(0 0 0 / 0.5);
  }
}

/* ---- base ---------------------------------------------------------------------------- */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

body.has-nav {
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom));
}

h1,
h2,
h3,
p {
  margin: 0;
}

a {
  color: var(--accent);
}

code {
  white-space: nowrap;
  font-size: 0.9em;
  background: var(--surface-2);
  padding: 0.1em 0.35em;
  border-radius: 6px;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}

.icon {
  width: 22px;
  height: 22px;
  flex: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
}

.skip:focus {
  left: 12px;
  top: calc(8px + var(--safe-top));
  z-index: 50;
  background: var(--surface);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
}

/* htmx's request indicator (its own inline <style> is off: see base.html). */
.htmx-indicator {
  opacity: 0;
  transition: opacity 200ms ease-in;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  opacity: 1;
}

.htmx-request button[type="submit"],
button.htmx-request {
  opacity: 0.6;
}

/* ---- layout ---------------------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: calc(10px + var(--safe-top)) var(--gutter) 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--tap);
  max-width: 640px;
  margin: 0 auto;
}

.topbar-title {
  font-size: 30px;
  line-height: 1.1;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.main {
  max-width: 640px;
  margin: 0 auto;
  padding: 4px var(--gutter) 32px;
}

.stack > * + * {
  margin-top: 16px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* ---- bottom navigation ------------------------------------------------------------ */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.tabbar-link {
  flex: 1;
  max-width: 160px;
  height: var(--nav-height);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--ink-3);
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.tabbar-link .icon {
  width: 24px;
  height: 24px;
}

.tabbar-link[aria-current="page"] {
  color: var(--accent);
}

/* A count on an entry (NavLink.count): a pill at the icon's top right; empty for 0. */
.tabbar-link {
  position: relative;
}

.tabbar-count {
  position: absolute;
  top: 5px;
  left: calc(50% + 6px);
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 0 0 2px var(--surface);
  font-size: 11.5px;
  font-weight: 750;
  line-height: 19px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

.tabbar-count:empty {
  display: none;
}

/* ---- buttons --------------------------------------------------------------------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 10px 18px;
  border: 0;
  border-radius: 999px;
  font-weight: 650;
  font-size: 16px;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 120ms, transform 80ms;
  touch-action: manipulation;
}

.button:active {
  transform: scale(0.97);
}

.button .icon {
  width: 20px;
  height: 20px;
}

.button-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.button-primary:hover {
  background: var(--accent-strong);
}

.button-secondary {
  background: var(--surface-2);
  color: var(--ink);
}

.button-danger {
  background: transparent;
  color: var(--bad);
  box-shadow: inset 0 0 0 1.5px var(--bad-line);
}

.button-small {
  min-height: var(--tap);
  padding: 7px 14px 7px 11px;
  font-size: 15px;
}

.button-block {
  display: flex;
  width: 100%;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  border-radius: 999px;
  border: 0;
  background: var(--surface-2);
  color: var(--ink-2);
  cursor: pointer;
}

/* ---- forms ----------------------------------------------------------------------- */

.field {
  display: block;
  min-width: 0;
  margin-inline: 0;
  margin-bottom: 0;
  padding: 0;
  border: 0;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 15px;
  font-weight: 650;
  color: var(--ink);
  padding: 0;
}

.field-optional {
  font-weight: 450;
  color: var(--ink-3);
}

.input {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 11px 14px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 17px; /* 16px or more: iOS does not zoom in on focus */
  appearance: none;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

input[type="date"].input {
  min-height: 48px;
  line-height: 24px;
}

input[type="date"].input::-webkit-date-and-time-value {
  text-align: left;
}

/* An empty date (app.js marks it): WebKit draws its blank fields (mm/dd/yyyy) in the
   text's own colour, as if filled; show them as a placeholder instead. */
input[type="date"].input[data-empty]:not(:focus)::-webkit-datetime-edit {
  color: var(--ink-3);
}

.has-error .input {
  border-color: var(--bad);
}

.field-hint,
.field-error {
  margin-top: 6px;
  font-size: 14px;
  color: var(--ink-3);
}

.field-error {
  color: var(--bad);
  font-weight: 550;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 12px;
}

.segment {
  position: relative;
  display: block;
}

.segment input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
}

.segment span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  border-radius: 9px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
}

.segment input:checked + span {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.segment input:focus-visible + span {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
}

/* In the dark, a lighter surface on surface-2 barely shows: the choice is outlined in
   the accent, and its text is the brightest ink. */
@media (prefers-color-scheme: dark) {
  .segment input:checked + span {
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1.5px var(--accent);
  }
}

.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 550;
}

.alert-error {
  background: var(--bad-bg);
  color: var(--bad);
}

.alert-warn {
  background: var(--soon-bg);
  color: var(--soon);
}

.alert-ok {
  background: color-mix(in srgb, var(--ok) 14%, var(--surface));
  color: var(--ok);
}

/* ---- the search box (the kitchen's and the recipes' toolbars) ----------------------- */

.search {
  position: relative;
  max-width: 640px;
  margin: 8px auto 0;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-3);
  display: flex;
  pointer-events: none;
}

.search-icon .icon {
  width: 20px;
  height: 20px;
}

.search-input {
  display: block;
  width: 100%;
  height: 44px;
  padding: 0 14px 0 42px;
  border: 0;
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 17px;
  appearance: none;
}

.search-input::placeholder {
  color: var(--ink-3);
}

.search-input:focus {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
  background: var(--surface);
}

/* ---- badges, empty states, notices --------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 650;
  background: var(--surface-2);
  color: var(--ink-2);
}

.badge-warn {
  background: var(--soon-bg);
  color: var(--soon);
}

.badge-accent {
  background: var(--accent-soft);
  color: var(--accent);
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 40px 24px;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin-bottom: 14px;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent);
}

.empty-icon .icon {
  width: 30px;
  height: 30px;
}

.empty-title {
  font-size: 19px;
  font-weight: 700;
}

.empty-text {
  max-width: 30ch;
  margin-top: 6px;
  color: var(--ink-2);
  font-size: 15px;
}

.empty-actions {
  margin-top: 20px;
}

.notice {
  margin-top: 12px;
}

.notice > * + * {
  margin-top: 12px;
}

.notice-status {
  color: var(--ink-3);
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0.04em;
}

.notice-title {
  font-size: 22px;
  line-height: 1.25;
}

.notice-text {
  color: var(--ink-2);
}

/* ---- the bottom sheet (a <dialog>) ------------------------------------------------- */

.sheet {
  width: 100%;
  max-width: 640px;
  max-height: calc(100dvh - 24px - var(--safe-top));
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
  overscroll-behavior: contain;
}

.sheet[open] {
  animation: sheet-up 220ms cubic-bezier(0.2, 0.9, 0.3, 1);
}

.sheet::backdrop {
  background: rgb(20 12 8 / 0.42);
}

@keyframes sheet-up {
  from {
    transform: translateY(40px);
    opacity: 0;
  }
}

.sheet-body {
  padding-bottom: var(--safe-bottom);
}

.sheet-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 16px 10px 20px;
  background: var(--surface);
}

.sheet-header::before {
  content: "";
  position: absolute;
  top: 7px;
  left: 50%;
  width: 38px;
  height: 5px;
  margin-left: -19px;
  border-radius: 3px;
  background: var(--line-strong);
}

.sheet-title:focus {
  outline: none; /* focused on opening, so the keyboard stays down */
}

.sheet-title {
  font-size: 21px;
  font-weight: 720;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.sheet-close .icon {
  width: 20px;
  height: 20px;
}

.sheet-content {
  padding: 6px 20px 20px;
}

.sheet-actions {
  padding-top: 6px;
}

.sheet-text {
  color: var(--ink-2);
}

.sheet-danger {
  margin-top: 12px;
}

.sheet-danger > * + * {
  margin-top: 10px;
}

/* The same sheet as a page of its own (no JavaScript). */
.sheet-page .sheet-panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.sheet-page .sheet-header {
  position: static;
  border-radius: var(--radius) var(--radius) 0 0;
}

.sheet-page .sheet-header::before {
  display: none;
}

@media (min-width: 700px) {
  .sheet {
    margin: auto;
    border-radius: 22px;
    max-height: calc(100dvh - 64px);
  }

  .sheet-header::before {
    display: none;
  }
}

/* ---- toasts ------------------------------------------------------------------------ */

.toasts {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 12px);
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 var(--gutter);
  pointer-events: none;
}

body:not(.has-nav) > .toasts {
  bottom: calc(var(--safe-bottom) + 16px);
}

/* In the open sheet (app.js puts them there, above the page): at the top of the screen,
   clear of the sheet's buttons; the page's own toasts wait for it to close. */
.sheet > .toasts {
  top: calc(var(--safe-top) + 12px);
  bottom: auto;
}

.sheet > .toasts .toast[data-page] {
  display: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 480px;
  min-height: 48px;
  padding: 8px 8px 8px 16px;
  border-radius: 14px;
  background: #2a2420;
  color: #f6efe9;
  box-shadow: 0 8px 28px rgb(0 0 0 / 0.25);
  font-size: 15px;
  font-weight: 550;
  pointer-events: auto;
  animation: toast-in 200ms ease-out;
  transition: opacity 250ms, transform 250ms;
}

/* One message at a time: a new one replaces the last. */
.toast:not(:last-child) {
  display: none;
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(8px);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

.toast-text {
  flex: 1;
  padding: 6px 0;
}

.toast-form {
  margin: 0;
}

.toast-undo {
  min-height: var(--tap);
  padding: 6px 14px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #ffb79e;
  font-weight: 700;
  cursor: pointer;
}

.toast-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 6px 14px;
  border-radius: 10px;
  color: #ffb79e;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

@media (prefers-color-scheme: dark) {
  .toast {
    background: #f2ece6;
    color: #221c18;
  }

  .toast-undo,
  .toast-link {
    color: #a33d25;
  }
}

/* ---- sign-in ------------------------------------------------------------------------- */

.signin {
  max-width: 400px;
  margin: 0 auto;
  padding-top: calc(48px + var(--safe-top));
}

.signin-mark {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 22px;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 30px color-mix(in srgb, var(--accent) 35%, transparent);
}

.signin-mark .icon {
  width: 40px;
  height: 40px;
  stroke-width: 1.7;
}

.signin-title {
  margin-top: 22px;
  font-size: 32px;
  font-weight: 760;
  letter-spacing: -0.02em;
}

.signin-lede {
  margin: 4px 0 28px;
  color: var(--ink-2);
}

.signin .alert {
  margin-bottom: 16px;
}

.signin .button-block {
  margin-top: 24px;
  min-height: 52px;
  font-size: 17px;
}

.signin-help {
  margin-top: 28px;
  font-size: 14px;
  color: var(--ink-3);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ---- "Share list" (share-list.js) ----------------------------------------------------- */

/* A .button is displayed whatever its hidden attribute says, unless told. */
.share-list-button[hidden],
.share-fallback[hidden] {
  display: none;
}

.share-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}
