/* Rama Farm Market — light, farmer-friendly theme */
:root {
  --field: #2f5d34;      /* deep field green */
  --leaf: #4f8a3c;       /* fresh leaf */
  --leaf-soft: #e6f0dc;
  --wheat: #e2b54d;      /* harvest wheat */
  --wheat-soft: #fbf1d6;
  --soil: #6b4f2a;       /* soil brown */
  --cream: #faf6ec;      /* page background */
  --card: #ffffff;
  --ink: #23301f;
  --muted: #6c7464;
  --line: #e4ddca;
  --danger: #b3412e;
  --danger-soft: #f8e3df;
  --info-soft: #e3eef7;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60, 50, 20, .06), 0 4px 14px rgba(60, 50, 20, .07);
  --nav-h: 64px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  background: var(--cream);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
img, video { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--field); }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--field);
  color: #fff;
  padding: 10px 16px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; flex: 1; min-width: 0; }
.brand svg { flex: none; }
.brand small { display: block; font-weight: 400; font-size: .75rem; opacity: .85; }
.icon-btn {
  background: rgba(255,255,255,.12); border: 0; color: #fff;
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-grid; place-items: center; cursor: pointer;
}
.icon-btn.text { width: auto; border-radius: 20px; padding: 0 14px; font-weight: 600; font-size: .85rem; }
.icon-btn:active { background: rgba(255,255,255,.25); }

/* rolling fields under header */
.fields-strip { height: 22px; background: var(--field); }
.fields-strip svg { width: 100%; height: 22px; display: block; }

/* ---------- layout ---------- */
.container { max-width: 960px; margin: 0 auto; padding: 12px 16px calc(var(--nav-h) + 24px); }
.section-title { font-size: 1.15rem; margin: 18px 0 10px; color: var(--soil); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) { .grid-2:not(.keep) { grid-template-columns: 1fr; } }

/* ---------- bottom navigation ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  height: var(--nav-h);
  background: #fff; border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav button {
  background: none; border: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .75rem; color: var(--muted);
}
.bottom-nav button.active { color: var(--field); font-weight: 700; }
.bottom-nav .sell-btn span.ico {
  background: var(--wheat); color: var(--soil); border-radius: 50%;
  width: 36px; height: 36px; display: grid; place-items: center; font-size: 1.4rem; font-weight: 700;
}

/* ---------- cards ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; border: 1px solid #efe8d6;
}
.card + .card { margin-top: 12px; }

.posts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.post-card {
  background: var(--card); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); cursor: pointer; border: 1px solid #efe8d6;
  display: flex; flex-direction: column;
}
.post-card .thumb { aspect-ratio: 4/3; background: var(--leaf-soft); position: relative; display: grid; place-items: center; font-size: 2.4rem; }
.post-card .thumb img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.post-card .thumb .has-video { position: absolute; right: 6px; bottom: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: .7rem; padding: 2px 6px; border-radius: 8px; }
.post-card .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 2px; }
.post-card .title { font-weight: 700; line-height: 1.25; }
.post-card .meta { font-size: .8rem; color: var(--muted); }

.price-row { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 4px; }
.price-row .off { margin-left: 0; }
.price { font-weight: 800; color: var(--field); font-size: 1.05rem; }
.price s { color: var(--muted); font-weight: 400; font-size: .85rem; margin-left: 6px; }
.off { white-space: nowrap; background: var(--wheat-soft); color: var(--soil); font-size: .7rem; font-weight: 700; padding: 1px 6px; border-radius: 6px; margin-left: 4px; }

.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--leaf-soft); color: var(--field); }
.badge.pending { background: var(--wheat-soft); color: #8a6212; }
.badge.rejected, .badge.sold { background: var(--danger-soft); color: var(--danger); }
.badge.expired { background: #eee; color: #666; }
.badge.cat { background: var(--info-soft); color: #2b5876; }

/* ad banner */
.ad-strip { display: grid; grid-auto-flow: column; grid-auto-columns: 100%; overflow-x: auto; scroll-snap-type: x mandatory; gap: 12px; margin-bottom: 12px; scrollbar-width: none; }
.ad-strip::-webkit-scrollbar { display: none; }
.ad {
  scroll-snap-align: start; border-radius: var(--radius); overflow: hidden;
  background: linear-gradient(120deg, var(--wheat-soft), #fff); border: 1px solid #f0dfb0;
  display: flex; gap: 12px; align-items: center; padding: 10px; text-decoration: none; color: inherit;
}
.ad img { width: 96px; height: 72px; object-fit: cover; border-radius: 10px; flex: none; }
.ad .ad-label { font-size: .65rem; font-weight: 700; letter-spacing: .05em; color: var(--soil); text-transform: uppercase; }
.ad.inline { margin: 0; grid-column: 1 / -1; }

/* ---------- filters ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 7px 14px; cursor: pointer; font-size: .9rem; white-space: nowrap;
}
.chip.active { background: var(--field); color: #fff; border-color: var(--field); }
.filter-row { display: flex; gap: 8px; margin: 6px 0 12px; }
.filter-row > * { flex: 1; min-width: 0; }

/* ---------- forms ---------- */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: .85rem; font-weight: 600; color: var(--soil); margin-bottom: 4px; }
input[type=text], input[type=number], input[type=tel], input[type=password], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; outline: none; min-height: 46px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--leaf); box-shadow: 0 0 0 3px var(--leaf-soft); }
.input-unit { display: flex; gap: 8px; }
.input-unit > input { flex: 2; }
.input-unit > select { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; min-height: 46px; border-radius: 10px; border: 1px solid transparent;
  background: var(--field); color: #fff; font-weight: 700; cursor: pointer; text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.secondary { background: #fff; color: var(--field); border-color: var(--field); }
.btn.wheat { background: var(--wheat); color: var(--soil); }
.btn.danger { background: var(--danger); }
.btn.ghost { background: transparent; color: var(--field); border-color: var(--line); }
.btn.sm { padding: 6px 12px; min-height: 36px; font-size: .85rem; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--leaf-soft); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: transparent; padding: 10px; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--field); }
.seg button.active { background: #fff; box-shadow: var(--shadow); }

.cat-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.cat-pick button {
  border: 2px solid var(--line); background: #fff; border-radius: var(--radius);
  padding: 16px 6px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; font-weight: 700;
}
.cat-pick button .em { font-size: 2rem; }
.cat-pick button.active { border-color: var(--leaf); background: var(--leaf-soft); }

/* media picker */
.media-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.media-slot {
  aspect-ratio: 1; border: 2px dashed var(--line); border-radius: 10px; background: #fff;
  display: grid; place-items: center; position: relative; overflow: hidden; cursor: pointer; color: var(--muted); font-size: .8rem; text-align: center;
}
.media-slot img, .media-slot video { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.media-slot .rm {
  position: absolute; top: 4px; right: 4px; z-index: 2; width: 26px; height: 26px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.65); color: #fff; cursor: pointer; line-height: 1;
}
.progress { height: 8px; background: var(--leaf-soft); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--leaf); transition: width .2s; }

/* ---------- auth screen ---------- */
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; }
.auth-hero {
  background: var(--field); color: #fff; text-align: center; padding: 28px 16px 0;
}
.auth-hero h1 { margin: 10px 0 2px; font-size: 1.5rem; }
.auth-hero p { margin: 0 0 8px; opacity: .9; }
.auth-hero svg.hills { width: 100%; height: 60px; display: block; }
.auth-box { width: 100%; max-width: 440px; margin: -10px auto 30px; padding: 0 16px; }
.auth-foot { text-align: center; margin-top: 16px; font-size: .9rem; }

/* ---------- dialog / sheet ---------- */
dialog.sheet {
  border: 0; padding: 0; width: 100%; max-width: 640px; max-height: 92vh;
  border-radius: 18px 18px 0 0; margin: auto auto 0; background: var(--cream);
}
@media (min-width: 700px) { dialog.sheet { border-radius: 18px; margin: auto; } }
dialog.sheet::backdrop { background: rgba(20, 25, 15, .55); }
.sheet-head { position: sticky; top: 0; z-index: 2; background: var(--cream); display: flex; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.sheet-head h3 { margin: 0; font-size: 1.05rem; flex: 1; }
.sheet-head .close { background: #fff; border: 1px solid var(--line); width: 38px; height: 38px; border-radius: 50%; cursor: pointer; font-size: 1.1rem; }
.sheet-body { padding: 14px 16px 20px; }

.gallery { display: grid; grid-auto-flow: column; grid-auto-columns: 100%; overflow-x: auto; scroll-snap-type: x mandatory; border-radius: var(--radius); background: #000; }
.gallery > * { scroll-snap-align: center; width: 100%; aspect-ratio: 4/3; object-fit: contain; background: #000; }
.gallery-dots { text-align: center; font-size: .8rem; color: var(--muted); margin-top: 4px; }

.spec { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.spec div { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.spec small { display: block; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; }
.spec b { font-weight: 700; }

.seller { display: flex; align-items: center; gap: 12px; }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--wheat); color: var(--soil); display: grid; place-items: center; font-weight: 800; flex: none; }

/* ---------- list rows ---------- */
.list-item { display: flex; gap: 12px; align-items: flex-start; }
.list-item .lthumb { width: 84px; height: 84px; border-radius: 10px; object-fit: cover; background: var(--leaf-soft); flex: none; display: grid; place-items: center; font-size: 2rem; overflow: hidden; }
.list-item .lthumb img { width: 100%; height: 100%; object-fit: cover; }
.list-item .lbody { flex: 1; min-width: 0; }
.list-item .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 600; font-size: .9rem; }
.switch input { width: 44px; height: 26px; appearance: none; background: #ccc; border-radius: 99px; position: relative; cursor: pointer; transition: background .2s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: left .2s; }
.switch input:checked { background: var(--leaf); }
.switch input:checked::after { left: 21px; }

/* ---------- misc ---------- */
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .em { font-size: 2.6rem; }
.notice { background: var(--wheat-soft); border: 1px solid #f0dfb0; color: #6b4f12; border-radius: 12px; padding: 10px 12px; font-size: .9rem; }
.error-text { color: var(--danger); font-size: .9rem; min-height: 1.2em; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 100;
  max-width: calc(100% - 32px); box-shadow: var(--shadow); font-size: .95rem;
}
.spinner { width: 28px; height: 28px; border: 3px solid var(--leaf-soft); border-top-color: var(--leaf); border-radius: 50%; animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-screen { min-height: 100vh; display: grid; place-items: center; }
hr.soft { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

/* ---------- admin ---------- */
.admin-tabs { display: flex; gap: 6px; overflow-x: auto; background: #fff; padding: 8px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 60px; z-index: 10; scrollbar-width: none; }
.admin-tabs button { flex: none; border: 0; background: transparent; padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; color: var(--muted); }
.admin-tabs button.active { background: var(--leaf-soft); color: var(--field); }
.admin-tabs .count { background: var(--wheat); color: var(--soil); border-radius: 99px; padding: 0 7px; font-size: .75rem; margin-left: 4px; }
.admin .container { padding-bottom: 40px; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stat b { font-size: 1.25rem; color: var(--field); display: block; }
.stat span { font-size: .8rem; color: var(--muted); }
.thumbs { display: flex; gap: 6px; overflow-x: auto; margin: 8px 0; }
.thumbs img, .thumbs video { width: 92px; height: 70px; object-fit: cover; border-radius: 8px; flex: none; cursor: pointer; background: #000; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 4px 12px; font-size: .9rem; }
.kv small { color: var(--muted); }
