/* Turtle Helper */

/* Icon */

.turtle-helper-icon {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99999;
    width: 64px;
    height: 64px;
    cursor: pointer;
    transition: transform 0.15s ease;
}

.turtle-helper-icon:hover {
    transform: scale(1.1);
}

.turtle-helper-icon img {
    width: 100%;
    height: 100%;
}

/* Panel */

#starlogo-turtle-helper {
    position: fixed;
    bottom: 80px;
    right: 20px;
    z-index: 99999;
    width: 600px;
    height: calc(100vh - 200px);
    background: var(--bg-dark-alt);
    color: var(--text-primary);
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    --chat-input-min-height: 34px;
    --chat-input-max-height: 132px;
}

#starlogo-turtle-helper.hidden {
    display: none;
}

/* Header */

#starlogo-turtle-helper .chat-header {
    padding: 12px 15px;
    background: var(--bg-dark);
    border-bottom: 1px solid var(--gray-700);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

#starlogo-turtle-helper .header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

#starlogo-turtle-helper .header-logo {
    width: 32px;
    height: 32px;
}

#starlogo-turtle-helper .header-text {
    font-size: 18px;
    font-weight: 600;
}

#starlogo-turtle-helper .header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

#starlogo-turtle-helper .header-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    background: var(--gray-600);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

#starlogo-turtle-helper .new-chat-btn {
    background: #0f90d1;
    color: #fff;
}

/* Settings button + dropdown */

#starlogo-turtle-helper .settings-btn {
    padding: 6px 10px;
    font-size: 16px;
    line-height: 1;
}

#starlogo-turtle-helper .settings-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 10;
    background: var(--bg-dark);
    border: 1px solid var(--gray-700);
    border-radius: 8px;
    padding: 12px;
    min-width: 280px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

#starlogo-turtle-helper .settings-dropdown.hidden {
    display: none;
}

#starlogo-turtle-helper .settings-dropdown label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#starlogo-turtle-helper .settings-dropdown select {
    padding: 6px 8px;
    border: 1px solid var(--gray-600);
    border-radius: 6px;
    background: var(--bg-dark-alt);
    color: var(--text-primary);
    font-size: 12px;
    cursor: pointer;
}

/* Interactive toggle */

#starlogo-turtle-helper .interactive-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
}

#starlogo-turtle-helper .interactive-toggle-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

#starlogo-turtle-helper .toggle-track {
    position: relative;
    width: 36px;
    min-width: 36px;
    height: 20px;
    background: var(--gray-600);
    border-radius: 10px;
}

#starlogo-turtle-helper .toggle-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.15s ease-in-out;
}

#starlogo-turtle-helper .interactive-toggle.active .toggle-track {
    background: var(--green-primary);
}

#starlogo-turtle-helper .interactive-toggle.active .toggle-knob {
    transform: translateX(16px);
}

/* Messages */

#starlogo-turtle-helper #past-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#starlogo-turtle-helper .user-message {
    padding: 10px 15px;
    line-height: 1.5;
    word-wrap: break-word;
    background-color: var(--green-light);
    color: var(--text-primary);
    border-radius: 18px 4px 18px 18px;
}

#starlogo-turtle-helper .assistant-message {
    padding: 10px 15px;
    line-height: 1.5;
    word-wrap: break-word;
    word-break: break-word;
    max-width: 80%;
}

/* Example prompts */

#starlogo-turtle-helper .example-prompts {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: auto;
}

#starlogo-turtle-helper .example-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0;
    width: 100%;
}

#starlogo-turtle-helper .example-btn {
    padding: 7px 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--gray-400);
    font-size: 12px;
    line-height: 1.4;
    text-align: left;
    cursor: pointer;
}

#starlogo-turtle-helper .example-btn:hover {
    border-color: rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.07);
    color: var(--text-primary);
}

/* Input */

#starlogo-turtle-helper #turtle-helper {
    padding: 10px;
    flex-shrink: 0;
}

#starlogo-turtle-helper .chat-input-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    border: 1px solid var(--gray-700);
    border-radius: 12px;
    background: #fff;
    padding: 4px 6px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#starlogo-turtle-helper .chat-input-container:focus-within {
    border-color: var(--gray-400);
}

#starlogo-turtle-helper textarea.chat-input {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font: inherit;
    font-size: 14px;
    line-height: 1.35;
    min-height: var(--chat-input-min-height);
    max-height: var(--chat-input-max-height);
    overflow-y: auto;
    background: transparent;
    color: var(--text-primary);
    padding: 6px 8px;
    margin: 0;
    width: 100% !important;
    max-width: 100% !important;
}

#starlogo-turtle-helper textarea.chat-input::placeholder {
    color: var(--gray-500);
}

#starlogo-turtle-helper #send-button {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    background: var(--green-primary);
    color: #fff;
    border: 1px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.12s ease, filter 0.12s ease, opacity 0.12s ease, background-color 0.12s ease;
}

#starlogo-turtle-helper #send-button svg {
    width: 16px;
    height: 16px;
}

#starlogo-turtle-helper #send-button:hover:not(:disabled) {
    filter: brightness(1.06);
}

#starlogo-turtle-helper #send-button:active:not(:disabled) {
    transform: translateY(1px);
}

#starlogo-turtle-helper #send-button:focus-visible {
    outline: 2px solid rgba(74, 222, 128, 0.35);
    outline-offset: 1px;
}

#starlogo-turtle-helper #send-button:disabled {
    opacity: 0.45;
    cursor: default;
    filter: saturate(0.7);
}

#starlogo-turtle-helper #send-button.is-stop-mode {
    background: #dc2626;
}

/* Image preview */

#starlogo-turtle-helper .chat-image-preview {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
    padding: 8px;
    background: var(--bg-dark);
    border-radius: 8px;
    border: 1px solid var(--gray-700);
}

#starlogo-turtle-helper .chat-image-wrapper {
    position: relative;
}

#starlogo-turtle-helper .chat-image-thumbnail {
    width: 120px;
    height: 120px;
    object-fit: contain;
    border: 1px solid var(--gray-600);
    border-radius: 6px;
    padding: 4px;
    cursor: pointer;
}

#starlogo-turtle-helper .chat-image-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background: #dc2626;
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
}

#starlogo-turtle-helper .chat-image-remove:hover {
    background: #b91c1c;
}

/* Markdown */

#starlogo-turtle-helper .markdown-content {
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-line;
}

#starlogo-turtle-helper .markdown-content .markdown-inline-code,
#starlogo-turtle-helper .markdown-content code:not(pre code) {
    background: var(--slate-800);
    color: #e01e5a;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.9em;
    border: 1px solid var(--gray-700);
}

#starlogo-turtle-helper .markdown-content pre {
    background: var(--slate-800);
    border: 1px solid var(--gray-700);
    border-radius: 6px;
    padding: 12px;
    margin: 1em 0;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

#starlogo-turtle-helper .markdown-content pre code {
    background: transparent;
    color: var(--text-primary);
    padding: 0;
    border: none;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.9em;
}

#starlogo-turtle-helper .markdown-content .markdown-list {
    margin: 0.5em 0 1em;
    padding-left: 1.5em;
}

#starlogo-turtle-helper .markdown-content .markdown-ul { list-style-type: disc; }
#starlogo-turtle-helper .markdown-content .markdown-ol { list-style-type: decimal; }

#starlogo-turtle-helper .markdown-content .markdown-list-item {
    margin: 0.25em 0;
    display: list-item;
}

#starlogo-turtle-helper .markdown-content a {
    color: #0066cc;
    text-decoration: underline;
}

/* Code blocks (blockConverter) */

#starlogo-turtle-helper .code-block-wrapper {
    display: flex;
    flex-direction: column;
}

#starlogo-turtle-helper .code-block-header {
    background: #C8C4A6;
    padding: 0.5rem 1rem;
    border: 1px solid #d6d3b8;
    border-bottom: none;
    border-radius: 0.5rem 0.5rem 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #3a3825;
}

#starlogo-turtle-helper .code-block-title {
    margin: 0;
    font-size: 13px;
    font-weight: bold;
}

#starlogo-turtle-helper .block-insert-status {
    font-size: 11px;
    font-weight: normal;
    opacity: 0.7;
    margin-left: auto;
    margin-right: 8px;
}

#starlogo-turtle-helper .code-block-content {
    background: #EDEAD1;
    padding: 1rem;
    border: 1px solid #d6d3b8;
    border-radius: 0 0 0.5rem 0.5rem;
}

#starlogo-turtle-helper .copy-button {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.6rem;
    border: 1px solid #b5b199;
    border-radius: 4px;
    background: #d6d3b8;
    color: #3a3825;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

#starlogo-turtle-helper .copy-button-icon {
    width: 14px;
    height: 14px;
}

/* Retry */

#starlogo-turtle-helper .message-retry-container {
    margin-top: 8px;
}

#starlogo-turtle-helper .message-retry-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 0.85em;
    color: var(--gray-400);
    background: transparent;
    border: 1px solid var(--gray-700);
    border-radius: 6px;
    cursor: pointer;
}

#starlogo-turtle-helper .message-retry-button:hover {
    color: var(--text-secondary);
    background: var(--bg-dark);
    border-color: var(--gray-600);
}

#starlogo-turtle-helper .retry-icon {
    width: 14px;
    height: 14px;
}

/* References */

#starlogo-turtle-helper .message-references {
    margin-top: 8px;
    padding: 6px 10px;
    background: var(--bg-dark);
    border-radius: 6px;
    border: 1px solid var(--gray-700);
    font-size: 0.85em;
    color: var(--gray-400);
}

#starlogo-turtle-helper .message-references a.reference-link {
    color: var(--text-primary);
    text-decoration: none;
    margin-left: 8px;
}

#starlogo-turtle-helper .message-references a.reference-link:hover {
    color: var(--green-primary);
    text-decoration: underline;
}

#starlogo-turtle-helper .reference-number {
    font-weight: 600;
    color: var(--green-primary);
}

/* JS utility classes (used by chathandler.js) */

#starlogo-turtle-helper .flex { display: flex; }
#starlogo-turtle-helper .items-center { align-items: center; }
#starlogo-turtle-helper .justify-end { justify-content: flex-end; }
#starlogo-turtle-helper .justify-start { justify-content: flex-start; }
#starlogo-turtle-helper .text-gray-500 { color: var(--gray-400); }
#starlogo-turtle-helper .whitespace-pre-wrap { white-space: pre-wrap; }
#starlogo-turtle-helper .text-neutral-900 { color: var(--text-primary); }
#starlogo-turtle-helper .space-y-6 { display: flex; flex-direction: column; gap: 1.5rem; }

/* ScriptBlocks isolation */

#starlogo-turtle-helper .block-preview,
#starlogo-turtle-helper .code-block-content {
    isolation: isolate;
    contain: layout style paint;
}

