/* -------------------------------------------
    Gutenberg Blocks
        1. Editor Style
           1-1  Base Style
           1-2  WP Block Cover
           1-3  WP Gallery Caption
           1-4  WP Block Separator
           1-5  WP Block Table
           1-6  WP Calendar & WP Latest Comment
           1-7  WP Blockquote
           1-8  WP Button
           1-9  WP Block Search & WC Block Search
           1-10 WP Gallery & Block Code & WP Columns
        2. Sidebar Widget
---------------------------------------------- */

@import '../config';
@import '../mixins';
@import '../direction';

// 1. Editor Style

// 1-1. Base Style
.editor-styles-wrapper .has-small-font-size,
.has-small-font-size {
    font-size: 1.5rem;
}

.editor-styles-wrapper .has-normal-font-size,
.editor-styles-wrapper .has-regular-font-size,
.has-normal-font-size,
.has-regular-font-size {
    font-size: 1.8rem;
}

.editor-styles-wrapper .has-medium-font-size,
.has-medium-font-size {
    font-size: 2.4rem;
}

.editor-styles-wrapper .has-large-font-size,
.has-large-font-size {
    font-size: 3rem;
}

.editor-styles-wrapper .has-huge-font-size,
.editor-styles-wrapper .has-larger-font-size,
.has-huge-font-size,
.has-larger-font-size {
    font-size: 3.4rem;
}

.alignleft {
    float: left;
    clear: both;
    margin-#{$right}: 1.5em
}

.alignright {
    float: right;
    clear: both;
    margin-#{$left}: 1.5em
}

.aligncenter {
    text-align: center;
    margin-left: auto;
    margin-right: auto;
    clear: both
}

ul.aligncenter,
ol.aligncenter {
    list-style-position: inside;
    padding: 0;
}

.alignfull,
.alignwide {
    margin-top: 2rem;
    margin-bottom: 2rem;
}

.alignwide {
    width: 90%;
    max-width: 90%;
    margin-left: auto;
    margin-right: auto;
}

.wp-caption {
    max-width: 100%;
    margin-bottom: 24px;
}

.wp-caption .wp-caption-text,
.wp-caption-dd {
    font-size: 12px;
    font-style: italic;
    line-height: 1.5;
    margin: 9px 0;
    padding: side-values(0 10px 0 0);
    /* Avoid the caption to overflow the width of the image because wp-caption has 10px wider width */
    text-align: $left;
}

img.aligncenter,
.wp-caption.aligncenter {
    display: block;
    margin: 0 auto
}

.alignnone {
    display: block
}

.has-primary-color {
    color: var(--alpha-primary-color);
}

.has-primary-background-color {
    background-color: var(--alpha-primary-color);
}

.has-secondary-color {
    color: var(--alpha-secondary-color);
}

.has-secondary-background-color {
    background-color: var(--alpha-secondary-color);
}

.has-dark-color {
    color: var(--alpha-change-color-dark-1);
}

.has-dark-background-color {
    background-color: var(--alpha-change-color-dark-1);
}

.has-light-color {
    color: var(--alpha-change-color-light-3);
}

.has-light-background-color {
    background-color: var(--alpha-change-color-light-3);
}

.has-success-color {
    color: var(--alpha-success-color);
}

.has-success-background-color {
    background-color: var(--alpha-success-color);
}

.has-info-color {
    color: $info-color;
}

.has-info-background-color {
    background-color: $info-color;
}

.has-warning-color {
    color: var(--alpha-alert-color);
}

.has-warning-background-color {
    background-color: var(--alpha-alert-color);
}

.has-danger-color {
    color: var(--alpha-danger-color);
}

.has-danger-background-color {
    background-color: var(--alpha-danger-color);
}

.has-white-color {
    color: var(--alpha-change-color-light-1);
}

.has-white-background-color {
    background-color: var(--alpha-change-color-light-1);
}

.has-transparent-color {
    color: transparent;
}

.has-transparent-background-color {
    background-color: transparent;
}

.wp-block-table {
    display: table;
    width: 100%;
}

// 1-2. WP Block Cover
.wp-block-cover {
    color: var(--alpha-change-color-light-1);

    a {
        color: inherit;
    }
}

.wp-block-cover .wp-block-cover__inner-container p {
    font-size: 2em !important;
    line-height: 1.25;
    z-index: 1;
    margin-bottom: 0;
}

.wp-block-cover-image .wp-block-cover-image-text,
.wp-block-cover .wp-block-cover-text,
.wp-block-cover .wp-block-cover__inner-container p,
section.wp-block-cover-image>h2 {
    padding: 0;
    max-width: 100%;
}

.wp-block-cover-image.has-background-dim:not(.has-pale-pink-background-color),
.wp-block-cover.has-background-dim:not(.has-pale-pink-background-color) {
    background-color: #000;
}

// 1-3. WP Gallery Caption
.blocks-gallery-caption,
.wp-block-embed figcaption,
.wp-block-image figcaption {
    width: 100%;
}

// 1-4. WP Block Separator
.wp-block-separator {
    clear: both;
}

// 1-5. WP Block Table 
.wp-block-table table td,
.wp-block-table table th {
    padding: .5em;
}

// 1-6. WP Calendar & WP Latest Comment
.wp-block-calendar {
    position: relative;
    padding-#{$left}: 1rem !important;
    padding-#{$right}: 1rem !important;
    color: var(--alpha-grey-color);
    margin: 3rem 0;
    font-size: 13px;
    border: 1px solid var(--alpha-change-border-color) !important;

    .wp-calendar-table {
        position: relative;
        margin-bottom: 0;

        th {
            padding: 65px 0 4px 0;
            font-weight: 600;
            color: var(--alpha-change-color-dark-1);
            line-height: 1;
            text-align: center;
            border: 0;
            background-color: transparent;
        }

        td {
            position: relative;
            padding: 12px 10px;
            text-align: center;
            border: 0;

            a {
                position: absolute;
                left: 0;
                right: 0;
                top: 0;
                bottom: 0;
                line-height: 3.8rem;
                transition: .3s;

                &:hover {
                    background-color: var(--alpha-primary-color);
                    color: var(--alpha-change-color-light-1) !important;
                }
            }
        }

        caption {
            position: absolute;
            top: 0;
            #{$left}: 0;
            width: 100%;
            margin-bottom: 1.3rem;
            font-weight: 400;
            font-size: 18px;
            color: var(--alpha-heading-color);
            text-transform: capitalize;
            line-height: 6rem;
            height: 6rem;
        }
    }

    .wp-calendar-nav {
        position: absolute;
        top: 2.9rem;
        width: calc(100% - 4rem);

        .widget & span a,
        .widget & span a:hover,
        .widget & span a:focus {
            color: var(--alpha-heading-color);
        }

        span {
            a {
                display: inline-block;
                position: relative;
                text-indent: -9999px;

                &:before {
                    content: '';
                    position: absolute;
                    font-family: $theme-font;
                    left: 0;
                    text-indent: 0;
                }
            }
        }

        .wp-calendar-nav-prev {
            float: #{$left};

            a:before {
                content: if-ltr('\e912', '\e913');
                margin-#{$left}: .5rem;
            }
        }

        .wp-calendar-nav-next {
            float: #{$right};

            a:before {
                content: if-ltr('\e913', '\e912');
                margin-#{$right}: .5rem;
            }
        }

    }
}

.wp-calendar-table {

    td,
    th {
        text-align: center;
    }

    #today {
        color: var(--alpha-primary-color);
    }

    caption {
        font-size: 1.8rem;
        font-weight: 600;
        padding: 1.6rem 0;
    }
}

.wp-block-latest-comments__comment {
    line-height: 1.1;
}

.wp-block-latest-comments .avatar,
.wp-block-latest-comments__comment-avatar {
    height: auto !important;
    padding-top: 0 !important;
}

// 1-7. WP Blockquote
.wp-block-quote {
    position: relative;
    padding: .8em 1em;
    background-color: var(--alpha-change-color-light-2);
    border-left: 2px solid var(--alpha-primary-color);

    &.has-text-align-right {
        border-right: 2px solid var(--alpha-primary-color);
    }

    &.has-text-align-center {
        text-align: center;

        &:before {
            content: '\e934';
            font-size: 32px;
            font-family: $theme-font;
            line-height: 1;
            color: var(--alpha-primary-color);
        }
    }

    p {
        margin: 0;
    }

    &.is-large {
        padding: 1em 1.5em;
        border-left: 2px solid var(--alpha-primary-color);

        &.has-text-align-right {
            border-right: 2px solid var(--alpha-primary-color);
        }

        background-color: var(--alpha-change-color-light-2);
    }

    cite {
        display: block;

        color: var(--alpha-change-color-dark-1);
        font-size: 1.2rem;
    }

    &.is-style-large {
        margin-bottom: 2rem;
        background: none;
        font-weight: 600;

        p {
            color: var(--alpha-change-color-dark-1);
            letter-spacing: -.025em;
        }

        &:before {
            content: '\f10e';
            display: inline-block;
            position: absolute;
            left: 0;
            top: 0;
            font-weight: 900;
            font-size: 2.5rem;
            font-family: 'Font Awesome 5 Free';
            color: var(--alpha-change-color-dark-1);
            line-height: 1;
        }

        @include mq(xl, max) {
            p {
                font-size: 1.5rem;
            }
        }

        @include mq(xs, max) {

            p,
            cite {
                font-size: 1.5rem;
            }
        }
    }

    &.is-style-large,
    &.is-style-large:not(.is-style-plain) {
        padding: side-values(0 0 0 6rem);

        @include mq(xl, max) {
            & {
                padding: side-values(0 0 0 4rem);
            }
        }
    }
}

.wp-block-pullquote blockquote {
    margin-bottom: 0;
    padding: 1em;
    border-#{$left}: 2px solid var(--alpha-primary-color);
    background-color: var(--alpha-change-color-light-2);
}

// 1-8. WP Buttons
.wp-block-button {
    margin-bottom: 2rem;

    .wp-block-button__link {
        background-color: var(--alpha-primary-color);
        color: var(--alpha-change-color-light-1);
        transition: color, background-color .3s;

        &:hover {
            color: var(--alpha-change-color-light-1);
            background-color: var(--alpha-primary-color-hover);
            text-decoration: none;
        }
    }

    &.is-style-outline {
        .wp-block-button__link {
            background-color: transparent;
            color: var(--alpha-primary-color);

            &:hover {
                background-color: var(--alpha-primary-color);
                color: var(--alpha-change-color-light-1);
            }
        }
    }

    &.is-style-squared {
        .wp-block-button__link {
            border-radius: 0;
        }
    }
}

// 1-9. WP Block Search & WC Block Search
.wp-block-search,
.post-password-form {
    margin-bottom: 2rem;
    font-size: 0.85em;

    input {
        font-size: inherit;
    }
}

.post-password-form {
    &>p {
        display: flex;
        align-items: flex-end;
    }

    input[type=submit] {
        padding: .9rem .6rem;
    }
}

.wp-block-search {
    &.wp-block-search__button-inside {
        .wp-block-search__inside-wrapper {
            border: 1px solid var(--alpha-change-border-color);

            .wp-block-search__input {
                border: none;
                padding: side-values(0 0 0 10px);
            }
        }

        .wp-block-search__button,
        .wp-block-search__button:hover {
            background: transparent;
        }
    }

    .wp-block-search__inside-wrapper {
        display: flex;
        flex-wrap: nowrap;
    }

    .wp-block-search__button {
        background: none;
        color: var(--alpha-change-color-dark-1);
        border: 0;

        svg {
            display: none;
        }

        &:before {
            display: inline-block;
            vertical-align: middle;
            font-family: $framework-font;
            font-size: 1.11em;
            font-weight: 400;
            line-height: 1em;
            padding-#{$right}: 5px;
            content: "\e97e";
        }

        &:hover {
            color: var(--alpha-primary-color);
        }

        &.has-icon:before {
            padding-#{$right}: 0;
        }
    }

    &.wp-block-search__button-inside .wp-block-search__button,
    .wp-block-search__button {
        padding: .125em .5em;
    }
}

.wp-block-search__button.has-icon {
    line-height: 0;
}

.wp-block-search .wp-block-search__label,
.wc-block-product-search__label {
    display: block;
    padding: 13px 0;
    color: var(--alpha-heading-color, var(--alpha-body-color));
    font-size: 16px;
    font-weight: 600;
}

.wp-block-search.wp-block-search__button-inside .wp-block-search__inside-wrapper {
    max-width: 100%;
    padding: 4px;
    border-radius: var(--alpha-border-radius);
    border-color: var(--alpha-change-border-color);

    .has-icon {
        border-width: 0;
    }
}

.wp-block-search .wp-block-search__input,
.wc-block-product-search .wc-block-product-search__field,
.woocommerce-product-search input,
.post-password-form input[type="password"] {
    width: 100%;
    min-height: 3.6rem;
    padding: .65em 1.53em;

    &.form-solid {
        background-color: var(--alpha-change-color-light-1);
        border: 0;
        color: #8d8d8d;
    }
}

.wp-block-search button:not(.has-icon),
.woocommerce-product-search button,
.post-password-form input[type="submit"] {
    display: inline-block;
    min-width: 9rem;
    flex: 0 0 auto;
    border-width: 0;
    background-color: var(--alpha-primary-color);
    color: var(--alpha-change-color-light-1);
    outline: 0;
    text-align: center;
    transition: color .3s, border-color .3s, background-color .3s, box-shadow .3s;
    white-space: nowrap;

    &:hover {
        background-color: var(--alpha-primary-color-hover);
    }
}

.wp-block-search button:not(.has-icon):hover {
    color: #fff
}

.wp-block-search button.has-icon,
.wc-block-product-search__button {
    color: var(--alpha-change-color-dark-1);
    font-size: 1.285714em;
    background: transparent;
    border: 1px solid var(--alpha-change-border-color);

    svg {
        display: none;
    }

    &::before {
        content: "\e97e";
        font-family: $framework-font;
    }

    &:hover,
    &:focus {
        color: var(--alpha-primary-color);
    }
}

.wc-block-product-search {
    font-size: 0.922em;

    .wc-block-product-search__button {
        overflow: inherit;
    }
}

.widget_product_search .woocommerce-product-search {
    display: flex;
}

// 1-10. WP Gallery & Block Code & WP Columns
.wp-block-search__icon-button .wp-block-search__input {
    padding: 1.2rem 2rem;
}

.wp-block-search__text-button .wp-block-search__input {
    border-radius: 0;
}

.gallery {
    display: flex;
    flex-wrap: wrap;
    margin: -5px;
}

.gallery-item {
    width: 100%;
    margin-bottom: 1.5rem;
    padding: 5px;
}

@for $i from 1 through 9 {
    .gallery-columns-#{$i}>* {
        max-width: #{ round( 100% / $i * 10000 ) / 10000 };
        flex: 0 0 #{ round( 100% / $i * 10000 ) / 10000 };
    }
}

.wp-block-code {
    background: var(--alpha-change-color-dark-1);
    border-color: var(--alpha-change-color-dark-1);

    code {
        color: var(--alpha-change-color-light-1);
    }
}

.main-content>.wp-block-columns:not(.alignwide):not(.alignfull) {
    max-width: var(--alpha-container-width);
}

.main-content>.alignwide {
    max-width: var(--alpha-container-fluid-width);
    padding-left: 30px;
    padding-right: 30px;
    margin-left: auto;
    margin-right: auto;
}

.main-content>.wp-block-columns:not(.alignfull) {
    padding-left: 15px;
    padding-right: 15px;
    margin-left: auto;
    margin-right: auto;
}

@include mq(1280px) {
    .main-content>.wp-block-columns:not(.alignwide):not(.alignfull) {
        max-width: 1280px;
        padding-left: 0;
        padding-right: 0;
        margin-left: auto;
        margin-right: auto;
    }
}

@include mq(1820px) {
    .main-content>.alignwide.wp-block-columns {
        max-width: 1800px;
        padding-left: 0;
        padding-right: 0;
        margin-left: auto;
        margin-right: auto;
    }
}

.container,
.container-fluid {
    .wp-block-columns:not(.alignfull) {
        padding-left: 0;
        padding-right: 0;
    }

    .main-content>.wp-block-columns {
        margin-left: -10px;
        margin-right: -10px;
    }

    .alignwide {
        padding-left: 0;
        padding-right: 0;
    }
}

.container-fluid .main-content> {
    @include mq(1300px) {
        .wp-block-columns:not(.alignwide):not(.alignfull) {
            margin-left: auto;
            margin-right: auto;
        }
    }
}

.wp-block-columns {
    gap: 0;
    margin-left: -10px;
    margin-right: -10px;
}

@include mq(xs, max) {
    .wp-block-columns:not(.alignfull) {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
}

.wp-block-columns>.wp-block-column {
    padding-left: 15px;
    padding-right: 15px;
    margin-#{$left}: 0 !important;
}

.blocks-gallery-grid[class*="columns-"] .blocks-gallery-image,
.blocks-gallery-grid[class*="columns-"] .blocks-gallery-item,
.wp-block-gallery[class*="columns-"] .blocks-gallery-image,
.wp-block-gallery[class*="columns-"] .blocks-gallery-item {
    margin-#{$right}: 30px;
    margin-bottom: 30px;

    &:last-child {
        margin-#{$right}: 0;
    }
}

.blocks-gallery-grid.columns-2 .blocks-gallery-image,
.blocks-gallery-grid.columns-2 .blocks-gallery-item,
.wp-block-gallery.columns-2 .blocks-gallery-image,
.wp-block-gallery.columns-2 .blocks-gallery-item {
    width: calc((100% - 15px * 2) / 2);
}

.blocks-gallery-grid.columns-3 .blocks-gallery-image,
.blocks-gallery-grid.columns-3 .blocks-gallery-item,
.wp-block-gallery.columns-3 .blocks-gallery-image,
.wp-block-gallery.columns-3 .blocks-gallery-item {
    width: calc((100% - 15px * 4) / 3);
}

.blocks-gallery-grid.columns-4 .blocks-gallery-image,
.blocks-gallery-grid.columns-4 .blocks-gallery-item,
.wp-block-gallery.columns-4 .blocks-gallery-image,
.wp-block-gallery.columns-4 .blocks-gallery-item {
    width: calc((100% - 15px * 6) / 4);
}

.blocks-gallery-grid.columns-5 .blocks-gallery-image,
.blocks-gallery-grid.columns-5 .blocks-gallery-item,
.wp-block-gallery.columns-5 .blocks-gallery-image,
.wp-block-gallery.columns-5 .blocks-gallery-item {
    width: calc((100% - 15px * 8) / 5);
}

.blocks-gallery-grid.columns-6 .blocks-gallery-image,
.blocks-gallery-grid.columns-6 .blocks-gallery-item,
.wp-block-gallery.columns-6 .blocks-gallery-image,
.wp-block-gallery.columns-6 .blocks-gallery-item {
    width: calc((100% - 15px * 10) / 6);
}

.blocks-gallery-grid.columns-7 .blocks-gallery-image,
.blocks-gallery-grid.columns-7 .blocks-gallery-item,
.wp-block-gallery.columns-7 .blocks-gallery-image,
.wp-block-gallery.columns-7 .blocks-gallery-item {
    width: calc((100% - 15px * 12) / 7);
}

.blocks-gallery-grid.columns-8 .blocks-gallery-image,
.blocks-gallery-grid.columns-8 .blocks-gallery-item,
.wp-block-gallery.columns-8 .blocks-gallery-image,
.wp-block-gallery.columns-8 .blocks-gallery-item {
    width: calc((100% - 15px * 14) / 8);
}

.blocks-gallery-grid.columns-9 .blocks-gallery-image,
.blocks-gallery-grid.columns-9 .blocks-gallery-item,
.wp-block-gallery.columns-9 .blocks-gallery-image,
.wp-block-gallery.columns-9 .blocks-gallery-item {
    width: calc((100% - 15px * 16) / 9);
}

.wp-block-columns {
    display: flex;
    flex-wrap: wrap;
    margin-left: -15px;
    margin-right: -15px;
}

.wp-block-column {
    padding-left: 15px;
    padding-right: 15px;
}

// @media (max-width: 781px) and (min-width: 600px) {
//     .wp-block-column {
//         flex-basis: 50% !important;
//         flex-grow: 0;
//     }
// }

.gallery-columns-7 .gallery-caption,
.gallery-columns-8 .gallery-caption,
.gallery-columns-9 .gallery-caption {
    display: none;
}

.widget_media_gallery {
    .gallery {
        display: flex;
        flex-wrap: wrap;
        margin: -5px;
    }

    figure {
        width: 100%;
        padding: 5px;
    }
}

@for $i from 1 through 8 {
    .gallery-columns-#{$i}>* {
        max-width: #{ round( 100% / $i * 10000 ) / 10000 };
        flex: 0 0 #{ round( 100% / $i * 10000 ) / 10000 };
    }
}

// 2. Sidebar Widget
.sidebar {
    .widget_block {
        margin-bottom: 1rem;

        h2,
        [class*="wp-block-woocommerce-"] h3 {
            font-size: 1.8rem;
            padding: 1.6rem 0;
            margin-bottom: 0;
        }
    }

    @include mq(lg) {
        .widget:first-child .wp-block-group__inner-container>h2 {
            padding-top: 0;
        }
    }

    .wp-block-latest-comments {
        padding-#{$left}: 0;
        margin: 0;
    }

    .wp-block-latest-comments__comment-date {
        margin-top: .5rem;
    }

    .widget.widget_block.widget_calendar {
        padding-top: 0;
        padding-bottom: 0;
    }

    .wp-calendar-table caption {
        padding: 0;
    }

    .wp-block-calendar {
        margin-top: 1rem;
    }

    .wp-block-calendar:first-child {
        margin-top: 4rem;
    }

    .wp-block-calendar:last-child {
        margin-bottom: 4rem;
    }

    .widget.widget_calendar .wp-block-calendar {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .widget {
        >:last-child {
            margin-bottom: 3.7rem; // @issue

            &.wp-block-group {
                margin-bottom: 0;

                >.wp-block-group__inner-container {
                    >:last-child {
                        margin-bottom: 3.7rem;
                    }

                    >ul:last-child {
                        margin: -.4rem 0 3rem; // @issue
                    }
                }
            }
        }

        >ul:last-child {
            margin-bottom: 3rem; // @issue
        }

        &:last-child {
            .wp-block-group>.wp-block-group__inner-container {
                >:last-child {
                    margin-bottom: 0;
                }
            }
        }
    }
}

.wp-caption img[class*="wp-image-"] {
    display: block;
}

.widget-block .alpha-block {
    text-align: initial;
}