/* --- 1. Global Buttons --- 
.ua-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    border-radius: 30px;
    font-weight: 400;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
    text-decoration: none;
    position: relative;
}

.ua-btn.primary {
    background: #0f0f0f;
    color: #f5f5f5;
    border: 1px solid #0f0f0f;
}
*/
.ua-btn.secondary {
    background: #fff;
    border: 1px solid #ddd;
    color: #333;
}

.ua-btn.primary:hover {
    background: #2f2f2f;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.ua-mini-btn {
    font-size: 13px;
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    border-radius: 20px;
    cursor: pointer;
    border: none;
    display: inline-flex;
    align-items: center;
    backdrop-filter: blur(4px);
}

.ua-mini-btn:hover {
    background: #000;
}

.ua-mini-btn.remove {
    background: #ef4444;
    width: 24px;
    justify-content: center;
    padding: 0;
}

/* --- 2. Modal Structure --- */
#cp-link-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99999;
    display: flex;
    justify-content: center;
    align-items: center;
}

.cp-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
}

.cp-modal-wrapper {
    position: relative;
    z-index: 10;
    width: 100%;
    padding: 20px;
    display: flex;
    justify-content: center;
    pointer-events: none;
}

.cp-modal-content {
    pointer-events: auto;
    background: #fff;
    width: 100%;
    max-width: 460px;
    max-height: 90vh;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: unaFadeUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* --- 3. Header & Body --- */
.cp-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    border-bottom: 1px solid #eee;
    background: #fff;
}

.cp-modal-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 500;
    color: #111;
    letter-spacing: -0.02em;
}

.cp-close-modal-btn {
    background: transparent;
    border: none;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    color: #999;
    transition: 0.2s;
    padding: 5px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}

.cp-close-modal-btn:hover {
    color: #111;
    background: #f5f5f5;
}

.cp-modal-body {
    overflow-y: auto;
    padding: 0;
    scrollbar-width: thin;
    background: #fff;
    display: flex;
    flex-direction: column;
    flex: 1;
    position: relative;
}

/* --- 4. Form Fields --- */
.ua-fields-wrapper {
    padding: 24px;
    flex: 1;
}

.ua-fields-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.ua-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ua-field.half {
    flex: 1 1 45%;
}

.ua-field.full {
    width: 100%;
}

.ua-field label {
    font-size: 13px;
    /* font-weight: 600; */
    color: #111;
}

.ua-field label .req {
    color: #ef4444;
}

/* GLOBAL INPUT STYLE */
.ua-field input[type="text"],
.ua-field input[type="url"],
.ua-field textarea,
.ua-clean-input {
    width: 100%;
    height: 40px;
    padding: 10px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    color: #333;
    box-sizing: border-box;
    font-family: inherit;
    transition: 0.2s;
    background: #fff;
    outline: none;
}

.ua-field input:focus,
.ua-field textarea:focus,
.ua-clean-input:focus {
    border-color: #111;
    box-shadow: 0px 0px 0px 3px #0000000d;
}

.ua-field textarea {
    resize: vertical;
    min-height: 80px;
    height: auto;
}

.ua-field select.ua-clean-input {
    cursor: pointer;
    appearance: none;
}

/* Icon Input Wrapper */
.ua-icon-input {
    position: relative;
}

.ua-icon-input i {
    position: absolute;
    top: 50%;
    left: 12px;
    transform: translateY(-50%);
    color: #999;
    font-size: 16px;
    pointer-events: none;
}

.ua-icon-input input {
    padding-left: 38px !important;
}

/* --- 5. Image Uploader --- */
.ua-img-upload-box {
    width: 100%;
    height: 160px;
    border: 1px dashed #ddd;
    border-radius: 10px;
    background: #fafafa;
    position: relative;
    overflow: hidden;
    margin-bottom: 20px;
    transition: 0.2s;
}

.ua-img-upload-box:hover {
    border-color: #999;
    background: #f5f5f5;
}

.ua-hidden-input {
    display: none;
}

.ua-img-upload-box label {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #888;
    margin: 0;
}

.ua-img-upload-box label i {
    font-size: 24px;
    margin-bottom: 5px;
    color: #ccc;
}

.ua-img-preview-box {
    width: 100%;
    height: 160px;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    margin-bottom: 20px;
    border: 1px solid #eee;
}

.ua-img-preview-box img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-actions {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 5px;
    opacity: 0;
    transition: 0.2s;
}

.ua-img-preview-box:hover .preview-actions {
    opacity: 1;
}

/* --- 6. Icon Picker --- */
.lib-icon-trigger {
    width: 40px;
    height: 40px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: #555;
    cursor: pointer;
    transition: 0.2s;
}

.lib-icon-trigger:hover {
    border-color: #111;
    color: #111;
    background: #fafafa;
}

.ua-icon-picker {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    background: #fff;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    padding: 15px;
    z-index: 200;
    border: 1px solid #eee;
    display: flex;
    flex-direction: column;
    max-height: 400px;
}

.picker-head {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #f0f0f0;
    padding-bottom: 10px;
}

.picker-search-wrap {
    margin-bottom: 10px;
}

.picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
    gap: 6px;
    overflow-y: auto;
    flex: 1;
    padding-right: 5px;
}

.p-item {
    aspect-ratio: 1;
    background: #f9f9f9;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    color: #555;
    border: 1px solid transparent;
    transition: 0.1s;
}

.p-item:hover {
    background: #111;
    color: #fff;
    border-color: #000;
}

.close-picker {
    cursor: pointer;
    padding: 5px;
    font-size: 18px;
}

.picker-loading {
    text-align: center;
    color: #999;
    padding: 20px;
    grid-column: 1 / -1;
}

.p-item.p-remove {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.05);
    border-color: rgba(239, 68, 68, 0.2);
}

.p-item.p-remove:hover {
    background: #ef4444;
    color: #fff;
    border-color: #ef4444;
}

/* --- 7. Footer & Status --- */
.ua-popup-footer {
    padding: 20px 24px;
    border-top: 1px solid #eee;
    margin-top: auto;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 15px;
    background: #fff;
    border-radius: 0 0 16px 16px;
}

.ua-status-msg {
    font-size: 13px;
    text-align: right;
}

.ua-error-msg {
    color: #ef4444;
    font-weight: 500;
    display: none;
}

.ua-success-view {
    text-align: center;
    padding: 60px 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.icon-circle {
    width: 64px;
    height: 64px;
    background: #ecfdf5;
    color: #10b981;
    font-size: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    margin-bottom: 15px;
}

.ua-success-view h3 {
    margin: 20px 0 8px;
    font-size: 1.25rem;
    font-weight: 600;
    color: #1c1c1c;
}

.ua-success-view p {
    color: #666;
    margin: 0 0 25px;
    font-size: 14px;
}

.ua-actions-row {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.ua-link-remove-btn {
    aspect-ratio: 1/1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    transition: 0.2s;
}

/* --- 8. Smart Redirects --- */
.ua-smart-redirects-wrapper {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #f0f0f0;
}

.ua-sr-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.ua-sr-label {
    font-size: 14px;
    color: #333;
}

.ua-sr-desc {
    font-size: 13px;
    color: #777;
    margin: 0 0 15px;
}

.ua-btn.small {
    padding: 6px 12px;
    font-size: 13px;
}

/* Toggle Switch */
.ua-toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
}

.ua-toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: #0f0f0f;
}

input:checked+.slider:before {
    transform: translateX(18px);
}

/* Rule Rows Layout */
.ua-sr-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    align-items: center;
    border: 1px solid #eee;
    padding: 8px;
    border-radius: 10px;
}

/* Helper to manage global width inside row */
.ua-sr-row .ua-clean-input {
    width: auto;
    flex: 1;
    border-radius: 8px;
    appearance: none;
    /*
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23333'%3E%3Cpath d='M11.9999 13.1714L16.9497 8.22168L18.3639 9.63589L11.9999 15.9999L5.63599 9.63589L7.0502 8.22168L11.9999 13.1714Z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 14px;
    */
}

.ua-clean-input:focus {
    border: 1px solid #1c1c1c !important;
    box-shadow: 0px 0px 0px 3px rgba(0, 0, 0, 0.050980392156862744);
}

.ua-clean-input {
    width: 100%;
    height: 40px;
    padding: 10px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    color: #333;
    box-sizing: border-box;
    font-family: inherit;
    transition: 0.2s;
    background: #fff;
    outline: none;
}

/* Specific widths for the selects */
.ua-sr-row .sr-type,
.ua-sr-row .sr-trigger {
    min-width: 0;
}

.ua-sr-delete {
    width: 40px;
    height: 40px;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ef4444;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.2s;
}

.ua-sr-delete:hover {
    background: #ef4444;
    color: #fff;
    border-color: #ef4444;
}

@keyframes unaFadeUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.98);
    }

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

/* Mobile Response: 2 Rows Layout */
@media (max-width: 480px) {
    .cp-modal-content {
        height: 100%;
        /* max-height: 100%; */
        border-radius: 16px 16px 0 0;
    }

    .ua-sr-row {
        flex-wrap: wrap;
        /* Allow items to wrap to next line */
        gap: 8px;
        /* Space between items */
    }

    /* --- Row 1: Device + Trigger --- */
    .ua-sr-row .sr-type,
    .ua-sr-row .sr-trigger {
        /* 50% width minus half the gap (4px) to fit perfectly */
        width: calc(50% - 4px) !important;
        flex: 0 0 calc(50% - 4px) !important;
        order: 1;
        /* Force to top */
    }

    /* --- Row 2: URL + Remove Icon --- */
    .ua-sr-row .sr-url {
        order: 2;
        /* Force to bottom */
        flex: 1 !important;
        /* Take up all remaining space */
        width: auto !important;
        min-width: 0;
    }

    .ua-sr-row .ua-sr-delete {
        order: 2;
        /* Force to bottom with URL */
        margin-left: 0;
    }
}

.label-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    /* margin-bottom: 2px; */
}

.char-counter {
    font-size: 11px;
    color: #999;
    font-weight: 400;
}

.char-counter.limit-reached {
    color: #ef4444;
    font-weight: 600;
}

/* Prevent background scroll when modal is active */
body.ua-modal-open {
    overflow: hidden !important;
    height: 100%;
}