/* ==========================================================================
   Muster-Dokumentation – Gestaltung
   Farben zentral hier oben ändern.
   ========================================================================== */
:root {
  /* HCE-Grün aus dem Logo */
  --brand: #7fcc28;
  --primary: #7fcc28;        /* Buttons, Markierungen */
  --primary-dark: #72b922;   /* Button beim Drüberfahren */
  --on-primary: #1f2a08;     /* Schrift auf grünen Buttons */
  --primary-text: #4e7f12;   /* grüne Schrift auf Weiß (gut lesbar) */
  --primary-soft: #eff6df;
  --bg: #f5f7f0;
  --surface: #ffffff;
  --text: #393536;
  --muted: #676d68;
  --border: #dfe3da;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --amber: #9a6700;
  --amber-soft: #fff4d6;
  --blue: #1d5fa8;
  --blue-soft: #e5effa;
  --green: #4d730b;
  --green-soft: #eff6df;
  --green-border: #d4e8a6;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(20, 28, 10, .06), 0 2px 8px rgba(20, 28, 10, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 var(--font);
  padding-bottom: env(safe-area-inset-bottom);
}
img { max-width: 100%; display: block; }
main { overflow-x: clip; }
a { color: var(--primary-text); }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 1rem; }
h3 { font-size: 1rem; margin: 0; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.inline { display: inline; margin: 0; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; opacity: 0; overflow: hidden; clip: rect(0 0 0 0); }
.icon { width: 1.15em; height: 1.15em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* ---------- Kopfzeile ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem 1rem; padding-top: max(.6rem, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
  border-top: 4px solid var(--brand);
}
.brand { display: flex; align-items: center; gap: .75rem; text-decoration: none; color: var(--text); font-weight: 700; white-space: nowrap; }
.brand-logo { height: 38px; width: auto; }
.brand-divider { width: 1px; height: 28px; background: var(--border); }
.brand-name { color: var(--muted); font-weight: 600; font-size: .98rem; }
.mainnav { display: flex; align-items: center; gap: .15rem; }
.mainnav a, .navbtn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .5rem .7rem; border-radius: var(--radius-sm);
  color: var(--muted); text-decoration: none; font: inherit; font-size: .95rem;
  background: none; border: 0; cursor: pointer;
}
.mainnav a:hover, .navbtn:hover { background: var(--bg); color: var(--text); }
.mainnav a.is-active { background: var(--primary-soft); color: var(--primary-text); font-weight: 600; }

/* ---------- Seitenaufbau ---------- */
.container { max-width: 1200px; margin: 0 auto; padding: 1.25rem 1rem 6rem; }
.container.narrow { max-width: 760px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.backlink { display: inline-flex; align-items: center; gap: .3rem; color: var(--muted); text-decoration: none; font-size: .9rem; margin-bottom: .35rem; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1rem;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.card-head h2 { margin: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: 44px; padding: .55rem 1rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: .95rem; text-decoration: none; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn-small { min-height: 36px; padding: .35rem .7rem; font-size: .875rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); cursor: pointer;
}
.iconbtn:disabled { opacity: .3; cursor: default; }

/* ---------- Formulare ---------- */
.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1.1rem; min-width: 0; }
.field > span, .field > label { font-weight: 600; font-size: .95rem; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=date], input[type=number], select, textarea {
  width: 100%; min-height: 46px; padding: .6rem .8rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; color: var(--text);
  font: inherit; font-size: 16px; /* 16px verhindert Zoom auf dem iPhone */
}
textarea { min-height: 120px; resize: vertical; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2366706b' stroke-width='2'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .85rem center; padding-right: 2.2rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.error { color: var(--danger); font-weight: 600; }
.req { color: var(--danger); }
.with-unit { display: flex; align-items: center; gap: .5rem; }
.with-unit input { max-width: 200px; }
.unit { color: var(--muted); font-weight: 600; }
.new-option { margin-top: .5rem; border-style: dashed !important; }
.check { display: flex; align-items: flex-start; gap: .55rem; cursor: pointer; font-weight: 500; }
.check input { width: 20px; height: 20px; margin: .15rem 0 0; accent-color: var(--primary); flex-shrink: 0; }
.checks { display: flex; flex-direction: column; gap: .7rem; margin-bottom: 1.1rem; }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 1rem; }
.field-end { justify-content: flex-end; }
.field-check { justify-content: center; }
.form-actions { display: flex; justify-content: flex-end; gap: .75rem; }
.form-actions.sticky {
  position: sticky; bottom: 0; z-index: 10; margin: 0 -1rem; padding: .75rem 1rem calc(.75rem + env(safe-area-inset-bottom));
  background: rgba(245, 247, 240, .92); backdrop-filter: blur(8px); border-top: 1px solid var(--border);
}
.form-actions .btn-primary { flex: 1; max-width: 320px; }
.step { display: flex; align-items: center; gap: .6rem; }
.step span { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: var(--on-primary); font-size: .9rem; font-weight: 700; }
.copyrow { display: flex; gap: .5rem; margin-top: .5rem; }

/* ---------- Hinweise ---------- */
.alert { padding: .85rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; border: 1px solid transparent; }
.alert p { margin: 0; }
.alert-success { background: var(--green-soft); color: var(--green); border-color: var(--green-border); }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: #f5c2bd; }
.alert-warning { background: var(--amber-soft); color: var(--amber); border-color: #f1d98c; }
.alert-info { background: var(--blue-soft); color: #173f6d; border-color: #c3d8f0; }

/* ---------- Abzeichen ---------- */
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .4rem; }
.chip, .badge {
  display: inline-flex; align-items: center; padding: .15rem .6rem; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--border); color: var(--text); font-size: .8rem; font-weight: 600; line-height: 1.5;
}
.chip.green, .badge.green { background: var(--green-soft); border-color: var(--green-border); color: var(--green); }
.chip.red, .badge.red { background: var(--danger-soft); border-color: #f5c2bd; color: var(--danger); }
.chip.amber, .badge.amber { background: var(--amber-soft); border-color: #f1d98c; color: var(--amber); }
.chip.blue, .badge.blue { background: var(--blue-soft); border-color: #c3d8f0; color: var(--blue); }
.muted-chip { color: var(--muted); font-weight: 500; }

/* ---------- Anmeldung ---------- */
body.bare { background: linear-gradient(160deg, #e9f4d2 0%, #f5f7f0 55%); }
.auth { min-height: 85vh; display: flex; align-items: center; justify-content: center; }
.auth-card { width: 100%; max-width: 420px; padding: 2rem 1.5rem; }
.auth-card h1 { text-align: center; }
.auth-card > p.muted { text-align: center; }
.auth-logo { margin: 0 auto 1.25rem; width: 190px; height: auto; }

/* ---------- Übersicht / Filter ---------- */
.filters { padding: 1rem; }
.searchrow { display: flex; gap: .5rem; }
.search { position: relative; flex: 1; display: flex; align-items: center; }
.search .icon { position: absolute; left: .8rem; color: var(--muted); }
.search input { padding-left: 2.4rem; }
.filter-panel { margin-top: .75rem; }
.filter-panel summary { cursor: pointer; display: inline-flex; align-items: center; gap: .45rem; font-weight: 600; color: var(--muted); padding: .35rem 0; list-style: none; }
.filter-panel summary::-webkit-details-marker { display: none; }
.filter-panel[open] summary { color: var(--text); margin-bottom: .75rem; }
.filter-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 1rem; }
.filter-grid .field { margin-bottom: .85rem; }
.range { display: flex; align-items: center; gap: .4rem; }
.range input { min-width: 0; flex: 1; }
input[type=date] { min-width: 0; -webkit-appearance: none; appearance: none; }
.filter-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .85rem; }
.sample-card {
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  text-decoration: none; color: inherit; transition: transform .12s, box-shadow .12s;
}
.sample-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(16, 24, 20, .1); }
.sample-card .thumb { aspect-ratio: 4 / 3; background: var(--bg); }
.sample-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.sample-card .body { padding: .75rem .85rem .85rem; display: flex; flex-direction: column; flex: 1; }
.sample-card h3 { font-size: .98rem; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sample-card .meta { margin: auto 0 0; padding-top: .5rem; font-size: .78rem; color: var(--muted); }
.nophoto { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: .5rem; color: #b7bfba; }
.nophoto .icon { width: 2.2rem; height: 2.2rem; }
.nophoto.big { aspect-ratio: 4 / 3; background: var(--bg); border-radius: var(--radius-sm); }
.empty { text-align: center; padding: 3rem 1rem; }
.empty > .icon { width: 3rem; height: 3rem; color: #b7bfba; margin-bottom: .5rem; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 1.5rem; }
.fab {
  position: fixed; right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 15;
  width: 58px; height: 58px; border-radius: 50%; background: var(--primary); color: var(--on-primary);
  display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 18px rgba(127, 204, 40, .45);
}
.fab .icon { width: 1.6rem; height: 1.6rem; }

/* ---------- Fotos im Formular ---------- */
.photo-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: .75rem; }
.photo-btn { min-height: 56px; position: relative; }
.photo-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: .5rem; margin-bottom: .6rem; }
.photo-list:empty { display: none; }
.photo-item { position: relative; border-radius: var(--radius-sm); overflow: hidden; background: var(--bg); aspect-ratio: 1; display: block; }
.photo-item img { width: 100%; height: 100%; object-fit: cover; }
.photo-item .remove {
  position: absolute; left: 0; right: 0; bottom: 0; padding: .3rem .4rem; font-size: .78rem; font-weight: 600;
  background: rgba(0, 0, 0, .55); color: #fff; display: flex; gap: .3rem; align-items: center; cursor: pointer;
}
.photo-item .x {
  position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%;
  border: 0; background: rgba(0, 0, 0, .6); color: #fff; font-size: 18px; line-height: 1; cursor: pointer;
}
.photo-item.processing { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: .8rem; }

/* ---------- Detailansicht ---------- */
.detail { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.detail .card { margin-bottom: 0; }
.detail-info { display: flex; flex-direction: column; gap: 1rem; }
.detail-media { padding: .75rem; align-self: start; }
.main-photo img { width: 100%; border-radius: var(--radius-sm); max-height: 70vh; object-fit: contain; background: var(--bg); }
.thumbs { display: flex; gap: .5rem; margin-top: .6rem; overflow-x: auto; }
.thumb-btn { padding: 0; border: 2px solid transparent; border-radius: 8px; overflow: hidden; width: 64px; height: 64px; flex-shrink: 0; cursor: pointer; background: none; }
.thumb-btn img { width: 100%; height: 100%; object-fit: cover; }
.thumb-btn.is-active { border-color: var(--primary); }
.facts { margin: 0; display: grid; grid-template-columns: 1fr; }
.facts > div { display: grid; grid-template-columns: minmax(110px, 40%) 1fr; gap: .75rem; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.facts > div:last-child { border-bottom: 0; }
.facts dt { color: var(--muted); font-weight: 500; }
.facts dd { margin: 0; font-weight: 600; word-break: break-word; }
.longtext { white-space: normal; margin: 0; }
.meta-card p { margin: 0 0 .35rem; font-size: .9rem; color: var(--muted); }
.meta-card form { margin-top: .75rem; }

/* ---------- Admin-Listen ---------- */
.qlist, .optlist, .userlist { list-style: none; margin: 0; padding: 0; }
.qlist li, .optlist li, .userlist li { display: flex; align-items: center; gap: .75rem; padding: .75rem 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.qlist li:last-child, .optlist li:last-child, .userlist li:last-child { border-bottom: 0; }
.inactive { opacity: .55; }
.order { display: flex; gap: .25rem; margin: 0; }
.order form { display: flex; gap: .25rem; margin: 0; }
.qinfo { flex: 1; min-width: 200px; display: flex; flex-direction: column; }
.qinfo a { text-decoration: none; color: var(--text); }
.qactions { display: flex; gap: .4rem; }
.qactions form { margin: 0; }
.optlist form { margin: 0; }
.rename { display: flex; gap: .4rem; flex: 1; min-width: 180px; }
.rename input { min-height: 38px; padding: .4rem .6rem; }
.uses { min-width: 2.5rem; text-align: right; }
.add-options { margin-top: 1.25rem; }
.userrow { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; width: 100%; margin: 0; }
.uinfo { flex: 1; min-width: 220px; display: flex; flex-direction: column; gap: .2rem; }
.uinfo input { min-height: 38px; padding: .35rem .6rem; font-weight: 600; }
.userrow select { width: auto; min-height: 38px; padding-top: .35rem; padding-bottom: .35rem; }

/* ---------- Handy: Menü unten ---------- */
@media (max-width: 759px) {
  .topbar { padding: .5rem 1rem; }
  .brand-logo { height: 32px; }
  .brand-divider { height: 22px; }
  .brand-name { font-size: .9rem; }
  .mainnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    justify-content: space-around; gap: 0; padding: .3rem .25rem calc(.3rem + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .mainnav a, .navbtn { flex-direction: column; gap: .1rem; font-size: .68rem; padding: .35rem .4rem; flex: 1; }
  .mainnav .icon { width: 1.35rem; height: 1.35rem; }
  .mainnav form { flex: 1; display: flex; }
  .container { padding-bottom: 7rem; }
  .fab { bottom: calc(4.8rem + env(safe-area-inset-bottom)); }
  .form-actions.sticky { bottom: calc(3.6rem + env(safe-area-inset-bottom)); }
  .page-head { align-items: flex-start; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1; }
  h1 { font-size: 1.3rem; }
  .card { padding: 1rem; }
  body.bare .container { padding-bottom: 2rem; }
}

/* ---------- Tablet / PC ---------- */
@media (min-width: 760px) {
  .fab { display: none; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-2 { grid-column: span 2; }
  .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
  .photo-buttons { max-width: 480px; }
  .form-actions.sticky { margin: 0; border-radius: var(--radius); border: 1px solid var(--border); }
}
@media (min-width: 1000px) {
  .filter-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .detail { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); align-items: start; }
  .detail-media { position: sticky; top: 80px; }
}

@media print {
  .topbar, .mainnav, .fab, .actions, .backlink, .meta-card form { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; }
}
