:root {
  --bg: #f7f4f1;
  --surface: #ffffff;
  --surface-2: #f0ebe6;
  --text: #2a2228;
  --muted: #7a6f75;
  --border: #e3dcd6;
  --accent: #7a4b8f;
  --accent-text: #ffffff;
  --accent-soft: #efe5f3;
  --fav: #d6336c;
  --danger: #c0392b;
  --notice: #e7f4ea;
  --notice-text: #1f5f33;
  --alert: #fbe9e7;
  --alert-text: #8a2a1d;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 14px rgb(0 0 0 / 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17141a;
    --surface: #221e25;
    --surface-2: #2c2730;
    --text: #efe9f1;
    --muted: #a99fae;
    --border: #3a3340;
    --accent: #b88ccc;
    --accent-text: #1b1420;
    --accent-soft: #3a2e42;
    --fav: #f06595;
    --danger: #ef6f61;
    --notice: #1d3324;
    --notice-text: #a5dcb5;
    --alert: #3d2220;
    --alert-text: #f4b4aa;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; line-height: 1.25; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
h2 { font-size: 1.15rem; margin: 2rem 0 .75rem; }
.h3 { font-size: 1rem; margin: 0 0 .5rem; }
code { font-size: .85em; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.count { color: var(--muted); font-weight: 400; font-size: .9em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Layout */
.container { max-width: 1100px; margin: 0 auto; padding: 1rem 1rem 6rem; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1.5rem;
  padding: .6rem 1rem; padding-top: max(.6rem, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); letter-spacing: -.01em; }
.mainnav { display: none; gap: .25rem; }
.mainnav a { color: var(--muted); padding: .35rem .7rem; border-radius: 999px; }
.mainnav a.active, .mainnav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.usermenu { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.usermenu form { margin: 0; }

.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: .45rem 0 .5rem; font-size: .72rem; color: var(--muted);
}
.bottomnav a span { font-size: 1.25rem; line-height: 1.2; }
.bottomnav a.active { color: var(--accent); font-weight: 600; }
.bottomnav a:hover { text-decoration: none; }

@media (min-width: 760px) {
  .mainnav { display: flex; }
  .bottomnav { display: none; }
  .container { padding: 1.5rem 1.5rem 4rem; }
}

.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.actions { display: flex; align-items: center; gap: .5rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: 2.5rem; padding: .45rem 1rem;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.btn-link:hover { text-decoration: underline; }

/* Messages */
.notice, .alert { padding: .7rem 1rem; border-radius: 10px; margin: 0 0 1rem; }
.notice { background: var(--notice); color: var(--notice-text); }
.alert { background: var(--alert); color: var(--alert-text); }
.empty { color: var(--muted); padding: 1rem 0; }
.empty-state { text-align: center; padding: 3rem 1rem; }
.empty-state .big { font-size: 3rem; margin: 0; }
.empty-state h2 { margin-top: .5rem; }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1.25rem; }
.filters input[type=search] { flex: 1 1 12rem; }
.filters select { flex: 0 1 auto; }

input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: .5rem .7rem; min-height: 2.5rem; width: 100%;
}
.filters select, .filters input { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
input[type=checkbox] { width: 1.1rem; height: 1.1rem; min-height: 0; accent-color: var(--accent); margin: 0; }

.check { display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; }
.chip { padding: .35rem .8rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); min-height: 2.5rem; }
.chip:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }

/* Forms */
.form { display: grid; gap: 1rem; }
.form label:not(.check) { display: grid; gap: .3rem; font-weight: 500; font-size: .92rem; }
.form fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.form legend { font-weight: 500; font-size: .92rem; margin-bottom: .5rem; padding: 0; }
.row { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); }
.form-actions { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin-top: 1rem; }
.form-actions form { margin: 0; }
.form-actions.sticky {
  position: sticky; bottom: 4.2rem; z-index: 5;
  padding: .75rem; margin: 0 -.75rem; border-radius: var(--radius);
  background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(6px);
}
@media (min-width: 760px) { .form-actions.sticky { bottom: 0; } }

.item-form { grid-template-columns: 1fr; align-items: start; }
@media (min-width: 860px) { .item-form { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 2rem; } }
.fields { display: grid; gap: 1rem; }

.photo-box { display: grid; gap: .75rem; }
@media (min-width: 860px) { .photo-box { position: sticky; top: 4.5rem; } }
.photo-preview, .camera-video {
  width: 100%; aspect-ratio: 3 / 4; border-radius: var(--radius);
  background: var(--surface-2); border: 1px dashed var(--border);
  display: grid; place-items: center; overflow: hidden; object-fit: cover;
}
.photo-preview img { width: 100%; height: 100%; object-fit: contain; }
.photo-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

/* Cards */
.grid { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
@media (min-width: 760px) { .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); } }
.grid-small { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: .6rem; }

.card {
  position: relative; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column;
}
.card-img { display: grid; place-items: center; aspect-ratio: 3 / 4; background: var(--surface-2); overflow: hidden; }
.card-img > img { width: 100%; height: 100%; object-fit: cover; }
.card-img .placeholder { font-size: 2.5rem; }
.card-body { padding: .55rem .7rem .7rem; min-width: 0; }
.card-title { display: block; color: var(--text); font-weight: 600; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { color: var(--muted); font-size: .8rem; display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; min-height: 1.2em; }

.mosaic { display: grid; gap: 2px; place-items: stretch; }
.mosaic img { width: 100%; height: 100%; object-fit: cover; min-height: 0; }
.mosaic-2 { grid-template-columns: 1fr 1fr; }
.mosaic-3, .mosaic-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.mosaic-3 img:first-child { grid-row: span 2; }

.badge, .tag {
  display: inline-block; font-size: .72rem; padding: .05rem .5rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-weight: 500;
}
.tag { font-size: .82rem; padding: .15rem .6rem; }

.fav-form { position: absolute; top: .4rem; right: .4rem; margin: 0; }
.actions .fav-form { position: static; }
.fav {
  width: 2.3rem; height: 2.3rem; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; font-size: 1.2rem; line-height: 1;
  background: color-mix(in srgb, var(--surface) 88%, transparent); color: var(--muted);
  box-shadow: var(--shadow);
}
.fav.on { color: var(--fav); }
.fav.static { position: absolute; top: .4rem; right: .4rem; }
.actions .fav { border: 1px solid var(--border); box-shadow: none; }

/* Picker */
.picker-filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .25rem; }
.picker-filters input[type=search] { flex: 1 1 10rem; width: auto; }
.picker-filters select { width: auto; }
.pick {
  position: relative; display: flex; flex-direction: column; cursor: pointer;
  border-radius: 12px; overflow: hidden; background: var(--surface);
  border: 2px solid transparent; box-shadow: var(--shadow);
}
.pick:has(input:checked) { border-color: var(--accent); }
.pick > img, .pick > .mosaic { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; background: var(--surface-2); }
.pick input { position: absolute; top: .4rem; left: .4rem; z-index: 1; }
.pick-label { font-size: .75rem; padding: .25rem .4rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Freigestellte Bilder (Dateiname endet auf _nb.webp / _nb_t.webp) vollständig zeigen statt zuschneiden */
/* Hintergrund in derselben Farbe wie im Bild (CUTOUT_BACKGROUND), damit Rand und Bild ineinander übergehen */
img[src*="_nb."], img[src*="_nb_t."] { object-fit: contain !important; padding: 6%; background: #f4f4f4; }
.detail-img.cutout { background: #f4f4f4; }
.detail-img.cutout img { padding: 4%; }
.image-actions { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; margin-top: .6rem; }
.image-actions form { margin: 0; }

/* Detail */
.detail { display: grid; gap: 1.5rem; }
@media (min-width: 760px) { .detail { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; } }
.detail-img { margin: 0; border-radius: var(--radius); overflow: hidden; background: var(--surface-2); }
.detail-img img { width: 100%; display: block; max-height: 75vh; object-fit: contain; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 0 0 1rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }
.notes { white-space: pre-line; background: var(--surface); padding: .8rem 1rem; border-radius: 10px; border: 1px solid var(--border); }

/* Panels / tables */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1.5rem; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: .6rem .8rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table th { color: var(--muted); font-weight: 500; font-size: .82rem; }

/* Users */
.user-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.user-list a { display: flex; gap: .8rem; align-items: center; padding: .75rem 1rem; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); color: var(--text); }
.user-list a:hover { text-decoration: none; outline: 1px solid var(--accent); }
.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 2.4rem; height: 2.4rem; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 700;
}

/* Login */
.login { min-height: 70vh; display: grid; place-items: center; }
.login-card { width: 100%; max-width: 380px; text-align: center; background: var(--surface); padding: 2rem 1.5rem; border-radius: 20px; box-shadow: var(--shadow); }
.login-card h1 { justify-content: center; margin-bottom: .5rem; }
.login-logo { font-size: 3rem; }
