/**
 * Elevate Guten Block - Frontend Block Styles
 *
 * @package ElevateGutenBlock
 */

/* ==========================================================================
   PDF Buttons Container (like core/buttons)
   ========================================================================== */

.wp-block-elevate-guten-block-pdf-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5em;
    align-items: center;
}

.wp-block-elevate-guten-block-pdf-buttons.is-layout-flex {
    gap: var(--wp--style--block-gap, 0.5em);
}

/* Horizontal Alignment - Standard WordPress classes */
.wp-block-elevate-guten-block-pdf-buttons.is-content-justification-left,
.wp-block-elevate-guten-block-pdf-buttons[class*="is-content-justification-left"] {
    justify-content: flex-start;
}

.wp-block-elevate-guten-block-pdf-buttons.is-content-justification-center,
.wp-block-elevate-guten-block-pdf-buttons[class*="is-content-justification-center"] {
    justify-content: center;
}

.wp-block-elevate-guten-block-pdf-buttons.is-content-justification-right,
.wp-block-elevate-guten-block-pdf-buttons[class*="is-content-justification-right"] {
    justify-content: flex-end;
}

.wp-block-elevate-guten-block-pdf-buttons.is-content-justification-space-between {
    justify-content: space-between;
}

/* Alternative alignment classes */
.wp-block-elevate-guten-block-pdf-buttons.alignleft {
    justify-content: flex-start;
}

.wp-block-elevate-guten-block-pdf-buttons.aligncenter {
    justify-content: center;
}

.wp-block-elevate-guten-block-pdf-buttons.alignright {
    justify-content: flex-end;
}

/* Vertical layout */
.wp-block-elevate-guten-block-pdf-buttons.is-vertical {
    flex-direction: column;
    align-items: stretch;
}

.wp-block-elevate-guten-block-pdf-buttons.is-vertical > .wp-block-elevate-guten-block-pdf-button {
    width: 100%;
}

/* ==========================================================================
   PDF Button Block (single button)
   ========================================================================== */

.wp-block-elevate-guten-block-pdf-button {
    display: flex;
    /* Default alignment left */
    justify-content: flex-start;
}

/* Custom width support - wrapper gets the width, button fills it */
.wp-block-elevate-guten-block-pdf-button.has-custom-width {
    /* Width is set via inline style */
}

.wp-block-elevate-guten-block-pdf-button.has-custom-width .egb-pdf-button {
    width: 100%;
}

/* Single button alignment support */
.wp-block-elevate-guten-block-pdf-button.is-content-justification-left {
    justify-content: flex-start;
}

.wp-block-elevate-guten-block-pdf-button.is-content-justification-center {
    justify-content: center;
}

.wp-block-elevate-guten-block-pdf-button.is-content-justification-right {
    justify-content: flex-end;
}

/* The actual button element - NOT the wrapper */
.wp-block-elevate-guten-block-pdf-button .egb-pdf-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
    padding: 0.6em 1.2em;
    font-size: inherit;
    font-weight: 500;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
    line-height: 1.4;
    box-sizing: border-box;
    /* Default styling */
    background-color: #0073aa;
    color: #ffffff;
    border-radius: 4px;
}

/* WordPress theme color classes - applied to button directly */
.wp-block-elevate-guten-block-pdf-button .egb-pdf-button.has-background {
    /* Has custom background via inline style */
}

.wp-block-elevate-guten-block-pdf-button .egb-pdf-button.has-text-color {
    /* Has custom text color via inline style */
}

/* Apply background and text colors directly to button */
.wp-block-elevate-guten-block-pdf-button.has-background .egb-pdf-button {
    background-color: inherit;
    background: inherit;
}

.wp-block-elevate-guten-block-pdf-button.has-text-color .egb-pdf-button {
    color: inherit;
}

/* NO default hover effects - let GSAP enhancements handle them */
.wp-block-elevate-guten-block-pdf-button .egb-pdf-button:hover {
    /* Only apply hover if no custom enhancements */
}

/* Enhanced elements get their hover from GSAP */
.wp-block-elevate-guten-block-pdf-button.egb-enhanced .egb-pdf-button:hover {
    /* No CSS hover - GSAP handles it */
}

/* Non-enhanced elements can have subtle hover */
.wp-block-elevate-guten-block-pdf-button:not(.egb-enhanced) .egb-pdf-button:hover {
    filter: brightness(1.1);
}

.wp-block-elevate-guten-block-pdf-button .egb-pdf-button:active {
    transform: scale(0.98);
}

.wp-block-elevate-guten-block-pdf-button .egb-pdf-button:focus {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

.wp-block-elevate-guten-block-pdf-button .egb-pdf-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

/* Icon */
.wp-block-elevate-guten-block-pdf-button .egb-pdf-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 1.2em;
    height: 1.2em;
}

.wp-block-elevate-guten-block-pdf-button .egb-pdf-icon svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
}

.egb-pdf-button-text {
    flex-shrink: 0;
}

/* Icon positions */
.egb-pdf-button--icon-left {
    flex-direction: row;
}

.egb-pdf-button--icon-right {
    flex-direction: row-reverse;
}

/* Width variations */
.wp-block-elevate-guten-block-pdf-button.has-custom-width {
    display: block;
}

.wp-block-elevate-guten-block-pdf-button.has-custom-width .egb-pdf-button {
    width: 100%;
}

/* Loading Spinner - HIDDEN by default, shown only on button itself */
.egb-pdf-loading {
    display: none !important;
}

/* ==========================================================================
   Custom Code Blocks (Hidden on Frontend)
   ========================================================================== */

.egb-custom-php,
.egb-custom-js,
.egb-custom-css {
    /* Container for custom code output */
}

/* PHP Error Display (Admin Only) */
.egb-php-error {
    padding: 16px;
    background: #fee;
    border: 1px solid #c00;
    border-radius: 4px;
    color: #c00;
    font-family: monospace;
    font-size: 13px;
    margin: 16px 0;
}

/* ==========================================================================
   Shape Dividers (Frontend) - Independent of Block Enhancements
   ========================================================================== */

/* Container setup */
.egb-has-shape-divider {
    position: relative !important;
    overflow: hidden !important; /* Clip dividers to container bounds */
}

/* Base shape divider */
.egb-shape-divider {
    position: absolute !important;
    overflow: hidden !important;
    line-height: 0 !important;
    pointer-events: none !important;
    z-index: 1;
}

/* Horizontal dividers (top/bottom) - Width and position set inline for scale support */
.egb-shape-divider-top,
.egb-shape-divider-bottom {
    /* left, width set inline to support scale > 100% */
    height: auto;
}

.egb-shape-divider-top {
    top: 0 !important;
    bottom: auto !important;
    margin-top: 0 !important;
}

.egb-shape-divider-bottom {
    bottom: 0 !important;
    top: auto !important;
}

/* Vertical dividers (left/right) - Full container height */
.egb-shape-divider-left,
.egb-shape-divider-right,
.egb-shape-divider-vertical {
    top: 0 !important;
    bottom: 0 !important;
    height: 100% !important;
    /* Width is set inline from PHP */
    /* Ensure visibility */
    opacity: 1 !important;
    visibility: visible !important;
    display: block !important;
    /* Keep overflow hidden to clip the SVG properly */
    overflow: hidden !important;
}

.egb-shape-divider-left {
    left: 0 !important;
    right: auto !important;
}

.egb-shape-divider-right {
    right: 0 !important;
    left: auto !important;
}

/* SVG inside vertical dividers */
.egb-shape-divider-vertical svg {
    display: block !important;
    height: 100% !important;
    /* Width and transform are set inline - don't override! */
}

/* SVG inside horizontal dividers only */
.egb-shape-divider:not(.egb-shape-divider-vertical) svg {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
}

/* Ensure parent blocks have proper positioning */
.wp-block-group.egb-has-shape-divider,
.wp-block-cover.egb-has-shape-divider,
.wp-block-columns.egb-has-shape-divider {
    position: relative !important;
    overflow: hidden !important;
}

/* Content above dividers */
.egb-has-shape-divider > .wp-block-group__inner-container,
.egb-has-shape-divider > .wp-block-cover__inner-container {
    position: relative !important;
    z-index: 10 !important;
}

.egb-has-shape-divider > *:not(.egb-shape-divider):not(.wp-block-cover__image-background) {
    position: relative;
    z-index: 10;
}

/* ==========================================================================
   Barcode Block (Frontend)
   ========================================================================== */

.wp-block-elevate-guten-block-barcode,
.egb-barcode-wrapper {
    display: flex;
    margin: 1em 0;
}

.egb-barcode-align-left {
    justify-content: flex-start;
}

.egb-barcode-align-center {
    justify-content: center;
}

.egb-barcode-align-right {
    justify-content: flex-end;
}

.egb-barcode-image {
    max-width: 100%;
    height: auto;
    display: block;
}

.egb-barcode-error {
    padding: 16px;
    background: #fee;
    border: 1px solid #c00;
    border-radius: 4px;
    color: #c00;
    font-family: monospace;
    font-size: 13px;
    margin: 16px 0;
}

/* ==========================================================================
   QR Code Block (Frontend)
   ========================================================================== */

.wp-block-elevate-guten-block-qrcode,
.egb-qrcode-wrapper {
    display: flex;
    margin: 1em 0;
}

.egb-qrcode-align-left {
    justify-content: flex-start;
}

.egb-qrcode-align-center {
    justify-content: center;
}

.egb-qrcode-align-right {
    justify-content: flex-end;
}

.egb-qrcode-image {
    max-width: 100%;
    height: auto;
    display: block;
}

.egb-qrcode-error {
    padding: 16px;
    background: #fee;
    border: 1px solid #c00;
    border-radius: 4px;
    color: #c00;
    font-family: monospace;
    font-size: 13px;
    margin: 16px 0;
}

/* Flex Container Block */
.egb-flex-container {
    display: flex;
    box-sizing: border-box;
}

/* Children default behavior - allow shrinking and text wrap */
.egb-flex-container > * {
    box-sizing: border-box;
    min-width: 0; /* Critical: allows content to shrink below intrinsic width */
    overflow-wrap: break-word;
    word-wrap: break-word;
}

/* When children should NOT shrink (fixed width mode) */
.egb-flex-container.egb-flex-no-shrink > * {
    flex-shrink: 0 !important;
    min-width: auto !important;
    flex-basis: auto !important;
}

/* Content alignment classes - use align-content for multi-line and align-items for single line */
/* These work when childrenHeight is 'stretch' to vertically position content inside stretched children */
.egb-flex-container.egb-content-align-center > *:not(.egb-flex-container):not(.wp-block-image) {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.egb-flex-container.egb-content-align-bottom > *:not(.egb-flex-container):not(.wp-block-image) {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.egb-flex-container.egb-content-align-top > *:not(.egb-flex-container):not(.wp-block-image) {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

/* Flex container inside Loop Template - remove any extra spacing */
.egb-acf-repeater--loop-template .egb-flex-container {
    margin: 0;
    padding: 0;
}

.egb-acf-repeater--loop-template .egb-flex-container > * {
    margin: 0;
}

/* Specific handling for figure/image blocks inside flex containers */
.egb-flex-container > figure.wp-block-image {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    height: 100%;
}

.egb-flex-container.egb-content-align-center > figure.wp-block-image {
    align-items: center;
}

.egb-flex-container.egb-content-align-top > figure.wp-block-image {
    align-items: flex-start;
}

.egb-flex-container.egb-content-align-bottom > figure.wp-block-image {
    align-items: flex-end;
}

/* Ensure images inside figure don't stretch */
.egb-flex-container > figure.wp-block-image img {
    height: auto;
    max-height: 100%;
    object-fit: contain;
}

/* For nested flex containers, they handle their own content alignment via their own class */

.egb-flex-container-editor {
    /* No min-height to allow container to shrink to content */
}

/* Use CSS custom properties to pass flex values through nested elements */
.egb-flex-container-editor {
    --egb-flex-direction: row;
    --egb-justify-content: flex-start;
    --egb-align-items: stretch;
    --egb-flex-wrap: nowrap;
    --egb-gap: 16px;
}

/* Empty state placeholder - only show when truly empty */
.egb-flex-container-editor:empty::before,
.egb-flex-container-editor > .block-editor-inner-blocks:empty::before {
    content: '';
    min-height: 40px;
    display: block;
}

.egb-flex-container-editor[style*="flex-direction: row"] { --egb-flex-direction: row; }
.egb-flex-container-editor[style*="flex-direction: column"] { --egb-flex-direction: column; }
.egb-flex-container-editor[style*="flex-direction: row-reverse"] { --egb-flex-direction: row-reverse; }
.egb-flex-container-editor[style*="flex-direction: column-reverse"] { --egb-flex-direction: column-reverse; }

.egb-flex-container-editor[style*="justify-content: flex-start"] { --egb-justify-content: flex-start; }
.egb-flex-container-editor[style*="justify-content: center"] { --egb-justify-content: center; }
.egb-flex-container-editor[style*="justify-content: flex-end"] { --egb-justify-content: flex-end; }
.egb-flex-container-editor[style*="justify-content: space-between"] { --egb-justify-content: space-between; }
.egb-flex-container-editor[style*="justify-content: space-around"] { --egb-justify-content: space-around; }
.egb-flex-container-editor[style*="justify-content: space-evenly"] { --egb-justify-content: space-evenly; }

.egb-flex-container-editor[style*="align-items: stretch"] { --egb-align-items: stretch; }
.egb-flex-container-editor[style*="align-items: flex-start"] { --egb-align-items: flex-start; }
.egb-flex-container-editor[style*="align-items: center"] { --egb-align-items: center; }
.egb-flex-container-editor[style*="align-items: flex-end"] { --egb-align-items: flex-end; }

.egb-flex-container-editor[style*="flex-wrap: nowrap"] { --egb-flex-wrap: nowrap; }
.egb-flex-container-editor[style*="flex-wrap: wrap;"] { --egb-flex-wrap: wrap; }
.egb-flex-container-editor[style*="flex-wrap: wrap-reverse"] { --egb-flex-wrap: wrap-reverse; }

.egb-flex-container-editor .block-editor-inner-blocks {
    width: 100%;
    height: 100%;
    display: flex !important;
    flex-direction: var(--egb-flex-direction) !important;
    justify-content: var(--egb-justify-content) !important;
    align-items: var(--egb-align-items) !important;
    flex-wrap: var(--egb-flex-wrap) !important;
    gap: inherit !important;
}

.egb-flex-container-editor .block-editor-block-list__layout {
    display: flex !important;
    flex-direction: var(--egb-flex-direction) !important;
    justify-content: var(--egb-justify-content) !important;
    align-items: var(--egb-align-items) !important;
    flex-wrap: var(--egb-flex-wrap) !important;
    gap: inherit !important;
    width: 100%;
}

/* Ensure nested flex containers in editor respect dimensions */
/* Default: allow shrink and text wrap */
.egb-flex-container-editor .block-editor-block-list__layout > * {
    min-width: 0;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

/* No shrink mode: keep natural width */
.egb-flex-container-editor.egb-flex-no-shrink .block-editor-block-list__layout > * {
    flex-shrink: 0 !important;
    min-width: auto !important;
    flex-basis: auto !important;
}

/* Force inner blocks content to also respect layout */
.egb-flex-container-editor > .block-editor-inner-blocks > .block-editor-block-list__layout {
    flex-direction: var(--egb-flex-direction) !important;
    justify-content: var(--egb-justify-content) !important;
    align-items: var(--egb-align-items) !important;
    flex-wrap: var(--egb-flex-wrap) !important;
}

/* ==========================================================================
   Dynamic Buttons Container Block
   ========================================================================== */

.wp-block-elevate-guten-block-dynamic-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5em;
    align-items: center;
}

/* Orientation */
.wp-block-elevate-guten-block-dynamic-buttons.is-vertical {
    flex-direction: column;
    align-items: stretch;
}

/* Content justification */
.wp-block-elevate-guten-block-dynamic-buttons.is-content-justification-left {
    justify-content: flex-start;
}

.wp-block-elevate-guten-block-dynamic-buttons.is-content-justification-center {
    justify-content: center;
}

.wp-block-elevate-guten-block-dynamic-buttons.is-content-justification-right {
    justify-content: flex-end;
}

.wp-block-elevate-guten-block-dynamic-buttons.is-content-justification-space-between {
    justify-content: space-between;
}

/* ==========================================================================
   Dynamic Button Block (single button)
   ========================================================================== */

.wp-block-elevate-guten-block-dynamic-button,
.egb-dynamic-button {
    display: inline-block;
    padding: 0.6em 1.2em;
    font-size: inherit;
    font-family: inherit;
    font-weight: 500;
    line-height: inherit;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 4px;
    background-color: var(--wp--preset--color--primary, #0073aa);
    color: var(--wp--preset--color--background, #ffffff);
    transition: opacity 0.1s ease-out, background 0.1s ease-out;
    box-sizing: border-box;
    word-break: normal;
    overflow-wrap: break-word;
}

/* Reset button/anchor defaults */
button.wp-block-elevate-guten-block-dynamic-button,
button.egb-dynamic-button {
    -webkit-appearance: none;
    appearance: none;
}

a.wp-block-elevate-guten-block-dynamic-button,
a.egb-dynamic-button {
    text-decoration: none;
}

/* Hover states */
.wp-block-elevate-guten-block-dynamic-button:hover,
.egb-dynamic-button:hover {
    opacity: 0.85;
}

.wp-block-elevate-guten-block-dynamic-button:focus,
.egb-dynamic-button:focus {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

.wp-block-elevate-guten-block-dynamic-button:active,
.egb-dynamic-button:active {
    opacity: 1;
}

/* Width control */
.wp-block-elevate-guten-block-dynamic-buttons .wp-block-elevate-guten-block-dynamic-button[style*="width:100%"],
.wp-block-elevate-guten-block-dynamic-buttons .egb-dynamic-button[style*="width:100%"] {
    flex-basis: 100%;
}

/* Preserve colors when has-* classes */
.wp-block-elevate-guten-block-dynamic-button.has-background,
.egb-dynamic-button.has-background {
    padding: 0.6em 1.2em;
}

/* Processing state */
.wp-block-elevate-guten-block-dynamic-button.processing,
.egb-dynamic-button.processing {
    opacity: 0.7;
    pointer-events: none;
    cursor: wait;
}

/* Added/success state */
.wp-block-elevate-guten-block-dynamic-button.added,
.egb-dynamic-button.added {
    background-color: #46b450 !important;
    color: #ffffff !important;
}

/* Error state */
.wp-block-elevate-guten-block-dynamic-button.error,
.egb-dynamic-button.error {
    background-color: #dc3232 !important;
    color: #ffffff !important;
}

/* Loading state */
.egb-dynamic-button.is-loading {
    opacity: 0.7;
    pointer-events: none;
    cursor: wait;
    position: relative;
}

.egb-dynamic-button.is-loading::after {
    content: "";
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: egb-btn-spin 0.8s linear infinite;
}

@keyframes egb-btn-spin {
    to { transform: translateY(-50%) rotate(360deg); }
}

/* Success state */
.egb-dynamic-button.is-success {
    background-color: #46b450 !important;
    color: #ffffff !important;
}

/* Error state */
.egb-dynamic-button.is-error {
    background-color: #dc3232 !important;
    color: #ffffff !important;
}

/* Visibility hidden */
.egb-dynamic-button.egb-visibility-hidden {
    display: none !important;
}

/* Toggle states */
.egb-dynamic-button.is-on {
    /* Can be styled via custom CSS */
}

.egb-dynamic-button.is-off {
    /* Can be styled via custom CSS */
}

/* ==========================================================================
   Editor Styles
   ========================================================================== */

/* Container in editor */
.block-editor-block-list__block.wp-block-elevate-guten-block-dynamic-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5em;
}

.block-editor-block-list__block.wp-block-elevate-guten-block-dynamic-buttons.is-vertical {
    flex-direction: column;
}

/* Button in editor */
.block-editor-block-list__block.wp-block-elevate-guten-block-dynamic-button {
    cursor: text;
}

/* Make RichText editable and styled */
.wp-block-elevate-guten-block-dynamic-button [data-rich-text-placeholder] {
    opacity: 0.6;
}

