/* ============================================================
   Privates Archiv  ·  Stylesheet
   Gestaltung: ruhiges "Archiv/Atelier"-Thema. Warmes Papier,
   tiefe Petrol-Akzente, bibliophiles Schriftpaar. Die Bühne
   ist der Buch-Betrachter mit Mittelfalz.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Newsreader:ital,opsz,wght@0,6..72,400;0,6..72,500;0,6..72,600;1,6..72,400&family=Inter:wght@400;500;600&display=swap');

:root {
    --paper:    #f6f4ef;
    --paper-2:  #efece3;
    --ink:      #1b1d1c;
    --muted:    #6f6c64;
    --line:     #ddd8cd;
    --accent:   #1f5f57;
    --accent-d: #174740;
    --brass:    #a9803f;
    --stage:    #16140f;
    --radius:   14px;
    --shadow:   0 1px 2px rgba(27,29,28,.06), 0 12px 32px rgba(27,29,28,.10);
    --display:  'Newsreader', Georgia, 'Times New Roman', serif;
    --ui:       'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--ui);
    color: var(--ink);
    background: var(--paper);
    background-image:
        radial-gradient(circle at 12% -8%, rgba(31,95,87,.05), transparent 42%),
        radial-gradient(circle at 100% 0%, rgba(169,128,63,.05), transparent 40%);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--display); font-weight: 500; letter-spacing: -.01em; }
.muted { color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
    font-family: var(--ui);
    font-size: 14px;
    font-weight: 500;
    color: #fff;
    background: var(--accent);
    border: 1px solid var(--accent);
    padding: 9px 16px;
    border-radius: 999px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background .15s, transform .05s, box-shadow .15s;
    white-space: nowrap;
}
.btn:hover { background: var(--accent-d); border-color: var(--accent-d); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost {
    color: var(--ink);
    background: transparent;
    border-color: var(--line);
}
.btn.ghost:hover { background: var(--paper-2); border-color: #cfc9bb; }
.btn.small { padding: 6px 12px; font-size: 13px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- Topbar ---------- */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px;
    padding: 14px 22px;
    background: rgba(246,244,239,.86);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: var(--ink); }
.brand-mark {
    width: 16px; height: 22px; border-radius: 2px 4px 4px 2px;
    background: linear-gradient(180deg, var(--accent), var(--accent-d));
    box-shadow: inset -3px 0 0 rgba(0,0,0,.18);
    display: inline-block;
}
.brand-name { font-family: var(--display); font-size: 20px; font-weight: 600; }
.topnav { display: flex; align-items: center; gap: 8px; }

/* ---------- Layout ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 30px 22px 80px; }
.page-head {
    display: flex; align-items: flex-end; justify-content: space-between;
    gap: 16px; flex-wrap: wrap; margin-bottom: 26px;
}
.page-head h1 { font-size: clamp(28px, 4vw, 40px); margin: 0; }
.head-actions { display: flex; gap: 8px; }
.section-title {
    font-size: 15px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
    color: var(--muted); font-family: var(--ui);
    margin: 34px 0 14px; padding-bottom: 8px; border-bottom: 1px solid var(--line);
}

/* ---------- Album-Gitter ---------- */
.album-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 22px;
}
.album-card {
    text-decoration: none; color: inherit;
    background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
    overflow: hidden; box-shadow: var(--shadow);
    transition: transform .16s ease, box-shadow .16s ease;
    display: flex; flex-direction: column;
}
.album-card:hover { transform: translateY(-3px); box-shadow: 0 4px 8px rgba(27,29,28,.08), 0 20px 40px rgba(27,29,28,.14); }
.album-cover {
    aspect-ratio: 4 / 3; background: var(--paper-2);
    display: flex; align-items: center; justify-content: center; overflow: hidden;
    border-bottom: 1px solid var(--line);
}
.album-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-doc {
    font-family: var(--display); font-size: 26px; color: var(--brass);
    letter-spacing: .08em;
}
.album-meta { padding: 13px 15px 15px; display: flex; flex-direction: column; gap: 3px; }
.album-name { font-family: var(--display); font-size: 19px; font-weight: 500; }
.album-count { font-size: 13px; color: var(--muted); }

/* ---------- Foto-Gitter ---------- */
.photo-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px;
}
.photo {
    padding: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
    cursor: pointer; background: var(--paper-2); aspect-ratio: 1; transition: transform .12s, box-shadow .12s;
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo:hover { transform: scale(1.015); box-shadow: var(--shadow); }

/* ---------- Video-Gitter ---------- */
.video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 18px;
}
.video-item {
    margin: 0;
    background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
    overflow: hidden; box-shadow: var(--shadow);
    display: flex; flex-direction: column;
}
.video-player {
    width: 100%; aspect-ratio: 16 / 9;
    background: #000; display: block;
}
.video-item figcaption {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
}
.video-item .media-name {
    flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-weight: 500; font-size: 14px;
}
.video-item .media-actions { display: flex; gap: 6px; flex: none; }

/* ---------- Audio-Liste ---------- */
.audio-list { display: flex; flex-direction: column; gap: 10px; }
.audio-row {
    background: #fff; border: 1px solid var(--line); border-radius: 12px;
    padding: 12px 14px; display: flex; flex-direction: column; gap: 8px;
}
.audio-row .audio-line {
    display: flex; align-items: center; gap: 10px;
}
.audio-row .media-name {
    flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-weight: 500;
}
.audio-row .media-actions { display: flex; gap: 6px; flex: none; }
.audio-player { width: 100%; height: 36px; }

/* ---------- Dokumentliste ---------- */
.doc-list { display: flex; flex-direction: column; gap: 8px; }
.doc-row {
    display: flex; align-items: center; gap: 14px;
    background: #fff; border: 1px solid var(--line); border-radius: 12px;
    padding: 12px 16px;
}
.doc-icon {
    flex: none; width: 40px; height: 50px; border-radius: 4px;
    background: linear-gradient(180deg, #fff, var(--paper-2));
    border: 1px solid var(--line);
    display: flex; align-items: center; justify-content: center;
    font-family: var(--display); font-size: 12px; font-weight: 600; color: var(--brass);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.5);
    text-transform: uppercase; letter-spacing: .02em;
    padding: 0 3px; overflow: hidden;
}
.doc-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.doc-actions { display: flex; gap: 8px; flex: none; }

/* ---------- Leerer Zustand ---------- */
.empty {
    text-align: center; padding: 70px 20px; color: var(--muted);
    border: 1px dashed var(--line); border-radius: var(--radius); background: rgba(255,255,255,.5);
}
.empty p { font-size: 17px; margin: 0 0 16px; }

/* ---------- Login ---------- */
.login-body {
    display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card {
    position: relative; width: 100%; max-width: 380px;
    background: #fff; border: 1px solid var(--line); border-radius: 18px;
    padding: 38px 34px 34px; box-shadow: var(--shadow); overflow: hidden;
}
.login-spine {
    position: absolute; left: 0; top: 0; bottom: 0; width: 8px;
    background: linear-gradient(180deg, var(--accent), var(--accent-d));
    box-shadow: inset -2px 0 0 rgba(0,0,0,.15);
}
.login-title { font-size: 28px; margin: 0 0 2px; }
.login-sub { color: var(--muted); margin: 0 0 24px; font-size: 14px; }
.login-form { display: flex; flex-direction: column; gap: 8px; }
.login-form label { font-size: 13px; font-weight: 600; color: var(--muted); }
.login-form input {
    font-family: var(--ui); font-size: 16px; padding: 12px 14px;
    border: 1px solid var(--line); border-radius: 10px; background: var(--paper);
}
.login-form input:focus { background: #fff; border-color: var(--accent); outline: none; }
.login-form button { margin-top: 10px; justify-content: center; padding: 12px; }
.notice {
    background: var(--paper-2); border: 1px solid var(--line); border-radius: 10px;
    padding: 12px 14px; font-size: 14px; line-height: 1.5;
}
.notice.error { background: #fbeceb; border-color: #f0c8c4; color: #8a2b22; }
.notice code { background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 4px; font-size: 13px; }

/* ---------- Modal (Upload) ---------- */
.modal {
    position: fixed; inset: 0; z-index: 60;
    background: rgba(20,19,15,.5); backdrop-filter: blur(3px);
    display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal[hidden] { display: none; }
.modal-card {
    width: 100%; max-width: 520px; max-height: calc(100vh - 40px);
    background: var(--paper); border-radius: 18px;
    box-shadow: 0 24px 60px rgba(0,0,0,.3); overflow: hidden;
    display: flex; flex-direction: column;
    animation: pop .18s ease;
}
.modal-card .modal-head, .modal-card .modal-foot { flex: none; }
.modal-card .modal-body { flex: 1 1 auto; overflow-y: auto; }
@keyframes pop { from { transform: translateY(8px) scale(.99); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 20px; }
.modal-close { background: none; border: none; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 4px; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input {
    font-family: var(--ui); font-size: 15px; padding: 11px 13px;
    border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
.field input:focus { border-color: var(--accent); outline: none; }
.field input[readonly] { background: var(--paper-2); color: var(--muted); }
.dropzone {
    border: 2px dashed var(--line); border-radius: 12px; background: #fff;
    padding: 26px 20px; text-align: center; transition: border-color .15s, background .15s;
}
.dropzone.over { border-color: var(--accent); background: #f0f6f4; }
.dropzone p { margin: 0 0 8px; font-weight: 500; }
.dropzone .muted { display: block; font-size: 13px; margin: 4px 0 10px; }
.ul-progress {
    display: flex; flex-direction: column; gap: 6px;
    padding: 4px 0;
}
.ul-progress[hidden] { display: none; }
.ul-bar {
    height: 8px; background: var(--paper-2); border: 1px solid var(--line);
    border-radius: 999px; overflow: hidden;
}
.ul-bar-fill {
    height: 100%; width: 0%; background: var(--accent);
    transition: width .15s ease;
}
.ul-meta {
    display: flex; justify-content: space-between; align-items: baseline;
    font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.ul-meta #ulPct { color: var(--ink); font-weight: 600; }
.ul-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 180px; overflow: auto; }
.ul-list .ul-summary {
    background: var(--paper-2); border-color: var(--line); font-weight: 600;
    color: var(--ink); position: sticky; top: 0; z-index: 1;
}
.ul-list .ul-walk {
    background: #eef4f3; border-color: #cfe1de; color: var(--accent);
    font-weight: 500; position: sticky; top: 0; z-index: 2;
}
.ul-list li { display: flex; align-items: center; gap: 10px; font-size: 14px; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.ul-list .st { margin-left: auto; font-size: 12px; color: var(--muted); }
.ul-list .st.ok   { color: var(--accent); }
.ul-list .st.err  { color: #b23b30; }
.ul-list .st.warn { color: var(--brass); font-weight: 600; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--line); }
.form-error {
    margin: 0; padding: 10px 12px; font-size: 14px; line-height: 1.4;
    background: #fbeceb; border: 1px solid #f0c8c4; color: #8a2b22;
    border-radius: 8px;
}
.form-error[hidden] { display: none; }

/* ---------- Betrachter (Foto / Buch) ---------- */
.viewer {
    position: fixed; inset: 0; z-index: 80; background: var(--stage);
    display: flex; align-items: center; justify-content: center;
}
.viewer[hidden] { display: none; }
.viewer-close {
    position: absolute; top: 16px; right: 18px; z-index: 3;
    background: rgba(255,255,255,.1); color: #fff; border: none;
    width: 42px; height: 42px; border-radius: 50%; font-size: 26px; cursor: pointer;
}
.viewer-close:hover { background: rgba(255,255,255,.2); }
.viewer-nav {
    position: absolute; top: 50%; transform: translateY(-50%); z-index: 3;
    background: rgba(255,255,255,.08); color: #fff; border: none;
    width: 54px; height: 64px; border-radius: 10px; font-size: 34px; cursor: pointer;
    transition: background .15s;
}
.viewer-nav:hover { background: rgba(255,255,255,.2); }
.viewer-nav.prev { left: 16px; }
.viewer-nav.next { right: 16px; }
.viewer-bar {
    position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 3;
    display: flex; align-items: center; gap: 16px;
    background: rgba(0,0,0,.35); padding: 8px 16px; border-radius: 999px; color: #fff; font-size: 14px;
}
.viewer-bar .btn.ghost { color: #fff; border-color: rgba(255,255,255,.3); }
.viewer-bar .btn.ghost:hover { background: rgba(255,255,255,.12); }

.viewer-stage {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    perspective: 2600px; padding: 64px 86px;
}
/* Einzelbild */
.viewer-stage img.single {
    max-width: 100%; max-height: 100%; object-fit: contain;
    box-shadow: 0 18px 60px rgba(0,0,0,.5); border-radius: 3px; background: #fff;
}
/* Buch-Doppelseite */
.spread {
    display: flex; height: 100%; max-height: 100%; align-items: stretch;
    box-shadow: 0 20px 70px rgba(0,0,0,.55); border-radius: 4px; background: #fff;
    transform-style: preserve-3d;
}
.spread .leaf {
    height: 100%; background: #fff; position: relative; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
}
.spread .leaf img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.spread .leaf.left  { border-right: 1px solid rgba(0,0,0,.12); box-shadow: inset -22px 0 32px -24px rgba(0,0,0,.5); border-radius: 4px 0 0 4px; }
.spread .leaf.right { box-shadow: inset 22px 0 32px -24px rgba(0,0,0,.5); border-radius: 0 4px 4px 0; }
.spread.turn-next { animation: turnNext .4s ease; }
.spread.turn-prev { animation: turnPrev .4s ease; }
@keyframes turnNext { from { transform: rotateY(7deg); } to { transform: rotateY(0); } }
@keyframes turnPrev { from { transform: rotateY(-7deg); } to { transform: rotateY(0); } }

/* ---------- PDF-Betrachter ---------- */
.viewer.pdf .pdf-stage {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    padding: 60px 86px; perspective: 2600px; gap: 0;
    overflow: hidden; touch-action: none;
}
.pdf-stage .pdf-spread {
    display: flex; box-shadow: 0 20px 70px rgba(0,0,0,.55);
    background: #fff; border-radius: 4px;
    will-change: transform;
}
.pdf-stage canvas { display: block; }
.pdf-stage .pdf-spread canvas + canvas { border-left: 1px solid rgba(0,0,0,.15); }
.pdf-stage.turn { animation: turnNext .4s ease; }
.pdf-stage.pannable { cursor: grab; }
.pdf-stage.panning  { cursor: grabbing; }
.pdf-loading { color: #fff; font-size: 15px; opacity: .8; }

/* Erweiterte PDF-Leiste mit Zoom/Toggle */
.viewer-bar.pdf-bar { gap: 10px; padding: 6px 12px; flex-wrap: wrap; max-width: calc(100vw - 32px); }
.viewer-bar.pdf-bar .btn.small.ghost { color: #fff; border-color: rgba(255,255,255,.25); }
.viewer-bar.pdf-bar .btn.small.ghost:hover { background: rgba(255,255,255,.15); }
.viewer-bar.pdf-bar #pdfZoomLabel { min-width: 56px; text-align: center; font-variant-numeric: tabular-nums; }
.viewer-bar.pdf-bar #pdfZoomIn, .viewer-bar.pdf-bar #pdfZoomOut { padding: 4px 12px; font-size: 16px; line-height: 1; }
.pdf-bar-spacer { width: 1px; height: 18px; background: rgba(255,255,255,.18); }

/* ---------- Responsiv ---------- */
@media (max-width: 640px) {
    .wrap { padding: 22px 16px 70px; }
    .brand-name { font-size: 18px; }
    .viewer-stage, .viewer.pdf .pdf-stage { padding: 56px 56px; }
    .viewer-nav { width: 44px; height: 56px; font-size: 28px; }
    .viewer-nav.prev { left: 6px; } .viewer-nav.next { right: 6px; }
    /* Auf dem Handy zeigt das Buch nur eine Seite */
    .spread .leaf.left:not(.solo), .pdf-stage .pdf-spread canvas:first-child:not(:only-child) { display: none; }
    .doc-actions .btn span { display: none; }
}

/* ---------- Bewegung reduzieren ---------- */
@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}

/* ---------- Mehrstufige Ordner: Brotkrümel + Badge ---------- */
.crumbs {
    font-size: 14px; color: var(--muted);
    display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-bottom: 10px;
}
.crumbs a { color: var(--accent); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.crumbs .sep { color: var(--line); }
.album-cover { position: relative; }
.folder-badge {
    position: absolute; right: 8px; bottom: 8px;
    background: rgba(20,19,15,.72); color: #fff; font-size: 11px;
    padding: 3px 9px; border-radius: 999px; backdrop-filter: blur(2px);
}

/* ---------- Drag-and-Drop: Ordner verschieben ---------- */
.album-card { cursor: pointer; }
.album-card.dragging { opacity: .45; }
.album-card.drop-target {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    box-shadow: 0 0 0 6px rgba(31,95,87,.12), var(--shadow);
}
.crumb-drop.drop-target {
    background: var(--accent);
    color: #fff !important;
    border-radius: 6px;
    padding: 2px 8px;
    text-decoration: none;
}

/* ---------- Verwalten: Aktionen-Knopf, Aktionsmenü, Verschieben ---------- */
.tile-actions {
    position: absolute; top: 8px; right: 8px; z-index: 2;
    width: 30px; height: 30px; border: none; border-radius: 50%;
    background: rgba(20,19,15,.55); color: #fff;
    font-size: 20px; line-height: 1; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.tile-actions:hover { background: rgba(20,19,15,.85); }
.as-btn { width: 100%; justify-content: center; margin-bottom: 8px; }
.as-btn:last-child { margin-bottom: 0; }
#moveDest {
    font-family: var(--ui); font-size: 15px; padding: 11px 13px;
    border: 1px solid var(--line); border-radius: 10px; background: #fff; width: 100%;
}
