/* Reset & Base */
.pb-book-creator-wrapper {
    max-width: 1200px;
    margin: 60px auto;
    padding: 0 20px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
}

.pb-book-creator-wrapper * {
    box-sizing: border-box;
}

/* Templates Grid */
.pb-templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 30px;
    margin-bottom: 40px;
}

@media (max-width: 768px) {
    .pb-templates-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}

/* Template Card */
.pb-template-card {
    background: #ffffff;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    border: 1px solid #e5e7eb;
}

.pb-template-image-wrapper {
    width: 100%;
    background: #f9fafb;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.pb-template-image {
    width: 100%;
    height: 400px;
    object-fit: cover;
    display: block;
    border-radius: 8px;
}

.pb-template-content {
    padding: 24px;
}

.pb-template-title {
    margin: 0 0 8px 0;
    font-size: 22px;
    font-weight: 700;
    color: #1a1a1a;
    line-height: 1.3;
}

.pb-template-description {
    margin: 0 0 20px 0;
    font-size: 15px;
    color: #666;
    line-height: 1.5;
}

/* Buttons */
.pb-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 28px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    line-height: 1;
    font-family: inherit;
}

.pb-btn-large {
    padding: 16px 32px;
    font-size: 17px;
    width: 100%;
}

.pb-btn-create {
    width: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(102, 126, 234, 0.3);
}

.pb-btn-create:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.pb-btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(102, 126, 234, 0.3);
}

.pb-btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.pb-btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.pb-btn-success {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(17, 153, 142, 0.3);
}

.pb-btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(17, 153, 142, 0.4);
}

.pb-btn-secondary {
    background: #f3f4f6;
    color: #1a1a1a;
}

.pb-btn-secondary:hover {
    background: #e5e7eb;
}

/* Modal */
.pb-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.pb-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.3s ease;
}

.pb-modal-container {
    position: relative;
    background: #ffffff;
    border-radius: 24px;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
    animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.pb-modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: #f3f4f6;
    color: #666;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10;
}

.pb-modal-close:hover {
    background: #e5e7eb;
    color: #1a1a1a;
    transform: rotate(90deg);
}

.pb-modal-content {
    padding: 40px;
}

@media (max-width: 768px) {
    .pb-modal-content {
        padding: 30px 20px;
    }
}

/* Steps Indicator */
.pb-steps {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 40px;
}

.pb-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.pb-step-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #e5e7eb;
    color: #9ca3af;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    transition: all 0.3s ease;
    position: relative;
}

.pb-step-check {
    display: none;
}

.pb-step-active .pb-step-circle {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.pb-step-completed .pb-step-circle {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    color: #ffffff;
}

.pb-step-completed .pb-step-number {
    display: none;
}

.pb-step-completed .pb-step-check {
    display: block;
}

.pb-step-label {
    font-size: 13px;
    font-weight: 600;
    color: #9ca3af;
    transition: color 0.3s ease;
}

.pb-step-active .pb-step-label {
    color: #667eea;
}

.pb-step-completed .pb-step-label {
    color: #11998e;
}

.pb-step-line {
    width: 60px;
    height: 2px;
    background: #e5e7eb;
    margin: 0 8px;
    margin-bottom: 28px;
}

/* Modal Steps Content */
.pb-modal-step {
    display: none;
}

.pb-modal-step-active {
    display: block;
    animation: fadeInStep 0.4s ease;
}

@keyframes fadeInStep {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.pb-modal-header {
    text-align: center;
    margin-bottom: 30px;
}

.pb-modal-title {
    margin: 0 0 8px 0;
    font-size: 26px;
    font-weight: 700;
    color: #1a1a1a;
}

.pb-modal-subtitle {
    margin: 0;
    font-size: 15px;
    color: #666;
}

/* Upload Zone */
.pb-upload-zone {
    position: relative;
    margin-bottom: 24px;
}

.pb-file-input {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}

.pb-file-input.pb-file-selected {
    pointer-events: none;
}

.pb-upload-placeholder {
    border: 2px dashed #cbd5e0;
    border-radius: 12px;
    padding: 50px 20px;
    text-align: center;
    transition: all 0.3s ease;
    background: #f8fafc;
}

.pb-upload-placeholder:hover {
    border-color: #667eea;
    background: #f0f4ff;
}

.pb-upload-zone.dragover .pb-upload-placeholder {
    border-color: #667eea;
    background: #e0e7ff;
    transform: scale(1.02);
}

.pb-upload-icon {
    margin-bottom: 16px;
    color: #667eea;
}

.pb-upload-text {
    margin: 0 0 8px 0;
    font-size: 16px;
    font-weight: 600;
    color: #1a1a1a;
}

.pb-upload-hint {
    margin: 0;
    font-size: 13px;
    color: #9ca3af;
}

/* Photo Preview */
.pb-photos-preview {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)) !important;
    gap: 12px;
    margin-top: 20px;
    max-width: 100%;
}

.pb-photo-preview-item {
    position: relative;
    width: 100% !important;
    max-width: 120px !important;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #e5e7eb;
    background: #f9fafb;
}

.pb-photo-preview-item img {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: cover !important;
    display: block;
}

.pb-photo-preview-item .pb-preview-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
    color: #ef4444;
    z-index: 10;
}

.pb-photo-preview-item .pb-preview-remove svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    pointer-events: none;
    display: block;
}

.pb-photo-preview-item .pb-preview-remove:hover {
    background: #ef4444;
    color: #ffffff;
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.pb-photo-preview-item .pb-preview-remove:hover svg {
    stroke: #ffffff;
}

.pb-photo-preview-item .pb-preview-number {
    position: absolute;
    bottom: 4px;
    left: 4px;
    background: rgba(0, 0, 0, 0.7);
    color: #ffffff;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
}

/* Backward compatibility - single photo preview */
.pb-photo-preview {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    max-width: 300px;
    margin: 0 auto;
}

.pb-photo-preview img {
    width: 100%;
    height: auto;
    display: block;
}

.pb-preview-remove {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.95);
    color: #ef4444;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 10;
    padding: 0;
}

.pb-preview-remove svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    pointer-events: none;
    display: block;
}

.pb-preview-remove:hover {
    background: #ef4444;
    color: #ffffff;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

.pb-preview-remove:hover svg {
    stroke: #ffffff;
}

/* Processing Step */
.pb-processing-content {
    text-align: center;
    padding: 40px 20px;
}

.pb-loader {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 30px;
}

.pb-loader-circle {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    animation: bounce 1.4s infinite ease-in-out both;
}

.pb-loader-circle:nth-child(1) {
    animation-delay: -0.32s;
}

.pb-loader-circle:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.pb-processing-title {
    margin: 0 0 12px 0;
    font-size: 24px;
    font-weight: 700;
    color: #1a1a1a;
}

.pb-processing-text {
    margin: 0 0 30px 0;
    font-size: 15px;
    color: #666;
}

.pb-processing-progress {
    max-width: 400px;
    margin: 0 auto;
}

.pb-progress-bar {
    width: 100%;
    height: 8px;
    background: #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 12px;
}

.pb-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    width: 0%;
    transition: width 0.3s ease;
    animation: progressShimmer 2s infinite;
}

@keyframes progressShimmer {
    0% {
        background-position: -200px 0;
    }

    100% {
        background-position: 200px 0;
    }
}

.pb-progress-text {
    margin: 0;
    font-size: 14px;
    color: #9ca3af;
    font-weight: 500;
}

/* Success Step */
.pb-success-content {
    text-align: center;
    padding: 20px;
}

.pb-success-animation {
    margin-bottom: 30px;
}

.pb-success-checkmark {
    width: 80px;
    height: 80px;
    margin: 0 auto;
}

.pb-success-circle {
    stroke-dasharray: 166;
    stroke-dashoffset: 166;
    stroke-width: 2;
    stroke-miterlimit: 10;
    stroke: #11998e;
    fill: none;
    animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.pb-success-check {
    transform-origin: 50% 50%;
    stroke-dasharray: 48;
    stroke-dashoffset: 48;
    stroke-width: 3;
    stroke: #11998e;
    animation: stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards;
}

@keyframes stroke {
    100% {
        stroke-dashoffset: 0;
    }
}

.pb-success-title {
    margin: 0 0 12px 0;
    font-size: 28px;
    font-weight: 700;
    color: #1a1a1a;
}

.pb-success-text {
    margin: 0 0 30px 0;
    font-size: 16px;
    color: #666;
}

.pb-preview-result {
    margin: 30px 0;
    padding: 20px;
    background: #f8fafc;
    border-radius: 12px;
}

.pb-success-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Error State */
.pb-modal-error {
    text-align: center;
    padding: 48px 32px;
}

.pb-error-icon {
    margin-bottom: 24px;
    color: #ef4444;
}

.pb-error-icon svg {
    width: 64px;
    height: 64px;
}

.pb-error-title {
    margin: 0 0 16px 0;
    font-size: 24px;
    font-weight: 600;
    color: #1f2937;
    letter-spacing: -0.01em;
}

.pb-error-message {
    margin: 0 0 24px 0;
    font-size: 15px;
    color: #374151;
    line-height: 1.7;
    max-height: 400px;
    overflow-y: auto;
    text-align: left;
    padding: 20px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    word-break: break-word;
    white-space: normal;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.pb-error-message::-webkit-scrollbar {
    width: 8px;
}

.pb-error-message::-webkit-scrollbar-track {
    background: #fee2e2;
    border-radius: 4px;
}

.pb-error-message::-webkit-scrollbar-thumb {
    background: #fca5a5;
    border-radius: 4px;
}

.pb-error-message::-webkit-scrollbar-thumb:hover {
    background: #f87171;
}

/* Error message text formatting */
.pb-error-message strong,
.pb-error-message b {
    font-weight: 600;
    color: #991b1b;
}

.pb-error-message code,
.pb-error-message pre {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 13px;
    background: rgba(239, 68, 68, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    color: #991b1b;
}

.pb-error-message a {
    color: #2563eb;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.pb-error-message a:hover {
    color: #1d4ed8;
}

/* Error Banner */
.pb-error {
    padding: 16px 20px;
    background: #fef2f2;
    color: #991b1b;
    border-left: 4px solid #ef4444;
    font-size: 14px;
    line-height: 1.5;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .pb-book-creator-wrapper {
        margin: 30px auto;
    }

    .pb-modal-container {
        max-height: 95vh;
    }

    .pb-steps {
        margin-bottom: 30px;
    }

    .pb-step-label {
        font-size: 11px;
    }

    .pb-step-line {
        width: 40px;
    }

    .pb-modal-title {
        font-size: 22px;
    }

    .pb-success-title {
        font-size: 24px;
    }
}

/* Scrollbar Styling */
.pb-modal-container::-webkit-scrollbar {
    width: 8px;
}

.pb-modal-container::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.pb-modal-container::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
}

.pb-modal-container::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}