/* Основные стили */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: #0f0f1a;
    color: #e0e0e0;
    height: 100vh;
    overflow: hidden;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Main content area */
.main {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid #2a2a3e;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: #fff;
}

.status {
    display: flex;
    gap: 15px;
    align-items: center;
}

.status-indicator {
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
}

.status-indicator.connected {
    background: rgba(46, 204, 113, 0.2);
    color: #2ecc71;
}

.status-indicator.disconnected {
    background: rgba(231, 76, 60, 0.2);
    color: #e74c3c;
}

.model-info {
    padding: 5px 12px;
    background: rgba(52, 152, 219, 0.2);
    color: #3498db;
    border-radius: 20px;
    font-size: 0.85rem;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 5px;
    padding: 15px 0;
    border-bottom: 1px solid #2a2a3e;
}

.tab {
    padding: 10px 20px;
    background: transparent;
    border: 1px solid #3a3a4e;
    border-radius: 8px 8px 0 0;
    color: #888;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.tab:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
}

.tab.active {
    background: #1a1a2e;
    color: #fff;
    border-bottom-color: #1a1a2e;
}

.tab-content {
    display: none;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.tab-content.active {
    display: flex;
    flex: 1;
    min-height: 0;
}

/* Chat Area */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 10px 20px 0;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-height: 0;
    max-height: 100%;
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.5;
}

.message.user {
    align-self: flex-end;
    background: #2980b9;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message.assistant {
    align-self: flex-start;
    background: #1a1a2e;
    border: 1px solid #2a2a3e;
    border-bottom-left-radius: 4px;
    max-height: none;
    overflow: visible;
}

.message.system {
    align-self: center;
    background: transparent;
    color: #888;
    font-size: 0.9rem;
    text-align: center;
    max-width: 100%;
}

.message-content {
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message-time {
    font-size: 0.75rem;
    color: #666;
    margin-top: 8px;
}

/* Steps Panel */
.steps-panel {
    width: 350px;
    background: #1a1a2e;
    border-left: 1px solid #2a2a3e;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.steps-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    border-bottom: 1px solid #2a2a3e;
}

.steps-header h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: #fff;
}

.steps {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 15px;
    min-height: 0;
}

.step-placeholder {
    color: #666;
    text-align: center;
    padding: 30px 0;
    font-size: 0.9rem;
}

/* Prompts Editor */
.prompts-container {
    display: flex;
    flex: 1;
    gap: 20px;
    padding: 20px 0;
}

.prompts-sidebar {
    width: 250px;
    background: #1a1a2e;
    border-radius: 12px;
    padding: 15px;
    display: flex;
    flex-direction: column;
}

.prompts-sidebar h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 15px;
    color: #fff;
}

.prompts-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.prompt-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.prompt-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.prompt-item.active {
    background: rgba(52, 152, 219, 0.2);
    color: #3498db;
}

.prompt-item-name {
    font-size: 0.9rem;
    font-weight: 500;
}

.prompt-item-tag {
    font-size: 0.7rem;
    padding: 2px 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: #888;
}

.prompts-editor {
    flex: 1;
    background: #1a1a2e;
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.editor-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: #fff;
}

.editor-actions {
    display: flex;
    gap: 10px;
}

.editor-meta {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.prompt-tag {
    font-size: 0.75rem;
    padding: 3px 8px;
    background: rgba(52, 152, 219, 0.2);
    color: #3498db;
    border-radius: 4px;
}

.prompt-version {
    font-size: 0.75rem;
    padding: 3px 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: #888;
}

.prompt-status {
    font-size: 0.75rem;
    padding: 3px 8px;
    background: rgba(46, 204, 113, 0.2);
    color: #2ecc71;
    border-radius: 4px;
}

.prompt-status.modified {
    background: rgba(241, 196, 15, 0.2);
    color: #f1c40f;
}

.prompt-editor {
    flex: 1;
    width: 100%;
    background: #0f0f1a;
    border: 1px solid #2a2a3e;
    border-radius: 8px;
    padding: 15px;
    color: #e0e0e0;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    resize: none;
}

.prompt-editor:focus {
    outline: none;
    border-color: #3498db;
}

.prompt-editor:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.editor-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #2a2a3e;
}

.saved-indicator {
    font-size: 0.85rem;
    color: #2ecc71;
}

.saved-indicator.unsaved {
    color: #f1c40f;
}

.char-count {
    font-size: 0.8rem;
    color: #666;
}

/* Agent Session Styles */
.agent-session {
    background: #1a1a2e;
    border-radius: 12px;
    padding: 0;
    margin: 0;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.85rem;
    color: #e0e0e0;
    overflow: hidden;
}

.session-header {
    background: linear-gradient(135deg, #1a1a2e 0%, #2a2a3e 100%);
    padding: 15px 20px;
    border-bottom: 1px solid #3a3a4e;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.session-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 10px;
}

.session-id {
    font-size: 0.75rem;
    background: rgba(52, 152, 219, 0.2);
    color: #3498db;
    padding: 3px 8px;
    border-radius: 4px;
    font-family: monospace;
}

.session-meta {
    display: flex;
    gap: 15px;
    font-size: 0.8rem;
    color: #888;
}

.session-separator {
    height: 8px;
    background: linear-gradient(180deg, #2a2a3e 0%, transparent 100%);
}

.step-item {
    padding: 12px 20px;
    border-bottom: 1px solid #2a2a3e;
    display: flex;
    gap: 12px;
}

.step-item:last-child {
    border-bottom: none;
}

.step-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.step-icon.tool_call {
    background: rgba(52, 152, 219, 0.2);
}

.step-icon.observation {
    background: rgba(46, 204, 113, 0.2);
}

.step-icon.thinking {
    background: rgba(155, 89, 182, 0.2);
}

.step-icon.answer {
    background: rgba(46, 204, 113, 0.2);
}

.step-icon.error {
    background: rgba(231, 76, 60, 0.2);
}

.step-content {
    flex: 1;
    min-width: 0;
}

.step-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}

.step-title {
    font-weight: 600;
    color: #fff;
    font-size: 0.9rem;
}

.step-number {
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    color: #888;
}

.step-details {
    font-size: 0.8rem;
    color: #888;
    word-break: break-all;
}

.step-result {
    margin-top: 8px;
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    font-size: 0.85rem;
    color: #bdc3c7;
    border-left: 3px solid #3498db;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 200px;
    overflow-y: auto;
}

.step-result.success {
    border-left-color: #2ecc71;
}

.step-result.warning {
    border-left-color: #f1c40f;
}

.step-result.error {
    border-left-color: #e74c3c;
}

/* Thinking animation */
.step-icon.thinking {
    background: rgba(155, 89, 182, 0.2);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Step details with context */
.step-context {
    margin-top: 4px;
    padding: 4px 8px;
    background: rgba(52, 152, 219, 0.1);
    border-radius: 4px;
    font-size: 0.75rem;
    color: #3498db;
}

/* Iteration badge */
.iteration-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: linear-gradient(135deg, rgba(155, 89, 182, 0.3) 0%, rgba(142, 68, 173, 0.2) 100%);
    border-radius: 12px;
    font-size: 0.7rem;
    color: #9b59b6;
    margin-left: 8px;
}

.iteration-badge::before {
    content: '🔄';
    font-size: 0.6rem;
}

/* Stream indicator */
.stream-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: rgba(46, 204, 113, 0.15);
    border-radius: 16px;
    font-size: 0.75rem;
    color: #2ecc71;
    margin-left: 8px;
    animation: fadeInOut 1.5s ease-in-out infinite;
}

.stream-indicator::before {
    content: '';
    width: 6px;
    height: 6px;
    background: #2ecc71;
    border-radius: 50%;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

/* Enhanced thinking step */
.step-item.thinking-enhanced {
    background: linear-gradient(90deg, rgba(155, 89, 182, 0.05) 0%, transparent 100%);
    border-left: 3px solid #9b59b6;
}

.step-item.thinking-enhanced .step-icon {
    background: linear-gradient(135deg, rgba(155, 89, 182, 0.3) 0%, rgba(142, 68, 173, 0.2) 100%);
    animation: pulse 2s infinite;
}

.step-item.thinking-enhanced .step-title {
    color: #9b59b6;
}

/* Tool call enhancement */
.step-item.tool-call-enhanced {
    background: linear-gradient(90deg, rgba(52, 152, 219, 0.05) 0%, transparent 100%);
    border-left: 3px solid #3498db;
}

.step-item.tool-call-enhanced .step-icon {
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.3) 0%, rgba(41, 128, 185, 0.2) 100%);
}

.step-item.tool-call-enhanced .step-title {
    color: #3498db;
}

/* Observation enhancement */
.step-item.observation-enhanced {
    background: linear-gradient(90deg, rgba(46, 204, 113, 0.05) 0%, transparent 100%);
    border-left: 3px solid #2ecc71;
}

.step-item.observation-enhanced .step-icon {
    background: linear-gradient(135deg, rgba(46, 204, 113, 0.3) 0%, rgba(39, 174, 96, 0.2) 100%);
}

.step-item.observation-enhanced .step-title {
    color: #2ecc71;
}

/* Answer step */
.step-item.answer-enhanced {
    background: linear-gradient(90deg, rgba(46, 204, 113, 0.08) 0%, transparent 100%);
    border-left: 3px solid #27ae60;
}

.step-item.answer-enhanced .step-icon {
    background: linear-gradient(135deg, rgba(46, 204, 113, 0.4) 0%, rgba(39, 174, 96, 0.3) 100%);
}

.step-item.answer-enhanced .step-title {
    color: #27ae60;
    font-weight: 600;
}

/* Step timestamp */
.step-timestamp {
    font-size: 0.7rem;
    color: #666;
    margin-left: auto;
}

/* Tool parameters in step details */
.step-params {
    margin-top: 6px;
    padding: 6px 10px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 6px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.75rem;
    color: #bdc3c7;
    overflow-x: auto;
}

.step-params code {
    color: #3498db;
}

.step-summary {
    margin-top: 8px;
    padding: 8px 12px;
    background: rgba(46, 204, 113, 0.1);
    border-radius: 6px;
    font-size: 0.85rem;
    color: #2ecc71;
}

.final-summary {
    padding: 20px;
    background: linear-gradient(135deg, rgba(46, 204, 113, 0.1) 0%, rgba(46, 204, 113, 0.05) 100%);
    border-top: 1px solid rgba(46, 204, 113, 0.3);
}

.final-summary-title {
    font-weight: 600;
    color: #2ecc71;
    margin-bottom: 8px;
}

.final-summary-stats {
    display: flex;
    gap: 20px;
    font-size: 0.85rem;
    color: #888;
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: #3498db;
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: #2980b9;
}

.btn-secondary {
    background: #3a3a4e;
    color: #e0e0e0;
}

.btn-secondary:hover:not(:disabled) {
    background: #4a4a5e;
}

.btn-small {
    padding: 5px 10px;
    font-size: 0.8rem;
}

/* Footer */
.footer {
    padding: 15px 0;
    border-top: 1px solid #2a2a3e;
}

.input-area {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.input-area textarea {
    flex: 1;
    padding: 12px 16px;
    background: #1a1a2e;
    border: 1px solid #2a2a3e;
    border-radius: 8px;
    color: #e0e0e0;
    font-size: 0.95rem;
    resize: none;
}

.input-area textarea:focus {
    outline: none;
    border-color: #3498db;
}

.input-area textarea::placeholder {
    color: #666;
}

.metrics {
    display: flex;
    gap: 20px;
    justify-content: flex-end;
}

.metric {
    display: flex;
    gap: 8px;
    font-size: 0.85rem;
}

.metric-label {
    color: #666;
}

.metric-value {
    color: #3498db;
    font-weight: 500;
}

/* Loading */
.loading {
    color: #666;
    text-align: center;
    padding: 20px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #0f0f1a;
}

::-webkit-scrollbar-thumb {
    background: #3a3a4e;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #4a4a5e;
}

/* History Tab Styles */
.history-container {
    display: flex;
    flex: 1;
    gap: 20px;
    padding: 20px 0;
    overflow: hidden;
    min-height: 0;
}

.history-sidebar {
    width: 350px;
    background: #1a1a2e;
    border-radius: 12px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.history-filters {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid #2a2a3e;
}

.history-filters h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 15px;
    color: #fff;
}

.filter-group {
    margin-bottom: 15px;
}

.filter-group label {
    display: block;
    font-size: 0.85rem;
    color: #888;
    margin-bottom: 5px;
}

.filter-group select {
    width: 100%;
    padding: 8px 12px;
    background: #0f0f1a;
    border: 1px solid #2a2a3e;
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 0.9rem;
}

.filter-group select:focus {
    outline: none;
    border-color: #3498db;
}

.history-list-container {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.history-list-container h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 15px;
    color: #fff;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
}

.history-item {
    padding: 12px;
    background: #0f0f1a;
    border: 1px solid #2a2a3e;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: #3498db;
}

.history-item.active {
    background: rgba(52, 152, 219, 0.15);
    border-color: #3498db;
}

.history-item-question {
    font-size: 0.9rem;
    font-weight: 500;
    color: #fff;
    margin-bottom: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-item-meta {
    display: flex;
    gap: 12px;
    font-size: 0.75rem;
    color: #666;
}

.history-item-status {
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
}

.history-item-status.success {
    background: rgba(46, 204, 113, 0.2);
    color: #2ecc71;
}

.history-item-status.error {
    background: rgba(231, 76, 60, 0.2);
    color: #e74c3c;
}

.history-detail {
    flex: 1;
    background: #1a1a2e;
    border-radius: 12px;
    padding: 20px;
    overflow-y: auto;
    min-height: 0;
}

.history-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #666;
    font-size: 0.9rem;
}

.history-detail-header {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid #2a2a3e;
}

.history-detail-header h3 {
    font-size: 1.2rem;
    font-weight: 600;
    color: #fff;
    margin-bottom: 12px;
    word-wrap: break-word;
}

.history-session-meta {
    display: flex;
    gap: 15px;
    font-size: 0.85rem;
    color: #888;
}

.history-session-answer {
    margin-bottom: 30px;
    padding: 15px;
    background: rgba(46, 204, 113, 0.1);
    border-left: 3px solid #2ecc71;
    border-radius: 6px;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.history-session-steps {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.history-step {
    background: #0f0f1a;
    border: 1px solid #2a2a3e;
    border-radius: 8px;
    overflow: hidden;
}

.history-step-header {
    padding: 12px 15px;
    background: #1a1a2e;
    border-bottom: 1px solid #2a2a3e;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}

.history-step-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

.history-step-header.active {
    background: rgba(52, 152, 219, 0.1);
}

.history-step-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    color: #fff;
}

.history-step-icon {
    font-size: 1.2rem;
}

.history-step-toggle {
    color: #666;
    font-size: 0.9rem;
    transition: transform 0.2s;
}

.history-step-toggle.expanded {
    transform: rotate(180deg);
}

.history-step-content {
    display: none;
    padding: 15px;
}

.history-step-content.expanded {
    display: block;
}

.history-step-code {
    background: #0a0a0f;
    border: 1px solid #2a2a3e;
    border-radius: 6px;
    padding: 12px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.8rem;
    color: #e0e0e0;
    overflow-x: auto;
    white-space: pre;
    margin-top: 10px;
}

.history-step-result {
    margin-top: 10px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.8rem;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 400px;
    overflow-y: auto;
}

.hub-api-request {
    color: #3498db;
    font-weight: 500;
}

.hub-api-response {
    color: #2ecc71;
    font-weight: 500;
}

.hub-api-error {
    color: #e74c3c;
    font-weight: 500;
}

.history-step-message {
    color: #bdc3c7;
    line-height: 1.6;
    margin-bottom: 10px;
}
