.aiprb-app {
    --aiprb-primary: #3157D5;
    --aiprb-secondary: #6D4AFF;
    --aiprb-dark: #172033;
    --aiprb-bg: #F6F8FC;
    --aiprb-surface: #FFFFFF;
    --aiprb-border: #E2E8F0;
    --aiprb-muted: #64748B;
    --aiprb-success: #16A36A;
    --aiprb-danger: #DC5252;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
    color: var(--aiprb-dark);
    background: var(--aiprb-bg);
    border-radius: 12px;
    overflow: hidden;
    box-sizing: border-box;
    border: 1px solid var(--aiprb-border);
    width: 100%;
    max-width: 100%;
    -webkit-text-size-adjust: 100%;
}

.aiprb-app *,
.aiprb-app *::before,
.aiprb-app *::after {
    box-sizing: border-box;
}

.aiprb-topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    background: #fff;
    border-bottom: 1px solid var(--aiprb-border);
    width: 100%;
    max-width: 100%;
}

.aiprb-topbar-left,
.aiprb-topbar-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    min-width: 0;
    max-width: 100%;
}

.aiprb-brand-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--aiprb-primary), var(--aiprb-secondary));
    color: #fff;
    font-weight: 700;
    font-size: 13px;
}

.aiprb-title-input {
    border: 1px solid transparent;
    background: transparent;
    font-size: 16px;
    font-weight: 600;
    color: var(--aiprb-dark);
    padding: 6px 10px;
    border-radius: 8px;
    min-width: 0;
    flex: 1 1 160px;
    max-width: 100%;
}

.aiprb-title-input:focus {
    outline: none;
    border-color: var(--aiprb-primary);
    background: #fff;
}

.aiprb-status-pill {
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 999px;
    background: #EEF2FF;
    color: var(--aiprb-primary);
    font-weight: 500;
    white-space: nowrap;
}

.aiprb-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    min-height: 38px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.aiprb-btn-primary { background: var(--aiprb-primary); color: #fff; }
.aiprb-btn-primary:hover { background: #2647B8; }
.aiprb-btn-secondary { background: var(--aiprb-secondary); color: #fff; }
.aiprb-btn-outline { background: #fff; border-color: var(--aiprb-border); color: var(--aiprb-dark); }
.aiprb-btn-ghost { background: transparent; color: var(--aiprb-dark); }
.aiprb-btn-ghost:hover { background: #EEF2FF; }

.aiprb-select,
.aiprb-input,
.aiprb-textarea {
    width: 100%;
    max-width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--aiprb-border);
    border-radius: 8px;
    background: #fff;
    color: var(--aiprb-dark);
    font-size: 14px;
}

.aiprb-topbar .aiprb-select {
    width: auto;
    max-width: 100%;
    padding: 7px 10px;
    font-size: 13px;
    min-height: 38px;
}

.aiprb-color-input {
    width: 38px;
    height: 38px;
    padding: 2px;
    border: 1px solid var(--aiprb-border);
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
}

/* Desktop Split Workspace — minmax(0, 1fr) prevents CSS grid horizontal blowout */
.aiprb-workspace {
    display: grid;
    grid-template-columns: minmax(340px, 46%) minmax(0, 1fr);
    min-height: 760px;
    width: 100%;
    max-width: 100%;
}

.aiprb-editor-pane {
    background: #fff;
    border-right: 1px solid var(--aiprb-border);
    padding: 20px;
    overflow-y: auto;
    max-height: 85vh;
    min-width: 0;
    max-width: 100%;
}

.aiprb-progress-bar-wrap { margin-bottom: 16px; }
.aiprb-progress-meta {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    margin-bottom: 6px;
    color: var(--aiprb-muted);
}
.aiprb-progress-track { height: 6px; background: #E2E8F0; border-radius: 999px; overflow: hidden; }
.aiprb-progress-fill { height: 100%; background: var(--aiprb-success); transition: width 0.25s ease; }

.aiprb-sections-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--aiprb-border);
}

.aiprb-sec-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
    background: var(--aiprb-bg);
    border: 1px solid var(--aiprb-border);
    cursor: grab;
    user-select: none;
}

.aiprb-sec-chip.active {
    background: var(--aiprb-primary);
    color: #fff;
    border-color: var(--aiprb-primary);
}

.aiprb-sec-chip.hidden-sec { opacity: 0.45; text-decoration: line-through; }

.aiprb-field-group { margin-bottom: 14px; min-width: 0; }
.aiprb-field-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--aiprb-muted);
    margin-bottom: 5px;
}

.aiprb-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.aiprb-entry-card {
    background: var(--aiprb-bg);
    border: 1px solid var(--aiprb-border);
    border-radius: 10px;
    padding: 14px;
    margin-bottom: 12px;
    min-width: 0;
    max-width: 100%;
}

/* Preview Pane */
.aiprb-preview-pane {
    display: flex;
    flex-direction: column;
    background: #E9EEF5;
    max-height: 85vh;
    min-width: 0;
    max-width: 100%;
}

.aiprb-preview-toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--aiprb-border);
    width: 100%;
    max-width: 100%;
}

.aiprb-zoom-controls {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.aiprb-preview-canvas {
    flex: 1;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px 14px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    width: 100%;
    max-width: 100%;
}

/* Stage wrapper sizes cleanly to the scaled sheet dimensions */
.aiprb-sheet-stage {
    position: relative;
    flex-shrink: 0;
    margin: 0 auto;
    overflow: visible;
}

.aiprb-sheet {
    position: absolute;
    top: 0;
    left: 0;
    background: #fff;
    box-shadow: 0 4px 20px rgba(23, 32, 51, 0.08);
    transform-origin: top left;
    padding: 36px 42px;
    color: #172033;
    line-height: 1.5;
    font-size: 13px;
}

.aiprb-sheet-a4 { width: 794px; min-height: 1123px; }
.aiprb-sheet-letter { width: 816px; min-height: 1056px; }

/* Mobile/Tablet Tabs */
.aiprb-mobile-tabs {
    display: none;
    background: #fff;
    border-bottom: 1px solid var(--aiprb-border);
    width: 100%;
}

.aiprb-tab {
    flex: 1;
    padding: 12px 8px;
    border: none;
    background: transparent;
    font-size: 14px;
    font-weight: 600;
    color: var(--aiprb-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
}

.aiprb-tab.active {
    color: var(--aiprb-primary);
    border-bottom-color: var(--aiprb-primary);
}

/* Tablet & Mobile Breakpoint (<= 1024px) */
@media (max-width: 1024px) {
    .aiprb-mobile-tabs { display: flex; }
    .aiprb-workspace {
        grid-template-columns: minmax(0, 1fr);
        min-height: auto;
    }
    .aiprb-editor-pane {
        border-right: none;
        max-height: none;
        overflow-y: visible;
        padding: 16px;
    }
    .aiprb-preview-pane {
        display: none;
        max-height: none;
    }
    .aiprb-preview-pane.mobile-active { display: flex; }
    .aiprb-editor-pane.mobile-hidden { display: none; }
    .aiprb-preview-canvas {
        padding: 14px 10px;
        justify-content: flex-start;
    }
    .aiprb-grid-2 { grid-template-columns: minmax(0, 1fr); }
}

/* Small Mobile Phones (<= 600px) */
@media (max-width: 600px) {
    .aiprb-topbar {
        padding: 12px;
        gap: 10px;
    }
    .aiprb-topbar-left,
    .aiprb-topbar-actions {
        width: 100%;
    }
    .aiprb-topbar .aiprb-select {
        flex: 1 1 130px;
        font-size: 16px; /* Prevents iOS Safari auto-zoom */
    }
    .aiprb-input,
    .aiprb-textarea,
    .aiprb-select {
        font-size: 16px; /* Prevents iOS Safari auto-zoom */
    }
    #aiprb-btn-export-pdf,
    #aiprb-btn-export-docx {
        flex: 1 1 auto;
    }
    .aiprb-preview-toolbar {
        padding: 8px 10px;
    }
    .aiprb-preview-toolbar .aiprb-btn {
        padding: 6px 10px;
        font-size: 12px;
        min-height: 34px;
    }
}

.aiprb-photo-uploader {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px;
    margin-bottom: 16px;
    background: var(--aiprb-bg);
    border: 1px solid var(--aiprb-border);
    border-radius: 10px;
    flex-wrap: wrap;
}
.aiprb-photo-thumb {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--aiprb-primary);
    background: #E2E8F0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--aiprb-muted);
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
    overflow: hidden;
}
.aiprb-photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.aiprb-photo-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
