/** General Component UI Widgets (BEM) */
:root {
    /* Widget colors with intensity levels */
    --widget-green-l1: #e8f5e9;
    --widget-green-l2: #a5d6a7;
    --widget-green-l3: #28a745;

    --widget-red-l1: #ffd1d1;
    --widget-red-l2: #ff9a9a;
    --widget-red-l3: #ef9a9a;
    --widget-red-l4: #c0392b;

    --widget-orange-l1: #fff3e0;
    --widget-orange-l2: #ffcc80;
    --widget-orange-l3: #f57c00;

    --widget-blue-l1: #e3f2fd;
    --widget-blue-l2: #90caf9;
    --widget-blue-l3: #0066cc;

    --widget-gray-l1: #f5f5f5;
    --widget-gray-l2: #dddddd;
    --widget-gray-l3: #999999;
    --widget-gray-l4: #666666;
    --widget-gray-l5: #555555;

    --widget-indigo-l1: #e8eaf6;
    --widget-indigo-l2: #9fa8da;
    --widget-indigo-l3: #3f51b5;

    --widget-pink-l1: #fce4ec;
    --widget-pink-l2: #f48fb1;
    --widget-pink-l3: #e91e63;
}

.widget--faded {
    opacity: 0;
}

/*--------------------------------------------------------
  || Spinner
--------------------------------------------------------*/
.spinner-position--center {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

.spinner--circle {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
}

.spinner--circle::after {
    content: "";
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 4px solid var(--widget-gray-l2);
    border-top-color: var(--widget-gray-l5);
    animation: spinner-circle-rotation 1.2s infinite linear;
}

@keyframes spinner-circle-rotation {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.spinner--cubes {
    width: 40px;
    height: 40px;
    --c: no-repeat linear-gradient(#2A9D8F 0 0);
    background: var(--c), var(--c), var(--c), var(--c);
    background-size: 21px 21px;
    animation: spinner-cubes-rotation 1.5s infinite cubic-bezier(0.3, 1, 0, 1);
}

@keyframes spinner-cubes-rotation {
    0% {
        background-position: 0 0, 100% 0, 100% 100%, 0 100%
    }

    33% {
        background-position: 0 0, 100% 0, 100% 100%, 0 100%;
        width: 60px;
        height: 60px
    }

    66% {
        background-position: 100% 0, 100% 100%, 0 100%, 0 0;
        width: 60px;
        height: 60px
    }

    100% {
        background-position: 100% 0, 100% 100%, 0 100%, 0 0
    }
}

.spinner--eyes {
    display: inline-flex;
    gap: 10px;
}

.spinner--eyes:before,
.spinner--eyes:after {
    content: "";
    height: 20px;
    aspect-ratio: 1;
    border-radius: 50%;
    background:
        radial-gradient(farthest-side, #000 95%, #0000) 35% 35%/6px 6px no-repeat #fff;
    animation: spinner-eyes-rotation 3s infinite;
}

@keyframes spinner-eyes-rotation {

    0%,
    11% {
        background-position: 35% 35%
    }

    14%,
    36% {
        background-position: 65% 35%
    }

    38%,
    61% {
        background-position: 65% 65%
    }

    64%,
    86% {
        background-position: 35% 65%
    }

    88%,
    100% {
        background-position: 35% 35%
    }
}


/*--------------------------------------------------------
  || Message Widget
--------------------------------------------------------*/
/* @MessageType */
.message--success {
    background-color: var(--widget-green-l1);
    color: var(--widget-green-l3);
    border: 1px solid var(--widget-green-l2);
}

.message--failed {
    background-color: var(--widget-red-l1);
    color: var(--widget-red-l4);
    border: 1px solid var(--widget-red-l3);
}

.message--error {
    background-color: var(--widget-red-l2);
    color: var(--widget-red-l4);
    border: 1px solid var(--widget-red-l3);
}

.message--warning {
    background-color: var(--widget-orange-l1);
    color: var(--widget-orange-l3);
    border: 1px solid var(--widget-orange-l2);
}

.message--note {
    background-color: var(--widget-blue-l1);
    color: var(--widget-blue-l3);
    border: 1px solid var(--widget-blue-l2);
}

.message--neutral {
    background-color: var(--widget-gray-l1);
    color: var(--widget-gray-l4);
    border: 1px solid var(--widget-gray-l2);
}

.message--tip {
    background-color: var(--widget-indigo-l1);
    color: var(--widget-indigo-l3);
    border: 1px solid var(--widget-indigo-l2);
}

.message--validation {
    background-color: var(--widget-pink-l1);
    color: var(--widget-pink-l3);
    border: 1px solid var(--widget-pink-l2);
}

/* Message */
.message-widget__message {
    padding: 0.75em;
    margin: 0.15em 0;
    border-radius: 0.5em;
    box-shadow: inset 0px 0px 0.25em 0px rgba(0, 0, 0, 0.2);
    width: 100%;
    overflow-wrap: anywhere;
    pointer-events: none;
}

/* Toast Container */
.message-widget__toaster {
    position: fixed;
    display: flex;
    flex-direction: column;
    padding: 8px;
    z-index: 10000;
}

.message-widget__toaster .message-widget__message {
    width: fit-content;
}

.message-widget__toaster--top {
    top: 0;
    flex-direction: column-reverse;
}

.message-widget__toaster--bottom {
    bottom: 0;
}

.message-widget__toaster--left {
    left: 0;
    align-items: start;
}

.message-widget__toaster--right {
    right: 0;
    align-items: end;
}

.message-widget__toaster--center-x {
    left: 50%;
    transform: translateX(-50%);
    align-items: center;
}

.message-widget__toaster--center-y {
    top: 50%;
    /* transform: translateY(-50%); */
    flex-direction: column-reverse;
}

.message-widget__toaster--center-xy {
    left: 50%;
    top: 50%;
    /* transform: translate(-50%, -50%); */
    transform: translateX(-50%);
    align-items: center;
    flex-direction: column-reverse;
}


/*--------------------------------------------------------
  || Button Widget
--------------------------------------------------------*/

.button-widget {
    padding: 0.75em 1.5em;
    border-radius: 0.5em;
    font-size: 1rem;
    text-align: center;
    font-weight: 600;
    width: fit-content;
    cursor: pointer;

    background: #ffffff;
    color: #111827;
    /* border: 1px solid #d1d5db; */
    border: none;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.1);

    transition: background-color 0.2s ease, opacity 0.2s ease;
}

/* States */
.button-widget:hover {
    background: var(--button-background-hover, #eeefef);
}

.button-widget:disabled {
    opacity: 0.4;
    pointer-events: none;
    cursor: default;
}

.button-widget--frozen {
    pointer-events: none;
    cursor: default;
}

/* Shape */
.button-widget__width--fill {
    width: 100%;
}

.button-widget__shape--round {
    border-radius: 50px;
}

/* Size */
.button-widget__size--sm {
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
}

.button-widget__size--lg {
    padding: 1rem 2rem;
    font-size: 1.2rem;
}

/* Color Style*/
.button-widget__style--clear {
    box-shadow: none;
    background: transparent;
}

.button-widget__style--grey {
    background: #afaeae;
    color: white;
    --button-background-hover: #9d9d9d;
}

.button-widget__style--green {
    background: #28a745;
    color: white;
    --button-background-hover: #218b3a;
}

.button-widget__style--blue {
    background: #2196F3;
    color: white;
    --button-background-hover: #1976D2;
}

/*--------------------------------------------------------
  || Form Widget
--------------------------------------------------------*/
.form-widget {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 0.5rem;
}

.form-widget--scroll {
    overflow-y: auto;
}

.form-widget__group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-widget__label {
    font-weight: 600;
    font-size: 1rem;
    color: #333;
}

.form-widget__label:has(.form-widget__input-checkbox) {
    font-size: 0.9rem;
}

.form-widget__input {
    padding: 0.75rem;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 0.9rem;
    max-height: 40vh;
    transition: border-color 0.2s ease;
}

.form-widget__input-checkbox {
    appearance: none;
    width: 1.8em;
    height: 1.8em;
    vertical-align: middle;
    border: 1px solid #ccc;
    border-radius: 100%;
    background: white;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
}

label .form-widget__input-checkbox {
    margin-left: 0.75em;
}

.form-widget__input-checkbox::after {
    content: '\2713';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 1.6em;
    font-weight: bold;
}

.form-widget__input-checkbox:checked {
    background: #28a745;
}

.form-widget__file-input::file-selector-button {
    padding: 0.5rem;
    border: 1px solid #aaaeb0;
    border-radius: 4px;
    font-size: 0.9rem;
    margin-right: 1rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.form-widget__file-input::file-selector-button:hover {
    background-color: #e1e1e1;
}

.form-widget__input:focus {
    outline: none;
    border-color: #2196F3;
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.1);
}

.form-widget__input--array {
    margin: 0.25rem;
    width: 120px;
}

/* non-input form elements */
.form-widget__preview-image {
    max-width: 100%;
    max-height: 40vh;
    margin-left: auto;
    margin-right: auto;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.form-widget__info {
    font-size: 0.8rem;
    color: var(--widget-gray-l3);
}

.form-widget__info-icon {
    font-size: 0.6em;
    vertical-align: super;
    padding-left: 0.25rem;
    cursor: pointer;
}

.form-widget__info-icon:hover {
    opacity: 0.8;
}

#captchaimg {
    width: 100%;
    border: 1px solid #ccc;
    border-radius: 0.5rem;
    cursor: pointer;
}

/*--------------------------------------------------------
  || Selection Widget
--------------------------------------------------------*/
.selection-widget {
    position: absolute;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 1010;
    width: 300px;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--widget-gray-l2);
    overflow: hidden;
}

/* Header */
.selection-widget__header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--widget-gray-l2);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--widget-gray-l1);
}

.selection-widget__header-title {
    font-weight: 500;
    font-size: 16px;
    flex-grow: 1;
    text-align: center;
}

.selection-widget__header-back,
.selection-widget__header-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--widget-gray-l5);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

.selection-widget__header-back:hover,
.selection-widget__header-close:hover {
    background-color: #e9ecef;
}

/* Content */
.selection-widget__content {
    position: relative;
    flex: 1;
    overflow: hidden;
    transition: min-height 0.18s ease;
}

.selection-widget__panel {
    position: absolute;
    inset: auto 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    transition: transform 0.18s ease;
}

.selection-widget__panel--pos-left {
    transform: translateX(-100%);
}

.selection-widget__panel--pos-right {
    transform: translateX(100%);
}

/* Items */
.selection-widget__item {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid var(--widget-gray-l1);
    position: relative;
    transition: background-color 0.2s ease;
}

.selection-widget__item--category {
    background-color: var(--widget-gray-l1);
    border-bottom: 1px solid var(--widget-gray-l2);
    border-top: 1px solid var(--widget-gray-l2);
    padding-right: 26px;
}

.selection-widget__item:hover {
    background-color: var(--widget-gray-l1);
}

.selection-widget__item-arrow {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--widget-gray-l4);
    font-size: 18px;
    line-height: 0;
}

/*--------------------------------------------------------
  || Modal Widget
--------------------------------------------------------*/
.modal-widget {
    /* new stacking context */
    position: fixed;
    z-index: 2000;
    inset: 0;
    transition: opacity 0.2s ease;
}

.modal-widget::before {
    content: '';
    position: absolute;
    z-index: 2;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
}

.modal-widget--hidden {
    display: none;
}

.modal-widget__panel {
    /* new stacking context for content */
    position: fixed;
    z-index: 1;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-height: 95vh;
    max-width: 95vw;
    pointer-events: none;
    border-radius: 16px;
    background-color: white;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    padding: 2rem;
    overflow: hidden;

    display: flex;
    flex-direction: column;
}

.modal-widget__panel--transparent {
    background-color: transparent;
    box-shadow: none;
}

.modal-widget__panel:last-child {
    /* Active Panel */
    pointer-events: auto;
    z-index: 3;
}

.modal-widget__panel:has(.modal-widget__close) {
    padding: calc(2rem + 12px) 2rem 2rem;
}

.modal-widget__close {
    position: absolute;
    inset: 12px 12px auto auto;
    background-color: transparent;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: var(--widget-gray-l5);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

.modal-widget__panel>h3 {
    margin-bottom: 1rem;
}

.modal-widget__close:hover {
    background-color: var(--widget-gray-l1);
}

.modal-widget__content {
    width: var(--modal-widget-max-content-width, 400px);
    max-width: 100%;

    /* Ensures scrollable content */
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* confirm */
.modal-widget__confirm {
    --modal-widget-max-content-width: 400px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.modal-widget__confirm p {
    grid-column: 1 / -1;
    font-size: 1.2rem;
    word-wrap: break-word;
}

.modal-widget__confirm-btn {
    grid-row: 2;
    font-size: 1.1rem;
    font-weight: 500;
    background-color: var(--widget-gray-l2);
    color: var(--widget-gray-l5);
    padding: 0.5rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
}

.modal-widget__confirm-btn:hover {
    filter: brightness(0.9);
}

.modal-widget__confirm-btn--danger {
    background-color: var(--widget-red-l2);
}

.modal-widget__confirm-btn--safe {
    background-color: var(--widget-green-l2);
}

/*--------------------------------------------------------
  || Dropdown Styling
--------------------------------------------------------*/

.dropdown-widget {
    position: relative;
    width: 100%;
}

.dropdown-widget>* {
    width: 100%;
}

.dropdown-widget__pane {
    position: absolute;
    top: 100%;
    left: 0;
    max-height: 40vh;
    overflow-y: auto;
    background: white;
    border: 1px solid #ccc;
    box-shadow: 0 8px 16px -4px rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    z-index: 1000;
    list-style: none;
    padding: 0;
    margin: 0;
}

.dropdown-widget__pane li {
    padding: 8px;
    cursor: pointer;
}

.dropdown-widget__pane li:hover {
    background: #f0f0f0;
}

/* Location Picker */
.dropdown-widget__pane li.location-picker {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
}

.dropdown-widget__pane li.location-picker .flag {
    font-size: 1.4rem;
    flex-shrink: 0;
}

.dropdown-widget__pane li.location-picker .content {
    flex: 1;
    min-width: 0;
}

.dropdown-widget__pane li.location-picker .location-name {
    font-weight: 500;
    color: #333;
    margin-bottom: 2px;
}

.dropdown-widget__pane li.location-picker .location-path {
    font-size: 0.85rem;
    color: var(--widget-gray-l4);
    line-height: 1.2;
    opacity: 0.8;
}