/* =====================================================
 *  EDUGROWN CONTENT PROTECTOR — PUBLIC STYLES (v2)
 *  Paginated PDF-style viewer with page navigation
 * ===================================================== */

.egcp-viewer,
.egcp-viewer * {
    box-sizing: border-box;
}

.egcp-viewer {
    --egcp-bg: #525659;
    --egcp-page-bg: #ffffff;
    --egcp-toolbar: #323639;
    --egcp-toolbar-fg: #f1f1f1;
    --egcp-accent: #4f46e5;
    --egcp-zoom: 1;

    position: relative;
    width: 100%;
    max-width: 100%;
    background: var(--egcp-bg);
    border-radius: 8px;
    overflow: hidden;
    margin: 24px 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);

    /* Disable selection */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

/* ===== TOOLBAR ===== */
.egcp-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 16px;
    background: var(--egcp-toolbar);
    color: var(--egcp-toolbar-fg);
    border-bottom: 1px solid rgba(0, 0, 0, 0.3);
    flex-wrap: wrap;
}
.egcp-toolbar-left,
.egcp-toolbar-center,
.egcp-toolbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
}
.egcp-toolbar-left { flex: 1 1 auto; min-width: 0; }
.egcp-toolbar-center {
    flex: 0 0 auto;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    padding: 3px 6px;
}

.egcp-doc-title {
    font-size: 14px;
    font-weight: 600;
    color: #f5f5f5;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.egcp-tb-btn {
    width: 34px;
    height: 34px;
    border-radius: 7px;
    background: transparent;
    border: none;
    color: var(--egcp-toolbar-fg);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s, transform 0.1s;
}
.egcp-tb-btn:hover { background: rgba(255, 255, 255, 0.12); }
.egcp-tb-btn:active { transform: scale(0.94); }
.egcp-tb-btn:focus { outline: 2px solid rgba(255, 255, 255, 0.3); outline-offset: 1px; }
.egcp-tb-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.egcp-tb-btn:disabled:hover { background: transparent; }

.egcp-tb-divider {
    width: 1px;
    height: 22px;
    background: rgba(255, 255, 255, 0.18);
    margin: 0 4px;
}

.egcp-zoom-level {
    font-size: 12px;
    font-weight: 600;
    color: #e5e5e5;
    min-width: 46px;
    text-align: center;
    padding: 0 4px;
    letter-spacing: 0.3px;
}

/* ===== PAGE INDICATOR ===== */
.egcp-page-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 6px;
}
.egcp-page-input {
    width: 44px;
    height: 28px;
    text-align: center;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.96);
    color: #1f2937;
    font-size: 13px;
    font-weight: 600;
    padding: 0;
    -moz-appearance: textfield;
}
.egcp-page-input::-webkit-outer-spin-button,
.egcp-page-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.egcp-page-input:focus {
    outline: none;
    border-color: var(--egcp-accent);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.4);
}
.egcp-page-of {
    font-size: 12px;
    color: #cfd1d3;
    font-weight: 500;
    white-space: nowrap;
}
.egcp-page-total { color: #fff; font-weight: 700; }

/* ===== DOC AREA ===== */
.egcp-doc-area {
    overflow: auto;
    max-height: 88vh;
    padding: 28px 18px;
    background: var(--egcp-bg);
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}
.egcp-doc-area::-webkit-scrollbar { width: 12px; height: 12px; }
.egcp-doc-area::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.2); }
.egcp-doc-area::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    border: 2px solid var(--egcp-bg);
}
.egcp-doc-area::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.3); }

/* ===== PAGE WRAP ===== */
.egcp-page-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    transform-origin: top center;
    transform: scale(var(--egcp-zoom));
    transition: transform 0.18s ease-out;
}

/* ===== PAGE SHEET ===== */
.egcp-page {
    position: relative;
    background: var(--egcp-page-bg);
    width: 100%;
    max-width: 850px;
    min-height: 1100px;
    padding: 64px 72px 80px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.28), 0 1px 3px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    color: #1a1a1a;
    border-radius: 2px;
    scroll-margin-top: 16px;
}

.egcp-page-number {
    position: absolute;
    top: 18px;
    right: 22px;
    font-size: 11px;
    font-weight: 600;
    color: #9ca3af;
    letter-spacing: 0.5px;
    background: #f9fafb;
    padding: 3px 9px;
    border-radius: 999px;
    border: 1px solid #f3f4f6;
    z-index: 5;
    pointer-events: none;
}

/* ===== WATERMARK ===== */
.egcp-watermark-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
    display: flex;
    flex-wrap: wrap;
    /* space-around distributes rows evenly across the full layer height
       so the watermark covers the entire page after diagonal rotation
       (flex-start packed all rows at the top, leaving the bottom half empty) */
    align-content: space-around;
    justify-content: center;
    transform: rotate(-30deg);
    transform-origin: center;
    width: 200%;
    height: 200%;
    top: -50%;
    left: -50%;
}
.egcp-wm-text {
    flex: 0 0 auto;
    width: 33.333%;
    padding: 50px 30px;
    font-size: 18px;
    font-weight: 700;
    color: var(--egcp-wm-rgba, rgba(0, 0, 0, 0.18));
    letter-spacing: 1.5px;
    text-align: center;
    white-space: nowrap;
    text-transform: lowercase;
    pointer-events: none;
    -webkit-user-select: none;
    user-select: none;
}

/* ===== CONTENT ===== */
.egcp-content {
    position: relative;
    z-index: 2;
    color: #1a1a1a;
    font-size: 16px;
    line-height: 1.75;
    -webkit-user-select: none;
    user-select: none;
}
.egcp-content h1, .egcp-content h2, .egcp-content h3, .egcp-content h4 {
    color: #111827;
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    line-height: 1.3;
}
.egcp-content h1 { font-size: 26px; font-weight: 700; }
.egcp-content h2 { font-size: 22px; font-weight: 700; }
.egcp-content h3 { font-size: 18px; font-weight: 600; }
.egcp-content h4 { font-size: 16px; font-weight: 600; }
.egcp-content p {
    display: block;
    margin: 0 0 1.25em;
    padding: 0;
}
.egcp-content p:last-child { margin-bottom: 0; }
.egcp-content p:empty { display: none; }
.egcp-content br { display: block; content: ""; margin-top: 0.5em; }
.egcp-content strong, .egcp-content b {
    color: #0f172a;
    font-weight: 700;
}
.egcp-content ul, .egcp-content ol { margin: 0 0 1em 0; padding-left: 1.6em; }
.egcp-content li { margin-bottom: 0.4em; }
.egcp-content blockquote {
    border-left: 3px solid var(--egcp-accent);
    margin: 1em 0;
    padding: 0.5em 1em;
    background: #f9fafb;
    color: #4b5563;
    font-style: italic;
    border-radius: 0 6px 6px 0;
}
.egcp-content img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    pointer-events: none;
}
.egcp-content a {
    color: var(--egcp-accent);
    text-decoration: underline;
}
.egcp-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
}
.egcp-content th, .egcp-content td {
    border: 1px solid #e5e7eb;
    padding: 8px 12px;
    text-align: left;
}
.egcp-content th { background: #f3f4f6; font-weight: 600; }
.egcp-content code {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: "SF Mono", Menlo, Monaco, Consolas, monospace;
}
.egcp-content pre {
    background: #1e293b;
    color: #f8fafc;
    padding: 14px 18px;
    border-radius: 7px;
    overflow-x: auto;
    margin: 1em 0;
}
.egcp-content pre code { background: transparent; color: inherit; padding: 0; }

/* Hide any leftover page-break HR */
.egcp-content hr.egcp-pagebreak { display: none !important; }

/* ===== SHIELD (transparent overlay to block right-click & selection) ===== */
.egcp-shield {
    position: absolute;
    inset: 0;
    z-index: 3;
    background: transparent;
    pointer-events: none;
}

/* ===== FOOTER ===== */
.egcp-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 16px;
    background: var(--egcp-toolbar);
    color: rgba(255, 255, 255, 0.6);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.3px;
    border-top: 1px solid rgba(0, 0, 0, 0.3);
}
.egcp-footer .dashicons { font-size: 14px; width: 14px; height: 14px; }

/* ===== IFRAME VIEWER (Google Drive) ===== */
.egcp-viewer-iframe .egcp-iframe-area {
    position: relative;
    padding: 0;
    height: 88vh;
    min-height: 600px;
    overflow: hidden;
    background: var(--egcp-bg);
    -webkit-user-select: none;
    user-select: none;
}
.egcp-viewer-iframe .egcp-watermark-layer {
    z-index: 5;
    pointer-events: none;
}
.egcp-viewer-iframe .egcp-wm-text {
    /* color & opacity inherited from CSS vars; just stronger size/weight for iframe overlay */
    font-size: 22px;
    font-weight: 800;
}
.egcp-embed-frame {
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
    display: block;
    position: relative;
    z-index: 1;
    -webkit-user-select: none;
    user-select: none;
    pointer-events: auto;
}
.egcp-iframe-shield {
    position: absolute;
    inset: 0;
    z-index: 4;
    /* Allow scrolling through but absorb mouse events from edges */
    pointer-events: none;
    background: transparent;
}
.egcp-viewer-iframe:fullscreen .egcp-iframe-area,
.egcp-viewer-iframe.egcp-ios-fullscreen .egcp-iframe-area {
    height: calc(100vh - 90px);
    flex: 1;
}

/* ===== PDF VIEWER (PDF.js canvas) ===== */
.egcp-pdf-canvas {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
    /* Prevent any text selection / drag */
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
    user-drag: none;
    pointer-events: auto;
}
.egcp-pdf-content {
    padding: 0 !important;
    background: transparent !important;
}
.egcp-viewer-pdf .egcp-page {
    padding: 0;
    overflow: hidden;
    background: #fff;
}
/* Critical: PDF canvas is opaque pixels, so watermark must sit ABOVE it */
.egcp-viewer-pdf .egcp-watermark-layer {
    z-index: 4 !important;
}
.egcp-viewer-pdf .egcp-page-number {
    z-index: 6;
}

/* PDF loading spinner */
.egcp-pdf-loading {
    text-align: center;
    color: rgba(255, 255, 255, 0.85);
    padding: 60px 20px;
}
.egcp-pdf-loading p {
    margin: 16px 0 0;
    font-size: 13px;
    font-weight: 500;
}
.egcp-spinner {
    display: inline-block;
    width: 36px;
    height: 36px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: egcp-spin 0.7s linear infinite;
}
@keyframes egcp-spin {
    to { transform: rotate(360deg); }
}

/* ===== WATERMARK ORIENTATION ===== */
.egcp-orient-diagonal .egcp-watermark-layer {
    transform: rotate(-30deg);
}
.egcp-orient-horizontal .egcp-watermark-layer {
    transform: rotate(0deg);
}
.egcp-orient-vertical .egcp-watermark-layer {
    transform: rotate(-90deg);
}

/* ===== TITLE HIDE ===== */
.egcp-no-title .egcp-doc-title {
    display: none;
}

/* ===== DOWNLOAD BUTTON ===== */
.egcp-download-btn {
    text-decoration: none !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
}
.egcp-download-btn .dashicons {
    font-size: 18px;
    width: 18px;
    height: 18px;
}

/* ===== ERROR ===== */
.egcp-error {
    padding: 20px;
    background: #fee2e2;
    border: 1px solid #fca5a5;
    color: #991b1b;
    border-radius: 8px;
    text-align: center;
    font-weight: 500;
}

/* ===== FULLSCREEN ===== */
.egcp-viewer:fullscreen,
.egcp-viewer.egcp-ios-fullscreen {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    border-radius: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
}
.egcp-viewer:fullscreen .egcp-doc-area,
.egcp-viewer.egcp-ios-fullscreen .egcp-doc-area {
    max-height: none;
    flex: 1;
}
.egcp-viewer.egcp-ios-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 999999;
}

/* ===== PRINT — block printing entirely ===== */
@media print {
    .egcp-viewer { display: none !important; }
    body::after {
        content: "Printing is disabled for this protected content.";
        display: block;
        font-size: 18px;
        text-align: center;
        padding: 40px;
    }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
    .egcp-page { padding: 44px 32px 56px; min-height: 900px; }
    .egcp-content { font-size: 15px; }
    .egcp-doc-title { max-width: 180px; font-size: 13px; }
    /* Watermark slightly smaller on tablet so text fits each rotated cell */
    .egcp-wm-text {
        font-size: 14px;
        padding: 36px 20px;
        letter-spacing: 1px;
    }
    .egcp-viewer-iframe .egcp-wm-text {
        font-size: 16px;
        font-weight: 700;
    }
}
@media (max-width: 600px) {
    .egcp-toolbar { padding: 8px 10px; gap: 6px; }
    .egcp-toolbar-left { order: 1; flex: 1 1 100%; justify-content: center; }
    .egcp-toolbar-center { order: 2; }
    .egcp-toolbar-right { order: 3; }
    .egcp-doc-title { max-width: 100%; text-align: center; }
    .egcp-page { padding: 32px 22px 44px; min-height: 700px; }
    .egcp-tb-btn { width: 32px; height: 32px; }
    .egcp-zoom-level { font-size: 11px; min-width: 38px; }
    .egcp-page-input { width: 38px; height: 26px; font-size: 12px; }
    .egcp-page-of { font-size: 11px; }
    .egcp-tb-divider { display: none; }
    .egcp-doc-area { padding: 18px 8px; }
    .egcp-page-wrap { gap: 16px; }
    .egcp-page-number { top: 12px; right: 14px; font-size: 10px; }
    .egcp-content { font-size: 14px; line-height: 1.65; }
    /* Watermark — small mobile: even smaller font + tighter spacing so default
       30-char watermark text fits inside narrow rotated cells without overlap */
    .egcp-wm-text {
        font-size: 11px;
        padding: 26px 14px;
        letter-spacing: 0.5px;
    }
    .egcp-viewer-iframe .egcp-wm-text {
        font-size: 12px;
        font-weight: 700;
        letter-spacing: 0.5px;
    }
}
@media (max-width: 380px) {
    .egcp-wm-text {
        font-size: 9px;
        padding: 22px 10px;
        letter-spacing: 0.3px;
    }
    .egcp-viewer-iframe .egcp-wm-text {
        font-size: 10px;
        letter-spacing: 0.3px;
    }
}
