/* ── SmartDoc Frontend Modal — Redesigned with Sidebar ──────────────── */

/* ── Scoped Font Reset — all modal elements use Roboto ───────────────── */
.sdap-modal-overlay,
.sdap-modal-overlay *,
.sdap-modal-overlay *::before,
.sdap-modal-overlay *::after {
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

/* ── Modal Overlay ───────────────────────────────────────────────────── */
.sdap-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    backdrop-filter: blur(4px);
}

.sdap-modal.sdap-modal-with-sidebar {
    background: #fff;
    width: 100vw;
    height: 100vh;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 0;
    animation: sdap-modal-in 0.25s ease-out;
}

@keyframes sdap-modal-in {
    from {
        opacity: 0;
        transform: scale(0.98);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ── Top Bar ─────────────────────────────────────────────────────────── */
.sdap-modal-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 20px;
    background: #f5f5f5;
    border-bottom: 1px solid #e0e0e0;
    min-height: 44px;
    flex-shrink: 0;
}

.sdap-topbar-left {
    display: flex;
    align-items: center;
    gap: 24px;
}

.sdap-topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sdap-topbar-link {
    font-size: 13px;
    color: #2271b1;
    text-decoration: none;
    font-weight: 500;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.15s;
}

.sdap-topbar-link:hover {
    background: #e8f0fe;
    color: #135e96;
}

.sdap-topbar-link.sdap-active {
    background: #2271b1;
    color: #fff;
}

.sdap-hotkeys-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 12px;
    color: #666;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.sdap-hotkeys-btn:hover {
    border-color: #2271b1;
    color: #2271b1;
}

.sdap-hotkeys-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 600;
}

/* ── Toggle Switch ───────────────────────────────────────────────────── */
.sdap-toggle-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sdap-toggle-label {
    font-size: 13px;
    color: #555;
    white-space: nowrap;
    user-select: none;
}

.sdap-toggle {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
}

.sdap-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.sdap-toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: #ccc;
    transition: 0.3s;
    border-radius: 22px;
}

.sdap-toggle-slider::before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.sdap-toggle input:checked + .sdap-toggle-slider {
    background-color: #2271b1;
}

.sdap-toggle input:checked + .sdap-toggle-slider::before {
    transform: translateX(18px);
}

/* ── Main Content Area ───────────────────────────────────────────────── */
.sdap-modal-main {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

.sdap-modal-content {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: #f8f8f8;
}

.sdap-modal-content iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* ── Custom PDF.js Viewer ─────────────────────────────────────────────── */
#sdap-front-pdf-view {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.sdap-pdf-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 6px 16px;
    background: #323639;
    border-bottom: 1px solid #222;
    flex-shrink: 0;
    min-height: 40px;
}

.sdap-pdf-nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: rgba(255,255,255,0.1);
    border: none;
    border-radius: 4px;
    color: #ddd;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.sdap-pdf-nav-btn:hover {
    background: rgba(255,255,255,0.2);
    color: #fff;
}

.sdap-pdf-nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.sdap-pdf-page-info {
    color: #ccc;
    font-size: 13px;
    font-weight: 500;
    min-width: 60px;
    text-align: center;
    user-select: none;
}

.sdap-pdf-zoom {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: 12px;
    padding-left: 12px;
    border-left: 1px solid rgba(255,255,255,0.15);
}

#sdap-pdf-zoom-level {
    color: #ccc;
    font-size: 12px;
    min-width: 40px;
    text-align: center;
    user-select: none;
}

.sdap-pdf-canvas-wrap {
    flex: 1;
    overflow: auto;
    padding: 20px;
    background: #525659;
}

.sdap-pdf-pages {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    min-height: 100%;
}

.sdap-pdf-page-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.sdap-pdf-page-canvas {
    box-shadow: 0 2px 12px rgba(0,0,0,0.4);
    background: #fff;
    max-width: none; /* allow zooming beyond container */
}

.sdap-pdf-page-label {
    color: #999;
    font-size: 11px;
    margin-top: 6px;
    user-select: none;
}

#sdap-front-html-view {
    width: 100%;
    height: 100%;
}

#sdap-front-html-content {
    width: 100%;
    height: 100%;
    overflow: auto;
    padding: 0;
    background: #fff;
}

/* Print-friendly mode */
.sdap-print-friendly #sdap-front-html-content {
    max-width: 800px;
    margin: 0 auto;
    padding: 40px;
    font-family: Georgia, 'Times New Roman', serif;
    line-height: 1.8;
}

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.sdap-modal-sidebar {
    width: 340px;
    min-width: 340px;
    background: #fafafa;
    border-left: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    transition: width 0.3s ease, min-width 0.3s ease;
}

.sdap-modal-sidebar.sdap-sidebar-collapsed {
    width: 0;
    min-width: 0;
    border-left: none;
}

.sdap-sidebar-toggle {
    position: absolute;
    left: -28px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 48px;
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-right: none;
    border-radius: 6px 0 0 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    transition: background 0.15s;
}

.sdap-sidebar-toggle:hover {
    background: #eee;
}

.sdap-sidebar-toggle-icon {
    font-size: 18px;
    color: #666;
    transition: transform 0.3s;
}

.sdap-sidebar-collapsed .sdap-sidebar-toggle-icon {
    transform: rotate(180deg);
}

.sdap-sidebar-inner {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

/* ── Document Info ───────────────────────────────────────────────────── */
.sdap-sidebar-section {
    padding-bottom: 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid #e8e8e8;
}

.sdap-doc-title {
    margin: 0 0 8px;
    font-size: 16px;
    font-weight: 700;
    color: #1a1a1a;
    line-height: 1.3;
}

.sdap-doc-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
}

.sdap-meta-item {
    font-size: 12px;
    color: #888;
}

.sdap-doc-desc {
    font-size: 13px;
    color: #555;
    line-height: 1.5;
    margin: 0;
}

/* ── Accordion Sections ──────────────────────────────────────────────── */
.sdap-accordion-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: none;
    border: none;
    padding: 10px 0;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    cursor: pointer;
    text-align: left;
    transition: color 0.15s;
}

.sdap-accordion-toggle:hover {
    color: #2271b1;
}

.sdap-accordion-icon {
    font-size: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.sdap-accordion-icon img {
    width: 16px;
    height: 16px;
    vertical-align: middle;
}

.sdap-chevron {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

.sdap-chevron svg {
    width: 12px;
    height: 12px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sdap-accordion-toggle[aria-expanded="true"] .sdap-chevron {
    transform: rotate(180deg);
}

.sdap-accordion-content {
    padding: 0 0 8px;
}

/* Document Outline */
.sdap-outline-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sdap-outline-list li {
    margin: 0;
}

.sdap-outline-list a {
    display: block;
    padding: 6px 8px;
    font-size: 13px;
    color: #444;
    text-decoration: none;
    border-radius: 4px;
    transition: background 0.15s, color 0.15s;
    line-height: 1.4;
}

.sdap-outline-list a:hover {
    background: #e8f0fe;
    color: #2271b1;
}

.sdap-outline-list .sdap-outline-h2 {
    padding-left: 20px;
}

.sdap-outline-list .sdap-outline-h3 {
    padding-left: 36px;
}

/* ── Outline Active Item ─────────────────────────────────────────────── */
.sdap-outline-list a.sdap-outline-active {
    background: #e8f0fe;
    color: #2271b1;
    font-weight: 600;
}

/* ── Heading Highlight (on outline click) ────────────────────────────── */
.sdap-heading-highlight {
    background: #fff3cd !important;
    border-left: 4px solid #2271b1 !important;
    padding-left: 12px !important;
    border-radius: 4px;
    transition: background 0.3s ease, border-left 0.3s ease;
    animation: sdap-highlight-fade 2.5s ease-out forwards;
}

@keyframes sdap-highlight-fade {
    0% {
        background: #fff3cd;
        border-left-color: #2271b1;
    }
    70% {
        background: #fff3cd;
        border-left-color: #2271b1;
    }
    100% {
        background: transparent;
        border-left-color: transparent;
    }
}

/* Google Translate element */
#sdap-google-translate-element {
    padding: 8px 0;
}

#sdap-google-translate-element .goog-te-gadget {
    font-size: 12px !important;
}

#sdap-google-translate-element select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
}

/* ── Action Buttons ──────────────────────────────────────────────────── */
.sdap-sidebar-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px 0;
    margin-bottom: 16px;
}

.sdap-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    border: none;
}

.sdap-action-btn-primary {
    background: #00a32a;
    color: #fff;
    border: 2px solid #00a32a;
}

.sdap-action-btn-primary:hover {
    background: #008a20;
    border-color: #008a20;
    color: #fff;
}

.sdap-action-btn-outline {
    background: #fff;
    color: #333;
    border: 1px solid #ccc;
}

.sdap-action-btn-outline:hover {
    border-color: #2271b1;
    color: #2271b1;
    background: #f0f7ff;
}

.sdap-btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.sdap-btn-icon svg {
    width: 16px;
    height: 16px;
}

/* ── SmartRoots Branding ─────────────────────────────────────────────── */
.sdap-sidebar-branding {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid #e8e8e8;
    text-align: center;
}

.sdap-brand-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 18px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 8px;
    text-decoration: none;
}

.sdap-brand-logo:hover {
    opacity: 0.85;
}

.sdap-brand-icon {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    object-fit: contain;
}

.sdap-brand-tagline {
    font-size: 12px;
    color: #666;
    line-height: 1.5;
    margin: 0 0 10px;
}

.sdap-brand-legal {
    font-size: 11px;
    color: #999;
    margin: 0;
}

.sdap-brand-legal a {
    color: #2271b1;
    text-decoration: none;
}

.sdap-brand-legal a:hover {
    text-decoration: underline;
}

/* ── Mobile Sidebar Button (hidden on desktop) ──────────────────────── */
.sdap-mobile-sidebar-btn {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
    color: #666;
    transition: border-color 0.15s, color 0.15s;
}

.sdap-mobile-sidebar-btn:hover {
    border-color: #2271b1;
    color: #2271b1;
}

/* ── Close Button ────────────────────────────────────────────────────── */
.sdap-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}

.sdap-modal-close:hover {
    color: #d63638;
    background: rgba(214, 54, 56, 0.08);
}

/* ── Loading Spinner ─────────────────────────────────────────────────── */
#sdap-front-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #fff;
    z-index: 5;
}

.sdap-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e0e0e0;
    border-top-color: #2271b1;
    border-radius: 50%;
    animation: sdap-spin 0.8s linear infinite;
    margin-bottom: 12px;
}

@keyframes sdap-spin {
    to { transform: rotate(360deg); }
}

/* ── Hotkeys Panel ───────────────────────────────────────────────────── */
.sdap-hotkeys-panel {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.sdap-hotkeys-content {
    background: #fff;
    border-radius: 12px;
    padding: 32px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.sdap-hotkeys-content h3 {
    margin: 0 0 16px;
    font-size: 18px;
    color: #1a1a1a;
}

.sdap-hotkeys-content ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sdap-hotkeys-content li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    font-size: 14px;
    color: #444;
    border-bottom: 1px solid #f0f0f0;
}

.sdap-hotkeys-content li:last-child {
    border-bottom: none;
}

.sdap-hotkeys-content kbd {
    display: inline-block;
    padding: 3px 8px;
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 12px;
    font-family: monospace;
    font-weight: 600;
    min-width: 28px;
    text-align: center;
}

.sdap-hotkeys-close {
    display: block;
    width: 100%;
    margin-top: 16px;
    padding: 8px;
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.15s;
}

.sdap-hotkeys-close:hover {
    background: #eee;
}

/* ── Responsive ──────────────────────────────────────────────────────── */
@media screen and (max-width: 768px) {
    .sdap-modal-main {
        position: relative;
    }

    .sdap-modal-sidebar {
        position: fixed;
        top: 0;
        right: 0;
        width: 300px;
        min-width: 300px;
        height: 100vh;
        max-height: 100vh;
        border-left: 1px solid #e0e0e0;
        z-index: 100;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
        transform: translateX(0);
        transition: transform 0.3s ease, box-shadow 0.3s ease;
    }

    .sdap-modal-sidebar.sdap-sidebar-collapsed {
        transform: translateX(100%);
        box-shadow: none;
        border-left: none;
    }

    .sdap-sidebar-toggle {
        left: -40px;
        top: 50%;
        transform: translateY(-50%);
        width: 40px;
        height: 48px;
        border-radius: 6px 0 0 6px;
        border: 1px solid #e0e0e0;
        border-right: none;
        background: #fafafa;
        box-shadow: -2px 0 6px rgba(0, 0, 0, 0.1);
    }

    /* Backdrop overlay when sidebar drawer is open */
    .sdap-modal-main::after {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 99;
        opacity: 1;
        pointer-events: auto;
        transition: opacity 0.3s ease;
    }

    .sdap-modal-main.sdap-sidebar-is-collapsed::after {
        opacity: 0;
        pointer-events: none;
    }

    .sdap-topbar-left {
        gap: 12px;
    }

    .sdap-modal-topbar {
        flex-wrap: wrap;
        gap: 8px;
        padding: 6px 12px;
    }

    .sdap-toggle-label {
        font-size: 11px;
    }

    .sdap-hotkeys-btn {
        display: none;
    }

    .sdap-mobile-sidebar-btn {
        display: inline-flex;
    }

    .sdap-sidebar-toggle {
        display: none;
    }
}

@media screen and (max-width: 400px) {
    .sdap-modal-sidebar {
        width: 85vw;
        min-width: 85vw;
    }
}
