/* Bericht-Modul Stylesheet
 * Nutzt Dolibarr CSS-Variablen, damit Light- und Dark-Theme automatisch passen.
 */

.bericht-overview-header { display:flex; justify-content:space-between; align-items:center; margin-bottom:10px; }

.bericht-editor { padding-top: 10px; }
.bericht-meta { margin-bottom: 12px; }

.bericht-layout {
    display: grid;
    /* minmax(0, 1fr) verhindert, dass die mittlere Spalte über die verfügbare
       Breite hinaus wächst, wenn der Canvas-Inhalt zu breit wird */
    grid-template-columns: 260px minmax(0, 1fr) 220px;
    gap: 12px;
    align-items: start;
}

.bericht-attachments,
.bericht-pages {
    background: var(--colorbacktitle1, #f7f7f9);
    color: var(--colortext, inherit);
    border: 1px solid var(--colorboxbordertitle1, #e3e3e7);
    border-radius: 6px;
    padding: 10px;
    max-height: 80vh;
    overflow-y: auto;
    overflow-x: hidden;
    box-sizing: border-box;
    min-width: 0; /* verhindert grid-Überlauf */
}
.bericht-attachments *, .bericht-pages * { box-sizing: border-box; }

/* Nur die Haupt-Actions unten in der Anhänge-Spalte einheitlich breit */
.bericht-add-selected select,
.bericht-add-selected .butAction,
.bericht-upload .butAction,
.bericht-upload label.butAction {
    display: block;
    width: 100%;
    box-sizing: border-box;
    text-align: center;
    padding: 8px 12px;
    margin: 4px 0 0 0;
    background: var(--colorbackbody, #2a2a30);
    color: var(--colortext, #e0e0e0);
    border: 1px solid var(--colorboxbordertitle1, #555);
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bericht-add-selected .butAction:hover,
.bericht-upload .butAction:hover { background: var(--colorbackhmenu1, #337ab7); color: #fff; }
.bericht-attachments h4,
.bericht-pages h4 {
    margin: 0 0 8px 0;
    font-size: 13px;
    text-transform: uppercase;
    color: var(--colortextlink, #555);
}

.bericht-att-group { margin-bottom: 10px; }
.bericht-att-group-title {
    font-weight: 600;
    font-size: 11px;
    opacity: 0.7;
    padding: 4px 0;
    border-bottom: 1px solid var(--colorboxbordertitle1, #ddd);
}
.bericht-att-item {
    display: flex; align-items: center; gap: 6px;
    padding: 4px 2px; font-size: 12px;
    color: var(--colortext, inherit);
}
.bericht-att-item:hover { background: rgba(255,255,255,0.05); }
.att-delete {
    background: transparent;
    border: none;
    cursor: pointer;
    opacity: 0.4;
    padding: 2px 4px;
    font-size: 13px;
}
.att-delete:hover { opacity: 1; color: #d9534f; }
.att-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-size { font-size: 10px; opacity: 0.6; }
.att-icon { font-size: 14px; }

.bericht-upload { margin-top: 10px; }

.bericht-grid-buttons {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--colorboxbordertitle1, #444);
}
.bericht-grid-buttons button {
    background: var(--colorbacktitle1, #2a2a30);
    color: var(--colortext, #ddd);
    border: 1px solid var(--colorboxbordertitle1, #555);
    border-radius: 3px;
    padding: 4px 8px;
    margin: 2px;
    cursor: pointer;
    font-size: 14px;
}
.bericht-grid-buttons button:hover { background: var(--colorbackhmenu1, #337ab7); color: #fff; }

/* Mittlere Spalte: Editor-Canvas — bewusst dunkler Hintergrund (auch im Light-Mode),
 * weil ein Canvas auf grauer Fläche besser sichtbar ist.
 */
.bericht-canvas-area {
    background: var(--colorbackbody, #2a2a2e);
    border: 1px solid var(--colorboxbordertitle1, transparent);
    border-radius: 6px;
    padding: 10px;
    display: flex; flex-direction: column;
}
.bericht-toolbar {
    display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center;
    background: var(--colorbacktitle1, #fff);
    color: var(--colortext, inherit);
    padding: 6px;
    border-radius: 4px;
    margin-bottom: 8px;
    border: 1px solid var(--colorboxbordertitle1, transparent);
}
/* Einheitliche Höhe für ALLE Steuerelemente in der Toolbar */
.bericht-toolbar button,
.bericht-toolbar .tool-btn,
.bericht-toolbar select,
.bericht-toolbar input[type="number"],
.bericht-toolbar input[type="text"],
.bericht-toolbar input[type="color"],
.bericht-toolbar input[type="range"] {
    height: 30px;
    box-sizing: border-box;
    line-height: 1;
    vertical-align: middle;
    margin: 0;
}
.bericht-toolbar button,
.bericht-toolbar .tool-btn {
    background: var(--colorbackbody, #2a2a30);
    color: var(--colortext, inherit);
    border: 1px solid var(--colorboxbordertitle1, #555);
    border-radius: 4px;
    padding: 0 10px;
    cursor: pointer;
    font-size: 14px;
    display: inline-flex; align-items: center; justify-content: center;
}
.bericht-toolbar input[type="color"] {
    width: 32px;
    padding: 2px;
    border: 1px solid var(--colorboxbordertitle1, #555);
    background: var(--colorbackbody, #2a2a30);
    border-radius: 4px;
    cursor: pointer;
}
.bericht-toolbar input[type="range"] { width: 90px; }
.bericht-toolbar .tool-btn.active {
    background: var(--colorbackhmenu1, #5cb85c);
    color: var(--colortextbackhmenu, #fff);
    border-color: var(--colortextlink, #4cae4c);
}
.bericht-toolbar .sep {
    width: 1px;
    background: var(--colorboxbordertitle1, #ddd);
    height: 24px;
    margin: 0 4px;
    align-self: center;
}
/* Forciert Zeilenumbruch — alle Elemente nach .row-break gehen auf neue Zeile */
.bericht-toolbar .row-break { flex-basis: 100%; height: 0; margin: 0; }
.bericht-toolbar label {
    display: flex; align-items: center; gap: 4px;
    font-size: 12px;
    color: var(--colortext, inherit);
}
.bericht-toolbar select,
.bericht-toolbar input[type="number"],
.bericht-toolbar input[type="text"] {
    background: var(--colorbackbody, #2a2a30);
    color: var(--colortext, #ddd);
    border: 1px solid var(--colorboxbordertitle1, #555);
    border-radius: 3px;
    padding: 2px 4px;
    font-size: 12px;
}
.bericht-toolbar select option {
    background: var(--colorbackbody, #2a2a30);
    color: var(--colortext, #ddd);
}
.bericht-toolbar #zoom-label { color: var(--colortext, inherit); }
.bericht-toolbar input[type="checkbox"] { accent-color: var(--colorbackhmenu1, #337ab7); }

.bericht-canvas-wrap {
    position: relative;
    background: var(--colorbackvmenu1, #444);
    padding: 20px; border-radius: 4px;
    display: flex; align-items: flex-start; justify-content: center;
    min-height: 400px;
}
.bericht-canvas-wrap.empty {
    align-items: center;
    padding: 40px 20px;
}
/* WICHTIG: kein max-width auf #pdf-canvas, sonst weicht display- von buffer-size ab
   und das Fabric-Overlay rutscht weg. Stattdessen rendert JS auf passende Größe. */
#pdf-canvas {
    background: #fff;
    box-shadow: 0 2px 12px rgba(0,0,0,0.4);
    display: block;
}
/* Leerer Zustand: A4 Hochformat anzeigen, damit der Canvas nicht winzig wirkt */
.bericht-canvas-wrap.empty #pdf-canvas {
    width: 100%;
    max-width: 900px;
    aspect-ratio: 1 / 1.414; /* DIN A4 */
    height: auto;
}
.bericht-canvas-wrap.empty::after {
    content: "Seite wählen oder Fotos hinzufügen";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #aaa;
    font-size: 16px;
    pointer-events: none;
    text-align: center;
    background: rgba(255,255,255,0.85);
    padding: 8px 16px;
    border-radius: 6px;
}
#fabric-canvas.fabric-overlay { position: absolute !important; pointer-events: auto; }
/* Fabric.js wickelt das Canvas in einen .canvas-container ein. Ohne diese Regel
   sitzt der Container im normalen Flow neben dem pdfCanvas und verdrängt es
   nach links — das ergibt einen "weißen Bereich rechts" der Bilder überlappt. */
.bericht-canvas-wrap .canvas-container {
    position: absolute !important;
}

.bericht-page-note { margin-top: 8px; }
.bericht-page-note label {
    display: block;
    color: var(--colortext, #e0e0e0);
    font-size: 12px;
    margin-bottom: 4px;
}
.bericht-page-note textarea {
    width: 100%;
    box-sizing: border-box;
    background: var(--colorbackbody, #2a2a30);
    color: var(--colortext, #e0e0e0);
    border: 1px solid var(--colorboxbordertitle1, #555);
    border-radius: 4px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    min-height: 60px;
    resize: vertical;
}
.bericht-page-note textarea:focus {
    outline: 2px solid var(--colortextlink, #7aa2f7);
    outline-offset: -1px;
}

/* Generische Input-Styles im Editor — Fallback damit alles zum Dark-Theme passt */
.bericht-editor textarea,
.bericht-editor input[type="text"],
.bericht-editor input[type="number"],
.bericht-editor input[type="email"],
.bericht-editor input[type="search"] {
    background: var(--colorbackbody, #2a2a30);
    color: var(--colortext, #e0e0e0);
    border: 1px solid var(--colorboxbordertitle1, #555);
    border-radius: 4px;
    padding: 8px 10px;
    font-size: 14px;
    font-family: inherit;
}
.bericht-editor textarea:focus,
.bericht-editor input:focus {
    outline: 2px solid var(--colortextlink, #7aa2f7);
    outline-offset: -1px;
}

.bericht-pages-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.bericht-pages-header h4 { margin: 0; }
#btn-toggle-thumb-bg {
    background: transparent;
    border: 1px solid var(--colorboxbordertitle1, #555);
    color: var(--colortext, inherit);
    border-radius: 3px;
    cursor: pointer;
    padding: 2px 6px;
}

.page-list { display: flex; flex-direction: column; gap: 8px; }

.page-thumb {
    border: 2px solid var(--colorboxbordertitle1, #444);
    border-radius: 3px;
    cursor: pointer;
    position: relative;
    transition: border-color 0.15s, box-shadow 0.15s;
    overflow: hidden;
}
.page-thumb:hover { border-color: var(--colortextlink, #888); }
.page-thumb.active {
    border-color: var(--colortextlink, #337ab7);
    box-shadow: 0 0 0 3px rgba(51,122,183,0.55), 0 2px 12px rgba(51,122,183,0.3);
    transform: scale(1.02);
}
.page-thumb.active .page-thumb-label {
    background: var(--colorbackhmenu1, #337ab7);
    color: #fff;
    font-weight: 600;
}

/* "Papier"-Look — heller Default, mit Papier-Schatten */
.page-list.paper-light .page-thumb-paper { background: #ffffff; }
.page-list.paper-dark  .page-thumb-paper { background: #1e1e22; }

.page-thumb-paper {
    width: 100%;
    aspect-ratio: 1 / 1.414; /* DIN A4 Verhältnis (Hochformat) */
    display: flex; align-items: center; justify-content: center;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.1);
    overflow: hidden;
}
.page-thumb-paper canvas.thumb-canvas {
    max-width: 100%;
    max-height: 100%;
    display: block;
}

.page-thumb-label {
    text-align: center;
    font-size: 11px;
    padding: 3px 0;
    background: var(--colorbacktitle1, #2a2a30);
    color: var(--colortext, #ddd);
    border-top: 1px solid var(--colorboxbordertitle1, #444);
}

.page-thumb-actions { position: absolute; top: 4px; right: 4px; }
.thumb-del, .thumb-verify {
    background: rgba(0,0,0,0.6);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 3px;
    cursor: pointer;
    padding: 2px 6px;
    font-size: 12px;
    margin-left: 2px;
}
.thumb-del:hover { background: rgba(217,83,79,0.9); }
.thumb-verify:hover { background: rgba(92,184,92,0.9); }

.page-thumb.page-signature {
    border-color: #5cb85c;
    box-shadow: 0 0 0 1px rgba(92,184,92,0.4);
}
.page-thumb.page-signature .sig-badge {
    margin-left: 4px;
    font-size: 12px;
}

.bericht-actions {
    margin-top: 16px;
    display: flex; gap: 8px; justify-content: flex-end;
}
.bericht-actions .butAction,
.bericht-actions .butActionConfirm,
.bericht-actions .butActionDelete {
    background: var(--colorbacktitle1, #f5f5f5);
    color: var(--colortext, #222);
    border: 1px solid var(--colorboxbordertitle1, #ccc);
    padding: 8px 16px;
    border-radius: 4px;
    text-decoration: none;
    cursor: pointer;
    font-weight: 500;
}
.bericht-actions .butActionConfirm {
    background: var(--colorbackhmenu1, #337ab7);
    color: var(--colortextbackhmenu, #fff);
    border-color: var(--colorbackhmenu1, #2e6da4);
}
.bericht-actions .butActionDelete {
    background: var(--colorbackerror, #d9534f);
    color: #fff;
    border-color: var(--colorbackerror, #d43f3a);
}
.bericht-actions .butAction:hover,
.bericht-actions .butActionConfirm:hover,
.bericht-actions .butActionDelete:hover {
    filter: brightness(1.1);
}

.bericht-toast {
    position: fixed; top: 20px; right: 20px;
    background: #5cb85c; color: #fff; padding: 12px 20px;
    border-radius: 4px; box-shadow: 0 2px 12px rgba(0,0,0,0.4);
    z-index: 9999; animation: fadeIn 0.2s;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; } }

.bericht-setup-section {
    background: var(--colorbacktitle1, #fff);
    color: var(--colortext, inherit);
    border: 1px solid var(--colorboxbordertitle1, #e3e3e7);
    border-radius: 6px;
    padding: 16px;
    margin-bottom: 16px;
}
.bericht-setup-section h3 { margin-top: 0; color: var(--colortextlink, inherit); }

@media (max-width: 1100px) {
    .bericht-layout { grid-template-columns: 1fr; }
    .bericht-attachments, .bericht-pages { max-height: 300px; }
}

/* PDF-Vorschau-Modal */
.bericht-modal {
    position: fixed;
    inset: 0;
    z-index: 9998;
}
.bericht-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.7);
}
.bericht-modal-content {
    position: absolute;
    top: 5vh; left: 5vw;
    right: 5vw; bottom: 5vh;
    background: var(--colorbacktitle1, #2a2a30);
    border: 1px solid var(--colorboxbordertitle1, #555);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
    display: flex; flex-direction: column;
    overflow: hidden;
}
.bericht-modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 16px;
    background: var(--colorbackbody, #222);
    border-bottom: 1px solid var(--colorboxbordertitle1, #555);
}
.bericht-modal-header h3 { margin: 0; font-size: 16px; color: var(--colortext, #ddd); }
.bericht-modal-header button {
    background: transparent;
    border: 1px solid var(--colorboxbordertitle1, #555);
    color: var(--colortext, #ddd);
    border-radius: 3px;
    padding: 4px 12px;
    cursor: pointer;
    font-size: 16px;
}
.bericht-modal-header button:hover { background: rgba(255,255,255,0.1); }
.bericht-modal-body {
    flex: 1;
    overflow: hidden;
}
.bericht-modal-body iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: #444;
}

.qr-modal {
    top: 10vh; left: 50%; right: auto; bottom: auto;
    transform: translateX(-50%);
    width: 380px; max-width: 90vw;
    height: auto; max-height: 80vh;
}
.qr-modal-body { padding: 20px; text-align: center; }
#qr-code-container {
    display: inline-block;
    background: #fff;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 16px;
}
.qr-info p { margin: 6px 0; font-size: 13px; color: var(--colortext, #ddd); }
.qr-url-display { word-break: break-all; }
.qr-url-display a { color: var(--colortextlink, #7aa2f7); }
.qr-status { padding: 8px; background: var(--colorbackbody, #1a1a1f); border-radius: 4px; margin-top: 12px; }

/* ---------- dolModal (alert/confirm/prompt Ersatz) ---------- */
.bericht-dolmodal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 100000;
    display: flex; align-items: center; justify-content: center;
}
.bericht-dolmodal {
    background: var(--colorbackbody, #22222a);
    color: var(--colortext, #eee);
    border: 1px solid var(--colorboxbordertitle1, #444);
    border-radius: 6px;
    min-width: 320px; max-width: 520px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.6);
    font-size: 14px;
}
.bericht-dolmodal-title {
    padding: 10px 14px;
    font-weight: bold;
    background: var(--colorbacktitle1, #2d2d38);
    border-bottom: 1px solid var(--colorboxbordertitle1, #444);
    border-radius: 6px 6px 0 0;
}
.bericht-dolmodal-body {
    padding: 16px 14px;
    line-height: 1.5;
    white-space: pre-wrap;
}
.bericht-dolmodal-input {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 6px 8px;
    background: var(--colorbackbody, #1a1a1f);
    color: var(--colortext, #eee);
    border: 1px solid var(--colorboxbordertitle1, #555);
    border-radius: 3px;
    box-sizing: border-box;
}
.bericht-dolmodal-foot {
    padding: 10px 14px;
    display: flex; gap: 8px; justify-content: flex-end;
    border-top: 1px solid var(--colorboxbordertitle1, #444);
}
