/* ── Reset & base ─────────────────────────────────────────────────────────── */
#apl-modal *,
#apl-modal *::before,
#apl-modal *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Overlay ──────────────────────────────────────────────────────────────── */
#apl-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 999999;
    align-items: stretch;
    justify-content: center;
}
#apl-modal.apl-open { display: flex; }

/* ── Inner layout ─────────────────────────────────────────────────────────── */
.apl-inner {
    display: flex;
    width: 95vw;
    max-width: 1300px;
    height: 90vh;
    margin: auto;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 24px 80px rgba(0,0,0,0.5);
    background: #fff;
}

/* ── PDF pane ─────────────────────────────────────────────────────────────── */
.apl-pdf-pane {
    flex: 1 1 0;
    min-width: 0;
    background: #404040;
    display: flex;
    flex-direction: column;
}

/* PDF toolbar */
.apl-pdf-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    background: #1e293b;
    color: #e2e8f0;
    flex-shrink: 0;
    flex-wrap: wrap;
}
.apl-pdf-toolbar-left {
    display: flex;
    align-items: center;
    min-width: 0;
    flex: 1 1 120px;
}
.apl-doc-title {
    font-size: 13.5px;
    font-weight: 600;
    color: #f1f5f9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.apl-pdf-toolbar-center {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.apl-tool-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background: transparent;
    border: none;
    border-radius: 7px;
    color: #cbd5e1;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}
.apl-tool-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
.apl-tool-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.apl-page-info {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: #cbd5e1;
    white-space: nowrap;
}
.apl-page-info input {
    width: 42px;
    text-align: center;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    color: #f1f5f9;
    border-radius: 5px;
    font-size: 13px;
    padding: 4px 2px;
}
.apl-page-info input:focus { outline: none; border-color: #3b82f6; }

.apl-toolbar-divider {
    width: 1px;
    height: 20px;
    background: rgba(255,255,255,0.15);
    margin: 0 4px;
    flex-shrink: 0;
}
.apl-zoom-level {
    font-size: 12.5px;
    color: #cbd5e1;
    min-width: 42px;
    text-align: center;
    white-space: nowrap;
}

/* Canvas area */
.apl-canvas-wrap {
    position: relative;
    flex: 1 1 auto;
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 24px;
    background: #404040;
}
#apl-canvas {
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
    background: #fff;
    visibility: hidden;
    max-width: 100%;
}

/* PDF loading state */
.apl-pdf-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    color: #cbd5e1;
    font-size: 13px;
}

/* PDF error state */
.apl-pdf-error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 320px;
    text-align: center;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 10px;
    padding: 20px 22px;
    color: #dc2626;
}
.apl-pdf-error strong { display: block; margin-bottom: 6px; font-size: 14px; }
.apl-pdf-error p { margin: 0; font-size: 13px; line-height: 1.5; color: #b91c1c; }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.apl-sidebar {
    width: 340px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: #f8fafc;
    border-left: 1px solid #e2e8f0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Sidebar header ───────────────────────────────────────────────────────── */
.apl-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    background: #1e293b;
    color: #fff;
    flex-shrink: 0;
}
.apl-sidebar-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.01em;
}

/* #apl-close styles moved to header-actions section */

/* ── Action buttons ───────────────────────────────────────────────────────── */
.apl-actions {
    display: flex;
    gap: 10px;
    padding: 16px;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
    background: #fff;
}

.apl-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    border: 1.5px solid #334155;
    background: #fff;
    color: #334155;
    transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
    line-height: 1.2;
}
.apl-btn:hover {
    background: #1e293b;
    color: #fff;
    border-color: #1e293b;
    box-shadow: 0 2px 8px rgba(30,41,59,0.2);
}
.apl-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.apl-btn svg { flex-shrink: 0; }

/* ── Output area ──────────────────────────────────────────────────────────── */
#apl-output {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    font-size: 14px;
    color: #334155;
    line-height: 1.65;
    scroll-behavior: smooth;
}

/* Scrollbar */
#apl-output::-webkit-scrollbar { width: 5px; }
#apl-output::-webkit-scrollbar-track { background: transparent; }
#apl-output::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 99px; }

/* Placeholder */
.apl-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    height: 100%;
    text-align: center;
    color: #94a3b8;
}
.apl-placeholder p { font-size: 13px; max-width: 200px; }

/* Loading state */
.apl-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 40px 0;
    color: #64748b;
    font-size: 13px;
}
.apl-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #e2e8f0;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: apl-spin 0.7s linear infinite;
}
@keyframes apl-spin { to { transform: rotate(360deg); } }

/* Result content */
.apl-result { animation: apl-fade 0.3s ease; }
@keyframes apl-fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.apl-result-header {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #3b82f6;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e2e8f0;
}

.apl-result-body {
    white-space: pre-wrap;
    word-break: break-word;
}
.apl-result-body strong { font-weight: 700; color: #1e293b; }

/* Error state */
.apl-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 14px;
    color: #dc2626;
    font-size: 13px;
    line-height: 1.5;
}
.apl-error strong { display: block; margin-bottom: 4px; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
    .apl-inner {
        flex-direction: column;
        width: 100vw;
        height: 100dvh;
        border-radius: 0;
    }
    .apl-pdf-pane { flex: 1 1 55%; }
    .apl-sidebar {
        width: 100%;
        max-height: 45%;
    }
    .apl-pdf-toolbar {
        padding: 8px 10px;
        gap: 8px;
    }
    .apl-doc-title { font-size: 12px; }
    .apl-pdf-toolbar-left { flex-basis: 100%; order: 1; }
    .apl-pdf-toolbar-center { order: 2; flex: 1 1 auto; justify-content: center; }
    .apl-tool-btn { width: 30px; height: 30px; }
    .apl-canvas-wrap { padding: 12px; }
    .apl-zoom-level { display: none; }
    .apl-toolbar-divider { display: none; }
}

/* ── Header actions (Download + Print + Close) ──────────────────────────── */
.apl-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.apl-icon-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.15);
    color: #94a3b8;
    width: 32px;
    height: 32px;
    border-radius: 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    padding: 0;
    flex-shrink: 0;
}
.apl-icon-btn:hover {
    background: rgba(255,255,255,0.12);
    color: #fff;
    border-color: rgba(255,255,255,0.3);
}
.apl-icon-btn svg {
    pointer-events: none;
}

/* #apl-close styles moved to header-actions section */

/* ── Numbered list items in AI result ───────────────────────────────────── */
.apl-list-item {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin-bottom: 12px;
    line-height: 1.6;
}
.apl-num {
    font-weight: 700;
    color: #3b82f6;
    flex-shrink: 0;
    min-width: 22px;
}
