:root {
  --bg: #f6f1e7;
  --card: #fffdf7;
  --text: #2a2d24;
  --muted: #6e6c5f;
  --primary: #5c7d4f;
  --primary-dark: #49653f;
  --border: #e1d8c7;
  --done: #51794a;
  --danger: #a2563f;
  --accent: #d7863b;
  --accent-soft: #f9ecd6;
  --heading-font: "Fraunces", "Times New Roman", serif;
  --body-font: "Instrument Sans", "Helvetica Neue", sans-serif;
  --paper-noise: radial-gradient(circle at 12% 18%, rgba(0, 0, 0, 0.03) 0 0.8px, transparent 0.9px)
      0 0 / 9px 9px,
    radial-gradient(circle at 78% 62%, rgba(0, 0, 0, 0.02) 0 0.6px, transparent 0.7px) 0 0 /
      11px 11px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: var(--body-font);
  background:
    radial-gradient(circle at 8% 2%, #efe9d8 0, rgba(239, 233, 216, 0) 36%),
    radial-gradient(circle at 92% 2%, #f5dfc3 0, rgba(245, 223, 195, 0) 34%),
    linear-gradient(180deg, #faf6ed 0%, #f4eee3 100%),
    var(--bg);
  color: var(--text);
}

.app {
  max-width: 680px;
  margin: 0 auto;
  padding: 1rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

.app__header {
  margin-bottom: 1rem;
}

.app__header h1 {
  margin: 0;
  font-family: var(--heading-font);
  font-size: 1.85rem;
  letter-spacing: -0.02em;
  color: #374733;
}

.app__header p {
  margin: 0.35rem 0 0;
  color: var(--muted);
}

.offline-banner {
  margin: 0 0 0.75rem;
  border: 1px solid #e5ccb4;
  background: #faefe2;
  color: #7a4f39;
  border-radius: 0.6rem;
  padding: 0.45rem 0.62rem;
  font-size: 0.8rem;
}

.offline-banner .tertiary {
  margin-left: 0.5rem;
  min-height: 1.5rem;
  font-size: 0.72rem;
  padding: 0 0.45rem;
}

.card {
  background:
    var(--paper-noise),
    var(--card);
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  box-shadow: 0 7px 16px rgba(60, 54, 38, 0.1);
  padding: 0.95rem;
  margin-bottom: 0.8rem;
}

.card--room {
  border-left: 3px solid var(--accent);
}

.card--add {
  border-left: 3px solid var(--primary);
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.45rem;
}

.room-controls,
.add-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.55rem;
}

.room-controls {
  grid-template-columns: 1fr auto auto;
}

.room-collapsed-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.room-collapsed-bar__text {
  font-size: 0.9rem;
  color: #5d624f;
  font-weight: 600;
}

input {
  width: 100%;
  min-height: 2.8rem;
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  padding: 0 0.8rem;
  font-size: 1rem;
  background: #fff;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 68%, white);
  outline-offset: 1px;
}

select {
  width: 100%;
  min-height: 2.1rem;
  border: 1px solid var(--border);
  border-radius: 0.55rem;
  padding: 0 0.55rem;
  font-size: 0.86rem;
  background: #fff;
  color: var(--muted);
}

button {
  min-height: 2.8rem;
  border: none;
  border-radius: 0.56rem;
  padding: 0 1.05rem;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 0.92rem;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background-color 140ms ease, transform 80ms ease, opacity 140ms ease;
}

button:active {
  transform: translateY(1px);
}

button:hover {
  background: var(--primary-dark);
}

button:disabled,
button:disabled:hover {
  opacity: 0.55;
  cursor: not-allowed;
  background: #aebad6;
}

button.secondary {
  background: #f6f2e9;
  color: #585c4a;
  border: 1px solid #ddd3c2;
}

button.tertiary {
  min-height: 1.85rem;
  background: transparent;
  color: #686553;
  border: 1px solid #d8cebf;
  font-size: 0.74rem;
  padding: 0 0.55rem;
}

button.danger {
  background: #f8eee7;
  color: #87503d;
  border: 1px solid #e4c8bc;
}

.list-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.55rem;
}

.list-header__title {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.list-header__actions {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.list-header h2 {
  margin: 0;
  font-family: var(--heading-font);
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}

.badge {
  background: #eef2e8;
  color: #4d7345;
  border-radius: 999px;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  font-size: 0.82rem;
}

.items-list {
  margin: 0.85rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.85rem;
}

.items-section {
  display: grid;
  gap: 0.5rem;
}

.items-section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.items-section__title {
  margin: 0;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #5e6959;
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
}

.items-section__title::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 42% 58% 45% 55%;
  background: #90a183;
  box-shadow: 0 0 0 1px rgba(74, 90, 63, 0.16);
}

.items-section__title--pending {
  color: #59754f;
  animation: pending-pulse 1.2s ease-in-out infinite;
}

.items-section__title--failed {
  color: var(--danger);
}

.items-section__title--failed::before {
  background: #c86a54;
}

.section-retry-btn {
  min-height: 1.8rem;
  padding: 0 0.58rem;
  border-radius: 0.5rem;
  border: 1px solid #e1c8b6;
  background: #f7eee7;
  color: #875344;
  font-size: 0.74rem;
}

.items-section__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}

.item {
  border: 1px solid #e0d6c4;
  border-radius: 0.7rem;
  position: relative;
  overflow: hidden;
  transition:
    height 190ms ease,
    padding-top 190ms ease,
    padding-bottom 190ms ease,
    border-top-width 190ms ease,
    border-bottom-width 190ms ease,
    opacity 140ms ease,
    transform 140ms ease;
}

.item__row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.55rem;
  align-items: center;
  padding: 0.7rem;
  background: var(--card);
  position: relative;
  z-index: 2;
  transition: transform 190ms ease;
  touch-action: pan-y;
}

.item__row.is-swiping {
  transition: none;
}

.item__text {
  word-break: break-word;
}

.item__main {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
}

.item__meta {
  font-size: 0.78rem;
  color: var(--muted);
}

.item__meta:empty {
  display: none;
}

.item__meta--pending {
  color: #5f7752;
}

.item__meta--failed {
  color: var(--danger);
}

.item--enter {
  animation: item-enter 220ms ease-out;
}

.item--exiting {
  pointer-events: none;
}

.item--collapsing {
  height: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  border-top-width: 0;
  border-bottom-width: 0;
  opacity: 0;
  transform: translateY(-3px) scale(0.985);
}

.item--pending {
  border-color: #c8d7bf;
}

.item--failed {
  border-color: #f0c5c5;
}

.item--pending::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    110deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(112, 154, 89, 0.13) 45%,
    rgba(255, 255, 255, 0) 65%
  );
  transform: translateX(-120%);
  animation: pending-sheen 1.35s linear infinite;
  pointer-events: none;
}

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

.item.completed {
  opacity: 0.66;
}

.item__toggle {
  width: 1.2rem;
  height: 1.2rem;
  accent-color: var(--primary);
  -webkit-tap-highlight-color: transparent;
}

.item__toggle:focus,
.item__toggle:focus-visible {
  outline: none;
  box-shadow: none;
}

.item__category-chip {
  min-height: 1.95rem;
  background: #f5ecdc;
  color: #6f5536;
  border: 1px solid #e4d4ba;
  font-size: 0.76rem;
  text-transform: lowercase;
  max-width: 8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item__swipe-delete {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 86px;
  border: none;
  border-radius: 0;
  background: #b0553d;
  color: #fff;
  font-size: 0.82rem;
  letter-spacing: 0.01em;
  z-index: 1;
}

.item__swipe-delete:hover {
  background: #984834;
}

.item__category-chip[data-tone="produce"] {
  background: #edf3e8;
  border-color: #cfddc5;
  color: #4d6644;
}

.item__category-chip[data-tone="drinks"],
.item__category-chip[data-tone="frozen"] {
  background: #edf2f5;
  border-color: #d1dbe2;
  color: #50636d;
}

.item__category-chip[data-tone="dairy"],
.item__category-chip[data-tone="bakery"] {
  background: #f8eee0;
  border-color: #e4d1b6;
  color: #765739;
}

.item__category-chip[data-tone="meat"] {
  background: #f9ece7;
  border-color: #e4c9be;
  color: #79493d;
}

.item__category-chip[data-tone="bulk"] {
  background: #efe8db;
  border-color: #d5c8b0;
  color: #5c503d;
}

.item__category-chip[data-tone="wellness"] {
  background: #edf0e3;
  border-color: #d2d8c2;
  color: #55604a;
}

.item--updated {
  animation: updated-glow 1.3s ease-out;
}

.status {
  text-align: center;
  color: var(--muted);
  margin: 0.48rem 0 0;
  font-size: 0.8rem;
  letter-spacing: 0.01em;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%) translateY(10px);
  background: #2f382f;
  color: #f8f8f5;
  border-radius: 999px;
  padding: 0.38rem 0.42rem 0.38rem 0.72rem;
  display: flex;
  gap: 0.45rem;
  align-items: center;
  box-shadow: 0 10px 24px rgba(26, 25, 21, 0.24);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 40;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.toast__action {
  min-height: 1.65rem;
  padding: 0 0.6rem;
  border-radius: 999px;
  border: 1px solid #556355;
  background: #455245;
  color: #f8f8f5;
  font-size: 0.74rem;
}

.toast__action:hover {
  background: #4f5e4f;
}

.inline-hint {
  margin: 0 0 0.55rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.card--add form:not(.is-ready) .inline-hint {
  color: #67796f;
}

.card--add form:not(.is-ready) .add-controls {
  opacity: 0.75;
}

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

small {
  color: var(--muted);
  display: block;
  margin-top: 0.4rem;
}

.link-btn {
  min-height: 1.6rem;
  margin-top: 0.15rem;
  padding: 0;
  border: none;
  background: transparent;
  color: #6f6b5d;
  font-size: 0.8rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  justify-self: start;
}

.link-btn:hover {
  background: transparent;
  color: #4f4b40;
}

.item-sheet {
  width: min(460px, 92vw);
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  padding: 0;
}

.item-sheet::backdrop {
  background: rgba(48, 39, 24, 0.35);
}

.item-sheet__content {
  display: grid;
  gap: 0.65rem;
  padding: 0.9rem;
}

.item-sheet__content h3 {
  margin: 0;
  font-family: var(--heading-font);
  font-size: 1.15rem;
  line-height: 1.25;
}

.item-sheet__meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.item-sheet__actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  margin-top: 0.3rem;
}

.order-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.order-list__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  border: 1px solid #e2d6c3;
  border-radius: 0.55rem;
  padding: 0.45rem 0.55rem;
  background: #fff;
  font-size: 0.88rem;
  cursor: grab;
  user-select: none;
}

.order-list__item:active {
  cursor: grabbing;
}

.order-list__item.is-dragging {
  opacity: 0.55;
}

.order-list__item.is-drop-target {
  border-color: #8dac7e;
  box-shadow: 0 0 0 2px rgba(93, 132, 75, 0.2);
}

.order-list__handle {
  width: 1rem;
  height: 1rem;
  border-radius: 0.2rem;
  background:
    radial-gradient(circle, #8a907c 1.2px, transparent 1.3px) 0 0 / 6px 6px,
    radial-gradient(circle, #8a907c 1.2px, transparent 1.3px) 3px 3px / 6px 6px;
  opacity: 0.9;
}

.install-btn {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  min-height: 2.1rem;
  z-index: 45;
}

.room-controls #joinBtn.is-leave {
  background: #b0553d;
}

.room-controls #joinBtn.is-leave:hover {
  background: #984834;
}

@media (max-width: 520px) {
  .room-controls {
    grid-template-columns: 1fr;
  }

  .room-collapsed-bar {
    flex-wrap: wrap;
  }

  .list-header {
    flex-direction: column;
    align-items: stretch;
  }

  .list-header__actions {
    justify-content: flex-start;
  }

  .item__row {
    gap: 0.42rem;
    padding: 0.62rem;
  }

  .item__category-chip {
    min-height: 1.78rem;
    font-size: 0.71rem;
    max-width: 6.5rem;
  }
}

@keyframes item-enter {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes pending-sheen {
  to {
    transform: translateX(120%);
  }
}

@keyframes pending-pulse {
  0%,
  100% {
    opacity: 0.6;
  }
  50% {
    opacity: 1;
  }
}

@keyframes updated-glow {
  0% {
    box-shadow: 0 0 0 0 rgba(96, 137, 79, 0.4);
  }
  100% {
    box-shadow: 0 0 0 8px rgba(96, 137, 79, 0);
  }
}
