/* =========================================================================
   Flip PWA — styles.css
   Mobile-first, large touch targets, dark-mode aware (prefers-color-scheme).
   No external fonts or assets: system font stack only, fully self-contained.
   ========================================================================= */

/* ---------- Design tokens ---------- */
:root {
  --accent: #2563eb;
  --accent-press: #1d4ed8;
  --danger: #dc2626;
  --danger-press: #b91c1c;
  --ok: #16a34a;

  /* Light theme (default) */
  --bg: #f4f6fb;
  --bg-elev: #ffffff;
  --bg-sunk: #eef1f7;
  --text: #0b1020;
  --text-muted: #5b6472;
  --border: #e2e6ee;
  --border-strong: #cfd5e0;
  --chip-bg: #e8ecf5;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);

  --tabbar-h: 62px;
  --topbar-h: 54px;
  --radius: 14px;
  --radius-sm: 10px;
  --gap: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --bg-elev: #151b2e;
    --bg-sunk: #0e1424;
    --text: #eaf0fb;
    --text-muted: #97a2b8;
    --border: #263049;
    --border-strong: #33405f;
    --chip-bg: #1d2740;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .35);
  }
}

/* ---------- Reset-ish ---------- */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}
input, textarea, select, button { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }

/* ---------- Screens & layout ---------- */
.screen { display: block; }
.screen--center {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.app { min-height: 100dvh; }

/* Content area sits above the fixed tab bar. */
.app .screen {
  padding: calc(var(--safe-top) + 8px) 16px calc(var(--tabbar-h) + var(--safe-bottom) + 20px);
  max-width: 640px;
  margin: 0 auto;
}

.stack { display: flex; flex-direction: column; gap: var(--gap); }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--topbar-h);
  margin: 0 -16px 12px;
  padding: calc(var(--safe-top)) 12px 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar__title { font-size: 20px; font-weight: 700; flex: 1; }
.topbar__spacer { width: 44px; }

/* ---------- Cards & fields ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card__title { font-size: 17px; font-weight: 700; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-muted); }

input[type="text"],
input[type="password"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 13px 14px;
  background: var(--bg-sunk);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
textarea { resize: vertical; min-height: 68px; }
select {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 38px;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

.muted { color: var(--text-muted); font-size: 14px; }
.small { font-size: 12px; }
.center { text-align: center; }

/* ---------- Buttons (large touch targets) ---------- */
.btn {
  --btn-bg: var(--bg-elev);
  --btn-fg: var(--text);
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--btn-bg);
  color: var(--btn-fg);
  border-radius: var(--radius-sm);
  padding: 13px 16px;
  min-height: 48px;
  font-weight: 650;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .04s ease, background .15s ease, opacity .15s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--block { width: 100%; }
.btn--sm { min-height: 38px; padding: 8px 12px; font-size: 14px; }
.btn--lg { min-height: 56px; font-size: 17px; }

.btn--primary { --btn-bg: var(--accent); --btn-fg: #fff; border-color: transparent; }
.btn--primary:active { --btn-bg: var(--accent-press); }
.btn--danger { --btn-bg: transparent; --btn-fg: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.btn--danger:active { --btn-bg: color-mix(in srgb, var(--danger) 12%, transparent); }
.btn--ghost { --btn-bg: transparent; border-color: transparent; color: var(--text-muted); padding-left: 6px; padding-right: 6px; }
.btn--outline { --btn-bg: transparent; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 auto; }

/* ---------- Login ---------- */
.login-card { width: 100%; max-width: 380px; gap: 16px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand__mark {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  border-radius: 12px;
  font-weight: 800; font-size: 26px;
}
.brand__name { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.form-error {
  color: var(--danger);
  font-size: 14px;
  font-weight: 600;
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
}

/* ---------- Photo capture ---------- */
.photo-drop {
  display: block;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-elev);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.photo-drop:active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, var(--bg-elev)); }
.photo-drop__inner { padding: 26px 18px; text-align: center; display: grid; gap: 4px; justify-items: center; }
.photo-drop__icon {
  width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent); font-size: 30px; font-weight: 700; line-height: 1;
  margin-bottom: 6px;
}
.photo-drop__label { font-weight: 700; font-size: 16px; }
.photo-drop__hint { color: var(--text-muted); font-size: 13px; }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.thumbs:empty { display: none; }
.thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-sunk);
  border: 1px solid var(--border);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb__remove {
  position: absolute; top: 4px; right: 4px;
  width: 26px; height: 26px; border-radius: 50%;
  border: none; background: rgba(0,0,0,.6); color: #fff;
  font-size: 16px; line-height: 1; cursor: pointer;
  display: grid; place-items: center;
}

/* ---------- Editor (draft / detail) ---------- */
.editor-photos {
  display: flex; gap: 8px; overflow-x: auto;
  padding-bottom: 4px; scroll-snap-type: x mandatory;
  margin: 0 -16px; padding-left: 16px; padding-right: 16px;
}
.editor-photos img {
  height: 128px; width: auto; border-radius: var(--radius-sm);
  object-fit: cover; scroll-snap-align: start; background: var(--bg-sunk);
  border: 1px solid var(--border);
}

.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; text-transform: capitalize;
  padding: 4px 10px; border-radius: 999px;
  background: var(--chip-bg); color: var(--text-muted);
}
.status-pill[data-status="draft"]   { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.status-pill[data-status="listed"],
.status-pill[data-status="approved"],
.status-pill[data-status="posting"] { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.status-pill[data-status="sold"]    { color: #fff; background: var(--ok); }
.status-pill[data-status="error"]   { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); }

/* Price panel */
.price-panel { background: var(--bg-sunk); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.price-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.price-cell { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 6px; }
.price-cell__label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.price-cell__value { font-size: 18px; font-weight: 800; margin-top: 2px; }
.price-cell--your { outline: 2px solid var(--accent); }
.price-cell--your .price-cell__value { color: var(--accent); }

.rationale { font-size: 14px; color: var(--text); }
.comps { display: flex; flex-direction: column; gap: 6px; }
.comps__title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.comp {
  display: flex; align-items: baseline; gap: 8px;
  padding: 8px 10px; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px;
}
.comp__price { font-weight: 800; }
.comp__body { flex: 1; min-width: 0; }
.comp__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.comp__src { color: var(--text-muted); font-size: 12px; }
.comp a { color: var(--accent); text-decoration: none; }

/* ---------- Lists (listings + inbox) ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.list-empty { text-align: center; color: var(--text-muted); padding: 48px 16px; }

.list-item {
  display: flex; gap: 12px; align-items: center;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; cursor: pointer;
  transition: transform .04s ease, border-color .15s ease;
  text-align: left; width: 100%;
}
.list-item:active { transform: scale(.99); border-color: var(--border-strong); }
.list-item__thumb {
  width: 60px; height: 60px; border-radius: var(--radius-sm);
  object-fit: cover; background: var(--bg-sunk); flex: none;
  display: grid; place-items: center; color: var(--text-muted); font-size: 22px;
  border: 1px solid var(--border);
}
.list-item__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.list-item__title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item__meta { color: var(--text-muted); font-size: 13px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.list-item__price { font-weight: 800; }

/* Inbox message rows */
.msg { align-items: flex-start; }
.msg.is-unread { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); }
.msg__dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); flex: none; margin-top: 7px; }
.msg__dot.is-hidden { visibility: hidden; }
.msg__from { font-weight: 700; }
.msg__item { color: var(--text-muted); font-size: 13px; }
.msg__body { font-size: 14px; color: var(--text); margin-top: 2px; }
.reply-box { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }

/* ---------- Chips (status filter) ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; -webkit-overflow-scrolling: touch; }
.chip {
  flex: none; border: 1px solid var(--border-strong);
  background: var(--bg-elev); color: var(--text-muted);
  border-radius: 999px; padding: 8px 16px; min-height: 40px;
  font-weight: 650; cursor: pointer; white-space: nowrap;
}
.chip.is-active { background: var(--accent); color: #fff; border-color: transparent; }

/* ---------- Pairing code ---------- */
.pairing-code {
  font-variant-numeric: tabular-nums;
  font-size: 42px; font-weight: 800; letter-spacing: .12em;
  text-align: center; padding: 18px; border-radius: var(--radius);
  background: var(--bg-sunk); border: 1px dashed var(--border-strong);
  color: var(--accent);
}

/* ---------- Bottom tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
  backdrop-filter: saturate(1.5) blur(14px);
  -webkit-backdrop-filter: saturate(1.5) blur(14px);
  border-top: 1px solid var(--border);
}
.tab {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 6px 0;
  -webkit-tap-highlight-color: transparent;
}
.tab.is-active { color: var(--accent); }
.tab__icon { font-size: 22px; line-height: 1; }
.tab__label { font-size: 11px; font-weight: 600; }
.tab__badge {
  position: absolute; top: 6px; left: calc(50% + 10px);
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--danger); color: #fff;
  border-radius: 999px; font-size: 11px; font-weight: 800;
  display: grid; place-items: center; line-height: 1;
}

/* ---------- Loader overlay ---------- */
.loader { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(2px); }
.loader__card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px 26px; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; gap: 12px; max-width: 260px; text-align: center; }
.loader__text { font-weight: 650; font-size: 14px; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toasts ---------- */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px); z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 16px; pointer-events: none; }
.toast {
  pointer-events: auto;
  max-width: 480px; width: 100%;
  background: #1e2536; color: #fff;
  border-radius: var(--radius-sm); padding: 12px 14px;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow);
  display: flex; gap: 10px; align-items: center;
  animation: toast-in .2s ease;
}
.toast--error { background: var(--danger); }
.toast--ok { background: var(--ok); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* Respect reduced-motion. */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
