@use '../abstracts' as *;

/**
 * Form Builder Page Styles
 */

.gfm-builder-header-main {
    @include flex-between;
    margin-bottom: $space-lg;
    padding: $space-sm 0;

    h1 {
        font-size: 32px;
        font-weight: 800;
        margin: 0;
        line-height: 1.25;
        padding: 4px 2px 6px;
        letter-spacing: -0.03em;
        background: linear-gradient(135deg, $primary 0%, #7C3AED 100%);
        -webkit-background-clip: text;
        background-clip: text;
        -webkit-text-fill-color: transparent;
    }
}

.gfm-builder-tabs {
    display: flex;
    gap: 8px;
    background: color-mix(in srgb, $bg, $text-main 5%);
    padding: 6px;
    border-radius: $radius-lg;
    border: 1px solid $border;
}

.gfm-tab-link {
    background: transparent;
    border: none;
    padding: 11px 30px;
    border-radius: $radius-md;
    font-weight: $weight-bold;
    cursor: pointer;
    color: $text-muted;
    transition: $transition-base;
    font-size: $size-base;
    white-space: nowrap;

    &:hover:not(.active) {
        color: $text-main;
        background: rgba($white, 0.6);
    }

    &.active {
        background: $white;
        color: $primary;
        box-shadow: $shadow-md;
        transform: translateY(0);
    }
}

.gfm-builder-top {
    @include flex-between;
    align-items: stretch;
    gap: $space-md;
    margin-bottom: $space-lg;
}

// Builder tab card headings (Settings / Notifications tabs).
#gfm-tab-settings .gfm-card h3,
#gfm-tab-notifications .gfm-card h3 {
    font-size: 16px;
    font-weight: 700;
    color: $text-main;
    margin: 0 0 $space-md 0;
    padding-bottom: $space-sm;
    border-bottom: 1px solid $border;
    display: flex;
    align-items: center;
    gap: $space-xs;
    letter-spacing: -0.01em;
}

.gfm-name-card {
    flex: 1;
    margin-bottom: 0;
    padding: $space-md $space-lg;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: $white;
    border: 1px solid $border;
    border-radius: $radius;
    box-shadow: $shadow-sm;

    label {
        display: block;
        font-weight: $weight-bold;
        margin-bottom: 6px;
        color: $text-light;
        text-transform: uppercase;
        font-size: 10px;
        letter-spacing: 0.1em;
    }

    input {
        font-size: 20px;
        font-weight: 700;
        border: none !important;
        padding: 0 !important;
        box-shadow: none !important;
        background: transparent !important;
        color: $text-main;
        letter-spacing: -0.02em;

        &:focus {
            outline: none;
        }

        &::placeholder {
            color: $border-dark;
        }
    }
}

.gfm-builder-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: $space-lg;
    align-items: start;
}

.gfm-sidebar .gfm-card {
    position: sticky;
    top: 32px;
    padding: $space-md;
    border-radius: $radius-lg;

    h3 {
        font-size: 13px;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin-top: 0;
        color: $text-muted;
        margin-bottom: $space-md;
    }

    // Pro Fields section within the sidebar card.
    .gfm-pro-fields-section {
        margin-top: $space-md;
        padding-top: $space-sm;
        border-top: 1px dashed $border;
    }

    .gfm-pro-fields-title {
        display: flex;
        align-items: center;
        gap: 6px;
        font-size: 11px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: #f59e0b;
        margin: 0 0 $space-sm 0;

        .dashicons {
            font-size: 14px;
            width: 14px;
            height: 14px;
        }
    }
}

.gfm-field-buttons {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
}

.gfm-add-field {
    display: flex;
    align-items: center;
    gap: $space-sm;
    background: $white;
    border: 1px solid $border;
    padding: 14px $space-sm;
    border-radius: $radius-md;
    text-align: left;
    cursor: pointer;
    transition: $transition-bounce;
    font-weight: $weight-medium;
    font-size: $size-base;
    color: $text-main;

    .dashicons {
        font-size: 20px;
        width: 20px;
        height: 20px;
        color: $primary;
        transition: $transition-bounce;
    }

    &:hover {
        border-color: $primary;
        background: $primary-light;
        transform: translateX(4px);
        box-shadow: $shadow-md;

        .dashicons {
            transform: scale(1.2);
        }
    }
}

.gfm-canvas {
    background-color: #f8fafc;
    background-image: radial-gradient(#e2e8f0 1px, transparent 1px);
    background-size: 20px 20px;
    border: 2px dashed $border-dark;
    border-radius: $radius-lg;
    min-height: 700px;
    padding: $space-lg;
    transition: $transition-base;

    &.ui-sortable-hover {
        border-color: $primary;
        background-color: $primary-light;
    }

    .gfm-empty-canvas {
        @include flex-center;
        flex-direction: column;
        height: 400px;
        color: $text-muted;
        text-align: center;

        .dashicons {
            font-size: 64px;
            width: 64px;
            height: 64px;
            margin-bottom: $space-md;
            opacity: 0.2;
            color: $primary;
        }

        h2 {
            font-size: 20px;
            font-weight: 700;
            margin-bottom: 8px;
            color: $text-main;
        }

        p {
            font-size: $size-base;
            max-width: 280px;
        }
    }
}

.gfm-field-node {
    margin-bottom: $space-md;
    background: $white;
    border: 1px solid $border;
    overflow: hidden;
    border-radius: $radius;
    box-shadow: $shadow-sm;
    transition: $transition-base;

    &:hover {
        border-color: $primary-alt;
        box-shadow: $shadow-lg;
    }

    &.active {
        border-color: $primary;
        box-shadow: $shadow-xl;
        transform: scale(1.01);
    }
}

.gfm-field-header {
    background: $white;
    padding: $space-sm $space-md;
    display: flex;
    align-items: center;
}

.gfm-field-drag-handle {
    cursor: move;
    margin-right: $space-sm;
    color: $text-light;
    @include flex-center;
    width: 32px;
    height: 32px;
    background: $bg;
    border-radius: $radius-sm;
    transition: $transition-base;

    &:hover {
        color: $primary;
        background: $primary-light;
    }
}

.gfm-field-title {
    flex: 1;

    strong {
        font-size: 15px;
        color: $text-main;
        font-weight: 700;
    }

    small {
        color: $primary;
        font-weight: 700;
        margin-left: $space-sm;
        background: $primary-light;
        padding: 4px 10px;
        border-radius: $radius-full;
        text-transform: uppercase;
        font-size: 9px;
        letter-spacing: 0.05em;
        border: 1px solid rgba($primary, 0.1);
    }
}

.gfm-field-actions {
    display: flex;
    gap: 8px;

    button {
        background: $bg;
        border: 1px solid $border;
        cursor: pointer;
        color: $text-muted;
        transition: $transition-base;
        width: 34px;
        height: 34px;
        border-radius: $radius-sm;
        @include flex-center;
    }

    .gfm-delete-btn:hover {
        color: $danger;
        background: color-mix(in srgb, $white, $danger 8%);
        border-color: rgba($danger, 0.2);
    }

    .gfm-edit-btn:hover {
        color: $primary;
        background: $primary-light;
        border-color: rgba($primary, 0.2);
    }

    .gfm-duplicate-btn:hover {
        color: $success;
        background: color-mix(in srgb, $white, $success 8%);
        border-color: rgba($success, 0.2);
    }
}

.gfm-field-node.active .gfm-edit-btn {
    color: $white;
    background: $primary;
    border-color: $primary;
}

.gfm-field-node.gfm-removing {
    opacity: 0;
    transform: scale(0.95);
    transition: all 0.3s ease;
}

.gfm-field-settings-panel {
    background: #FAFAFB;
    border-top: 1px solid $border;
    padding: $space-lg;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: $space-md;

    &.gfm-hidden {
        display: none !important;
    }

    .gfm-form-group {
        margin-bottom: 0;

        &.full-width {
            grid-column: span 2;
        }
    }
}

.gfm-field-settings-header {
    grid-column: span 2;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: $weight-bold;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: $text-muted;
    padding-bottom: $space-sm;
    margin-bottom: $space-xs;
    border-bottom: 1px solid $border;

    .dashicons {
        font-size: 16px;
        width: 16px;
        height: 16px;
        color: $primary;
    }
}

.gfm-setting-desc {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    color: $text-light;
    line-height: 1.4;
}

.gfm-required-toggle-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
}

.gfm-required-label {
    font-weight: 600;
    font-size: 13px;
    color: $text-main;
}

.gfm-options-setter {
    grid-column: span 2;
    margin-top: $space-sm;
    padding-top: $space-md;
    border-top: 1px dashed $border-dark;

    h4 {
        font-size: 12px;
        text-transform: uppercase;
        color: $text-muted;
        margin: 0 0 $space-sm 0;
        letter-spacing: 0.05em;
        font-weight: 700;
    }
}

.gfm-opt-row {
    display: flex;
    align-items: center;
    gap: $space-sm;
    background: $white;
    padding: $space-sm;
    border-radius: $radius-md;
    border: 1px solid $border;
    margin-bottom: $space-sm;
    box-shadow: $shadow-sm;

    input {
        background: $bg !important;
        transition: $transition-base;

        &:focus {
            background: $white !important;
            border-color: $primary;
        }
    }
}

.gfm-opt-drag {
    color: $text-light;
    cursor: move;
}

// ==========================================
// Template Tag Picker (clickable chips that
// insert {tags} into the related textarea).
// ==========================================
.gfm-tag-picker {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 8px;

    .gfm-tag-picker-label {
        font-size: 12px;
        font-weight: 600;
        color: $text-muted;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        margin-right: 4px;
    }
}

.gfm-tag-chip {
    display: inline-flex;
    align-items: center;
    height: 26px;
    padding: 0 10px;
    background: $primary-light;
    color: $primary;
    border: 1px solid rgba($primary, 0.18);
    border-radius: 999px;
    font-family: ui-monospace, SFMono-Regular, 'Menlo', monospace;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: $transition-base;
    line-height: 1;
    box-shadow: none;

    &:hover {
        background: $primary;
        color: $white;
        border-color: $primary;
        transform: translateY(-1px);
    }

    &:active {
        transform: scale(0.96);
    }

    &.is-inserted {
        background: $success;
        color: $white;
        border-color: $success;
        animation: gfm-chip-pulse 0.5s ease;
    }
}

@keyframes gfm-chip-pulse {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.08); }
    100% { transform: scale(1); }
}

.gfm-opt-btn {
    border: none;
    background: $bg;
    color: $text-muted;
    width: 32px;
    height: 32px;
    border-radius: $radius-sm;
    cursor: pointer;
    @include flex-center;
    transition: $transition-base;

    &:hover {
        background: $primary;
        color: $white;
    }

    &.gfm-opt-remove:hover {
        background: $danger;
    }
}

.gfm-add-opt-btn {
    margin-top: $space-sm;
    font-size: 13px;
    font-weight: $weight-bold;
    color: $primary;
    background: $white;
    border: 2px dashed rgba($primary, 0.4);
    width: 100%;
    padding: $space-sm;
    border-radius: $radius-md;
    cursor: pointer;
    transition: $transition-bounce;
    @include flex-center;
    gap: 8px;

    &:hover {
        background: $primary-light;
        border-color: $primary;
        color: $primary-dark;
        transform: translateY(-2px);
    }
}

.gfm-width-selector {
    display: flex;
    gap: 3px;
    background: $bg;
    padding: 3px;
    border-radius: $radius-md;
    border: 1px solid $border;
}

.gfm-width-btn {
    flex: 1;
    border: none;
    background: transparent;
    padding: 6px 4px;
    font-size: 10px;
    font-weight: 700;
    border-radius: $radius-sm;
    cursor: pointer;
    transition: $transition-base;
    color: $text-muted;
    white-space: nowrap;
    min-width: 0;

    &.active {
        background: $white;
        color: $primary;
        box-shadow: $shadow-sm;
    }

    &:hover:not(.active) {
        background: rgba($white, 0.5);
    }
}