/* 
   E-Dani Pro Suite | Shared Modal Architecture (v1.0)
   Standardized Modals, IFrames, Tabs, and Document Viewers
*/

/* --- MODAL (Unified Suite Style) --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 50000;
    backdrop-filter: blur(6px);
    padding: 0px !important; /* 0px EDGE TO EDGE BUFFER */
}

.modal-content {
    background: white;
    width: 95%;
    max-width: 600px;
    max-height: 92vh;
    border-radius: 10px; /* Unified floating bubble */
    box-shadow: 0 30px 60px -12px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    overflow: hidden; /* clips header top-corners and body bottom-corners */
    animation: modalSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Desktop sizing for large modals - floating with visible backdrop around edges */
#previewModal .modal-content,
#filesModal .modal-content,
#groupDocsModal .modal-content,
#erstModal .modal-content,
#berichtModal .modal-content,
#stammEditModal .modal-content,
#aiViewerModal .modal-content,
.doc-preview-modal .modal-content,
#ooEditorModal .modal-content,
#auditReportModal .modal-content,
#docViewer .modal-content,
#templateToolModal .modal-content,
#templatePreviewModal .modal-content {
    max-width: none !important;
    width: 98vw !important;
    height: 96vh !important;
    max-height: 96vh !important;
    margin: auto !important;
    border-radius: 10px !important; /* Visible rounded corners against blurred backdrop */
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(30px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* --- MODAL SIZE VARIANTS (shared — add ONE class instead of being hardcoded) ---
   The big per-app ID list above (#previewModal, .doc-preview-modal, #docViewer …)
   gives those modals a fullscreen size. New code should instead put a size class on
   .modal-content so any modal — in any app — opts in without editing this file:
     .modal-fullscreen  → near-edge-to-edge (the "1:1"-style big iframe / doc viewer)
     .modal-md          → default ~600px floating bubble (no class needed)
     .modal-sm          → compact dialog / small embedded frame
   Goal: migrate the ID list onto .modal-fullscreen over time, then delete the list. */
.modal-content.modal-fullscreen {
    /* Edge-to-edge, no gutter — the "1:1"/.doc-frame look. */
    max-width: none;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
}
.modal-content.modal-sm { max-width: 440px; }
.modal-content.modal-lg { max-width: 820px; }   /* tables / legends (2026-09-16, first user: IW Coaching-Termin legend) */

.modal-header {
    padding: var(--space-sm) 15px;
    background: var(--c-primary, var(--primary-color, #001f54));
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.modal-header h3, .modal-header h4 { 
    margin: 0; 
    font-size: 1rem; 
    font-weight: 700;
    color: white; 
    border: none; 
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.modal-close {
    background: rgba(255,255,255,0.1); 
    color: white; 
    border: 1px solid rgba(255,255,255,0.2); 
    padding: 0; 
    width: 28px;
    height: 28px;
    border-radius: var(--radius-xs); 
    cursor: pointer; 
    font-size: 14px; 
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.modal-close:hover { background: #dc3545; border-color: #dc3545; }

.modal-body { 
    padding: var(--space-2xl); 
    overflow-y: auto; 
    line-height: 1.5; 
    color: #1e293b; 
    flex: 1;
    min-height: 0;
}

.modal-footer {
    padding: var(--space-lg) var(--space-2xl);
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: flex-end;
    gap: var(--space-md);
    flex-shrink: 0;
}

/* --- TABS SYSTEM --- */
.modal-tabs {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px;
    height: 48px;
    flex-shrink: 0;
    gap: var(--space-md);
}

.modal-tabs-left {
    display: flex;
    gap: var(--space-2xs);
    height: 100%;
    align-items: flex-end;
}

.modal-tabs-right {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    background: white;
    padding: var(--space-2xs) 15px;
    border-radius: var(--radius-2xl);
    border: 1px solid #e2e8f0;
    height: 32px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    flex-shrink: 0;
}

.modal-tab {
    padding: 0 15px;
    background: #e2e8f0;
    color: #475569;
    border: 1px solid #cbd5e1;
    border-bottom: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    transition: all 0.2s;
    height: 34px;
    display: flex;
    align-items: center;
    white-space: nowrap;
}

.modal-tab:hover { background: #cbd5e1; }
.modal-tab.active {
    background: white !important;
    color: var(--primary-color) !important;
    border-color: #e2e8f0 !important;
    border-bottom: 2px solid white !important;
    margin-bottom: -1px;
    z-index: 2;
    opacity: 1;
}

.modal-breadcrumbs {
    font-size: 11px;
    color: #64748b;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 5px;
    flex: 1;
    justify-content: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin: 0 15px;
}

/* --- FRAMED IFRAMES --- */
.modal-body-framed {
    position: relative !important;
    padding: 0 !important;
    background: #525659 !important; /* Dark PDF-style frame (only visible for actual iframes) */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex: 1;
    min-height: 0;
}

.modal-body-framed iframe,
.modal-body-framed .inner-frame {
    flex: 1;
    width: 100%;
    height: 100%;
    border: none !important;
    border-radius: 0 !important;
    background: white;
    overflow-y: auto;
    box-shadow: none !important;
}

/* Content padding for div-based frames so text doesn't touch the edge */
.modal-body-framed .inner-frame {
    padding: var(--space-xl) !important;
    box-sizing: border-box;
}

@media (max-width: 1024px) {
    .modal-body-framed .inner-frame {
        padding: var(--space-2xs) !important; /* Minimal gutter on mobile */
    }
}

/* Mobile/tablet dynamic fit-to-screen scaling is handled via JS adjustDocPreviewScale */


/* --- DOCUMENT VIEWER (Hidden by default) --- */
.doc-viewer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 50000;
    padding: 0;
    backdrop-filter: blur(5px);
}
.doc-frame {
    width: 100vw;
    max-width: none;
    height: 100vh;
    background: white;
    border-radius: 0;
    box-shadow: none;
    border: none;
    margin: 0;
}

/* Enforce uniform card height in modal file lists */
.list .card {
    height: 180px !important;
    min-height: 180px !important;
    max-height: 180px !important;
    display: flex;
    flex-direction: column;
}

/* --- FLOATING HELP & QUICK GUIDE --- */
.help-fab {
    position: fixed !important;
    bottom: 30px !important;
    right: 30px !important;
    width: 55px !important;
    height: 55px !important;
    min-width: 55px !important;
    min-height: 55px !important;
    background: var(--primary-color, #001f54) !important;
    color: white !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 28px !important;
    font-weight: bold !important;
    cursor: pointer !important;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3) !important;
    border: 2px solid white !important;
    z-index: 21000 !important;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important;
    padding: 0 !important;
    margin: 0 !important;
    line-height: 1 !important;
}
.help-fab:hover {
    transform: scale(1.1) rotate(15deg) !important;
    background: var(--accent-color, #fd7e14) !important;
    box-shadow: 0 6px 20px rgba(0,0,0,0.4) !important;
}
@media (max-width: 1024px) {
    /* The bottom dock is gone (replaced by the round .menu-fab), so the help button
       can sit low in the corner — mirrors the menu-fab on the left. max() (not +) so
       we don't stack 30px on top of the iPhone home-indicator inset (~34px). */
    .help-fab {
        bottom: max(20px, calc(env(safe-area-inset-bottom) - 6px)) !important;
    }
}

#quickHelpModal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(8px);
    z-index: 100000;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.qh-container {
    background: #fff;
    width: 100%;
    max-width: 1000px;
    height: 90vh;
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}

.qh-header {
    background: var(--c-primary, var(--primary-color, #001f54));
    color: white;
    padding: var(--space-2xl) 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.qh-content {
    flex: 1;
    overflow-y: auto;
    padding: 40px;
    line-height: 1.6;
    color: #333;
    background: #fdfdfd;
}

.qh-content h1, .qh-content h2 { color: var(--c-primary, var(--primary-color, #001f54)); border-bottom: 2px solid #eee; padding-bottom: var(--space-md); margin-top: 30px; }
.qh-content h3 { color: #6f42c1; margin-top: var(--space-2xl); }
.qh-content code { background: #eee; padding: var(--space-3xs) 5px; border-radius: var(--radius-xs); font-family: monospace; }
.qh-content blockquote { border-left: 5px solid #ffc107; background: #fff9e6; padding: 15px; margin: var(--space-2xl) 0; border-radius: 0 var(--radius-md) var(--radius-md) 0; }
.qh-content hr { border: none; border-top: 1px solid #eee; margin: 30px 0; }

.qh-close {
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}
.qh-close:hover { background: rgba(255,255,255,0.2); }

/* ── P2: Handbuch overlay inner frame — mobile 2px gutter ── */
@media (max-width: 1024px) {
    .hb-overlay-inner {
        inset: 2px !important;
        border-radius: var(--radius-md) !important;
    }
}

/* ── MOBILE: Quick-Help popup (≤1024px) ── */
@media (max-width: 1024px) {
    /* P0: Reduce overlay padding so container fills the screen */
    #quickHelpModal {
        padding: var(--space-2xs);
    }

    /* P0: Taller container, smaller radius to match 2px gutter standard */
    .qh-container {
        height: 96vh;
        max-height: 96dvh;
        border-radius: var(--radius-md);
    }

    /* P0: Hide the long "→ Vollständiges Handbuch" link — it pushes × off-screen.
       The manual is still reachable via the main navigation. */
    #qhHandbuchLink {
        display: none !important;
    }

    /* P0: Guarantee the × button is always visible and tappable (≥44×44px) */
    .qh-close {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        flex-shrink: 0;
    }

    /* P0: Standard modal close button — meet 44×44px touch-target on mobile */
    .modal-close {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        font-size: 16px;
    }

    /* P1: Compact header on mobile */
    .qh-header {
        padding: var(--space-md) var(--space-lg);
    }
    .qh-header h2 {
        font-size: 1.1rem;
    }

    /* P1: Compact content area */
    .qh-content {
        padding: var(--space-lg);
    }

    /* P1: Collapse the JS-rendered 200px 1fr grid to single column so label and
       description stack instead of being crushed side-by-side on 420px screens. */
    .qh-content div[style*="200px 1fr"] {
        grid-template-columns: 1fr !important;
        gap: var(--space-3xs) !important;
    }

    /* P1: Belt-and-suspenders — stack any real <table> inside quick-help too */
    .qh-content table,
    .qh-content tbody,
    .qh-content tr,
    .qh-content td,
    .qh-content th {
        display: block;
        width: 100% !important;
    }
    .qh-content thead {
        display: none;
    }
    .qh-content td {
        padding: var(--space-3xs) 0;
    }
}

/* Mobile Modal Header adjustments to prevent button cutoff */
@media (max-width: 600px) {
    .modal-header {
        flex-wrap: nowrap !important;
        gap: var(--space-xs) !important;
        padding: var(--space-xs) var(--space-md) !important;
        height: 48px !important;
    }
    .modal-header h3, 
    .modal-header h4 {
        font-size: 0.9rem !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        min-width: 0 !important;
        flex: 1 !important;
    }
    .modal-header .btn-text {
        display: none !important;
    }
    .modal-header button {
        padding: var(--space-xs) var(--space-md) !important;
        font-size: 11px !important;
        flex-shrink: 0 !important;
    }
    /* Owner 2026-10-02: "reduce the gaps to the screen edge to a minimum for all mobile windows".
       Measured 393px on hub/hw/iw/schule/projekte: card 95% wide (14px edge) + 16px body padding put text
       29px from the screen edge; close button 31px (<44px touch minimum). Phone: edge-to-edge sheet with a
       small top inset, 8px body/footer padding, 44px close. */
    .modal-content {
        width: 100% !important;     /* beats inline `width:95%` on some app modals (schule #projektModal) */
        max-width: 100% !important;
        max-height: 100dvh;
        border-radius: 12px 12px 0 0;
    }
    /* Bottom sheet: a short dialog sits on the bottom edge (matching the 12px top-only radius) instead of
       floating mid-screen with square bottom corners. */
    .modal-overlay { align-items: flex-end !important; }
    .modal-body { padding: var(--space-sm, 8px); }
    .modal-footer { padding: var(--space-sm, 8px); padding-bottom: calc(var(--space-sm, 8px) + env(safe-area-inset-bottom, 0px)); flex-wrap: wrap; }
    /* Measured IW #newCourseWizardModal: two nowrap buttons wider than 393px overflowed the footer to the
       LEFT (justify-content:flex-end), clipping "Abbrechen". Buttons share the row and may wrap text. */
    .modal-footer > .btn, .modal-footer > button { flex: 1 1 auto; min-width: 0; white-space: normal; min-height: 44px; }
    .modal-close {
        width: 44px !important;
        height: 44px !important;
        min-width: 44px !important;
        min-height: 44px !important;
        flex-shrink: 0 !important;
        font-size: 18px !important;
    }
    /* `.modal-header button` (0,1,1) shrinks every header button to 11px and outranks `.modal-close` (0,1,0). */
    .modal-header .modal-close {
        font-size: 18px !important;
        padding: 0 !important;
    }
    #stammEditModal .modal-content,
    #previewModal .modal-content,
    #filesModal .modal-content,
    #erstModal .modal-content,
    #berichtModal .modal-content,
    #aiViewerModal .modal-content,
    .doc-preview-modal .modal-content,
    #ooEditorModal .modal-content,
    #auditReportModal .modal-content,
    #docViewer .modal-content,
    #templateToolModal .modal-content,
    #templatePreviewModal .modal-content {
        width: 100vw !important;
        height: 100vh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }
    .modal-body-framed .inner-frame {
        padding: 0 !important;
    }
}

