:root {
  --bg: #f6f1ea;
  --surface: #fffdf9;
  --surface-2: #efe8de;
  --text: #2a2622;
  --muted: #7a7168;
  --line: #e3dbcf;
  --accent: #c2553a;
  --accent-ink: #fff;
  --good: #2f7d53;
  --good-bg: #e2f2e8;
  --warn: #9a6b12;
  --warn-bg: #f7ecd2;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 16px rgba(60, 40, 20, .06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1916;
    --surface: #24211d;
    --surface-2: #2e2a25;
    --text: #f1ebe3;
    --muted: #a69b8f;
    --line: #3a352f;
    --accent: #e0745a;
    --good: #7fd3a0;
    --good-bg: #1f3529;
    --warn: #e9c46a;
    --warn-bg: #3a3020;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  padding-bottom: calc(96px + var(--safe-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }

/* ── Barra superior ─────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid transparent;
}
.topbar h1 {
  flex: 1; margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar-actions { display: flex; gap: 4px; }
.icon-btn {
  position: relative; border: 0; background: transparent; cursor: pointer;
  width: 40px; height: 40px; border-radius: 12px; font-size: 22px; line-height: 1;
}
.icon-btn:active { background: var(--surface-2); }
.badge {
  position: absolute; top: 4px; right: 3px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}

main { max-width: 900px; margin: 0 auto; padding: 8px 16px 24px; }

/* ── Seccions i carpetes ────────────────── */
.section-title {
  margin: 20px 4px 10px; font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  display: flex; align-items: center; gap: 6px;
}
.folders { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.folder {
  display: flex; flex-direction: column; gap: 6px; text-align: left;
  padding: 16px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); box-shadow: var(--shadow); cursor: pointer;
  min-height: 108px;
}
.folder:active { transform: scale(.985); }
.folder .emoji { font-size: 28px; }
.folder .name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; }
.folder .meta { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.folder.new { border-style: dashed; background: transparent; box-shadow: none; color: var(--muted); justify-content: center; align-items: center; }
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
}
.pill.shared { background: var(--warn-bg); color: var(--warn); }
.pill.good { background: var(--good-bg); color: var(--good); }

/* ── Desitjos ───────────────────────────── */
.items { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.item {
  display: flex; flex-direction: column; overflow: hidden; text-align: left; padding: 0;
  border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); box-shadow: var(--shadow); cursor: pointer;
}
.item:active { transform: scale(.985); }
.item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.thumb {
  aspect-ratio: 1; width: 100%; background: var(--surface-2) center/cover no-repeat;
  display: grid; place-items: center; font-size: 34px; color: var(--muted);
  position: relative;
}
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .drop {
  position: absolute; left: 8px; top: 8px;
  background: var(--good); color: #fff; font-size: 12px; font-weight: 700;
  padding: 3px 8px; border-radius: 999px;
}
.item .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.item .t {
  font-size: 14px; font-weight: 550; display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden;
}
.item .price { font-size: 17px; font-weight: 700; }
.item .price s { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.item .host { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty .big { font-size: 44px; }

/* ── Botons i formularis ────────────────── */
.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; cursor: pointer;
  background: var(--surface-2); color: var(--text);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: transparent; color: var(--accent); }
.btn.small { padding: 8px 12px; font-size: 14px; }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }

.fab {
  position: fixed; right: 20px; bottom: calc(20px + var(--safe-bottom)); z-index: 6;
  width: 60px; height: 60px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-size: 30px;
  box-shadow: 0 6px 20px rgba(194, 85, 58, .4);
}

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); font-size: 16px;
}
.field textarea { min-height: 72px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.check { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 14px; font-size: 15px; }
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); }
.hint { font-size: 13px; color: var(--muted); }
.suggest {
  border: 0; background: var(--good-bg); color: var(--good); border-radius: 8px;
  padding: 4px 10px; font-size: 13px; font-weight: 600; cursor: pointer; align-self: flex-start;
}
.url-row { display: flex; gap: 8px; }
.url-row input { flex: 1; }

.preview {
  display: flex; gap: 12px; align-items: center; padding: 10px; margin-bottom: 14px;
  border-radius: 12px; background: var(--surface-2);
}
.preview .thumb { position: relative; width: 72px; min-width: 72px; border-radius: 10px; overflow: hidden; font-size: 24px; }
.preview .pt { font-size: 14px; font-weight: 550; }

/* ── Diàleg ─────────────────────────────── */
dialog {
  width: min(560px, 100vw); max-width: 100vw; max-height: 92dvh;
  margin: auto auto 0; padding: 0; border: 0; border-radius: 22px 22px 0 0;
  background: var(--bg); color: var(--text);
}
@media (min-width: 640px) { dialog { margin: auto; border-radius: 22px; } }
dialog::backdrop { background: rgba(20, 15, 10, .45); }
.sheet { padding: 20px 16px calc(20px + var(--safe-bottom)); overflow-y: auto; max-height: 92dvh; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.sheet .hero {
  position: relative; width: 100%; aspect-ratio: 4/3; border-radius: 14px; overflow: hidden; margin-bottom: 14px;
  background: var(--surface-2); display: grid; place-items: center; font-size: 48px;
}
.sheet .hero img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #fff; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-weight: 700; }
.list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.row {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
.row .grow { flex: 1; min-width: 0; }
.row .sub { font-size: 13px; color: var(--muted); }
.row.unread { border-color: var(--good); }
.menu-list { display: flex; flex-direction: column; gap: 6px; }
.menu-list .btn { text-align: left; }

/* ── Login ──────────────────────────────── */
.login { max-width: 380px; margin: 10dvh auto 0; text-align: center; }
.login .logo { font-size: 56px; }
.login h2 { margin: 8px 0 4px; font-size: 26px; }
.login p { color: var(--muted); margin: 0 0 24px; }
.login form { text-align: left; }
.login .btn { width: 100%; }

#toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translateX(-50%);
  z-index: 20; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; max-width: calc(100vw - 32px); box-shadow: var(--shadow);
}
.spinner {
  width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.emoji-opt {
  height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  font-size: 22px; cursor: pointer; color: var(--muted);
}
.emoji-opt.on { border: 2px solid var(--accent); background: var(--surface-2); }
.emoji-custom { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.emoji-custom label { flex: 1; font-size: 13px; color: var(--muted); }
.emoji-custom input {
  width: 64px !important; height: 44px; text-align: center; font-size: 22px; padding: 0 !important;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
}
.emoji-custom input.on { border: 2px solid var(--accent); background: var(--surface-2); }

.folder-checks { display: flex; flex-direction: column; gap: 6px; }
.fcheck {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-size: 15px;
}
.fcheck input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
.fcheck .grow { flex: 1; min-width: 0; }
.fcheck:has(input:checked) { border-color: var(--accent); background: var(--surface-2); }

/* Fotos i avisos */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.photo-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: -4px 0 14px; }
.photo-row .btn { cursor: pointer; }
.photo-row .hint { flex: 1; min-width: 160px; }
.hero-btn {
  position: absolute; right: 10px; bottom: 10px; z-index: 1; cursor: pointer;
  padding: 8px 12px; border-radius: 999px; font-size: 14px; font-weight: 600;
  background: color-mix(in srgb, var(--bg) 88%, transparent); color: var(--text);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); box-shadow: var(--shadow);
}
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert .hint { color: inherit; opacity: .85; margin-top: 2px; }
.alert-ic { font-size: 18px; line-height: 1.3; }
.thumb .nowatch {
  position: absolute; right: 8px; top: 8px; z-index: 1; font-size: 13px; line-height: 1;
  padding: 4px 6px; border-radius: 999px; background: color-mix(in srgb, var(--bg) 85%, transparent);
}
.thumb .drop { z-index: 1; }

/* Cerca, filtres i preferits */
.search {
  display: flex; align-items: center; gap: 8px; padding: 0 14px; height: 46px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
}
.search input { flex: 1; min-width: 0; border: 0; background: transparent; font-size: 16px; outline: none; height: 100%; }
.search:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; }
.home-search { margin: 4px 0 6px; }
.toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  font-size: 14px; font-weight: 600; color: var(--text); cursor: pointer; white-space: nowrap;
}
.chip[aria-pressed="true"], .chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip-select select { border: 0; background: transparent; font: inherit; color: inherit; appearance: none; -webkit-appearance: none; padding: 0; cursor: pointer; }
.chip-input input { width: 54px; border: 0; background: transparent; font: inherit; color: inherit; text-align: center; outline: none; padding: 0; }
.chip-input input::placeholder { color: inherit; opacity: .5; }
.result-line { margin: 0 4px 10px; }
.section-title .count { font-weight: 600; color: var(--muted); background: var(--surface-2); border-radius: 999px; padding: 0 7px; letter-spacing: 0; }
.tip { margin: 18px 4px 0; }
.star {
  position: absolute; right: 8px; bottom: 8px; z-index: 2; width: 34px; height: 34px; border: 0; cursor: pointer;
  border-radius: 50%; display: grid; place-items: center; font-size: 19px; line-height: 1;
  background: color-mix(in srgb, var(--bg) 85%, transparent); color: var(--muted);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.star.on { color: #e3a008; }
.head-actions { display: flex; gap: 4px; align-items: center; }
.fav-head { color: var(--muted); }
.fav-head.on { color: #e3a008; }
.fav-strip { margin-bottom: 4px; }

/* Compartir i compte */
.avatar {
  width: 34px; height: 34px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); color: var(--text); font-weight: 700; font-size: 14px;
}
.row.pending { border-style: dashed; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.acc-section { margin-top: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); padding: 0 14px; }
.acc-section summary { cursor: pointer; padding: 14px 0; font-weight: 600; list-style: none; }
.acc-section summary::-webkit-details-marker { display: none; }
.acc-section summary::after { content: '›'; float: right; color: var(--muted); transition: transform .15s; }
.acc-section[open] summary::after { transform: rotate(90deg); }
.acc-section[open] { padding-bottom: 14px; }
.danger-zone summary { color: var(--accent); }
.btn.danger-solid { background: var(--accent); color: var(--accent-ink); }
.menu-list a.btn { text-decoration: none; display: block; }

.diag { margin: -6px 0 14px; font-size: 12px; }
.diag code { display: block; margin-top: 4px; padding: 6px 8px; border-radius: 8px; background: var(--surface-2); word-break: break-all; font-size: 11px; }

.tip-card {
  display: flex; align-items: center; gap: 12px; padding: 12px 8px 12px 14px; margin: 10px 0 4px;
  border-radius: var(--radius); background: var(--good-bg); color: var(--text);
}
.tip-card a { text-decoration: none; color: inherit; min-width: 0; }
.tip-card .tip-ic { font-size: 24px; }
.tip-card .grow { flex: 1; }

/* Avís de preu pendent */
.field input.needs { border-color: var(--warn); outline: 2px solid color-mix(in srgb, var(--warn) 40%, transparent); }
.warn-text { color: var(--warn); font-weight: 600; }
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px;
  background: rgba(20, 15, 10, .45);
}
.modal {
  width: min(360px, 100%); background: var(--bg); color: var(--text); border-radius: 20px;
  padding: 22px 18px 16px; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.3);
}
.modal-ic { font-size: 34px; }
.modal h3 { margin: 6px 0 6px; font-size: 18px; }
.modal p { margin: 0 0 16px; color: var(--muted); font-size: 15px; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; }

/* Benvinguda */
.onb { display: flex; flex-direction: column; gap: 10px; }
.onb-ic { font-size: 44px; text-align: center; }
.onb h2 { margin: 0; text-align: center; font-size: 24px; }
.onb-lead { margin: 0 0 6px; text-align: center; color: var(--muted); }
.onb-steps { list-style: none; counter-reset: s; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.onb-steps > li { counter-increment: s; position: relative; display: flex; flex-direction: column; gap: 8px;
  padding: 14px 14px 14px 56px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
.onb-steps > li::before { content: counter(s); position: absolute; left: 14px; top: 13px; width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; display: grid; place-items: center; }
.onb-steps > li > span { font-size: 15px; }
.onb-btn { text-align: center; text-decoration: none; display: block; }
.onb-btn.done { background: var(--good); }
.onb-how { padding: 12px 14px; border-radius: 14px; background: var(--good-bg); font-size: 15px; }
.onb-later { background: transparent; color: var(--muted); }
