/* VOD-Sammlung — responsiver Stil (mobile-first) */
* { box-sizing: border-box; }
body {
    font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
    margin: 0; background: #f5f6f8; color: #1c1e21;
    -webkit-text-size-adjust: 100%;
}

/* ── Header ─────────────────────────────────────────────────────────── */
header {
    background: #1f2937; color: #fff; padding: .85rem 1rem;
    display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
}
header h1 { margin: 0; font-size: 1.15rem; flex: 1; min-width: 0; }
header nav { display: flex; flex-wrap: wrap; gap: .2rem; }
header nav a {
    color: #cbd5e1; text-decoration: none;
    padding: .3rem .5rem; border-radius: 4px; font-size: .9rem;
    white-space: nowrap;
}
header nav a.active, header nav a:hover { color: #fff; background: rgba(255,255,255,.1); }
header .stats { width: 100%; color: #9ca3af; font-size: .8rem; padding-top: .1rem; }

main { max-width: 1100px; margin: 1rem auto; padding: 0 .75rem; }

/* ── Inputs / Buttons ────────────────────────────────────────────────── */
label { display: block; margin: .6rem 0 .2rem; font-size: .9rem; color: #444; }
input, select, textarea, button {
    font: inherit;
    padding: .65rem .8rem;       /* etwas mehr Padding für Touch */
    border: 1px solid #cbd5e1;
    border-radius: 6px; background: #fff;
    min-height: 44px;            /* Apple HIG touch target */
}
input, select { width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #3b82f6; border-color: #3b82f6; }
textarea { width: 100%; min-height: 70px; }
button { cursor: pointer; background: #fff; min-width: 44px; }
button.primary {
    background: #3b82f6; color: #fff; border-color: #2563eb;
    padding: .75rem 1.25rem; font-weight: 600;
}
button.primary:hover, button.primary:active { background: #2563eb; }
button.danger { background: #dc2626; color: #fff; border-color: #b91c1c; }

/* ── Alerts ──────────────────────────────────────────────────────────── */
.msg { padding: .75rem 1rem; border-radius: 6px; margin: .75rem 0; }
.msg.ok  { background: #dcfce7; color: #166534; }
.msg.err { background: #fee2e2; color: #991b1b; }
.ok { color: #16a34a; }
.err { color: #dc2626; }

/* ── Box-Set / Sammlung ──────────────────────────────────────────────── */
.label-checkbox {
    display: flex; align-items: center; gap: .5rem;
    cursor: pointer; font-size: .95rem; color: #374151;
}
.label-checkbox input[type=checkbox] {
    width: 18px; height: 18px; min-height: unset; flex-shrink: 0;
}
#collection-fields {
    background: #fffbeb; border: 1px solid #fde68a;
    border-radius: 8px; padding: .75rem 1rem; margin: .5rem 0;
}
.badge-collection {
    font-size: 1rem; margin-right: .25rem; cursor: help;
}
.film-count {
    color: #9ca3af; font-size: .78rem; margin-left: .3rem;
}
.badge-collection-detail {
    display: inline-block; background: #fef3c7; color: #92400e;
    border: 1px solid #fde68a; border-radius: 6px;
    padding: .3rem .75rem; font-size: .9rem; font-weight: 600;
    margin-bottom: .5rem;
}

/* ── Jellyfin ────────────────────────────────────────────────────────── */
.jellyfin-bar {
    display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
    background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px;
    padding: .65rem 1rem; margin-bottom: .4rem; font-size: .9rem;
}
.jellyfin-bar span { color: #166534; font-weight: 500; }
#sync-status { font-size: .85rem; color: #374151; }

/* Sync-Fortschritt */
#sync-progress-wrap {
    background: #f0fdf4; border: 1px solid #bbf7d0; border-top: none;
    border-radius: 0 0 8px 8px; padding: .5rem 1rem .65rem; margin-bottom: 1rem;
}
.sync-progress-bar {
    height: 6px; background: #d1fae5; border-radius: 99px; overflow: hidden; margin-bottom: .4rem;
}
#sync-progress-inner {
    height: 100%; width: 0; background: #16a34a; border-radius: 99px;
    transition: width .2s ease;
}
.sync-log {
    max-height: 120px; overflow-y: auto; font-size: .8rem; line-height: 1.6;
}
.sync-log-entry     { color: #374151; }
.sync-log-ok        { color: #16a34a; font-weight: 500; }
.sync-log-err       { color: #dc2626; }
.sync-log-dim       { color: #9ca3af; }

.badge-digital {
    display: inline-flex; align-items: center; gap: .25rem;
    background: #22c55e; color: #fff;
    padding: .2rem .55rem; border-radius: 999px;
    font-size: .78rem; font-weight: 600; white-space: nowrap;
    text-decoration: none; cursor: pointer;
}
.badge-digital:hover { background: #16a34a; }
.badge-missing {
    display: inline-flex; align-items: center;
    color: #9ca3af; font-size: .85rem;
}

/* Film-Detailseite Jellyfin-Block */
.jellyfin-section {
    background: #f8fafc; border: 1px solid #e2e8f0;
    border-radius: 8px; padding: .85rem 1rem; margin: .8rem 0;
}
.jellyfin-section h3 { margin: 0 0 .5rem; font-size: 1rem; color: #0ea5e9; }
.jf-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .5rem; }
.jf-actions button { padding: .45rem .9rem; font-size: .9rem; }
#jf-status { font-size: .85rem; color: #374151; }
.jf-manual summary { cursor: pointer; color: #3b82f6; font-size: .9rem; }
.jf-manual input { margin-bottom: .4rem; }
.jf-manual ul li button {
    width: 100%; text-align: left; padding: .5rem .75rem; margin: .2rem 0;
    background: #f1f5f9; border-color: #e2e8f0; font-size: .9rem;
}
.jf-manual ul li button:hover { background: #e2e8f0; }

/* Jellyfin-Button auf Detailseite (unter Poster) */
.btn-jellyfin {
    display: block; text-align: center; margin-top: .6rem;
    background: #0ea5e9; color: #fff; border-radius: 6px;
    padding: .6rem; font-size: .9rem; text-decoration: none; font-weight: 600;
}
.btn-jellyfin:hover { background: #0284c7; }

/* "Fehlende Filme"-Seite */
.missing-header {
    background: #fff; border-radius: 8px; padding: 1rem 1.25rem;
    margin-bottom: 1rem; box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.missing-header p { margin: 0 0 .75rem; color: #374151; }

/* ── Setup-Wizard ────────────────────────────────────────────────────── */
.setup main {
    background: #fff; padding: 1.25rem 1rem;
    border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
nav.steps {
    display: flex; gap: .35rem;
    max-width: 1100px; margin: .75rem auto 0; padding: 0 .75rem;
    overflow-x: auto;            /* auf sehr kleinen Screens scrollen statt umbrechen */
    -webkit-overflow-scrolling: touch;
}
nav.steps a {
    flex: 0 0 auto;              /* kein Shrink — lieber horizontal scrollen */
    text-align: center; padding: .65rem .8rem;
    background: #e5e7eb; color: #374151;
    text-decoration: none; border-radius: 6px; font-size: .85rem;
    white-space: nowrap;
}
nav.steps a.active { background: #3b82f6; color: #fff; }
fieldset { margin: .8rem 0; padding: .8rem 1rem; border: 1px solid #e5e7eb; border-radius: 6px; }
fieldset legend { padding: 0 .4rem; font-weight: 600; }
fieldset input { width: 100%; }
.test-result { display: block; margin-top: .3rem; font-size: .9rem; }

/* ── Dashboard ───────────────────────────────────────────────────────── */
.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters input { flex: 1; min-width: 160px; }
.filters select { flex: 0 0 auto; }
.filters button, .filters a { flex: 0 0 auto; }

/* Tabelle auf Mobile scrollbar machen */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 6px; }
table.films, table.copies {
    width: 100%; border-collapse: collapse; background: #fff;
    border-radius: 6px; overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,.05);
    min-width: 480px;            /* verhindert Quetschen, erzwingt Scroll */
}
table.films th, table.films td,
table.copies th, table.copies td {
    padding: .65rem .6rem; border-bottom: 1px solid #f1f5f9; text-align: left;
    font-size: .9rem;
}
table.films tbody tr { cursor: pointer; }
table.films tbody tr:hover, table.films tbody tr:active { background: #f8fafc; }
.thumb { width: 34px; height: auto; border-radius: 3px; }

/* ── Scan-Seite ──────────────────────────────────────────────────────── */
.scan { display: grid; gap: 1rem; }
.ean-input {
    background: #fff; padding: 1rem; border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.ean-input input {
    width: 100%; font-size: 1.3rem; padding: .9rem;
    /* inputmode=numeric würde ggf. den Nummern-Pad öffnen — wir lassen offen für Text-EANs */
}
.ean-input button { margin-top: .5rem; width: 100%; justify-content: center; }
#camera-area { margin-top: .8rem; }
#cam { width: 100%; max-width: 480px; border-radius: 6px; background: #000; display: block; }
#cam-stop { width: 100%; max-width: 480px; margin-top: .4rem; }
#lookup-status { margin-top: .6rem; color: #4b5563; font-size: .9rem; }

/* Film-Karte nach Lookup: auf Mobile untereinander */
.film-card {
    display: flex; flex-direction: column; gap: .75rem;
    background: #fff; padding: 1rem; border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.film-card img { width: 100px; height: auto; border-radius: 4px; align-self: flex-start; }
.film-card .meta h2 { margin: 0 0 .3rem; font-size: 1.1rem; }
.film-card .sub { color: #6b7280; margin: 0 0 .5rem; font-size: .85rem; }
.film-card .plot { font-size: .85rem; color: #374151; }
.film-card .src { font-size: .75rem; color: #9ca3af; }

/* Copy-Formular */
.copy-form { background: #fff; padding: 1rem; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.05); }
.copy-form form { display: flex; flex-direction: column; gap: .6rem; }
#save-status { font-size: .9rem; }

/* Copy-Rows (Mehrfach-Medientyp) */
#copy-rows { display: flex; flex-direction: column; gap: .4rem; }
.copy-row {
    display: flex; flex-wrap: wrap; gap: .4rem; align-items: center;
    background: #f8fafc; border: 1px solid #e2e8f0;
    border-radius: 7px; padding: .5rem .65rem;
}
.copy-row select, .copy-row input { width: auto; min-height: 40px; flex: 1; min-width: 80px; }
.copy-row .cr-media  { flex: 0 0 90px; }
.copy-row .cr-inv    { flex: 1 1 120px; }
.copy-row .cr-loc    { flex: 1 1 130px; }
.copy-row .cr-qty-label { flex: 0 0 auto; display: flex; align-items: center; gap: .3rem; white-space: nowrap; font-size: .9rem; }
.copy-row .cr-qty    { width: 58px; min-width: unset; flex: none; }
.copy-row .cr-remove { flex: 0 0 36px; padding: 0; min-height: 36px; color: #ef4444; border-color: #fca5a5; background: #fff; font-size: 1rem; }
.copy-row .cr-remove:hover { background: #fee2e2; }

.btn-add-row {
    align-self: flex-start; background: #f0fdf4; border-color: #bbf7d0;
    color: #166534; padding: .5rem .9rem; font-size: .9rem;
}

/* ── Film-Picker (Box-Set Auswahl) ───────────────────────────────────── */
.cf-picker { margin-top: .75rem; }
.cf-picker-label { margin: 0 0 .4rem; font-size: .9rem; color: #374151; font-weight: 500; }
.cf-search-row { display: flex; gap: .5rem; }
.cf-search-row input { flex: 1; }
.cf-search-row button { flex: 0 0 auto; }

.cf-results { list-style: none; padding: 0; margin: .5rem 0; max-height: 260px; overflow-y: auto; border: 1px solid #e5e7eb; border-radius: 6px; }
.cf-results li + li { border-top: 1px solid #f1f5f9; }
.cf-result-btn {
    display: flex; align-items: center; gap: .5rem;
    width: 100%; text-align: left; border: none; border-radius: 0;
    background: #fff; padding: .5rem .75rem; min-height: 48px;
    font-size: .9rem; color: #1c1e21;
}
.cf-result-btn:hover:not(:disabled) { background: #f8fafc; }
.cf-result-btn:disabled { color: #9ca3af; cursor: default; }
.cf-result-btn img { width: 36px; height: auto; border-radius: 3px; flex-shrink: 0; }
.cf-no-poster { font-size: 1.3rem; width: 36px; text-align: center; flex-shrink: 0; }
.cf-added { font-size: .8rem; color: #16a34a; margin-left: auto; white-space: nowrap; }
.cf-loading { padding: .6rem .75rem; color: #9ca3af; font-size: .9rem; }

.cf-selected {
    display: flex; flex-wrap: wrap; gap: .4rem;
    min-height: 40px; margin-top: .5rem;
    padding: .4rem; background: #f8fafc; border: 1px dashed #d1d5db; border-radius: 6px;
}
.cf-empty { color: #9ca3af; font-size: .85rem; align-self: center; margin: 0 auto; }
.cf-item {
    display: flex; align-items: center; gap: .35rem;
    background: #fff; border: 1px solid #e2e8f0; border-radius: 20px;
    padding: .2rem .35rem .2rem .5rem; font-size: .82rem;
}
.cf-item img { width: 24px; height: auto; border-radius: 2px; }
.cf-item .cf-no-poster { font-size: .95rem; width: 24px; }
.cf-item-title { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cf-remove {
    border: none; background: none; cursor: pointer;
    color: #9ca3af; padding: 0 .2rem; min-height: unset;
    font-size: .85rem; line-height: 1; border-radius: 50%;
}
.cf-remove:hover { color: #ef4444; background: #fee2e2; }

/* ── Collection-Mitglieder (film.php) ────────────────────────────────── */
.cf-member-list { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .5rem; }
.cf-member-item {
    display: flex; align-items: center; gap: .4rem;
    background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px;
    padding: .3rem .55rem; text-decoration: none; color: #1c1e21; font-size: .85rem;
    transition: background .15s;
}
.cf-member-item:hover { background: #e2e8f0; }
.cf-member-item img { width: 32px; height: auto; border-radius: 3px; }
.cf-member-item .cf-no-poster { font-size: 1.1rem; }

/* ── Teil-von Badge ──────────────────────────────────────────────────── */
.badge-part-of {
    display: inline-block; background: #fffbeb; color: #92400e;
    border: 1px solid #fde68a; border-radius: 6px;
    padding: .25rem .65rem; font-size: .88rem; margin-bottom: .4rem;
}
.badge-part-of a { color: #92400e; font-weight: 600; }
.badge-part-of a:hover { color: #78350f; }

.manual-area {
    background: #fff; padding: 1rem; border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.manual-area input { margin-bottom: .5rem; }
.manual-area ul { list-style: none; padding: 0; margin: .5rem 0 0; }
.manual-area li button { width: 100%; text-align: left; margin: .25rem 0; min-height: 48px; }

/* ── Bestand-Tabelle Edit-Modus ──────────────────────────────────────── */
.copy-actions { white-space: nowrap; display: flex; gap: .3rem; }
.copy-actions button { padding: .25rem .45rem; min-height: unset; font-size: .9rem; border-radius: 5px; }
.btn-edit-copy  { background: #f0f9ff; border-color: #bae6fd; color: #0369a1; }
.btn-edit-copy:hover { background: #e0f2fe; }
.btn-save-copy  { background: #f0fdf4; border-color: #bbf7d0; color: #166534; font-weight: 600; }
.btn-save-copy:hover { background: #dcfce7; }
.btn-cancel-copy { background: #f9fafb; border-color: #e5e7eb; color: #6b7280; }
.btn-cancel-copy:hover { background: #f3f4f6; }
.copy-edit-row td { background: #fffbeb; vertical-align: middle; padding: .35rem .4rem; }
.copy-edit-row input, .copy-edit-row select {
    width: 100%; min-height: 34px; padding: .25rem .4rem;
    font-size: .88rem; border-radius: 5px;
}
.notes-cell { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Film-Detail ─────────────────────────────────────────────────────── */
.film-detail {
    display: grid; grid-template-columns: 1fr;  /* mobile: 1 Spalte */
    gap: 1rem; background: #fff; padding: 1rem; border-radius: 8px;
}
.film-detail aside img { width: 120px; border-radius: 4px; }
.film-detail .sub { color: #6b7280; }
.film-detail .ids { font-size: .85rem; color: #6b7280; }
.film-detail section h3 { margin: 1rem 0 .4rem; }

/* ── Tablet + Desktop ────────────────────────────────────────────────── */
@media (min-width: 600px) {
    header { padding: 1rem 1.5rem; }
    header .stats { width: auto; padding-top: 0; margin-left: auto; }
    main { padding: 0 1rem; margin-top: 1.5rem; }
    .setup main { padding: 1.5rem 2rem; }

    /* Copy-Formular: 2 Spalten für Labels+Inputs, kritische Bereiche volley */
    .copy-form form { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem 1rem; }
    .copy-form label { margin: 0; }
    /* Diese Elemente immer über die volle Breite */
    .label-checkbox,
    #collection-fields,
    #copy-rows,
    #add-copy-row,
    .copy-form label:has(textarea),
    .copy-form button[type=submit],
    #save-status { grid-column: 1 / -1; }

    /* Film-Karte: nebeneinander */
    .film-card { flex-direction: row; }
    .film-card img { width: 140px; flex-shrink: 0; }

    /* Kamera-Button nicht mehr full-width */
    .ean-input button { width: auto; }
    #cam-stop { width: auto; max-width: none; }

    nav.steps { flex-wrap: wrap; overflow-x: visible; }
    nav.steps a { flex: 1; }

    fieldset input { width: 60%; }
    .test-result { display: inline; margin-left: .6rem; }
}

@media (min-width: 800px) {
    /* Film-Detail: Poster links */
    .film-detail { grid-template-columns: 200px 1fr; gap: 2rem; padding: 1.5rem; }
    .film-detail aside img { width: 100%; }
}
