/* =====================================================================
   Shared Shopping List - app.css
   Mobile first, no framework, ~1 screen of tokens then components.
   ===================================================================== */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --brand-soft: #ccfbf1;
  --danger: #dc2626;
  --promo: #b45309;
  --promo-soft: #fef3c7;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 12px rgba(15, 23, 42, .05);
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #131c2f;
    --surface-2: #0f1727;
    --border: #26334a;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --brand: #2dd4bf;
    --brand-dark: #14b8a6;
    --brand-soft: #134e4a;
    --promo: #fbbf24;
    --promo-soft: #422006;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 12px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }

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

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.is-hidden { display: none !important; }

/* ---------------------------------------------------------- top bar */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .65rem .9rem 0;
  padding-top: calc(.65rem + env(safe-area-inset-top));
}

.topbar__row { display: flex; align-items: center; gap: .75rem; }

.topbar__title {
  flex: 1; font-size: 1.05rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  cursor: pointer;
}

.icon-btn {
  border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 999px; padding: .4rem .85rem; cursor: pointer;
  font-size: .85rem; color: var(--muted);
}
.icon-btn:hover { color: var(--text); border-color: var(--muted); }

.modes { display: flex; gap: .25rem; margin-top: .6rem; }

.modes__btn {
  flex: 1; background: none; border: 0; cursor: pointer;
  padding: .7rem .5rem; font-size: .92rem; font-weight: 600;
  color: var(--muted); border-bottom: 3px solid transparent;
  min-height: var(--tap);
}
.modes__btn.is-active { color: var(--brand); border-bottom-color: var(--brand); }

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

.wrap { max-width: 760px; margin: 0 auto; padding: 1rem .9rem 4rem; }

.view { display: none; }
.view.is-active { display: block; animation: fade .18s ease; }

@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

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

/* ---------------------------------------------------------- form */

.form__grid { display: flex; flex-wrap: wrap; gap: .6rem; }

.field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .6rem; flex: 1 1 100%; }
.field--grow { flex: 3 1 12rem; margin-bottom: 0; }
.field--sm   { flex: 1 1 4.5rem; margin-bottom: 0; }
.field--md   { flex: 2 1 8rem;  margin-bottom: 0; }

.field__label { font-size: .78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.field input, .field select, .sharebox input, .drawer__search input, .drawer__search select {
  width: 100%; min-height: var(--tap);
  padding: .55rem .7rem;
  background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  outline: none;
}
.field input:focus, .field select:focus, .drawer__search input:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent);
}

.form__grid + .field { margin-top: .6rem; }
.form__actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .4rem; }

.btn {
  min-height: var(--tap); padding: .55rem 1rem; cursor: pointer;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); font-weight: 600; font-size: .92rem;
  transition: transform .06s ease, background .15s ease;
}
.btn:active { transform: scale(.98); }
.btn--primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-dark); }
.btn--ghost:hover { border-color: var(--brand); color: var(--brand); }
.btn--link { border: 0; background: none; color: var(--muted); }
.btn--danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.btn--tiny { min-height: 34px; padding: .3rem .65rem; font-size: .8rem; }
.btn--block { width: 100%; }

.promo-chip {
  display: flex; align-items: center; gap: .5rem; margin: .1rem 0 0;
  background: var(--promo-soft); color: var(--promo);
  border-radius: 999px; padding: .35rem .5rem .35rem .8rem;
  font-size: .85rem; font-weight: 600; width: fit-content; max-width: 100%;
}
.promo-chip__x { border: 0; background: none; cursor: pointer; color: inherit; font-size: 1.1rem; line-height: 1; }

/* ---------------------------------------------------------- list head */

.listhead { display: flex; align-items: center; gap: .5rem; margin: 1.4rem 0 .6rem; }
.listhead__title { font-size: 1rem; flex: 1; }
.listhead__actions { display: flex; gap: .4rem; }

.badge {
  display: inline-block; min-width: 1.5rem; text-align: center;
  background: var(--brand-soft); color: var(--brand-dark);
  border-radius: 999px; padding: .05rem .45rem; font-size: .8rem; font-weight: 700;
}
@media (prefers-color-scheme: dark) { .badge { color: var(--brand); } }

/* ---------------------------------------------------------- items */

.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }

.item {
  display: flex; align-items: flex-start; gap: .75rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .75rem .85rem; box-shadow: var(--shadow);
}

.item__body { flex: 1; min-width: 0; }

.item__name { font-weight: 600; word-break: break-word; }
.item__qty {
  display: inline-block; margin-right: .45rem; padding: .05rem .4rem;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; font-size: .8rem; color: var(--muted); font-weight: 700;
}
.item__meta { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-top: .3rem; font-size: .82rem; color: var(--muted); }

.tag {
  --chip: var(--muted);
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 700;
  color: var(--chip); border: 1px solid color-mix(in srgb, var(--chip) 40%, transparent);
  background: color-mix(in srgb, var(--chip) 10%, transparent);
}

.item__promo {
  display: block; margin-top: .35rem; font-size: .8rem; font-weight: 700;
  color: var(--promo); background: var(--promo-soft);
  border-radius: 6px; padding: .2rem .5rem; width: fit-content; max-width: 100%;
}

.item__actions { display: flex; gap: .35rem; flex-shrink: 0; }

.iconbtn {
  width: 36px; height: 36px; display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); cursor: pointer; color: var(--muted);
}
.iconbtn:hover { color: var(--text); }
.iconbtn--danger:hover { color: var(--danger); border-color: var(--danger); }

/* shopping mode: whole row is the checkbox */

.items--shopping .item { cursor: pointer; user-select: none; align-items: center; }
.items--shopping .item:active { transform: scale(.995); }

.check {
  width: 26px; height: 26px; flex-shrink: 0; border-radius: 50%;
  border: 2px solid var(--border); display: grid; place-items: center;
  color: transparent; font-size: .85rem; font-weight: 900;
  transition: background .15s ease, border-color .15s ease;
}

.item.is-checked { opacity: .55; }
.item.is-checked .check { background: var(--brand); border-color: var(--brand); color: #fff; }
.item.is-checked .item__name { text-decoration: line-through; }

/* ---------------------------------------------------------- market bar + progress */

.marketbar {
  display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .5rem;
  margin: 0 -.9rem .6rem; padding-inline: .9rem;
  scrollbar-width: none;
}
.marketbar::-webkit-scrollbar { display: none; }

.chip {
  --chip: var(--brand);
  white-space: nowrap; cursor: pointer; min-height: 38px;
  padding: .35rem .9rem; border-radius: 999px; font-size: .87rem; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
}
.chip.is-active {
  color: #fff; border-color: var(--chip);
  background: var(--chip);
}

.progress { margin-bottom: .8rem; }
.progress__bar { height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; }
.progress__bar span { display: block; height: 100%; width: 0; background: var(--brand); transition: width .25s ease; }
.progress__text { margin: .35rem 0 0; font-size: .82rem; color: var(--muted); }

.shopfoot { margin-top: 1.2rem; }

.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

/* ---------------------------------------------------------- drawer / modal */

.drawer { position: fixed; inset: 0; z-index: 50; display: flex; }
.drawer[hidden] { display: none; }

.drawer__backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .5); backdrop-filter: blur(2px); }

.drawer__panel {
  position: relative; margin-left: auto; width: min(460px, 100%);
  background: var(--surface); display: flex; flex-direction: column;
  box-shadow: -8px 0 30px rgba(15, 23, 42, .2);
  animation: slide .2s ease;
}
@keyframes slide { from { transform: translateX(20px); opacity: .6; } to { transform: none; opacity: 1; } }

.drawer--center { align-items: center; justify-content: center; padding: 1rem; }
.drawer--center .drawer__panel {
  margin: 0; border-radius: var(--radius); width: min(440px, 100%); height: auto;
}
.drawer__panel--small { max-height: 90vh; }

.drawer__head {
  display: flex; align-items: center; gap: .75rem;
  padding: 1rem; border-bottom: 1px solid var(--border);
}
.drawer__head h2 { flex: 1; font-size: 1.05rem; }

.drawer__search { display: flex; gap: .4rem; padding: .8rem 1rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.drawer__search input { flex: 2 1 9rem; }
.drawer__search select { flex: 1 1 7rem; }

.drawer__body { padding: 1rem; overflow-y: auto; flex: 1; }

@media (max-width: 560px) {
  .drawer__panel { width: 100%; height: 88vh; margin-top: auto; border-radius: var(--radius) var(--radius) 0 0; }
  .drawer { align-items: flex-end; }
  .drawer--center { align-items: center; }
}

/* promotion cards */

.promo {
  display: flex; gap: .75rem; align-items: flex-start;
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: .75rem; margin-bottom: .6rem; background: var(--surface-2);
}
.promo__body { flex: 1; min-width: 0; }
.promo__title { font-weight: 650; }
.promo__brand { font-size: .82rem; color: var(--muted); }
.promo__prices { display: flex; align-items: baseline; gap: .45rem; margin-top: .3rem; flex-wrap: wrap; }
.promo__price { font-size: 1.05rem; font-weight: 800; color: var(--brand); }
.promo__old { text-decoration: line-through; color: var(--muted); font-size: .85rem; }
.promo__disc { background: var(--promo-soft); color: var(--promo); border-radius: 6px; padding: .05rem .4rem; font-size: .75rem; font-weight: 800; }
.promo__foot { margin-top: .3rem; font-size: .76rem; color: var(--muted); }

.spinner { text-align: center; color: var(--muted); padding: 2rem 0; }

/* ---------------------------------------------------------- share + toast */

.sharebox { display: flex; gap: .4rem; margin: .6rem 0; }
.sharebox input { flex: 1; }

.toast {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translate(-50%, 150%);
  background: var(--text); color: var(--bg);
  padding: .6rem 1rem; border-radius: 999px; font-size: .88rem; font-weight: 600;
  box-shadow: var(--shadow); transition: transform .25s ease; z-index: 80;
  max-width: 90vw; text-align: center;
}
.toast.is-visible { transform: translate(-50%, 0); }

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

/* "already in the basket" marker, shown in manage mode only */
.tag--done { --chip: var(--brand); }
