:root {
  --green-900: #1d5235;
  --green-800: #2e7d4f;
  --green-600: #4a9a6c;
  --green-100: #e2f0e7;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef1ec;
  --text: #1b1f1b;
  --muted: #5c665c;
  --border: #dde3da;
  --danger: #b3261e;
  --danger-bg: #fdecea;
  --focus: #1d5235;
  --radius: 0.75rem;
  --radius-sm: 0.5rem;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 12px rgb(0 0 0 / 0.05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --green-900: #17422b;
    --green-800: #3d8f60;
    --green-600: #6fbf8f;
    --green-100: #1c2b21;
    --bg: #101310;
    --surface: #191e19;
    --surface-2: #212821;
    --text: #e9ede8;
    --muted: #a2aca2;
    --border: #2d352d;
    --danger: #f2b8b5;
    --danger-bg: #3b1f1d;
    --focus: #6fbf8f;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 4px 12px rgb(0 0 0 / 0.3);
  }
}

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

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

h1, h2, h3 {
  line-height: 1.25;
  margin: 0 0 0.5rem;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }

p { margin: 0 0 0.75rem; }

a {
  color: var(--green-800);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:hover { color: var(--green-900); }

code, pre {
  font-family: var(--mono);
  font-size: 0.875em;
}

code {
  background: var(--surface-2);
  border-radius: 0.3rem;
  padding: 0.1rem 0.35rem;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 0.2rem;
}

.container {
  width: 100%;
  max-width: 46rem;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Header */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 3.5rem;
}

.brand {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-user form { margin: 0; }

.header-nav {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  flex: 1;
  margin-left: 0.5rem;
}

.header-nav a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
}

.header-nav a:hover { color: var(--text); }

/* Main */
.site-main {
  flex: 1;
  padding: 1.25rem 0 2.5rem;
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 0.9rem 0 calc(0.9rem + env(safe-area-inset-bottom));
  background: var(--surface);
}

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

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.15rem;
  margin-bottom: 1rem;
}

.card > :last-child { margin-bottom: 0; }

/* Auth */
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem 1.25rem;
  max-width: 24rem;
  margin: 8vh auto 0;
}

.auth-card h1 {
  text-align: center;
  margin-bottom: 1rem;
}

/* Forms */
.stack > * + * { margin-top: 0.9rem; }

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

label {
  font-weight: 600;
  font-size: 0.9rem;
}

input[type="text"],
input[type="password"],
input[type="search"],
input:not([type]),
select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.75rem;
  width: 100%;
  min-height: 2.75rem;
}

select {
  width: auto;
  padding-right: 2rem;
}

input:focus,
select:focus {
  border-color: var(--green-800);
  outline: none;
  box-shadow: 0 0 0 3px var(--green-100);
}

/* Buttons */
.btn {
  font: inherit;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1rem;
  min-height: 2.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.btn:hover { background: var(--surface-2); color: var(--text); }

.btn-primary {
  background: var(--green-800);
  border-color: var(--green-800);
  color: #fff;
}

.btn-primary:hover {
  background: var(--green-900);
  border-color: var(--green-900);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  min-height: 2.25rem;
  padding: 0.35rem 0.6rem;
}

.btn-ghost:hover { background: var(--surface-2); }

.btn-block { width: 100%; }

/* Alerts */
.alert {
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.8rem;
  font-size: 0.925rem;
  margin-bottom: 0.9rem;
}

.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent);
}

.alert-ok {
  background: var(--green-100);
  color: var(--green-900);
  border: 1px solid color-mix(in srgb, var(--green-800) 25%, transparent);
}

/* Groups */
.group-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.group-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
}

.group-link:hover {
  border-color: var(--green-600);
  background: var(--surface-2);
}

.group-name {
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}

.badge-admin {
  background: var(--green-100);
  color: var(--green-900);
}

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

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

.inline-form form { margin: 0; }

.add-member {
  margin-top: 0.9rem;
}

/* Members */
.member-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.member-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}

.member-row:last-child { border-bottom: none; }

.member-id {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

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

.member-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.member-actions form { margin: 0; }

/* Buttons (small / danger) */
.btn-small {
  min-height: 2.25rem;
  padding: 0.3rem 0.7rem;
  font-size: 0.9rem;
}

.btn-danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
  background: transparent;
}

.btn-danger:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

/* Tokens */
.secret-box {
  background: var(--surface-2);
  border: 1px dashed var(--green-600);
  border-radius: var(--radius-sm);
  padding: 0.8rem;
  overflow-x: auto;
}

.secret-box code {
  background: none;
  padding: 0;
  word-break: break-all;
}

.scopes {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.scopes legend {
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0 0.3rem;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 400;
}

.checkbox input {
  width: 1.15rem;
  height: 1.15rem;
  min-height: 0;
  accent-color: var(--green-800);
}

/* Language form on login */
.lang-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  margin-top: 1.25rem;
}

.lang-form select { min-height: 2.25rem; }

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

.page-head h1 { margin: 0; }

.head-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.head-actions form { margin: 0; }

.search-form { margin-bottom: 1rem; }

.recipe-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.ing-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.ing-list li {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.ing-list li:last-child { border-bottom: none; }

.ing-qty {
  min-width: 5rem;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.steps { white-space: pre-wrap; }

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.scope-static {
  margin: 0;
  padding: 0.65rem 0;
  color: var(--muted);
}

.ing-fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  margin: 0;
}

.ing-fieldset legend {
  font-weight: 600;
  padding: 0 0.3rem;
}

.ing-editor {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.ing-row {
  display: grid;
  grid-template-columns: 2fr 0.8fr 0.9fr 1.1fr 1.2fr auto;
  gap: 0.4rem;
  align-items: center;
}

.ing-row input,
.ing-row select {
  min-height: 2.5rem;
  padding: 0.45rem 0.55rem;
}

/* Tags */
.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin: 0.5rem 0;
}

.tag-chip {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
}

a.tag-chip:hover {
  border-color: var(--green-600);
  color: var(--text);
}

.tag-chip.active {
  background: var(--green-100);
  color: var(--green-900);
  border-color: var(--green-600);
}

.tag-chip.clear {
  background: transparent;
  border-color: var(--border);
}

button.tag-chip {
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
}

.recipe-tags {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  margin-top: 0.25rem;
}

.filter-chips { margin-bottom: 0.75rem; }

/* Shopping list */
.list-modes {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.list-modes a {
  flex: 1;
  text-align: center;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
  background: var(--surface);
}

.list-modes a.active {
  background: var(--green-800);
  border-color: var(--green-800);
  color: #fff;
}

.list-progress {
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.category-heading {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 1.1rem 0 0.4rem;
}

.list-items {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.list-item.at_home { opacity: 0.65; }

.list-item.bought .item-name {
  text-decoration: line-through;
  color: var(--muted);
}

.item-check-form { margin: 0; }

.item-check {
  width: 1.6rem;
  height: 1.6rem;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
}

.list-item.at_home .item-check,
.list-item.bought .item-check {
  background: var(--green-800);
  border-color: var(--green-800);
}

.check-open {
  display: block;
  width: 0.5rem;
  height: 0.5rem;
}

.item-main {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
  align-items: baseline;
  min-width: 0;
}

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

.item-amounts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.amount-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.amount-remove {
  margin: 0;
  display: inline-flex;
}

.amount-edit {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.amount-chip .amount-input {
  width: 3.6rem;
  min-height: 0;
  padding: 0.1rem 0.3rem;
  font-size: 0.8rem;
  text-align: right;
  border-radius: 0.4rem;
}

.amount-chip .amount-input:focus {
  border-color: var(--green-800);
  box-shadow: none;
}

.amount-unit { font-size: 0.8rem; }


.amount-x {
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0 0.15rem;
  line-height: 1;
}

.amount-x:hover { color: var(--danger); }

.item-sources a { color: var(--muted); }

.item-actions {
  margin: 0;
  display: flex;
}

.item-actions form { margin: 0; }

.add-item-card .inline-form input[name="name"] { flex: 2; }
.add-item-card .inline-form input[name="qty"] { flex: 0 0 5.5rem; min-width: 5.5rem; }

@media (max-width: 42rem) {
  .row-2 { grid-template-columns: 1fr; }

  .ing-row { grid-template-columns: 1fr 1fr; }

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


/* Docs */
.doc-list {
  margin: 0;
  padding-left: 1.1rem;
}

.table-wrap {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

/* Error page */
.error-page {
  text-align: center;
  padding: 3rem 0;
}

/* Install banner */
.install-banner {
  position: fixed;
  left: 0.75rem;
  right: 0.75rem;
  bottom: calc(0.75rem + env(safe-area-inset-bottom));
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.8rem 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 28rem;
  margin: 0 auto;
}

.install-banner p {
  margin: 0;
  flex: 1;
  font-size: 0.9rem;
}

.install-banner .btn { min-height: 2.25rem; padding: 0.35rem 0.75rem; }

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