/* ============================================================
   SwapIt v2 — mobile-first, system-font, no external requests.
   ============================================================ */
:root {
  --bg: #f6f6f9;
  --surface: #ffffff;
  --surface-2: #f0f0f4;
  --text: #14161a;
  --muted: #6b7280;
  --primary: #4f46e5;
  --primary-d: #3730a3;
  --primary-light: #eef0ff;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --success: #16a34a;
  --border: #e5e5ea;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(15,15,20,.05);
  --shadow: 0 2px 8px rgba(15,15,20,.06), 0 10px 26px rgba(15,15,20,.06);
  --shadow-lg: 0 16px 40px rgba(15,15,20,.14);
  --maxw: 900px;
  --topbar-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; border: 0; background: none; padding: 0; color: inherit; }
img { display: block; max-width: 100%; }

/* boot splash */
.boot { min-height: 100vh; display: grid; place-content: center; text-align: center; gap: 12px; color: var(--muted); }
.boot .wordmark { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }

/* wordmark (text logo) */
.wordmark { font-weight: 800; letter-spacing: -.3px; font-size: 25px; }
.wordmark.lg {
  display: inline-block; font-size: 40px;
  background: linear-gradient(135deg, var(--primary), var(--primary-d));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* layout */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(135deg, #312e81, #4338ca);
}
.topbar-in { max-width: var(--maxw); margin: 0 auto; display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; }
.grow { flex: 1; }
.hero {
  position: sticky; top: var(--topbar-h); z-index: 15;
  background: linear-gradient(135deg, #312e81, #4338ca); color: #fff; text-align: center;
  margin: -14px -14px 14px; padding: 16px 16px; border-radius: 0 0 20px 20px;
}
.searchbar { display: flex; align-items: center; gap: 8px; background: #fff; color: var(--text); border-radius: 999px; padding: 13px 18px; max-width: 520px; margin: 0 auto; box-shadow: var(--shadow); }
.searchbar input { border: 0; background: transparent; outline: none; width: 100%; font-size: 15px; color: var(--text); }
.searchbar input::placeholder { color: var(--muted); }
.iconbtn { position: relative; border: 0; background: var(--primary); color: #fff; width: 40px; height: 40px; border-radius: 999px; display: grid; place-content: center; font-size: 19px; transition: transform .12s ease, background .12s ease; }
.iconbtn:hover { background: var(--primary-d); }
.iconbtn:active { transform: scale(.94); }
.badge-dot { position: absolute; top: -3px; right: -3px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-content: center; border: 2px solid var(--surface); }
.badge-dot[hidden] { display: none; }
.topbar-icon { position: relative; border: 0; background: transparent; color: #fff; width: 38px; height: 38px; border-radius: 999px; display: grid; place-content: center; font-size: 19px; transition: background .12s ease, transform .1s ease; }
.topbar-icon:hover { background: rgba(255,255,255,.14); }
.topbar-icon:active { transform: scale(.94); }
.topbar-icon .badge-dot { border-color: #3730a3; }

main { max-width: var(--maxw); margin: 0 auto; padding: 14px 14px 96px; }

/* brand mark (inline SVG logo) */
/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 12px; padding: 11px 16px; font-weight: 600; font-size: 15px; transition: transform .06s ease, background .12s ease, box-shadow .12s ease; }
.btn:hover { box-shadow: var(--shadow-sm); }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); border-color: var(--primary-d); }
.btn-primary:disabled { opacity: .6; }
.btn-danger { background: var(--danger-light); border-color: #fecaca; color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 14px; border-radius: 10px; }

/* forms */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid var(--border); background: var(--surface);
  border-radius: 12px; padding: 12px 14px; font-size: 15px; outline: none;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.field textarea { resize: vertical; min-height: 84px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* cards / grid */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 620px) { .grid { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); transition: transform .12s ease, box-shadow .12s ease; }
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.card .thumb { aspect-ratio: 1/1; background: var(--surface-2); color: var(--muted); display: grid; place-content: center; font-size: 40px; overflow: hidden; position: relative; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.card .fav { position: absolute; top: 8px; right: 8px; width: 34px; height: 34px; border-radius: 999px; background: rgba(255,255,255,.92); color: var(--text); border: 0; display: grid; place-content: center; font-size: 16px; box-shadow: var(--shadow-sm); transition: transform .1s ease; }
.card .fav:active { transform: scale(.9); }
.card .fav.on { color: var(--danger); }
.card .body { padding: 10px 12px 12px; }
.card .title { font-weight: 700; font-size: 15px; margin: 0 0 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .wants { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .row { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.status-swapped { position: absolute; inset: 0; background: rgba(20,23,28,.6); color: #fff; display: grid; place-content: center; font-weight: 700; letter-spacing: 1px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 7px 14px; font-size: 13.5px; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; transition: background .12s ease, color .12s ease, border-color .12s ease; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* avatars — initial-letter badges, colored via server-chosen palette key */
.avatar { width: 28px; height: 28px; border-radius: 999px; display: inline-grid; place-content: center; font-size: 13px; font-weight: 700; flex: 0 0 auto; color: #fff; }
.avatar.sm { width: 32px; height: 32px; font-size: 14px; }
.avatar.md { width: 44px; height: 44px; font-size: 18px; }
.avatar.lg { width: 64px; height: 64px; font-size: 26px; }

.av-violet  { background: #7c3aed; }
.av-blue    { background: #2563eb; }
.av-teal    { background: #0d9488; }
.av-amber   { background: #d97706; }
.av-rose    { background: #e11d48; }
.av-indigo  { background: #4f46e5; }
.av-emerald { background: #059669; }
.av-slate   { background: #475569; }

.swatch { width: 34px; height: 34px; border-radius: 999px; border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--border); flex: 0 0 auto; transition: box-shadow .12s ease, transform .1s ease; }
.swatch.active { box-shadow: 0 0 0 2px var(--primary); transform: scale(1.05); }

/* detail */
.detail-hero { aspect-ratio: 4/3; background: var(--surface-2); color: var(--muted); border-radius: var(--radius); display: grid; place-content: center; font-size: 72px; overflow: hidden; position: relative; }
.detail-hero img { width: 100%; height: 100%; object-fit: cover; }
.pill { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2); border-radius: 999px; padding: 5px 11px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.section-title { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin: 22px 0 10px; scroll-margin-top: calc(var(--topbar-h) + 16px); }

/* item detail: keep the primary action reachable without scrolling */
.detail-cta {
  position: fixed; left: 0; right: 0; bottom: calc(64px + var(--safe-b)); z-index: 18;
  max-width: var(--maxw); margin: 0 auto;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 10px 14px; box-shadow: 0 -6px 20px rgba(15,15,20,.08);
}
.cta-pad { padding-bottom: 168px; }

/* list rows (swaps / chat / notifs) */
.list { display: flex; flex-direction: column; gap: 10px; }
.rowcard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); display: flex; gap: 12px; align-items: center; transition: box-shadow .12s ease; }
.rowcard[data-link]:hover { box-shadow: var(--shadow-lg); }
.rowcard .mini { width: 46px; height: 46px; border-radius: 12px; background: var(--surface-2); color: var(--muted); display: grid; place-content: center; font-size: 22px; overflow: hidden; flex: 0 0 auto; }
.rowcard .mini img { width: 100%; height: 100%; object-fit: cover; }
.rowcard .fill { flex: 1; min-width: 0; }
.rowcard .fill .t { font-weight: 700; font-size: 15px; }
.rowcard .fill .s { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .3px; }
.tag.pending { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.tag.accepted { background: var(--success); color: #fff; }
.tag.declined, .tag.cancelled { background: var(--surface-2); color: #9ca3af; }
.unread { background: var(--primary); color: #fff; min-width: 20px; height: 20px; border-radius: 999px; font-size: 12px; font-weight: 700; display: grid; place-content: center; padding: 0 6px; }
.notif.unread-row { border-left: 3px solid var(--primary); }

/* segmented */
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 9px; font-weight: 600; color: var(--muted); transition: background .12s ease, color .12s ease; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* chat thread */
.thread { display: flex; flex-direction: column; gap: 8px; padding-bottom: 12px; }
.bubble { max-width: 78%; padding: 9px 13px; border-radius: 16px; font-size: 15px; word-wrap: break-word; }
.bubble.me { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 5px; }
.bubble.them { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 5px; }
.bubble .time { display: block; font-size: 10.5px; opacity: .7; margin-top: 3px; }
.composer { position: sticky; bottom: calc(64px + var(--safe-b)); background: var(--bg); padding: 8px 0; display: flex; gap: 8px; }
.composer input { flex: 1; border: 1px solid var(--border); border-radius: 999px; padding: 12px 16px; outline: none; font-size: 15px; background: var(--surface); }

/* empty / helper states */
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty-icon {
  width: 72px; height: 72px; margin: 0 auto 14px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
  display: grid; place-content: center; font-size: 30px;
}
.auth-icon {
  width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 999px;
  background: linear-gradient(135deg, #818cf8, #4f46e5); color: #fff;
  display: grid; place-content: center; font-size: 26px; box-shadow: var(--shadow-lg);
}
.center-narrow { max-width: 420px; margin: 0 auto; }
.spinner { text-align: center; color: var(--muted); padding: 28px; }
.imgpick { border: 2px dashed var(--border); border-radius: var(--radius); aspect-ratio: 4/3; display: grid; place-content: center; text-align: center; color: var(--muted); overflow: hidden; position: relative; }
.imgpick img { width: 100%; height: 100%; object-fit: cover; }
.imgpick-icon {
  width: 48px; height: 48px; margin: 0 auto 8px; border-radius: 999px;
  background: var(--surface); color: var(--muted); display: grid; place-content: center; font-size: 22px;
}
.stat-row { display: flex; gap: 10px; }
.stat { flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; text-align: center; box-shadow: var(--shadow); }
.stat .n { font-size: 24px; font-weight: 800; }
.stat .l { font-size: 12px; color: var(--muted); }

/* bottom tab bar */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--border); padding-bottom: var(--safe-b); }
.tabbar-in { max-width: var(--maxw); margin: 0 auto; display: flex; justify-content: space-around; align-items: center; }
.tab { flex: 1; border: 0; background: transparent; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 9px 0; color: var(--muted); font-size: 11px; font-weight: 600; position: relative; transition: color .12s ease; }
.tab .ic { font-size: 21px; line-height: 1; }
.fa { width: 1em; height: 1em; display: block; fill: currentColor; }
.tab.active { color: var(--primary); }
.tab.fab .ic { background: linear-gradient(135deg, var(--primary), var(--primary-d)); color: #fff; width: 38px; height: 38px; border-radius: 999px; display: grid; place-content: center; box-shadow: var(--shadow-lg); font-size: 20px; }
.tab .badge-dot { top: 2px; right: 50%; margin-right: -22px; }

/* wide viewports: just let the existing layout fill more horizontal space */
@media (min-width: 900px) { :root { --maxw: min(1600px, 96vw); } }

/* toast */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(80px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 50; pointer-events: none; }
.toast { background: #14171c; color: #fff; padding: 11px 18px; border-radius: 999px; font-size: 14px; font-weight: 500; box-shadow: var(--shadow); animation: pop .2s ease; max-width: 90%; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--success); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

.pagehead { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.pagehead h1 { font-size: 22px; margin: 0; }
.backbtn { border: 0; background: var(--surface-2); color: var(--text); width: 38px; height: 38px; border-radius: 999px; font-size: 16px; display: grid; place-content: center; transition: background .12s ease; }
.backbtn:hover { background: var(--border); }
.muted { color: var(--muted); }
.mt { margin-top: 16px; }
.sentinel { height: 1px; }
