/* krecette: one hand-written stylesheet, mobile first, system fonts. */

:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --text: #24211d;
  --muted: #6b645b;
  --border: #ddd6cb;
  --accent: #a6461f;
  --accent-text: #ffffff;
  --danger: #a32020;
  --error-bg: #fdecea;
  --radius: 6px;
  color-scheme: light;
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

h1,
h2 {
  line-height: 1.2;
}

h1 {
  font-size: 1.6rem;
  margin: 0 0 0.75rem;
}

h2 {
  font-size: 1.2rem;
  margin: 1.5rem 0 0.5rem;
}

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

img {
  max-width: 100%;
}

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

[hidden] {
  display: none !important;
}

/* Header */

/* On a phone, two rows: the brand and the user on the first, the nav on the second. */
.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 1.5rem;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--text);
  text-decoration: none;
}

.site-header nav {
  display: flex;
  order: 2;
  flex-basis: 100%;
  gap: 1rem;
}

/* The logged-in user and the logout button, at the end of the first row. */
.site-header .logout {
  display: flex;
  order: 1;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  margin: 0 0 0 auto;
  color: var(--muted);
  white-space: nowrap;
}

.site-header .username {
  min-width: 0;
  max-width: 10rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

button.link {
  min-height: 2.5rem;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  text-decoration: underline;
}

form.login {
  max-width: 22rem;
}

main {
  max-width: 48rem;
  margin: 0 auto;
  padding: 1rem;
}

/* Buttons and inputs */

button,
.button {
  display: inline-block;
  min-height: 2.5rem;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

button.primary,
.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

button.danger,
.button.danger {
  color: var(--danger);
  border-color: var(--danger);
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  min-height: 2.5rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  /* 16px at least, so phones do not zoom on focus. */
  font: inherit;
  font-size: max(1rem, 16px);
}

textarea {
  resize: vertical;
  min-height: 6.5em;
  field-sizing: content;
}

[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 1px var(--danger);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

/* Recipe list */

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 0.75rem;
}

.page-head h1 {
  margin: 0;
}

.search {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.search input {
  flex: 1;
}

.recipe-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--border);
}

/* The title, then its servings and time on their own line. */
.recipe-list li {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}

.recipe-list .meta {
  margin: 0.1rem 0 0;
}

.recipe-list a {
  font-weight: 600;
  text-decoration: none;
}

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

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

/* Recipe page */

.recipe .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  margin: 0 0 1rem;
}

.ingredient-lines {
  padding-left: 1.25rem;
}

.steps {
  padding-left: 1.5rem;
}

.steps li {
  margin-bottom: 0.6rem;
  white-space: pre-line;
}

/* Notes */

.notes {
  margin-top: 2rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.notes h2 {
  margin-bottom: 1rem;
}

.note-date input {
  max-width: 12rem;
}

.note-list {
  list-style: none;
  margin: 1.5rem 0 0;
  padding: 0;
}

.note-list li {
  padding: 0.75rem 0;
  border-top: 1px solid var(--border);
}

.note-meta {
  margin: 0 0 0.25rem;
  color: var(--muted);
  font-weight: 600;
}

/* Typed line breaks are kept; the text is escaped, never run. */
.note-text {
  white-space: pre-line;
}

.note-actions {
  display: flex;
  gap: 1rem;
  margin: 0.5rem 0 0;
}

.note-excerpt {
  margin: 1rem 0;
  padding-left: 1rem;
  border-left: 3px solid var(--border);
  color: var(--muted);
}

/* Recipe form */

.errors {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  background: var(--error-bg);
}

.errors p,
.errors ul {
  margin: 0;
}

.field-error {
  margin: 0.25rem 0 0;
  color: var(--danger);
  font-size: 0.95rem;
}

.field {
  margin-bottom: 0.75rem;
}

.field label {
  display: block;
  margin-bottom: 0.2rem;
  font-weight: 600;
}

fieldset {
  min-width: 0;
  margin: 1.25rem 0 0;
  padding: 0;
  border: 0;
}

legend {
  padding: 0;
  margin-bottom: 0.5rem;
  font-size: 1.2rem;
  font-weight: 700;
}

.rows {
  margin: 0 0 0.5rem;
  padding: 0;
  list-style: none;
}

.step-rows {
  counter-reset: step;
}

.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.4rem;
  align-items: start;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.row .field-error {
  grid-column: 1 / -1;
}

.step-row::before {
  counter-increment: step;
  content: counter(step) ".";
  grid-column: 1 / -1;
  font-weight: 600;
  color: var(--muted);
}

/* Phone: quantity and unit side by side, then the ingredient, then its detail. */
.line-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.4rem;
}

.line-fields .ingredient,
.line-fields .detail {
  grid-column: 1 / -1;
}

.row-actions {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.row-actions button {
  min-width: 2.5rem;
  padding: 0.3rem 0.5rem;
}

@media (min-width: 40rem) {
  /* One row: brand, nav, then the user at the end. */
  .site-header nav {
    order: 0;
    flex-basis: auto;
  }

  h1 {
    font-size: 2rem;
  }

  .field-group {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0 1rem;
  }

  /* Label, input and message rows shared by the three fields: should a label wrap, the
     inputs still line up, and a message under one input does not move the others. */
  .field-group .field {
    display: grid;
    grid-row: span 3;
    grid-template-rows: subgrid;
    align-content: start;
  }

  .field-group label {
    align-self: end;
  }

  .line-fields {
    grid-template-columns: 6rem 8.5rem minmax(0, 2fr) minmax(0, 2fr);
  }

  .line-fields .ingredient,
  .line-fields .detail {
    grid-column: auto;
  }

  .row-actions {
    flex-direction: row;
  }
}

/* Shopping lists */

.inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.inline-form input {
  flex: 1 1 10rem;
}

.new-list,
.add-item {
  margin-bottom: 1rem;
}

.new-list label,
.add-item label {
  display: block;
  margin-bottom: 0.2rem;
  font-weight: 600;
}

.shopping-lists {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--border);
}

.shopping-lists li {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}

.shopping-lists a {
  font-weight: 600;
  text-decoration: none;
}

.shopping-lists .meta {
  margin: 0.1rem 0 0;
}

.list-actions {
  display: flex;
  gap: 1rem;
  margin: 0 0 1rem;
}

/* One full-width button per item: one tap checks or unchecks it. */
.items {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* Items of several recipes, of one recipe, manual items: a small heading above each group. */
.item-group + .item-group {
  margin-top: 1rem;
}

.item-group-title {
  margin: 0 0 0.4rem;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.2;
}

/* The ✕ of a manual item keeps 16px from the item's button, so a tap does not hit it. */
.item {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 0.4rem;
}

.item-check {
  flex: 1;
  min-width: 0;
}

.item-button {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  min-height: 48px;
  padding: 0.5rem 0.75rem;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.mark {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border: 2px solid var(--muted);
  border-radius: 4px;
  font-weight: 700;
  line-height: 1;
}

.item-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.item-name {
  font-weight: 600;
}

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

.item.checked .item-button {
  background: var(--bg);
}

.item.checked .item-label {
  color: var(--muted);
  text-decoration: line-through;
}

.item.checked .mark {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

/* Small and plain, unlike the item's button; 48px square even when the name wraps. */
.item-remove button {
  width: 48px;
  height: 48px;
  min-height: 48px;
  padding: 0;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
}

.items-status:empty {
  display: none;
}

/* A bar over the bottom of the screen: showing it never moves the items under the finger. */
.items-status {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  left: 1rem;
  z-index: 10;
  max-width: 40rem;
  margin: 0 auto;
  padding: 0.75rem;
  box-shadow: 0 2px 8px rgb(0 0 0 / 20%);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  background: var(--error-bg);
}

.planned-recipes {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  border-top: 1px solid var(--border);
}

/* The title with « Retirer » at its right, then the servings and « Modifier ». */
.planned-recipe {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.4rem 0.75rem;
  align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}

.planned-servings {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  gap: 0.5rem;
}

.planned-servings input.servings {
  width: 4.5rem;
}

.planned-recipe .field-error {
  grid-column: 1 / -1;
}

.planned-recipes a {
  font-weight: 600;
}

.plan-form h3 {
  margin: 1.5rem 0 0.5rem;
  font-size: 1.05rem;
}

.plan-form .servings {
  max-width: 14rem;
}
