/* Paperless-Neu: Design angelehnt an ein physisches Aktenarchiv –
   gedecktes Papierpalette, Petrol als Registratur-Akzent, klare Tabellenstruktur
   statt Karten-Kacheln. */

:root {
    --paper: #f6f3ec;
    --paper-dim: #eae5d9;
    --ink: #24211c;
    --ink-soft: #5c574d;
    --petrol: #2b4a4a;
    --petrol-light: #3d6363;
    --line: #d8d2c2;
    --amber: #b8843f;
    --error: #a33d2f;
    --success: #3d6b4a;
    --radius: 3px;
    --font-body: "Iowan Old Style", "Source Serif Pro", Georgia, serif;
    --font-ui: "Inter", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--petrol); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    background: var(--petrol);
    border-bottom: 3px solid var(--amber);
}
.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 32px;
    height: 56px;
}
.brand {
    font-family: var(--font_body, serif);
    font-family: var(--font-body);
    font-size: 20px;
    font-weight: 600;
    color: var(--paper);
    letter-spacing: 0.02em;
}
.brand:hover { text-decoration: none; opacity: 0.9; }
.topnav { display: flex; gap: 4px; flex: 1; }
.topnav a {
    color: #d8ddd8;
    padding: 8px 14px;
    border-radius: var(--radius);
    font-size: 14px;
}
.topnav a:hover { background: rgba(255,255,255,0.08); text-decoration: none; }
.topnav a.active { background: rgba(255,255,255,0.14); color: #fff; }

/* Hamburger-Button: auf Desktop unsichtbar, wird in der Media-Query unten
   für Smartphones (max-width: 640px) auf flex umgeschaltet. */
.nav-toggle { display: none; }

.logout-form { margin: 0; }
.link-button {
    background: none;
    border: none;
    color: #d8ddd8;
    font-size: 14px;
    cursor: pointer;
    font-family: inherit;
    padding: 8px 4px;
}
.link-button:hover { color: #fff; text-decoration: underline; }

.page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 24px 64px;
}

h1 {
    font-family: var(--font-body);
    font-size: 28px;
    font-weight: 600;
    margin: 0 0 24px;
    color: var(--ink);
}
h2 {
    font-family: var(--font-body);
    font-size: 20px;
    font-weight: 600;
    margin: 0 0 16px;
}

.messages { list-style: none; padding: 0; margin: 0 0 20px; }
.message {
    padding: 10px 16px;
    border-radius: var(--radius);
    margin-bottom: 8px;
    font-size: 14px;
    border-left: 3px solid var(--ink-soft);
}
.message-success { background: #e7f0e9; border-color: var(--success); color: #2a4d33; }
.message-error { background: #f5e6e3; border-color: var(--error); color: #7a2c20; }

/* --- Suchleiste & Filter --- */
.search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.search-bar input[type="text"] {
    flex: 1;
    min-width: 240px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    font-size: 15px;
}
select, input[type="text"], input[type="password"], textarea {
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    font-family: inherit;
    font-size: 14px;
    color: var(--ink);
}
.filters { display: flex; gap: 8px; flex-wrap: wrap; }

button, .btn {
    background: var(--petrol);
    color: #fff;
    border: none;
    padding: 9px 18px;
    border-radius: var(--radius);
    font-size: 14px;
    cursor: pointer;
    font-family: var(--font-ui);
    display: inline-block;
}
button:hover, .btn:hover { background: var(--petrol-light); text-decoration: none; }
.btn-secondary { background: transparent; color: var(--petrol); border: 1px solid var(--line); }
.btn-secondary:hover { background: var(--paper-dim); }
.btn-danger { background: var(--error); }
.btn-danger:hover { background: #8c3628; }

/* --- Dokumentenliste: Tabelle statt Kartenraster, wie ein Registerbuch --- */
.doc-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}
.doc-table th {
    text-align: left;
    font-size: 12px;
    text-transform: none;
    color: var(--ink-soft);
    font-weight: 600;
    padding: 10px 14px;
    border-bottom: 2px solid var(--line);
    background: var(--paper-dim);
}
.doc-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
    font-size: 14px;
}
.doc-table tr:last-child td { border-bottom: none; }
.doc-table tr:hover { background: #fbfaf6; }
.doc-title { font-weight: 600; color: var(--ink); }
.doc-title a { color: inherit; }

.thumb-cell img {
    width: 40px;
    height: 52px;
    object-fit: cover;
    border: 1px solid var(--line);
    border-radius: 2px;
    background: var(--paper-dim);
}
.thumb-placeholder {
    width: 40px; height: 52px;
    background: var(--paper-dim);
    border: 1px solid var(--line);
    border-radius: 2px;
}

.tag-pill {
    display: inline-block;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    color: #fff;
    margin-right: 4px;
}

.status-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}
.status-pending, .status-processing { background: #f0e6d0; color: #7a5a1e; }
.status-ready { background: #e0eee2; color: var(--success); }
.status-failed { background: #f5e0dc; color: var(--error); }

.empty-state {
    text-align: center;
    padding: 64px 24px;
    color: var(--ink-soft);
}

/* --- Detailseite --- */
.detail-grid {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 32px;
}
.detail-preview {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    overflow: hidden;
}
.detail-preview img { width: 100%; display: block; }
.detail-form label {
    display: block;
    font-size: 13px;
    color: var(--ink-soft);
    margin: 16px 0 4px;
    font-weight: 600;
}
.detail-form label:first-child { margin-top: 0; }
.detail-form input, .detail-form select, .detail-form textarea { width: 100%; }
.tag-checklist input[type="checkbox"] { width: auto; flex-shrink: 0; }
.tag-checklist { display: flex; flex-wrap: wrap; gap: 10px 16px; }
.tag-checklist label {
    display: inline-flex; align-items: center; gap: 6px;
    font-weight: 400; font-size: 14px; margin: 0; white-space: nowrap;
}
.form-actions { margin-top: 24px; display: flex; gap: 10px; }

.auto-badge {
    font-size: 11px;
    color: var(--amber);
    border: 1px solid var(--amber);
    padding: 1px 6px;
    border-radius: 8px;
    margin-left: 8px;
}

/* --- Upload --- */
.upload-drop {
    border: 2px dashed var(--line);
    border-radius: var(--radius);
    padding: 48px 24px;
    text-align: center;
    background: #fff;
}
.upload-drop input[type="file"] { margin-top: 16px; }

/* --- Verwaltung --- */
.manage-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}
.manage-section {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px;
}
.manage-list { list-style: none; padding: 0; margin: 0 0 16px; }
.manage-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
}
.manage-list li:last-child { border-bottom: none; }
.inline-form { display: flex; gap: 6px; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 100px; }

/* --- Login --- */
.login-wrap {
    max-width: 360px;
    margin: 80px auto;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 32px;
}
.login-wrap h1 { text-align: center; font-size: 22px; }
.login-wrap form { display: flex; flex-direction: column; gap: 14px; margin-top: 20px; }

@media (max-width: 800px) {
    .detail-grid { grid-template-columns: 1fr; }
    .manage-grid { grid-template-columns: 1fr; }
    .dashboard-grid { grid-template-columns: 1fr; }
}

/* ========================================================
   SMARTPHONE-OPTIMIERUNG (bis 640px Breite)
   ======================================================== */
@media (max-width: 640px) {
    body { font-size: 15px; }
    .page { padding: 16px 12px 48px; }

    /* Kopfzeile: Hamburger-Menü statt horizontaler Navigation */
    .topbar-inner {
        flex-wrap: nowrap;
        height: 52px;
        padding: 0 12px;
        position: relative;
    }
    .topbar {
        /* Verhindert, dass die Kopfzeile im iOS-Vollbildmodus (Homescreen-App)
           unter die Notch/Dynamic Island bzw. Statusleiste rutscht. */
        padding-top: env(safe-area-inset-top, 0px);
    }
    .brand { font-size: 17px; }
    .topnav {
        display: none;
        position: absolute;
        /* top: 100% statt fester Pixelzahl, damit das Menü IMMER direkt
           unter der Kopfzeile andockt, unabhängig von Safe-Area-Höhe
           (Notch/Dynamic Island) im iOS-Homescreen-Vollbildmodus. */
        top: 100%;
        left: 0;
        right: 0;
        background: var(--petrol);
        flex-direction: column;
        gap: 0;
        padding: 8px 0;
        box-shadow: 0 4px 8px rgba(0,0,0,0.15);
        z-index: 100;
    }
    .topnav.nav-open { display: flex; }
    .topnav a { padding: 14px 20px; border-radius: 0; font-size: 15px; }
    .nav-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        background: none;
        border: none;
        color: #fff;
        font-size: 22px;
        cursor: pointer;
        margin-left: auto;
        margin-right: 8px;
    }
    .logout-form { margin-left: 0; }
    .link-button { font-size: 13px; padding: 6px 4px; }

    h1 { font-size: 22px; margin-bottom: 16px; }
    h2 { font-size: 17px; }

    /* Suchleiste und Filter: alles untereinander, volle Breite */
    .search-bar, .filters { flex-direction: column; }
    .search-bar input[type="text"], .search-bar select, .search-bar button {
        width: 100%;
    }

    /* Tabellen: kein seitliches Scrollen - jede Zeile wird zur Karte, die
       Spaltenüberschriften erscheinen als kleine Beschriftung (siehe Skript
       in base.html, das data-label setzt). */
    .doc-table-wrap { overflow-x: visible; }
    .doc-table { min-width: 0; display: block; border: none; background: none; }
    .doc-table thead { display: none; }
    .doc-table tbody { display: block; }
    .doc-table tr {
        display: block; background: #fff; border: 1px solid var(--line);
        border-radius: var(--radius); margin-bottom: 10px; padding: 8px 10px;
    }
    .doc-table td {
        display: flex; align-items: center; gap: 8px; width: 100%;
        padding: 3px 0; border: none; font-size: 14px; flex-wrap: wrap;
    }
    .doc-table td[data-label]::before {
        content: attr(data-label); flex: 0 0 92px; font-size: 12px; color: var(--ink-soft);
    }
    .doc-table td.doc-title::before { display: none; }
    .doc-table td.doc-title { font-size: 15px; }
    .doc-table td.checkbox-cell { width: auto; display: inline-flex; }
    .doc-table td.thumb-cell { width: auto; display: inline-flex; }
    .doc-table td.thumb-cell img { width: 36px; height: 46px; }

    /* Dashboard: Statistik-Spalte unter den Hauptinhalt, volle Breite */
    .dashboard-grid { gap: 20px; }
    .doc-cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }

    /* Detail-/Bearbeitungsseite: Vorschau über dem Formular, volle Breite */
    .detail-grid { gap: 20px; }
    .detail-form input, .detail-form select, .detail-form textarea { font-size: 16px; } /* 16px verhindert Auto-Zoom auf iOS */
    .form-actions { flex-direction: column; }
    .form-actions button, .form-actions .btn { width: 100%; text-align: center; }

    /* Verwaltung: Inline-Formulare gestapelt */
    .manage-grid { gap: 16px; }
    .inline-form { flex-direction: column; align-items: stretch; }
    .inline-form input, .inline-form select { width: 100%; }
    .manage-row-display { flex-direction: column; align-items: flex-start; gap: 8px; }
    .manage-row-actions { width: 100%; }
    .manage-row-actions button, .manage-row-actions form { flex: 1; }

    /* Upload-Bereich */
    .upload-drop { padding: 32px 16px; }

    /* Login */
    .login-wrap { margin: 40px auto; padding: 24px; max-width: 90%; }
}

/* --- Dashboard --- */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 32px;
    align-items: start;
}
.dashboard-side {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px;
}
.dashboard-side h2 { font-size: 16px; margin-top: 24px; }
.dashboard-side h2:first-child { margin-top: 0; }

.stats-list { list-style: none; padding: 0; margin: 0; }
.stats-list li {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 7px 0;
    border-bottom: 1px solid var(--line);
    font-size: 13px;
    color: var(--ink-soft);
}
.stats-list li:last-child { border-bottom: none; }
.stats-list strong { color: var(--ink); font-size: 15px; }
.stat-warning { color: var(--error) !important; }

.doc-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}
.doc-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.doc-card:hover { border-color: var(--petrol); }
.doc-card-link { color: inherit; display: block; }
.doc-card-link:hover { text-decoration: none; }
.doc-card-thumb {
    position: relative;
    aspect-ratio: 3/4;
    background: var(--paper-dim);
}
.doc-card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.doc-card-status {
    position: absolute;
    top: 6px;
    right: 6px;
}
.doc-card-body { padding: 10px 12px; }
.doc-card-title-line {
    font-weight: 400;
    font-size: 11px;
    color: var(--ink-soft);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.doc-card-meta { font-size: 11px; color: var(--ink-soft); margin-bottom: 6px; }
.doc-card-tags .tag-pill { font-size: 10px; }
.doc-card-delete-form {
    padding: 0 12px 12px;
    margin: 0;
}
.btn-small {
    padding: 4px 10px;
    font-size: 12px;
    width: 100%;
}
.inline-delete-form { margin: 0; }

/* --- Export/Import --- */
.export-import-box {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 560px;
}
.export-import-box p { color: var(--ink-soft); font-size: 14px; }

/* --- Fehler-Hinweis in Dashboard-Karten --- */
.doc-card-error {
    font-size: 11px;
    color: var(--error);
    background: #f5e6e3;
    padding: 4px 6px;
    border-radius: 2px;
    margin-bottom: 6px;
}

/* --- Verwaltung: Bearbeiten-Modus --- */
.manage-row { display: block; padding: 8px 0; border-bottom: 1px solid var(--line); }
.manage-row:last-child { border-bottom: none; }
.manage-row-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
}
.manage-row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.manage-row-edit { margin-top: 8px; }

/* --- Ordner-Baum --- */
.folder-tree { display: flex; flex-direction: column; gap: 10px; }
.folder-branch {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 4px 16px;
}
.folder-branch-label {
    cursor: pointer;
    padding: 10px 0;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    list-style: none;
}
.folder-branch-label::-webkit-details-marker { display: none; }
.folder-arrow {
    display: inline-block;
    font-size: 11px;
    color: var(--ink-soft);
    transition: transform 0.15s ease;
    flex-shrink: 0;
}
details[open] > .folder-branch-label .folder-arrow { transform: rotate(90deg); }
.folder-icon { flex-shrink: 0; }
.folder-count {
    font-size: 11px;
    color: var(--ink-soft);
    background: var(--paper-dim);
    padding: 1px 8px;
    border-radius: 8px;
    font-weight: 400;
}
.folder-doc-list { list-style: none; padding: 0 0 12px 26px; margin: 0; }
.folder-doc-list li { padding: 5px 0; font-size: 13px; border-top: 1px solid var(--line); }
.folder-doc-list li:first-child { border-top: none; }
.folder-doc-meta { color: var(--ink-soft); font-size: 11px; margin-left: 8px; }
.folder-doc-empty { color: var(--ink-soft); font-style: italic; }

/* --- KI-Hinweise --- */
.message-ai {
    background: #f0ebf7;
    border-left: 3px solid #6b4c9a;
    color: #4a3466;
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    margin-bottom: 20px;
}
.section-hint {
    font-size: 12px;
    font-weight: 400;
    color: var(--ink-soft);
    margin-left: 8px;
}

/* Ermöglicht horizontales Scrollen der Tabelle auf schmalen Bildschirmen,
   ohne das Layout auf Desktop zu verändern. */
.doc-table-wrap { width: 100%; }



/* --- Mehrfachauswahl / Sammel-Löschen --- */
.bulk-actions-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px 14px;
    margin-bottom: 12px;
    font-size: 14px;
}
.select-all-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 600;
}
.select-all-label input[type="checkbox"] { width: auto; }
#bulk-delete-btn:disabled {
    background: var(--paper-dim);
    color: var(--ink-soft);
    cursor: not-allowed;
}
.checkbox-cell { width: 34px; text-align: center; }
.checkbox-cell input[type="checkbox"] { width: auto; }

.folder-doc-select {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}
.folder-doc-select input[type="checkbox"] { width: auto; flex-shrink: 0; }

@media (max-width: 640px) {
    .bulk-actions-bar { flex-wrap: wrap; gap: 10px; }
}

/* --- PDF-Vorschau (eingebettet, eigene Kopfleiste) --- */
.pdf-viewer-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--petrol);
    color: #fff;
    padding: 12px 16px;
    border-radius: var(--radius) var(--radius) 0 0;
    margin: -16px -16px 0;
}
.pdf-viewer-back {
    color: #fff;
    font-size: 14px;
    white-space: nowrap;
    flex-shrink: 0;
}
.pdf-viewer-back:hover { color: #fff; text-decoration: underline; }
.pdf-viewer-title {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pdf-viewer-share {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    padding: 6px 12px;
    border-radius: var(--radius);
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}
.pdf-viewer-share:hover { background: rgba(255,255,255,0.25); }

.pdf-viewer-frame-wrap {
    background: #525659;
    border-radius: 0 0 var(--radius) var(--radius);
    margin: 0 -16px -48px;
    min-height: 400px;
    max-height: calc(100vh - 180px);
    overflow-y: auto;
    padding: 12px;
}
#pdf-pages { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.pdf-page-canvas {
    max-width: 100%;
    height: auto;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    background: #fff;
}

@media (max-width: 640px) {
    .pdf-viewer-bar { margin: -16px -12px 0; padding: 10px 12px; }
    .pdf-viewer-frame-wrap { margin: 0 -12px -48px; max-height: calc(100vh - 160px); }
    .pdf-viewer-back, .pdf-viewer-share { font-size: 13px; }
}

/* --- Sammelbearbeitung & Papierkorb --- */
.bulk-edit-panel {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px 14px;
    margin-bottom: 12px;
    font-size: 14px;
}
.bulk-edit-panel summary { cursor: pointer; font-weight: 600; color: var(--petrol); }
.bulk-edit-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-top: 12px;
    align-items: end;
}
.bulk-edit-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-soft); }
.bulk-edit-grid select { width: 100%; }
#bulk-edit-btn:disabled { background: var(--paper-dim); color: var(--ink-soft); cursor: not-allowed; }
.trash-hint { color: var(--ink-soft); font-size: 13px; margin-top: -16px; }
.trash-days { font-size: 12px; color: var(--ink-soft); }
.trash-days.soon { color: #a33; font-weight: 600; }
#bulk-reprocess-btn:disabled { background: var(--paper-dim); color: var(--ink-soft); cursor: not-allowed; }
.bulk-edit-submit { display: flex; gap: 8px; flex-wrap: wrap; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 18px 0; font-size: 14px; }
.pager a { padding: 6px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.pager .pager-off { color: var(--ink-soft); padding: 6px 14px; }
.algo-select { max-width: 230px; }
.doc-count { color: var(--ink-soft); font-size: 13px; margin: 0 0 10px; }

/* --- Fristen, Fragen, Auswertung --- */
.dl-list { list-style: none; margin: 0 0 20px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.dl-item {
    display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
    background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px;
}
.dl-main { flex: 1; min-width: 220px; }
.dl-sub { color: var(--ink-soft); font-size: 13px; margin-left: 6px; }
.dl-context { color: var(--ink-soft); font-size: 12px; margin-top: 4px; }
.dl-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0; }
.dl-form input[type="text"], .dl-form input[type="date"] { width: auto; max-width: 180px; }
.dl-inline { margin: 6px 0; }
.dl-empty { color: var(--ink-soft); font-size: 14px; }
.dl-hint { margin: -6px 0 10px; font-size: 14px; }
.dl-badge { font-size: 12px; padding: 2px 8px; border-radius: 10px; margin-left: 6px; color: #fff; }
.dl-over { background: #a33; }
.dl-soon { background: #b8843f; }
.dl-later { background: #6c757d; }
.dl-done { opacity: 0.75; }
.detail-box { margin-top: 28px; padding-top: 4px; }
.ask-form { display: flex; gap: 8px; margin-bottom: 20px; }
.ask-form input { flex: 1; }
.ask-item { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
.ask-q { font-weight: 600; margin-bottom: 6px; }
.ask-a { font-size: 14px; }
.ask-wait { color: var(--ink-soft); font-style: italic; }
.ask-err { color: #a33; }
.ask-src { margin-top: 8px; font-size: 13px; color: var(--ink-soft); }
.report-filter { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 18px; }
.report-filter label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-soft); }
.report-total td { border-top: 2px solid var(--line); }
@media (max-width: 640px) {
    .ask-form { flex-direction: column; }
    .dl-form input[type="text"], .dl-form input[type="date"] { max-width: 100%; flex: 1; }
}


/* --- Feste Breite am Smartphone: nie seitlich scrollbar --- */
html { max-width: 100%; overflow-x: hidden; -webkit-text-size-adjust: 100%; }
body { max-width: 100%; overflow-x: hidden; }
img, canvas, video, iframe, table, pre, textarea, select, input { max-width: 100%; }
.dashboard-grid > *, .detail-grid > *, .manage-grid > * { min-width: 0; }
.nav-home { display: none; }

@media (max-width: 640px) {
    body { overflow-wrap: anywhere; }
    .page { max-width: 100vw; }
    .brand { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .nav-home {
        display: inline-flex; align-items: center; gap: 4px; margin-left: auto; flex-shrink: 0;
        background: rgba(255,255,255,0.14); color: #fff; padding: 6px 10px;
        border-radius: var(--radius); font-size: 13px; font-weight: 600;
    }
    .nav-home:hover { text-decoration: none; background: rgba(255,255,255,0.24); }
    .nav-home ~ .nav-toggle { margin-left: 0; }
    .search-bar, .filters, .bulk-actions-bar, .form-actions { max-width: 100%; }
    .bulk-actions-bar > *, .dl-form > * { min-width: 0; }
    input:not([type="checkbox"]):not([type="radio"]), select, textarea { font-size: 16px; } /* verhindert Auto-Zoom auf iOS */
}

/* --- Dashboard am Smartphone: eine Spalte, Hauptinhalt zuerst, Statistik kompakt darunter --- */
@media (max-width: 800px) {
    .dashboard-grid { grid-template-columns: minmax(0, 1fr); gap: 16px; }
    .dashboard-side { padding: 12px 14px; }
    .dashboard-side h2 { font-size: 14px; margin-top: 14px; }
    .dashboard-side .stats-list li { padding: 5px 0; font-size: 13px; }
    .dashboard-side .btn { padding: 8px 10px; font-size: 13px; margin-bottom: 6px !important; }
}

/* --- Foto-Scan --- */
.photo-intro { color: var(--ink-soft); font-size: 14px; }
.photo-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0; }
.photo-btn { cursor: pointer; text-align: center; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin: 10px 0; }
.photo-item { position: relative; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.photo-item img { display: block; width: 100%; height: 130px; object-fit: cover; }
.photo-nr { position: absolute; top: 4px; left: 4px; background: rgba(0,0,0,.65); color: #fff; font-size: 12px; border-radius: 10px; padding: 1px 7px; }
.photo-ctl { display: flex; justify-content: space-between; padding: 3px; }
.photo-ctl button { flex: 1; padding: 6px 0; font-size: 13px; background: transparent; color: var(--ink); border: 0; }
.photo-empty { color: var(--ink-soft); font-size: 13px; }
.photo-title { width: 100%; margin: 10px 0; }

/* --- Angeheftete Datei / Tabelle --- */
.pinned-table { margin-top: 28px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; }
.pinned-table h2 { margin-top: 0; font-size: 16px; }
.pinned-name { display: flex; flex-direction: column; gap: 2px; margin: 0 0 10px; }
.pinned-name span, .pinned-hint, .table-meta, .table-count { color: var(--ink-soft); font-size: 13px; }
.pinned-search { display: flex; gap: 8px; margin-bottom: 10px; }
.pinned-search input { flex: 1; min-width: 0; }
.pinned-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pinned-actions form { margin: 0; }
.pinned-actions label.btn, .pinned-table label.btn { cursor: pointer; }
.table-search { display: flex; gap: 8px; margin: 12px 0; }
.table-search input { flex: 1; min-width: 0; }
.sheet-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.sheet-tabs a { padding: 5px 12px; border: 1px solid var(--line); border-radius: 16px; font-size: 13px; background: #fff; color: var(--ink); }
.sheet-tabs a.active { background: var(--green, #2b4a47); color: #fff; border-color: transparent; }
.data-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.data-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.data-table th { position: sticky; top: 0; background: #eef2f0; text-align: left; white-space: nowrap; }
.data-table th, .data-table td { padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table mark { background: #ffe58a; padding: 0 1px; }
@media (max-width: 640px) {
    .data-wrap { overflow-x: visible; border: 0; background: transparent; }
    .data-table thead { display: none; }
    .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
    .data-table tr { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; padding: 6px 10px; }
    .data-table td { border: 0; padding: 3px 0; display: flex; gap: 8px; }
    .data-table td:empty { display: none; }
    .data-table td::before { content: attr(data-label); flex: 0 0 38%; color: var(--ink-soft); font-size: 12px; }
}

/* --- Teilen-Dialog im PDF-Viewer --- */
.share-dialog { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 1000; align-items: flex-end; justify-content: center; }
.share-box { background: #fff; width: 100%; max-width: 420px; border-radius: 14px 14px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }
.share-box h3 { margin: 0; }
.share-box form { display: flex; flex-direction: column; gap: 8px; }
.share-box label { font-size: 13px; color: var(--ink-soft); }
.share-status { min-height: 18px; font-size: 13px; margin: 0; }
@media (min-width: 641px) { .share-dialog { align-items: center; } .share-box { border-radius: 14px; } }

/* --- Seiten bearbeiten --- */
.page-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin: 14px 0; }
.page-item { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.page-item.deleted { opacity: .35; }
.page-frame { position: relative; height: 170px; display: flex; align-items: center; justify-content: center; background: #eee; overflow: hidden; }
.page-frame img { max-width: 100%; max-height: 100%; transition: transform .15s; }
.page-item .photo-ctl { flex-wrap: wrap; }
.page-item .photo-ctl button { flex: 1 0 20%; padding: 8px 0; }
.page-sel { display: block; font-size: 12px; padding: 4px 8px 8px; color: var(--ink-soft); }
.page-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 18px; }
@media (max-width: 640px) { .page-grid { grid-template-columns: repeat(2, 1fr); } }

/* --- PDF-Viewer: Leiste immer sichtbar, mit Zurück / Home / Speichern / Teilen --- */
.pdf-viewer-bar { position: sticky; top: 0; z-index: 50; flex-wrap: wrap; }
.pdf-viewer-title { flex: 1 1 120px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 640px) {
    .pdf-viewer-bar { gap: 8px; }
    .pdf-viewer-title { order: 5; flex: 1 1 100%; font-size: 12px; opacity: .85; }
    .pdf-viewer-back, .pdf-viewer-share { padding: 6px 8px; }
}
