/* ==========================================================================
   ListNear - base styles
   Mobile-first, CSS-variable driven theming with automatic dark mode.
   ========================================================================== */

:root {
  /* Brand */
  --brand: #0b6bcb;
  --brand-strong: #0956a5;
  --brand-soft: #e8f1fd;
  --accent: #128a4b;
  --accent-strong: #0e6e3c;
  --danger: #c62828;
  --warning: #b26a00;

  /* Surfaces */
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --border: #dbe2ea;
  --text: #16202c;
  --text-muted: #5b6b7c;
  --text-inverse: #ffffff;

  /* Feedback */
  --ok-bg: #e6f6ec;
  --ok-text: #0e6e3c;
  --err-bg: #fdecea;
  --err-text: #b3261e;
  --warn-bg: #fdf3e2;
  --warn-text: #8a5200;

  /* Shape + depth */
  --radius-sm: 6px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow: 0 4px 16px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.14);

  /* Layout */
  --container: 1160px;
  --header-h: 62px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #5aa2ff;
    --brand-strong: #7bb6ff;
    --brand-soft: #16283f;
    --accent: #3ec27e;
    --accent-strong: #2ea568;

    --bg: #0e1620;
    --surface: #16202c;
    --surface-2: #1e2a38;
    --border: #2a3a4c;
    --text: #e8eef5;
    --text-muted: #9db0c4;
    --text-inverse: #0e1620;

    --ok-bg: #12301f;
    --ok-text: #6ee7a2;
    --err-bg: #3a1a1a;
    --err-text: #ff9d9d;
    --warn-bg: #33280f;
    --warn-text: #ffcf7a;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.55);
  }
}

/* --- Reset ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
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;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 var(--space-3); }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 var(--space-4); }
ul, ol { margin: 0 0 var(--space-4); padding-left: 1.25rem; }
:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--brand); color: #fff; padding: 10px 16px;
}
.skip-link:focus { left: 8px; top: 8px; }

/* --- Layout --------------------------------------------------------------- */
.container { width: 100%; max-width: var(--container); margin: 0 auto; padding: 0 var(--space-4); }
main { flex: 1 0 auto; padding: var(--space-5) 0 var(--space-7); }
.section { margin-bottom: var(--space-7); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-4); flex-wrap: wrap; }
.muted { color: var(--text-muted); }
.small { font-size: 0.875rem; }
.center { text-align: center; }
.stack > * + * { margin-top: var(--space-4); }
.row { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: center; }
.grow { flex: 1 1 auto; }
.hidden { display: none !important; }

/* --- Header --------------------------------------------------------------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40;
}
.site-header .container {
  display: flex; align-items: center; gap: var(--space-4);
  min-height: var(--header-h);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.2rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  display: grid; place-items: center; color: #fff; font-weight: 800;
}
.header-nav { display: flex; align-items: center; gap: var(--space-2); margin-left: auto; }
.header-nav a.navlink { color: var(--text-muted); font-weight: 600; padding: 8px 10px; border-radius: var(--radius-sm); }
.header-nav a.navlink:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.header-search { display: none; flex: 1 1 auto; max-width: 440px; }

/* --- Buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 700; cursor: pointer;
  padding: 11px 18px; border-radius: 999px; border: 1px solid transparent;
  background: var(--surface-2); color: var(--text); text-decoration: none;
  transition: transform .06s ease, background .15s ease, box-shadow .15s ease;
  min-height: 44px;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-brand { background: var(--brand); color: #fff; }
.btn-brand:hover { background: var(--brand-strong); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 7px 12px; min-height: 36px; font-size: 0.875rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* --- Cards ---------------------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-pad { padding: var(--space-5); }
.grid { display: grid; gap: var(--space-4); }
.grid-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.ad-card { overflow: hidden; display: flex; flex-direction: column; height: 100%; }
.ad-card .thumb {
  aspect-ratio: 4 / 3; background: var(--surface-2); position: relative; overflow: hidden;
}
.ad-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.ad-card .thumb .ph { display: grid; place-items: center; height: 100%; color: var(--text-muted); font-size: 2rem; }
.ad-card .body { padding: var(--space-3) var(--space-4) var(--space-4); display: flex; flex-direction: column; gap: 6px; flex: 1; }
.ad-card .price { font-weight: 800; color: var(--accent-strong); }
.ad-card .title { font-weight: 700; color: var(--text); font-size: 0.98rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ad-card .meta { color: var(--text-muted); font-size: 0.82rem; margin-top: auto; display: flex; justify-content: space-between; gap: 8px; }
@media (hover: hover) { .ad-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); } .ad-card { transition: transform .12s ease, box-shadow .12s ease; } }

/* --- Category tiles ------------------------------------------------------- */
.tile { display: flex; gap: var(--space-3); align-items: center; padding: var(--space-4); }
.tile .ico {
  width: 44px; height: 44px; border-radius: 12px; flex: 0 0 auto;
  background: var(--brand-soft); color: var(--brand); display: grid; place-items: center;
}
.tile .ico svg { width: 22px; height: 22px; }
.tile .name { font-weight: 700; }
.tile .count { color: var(--text-muted); font-size: 0.82rem; }
.tile:hover { text-decoration: none; border-color: var(--brand); }

/* --- Hero ----------------------------------------------------------------- */
.hero { background: linear-gradient(160deg, var(--brand-soft), transparent 70%); border-bottom: 1px solid var(--border); padding: var(--space-6) 0; }
.hero h1 { font-size: 1.9rem; margin-bottom: var(--space-3); }
.hero p.lead { font-size: 1.05rem; color: var(--text-muted); max-width: 60ch; }

/* --- Forms ---------------------------------------------------------------- */
.field { margin-bottom: var(--space-4); }
.field label { display: block; font-weight: 600; margin-bottom: 6px; }
.field .hint { color: var(--text-muted); font-size: 0.82rem; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=search], input[type=url], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 11px 12px; min-height: 44px;
}
textarea { min-height: 140px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px var(--brand-soft); }
.field-error { color: var(--err-text); font-size: 0.85rem; margin-top: 4px; }
.form-grid { display: grid; gap: var(--space-4); grid-template-columns: 1fr; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4); margin: 0 0 var(--space-5); }
legend { font-weight: 700; padding: 0 6px; }
.checkbox { display: flex; gap: 10px; align-items: flex-start; }
.checkbox input { width: auto; min-height: auto; margin-top: 4px; }
.hp-field { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; overflow: hidden; }

/* --- Alerts --------------------------------------------------------------- */
.alert { padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid transparent; margin-bottom: var(--space-4); }
.alert-ok { background: var(--ok-bg); color: var(--ok-text); border-color: var(--ok-text); }
.alert-err { background: var(--err-bg); color: var(--err-text); border-color: var(--err-text); }
.alert-warn { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-text); }
.alert-info { background: var(--brand-soft); color: var(--brand-strong); border-color: var(--brand); }

/* --- Badges --------------------------------------------------------------- */
.badge { display: inline-block; font-size: 0.72rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--text-muted); text-transform: uppercase; letter-spacing: .02em; }
.badge-pending { background: var(--warn-bg); color: var(--warn-text); }
.badge-active { background: var(--ok-bg); color: var(--ok-text); }
.badge-rejected { background: var(--err-bg); color: var(--err-text); }
.badge-flagged { background: var(--err-bg); color: var(--err-text); }
.badge-expired { background: var(--surface-2); color: var(--text-muted); }

/* --- Breadcrumbs ---------------------------------------------------------- */
.breadcrumbs { font-size: 0.85rem; color: var(--text-muted); margin-bottom: var(--space-4); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.breadcrumbs a { color: var(--text-muted); }
.breadcrumbs .sep { opacity: .5; }

/* --- Search / filters ----------------------------------------------------- */
.searchbar { display: flex; gap: var(--space-2); }
.searchbar input { flex: 1 1 auto; }
.filters { display: grid; gap: var(--space-3); grid-template-columns: 1fr 1fr; align-items: end; }
.filters .field { margin: 0; }
.pill-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.pill { padding: 7px 13px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--text-muted); font-weight: 600; font-size: .875rem; }
.pill.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.pill:hover { text-decoration: none; border-color: var(--brand); }

/* --- Ad detail ------------------------------------------------------------ */
.ad-layout { display: grid; gap: var(--space-6); grid-template-columns: 1fr; }
.gallery { display: grid; gap: var(--space-2); grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.gallery img { border-radius: var(--radius-sm); border: 1px solid var(--border); aspect-ratio: 4/3; object-fit: cover; cursor: zoom-in; }
.gallery-main { border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; background: var(--surface); }
.gallery-main img { width: 100%; max-height: 520px; object-fit: contain; background: var(--surface-2); }
.price-tag { font-size: 1.6rem; font-weight: 800; color: var(--accent-strong); }
.detail-list { list-style: none; padding: 0; }
.detail-list li { display: flex; justify-content: space-between; gap: var(--space-4); padding: 9px 0; border-bottom: 1px dashed var(--border); }
.detail-list li span:first-child { color: var(--text-muted); }
.ad-body { white-space: pre-wrap; overflow-wrap: anywhere; }

/* --- Footer --------------------------------------------------------------- */
.site-footer { background: var(--surface); border-top: 1px solid var(--border); padding: var(--space-6) 0; margin-top: auto; color: var(--text-muted); font-size: 0.9rem; }
.footer-grid { display: grid; gap: var(--space-5); grid-template-columns: 1fr; }
.footer-grid h3 { font-size: 0.95rem; color: var(--text); }
.footer-links { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.footer-links a { color: var(--text-muted); }
.footer-bottom { border-top: 1px solid var(--border); margin-top: var(--space-5); padding-top: var(--space-4); display: flex; flex-wrap: wrap; gap: var(--space-3); justify-content: space-between; align-items: center; }
.coffee { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; color: var(--warn-text); background: var(--warn-bg); padding: 9px 15px; border-radius: 999px; }
.coffee:hover { text-decoration: none; }

/* --- Pagination ----------------------------------------------------------- */
.pagination { display: flex; gap: var(--space-2); justify-content: center; align-items: center; flex-wrap: wrap; margin-top: var(--space-6); }
.pagination a, .pagination span { padding: 8px 13px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); }
.pagination .current { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 700; }

/* --- Admin ---------------------------------------------------------------- */
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.admin-table th, .admin-table td { text-align: left; padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.admin-table th { color: var(--text-muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: .03em; }
.table-wrap { overflow-x: auto; }
.stat-row { display: grid; gap: var(--space-3); grid-template-columns: repeat(2, 1fr); }
.stat { padding: var(--space-4); text-align: center; }
.stat .n { font-size: 1.7rem; font-weight: 800; }
.stat .l { color: var(--text-muted); font-size: .82rem; }

/* --- Utilities ------------------------------------------------------------ */
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.mt-4 { margin-top: var(--space-4); } .mb-4 { margin-bottom: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.prose { max-width: 72ch; }
.prose h2 { margin-top: var(--space-6); }
.prose ul li { margin-bottom: 6px; }
.img-count { color: var(--text-muted); font-size: .85rem; }

/* --- Breakpoints ---------------------------------------------------------- */
@media (min-width: 640px) {
  h1 { font-size: 1.9rem; }
  .grid-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .footer-grid { grid-template-columns: 2fr 1fr 1fr 1fr; }
  .stat-row { grid-template-columns: repeat(4, 1fr); }
  .header-search { display: block; }
}
@media (min-width: 900px) {
  h1 { font-size: 2.1rem; }
  .hero h1 { font-size: 2.5rem; }
  .grid-cards { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .ad-layout { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); }
  .filters { grid-template-columns: repeat(4, 1fr); }
}

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