:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1f2421;
  --muted: #6b7370;
  --primary: #1f6f43;
  --primary-dark: #185936;
  --danger: #b3392f;
  --border: #e3e1db;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

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

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Header */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
  flex-wrap: wrap;
}
.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary);
  text-decoration: none;
  letter-spacing: -0.02em;
}
.logo img {
  width: 1.85rem;
  height: 1.85rem;
  display: block;
}
.nav {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  flex-wrap: wrap;
}
.nav-link {
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
}
.nav-link:hover { color: var(--primary); }
.inline-form { display: inline; margin: 0; }
.nav-button {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  cursor: pointer;
}

main.container { padding-top: 1.5rem; padding-bottom: 3rem; }

.page-title { font-size: 1.3rem; margin: 0 0 1rem; }

/* Listing grid - adapts to the width of the window */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}
@media (max-width: 420px) {
  .grid { grid-template-columns: 1fr; }
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  color: inherit;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
/* The title link covers the whole card, so anywhere on it leads to the listing. */
.card-link { text-decoration: none; color: inherit; }
.card-link::after {
  content: "";
  position: absolute;
  inset: 0;
}
/* Above that overlay, so the seller stays reachable. */
.card-seller {
  position: relative;
  /* Pushed to the bottom of the card and over to the right, so the row of
     cards lines its sellers up however tall each card's text runs. */
  margin-top: auto;
  padding-top: 0.35rem;
  align-self: flex-end;
  text-align: right;
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: none;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-seller:hover { color: var(--primary); text-decoration: underline; }
.card-image {
  display: block;
  aspect-ratio: 4 / 3;
  background: #edece8;
}
.card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  padding: 0.7rem 0.85rem 0.85rem;
}
.card-title {
  display: block;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-price { color: var(--primary); font-weight: 700; margin-top: 0.15rem; }

/* Listing page */
.product {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 760px) {
  .product { grid-template-columns: 1fr; }
}
.product-image img {
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}
.product-info h1 { margin: 0 0 0.5rem; font-size: 1.5rem; }
.product-price { font-size: 1.4rem; font-weight: 800; color: var(--primary); margin: 0 0 1rem; }
.product-description { white-space: pre-line; margin: 0 0 1rem; }
.product-meta { color: var(--muted); font-size: 0.85rem; }

/* Forms */
.auth-box {
  max-width: 460px;
  margin: 1rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.auth-box h1 { margin-top: 0; font-size: 1.4rem; }
.auth-box label { display: block; font-weight: 600; margin: 1rem 0 0.3rem; }
.auth-box input[type="text"],
.auth-box input[type="email"],
.auth-box input[type="number"],
.auth-box input[type="file"],
.auth-box textarea {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: var(--bg);
}
.auth-box textarea { resize: vertical; }
.auth-box .btn { margin-top: 1.25rem; width: 100%; }
.auth-box label.checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 400;
  margin: 1rem 0 0;
  cursor: pointer;
}
.auth-box label.checkbox input {
  width: auto;
  margin: 0;
  accent-color: var(--primary);
}
.pin-input {
  font-size: 1.5rem;
  letter-spacing: 0.4em;
  text-align: center;
}
.required { color: var(--danger); font-weight: 400; font-size: 0.85rem; }
.optional { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.error {
  background: #fbe9e7;
  border: 1px solid #f0c4bf;
  color: var(--danger);
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.55rem 1rem;
  border-radius: 6px;
  border: none;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.link-button {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--primary);
  cursor: pointer;
  text-decoration: underline;
}

/* Waiting state while a form is being submitted */
button.is-loading {
  cursor: progress;
  opacity: 0.85;
}
button.is-loading:disabled { cursor: progress; }
.spinner {
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  margin-right: 0.5em;
  vertical-align: -0.1em;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.5s; }
}
.link-button.danger { color: var(--danger); }
.resend-form { margin-top: 1rem; text-align: center; }

/* Panels: contact the seller, edit a listing, set a display name */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem 1.25rem;
  box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 0.5rem; font-size: 1.05rem; }
.panel label {
  display: block;
  font-weight: 600;
  margin: 0.9rem 0 0.3rem;
}
.panel label:first-of-type { margin-top: 0.75rem; }
.panel input[type="text"],
.panel input[type="number"],
.panel textarea {
  display: block;
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  line-height: 1.4;
  background: var(--bg);
}
.panel textarea { resize: vertical; }
.panel .btn { margin-top: 1rem; }
.panel .hint { margin-top: 0.5rem; }

.contact-box { margin-top: 1.5rem; }
.delete-form { margin-top: 1rem; }

/* Display name, where the field and its button sit on one line */
.name-box { margin-bottom: 1.5rem; }
.name-form {
  display: flex;
  align-items: stretch;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}
.name-form input { flex: 1 1 220px; min-width: 0; }
.name-form .btn { margin-top: 0; flex: 0 0 auto; }

.hint { color: var(--muted); font-size: 0.85rem; margin: 0.35rem 0 0; }
.notice {
  background: #e7f3ec;
  border: 1px solid #bcdcc8;
  color: var(--primary-dark);
  padding: 0.5rem 0.7rem;
  border-radius: 6px;
  margin: 0.6rem 0 0;
}
.seller { font-weight: 600; color: var(--text); }
a.seller { color: var(--primary); text-decoration: none; }
a.seller:hover { text-decoration: underline; }
.seller-count { color: var(--muted); font-size: 0.9rem; margin: -0.5rem 0 1rem; }

/* Stores */
.store-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: -0.5rem 0 1.25rem;
}
.store-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
}
.store-chip:hover { border-color: var(--primary); color: var(--primary); }
.store-chip-count { color: var(--muted); font-size: 0.8rem; }

.store-list { list-style: none; margin: 0.75rem 0 0; padding: 0; }
.store-list li {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}
.store-list li:last-child { border-bottom: 0; }
.store-list a { color: var(--primary); text-decoration: none; font-weight: 600; }
.store-list a:hover { text-decoration: underline; }
.store-list form { margin-left: auto; }
.store-list .hint { margin: 0; }

.card-store { color: var(--muted); font-size: 0.85rem; margin-top: 0.15rem; }

.panel select,
.auth-box select {
  display: block;
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: var(--bg);
}

/* "Your name: R2QTZ7  [Ändra]" above a message */
.identity { margin: 0 0 0.5rem; }
.rename { display: inline; }
.rename summary {
  display: inline;
  margin-left: 0.4rem;
  color: var(--primary);
  font-size: 0.85rem;
  cursor: pointer;
  list-style: none;
}
.rename summary::-webkit-details-marker { display: none; }
.rename summary:hover { text-decoration: underline; }
.rename[open] summary { color: var(--muted); }
.rename[open] label { margin-top: 0.6rem; }
.rename .hint { display: block; }

/* Messages */
.badge {
  display: inline-block;
  min-width: 1.25em;
  margin-left: 0.35em;
  padding: 0.05em 0.4em;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
  vertical-align: 0.1em;
}
.breadcrumb { margin: 0 0 1rem; font-size: 0.9rem; }
.breadcrumb a { color: var(--muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--primary); }

.thread-list { list-style: none; margin: 0; padding: 0; }
.thread-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow);
}
.thread-item.is-unread { border-color: var(--primary); }
.thread-link {
  display: flex;
  gap: 0.9rem;
  padding: 0.85rem;
  text-decoration: none;
  color: inherit;
  align-items: flex-start;
}
.thread-thumb {
  width: 64px;
  height: 64px;
  flex: 0 0 auto;
  object-fit: cover;
  border-radius: 6px;
  background: #edece8;
}
.thread-text { min-width: 0; }
.thread-title { display: block; font-weight: 600; }
.thread-price { color: var(--primary); font-weight: 700; margin-left: 0.5rem; }
.thread-meta { color: var(--muted); font-size: 0.85rem; margin: 0.1rem 0; display: block; }
.thread-snippet {
  display: block;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.thread-from { font-weight: 600; }

.thread-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem;
  box-shadow: var(--shadow);
}
.thread-header-link {
  display: flex;
  gap: 0.9rem;
  align-items: center;
  text-decoration: none;
  color: inherit;
}

.messages { list-style: none; margin: 1.25rem 0; padding: 0; }
.message {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
  margin-bottom: 0.75rem;
  max-width: 42rem;
}
.message.is-mine {
  background: #e7f3ec;
  border-color: #bcdcc8;
  margin-left: auto;
}
.message-body { margin: 0; white-space: pre-line; }
.message-meta { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.8rem; }

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}
.empty-state h1 { color: var(--text); }

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.25rem 0;
  color: var(--muted);
  font-size: 0.85rem;
  background: var(--surface);
}
