:root {
  --bg: #f7f7f5;
  --card: #ffffff;
  --ink: #1d1d1f;
  --muted: #6b6b70;
  --line: #e3e3df;
  --accent: #2f6f4f;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --radius: 12px;
  --max: 1560px;
}

* { box-sizing: border-box; }

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

a { color: var(--accent); }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.2rem; text-decoration: none; color: var(--ink); }
.admin-nav a { margin-left: 16px; font-size: .92rem; }

/* "Load my offers" dropdown in the header */
.load-offers { position: relative; }
.load-offers summary {
  cursor: pointer; list-style: none; font-size: .9rem; color: var(--accent);
  padding: 7px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.load-offers summary::-webkit-details-marker { display: none; }
.load-offers[open] summary { border-color: var(--accent); }
.lo-pop {
  position: absolute; right: 0; top: calc(100% + 6px); width: 260px; z-index: 50;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.lo-hint { margin: 0 0 8px; font-size: .82rem; color: var(--muted); }
.lo-pop form { display: flex; gap: 6px; align-items: center; }
.lo-pop input { margin: 0; }
.link-muted { border: none; background: none; color: var(--muted); cursor: pointer; padding: 8px 0 0; font-size: .82rem; }

.container { max-width: var(--max); margin: 0 auto; padding: 24px 40px 60px; }

.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: .85rem;
  padding: 30px 0;
}

.page-title { margin-top: 0; }
.empty { color: var(--muted); }
.back { display: inline-block; margin-bottom: 16px; text-decoration: none; }

/* Master-detail browse layout */
.browse { display: flex; gap: 24px; align-items: flex-start; }
.item-list { flex: 1 1 auto; min-width: 0; }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.list-head .page-title { margin: 0; }
.sort-control { font-size: .9rem; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.sort-control select { width: auto; margin: 0; padding: 6px 8px; }
.detail-panel {
  flex: 0 0 46%;
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 110px);
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
}
.panel-placeholder { color: var(--muted); display: flex; height: 200px; align-items: center; justify-content: center; }

@media (max-width: 899px) {
  .detail-panel { display: none; }
  .browse.has-open .item-list { display: none; }
  .browse.has-open .detail-panel {
    display: block; flex-basis: 100%;
    position: static; max-height: none; border: none; padding: 0;
  }
}

/* Horizontal item rows */
.row-card {
  display: flex; gap: 14px; align-items: center;
  padding: 12px; margin-bottom: 12px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); text-decoration: none; color: inherit;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.row-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.06); }
.row-card.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(47,111,79,.18); }
.row-card.is-sold { opacity: .6; }
.row-card.offered { border-left: 4px solid var(--accent); background: #f1f8f3; }
.row-card.free { border-left: 4px solid #c9871f; background: #fdf6e9; }
.free-price { color: #b5740f; font-weight: 700; }
.row-imgs { display: flex; gap: 6px; flex: 0 0 auto; }
.row-imgs img { width: 74px; height: 74px; object-fit: contain; border-radius: 8px; background: #eee; }
.row-imgs .no-img {
  width: 74px; height: 74px; display: flex; align-items: center; justify-content: center;
  border: 1px dashed var(--line); border-radius: 8px; color: var(--muted); font-size: .7rem;
}
.row-body { flex: 1 1 auto; min-width: 0; }
.row-title { font-size: 1.05rem; margin: 0 0 5px; }
.row-desc {
  margin: 0; color: var(--muted); font-size: .9rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.row-meta { flex: 0 0 auto; text-align: right; white-space: nowrap; }
.row-price { font-weight: 600; display: block; }
.was { color: var(--muted); text-decoration: line-through; font-weight: 400; font-size: .85em; margin-right: 4px; }
.discount-badge {
  display: inline-block; margin-top: 4px;
  background: #fde7e7; color: var(--danger); font-size: .72rem; font-weight: 600;
  padding: 1px 7px; border-radius: 6px;
}
.your-offer-tag { display: block; font-size: .8rem; color: var(--accent); margin-top: 4px; }
.badge-sold {
  display: inline-block; vertical-align: middle;
  background: var(--danger); color: #fff; font-size: .68rem;
  padding: 2px 7px; border-radius: 6px; text-transform: uppercase; letter-spacing: .04em;
}

/* Detail panel contents */
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.detail-head h1 { margin: 0 0 6px; font-size: 1.4rem; }
.panel-close {
  border: none; background: none; font-size: 1.6rem; line-height: 1;
  color: var(--muted); cursor: pointer; padding: 0 4px;
}
.ask { font-size: 1.1rem; }
.your-offer { color: var(--accent); font-size: .95rem; }
.gallery-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 16px 0 8px; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.thumbs img { width: 100%; aspect-ratio: 1; object-fit: contain; border-radius: 8px; border: 1px solid var(--line); display: block; cursor: zoom-in; background: #eee; }
.description { white-space: normal; margin: 16px 0; }
.buy-new { color: var(--muted); font-size: .95rem; }
.sold-note { color: var(--danger); font-weight: 600; }
.confirm-inline { background: #e7f4ec; border: 1px solid #bfe3cd; border-radius: var(--radius); padding: 16px 18px; }
.confirm-inline h3 { margin-top: 0; }

.actions { display: grid; gap: 12px; margin-top: 16px; }
.offer-form, .buy-form {
  background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px;
}
.offer-form h3, .buy-form h3 { margin: 0 0 6px; font-size: 1rem; }
/* Compact form controls inside the detail panel */
.detail label { margin: 7px 0; font-size: .85rem; }
.detail input, .detail textarea { padding: 7px 9px; font-size: .92rem; margin-top: 3px; }
.detail textarea { min-height: 38px; }
.buy-form p { margin: 4px 0 8px; font-size: .9rem; }
/* Offer amount beside email, etc. */
.field-row { display: flex; gap: 10px; }
.field-row label { flex: 1 1 0; min-width: 0; }
.field-row label:first-child { flex: 0 0 38%; }
/* Message boxes: only resize vertically, with a sensible minimum. */
textarea { resize: vertical; min-height: 38px; }

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.88);
  display: flex; align-items: center; justify-content: center;
}
.lightbox[hidden] { display: none; }
.lb-fig { margin: 0; max-width: 92vw; max-height: 86vh; text-align: center; }
.lb-img { max-width: 92vw; max-height: 78vh; border-radius: 8px; display: block; margin: 0 auto; cursor: zoom-in; transition: transform .15s ease; }
.lb-img.zoomed { cursor: zoom-out; }
.lb-caption { color: #ddd; font-size: .85rem; margin-top: 10px; }
.lb-close, .lb-prev, .lb-next {
  position: absolute; background: rgba(255,255,255,.12); color: #fff;
  border: none; cursor: pointer; border-radius: 8px;
}
.lb-close { top: 18px; right: 22px; font-size: 1.6rem; width: 44px; height: 44px; }
.lb-prev, .lb-next { top: 50%; transform: translateY(-50%); font-size: 2rem; width: 52px; height: 64px; }
.lb-prev { left: 18px; }
.lb-next { right: 18px; }
.lb-count { position: absolute; bottom: 18px; left: 0; right: 0; text-align: center; color: #ddd; font-size: .85rem; }

label { display: block; margin: 10px 0; font-size: .92rem; }
input, textarea, select {
  width: 100%; margin-top: 4px; padding: 9px 10px;
  border: 1px solid var(--line); border-radius: 8px; font-size: 1rem;
  font-family: inherit; background: #fff;
}
button {
  cursor: pointer; border: 1px solid var(--line); background: #fff;
  padding: 9px 16px; border-radius: 8px; font-size: .95rem; font-family: inherit;
}
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.link-danger { border: none; background: none; color: var(--danger); padding: 4px; }

.form-error { color: var(--danger); background: #fdecea; border: 1px solid #f6c9c5; padding: 10px 12px; border-radius: 8px; }
.notice { color: #1d5b3a; background: #e7f4ec; border: 1px solid #bfe3cd; padding: 10px 12px; border-radius: 8px; }

/* Confirmation / login */
.confirm, .login-box { max-width: 480px; margin: 20px auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; }
.button { display: inline-block; margin-top: 14px; padding: 9px 16px; background: var(--accent); color: #fff; border-radius: 8px; text-decoration: none; }

/* Admin */
.admin-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.admin-table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.admin-table th, .admin-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: .92rem; }
.admin-table th { background: #fafafa; font-weight: 600; }
.admin-table tr:last-child td { border-bottom: none; }
.buy-now-row { background: #fff8e6; }
.winner-row { background: #e7f4ec; }
.winner-row td { font-weight: 500; }
.preview-toggle { display: flex; align-items: center; gap: 6px; font-size: .82rem; margin: 6px 0 0; color: var(--ink); }
.preview-toggle input { width: auto; margin: 0; }

/* Inline discount control on the dashboard */
.discount-form { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.discount-form select, .discount-form input { width: auto; margin: 0; padding: 5px 6px; font-size: .82rem; }
.discount-form input { width: 70px; }
.discount-form button { padding: 5px 10px; font-size: .82rem; }
.owner-tag { font-size: .82rem; color: var(--muted); }

/* Collapsible long messages (bid lists) */
.msg-cell { max-width: 360px; }
.msg-clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; word-break: break-word; }
.msg-clamp.expanded { -webkit-line-clamp: unset; }
.msg-toggle { border: none; background: none; color: var(--accent); cursor: pointer; padding: 2px 0; font-size: .82rem; }
.row-actions a { margin-right: 10px; }
.muted { color: var(--muted); }
.pill { padding: 2px 9px; border-radius: 99px; font-size: .8rem; }
.pill.available { background: #e7f4ec; color: #1d5b3a; }
.pill.sold { background: #fdecea; color: var(--danger); }

.item-form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 600px) { .item-form .row { grid-template-columns: 1fr; } }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 14px 0; }
legend { padding: 0 6px; color: var(--muted); font-size: .9rem; }
.admin-thumbs { margin-top: 12px; }
.admin-thumb { position: relative; cursor: grab; }
.admin-thumb.dragging { opacity: .45; }
.admin-thumb.drop-target { outline: 2px dashed var(--accent); outline-offset: 2px; }
.admin-thumb img { cursor: grab; -webkit-user-drag: none; user-select: none; }
.admin-thumb .pos-num {
  position: absolute; top: 4px; left: 4px; z-index: 1;
  background: rgba(0,0,0,.62); color: #fff; font-size: .72rem; line-height: 1;
  padding: 3px 6px; border-radius: 10px; pointer-events: none;
}
.admin-thumb .img-type { display: block; font-size: .78rem; color: var(--muted); margin-top: 4px; }
.move-row { display: flex; gap: 6px; margin-top: 4px; }
.move-btn {
  flex: 1 1 auto; padding: 2px 0; font-size: .9rem; line-height: 1; cursor: pointer;
  border: 1px solid var(--line); border-radius: 6px; background: #fff;
}
.move-btn:hover { background: #f3f3f3; }
.move-btn:disabled { opacity: .35; cursor: default; }
#previewHint.flash { color: var(--danger); font-weight: 600; }
