/* ═══════════════════════════════════════════════
   AI Chat Box — Right Side Collapsible Widget
   ═══════════════════════════════════════════════ */

:root {
    --ai-bg-color: #ffffff;
    --ai-bg2-color: #f8f9fa;
    --ai-font-color: #1a1a1a;
    --ai-btn-color: #333333;
    --ai-brd-color: #e5e5e5;
    --ai-cbg-color: #f4f4f4;
    --ai-input-brd-color: #d4d4d4;
    --ai-placeholder-color: #8e8e8e;
    --ai-accent: #0D99FF;
    --ai-shadow: 0 4px 24px rgba(0, 0, 0, 0.12), 0 1px 4px rgba(0, 0, 0, 0.06);
    --ai-radius: 12px;
    --ai-width: 380px;
}

[data-theme="dark"] {
    --ai-bg-color: #2a2a2a;
    --ai-bg2-color: #333333;
    --ai-font-color: #e8e8e8;
    --ai-btn-color: #888888;
    --ai-brd-color: #444444;
    --ai-cbg-color: #363636;
    --ai-input-brd-color: #505050;
    --ai-placeholder-color: #666666;
    --ai-shadow: 0 4px 24px rgba(0, 0, 0, 0.3), 0 1px 4px rgba(0, 0, 0, 0.15);
}

/* ─── Main Container ─── */
.ai {
    position: fixed !important;
    right: 280px;
    bottom: 20px;
    width: var(--ai-width);
    border-radius: var(--ai-radius);
    background: var(--ai-bg-color);
    box-shadow: var(--ai-shadow);
    z-index: 9999;
    flex-direction: column;
    overflow: hidden;
    transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 600px;
    border: 1px solid var(--ai-brd-color);
}

/* ─── Collapsed State — Only header visible ─── */
.ai.ai_collapsed {
    max-height: 48px;
}

.ai.ai_collapsed .ai_content {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-8px);
}

.ai.ai_collapsed .ai_header_toggle_icon {
    transform: rotate(180deg);
}

/* ─── Header ─── */
.ai_header {
    background: var(--ai-bg-color);
    width: 100%;
    height: 48px;
    min-height: 48px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 6px 0 14px;
    border-bottom: 1px solid var(--ai-brd-color);
    border-radius: var(--ai-radius) var(--ai-radius) 0 0;
    cursor: pointer;
    position: relative;
    z-index: 2;
    user-select: none;
}

.ai:not(.ai_collapsed) .ai_header {
    cursor: default;
}

.ai_header_title {
    font-size: 13px;
    font-weight: 600;
    color: var(--ai-font-color);
    display: flex;
    align-items: center;
    gap: 6px;
    letter-spacing: 0.01em;
}

.ai_header_title::before {
    content: '✨';
    font-size: 14px;
}

.ai_logo {
    display: none;
}

.ai_header_right {
    display: flex;
    align-items: center;
    gap: 2px;
}

.ai_coins_link {
    display: none !important;
}

.ai_exit {
    width: 32px;
    height: 32px;
    text-align: center;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background 0.2s ease;
}

.ai_exit:hover {
    background: var(--ai-cbg-color);
}

.ai_exit svg {
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai_icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    stroke-width: 0;
    stroke: var(--ai-font-color);
    fill: var(--ai-font-color);
    vertical-align: middle;
}

/* ─── Content Area ─── */
.ai_content {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: auto;
    padding: 0;
    align-items: stretch;
    justify-content: flex-start;
    overflow-y: auto;
    transition: opacity 0.25s ease, transform 0.25s ease;
    opacity: 1;
    transform: translateY(0);
}

.ai_case {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 12px 14px;
    box-sizing: border-box;
    position: relative;
}

/* ─── Title ─── */
.ai_title {
    font-size: 13px;
    font-weight: 500;
    margin: 0 0 10px 0;
    text-align: left;
    color: var(--ai-font-color);
    line-height: 1.4;
}

/* ─── Textarea Container ─── */
.ai_case_text {
    width: 100%;
    position: relative;
    flex-direction: column;
    display: flex;
    background: var(--ai-cbg-color);
    border-radius: 10px;
    margin-bottom: 0;
    border: 1px solid var(--ai-input-brd-color);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.ai_case_text:has(textarea:focus) {
    border-color: var(--ai-accent);
    box-shadow: 0 0 0 2px rgba(13, 153, 255, 0.1);
}

.ai_left {
    width: 100%;
}

.ai_textarea {
    width: 100%;
    height: 100%;
    background: transparent;
    border: 0;
    border-radius: 10px;
    font-size: 13px;
    padding: 10px 12px;
    box-sizing: border-box;
    outline: none;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    resize: none;
    min-height: 56px;
    max-height: 100px;
    color: var(--ai-font-color);
    caret-color: var(--ai-accent) !important;
    line-height: 1.5;
}

.ai_textarea::placeholder {
    color: var(--ai-placeholder-color);
    font-size: 12px;
}

/* ─── Actions Row ─── */
.ai_textarea_actions {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 4px 4px 0;
    box-sizing: border-box;
}

.ai_settings_button {
    height: 32px;
    cursor: pointer;
    border: 0;
    background: transparent;
    border-radius: 6px;
    display: flex;
    padding: 0 6px;
    font-size: 11px;
    align-items: center;
    color: var(--ai-font-color);
    transition: background 0.2s ease;
    gap: 4px;
}

.ai_settings_button:hover {
    background: var(--ai-brd-color);
}

.ai_settings_button img {
    height: 18px;
    width: 18px;
    border-radius: 3px;
}

#aiTimer {
    font-size: 11px !important;
    position: static !important;
    color: var(--ai-placeholder-color) !important;
}

/* ─── Send Button ─── */
.ai_send {
    height: 32px;
    min-width: 32px;
    padding: 0 14px;
    border-radius: 16px;
    border: 0;
    background: var(--ai-accent);
    cursor: pointer;
    margin: 3px;
    transition: background 0.2s ease, transform 0.15s ease;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 12px;
    font-weight: 600;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    letter-spacing: 0.02em;
}

.ai_send:hover {
    background: #0a7acc;
    transform: scale(1.06);
}

.ai_send:active {
    transform: scale(0.94);
}

.ai_send svg {
    fill: white;
    stroke: none;
    width: 14px;
    height: 14px;
}

.ai_send.ai_loading svg {
    opacity: 0;
}

.ai_send.ai_loading {
    background: var(--ai-btn-color);
    pointer-events: none;
}

.ai_send.ai_loading:after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -10px;
    margin-top: -10px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: ai-spin 0.7s linear infinite;
}

@keyframes ai-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ─── Error Message ─── */
.ai_error_message {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    max-width: 340px;
    z-index: 100001;
    margin-bottom: 8px;
    background: #ff4d4f;
    color: white;
    min-width: 200px;
    padding: 10px 14px;
    border-radius: 8px;
    display: none;
    font-size: 12px;
    line-height: 1.4;
    box-shadow: 0 4px 12px rgba(255, 77, 79, 0.3);
}

/* ─── Materials Window (Modal) ─── */
.ai_overlay_stop {
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 99999;
    display: none;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(2px);
}

.ai_materials_window {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--ai-bg-color);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    z-index: 999999;
    min-width: 300px;
    max-width: 360px;
    box-sizing: border-box;
}

.ai_materials_window.visible {
    display: block;
}

.ai_material-selector {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.ai_selector-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.ai_selector-group label {
    font-weight: 600;
    font-size: 12px;
    color: var(--ai-font-color);
}

.ai_selector-group select {
    padding: 7px 10px;
    border: 1px solid var(--ai-input-brd-color);
    border-radius: 6px;
    font-size: 12px;
    background-color: var(--ai-bg-color);
    cursor: pointer;
    outline: 0;
    color: var(--ai-font-color);
    transition: border-color 0.2s ease;
}

.ai_selector-group select:focus {
    border-color: var(--ai-accent);
}

.ai_select-material-btn {
    padding: 8px 14px;
    background-color: var(--ai-accent);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
    margin-top: 6px;
}

.ai_select-material-btn:hover {
    background-color: #0a7acc;
}

/* ─── Custom Select ─── */
.ai_custom-select-container {
    position: relative;
}

.ai_custom-select-trigger {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid var(--ai-input-brd-color);
    border-radius: 6px;
    background-color: var(--ai-bg-color);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    box-sizing: border-box;
    outline: none;
    color: var(--ai-font-color);
}

.ai_selected-option-content {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai_selected-option-img {
    width: 22px;
    height: 22px;
    object-fit: cover;
    border-radius: 3px;
    flex-shrink: 0;
}

.ai_selected-option-text {
    color: var(--ai-font-color);
    font-size: 12px;
}

.ai_arrow {
    font-size: 9px;
    color: var(--ai-placeholder-color);
}

.ai_custom-select-options {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: var(--ai-bg-color);
    border: 1px solid var(--ai-input-brd-color);
    border-top: none;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 10;
    max-height: 160px;
    overflow-y: auto;
}

.ai_custom-select-options.visible {
    display: block;
}

.ai_custom-select-option {
    padding: 6px 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: background-color 0.15s ease;
    color: var(--ai-font-color);
    font-size: 12px;
}

.ai_custom-select-option:hover {
    background-color: var(--ai-cbg-color);
}

.ai_custom-select-option img {
    width: 28px;
    height: 28px;
    object-fit: cover;
    border-radius: 3px;
    flex-shrink: 0;
}

.ai_custom-select-option span {
    font-size: 12px;
    color: var(--ai-font-color);
}

.ai_custom-select-options::-webkit-scrollbar {
    width: 4px;
}

.ai_custom-select-options::-webkit-scrollbar-track {
    background: transparent;
}

.ai_custom-select-options::-webkit-scrollbar-thumb {
    background: var(--ai-brd-color);
    border-radius: 3px;
}

/* ─── Custom Size Inputs ─── */
.ai_custom-input-group {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed var(--ai-brd-color);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ai_custom-input-group.hidden {
    display: none;
}

.ai_custom-input-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai_custom-input-row label {
    font-weight: normal;
    font-size: 12px;
    color: var(--ai-font-color);
    width: 50px;
    flex-shrink: 0;
}

.ai_custom-input-row input[type="number"] {
    flex-grow: 1;
    padding: 6px 8px;
    border: 1px solid var(--ai-input-brd-color);
    border-radius: 6px;
    font-size: 12px;
    box-sizing: border-box;
    color: var(--ai-font-color);
    background: var(--ai-bg-color);
    outline: none;
}

.ai_custom-input-row input[type="number"]:focus {
    border-color: var(--ai-accent);
}

.ai_custom-input-row input[type=number]::-webkit-inner-spin-button,
.ai_custom-input-row input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.ai_custom-input-row input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* ─── Hidden elements ─── */
.ai_bouncing-icon,
.ai_logo_link,
.ai_case_btns,
.ai_right {
    display: none !important;
}

/* ─── Responsive ─── */
@media screen and (max-width: 480px) {
    .ai {
        width: calc(100vw - 16px);
        right: 8px;
        top: auto;
        bottom: 8px;
    }
}