/* ==========================================================================
   Site styles - mobile first, light + dark themes, no framework.
   ========================================================================== */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef0f7;
  --text: #14172b;
  --muted: #5b6078;
  --border: #dde0ec;
  --primary: #4338ca;
  --primary-ink: #ffffff;
  --primary-soft: #e8e7fb;
  --accent: #f59e0b;
  --accent-ink: #1f1300;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --success: #067647;
  --success-soft: #e6f6ee;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 23, 43, 0.06), 0 4px 16px rgba(20, 23, 43, 0.06);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans Sinhala', 'Noto Sans Tamil', 'Iskoola Pota', 'Latha', sans-serif;
  color-scheme: light;
}
[data-theme='dark'] {
  --bg: #0e1020;
  --surface: #171a2e;
  --surface-2: #20243b;
  --text: #eceefa;
  --muted: #a3a8c3;
  --border: #2c3150;
  --primary: #8b85ff;
  --primary-ink: #0e1020;
  --primary-soft: #26244d;
  --accent: #fbbf24;
  --danger: #ff8a80;
  --danger-soft: #3a1d1d;
  --success: #5fd49b;
  --success-soft: #16302a;
  --shadow: none;
  color-scheme: dark;
}

*,
*::before,
*::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--primary); }
img { max-width: 100%; height: auto; }
h1, h2, h3 { line-height: 1.25; }
code { font-size: 0.85em; word-break: break-all; }

.wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.main { flex: 1; padding-top: 20px; padding-bottom: 40px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.center { text-align: center; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }

/* ---------- header ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font-weight: 700; }
.brand-mark {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  background: var(--primary); color: var(--primary-ink); font-size: 0.8rem; letter-spacing: 0.5px;
}
.brand-name { display: none; }
@media (min-width: 560px) { .brand-name { display: inline; } }
.topnav { display: flex; align-items: center; gap: 6px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid transparent;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-accent { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-block { width: 100%; }
.btn-google {
  background: #ffffff; color: #1f1f1f; border-color: #747775; gap: 10px; font-weight: 500;
  margin: 12px 0 4px;
}
.btn-google:hover { background: #f8f9fa; }
[data-theme='dark'] .btn-google { background: #131314; color: #e3e3e3; border-color: #8e918f; }
.g-logo { flex: none; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.875rem; margin: 12px 0 0; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.btn-sm { min-height: 34px; padding: 0 10px; font-size: 0.875rem; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--border);
  background: transparent; color: var(--text); font-size: 1.1rem; cursor: pointer;
}
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- cards & forms ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px;
}
.card-narrow { max-width: 440px; margin-left: auto; margin-right: auto; }
.card-title { font-size: 1.35rem; margin: 0 0 8px; }
.stack { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
label { font-weight: 600; font-size: 0.95rem; }
input, select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: 2px solid var(--primary-soft); }
.input-prefix { display: flex; align-items: stretch; }
.input-prefix span {
  display: grid; place-items: center; padding: 0 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-right: 0; border-radius: 12px 0 0 12px; font-weight: 600;
}
.input-prefix input { border-radius: 0 12px 12px 0; }
.otp-input { font-size: 1.6rem; letter-spacing: 0.5em; text-align: center; font-variant-numeric: tabular-nums; }
.cf-turnstile { min-height: 65px; }
fieldset.choice { border: 0; padding: 0; margin: 4px 0; display: grid; gap: 8px; }
fieldset.choice legend { font-weight: 600; margin-bottom: 6px; }
.choice-item {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--border);
  border-radius: 12px; font-weight: 400; cursor: pointer;
}
.choice-item input { width: 20px; min-height: 20px; margin-top: 3px; }
.choice-item span { display: flex; flex-direction: column; }
details.resend { margin-top: 8px; }
details.resend summary { cursor: pointer; color: var(--primary); min-height: 44px; display: flex; align-items: center; }

.alert { padding: 12px 14px; border-radius: 12px; margin: 10px 0; font-weight: 500; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-info { background: var(--primary-soft); color: var(--primary); }

.badge { display: inline-block; margin-left: 6px; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; background: var(--surface-2); }
.badge-verified { background: var(--success-soft); color: var(--success); }
.badge-pending { background: #fff4d6; color: #7a4b00; }
[data-theme='dark'] .badge-pending { background: #3a2e10; color: #fbd38d; }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 12px 0 16px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }
.grid-account { display: grid; gap: 0 16px; }
@media (min-width: 860px) { .grid-account { grid-template-columns: 1fr 1fr; } }

/* ---------- home ---------- */
.hero { padding: 28px 0 12px; }
.hero h1 { font-size: clamp(1.6rem, 5vw, 2.4rem); margin: 0 0 6px; }
.section-title { font-size: 1.2rem; margin: 24px 0 12px; }
.cat-grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (min-width: 640px) { .cat-grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 960px) { .cat-grid { grid-template-columns: repeat(6, 1fr); } }
.cat-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center;
  min-height: 96px; padding: 12px 6px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); text-decoration: none; font-size: 0.9rem; font-weight: 600;
}
.cat-tile:hover { border-color: var(--primary); }
.cat-icon { width: 36px; height: 36px; border-radius: 10px; background: var(--primary-soft); display: grid; place-items: center; font-size: 1.25rem; line-height: 1; }
.prose p { margin: 0 0 10px; }

/* ---------- skeleton loaders (used from Phase 3) ---------- */
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: sk 1.4s ease infinite; border-radius: 8px; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* ---------- footer & errors ---------- */
.footer { border-top: 1px solid var(--border); background: var(--surface); padding: 20px 0; }
.footer-inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; }
.footer nav { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.footer nav a { color: var(--muted); text-decoration: none; min-height: 32px; display: inline-flex; align-items: center; }
.error-page { text-align: center; padding-top: 60px; }
.error-code { font-size: 4rem; font-weight: 800; color: var(--primary); margin: 0; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; }
.g-linked { display: flex; align-items: center; gap: 8px; margin: 8px 0 12px; }

/* ---------- helpers ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.m0 { margin: 0; }
.h3 { font-size: 1.1rem; margin: 18px 0 10px; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; font-weight: 600; color: var(--primary); text-decoration: underline; cursor: pointer; min-height: 32px; }
.btn-danger { color: var(--danger); }
button.cat-tile { font: inherit; font-size: 0.9rem; font-weight: 600; cursor: pointer; width: 100%; }

/* ---------- status badges ---------- */
.badge-draft { background: var(--surface-2); color: var(--muted); }
.badge-live { background: var(--success-soft); color: var(--success); }
.badge-rejected { background: var(--danger-soft); color: var(--danger); }
.badge-expired, .badge-hidden, .badge-sold { background: var(--surface-2); color: var(--muted); }

/* ---------- post-ad wizard ---------- */
.wizard { max-width: 820px; margin-left: auto; margin-right: auto; }
.steps { list-style: none; display: flex; gap: 6px; padding: 0; margin: 0 0 16px; counter-reset: none; }
.step { flex: 1; min-width: 0; }
.step > a, .step > span { display: flex; flex-direction: column; align-items: center; gap: 4px; text-decoration: none; color: var(--muted); font-size: 0.8rem; font-weight: 600; text-align: center; }
.step-num { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--surface-2); color: var(--muted); font-size: 0.85rem; }
.step::after { content: ''; display: block; height: 3px; border-radius: 3px; background: var(--surface-2); margin-top: 6px; }
.step-done .step-num { background: var(--success-soft); color: var(--success); }
.step-done::after { background: var(--success); }
.step-current .step-num { background: var(--primary); color: var(--primary-ink); }
.step-current > span { color: var(--text); }
.step-current::after { background: var(--primary); }
.step-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.crumbs { color: var(--muted); margin: 0 0 12px; }

.ad-form { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-end { justify-content: flex-end; }
.field-grid { display: grid; gap: 14px; }
@media (min-width: 640px) { .field-grid { grid-template-columns: 1fr 1fr; } }
.field-error { color: var(--danger); font-size: 0.875rem; font-weight: 600; margin: 0; }
[aria-invalid='true'] { border-color: var(--danger); }
.counter { align-self: flex-end; font-size: 0.75rem; margin-top: -2px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; min-height: 44px; cursor: pointer; }
.check input { width: 20px; min-height: 20px; height: 20px; flex: none; }
.choice-row { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.choice-row .field-error { grid-column: 1 / -1; }
.input-suffix { display: flex; align-items: stretch; }
.input-suffix input { border-radius: 12px 0 0 12px; }
.input-suffix span {
  display: grid; place-items: center; padding: 0 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-left: 0; border-radius: 0 12px 12px 0; color: var(--muted);
}
textarea { resize: vertical; min-height: 160px; line-height: 1.5; }
select:disabled { opacity: 0.6; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.center-actions { justify-content: center; }

/* category step */
.drafts { margin-bottom: 8px; }
.draft-list, .choice-list, .my-ads { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; }
.draft-list li { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 12px; padding: 8px 8px 8px 12px; }
.draft-link { flex: 1; min-width: 0; display: flex; flex-direction: column; text-decoration: none; color: var(--text); }
.draft-link strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.choice-btn {
  width: 100%; display: flex; justify-content: space-between; align-items: center; min-height: 52px; padding: 0 16px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 12px;
  font: inherit; font-weight: 600; text-align: left; cursor: pointer;
}
.choice-btn:hover, button.cat-tile:hover { border-color: var(--primary); }

/* photos step */
.photo-grid { list-style: none; padding: 0; margin: 12px 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .photo-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 820px) { .photo-grid { grid-template-columns: repeat(4, 1fr); } }
.photo-tile { position: relative; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface-2); }
.photo-tile img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.cover-badge { position: absolute; top: 6px; left: 6px; background: var(--primary); color: var(--primary-ink); font-size: 0.75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.photo-actions { display: flex; justify-content: space-between; gap: 2px; padding: 4px; background: var(--surface); }
.photo-actions form { display: contents; }
.photo-actions .btn { padding: 0 8px; min-width: 36px; }
.uploader { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 16px; border: 2px dashed var(--border); border-radius: var(--radius); margin: 12px 0; }
.uploader input:focus-visible + .upload-btn { outline: 3px solid var(--accent); outline-offset: 2px; }
.upload-btn { cursor: pointer; }
.upload-list { list-style: none; padding: 0; margin: 0; width: 100%; display: grid; gap: 8px; }
.upload-list:empty { display: none; }
.upload-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; font-size: 0.875rem; }
.upload-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-row progress { grid-column: 1 / -1; width: 100%; height: 8px; accent-color: var(--primary); }
.upload-failed .upload-status { color: var(--danger); font-weight: 600; }
.upload-done .upload-status { color: var(--success); font-weight: 600; }

/* review step */
.issue-list { margin: 6px 0 0; padding-left: 20px; }
.issue-list a { color: inherit; }
.ad-preview { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin: 12px 0 16px; }
.preview-photos { margin: -14px -14px 12px; }
.preview-cover { display: block; width: 100%; max-height: 420px; object-fit: contain; background: var(--surface-2); border-radius: var(--radius) var(--radius) 0 0; }
.preview-thumbs { list-style: none; display: flex; gap: 6px; padding: 6px; margin: 0; overflow-x: auto; }
.preview-thumbs img { width: 72px; height: 54px; object-fit: cover; border-radius: 8px; display: block; }
.preview-title { font-size: 1.3rem; margin: 0 0 4px; overflow-wrap: anywhere; }
.preview-price { font-size: 1.25rem; font-weight: 800; color: var(--primary); margin: 0 0 4px; }
.ad-preview .prose { overflow-wrap: anywhere; }
.publish-form { border-top: 1px solid var(--border); padding-top: 8px; }

/* done */
.done-icon { display: grid; place-items: center; width: 64px; height: 64px; margin: 8px auto 12px; border-radius: 50%; background: var(--success-soft); color: var(--success); font-size: 2rem; }

/* my ads (account) */
.my-ad { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); border: 1px solid var(--border); border-radius: 12px; padding: 6px; }
.my-ad img, .my-ad-noimg { width: 64px; height: 64px; flex: none; border-radius: 8px; object-fit: cover; background: var(--surface-2); }
.my-ad-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.my-ad-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.my-ad .badge { margin-right: 4px; }

/* ==========================================================================
   Phase 3: home, listings, ad page
   ========================================================================== */
.chip { display: inline-flex; align-items: center; min-height: 32px; padding: 0 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--text); text-decoration: none; font-size: 0.875rem; }
.chip:hover { border-color: var(--primary); }
.popular { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 12px 0 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.section-head a { font-weight: 600; text-decoration: none; }
.cta { text-align: center; margin-top: 28px; }
.cta h2 { margin: 0 0 4px; }
.cta .btn { margin: 8px 4px 0; }

/* search bar */
.searchbar { display: flex; gap: 8px; margin: 12px 0; }
.searchbar input[type='search'] { flex: 1; min-width: 0; }
.searchbar select { width: auto; max-width: 40%; }
.searchbar-big input[type='search'] { min-height: 54px; font-size: 1.05rem; }
@media (max-width: 559px) {
  .searchbar-big { flex-wrap: wrap; }
  .searchbar-big select { flex: 1; max-width: none; }
}

/* ad cards */
.ad-grid { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 720px) { .ad-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1080px) { .ad-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.listing-main .ad-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 1080px) { .listing-main .ad-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.ad-card { min-width: 0; }
.ad-card-link {
  display: flex; flex-direction: column; height: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; color: var(--text); text-decoration: none;
}
.ad-card-link:hover { border-color: var(--primary); }
.ad-card-img { position: relative; aspect-ratio: 4 / 3; background: var(--surface-2); }
.ad-card-img img { display: block; width: 100%; height: 100%; object-fit: cover; }
.noimg { display: grid; place-items: center; height: 100%; color: var(--muted); font-size: 0.85rem; }
.photo-count, .tag-featured {
  position: absolute; bottom: 6px; right: 6px; padding: 1px 8px; border-radius: 999px; font-size: 0.72rem; font-weight: 700;
  background: rgba(0, 0, 0, 0.6); color: #fff;
}
.tag-featured { bottom: auto; right: auto; top: 6px; left: 6px; background: var(--accent); color: var(--accent-ink); }
.ad-card-body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.ad-card-title { font-size: 0.95rem; font-weight: 600; margin: 0; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.ad-card-chips { margin: 0; font-size: 0.8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ad-card-price { margin: 2px 0 0; font-weight: 800; color: var(--primary); }
.ad-card-meta { margin: auto 0 0; display: flex; justify-content: space-between; gap: 6px; font-size: 0.75rem; color: var(--muted); }
.ad-card-meta span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ad-card-meta span:last-child { flex: none; }
.ad-card-tags { margin: 4px 0 0; }
.ad-card-tags .badge { margin: 0 4px 0 0; }
.ad-grid-small { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 720px) { .ad-grid-small { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1080px) { .ad-grid-small { grid-template-columns: repeat(6, minmax(0, 1fr)); } }

/* listing page */
nav.crumbs { font-size: 0.875rem; margin-bottom: 8px; }
nav.crumbs a { color: var(--muted); }
.listing-head h1 { font-size: clamp(1.25rem, 4vw, 1.6rem); margin: 0; overflow-wrap: anywhere; }
.listing { display: grid; gap: 16px; }
@media (min-width: 900px) { .listing { grid-template-columns: 260px minmax(0, 1fr); align-items: start; } }
.filters > summary { list-style: none; width: 100%; }
.filters > summary::-webkit-details-marker { display: none; }
.filters[open] > summary { margin-bottom: 10px; }
@media (min-width: 900px) { .filters > summary { display: none; } }
.filters-form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 14px; }
@media (min-width: 900px) { .listing-side { position: sticky; top: 76px; max-height: calc(100vh - 90px); overflow-y: auto; } }
.filter-group { display: flex; flex-direction: column; gap: 6px; margin: 0; }
.filter-title { font-weight: 700; font-size: 0.9rem; margin: 0; }
.filters-form input, .filters-form select { min-height: 42px; }
.range { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.sub-cats { list-style: none; padding: 0; margin: 0; display: grid; gap: 2px; }
.sub-cats a { display: flex; justify-content: space-between; padding: 6px 4px; color: var(--text); text-decoration: none; border-radius: 8px; }
.sub-cats a:hover { background: var(--surface-2); }
.pager { display: flex; justify-content: center; gap: 10px; margin: 8px 0 24px; }
.empty { text-align: center; }

/* ad page */
.ad-layout { display: grid; gap: 16px; }
@media (min-width: 900px) { .ad-layout { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; } .ad-side { position: sticky; top: 76px; } }
.gallery { position: relative; background: #0b0c14; border-radius: var(--radius); overflow: hidden; }
.gallery-empty { display: grid; place-items: center; aspect-ratio: 16 / 9; color: #aaa; }
.gallery-track { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; aspect-ratio: 4 / 3; }
@media (min-width: 900px) { .gallery-track { aspect-ratio: 16 / 10; } }
.gallery-track::-webkit-scrollbar { display: none; }
.gallery-slide { flex: 0 0 100%; margin: 0; scroll-snap-align: center; display: grid; place-items: center; }
.gallery-slide img { max-width: 100%; max-height: 100%; object-fit: contain; }
.gallery-nav {
  position: absolute; top: calc(50% - 60px); width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: rgba(0, 0, 0, 0.5); color: #fff; font-size: 1.6rem; cursor: pointer; display: grid; place-items: center;
}
.gallery-nav.prev { left: 8px; }
.gallery-nav.next { right: 8px; }
.gallery-count { position: absolute; top: 8px; right: 8px; padding: 2px 10px; border-radius: 999px; background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 0.8rem; }
.gallery-thumbs { list-style: none; display: flex; gap: 6px; margin: 0; padding: 6px; overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-top: 0; border-radius: 0 0 var(--radius) var(--radius); }
.gallery-thumbs img { display: block; width: 80px; height: 60px; object-fit: cover; border-radius: 8px; }
.ad-title { font-size: clamp(1.3rem, 4vw, 1.75rem); margin: 14px 0 4px; overflow-wrap: anywhere; }
.ad-price { font-size: 1.6rem; font-weight: 800; color: var(--primary); margin: 0 0 4px; }
.ad-main .prose { overflow-wrap: anywhere; }
dl.spec { grid-template-columns: minmax(120px, max-content) 1fr; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.seller-name { font-size: 1.15rem; font-weight: 700; margin: 0 0 2px; overflow-wrap: anywhere; }
.phone-box { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.phone-number { font-size: 1.4rem; font-weight: 800; letter-spacing: 0.5px; margin: 0; font-variant-numeric: tabular-nums; }
.phone-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.phone-actions[hidden] { display: none; }
.btn-whatsapp { background: #128c4a; color: #fff; }
.safety ul { padding-left: 18px; margin: 8px 0; }
.report { margin: 20px 0; }
.report summary { cursor: pointer; color: var(--muted); min-height: 44px; display: flex; align-items: center; }

/* ==========================================================================
   Phase 4: My account, saved ads, saved searches, notifications,
   seller / shop pages, ad page tools (save, share, zoom, loan calculator)
   ========================================================================== */

/* header bell */
.bell { position: relative; display: inline-grid; place-items: center; text-decoration: none; }
.bell-count {
  position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 0.7rem; font-weight: 800; line-height: 20px; text-align: center;
}

/* account menu */
.account-nav {
  display: flex; gap: 6px; overflow-x: auto; margin: 8px 0 16px; padding-bottom: 4px; scrollbar-width: thin;
}
.account-nav a {
  flex: none; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-weight: 600; font-size: 0.9rem; text-decoration: none; white-space: nowrap;
}
.account-nav a.active { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

/* small number tiles */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin: 8px 0 12px; }
.stat {
  display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2);
  color: var(--text); text-decoration: none;
}
a.stat:hover { outline: 2px solid var(--primary-soft); }
.stat strong { font-size: 1.4rem; line-height: 1.1; }
.stat span { font-size: 0.8rem; color: var(--muted); }

/* status tabs */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); margin: 12px 0; }
.tabs a {
  flex: none; padding: 10px 12px; color: var(--muted); font-weight: 600; text-decoration: none;
  border-bottom: 3px solid transparent; white-space: nowrap;
}
.tabs a.active { color: var(--text); border-bottom-color: var(--primary); }

/* my ads list */
.myads { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.myad { display: flex; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border); scroll-margin-top: 80px; }
.myad:target { background: var(--primary-soft); border-radius: 12px; padding-left: 8px; padding-right: 8px; }
.myad-img { flex: none; }
.myad-img img, .myad-img .my-ad-noimg { display: block; width: 96px; height: 72px; border-radius: 10px; object-fit: cover; background: var(--surface-2); }
.myad-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.myad-title { margin: 0; font-weight: 700; overflow-wrap: anywhere; }
.myad-title a { color: var(--text); text-decoration: none; }
.myad-title a:hover { text-decoration: underline; }
.myad-note { margin: 0; padding: 6px 10px; border-radius: 8px; background: var(--surface-2); }
.myad-note.error { background: var(--danger-soft); color: var(--danger); }
.myad-stats { margin: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); }
.myad-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.myad-actions form { margin: 0; }
.badge-deleted { background: var(--surface-2); color: var(--muted); }

/* stats chart (SVG) */
.bars { display: block; width: 100%; height: 140px; margin-top: 8px; background: var(--surface-2); border-radius: 10px; }
.bars .bar { fill: var(--primary); }
.bars .bar:hover { fill: var(--accent); }
.bars-axis { display: flex; justify-content: space-between; margin-top: 4px; }

/* saved ads */
.ad-card { position: relative; }
.ad-card-dim .ad-card-img img { filter: grayscale(1); opacity: 0.6; }
.tag-note {
  position: absolute; top: 6px; left: 6px; padding: 1px 8px; border-radius: 999px; font-size: 0.72rem; font-weight: 700;
  background: var(--danger); color: #fff;
}
.card-extra { margin: 4px 2px 0; text-align: right; }

/* saved searches */
.saved-list, .notif-list { list-style: none; margin: 0; padding: 0; }
.saved-list li {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.saved-name { font-weight: 700; overflow-wrap: anywhere; }
.listing-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 8px; }
.save-search { margin: 0; }

/* notifications */
.notif-list li { padding: 12px; border-bottom: 1px solid var(--border); border-radius: 10px; }
.notif-list li.unread { background: var(--primary-soft); }
.notif-title { font-weight: 700; overflow-wrap: anywhere; }

/* seller / shop pages */
.seller-head { display: flex; gap: 16px; align-items: flex-start; }
.seller-info { flex: 1; min-width: 0; }
.seller-info h1 { font-size: clamp(1.3rem, 4vw, 1.7rem); overflow-wrap: anywhere; }
.seller-avatar {
  flex: none; display: grid; place-items: center; width: 72px; height: 72px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary); font-size: 2rem; font-weight: 800;
}
.shop-logo { flex: none; width: 96px; height: 96px; border-radius: 16px; object-fit: contain; background: #fff; border: 1px solid var(--border); }
.shop-logo-lg { width: 120px; height: 120px; display: block; margin-bottom: 8px; }
.shop-kv { margin-bottom: 0; }

/* ad page tools: save + share */
.ad-tools { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.ad-tools form { margin: 0; }
.ad-tools [aria-pressed='true'] { color: var(--danger); border-color: var(--danger); }
.gallery-slide a { display: grid; place-items: center; width: 100%; height: 100%; cursor: zoom-in; }

/* leasing calculator */
.loan { margin: 16px 0; }
.loan-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin: 10px 0; }
.loan-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; }
.loan-result { margin: 4px 0; font-size: 1.05rem; }
.loan-result strong { font-size: 1.3rem; color: var(--primary); }

/* photo zoom viewer */
.lightbox { width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: rgba(0, 0, 0, 0.92); color: #fff; }
.lightbox::backdrop { background: rgba(0, 0, 0, 0.92); }
.lightbox-stage { width: 100%; height: 100%; overflow: auto; display: grid; place-items: center; touch-action: pinch-zoom pan-x pan-y; }
.lightbox-stage img { max-width: 100%; max-height: 100vh; object-fit: contain; cursor: zoom-in; }
.lightbox-stage.zoomed { display: block; }
.lightbox-stage.zoomed img { max-width: none; max-height: none; cursor: zoom-out; }
.lightbox-btn {
  position: fixed; width: 48px; height: 48px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, 0.55);
  color: #fff; font-size: 1.6rem; cursor: pointer;
}
.lightbox-close { top: 12px; right: 12px; }
.lightbox-prev { left: 12px; top: 50%; transform: translateY(-50%); }
.lightbox-next { right: 12px; top: 50%; transform: translateY(-50%); }
.lightbox-help { position: fixed; bottom: 8px; left: 0; right: 0; margin: 0; text-align: center; font-size: 0.85rem; opacity: 0.8; pointer-events: none; }

/* ---------------------------------------------------------------- Phase 5 (public) */
.brand-logo { height: 36px; width: auto; max-width: 160px; object-fit: contain; border-radius: 6px; }
.banners { margin: 0 0 16px; }
.banner-track { display: grid; grid-auto-flow: column; grid-auto-columns: 100%; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; border-radius: var(--radius); }
.banner { display: block; scroll-snap-align: start; }
.banner img { display: block; width: 100%; height: auto; aspect-ratio: 16 / 5; object-fit: cover; border-radius: var(--radius); background: var(--surface-2); }
.footer-contact, .footer-social { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0; }
.footer-contact a, .footer-social a { color: var(--muted); }
.prose h2, .prose h3, .prose h4 { margin: 18px 0 8px; }
.prose ul, .prose ol { margin: 0 0 12px; padding-left: 22px; }
.prose li { margin: 4px 0; }

/* ==========================================================================
   Phase 6: languages, PWA install, loading placeholders
   ========================================================================== */
/* Sinhala and Tamil letters are taller: a little more line height, slightly smaller headings. */
:lang(si), :lang(ta) { line-height: 1.65; }
:lang(si) h1, :lang(ta) h1 { font-size: 1.45rem; line-height: 1.4; }
:lang(si) .btn, :lang(ta) .btn { white-space: normal; text-align: center; line-height: 1.25; }

.lang-switch { display: flex; gap: 4px; justify-content: flex-end; padding-bottom: 6px; font-size: 0.85rem; }
.lang-switch a, .lang-switch .lang-current {
  display: inline-flex; align-items: center; min-height: 32px; padding: 0 10px; border-radius: 999px;
  text-decoration: none; color: var(--muted);
}
.lang-switch a:hover { background: var(--surface-2); color: var(--text); }
.lang-switch .lang-current { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
[data-theme='dark'] .lang-switch .lang-current { color: var(--text); }

/* "Install app" button (shown by app.js only when the browser offers it). */
.install-app[hidden] { display: none; }
.install-app { position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 20; display: flex; gap: 8px; align-items: center;
  justify-content: space-between; padding: 10px 12px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow); max-width: 520px; margin: 0 auto; }

/* Loading placeholders: photos show a soft moving shade until they arrive. */
.ad-card-img, .gallery-slide { background-color: var(--surface-2); }
@media (prefers-reduced-motion: no-preference) {
  .ad-card-img img, .gallery-slide img { background: linear-gradient(90deg, var(--surface-2) 0%, var(--border) 50%, var(--surface-2) 100%);
    background-size: 200% 100%; animation: shimmer 1.4s ease-in-out infinite; }
  .ad-card-img img.loaded, .gallery-slide img.loaded { animation: none; background: none; }
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* Offline notice (service worker) */
.offline-bar { position: fixed; top: 0; left: 0; right: 0; z-index: 30; background: var(--accent); color: var(--accent-ink);
  text-align: center; padding: 6px; font-size: 0.9rem; }
.offline-bar[hidden] { display: none; }

/* ---------------------------------------------------------------- Phase 7 */
/* Card tags: Top ad, Urgent */
.tag-top, .tag-urgent {
  position: absolute; top: 6px; right: 6px; padding: 1px 8px; border-radius: 999px; font-size: 0.72rem; font-weight: 700;
}
.tag-top { background: var(--primary); color: var(--primary-ink); }
.tag-urgent { background: var(--danger); color: #fff; }
.tag-top + .tag-urgent { top: 30px; }
.ad-card-top .ad-card-link { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary-soft); }
.top-ads { background: var(--primary-soft); border-radius: var(--radius); padding: 10px; margin-bottom: 14px; }
.top-ads .filter-title { margin-bottom: 8px; }

/* Prices: dropped price, lease / per perch line */
.price-was { color: var(--muted); font-weight: 400; font-size: 0.8em; margin-left: 4px; }
.ad-card-sub { margin: 0; font-size: 0.78rem; color: var(--success); font-weight: 600; }

/* Deal / drop / urgent badges */
.badge-deal-good { background: var(--success-soft); color: var(--success); }
.badge-deal-fair { background: var(--surface-2); color: var(--text); }
.badge-deal-high { background: #fff4d6; color: #7a4b00; }
[data-theme='dark'] .badge-deal-high { background: #3a2e10; color: #fbd38d; }
.badge-drop { background: var(--success-soft); color: var(--success); }
.badge-urgent { background: var(--danger-soft); color: var(--danger); }

/* Filters: near a place, "show only" checkboxes */
.near-box summary { cursor: pointer; }
.near-box[open] { gap: 6px; }
.near-box .btn { align-self: flex-start; }
.filter-checks { border: 0; padding: 0; }
.filter-checks .check { font-size: 0.9rem; }

/* Market price box (ad page) and /market-prices */
.market { border-left: 4px solid var(--primary); }
.market p { margin: 8px 0; }
.market-table td:nth-child(2) { color: var(--muted); }
.table .num { text-align: right; white-space: nowrap; }

/* Rates strip (home page) */
.rates-box { margin: 0 0 16px; }
.rates-strip {
  list-style: none; margin: 0; padding: 8px 12px; display: flex; gap: 6px 18px; flex-wrap: wrap; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.rates-strip li { display: flex; flex-direction: column; line-height: 1.25; min-width: 70px; }
.rates-strip strong { font-size: 0.95rem; white-space: nowrap; }
.rates-more { flex-direction: row !important; gap: 12px; margin-left: auto; font-size: 0.85rem; }
.trend { font-size: 0.7rem; margin-left: 3px; }
.trend-up { color: var(--danger); }
.trend-down { color: var(--success); }

/* My ads: "Bump up again in 5 h" */
.myad-wait { align-self: center; }

/* Compare */
.compare-bar {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 20; display: flex; gap: 6px;
  padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
}
.compare-bar[hidden] { display: none; }
.compare-bar .btn { border-radius: 999px; }
.compare-table { table-layout: fixed; min-width: 520px; }
.compare-table thead td { width: 140px; }
.compare-table th[scope='row'] { width: 140px; }
.compare-table td { color: var(--text); overflow-wrap: anywhere; }
.compare-head { display: flex; flex-direction: column; gap: 6px; color: var(--text); text-decoration: none; font-weight: 600; }
.compare-head img, .compare-noimg {
  display: block; width: 100%; max-width: 200px; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 10px; background: var(--surface-2);
}
@media print { .compare-bar { display: none; } }
