/* Light theme (default).
   Positive polarity — dark text on a light background — measurably improves
   legibility and proofreading (Piepenbrock/Mayr/Buchner, Ergonomics 2013/2014).
   The background is warm off-white rather than pure white to cut glare, and
   text is dark grey rather than black, keeping contrast ~10:1 instead of a
   harsh 21:1. --accent is for accent-coloured text/borders (dark enough to
   read); --accent-bg is for accent-coloured fills. */
:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --surface: #fdfcf9;
  --surface-2: #ece8df;
  --border: #d9d3c6;
  --text: #33302a;
  --muted: #6e695f;
  --accent: #8f5d06;
  --accent-bg: #e8a33d;
  --accent-text: #1a1503;
  --green: #3fae6a;
  --red: #c14f4f;
  --radius: 10px;
}

/* Dark theme (user toggle, stored in the `theme` cookie).
   Dark grey, never pure black (OLED smearing / halation); text softened
   off-white, never pure white. */
:root.dark {
  color-scheme: dark;
  --bg: #14161a;
  --surface: #1d2026;
  --surface-2: #262a32;
  --border: #333842;
  --text: #e2e4e7;
  --muted: #9aa0a8;
  --accent: #e8a33d;
  --accent-bg: #e8a33d;
  --red: #d05c5c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
}

main { max-width: 1400px; margin: 0 auto; padding: 16px; }
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ── Top bar ─────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 800; font-size: 1.15rem; white-space: nowrap; letter-spacing: 0.02em; }
.brand-abused { color: var(--text); }
.brand-guns { color: var(--accent); }
.brand-tld { color: var(--muted); font-weight: 500; font-size: 0.75em; margin-left: 1px; }
.brand-login { letter-spacing: 0.02em; }
.brand-login .brand-abused { color: var(--text); }
.navsearch { flex: 1; max-width: 480px; }
.navsearch input { width: 100%; }

/* ── Alert bell ──────────────────────────────────────── */
.bell {
  position: relative;
  font-size: 1.25rem;
  line-height: 1;
  padding: 6px 8px;
  border-radius: var(--radius);
}
.bell:hover { background: var(--surface-2); }
.theme-btn { padding: 6px 10px; font-size: 1rem; line-height: 1; }
.bell-count {
  position: absolute;
  top: -2px;
  right: -4px;
  min-width: 18px;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  text-align: center;
}

/* ── Inputs & buttons ────────────────────────────────── */
input, select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 0.95rem;
}
input:focus, select:focus { outline: 2px solid var(--accent); border-color: transparent; }

.btn {
  display: inline-block;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  font-size: 0.95rem;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
}
.btn-primary { background: var(--accent-bg); color: var(--accent-text); border-color: var(--accent-bg); font-weight: 600; }
.btn-ghost:hover, .btn:hover { filter: brightness(1.15); }

/* ── Filters ─────────────────────────────────────────── */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 0;
  align-items: center;
}
.filters .price { width: 90px; }
.result-count { color: var(--muted); margin: 4px 0 12px; }

/* ── Listing rows (vertical list) ────────────────────── */
.listing-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.row-card {
  display: flex;
  gap: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  transition: border-color 0.1s ease;
}
.row-card:hover { border-color: var(--accent); }

.row-details { flex: 1; min-width: 0; }
.row-details h3 { margin: 0 0 8px; font-size: 1.05rem; line-height: 1.3; }

.row-fields { margin: 0; }
.row-fields > div { display: flex; gap: 6px; margin: 2px 0; font-size: 0.92rem; }
.row-fields dt { font-weight: 700; color: var(--accent); white-space: nowrap; }
.row-fields dd { margin: 0; min-width: 0; }
.row-price { font-weight: 700; }
.row-comment dd {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--muted);
}

.row-tags { display: flex; align-items: center; gap: 8px; margin: 10px 0 0; flex-wrap: wrap; }
.row-location { color: var(--muted); font-size: 0.85rem; }

.row-thumb {
  /* Scales with the browser: 42% of the row, never smaller than 300px.
     Height follows the image — rows are as tall as they need to be. */
  flex: 1 1 42%;
  min-width: 300px;
  max-width: 640px;
  align-self: flex-start;
  border-radius: calc(var(--radius) - 4px);
  overflow: hidden;
}
.row-thumb img { width: 100%; height: auto; display: block; }

.noimg {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.9rem;
}
.noimg.tall { min-height: 260px; }

.badge {
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--text);
}
.badge-source { background: var(--surface-2); color: var(--muted); }
/* Site brand colours — same as the Discord embed accents */
.source-used-guns-australia { background: #9fc6fe; color: #10233d; }
.source-oz-gun-sales { background: #153920; color: #b9e4c5; }
.source-ssaa-gun-sales { background: #f16424; color: #331302; }
.status-for-sale { background: var(--green); color: #06210f; }
.status-sold, .status-taken-deposit { background: var(--red); color: #fff; }

/* ── Ad banner ───────────────────────────────────────── */
.ad-banner {
  margin: 16px 0 4px;
  display: flex;
  justify-content: center;
}
.ad-banner img {
  max-width: 100%;
  /* Cap roughly at the height of a photo-less listing row */
  max-height: 200px;
  width: auto;
  height: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ── Keyword alerts page ─────────────────────────────── */
.page-title { margin: 12px 0 4px; font-size: 1.4rem; }
.keyword-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: 16px 0 24px;
}
.keyword-box h2 { margin: 0 0 10px; font-size: 1.1rem; }
.keyword-box .error { margin-bottom: 12px; }
.keyword-add { display: flex; gap: 8px; flex-wrap: wrap; }
.keyword-add input { flex: 1; min-width: 200px; max-width: 380px; }
.keyword-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 0;
  padding: 0;
}
.keyword-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 6px 4px 14px;
  font-size: 0.92rem;
}
.chip-x {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 7px;
  border-radius: 999px;
}
.chip-x:hover { background: var(--red); color: #fff; }
.matches-heading { display: flex; align-items: center; gap: 10px; font-size: 1.15rem; }
.badge-new { background: var(--accent-bg); color: var(--accent-text); }
.row-new { border-color: var(--accent); }

/* ── Pagination ──────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px 0;
  color: var(--muted);
}

/* ── Detail page ─────────────────────────────────────── */
.detail .back { margin-bottom: 14px; }
.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 24px;
}
.detail-image img {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.detail-info h1 { margin: 0 0 8px; font-size: 1.4rem; }
.detail-price { font-size: 1.3rem; font-weight: 700; color: var(--accent); display: flex; align-items: center; gap: 10px; }

.fields { border-collapse: collapse; width: 100%; margin: 12px 0 18px; }
.fields th, .fields td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
.fields th { color: var(--muted); font-weight: 500; width: 40%; }

.description {
  margin-top: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.description h2 { margin-top: 0; font-size: 1.05rem; }
.description p { white-space: pre-line; }

/* ── Login ───────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.login-card h1 { margin: 0; font-size: 1.3rem; text-align: center; }
.login-card .muted { text-align: center; margin: 0 0 12px; }
.login-card label { font-size: 0.85rem; color: var(--muted); margin-top: 6px; }
.login-card button { margin-top: 16px; }
.error {
  background: rgba(208, 92, 92, 0.15);
  border: 1px solid var(--red);
  color: var(--red);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin: 0;
  font-size: 0.9rem;
}

/* ── Mobile ──────────────────────────────────────────── */
@media (max-width: 720px) {
  .detail-grid { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .navsearch { order: 3; max-width: none; flex-basis: 100%; }
  .row-card { flex-direction: column-reverse; gap: 12px; }
  .row-thumb { flex: none; width: 100%; min-width: 0; max-width: none; }
}
