/* NeuroHelper Widget - NeuroBack Style */

/* CSS переменные */
:root {
    --nh-primary: #2196f3;
    --nh-primary-dark: #1976d2;
    --nh-primary-light: #64b5f6;
    --nh-secondary: #00bcd4;
    --nh-success: #34a853;
    --nh-error: #f44336;
    --nh-warning: #ff9800;
    
    --nh-bg-dark: #0f1b2e;
    --nh-bg-darker: #0a1628;
    --nh-bg-panel: #1a2b42;
    --nh-border: #1e3a5f;
    --nh-border-light: rgba(255, 255, 255, 0.1);
    
    --nh-text-primary: #ffffff;
    --nh-text-secondary: #94a3b8;
    --nh-text-muted: #64748b;
    
    --nh-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    --nh-shadow-sm: 0 4px 20px rgba(0, 0, 0, 0.2);
    
    --nh-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --nh-panel-width: 450px;
    --nh-panel-height: 600px;
}

/* Основной контейнер */
.neurohelper-widget {
    position: fixed;
    z-index: 10000;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Позиционирование */
.neurohelper-widget.bottom-right {
    bottom: 20px;
    right: 20px;
}

.neurohelper-widget.bottom-left {
    bottom: 20px;
    left: 20px;
}

.neurohelper-widget.top-right {
    top: 80px;
    right: 20px;
}

.neurohelper-widget.top-left {
    top: 80px;
    left: 20px;
}

/* Кнопка переключения */
.neurohelper-toggle {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--nh-primary) 0%, var(--nh-secondary) 100%);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--nh-shadow-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: var(--nh-transition);
    overflow: hidden;
}

.neurohelper-toggle:hover {
    transform: scale(1.1);
    box-shadow: var(--nh-shadow);
}

.neurohelper-toggle:active {
    transform: scale(0.95);
}

.toggle-icon {
    width: 28px;
    height: 28px;
    color: white;
    transition: var(--nh-transition);
}

.neurohelper-widget.open .toggle-icon {
    transform: rotate(180deg);
}

.toggle-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--nh-error);
    color: white;
    font-size: 10px;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Панель */
.neurohelper-panel {
    position: absolute;
    width: var(--nh-panel-width);
    height: var(--nh-panel-height);
    background: var(--nh-bg-dark);
    border: 1px solid var(--nh-border);
    border-radius: 16px;
    box-shadow: var(--nh-shadow);
    opacity: 0;
    visibility: hidden;
    transform: scale(0.9) translateY(20px);
    transition: var(--nh-transition);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Позиционирование панели */
.neurohelper-widget.bottom-right .neurohelper-panel {
    bottom: 80px;
    right: 0;
    transform-origin: bottom right;
}

.neurohelper-widget.bottom-left .neurohelper-panel {
    bottom: 80px;
    left: 0;
    transform-origin: bottom left;
}

.neurohelper-widget.top-right .neurohelper-panel {
    top: 80px;
    right: 0;
    transform-origin: top right;
}

.neurohelper-widget.top-left .neurohelper-panel {
    top: 80px;
    left: 0;
    transform-origin: top left;
}

/* Открытое состояние */
.neurohelper-widget.open .neurohelper-panel {
    opacity: 1;
    visibility: visible;
    transform: scale(1) translateY(0);
}

/* Заголовок панели */
.panel-header {
    background: var(--nh-bg-panel);
    padding: 20px;
    border-bottom: 1px solid var(--nh-border);
    position: relative;
}

.panel-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--nh-text-primary);
    background: linear-gradient(45deg, var(--nh-primary), var(--nh-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.panel-subtitle {
    margin: 5px 0 0;
    font-size: 13px;
    color: var(--nh-text-secondary);
}

.panel-close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--nh-border-light);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--nh-transition);
}

.panel-close:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--nh-primary);
}

.panel-close svg {
    width: 16px;
    height: 16px;
    color: var(--nh-text-secondary);
}

/* Контент панели */
.panel-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--nh-border) transparent;
}

.panel-content::-webkit-scrollbar {
    width: 6px;
}

.panel-content::-webkit-scrollbar-track {
    background: transparent;
}

.panel-content::-webkit-scrollbar-thumb {
    background: var(--nh-border);
    border-radius: 3px;
}

/* Секция ввода */
.input-section {
    margin-bottom: 20px;
}

.input-section label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--nh-text-primary);
}

.idea-input {
    width: 100%;
    background: var(--nh-bg-darker);
    border: 1px solid var(--nh-border);
    border-radius: 8px;
    padding: 12px;
    font-size: 14px;
    color: var(--nh-text-primary);
    resize: vertical;
    min-height: 100px;
    transition: var(--nh-transition);
}

.idea-input:focus {
    outline: none;
    border-color: var(--nh-primary);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.idea-input.error {
    border-color: var(--nh-error);
}

.idea-input::placeholder {
    color: var(--nh-text-muted);
}

/* Действия ввода */
.input-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
}

.char-count {
    font-size: 12px;
    color: var(--nh-text-muted);
}

.clear-btn {
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: var(--nh-transition);
}

.clear-btn:hover {
    background: rgba(255, 255, 255, 0.05);
}

.clear-btn svg {
    width: 16px;
    height: 16px;
    color: var(--nh-text-muted);
}

/* Кнопка генерации */
.generate-btn {
    width: 100%;
    background: linear-gradient(135deg, var(--nh-primary) 0%, var(--nh-secondary) 100%);
    border: none;
    border-radius: 8px;
    padding: 14px 20px;
    font-size: 16px;
    font-weight: 600;
    color: white;
    cursor: pointer;
    transition: var(--nh-transition);
    position: relative;
    overflow: hidden;
    margin-bottom: 20px;
}

.generate-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(33, 150, 243, 0.3);
}

.generate-btn:active:not(:disabled) {
    transform: translateY(0);
}

.generate-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.generate-btn.loading .btn-text {
    opacity: 0;
}

.btn-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.generate-btn.loading .btn-loader {
    opacity: 1;
}

.spinner {
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
}

.spinner circle {
    stroke: white;
    stroke-dasharray: 80;
    stroke-dashoffset: 60;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Секция вывода */
.output-section {
    position: relative;
}

.output-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.output-header label {
    font-size: 14px;
    font-weight: 500;
    color: var(--nh-text-primary);
}

.output-actions {
    display: flex;
    gap: 8px;
}

.copy-btn,
.download-btn {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--nh-border-light);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--nh-transition);
}

.copy-btn:hover,
.download-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--nh-primary);
}

.copy-btn.success {
    background: var(--nh-success);
    border-color: var(--nh-success);
}

.copy-btn svg,
.download-btn svg {
    width: 16px;
    height: 16px;
    color: var(--nh-text-secondary);
}

.copy-btn.success svg {
    color: white;
}

/* Результат */
.result-output {
    background: var(--nh-bg-darker);
    border: 1px solid var(--nh-border);
    border-radius: 8px;
    padding: 16px;
    min-height: 200px;
    max-height: 300px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--nh-border) transparent;
}

.result-output::-webkit-scrollbar {
    width: 6px;
}

.result-output::-webkit-scrollbar-track {
    background: transparent;
}

.result-output::-webkit-scrollbar-thumb {
    background: var(--nh-border);
    border-radius: 3px;
}

.output-placeholder {
    color: var(--nh-text-muted);
    font-size: 14px;
    line-height: 1.6;
}

/* Контент результата */
.result-content {
    color: var(--nh-text-primary);
    font-size: 14px;
    line-height: 1.8;
}

/* Стили для Markdown */
.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4 {
    color: var(--nh-text-primary);
    margin-top: 20px;
    margin-bottom: 10px;
    font-weight: 600;
}

.markdown-content h1 {
    font-size: 20px;
    color: var(--nh-primary);
}

.markdown-content h2 {
    font-size: 18px;
    color: var(--nh-primary-light);
}

.markdown-content h3 {
    font-size: 16px;
}

.markdown-content p {
    margin-bottom: 12px;
}

.markdown-content ul,
.markdown-content ol {
    margin-bottom: 12px;
    padding-left: 24px;
}

.markdown-content li {
    margin-bottom: 6px;
}

.markdown-content strong {
    color: var(--nh-primary);
}

.markdown-content code {
    background: rgba(33, 150, 243, 0.1);
    color: var(--nh-primary-light);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

.markdown-content blockquote {
    border-left: 4px solid var(--nh-primary);
    padding-left: 16px;
    margin: 16px 0;
    color: var(--nh-text-secondary);
}

/* Загрузочный скелетон */
.loading-skeleton {
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.skeleton-line {
    height: 14px;
    background: linear-gradient(90deg, var(--nh-border) 25%, rgba(255, 255, 255, 0.05) 50%, var(--nh-border) 75%);
    background-size: 200% 100%;
    margin-bottom: 8px;
    border-radius: 4px;
}

.skeleton-line:nth-child(2) {
    width: 80%;
}

.skeleton-line:nth-child(3) {
    width: 60%;
}

@keyframes skeleton-pulse {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Сообщение об ошибке */
.error-message {
    text-align: center;
    padding: 20px;
}

.error-message svg {
    width: 48px;
    height: 48px;
    color: var(--nh-error);
    margin-bottom: 12px;
}

.error-message p {
    color: var(--nh-text-secondary);
    margin-bottom: 16px;
}

.retry-btn {
    background: var(--nh-error);
    border: none;
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: var(--nh-transition);
}

.retry-btn:hover {
    background: #d32f2f;
}

/* История */
.history-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--nh-border);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.history-header span {
    font-size: 14px;
    font-weight: 500;
    color: var(--nh-text-primary);
}

.clear-history-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: var(--nh-transition);
}

.clear-history-btn:hover {
    background: rgba(255, 255, 255, 0.05);
}

.clear-history-btn svg {
    width: 16px;
    height: 16px;
    color: var(--nh-text-muted);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--nh-border-light);
    border-radius: 6px;
    padding: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: var(--nh-transition);
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--nh-primary);
}

.history-time {
    font-size: 11px;
    color: var(--nh-text-muted);
}

.history-input {
    flex: 1;
    font-size: 13px;
    color: var(--nh-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-load-btn {
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: var(--nh-transition);
}

.history-load-btn:hover {
    background: rgba(33, 150, 243, 0.1);
}

.history-load-btn svg {
    width: 16px;
    height: 16px;
    color: var(--nh-primary);
}

/* Футер панели */
.panel-footer {
    padding: 12px 20px;
    background: var(--nh-bg-panel);
    border-top: 1px solid var(--nh-border);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

.footer-link {
    font-size: 12px;
    color: var(--nh-text-muted);
    text-decoration: none;
    transition: var(--nh-transition);
}

.footer-link:hover {
    color: var(--nh-primary);
}

.footer-divider {
    color: var(--nh-text-muted);
    font-size: 12px;
}

/* Мобильная адаптация */
@media (max-width: 768px) {
    :root {
        --nh-panel-width: 100vw;
        --nh-panel-height: 100vh;
    }
    
    .neurohelper-widget {
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: 0 !important;
    }
    
    .neurohelper-toggle {
        position: fixed;
        bottom: 20px;
        right: 20px;
    }
    
    .neurohelper-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        border-radius: 0;
        transform: translateY(100%);
    }
    
    .neurohelper-widget.open .neurohelper-panel {
        transform: translateY(0);
    }
    
    .panel-content {
        padding: 15px;
    }
}

/* Анимации */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(33, 150, 243, 0.4);
    }
    70% {
        box-shadow: 0 0 0 15px rgba(33, 150, 243, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(33, 150, 243, 0);
    }
}

/* Пульсирующая анимация для кнопки */
.neurohelper-toggle {
    animation: pulse 2s infinite;
}

/* Поддержка темной темы */
@media (prefers-color-scheme: dark) {
    :root {
        --nh-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    }
}

/* Уменьшение анимаций */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Печать */
@media print {
    .neurohelper-widget {
        display: none !important;
    }
}