/* ==========================================================================
   COMMON UI COMPONENTS (Panels, Buttons, Inputs, Sliders)
   Decoupled from style.css
   ========================================================================== */

/* --- Unified Panel Style --- */
:is(.panel, .static-page-panel, .standalone-static-panel, .static-content-panel) {
    background-color: #ffffff;
    background-image: 
        linear-gradient(135deg, rgba(255, 255, 255, 0.06), transparent 20%),
        linear-gradient(color-mix(in srgb, var(--panel-bg), black 6%), color-mix(in srgb, var(--panel-bg), black 6%)),
        linear-gradient(var(--panel-bg), var(--panel-bg)),
        url('/assets/shaders/confetti.webp');
    background-size: 100% 100%, 100% 100%, 100% 100%, 500.5px 500.5px;
    background-repeat: no-repeat, repeat, repeat, repeat;
    background-attachment: scroll, local, local, local;
    background-blend-mode: overlay, lighten, multiply, difference;
    border-radius: 10px;
    box-shadow: -2px -2px 6px rgba(255, 255, 255, 0.03), 3px 3px 8px rgba(0, 0, 0, 0.25);
    padding: 20px;
    position: relative;
    display: flex; 
    flex-direction: column;
    overflow: visible; 
    flex-shrink: 0;
    isolation: isolate;
    color: var(--text-primary);
}

.panel > h2, .panel > h3 { 
    margin-bottom: 15px; 
    color: var(--highlight-secondary); 
}

.subpanel {
    margin-top: 12px; 
    padding: 12px;
    border-radius: 8px; 
    background: var(--bg-secondary);
    color: #ffd9a6; 
    font-size: 0.9rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.subpanel h4 { 
    margin-bottom: 5px; 
    color: var(--highlight-secondary); 
}

.subpanel p { 
    font-size: 0.9em; 
    color: var(--text-secondary); 
}


/* --- Buttons --- */
.base-button {
    display: inline-block; 
    padding: 10px 18px;
    border-radius: 8px; 
    border: none; 
    cursor: pointer;
    background: linear-gradient(135deg, var(--highlight-primary), var(--highlight-secondary));
    color: #fff; 
    font-weight: 600; 
    text-decoration: none; 
    text-align: center;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
    transition: transform 120ms ease, filter 120ms;
}

.base-button:hover { 
    filter: brightness(1.1); 
}

.base-button:active { 
    transform: scale(0.98); 
}

.base-button:disabled {
    background: var(--text-secondary); 
    color: var(--bg-tertiary);
    cursor: not-allowed; 
    transform: none; 
    filter: none; 
    opacity: 0.5;
}

.option-popout {
    background: linear-gradient(135deg, var(--highlight-primary), var(--highlight-secondary));
    display: inline-block; 
    padding: 12px 24px;
    border-radius: 8px; 
    color: #fff; 
    font-weight: 700;
    text-align: center; 
    cursor: pointer; 
    border: none;
    transform: translateY(0);
    box-shadow: 0 0 0 color-mix(in oklab, var(--highlight-primary), black 40%);
    transition: transform 230ms cubic-bezier(.2, .8, .2, 1), box-shadow 230ms cubic-bezier(.2, .8, .2, 1);
    will-change: transform, box-shadow; 
    position: relative; 
    isolation: isolate;
}

.option-popout::after {
    content: ""; 
    position: absolute; 
    inset: 0; 
    pointer-events: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='40' height='8' viewBox='0 0 40 8'><path d='M0 6 L8 2 L16 6 L24 2 L32 6 L40 2' stroke='white' stroke-opacity='0.14' stroke-width='1' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-size: 40px 8px; 
    background-repeat: repeat; 
    mix-blend-mode: overlay;
}

.option-popout:hover { 
    transform: translateY(-10px); 
    box-shadow: 0 10px 0 color-mix(in oklab, var(--highlight-primary), rgb(31, 16, 58) 50%); 
}

.option-popout:active { 
    transform: translateY(-8px); 
    box-shadow: 0 8px 0 color-mix(in oklab, var(--highlight-primary), rgb(31, 16, 58) 50%); 
}

.option-popout:disabled {
    transform: translateY(0); 
    box-shadow: 0 0 0 rgba(0, 0, 0, 0);
    background-image: none; 
    background-color: var(--text-secondary);
    opacity: 0.5; 
    cursor: not-allowed;
}

.waiting-button {
    display: inline-flex; 
    align-items: center;
    padding: 10px 18px; 
    border-radius: 8px;
    background: var(--bg-secondary); 
    color: var(--text-secondary);
    font-weight: 600; 
    text-align: center; 
    border: 1px solid var(--border-color);
}

.waiting-spinner {
    margin-right: 10px; 
    width: 20px; 
    height: 20px;
    border-radius: 50%; 
    border: 4px solid rgba(var(--highlight-primary-rgb), 0.2);
    border-top-color: var(--highlight-primary);
    animation: playful-spin 3s cubic-bezier(0.55, -0.8, 0.27, 0.5) infinite;
    flex-shrink: 0; 
    display: inline-block; 
    box-sizing: border-box;
}


/* --- Inputs & Checkboxes & Dropdowns --- */
.base-input, 
.base-dropdown {
    padding: 10px 12px; 
    border-radius: 8px;
    background: var(--input-bg); 
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.08);
    font-family: inherit; 
    font-size: 1em;
    max-width: 100%;
}

.base-checkbox {
    appearance: none;
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: var(--input-bg);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    cursor: pointer;
    position: relative;
    transition: background-color 0.2s, border-color 0.2s;
    flex-shrink: 0;
    padding: 0;
}

.base-checkbox:checked {
    background-color: var(--highlight-primary);
    border-color: var(--highlight-primary);
}

.base-checkbox:checked::after {
    content: '✓';
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 14px;
    font-weight: bold;
}

.base-input:focus, 
.base-dropdown:focus, 
.base-checkbox:focus {
    outline: none; 
    border-color: var(--highlight-primary);
    box-shadow: 0 0 0 2px rgba(var(--highlight-primary-rgb), 0.3);
}

.base-dropdown {
    -webkit-appearance: none; 
    appearance: none;
    padding: 8px 2.5rem 8px 12px;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat; 
    background-position: right 0.8rem center;
    background-size: 1em; 
    cursor: pointer;
}

.base-dropdown:disabled { 
    opacity: 0.5; 
    cursor: not-allowed; 
}


/* --- Multi-Select Dropdown --- */
.multi-select-container { 
    position: relative; 
    width: 100%; 
    min-width: min(200px, 100%); 
}

.multi-select-trigger {
    position: relative; 
    cursor: pointer; 
    user-select: none;
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis;
    padding: 10px 12px; 
    border-radius: 8px;
    background: var(--input-bg); 
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.08);
    font-family: inherit; 
    font-size: 1em;
    padding-right: 2.5rem;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat; 
    background-position: right 0.8rem center; 
    background-size: 1em;
}

.multi-select-options {
    position: absolute; 
    top: 100%; left: 0; right: 0;
    background: var(--bg-tertiary); 
    border: 1px solid var(--border-color);
    border-radius: 8px; 
    margin-top: 5px; 
    max-height: 250px; 
    overflow-y: auto;
    z-index: 500; 
    display: none; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
}

.multi-select-options.show { 
    display: block; 
    animation: popInFromTop 0.2s ease-out; 
}

.multi-select-option {
    padding: 10px 15px; 
    cursor: pointer; 
    display: flex;
    align-items: center; 
    gap: 10px;
    border-bottom: 1px solid var(--muted-line);
    transition: background-color 0.1s;
}

.multi-select-option:last-child { 
    border-bottom: none; 
}

.multi-select-option:hover { 
    background-color: var(--bg-secondary); 
}

.multi-select-all-option { 
    background-color: rgba(var(--bg-tertiary-rgb), 0.8); 
    font-weight: bold; 
    border-bottom: 2px solid var(--border-color); 
}

.multi-select-checkbox {
    width: 18px; 
    height: 18px; 
    border: 2px solid var(--text-secondary);
    border-radius: 4px; 
    position: relative;
    transition: border-color 0.2s, background-color 0.2s;
}

.multi-select-option.selected .multi-select-checkbox { 
    background-color: var(--highlight-primary); 
    border-color: var(--highlight-primary); 
}

.multi-select-option.selected .multi-select-checkbox::after {
    content: '✓'; 
    position: absolute; 
    top: 50%; left: 50%;
    transform: translate(-50%, -50%); 
    color: white; 
    font-size: 12px; 
    font-weight: bold;
}


/* --- Sliders & Scrollbars --- */
.base-slider {
    width: 100%; 
    appearance: none; 
    height: 6px;
    border-radius: 8px; 
    background: var(--border-color);
    outline: none; 
    flex-grow: 1;
}

.base-slider::-webkit-slider-thumb {
    appearance: none; 
    width: 16px; 
    height: 16px; 
    border-radius: 50%;
    background: linear-gradient(180deg, var(--highlight-secondary), var(--highlight-primary));
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.5); 
    cursor: pointer; 
    transition: transform 120ms;
}

.base-slider::-webkit-slider-thumb:hover { 
    transform: scale(1.15); 
}

.base-slider::-moz-range-thumb {
    width: 16px; 
    height: 16px; 
    border-radius: 50%;
    background: linear-gradient(180deg, var(--highlight-secondary), var(--highlight-primary));
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.5); 
    cursor: pointer; 
    border: none; 
    transition: transform 120ms;
}

.base-slider::-moz-range-thumb:hover { 
    transform: scale(1.15); 
}

::-webkit-scrollbar { 
    width: 10px; 
    height: 10px; 
}

::-webkit-scrollbar-track { 
    background: var(--bg-tertiary); 
    border-radius: 8px; 
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--highlight-primary), var(--highlight-secondary));
    border-radius: 8px; 
    border: 2px solid rgba(0, 0, 0, 0.25);
}

::-webkit-scrollbar-thumb:hover { 
    filter: brightness(1.1); 
}
