/* ============================================================
   Inventar-Ansichten (js/invview.js)
   1. Breite Item-Ansicht: Modal mit Klasse .ivx (+ .ivx-cols ab 700 px)
      Tablet 700–1099 px: 2 Spalten, Modal scrollt, Kopf klebt oben
      Desktop ≥ 1100 px:  3 Spalten, jede Spalte scrollt für sich, Kopf fest
      Handy < 700 px:     unverändert (Originalreihenfolge, kein Kopf)
   2. Listenansicht „🖼️ Fotos": .page.inv-photos, Zeilen .ivp-row mit .ivp-strip
   Nur Farb-Tokens, harte Kanten, keine Gradients.
   ============================================================ */

/* ---------- 1. Item-Ansicht ---------- */
@media (min-width: 700px) {
  .modal.ivx.ivx-cols {
    max-width: min(96vw, 1000px);
    max-height: 94dvh;
    padding: 0;
  }
  .modal.ivx-cols > h2 { display: none; }
  .ivx-cols #inv-form {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    grid-template-areas: "head head" "c1 c2" "c3 c2";
    grid-template-rows: auto auto 1fr;
    align-items: start;
  }
  .ivx-head { grid-area: head; }
  .ivx-c1 { grid-area: c1; }
  .ivx-c2 { grid-area: c2; align-self: stretch; border-left: 2px solid var(--border); }
  .ivx-c3 { grid-area: c3; border-top: 2px solid var(--border); }
}

@media (min-width: 1100px) {
  .modal.ivx.ivx-cols {
    max-width: min(96vw, 1500px);
    display: flex; flex-direction: column;
    overflow: hidden;
  }
  .ivx-cols #inv-form {
    flex: 1 1 auto; min-height: 0;
    grid-template-columns: minmax(280px, 30fr) minmax(0, 40fr) minmax(300px, 30fr);
    grid-template-areas: "head head head" "c1 c2 c3";
    grid-template-rows: auto minmax(0, 1fr);
    align-items: stretch;
  }
  .ivx-cols .ivx-col { overflow: auto; min-height: 0; overscroll-behavior: contain; }
  .ivx-c3 { border-top: none; border-left: 2px solid var(--border); }
  /* Aktionen bleiben am Fuß der Spalte sichtbar, auch bei langen Kommentaren */
  .ivx-c3 .row-btns { position: sticky; bottom: 0; z-index: 1; }
}

/* Kopf: Emoji, Name, Art · Ort-Pfad, Status + Zeiten, Speichern/Abbrechen */
.ivx-head {
  position: sticky; top: 0; z-index: 3;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--surface-2);
  border-bottom: 3px solid var(--line);
}
.ivx-hem {
  flex: none; width: 46px; height: 46px;
  display: grid; place-items: center;
  font-size: 1.7rem; line-height: 1;
  border: 2px solid var(--line); background: var(--surface);
  box-shadow: 2px 2px 0 var(--shadow-c);
}
.ivx-htitle { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.ivx-hname {
  font-size: 1.15rem; line-height: 1.2; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ivx-hname.ivx-ph { color: var(--muted); font-weight: 600; }
.ivx-hpath {
  font-family: var(--px); font-size: .58rem; font-weight: 700; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ivx-hmeta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 3px 10px;
  font-size: .72rem; color: var(--muted);
}
.ivx-hmeta > span:not(.inv-badge) { white-space: nowrap; }
.ivx-dirty {
  flex: none; white-space: nowrap;
  font-family: var(--px); font-size: .55rem; font-weight: 700;
  color: var(--accent); border: 2px solid var(--accent); background: var(--accent-soft);
  padding: 3px 7px;
}
.ivx-hbtns { flex: none; display: flex; gap: 8px; }
.ivx-hbtns .btn { padding: 8px 12px; font-size: .66rem; }

/* Zahlenfelder (Menge, Schwellen) sahen im Item-Modal ungestylt aus — wie die übrigen Eingaben */
.modal.ivx input[type=number] {
  width: 100%; margin-top: 6px;
  border: 2px solid var(--line); border-radius: 0;
  background: var(--surface); color: var(--text);
  padding: 10px 12px; outline: none;
  font-family: var(--font); font-weight: 400; font-size: 1rem;
}
.modal.ivx input[type=number]:focus { border-color: var(--accent); box-shadow: 3px 3px 0 var(--accent-soft); }

/* Spalten */
.ivx-col { min-width: 0; padding: 14px 16px; }
.ivx-cols .ivx-col label { margin-bottom: 9px; }
.ivx-cols .ivx-col > label:last-child { margin-bottom: 0; }

/* Spalte 1: Fotos */
.ivx-hero { position: relative; margin-bottom: 12px; }
.ivx-hero-img, .ivx-hero-empty {
  display: block; width: 100%;
  aspect-ratio: 4 / 3; max-height: 50dvh;
  padding: 0; margin: 0;
  border: 2px solid var(--line); background: var(--surface-2);
  box-shadow: 3px 3px 0 var(--shadow-c);
  color: var(--muted);
}
.ivx-hero-img { cursor: zoom-in; }
.ivx-hero-img img { width: 100%; height: 100%; object-fit: contain; display: block; }
.ivx-hero-empty {
  cursor: pointer; border-style: dashed;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--px);
}
.ivx-hero-empty span { font-size: 2.4rem; }
.ivx-hero-empty b { font-size: .7rem; color: var(--text); }
.ivx-hero-empty small { font-size: .52rem; }
.ivx-hero-empty:hover, .ivx-hero-img:hover { border-color: var(--accent); }
.ivx-hero-n {
  position: absolute; right: 8px; bottom: 8px;
  font-family: var(--px); font-size: .55rem; font-weight: 700;
  background: var(--surface); border: 2px solid var(--line); padding: 2px 6px;
  pointer-events: none;
}
.ivx-c1 .iv-media { gap: 10px; }
.ivx-c1 .iv-thumb img { width: 60px; height: 60px; }
.ivx-c1.ivx-drop { outline: 3px dashed var(--accent); outline-offset: -6px; background: var(--accent-soft); }

/* Spalte 2: Kerndaten dicht im Raster */
.ivx-sec { margin-bottom: 12px; }
.ivx-sech {
  grid-column: 1 / -1;
  font-family: var(--px); font-size: .6rem; font-weight: 700; color: var(--accent);
  border-bottom: 2px solid var(--border);
  padding-bottom: 3px; margin-bottom: 8px;
}
.ivx-cols .ivx-s-head, .ivx-cols .ivx-s-stock, .ivx-cols .ivx-s-detail {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 12px;
}
.ivx-cols .ivx-s-detail { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.ivx-cols .ivx-s-head { grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(150px, 1fr); }
/* Abschnitt ohne sichtbaren Inhalt (z. B. Bestand bei Einzelstücken) samt Überschrift ausblenden */
.ivx-cols .ivx-sec:not(:has(> :not(.hidden, .ivx-sech))) { display: none; }
.ivx-cols .ivx-sec > .grid-2 { display: contents; }
/* mehrzeilige Beschriftungen: Eingaben einer Rasterzeile trotzdem auf einer Linie */
.ivx-cols .ivx-sec > label, .ivx-cols .ivx-sec > .grid-2 > label { align-self: end; }
.ivx-s-head > * { grid-column: span 2; }
.ivx-s-head > label:has(#iv-name) { grid-column: span 3; }
.ivx-s-head > .grid-2 > label:has(#iv-emoji) { grid-column: span 1; }
.ivx-s-head > .grid-2 > label:has(#iv-kind) { grid-column: span 2; }
.ivx-s-head > .iv-b-parent { grid-column: span 2; }
.ivx-s-stock > .iv-b-fill, .ivx-s-stock > .iv-b-mhd { grid-column: span 2; }
.ivx-cols .iv-b-fill input[type=range] { margin-top: 12px; }
.ivx-cols .ivx-s-tags .iv-cf-group .grid-2 {
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
}
.ivx-cols .iv-cf-group { padding: 8px 10px; }
.ivx-cols .cf-yt { max-width: 560px; }

/* Spalte 3: Notizen, Gebraucht für, Kommentare, Aktionen */
.ivx-c3 .cm-details { margin-top: 12px; }
.ivx-c3 .row-btns {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin-top: 14px; padding: 10px 0 4px;
  background: var(--surface);
  border-top: 2px solid var(--border);
}
.ivx-c3 .row-btns .btn { padding: 8px 10px; font-size: .62rem; }
/* Zweites Paar Abbrechen/💾 Speichern (wie im Kopf) am Fuß: ungerade Werkzeugzahl → Abbrechen füllt die
   freie Zelle, Speichern über die ganze Breite (.ivx-save-wide, invview.js); sonst „Abbrechen | Speichern" */
.ivx-c3 .row-btns.ivx-save-wide [type=submit] { grid-column: 1 / -1; }
/* Löschen: ganz unten, durch Abstand + gestrichelte Linie klar vom Speichern getrennt */
.ivx-c3 .row-btns:has(#iv-del)::after {
  content: ""; order: 8; grid-column: 1 / -1;
  margin: 4px 0 0; border-top: 2px dashed var(--border);
}
.ivx-c3 .row-btns #iv-del { order: 9; grid-column: 1 / -1; }
/* Beim Speichern sind beide Paare gesperrt (inventory.js setBusy) */
#inv-form[aria-busy="true"] .btn:disabled { cursor: progress; opacity: .7; }

/* ---------- 2. Listenansicht „🖼️ Fotos" ---------- */
.ivp-toggle {
  flex: none; display: flex; align-items: stretch;
  box-shadow: 2px 2px 0 var(--shadow-c);
}
.ivp-toggle .btn {
  box-shadow: none; padding: 6px 10px; font-size: .6rem; white-space: nowrap;
  color: var(--muted);
}
.ivp-toggle .btn + .btn { border-left: none; }
.ivp-toggle .btn.on { background: var(--accent-soft); color: var(--text); border-color: var(--accent); }
.ivp-toggle .btn + .btn.on { border-left: 2px solid var(--accent); }
.ivp-toggle .btn:active { transform: translate(1px, 1px); }
@media (max-width: 560px) { .ivp-toggle { flex: 1 1 100%; } .ivp-toggle .btn { flex: 1; } }

.layer-row.ivp-row { flex-wrap: wrap; row-gap: 6px; padding-bottom: 8px; margin-bottom: 2px; }
.ivp-strip {
  order: 99; flex: 1 1 100%; min-width: 0;
  display: flex; gap: 6px; align-items: center;
  overflow-x: auto; overflow-y: hidden;
  padding: 0 4px 6px 26px;
  scrollbar-width: thin;
}
.ivp-th {
  flex: none; width: 84px; height: 84px;
  object-fit: cover; display: block;
  border: 2px solid var(--line); background: var(--surface-2);
  box-shadow: 2px 2px 0 var(--shadow-c);
  cursor: zoom-in;
}
.ivp-th:hover { border-color: var(--accent); }
.ivp-th.ivp-bad { opacity: .3; cursor: default; }
.ivp-strip.ivp-none { padding-bottom: 0; }
.ivp-empty {
  font-family: var(--px); font-size: .5rem; font-weight: 700; color: var(--muted);
  border: 2px dashed var(--border); padding: 3px 8px;
}
@media (max-width: 560px) {
  .ivp-th { width: 72px; height: 72px; }
  .ivp-strip { padding-left: 20px; }
}
/* Schmal: Name bekommt die Zeile, Badges rutschen darunter (sonst bleibt vom Namen kaum etwas) */
@media (max-width: 699px) {
  .ivp-row .lr-name { flex-wrap: wrap; row-gap: 4px; }
  .ivp-row .inv-name { flex: 1 1 calc(100% - 30px); }
}

/* Desktop: Seite nutzt die Breite; flache Listen (Sortierung/Suche) als Karten-Raster */
@media (min-width: 1100px) {
  .page.inv-photos { max-width: 1480px; }
  .ivp-th { width: 96px; height: 96px; }
  .page.inv-photos .inv-sorted, .page.inv-photos .inv-flat {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 10px; align-items: stretch;
  }
  .page.inv-photos :is(.inv-sorted, .inv-flat) > :not(.layer-row) { grid-column: 1 / -1; }
  .page.inv-photos :is(.inv-sorted, .inv-flat) > .layer-row {
    margin: 0; flex-wrap: wrap; align-content: flex-start; align-items: flex-start;
    border-color: var(--border); background: var(--surface-2);
  }
  .page.inv-photos :is(.inv-sorted, .inv-flat) > .layer-row:hover { border-color: var(--line); }
  .page.inv-photos :is(.inv-sorted, .inv-flat) .ivp-strip { padding-left: 4px; }
  /* Karte: Name bekommt die ganze Zeile, Badges rutschen darunter */
  .page.inv-photos :is(.inv-sorted, .inv-flat) .lr-name { flex-wrap: wrap; row-gap: 4px; }
  .page.inv-photos :is(.inv-sorted, .inv-flat) .inv-name { flex: 1 1 calc(100% - 30px); }
  .page.inv-photos :is(.inv-sorted, .inv-flat) .ivp-th { background: var(--surface); }
}

/* ⧉ Exemplare / Duplizieren × N (inventory.js, js/exemplars.js) */
.iv-copies { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.iv-copies input[type=number] { width: 6em; min-height: 38px; margin: 0; padding: 6px 8px; font-size: 1rem; text-align: center; }
.iv-copies .btn { padding: 4px 12px; }
.iv-copies-note, .iv-dup-help { color: var(--muted); font-size: .8rem; font-weight: 400; }
.iv-dup-src { margin: 0 0 10px; }
.iv-dup-prev { border: 2px dashed var(--accent); padding: 8px 10px; margin: 8px 0; font-size: .85rem; overflow-wrap: anywhere; }
.iv-dup-prev b { color: var(--accent); }
