:root {
  --bg: #f4f4f5;
  --surface: #ffffff;
  --text: #1c1c1f;
  --muted: #6b6b74;
  --border: #d9d9de;
  --accent: #2f6f4f;
  --accent-text: #ffffff;
  --error-bg: #fdecec;
  --error-text: #8c1d1d;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17171a;
    --surface: #212126;
    --text: #ececf0;
    --muted: #a0a0aa;
    --border: #35353d;
    --accent: #4a9c72;
    --accent-text: #0d0d0f;
    --error-bg: #3a1f1f;
    --error-text: #f3b5b5;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}

.menu {
  position: relative;
  flex: none;
}

.menu summary {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.2rem;
  border-radius: 999px;
  cursor: pointer;
  /* The default triangle sits next to the face and looks like a glitch. */
  list-style: none;
}

.menu summary::-webkit-details-marker { display: none; }

.menu summary::after {
  content: "▾";
  color: var(--muted);
  font-size: 0.75rem;
}

.menu summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.menu-panel {
  position: absolute;
  top: calc(100% + 0.6rem);
  right: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.7rem;
  min-width: 12rem;
  padding: 0.9rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
}

.menu-name {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.menu-panel form { margin: 0; }
.menu-panel .primary { margin-top: 0; }

/* Shown only where the header has no room for it. Two classes deep, because
   `.button` sets a display of its own further down. */
.site-header .only-narrow { display: none; }

main {
  max-width: 44rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

/* Grids need room; reading a single listing does not. */
main.wide { max-width: 74rem; }

.tabs {
  display: flex;
  gap: 0.25rem;
  margin-right: auto;
}

.tab {
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
}

.tab:hover { background: var(--bg); }

.tab.is-active {
  color: var(--accent-text);
  background: var(--accent);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
}

h1 { margin: 0 0 0.6rem; font-size: 1.35rem; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

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

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

label { font-size: 0.85rem; font-weight: 600; }

input[type="text"] {
  width: 100%;
  padding: 0.6rem 0.7rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
}

input[type="text"]:focus-visible,
input[type="date"]:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.input-prefix {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.input-prefix span { color: var(--muted); }

.code-input {
  font-size: 1.6rem;
  letter-spacing: 0.4em;
  text-align: center;
}

button { font: inherit; cursor: pointer; }

.primary {
  margin-top: 0.5rem;
  padding: 0.65rem 1rem;
  color: var(--accent-text);
  background: var(--accent);
  border: none;
  border-radius: 7px;
  font-weight: 600;
}

.link-button {
  padding: 0;
  color: var(--accent);
  background: none;
  border: none;
  text-decoration: underline;
}

.site-header .primary {
  margin-top: 0;
  padding: 0.4rem 0.85rem;
}

.flash {
  margin: 0 0 1rem;
  padding: 0.7rem 0.9rem;
  border-radius: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.flash-error {
  background: var(--error-bg);
  color: var(--error-text);
  border-color: transparent;
}

/* --- Anzeigen --- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.filters input[type="search"] {
  flex: 1 1 12rem;
  min-width: 0;
}

.filters .primary { margin-top: 0; }

input[type="search"],
input[type="date"],
select,
textarea {
  padding: 0.6rem 0.7rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
}

textarea {
  width: 100%;
  resize: vertical;
}

.listing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 1rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.listing-card { display: flex; }

.listing-card > a {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  color: inherit;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.listing-card > a:hover { border-color: var(--accent); }

.card-media {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--bg);
}

.card-media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted);
  font-size: 0.8rem;
}

.card-badges {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.card-count {
  position: absolute;
  right: 0.5rem;
  bottom: 0.5rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
}

.card-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.7rem 0.8rem 0.8rem;
  min-width: 0;
}

.card-title {
  /* Two lines at most, so the cards keep a common rhythm. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0;
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.card-foot {
  /* Pushed down, so prices line up across a row of cards no matter how long
     the titles are — and stay put on a Gesuch, which has no price. */
  margin-top: auto;
  padding-top: 0.35rem;
}

.card-foot .price { font-size: 1.05rem; }

.card-meta {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

/* A long name must push the date out of the card, not the card out of shape. */
.card-who {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Gesichter --- */

.avatar {
  flex: none;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  object-fit: cover;
  background: var(--bg);
}

.avatar-blank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  /* Initials should not inherit a card's line height and sit off-centre. */
  line-height: 1;
}

.avatar-small {
  width: 1.35rem;
  height: 1.35rem;
  font-size: 0.6rem;
}

.avatar-big {
  width: 4.5rem;
  height: 4.5rem;
  font-size: 1.4rem;
}

.byline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: inherit;
  text-decoration: none;
}

/* The name reacts to the hover, the face stays a face. */
a.byline:hover span:not(.avatar) { text-decoration: underline; }

.profile-head {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.profile-head h1 { margin: 0; }

.profile-who p { margin: 0.1rem 0 0.6rem; }

.profile-who > :last-child { margin-bottom: 0; }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: 0.6rem;
  margin: 1rem 0 1.25rem;
}

.gallery img {
  width: 100%;
  height: 7rem;
  object-fit: cover;
  border-radius: 8px;
  background: var(--bg);
}

/* Across the whole width, and never cropped: a coat photographed upright has
   to stay a coat. The cap keeps a tall picture from filling the screen. */
.gallery-hero { grid-column: 1 / -1; }

.gallery-hero img {
  height: auto;
  max-height: 26rem;
  object-fit: contain;
}

/* --- Bild-Overlay --- */

.lightbox {
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  overflow: hidden;
}

.lightbox::backdrop { background: rgba(0, 0, 0, 0.95); }

.lightbox-image {
  display: block;
  width: 100%;
  height: 100%;
  /* The whole photo, never cropped — this is the view people came for. */
  object-fit: contain;
  padding: 3.5rem 1rem;
}

.lightbox button {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  font-size: 1.5rem;
  line-height: 1;
}

.lightbox button:hover { background: rgba(0, 0, 0, 0.8); }

.lightbox-close {
  top: 1rem;
  right: 1rem;
  font-size: 1.1rem;
}

.lightbox-step {
  top: 50%;
  transform: translateY(-50%);
}

.lightbox-prev { left: 1rem; }
.lightbox-next { right: 1rem; }

.lightbox-count {
  position: absolute;
  bottom: 1rem;
  left: 0;
  width: 100%;
  margin: 0;
  text-align: center;
  color: #fff;
  font-size: 0.85rem;
}

/* Behind an open dialog the page must not scroll away under the photo. */
html:has(dialog[open]) { overflow: hidden; }

.image-editor {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr));
  gap: 0.6rem;
  margin: 0 0 0.5rem;
  padding: 0;
  list-style: none;
}

.image-editor img,
.upload-preview img {
  width: 100%;
  height: 5rem;
  object-fit: cover;
  border-radius: 7px;
}

.upload-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr));
  gap: 0.6rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.upload-preview:empty { display: none; }

.upload-preview span {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.upload-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 5rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 7px;
}

.image-editor label {
  display: flex;
  gap: 0.3rem;
  align-items: center;
  font-weight: 400;
  font-size: 0.8rem;
}

.label-like { font-size: 0.85rem; font-weight: 600; }

.radio-row { display: flex; gap: 0.5rem; }

.radio {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  font-weight: 400;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
}

.radio:has(> input:checked) { border-color: var(--accent); }

/* A Gesuch has nothing to sell, so the question does not come up. */
.stack:has(input[name="kind"][value="suche"]:checked) .price-field { display: none; }

.price-field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.price-modes {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.4rem;
}

/* Amount and VB sit inside the button, so the row reads as one control. */
.price-amount { gap: 0.55rem; }

.price-amount:has(input[name="price_mode"]:checked) { border-color: var(--accent); }

.price-pick {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 400;
  cursor: pointer;
}

.price-amount input[type="text"] {
  width: 5.5rem;
  padding: 0.3rem 0.5rem;
  background: var(--surface);
}

.price-vb {
  padding-left: 0.55rem;
  border-left: 1px solid var(--border);
}

input[type="file"] { font: inherit; color: var(--muted); }

.listing-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.badge {
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent);
}

.badge-suche { background: #5b6bb5; color: #fff; }

.category { font-size: 0.8rem; color: var(--muted); }

/* Sits on top of a photo, so it needs a background of its own. */
.status {
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
}

.status-active { color: var(--accent); }

.price { font-weight: 600; }
/* Free is the good news on the card, so it keeps the weight and the colour. */
.price-free { color: var(--accent); }

.price-none { font-weight: 400; color: var(--muted); }

.detail-price { margin: 0.2rem 0 1rem; font-size: 1.1rem; }

.description > :first-child { margin-top: 0; }
.description > :last-child { margin-bottom: 0; }

.description ul,
.description ol { padding-left: 1.3rem; }

.description blockquote {
  margin: 0.8rem 0;
  padding-left: 0.8rem;
  border-left: 3px solid var(--border);
  color: var(--muted);
}

.description code {
  padding: 0.05rem 0.3rem;
  font-size: 0.9em;
  background: var(--bg);
  border-radius: 4px;
}

.description a { overflow-wrap: anywhere; }

.meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 1rem;
  margin: 1.25rem 0;
  font-size: 0.9rem;
}

.meta dt { color: var(--muted); }
.meta dd { margin: 0; }

.button {
  display: inline-block;
  color: var(--accent-text);
  text-decoration: none;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
}

.button-row form { margin: 0; }

.owner-actions { margin-top: 1rem; }
.owner-actions h2 { margin: 0 0 0.75rem; font-size: 0.95rem; }

.danger { color: var(--error-text); }

.field-error {
  margin: -0.25rem 0 0.25rem;
  font-size: 0.85rem;
  color: var(--error-text);
}

.empty { text-align: center; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.section { margin-bottom: 2.25rem; }

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.section-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.section-more { font-size: 0.9rem; }

/* --- Admin --- */

.table-scroll { overflow-x: auto; }

.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.admin-table th,
.admin-table td {
  padding: 0.6rem 0.8rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}

.admin-table th {
  font-size: 0.8rem;
  color: var(--muted);
}

.admin-table tr:last-child td { border-bottom: none; }

.admin-table td span.small { display: block; }

/* Blocked or hidden rows are still there, just visibly out of play. */
.admin-table tr.is-hidden td:not(:last-child) { opacity: 0.55; }

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.row-actions form { margin: 0; }

/* One line, whatever the site is called: the brand gives way first, and what
   does not fit at all moves into the menu. */
@media (max-width: 48rem) {
  .hide-narrow { display: none; }
  .site-header .only-narrow { display: inline-block; }

  .site-header {
    flex-wrap: nowrap;
    gap: 0.5rem;
    padding: 0.6rem 0.9rem;
  }

  .brand {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tabs { gap: 0.15rem; }

  .tab {
    padding: 0.35rem 0.65rem;
    font-size: 0.9rem;
  }
}

/* On the smallest phones the tabs give a little back, so the brand keeps more
   than its first syllable. */
@media (max-width: 26rem) {
  .brand { font-size: 0.95rem; }

  .tab {
    padding: 0.3rem 0.45rem;
    font-size: 0.85rem;
  }
}

@media (max-width: 32rem) {
  main { padding: 1rem 0.9rem 3rem; }

  /* Two per row keeps the shop feel on a phone; auto-fill would drop to one. */
  .listing-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.7rem;
  }

  .card-text { padding: 0.6rem 0.65rem 0.7rem; }
  .card-title { font-size: 0.92rem; }
  .card-text .price { font-size: 0.95rem; }
}
