/**
 * AgomTradePro Terminal - CLI Style Interface
 * A bash-like terminal UI for AI chat and system commands
 */

/* ===== CSS Variables for Terminal Theme ===== */
:root {
    --terminal-bg: #0d1117;
    --terminal-bg-secondary: #161b22;
    --terminal-bg-tertiary: #21262d;
    --terminal-text: #c9d1d9;
    --terminal-text-dim: #8b949e;
    --terminal-text-bright: #f0f6fc;
    --terminal-green: #3fb950;
    --terminal-green-dim: #238636;
    --terminal-yellow: #d29922;
    --terminal-orange: #db6d28;
    --terminal-red: #f85149;
    --terminal-blue: #58a6ff;
    --terminal-purple: #a371f7;
    --terminal-cyan: #39c5cf;
    --terminal-pink: #db61a2;
    --terminal-border: #30363d;
    --terminal-glow: rgba(63, 185, 80, 0.4);
    --terminal-font: 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', 'Source Code Pro', 'Menlo', 'Consolas', monospace;
    --terminal-font-size: 14px;
    --terminal-line-height: 1.6;
    --terminal-cursor-blink: 1s;
    --terminal-shadow: 0 16px 70px rgba(0, 0, 0, 0.75);
    --terminal-border-radius: 12px;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
}

/* ===== Main Container ===== */
.terminal-container {
    display: flex;
    min-height: calc(100vh - 120px);
    padding: var(--spacing-lg, 24px);
    gap: var(--spacing-lg, 24px);
    background: linear-gradient(135deg, #0d1117 0%, #161b22 50%, #0d1117 100%);
}

/* ===== Terminal Window ===== */
.terminal-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--terminal-bg);
    border-radius: var(--terminal-border-radius);
    border: 1px solid var(--terminal-border);
    box-shadow: var(--terminal-shadow);
    overflow: hidden;
    position: relative;
}

.terminal-window::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--terminal-green), transparent);
    opacity: 0.5;
}

/* ===== Terminal Header ===== */
.terminal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--terminal-bg-secondary);
    border-bottom: 1px solid var(--terminal-border);
    user-select: none;
}

.terminal-buttons {
    display: flex;
    gap: 8px;
}

.terminal-btn {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition-fast);
}

.terminal-btn-close {
    background: var(--terminal-red);
    box-shadow: 0 0 6px rgba(248, 81, 73, 0.4);
}

.terminal-btn-close:hover {
    box-shadow: 0 0 12px rgba(248, 81, 73, 0.8);
}

.terminal-btn-minimize {
    background: var(--terminal-yellow);
    box-shadow: 0 0 6px rgba(210, 153, 34, 0.4);
}

.terminal-btn-minimize:hover {
    box-shadow: 0 0 12px rgba(210, 153, 34, 0.8);
}

.terminal-btn-maximize {
    background: var(--terminal-green);
    box-shadow: 0 0 6px rgba(63, 185, 80, 0.4);
}

.terminal-btn-maximize:hover {
    box-shadow: 0 0 12px rgba(63, 185, 80, 0.8);
}

.terminal-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--terminal-font);
    font-size: 13px;
    color: var(--terminal-text-dim);
}

.terminal-icon {
    color: var(--terminal-green);
    font-size: 16px;
}

.terminal-info {
    display: flex;
    gap: 8px;
}

.terminal-badge {
    padding: 2px 8px;
    font-family: var(--terminal-font);
    font-size: 11px;
    background: var(--terminal-bg-tertiary);
    border: 1px solid var(--terminal-border);
    border-radius: 4px;
    color: var(--terminal-text-dim);
}

.terminal-badge-model {
    color: var(--terminal-cyan);
    border-color: rgba(57, 197, 207, 0.3);
}

.terminal-badge-link {
    color: var(--terminal-green);
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.terminal-badge-link:hover {
    background: rgba(46, 160, 67, 0.2);
    border-color: var(--terminal-green);
}

/* ===== Terminal Body ===== */
.terminal-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px;
    font-family: var(--terminal-font);
    font-size: var(--terminal-font-size);
    line-height: var(--terminal-line-height);
    color: var(--terminal-text);
    overflow-y: auto;
    scroll-behavior: smooth;
}

/* Custom Scrollbar */
.terminal-body::-webkit-scrollbar {
    width: 8px;
}

.terminal-body::-webkit-scrollbar-track {
    background: var(--terminal-bg-secondary);
}

.terminal-body::-webkit-scrollbar-thumb {
    background: var(--terminal-border);
    border-radius: 4px;
}

.terminal-body::-webkit-scrollbar-thumb:hover {
    background: var(--terminal-text-dim);
}

/* ===== Welcome Section ===== */
.terminal-welcome {
    margin-bottom: 16px;
}

.terminal-ascii-art {
    color: var(--terminal-green);
    font-size: 12px;
    line-height: 1.2;
    margin-bottom: 16px;
    text-shadow: 0 0 20px var(--terminal-glow);
    overflow-x: auto;
}

.terminal-ascii-art pre {
    margin: 0;
    font-family: inherit;
}

.terminal-system-info {
    color: var(--terminal-text);
}

.terminal-system-info p {
    margin: 4px 0;
}

/* ===== Output Area ===== */
.terminal-output-area {
    flex: 1;
    user-select: text;
    -webkit-user-select: text;
}

/* ===== Command Line Elements ===== */
.terminal-prompt {
    color: var(--terminal-green);
    font-weight: 600;
    margin-right: 8px;
    text-shadow: 0 0 8px var(--terminal-glow);
}

.terminal-cmd {
    color: var(--terminal-cyan);
    background: rgba(57, 197, 207, 0.1);
    padding: 1px 4px;
    border-radius: 3px;
}

.terminal-key {
    color: var(--terminal-yellow);
    background: rgba(210, 153, 34, 0.15);
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 12px;
}

.terminal-result {
    color: var(--terminal-text);
    margin-left: 16px;
}

.terminal-result::before {
    content: '│ ';
    color: var(--terminal-border);
}

/* ===== Input Line ===== */
.terminal-input-line {
    display: flex;
    align-items: flex-start;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--terminal-border);
    gap: 8px;
}

.terminal-input-wrap {
    flex: 1;
    min-width: 0;
}

.terminal-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-family: var(--terminal-font);
    font-size: var(--terminal-font-size);
    color: var(--terminal-text-bright);
    caret-color: var(--terminal-green);
    width: 100%;
    min-height: 24px;
    max-height: 220px;
    resize: none;
    overflow-y: auto;
    line-height: 1.5;
    padding: 0;
    margin: 0;
    text-shadow: 0 0 1px var(--terminal-glow);
}

.terminal-input::placeholder {
    color: var(--terminal-text-dim);
    opacity: 0.5;
}

.terminal-input-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
    min-height: 16px;
    font-size: 11px;
    color: var(--terminal-text-dim);
}

.terminal-input-status {
    color: var(--terminal-yellow);
}

.terminal-input-status.warning {
    color: var(--terminal-yellow);
}

.terminal-input-status.danger {
    color: var(--terminal-red);
}

.terminal-input-count {
    color: var(--terminal-text-dim);
}

.terminal-input-count.warning {
    color: var(--terminal-yellow);
}

.terminal-input-count.danger {
    color: var(--terminal-red);
}

/* ===== Cursor (Hidden - using native input cursor) ===== */
.terminal-cursor {
    display: none;
}

/* ===== Output Styles ===== */
.terminal-output {
    margin-bottom: 12px;
}

.terminal-output-line {
    margin: 2px 0;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.terminal-output-line.command {
    display: flex;
    align-items: flex-start;
}

.terminal-output-line.command .terminal-prompt {
    flex-shrink: 0;
}

.terminal-output-line.response {
    padding-left: 16px;
    border-left: 1px solid var(--terminal-border);
    margin-left: 8px;
}

.terminal-output-line.error {
    color: var(--terminal-red);
    border-left-color: var(--terminal-red);
}

.terminal-output-line.success {
    color: var(--terminal-green);
}

.terminal-output-line.warning {
    color: var(--terminal-yellow);
}

.terminal-output-line.info {
    color: var(--terminal-blue);
}

.terminal-output-line.ai-response {
    background: linear-gradient(135deg, rgba(163, 113, 247, 0.08) 0%, rgba(88, 166, 255, 0.08) 100%);
    border-left: 2px solid var(--terminal-purple);
    padding: 12px 16px;
    margin: 8px 0 8px 16px;
    border-radius: 0 8px 8px 0;
    white-space: normal;
    user-select: text;
    -webkit-user-select: text;
}

.terminal-output-line.ai-response p,
.terminal-output-line.ai-response ul,
.terminal-output-line.ai-response ol,
.terminal-output-line.ai-response blockquote,
.terminal-output-line.ai-response h1,
.terminal-output-line.ai-response h2,
.terminal-output-line.ai-response h3,
.terminal-output-line.ai-response h4 {
    margin: 0 0 10px;
}

.terminal-output-line.ai-response ul,
.terminal-output-line.ai-response ol {
    padding-left: 20px;
}

.terminal-output-line.ai-response a {
    color: var(--terminal-cyan);
}

.terminal-output-line.ai-response hr {
    border: none;
    border-top: 1px solid var(--terminal-border);
    margin: 14px 0;
}

.terminal-output-line.ai-response table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
}

.terminal-output-line.ai-response th,
.terminal-output-line.ai-response td {
    border: 1px solid var(--terminal-border);
    padding: 6px 8px;
    text-align: left;
}

.terminal-output-line.ai-response thead {
    background: var(--terminal-bg-secondary);
}

.terminal-code-block {
    background: var(--terminal-bg-secondary);
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}

.terminal-inline-code {
    background: var(--terminal-bg-secondary);
    padding: 2px 6px;
    border-radius: 3px;
}

.terminal-mermaid-wrap {
    margin: 12px 0;
    padding: 12px;
    border: 1px solid var(--terminal-border);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.02);
    overflow-x: auto;
}

.terminal-mermaid-label {
    display: block;
    margin-bottom: 8px;
    font-size: 11px;
    color: var(--terminal-text-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.terminal-mermaid-error {
    color: var(--terminal-red);
    font-size: 12px;
}

.terminal-answer-chain {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px dashed var(--terminal-border);
}

.terminal-answer-chain-toggle {
    appearance: none;
    border: 1px solid var(--terminal-border);
    background: transparent;
    color: var(--terminal-cyan);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 11px;
    cursor: pointer;
}

.terminal-answer-chain-toggle.expanded {
    color: var(--terminal-green);
    border-color: var(--terminal-green);
}

.terminal-answer-chain-panel {
    margin-top: 10px;
    display: grid;
    gap: 10px;
}

.terminal-answer-chain-panel[hidden] {
    display: none !important;
}

.terminal-answer-chain-step {
    display: grid;
    grid-template-columns: 24px 1fr;
    gap: 10px;
    align-items: start;
}

.terminal-answer-chain-stepno {
    width: 24px;
    height: 24px;
    border-radius: 999px;
    background: rgba(88, 166, 255, 0.12);
    color: var(--terminal-cyan);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
}

.terminal-answer-chain-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--terminal-text-bright);
    margin-bottom: 2px;
}

.terminal-answer-chain-summary {
    font-size: 12px;
    color: var(--terminal-text);
}

.terminal-answer-chain-source {
    margin-top: 4px;
    font-size: 11px;
    color: var(--terminal-text-dim);
}

.terminal-answer-chain-tech {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.terminal-answer-chain-tech code {
    background: var(--terminal-bg-secondary);
    border-radius: 4px;
    padding: 2px 6px;
    color: var(--terminal-yellow);
}

/* ===== Typing Indicator ===== */
.terminal-typing {
    display: flex;
    gap: 4px;
    padding: 8px 16px;
    color: var(--terminal-text-dim);
}

.terminal-typing-dot {
    width: 8px;
    height: 8px;
    background: var(--terminal-green);
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite ease-in-out both;
}

.terminal-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.terminal-typing-dot:nth-child(2) { animation-delay: -0.16s; }
.terminal-typing-dot:nth-child(3) { animation-delay: 0s; }

@keyframes typing-bounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ===== Sidebar ===== */
.terminal-sidebar {
    width: 280px;
    background: var(--terminal-bg-secondary);
    border-radius: var(--terminal-border-radius);
    border: 1px solid var(--terminal-border);
    display: flex;
    flex-direction: column;
    transition: var(--transition-normal);
    overflow: hidden;
}

.terminal-sidebar.collapsed {
    width: 48px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--terminal-border);
    background: var(--terminal-bg-tertiary);
}

.sidebar-title {
    font-family: var(--terminal-font);
    font-size: 12px;
    color: var(--terminal-text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.sidebar-toggle {
    background: transparent;
    border: none;
    color: var(--terminal-text-dim);
    cursor: pointer;
    padding: 4px 8px;
    font-size: 12px;
    transition: var(--transition-fast);
}

.sidebar-toggle:hover {
    color: var(--terminal-text-bright);
}

.terminal-sidebar.collapsed .sidebar-title,
.terminal-sidebar.collapsed .sidebar-content {
    display: none;
}

.sidebar-content {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
}

.sidebar-section {
    margin-bottom: 20px;
}

.sidebar-label {
    display: block;
    font-family: var(--terminal-font);
    font-size: 11px;
    color: var(--terminal-text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.sidebar-select {
    width: 100%;
    padding: 8px 12px;
    background: var(--terminal-bg);
    border: 1px solid var(--terminal-border);
    border-radius: 6px;
    color: var(--terminal-text);
    font-family: var(--terminal-font);
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition-fast);
}

.sidebar-select:hover {
    border-color: var(--terminal-green);
}

.sidebar-select:focus {
    outline: none;
    border-color: var(--terminal-green);
    box-shadow: 0 0 0 3px rgba(63, 185, 80, 0.2);
}

/* ===== Quick Commands ===== */
.quick-commands {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.quick-cmd-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--terminal-bg);
    border: 1px solid var(--terminal-border);
    border-radius: 6px;
    color: var(--terminal-text);
    font-family: var(--terminal-font);
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition-fast);
    text-align: left;
}

.quick-cmd-btn:hover {
    background: var(--terminal-bg-tertiary);
    border-color: var(--terminal-green);
    color: var(--terminal-text-bright);
    transform: translateX(4px);
}

.quick-cmd-icon {
    font-size: 14px;
}

/* ===== Session Info ===== */
.session-info {
    background: var(--terminal-bg);
    border-radius: 6px;
    padding: 12px;
}

.session-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.session-item:last-child {
    margin-bottom: 0;
}

.session-label {
    color: var(--terminal-text-dim);
    font-size: 12px;
}

.session-value {
    color: var(--terminal-cyan);
    font-size: 12px;
    font-family: var(--terminal-font);
}

/* ===== Responsive Design ===== */
@media (max-width: 1200px) {
    .terminal-sidebar {
        width: 240px;
    }
}

@media (max-width: 900px) {
    .terminal-container {
        flex-direction: column;
    }
    
    .terminal-sidebar {
        width: 100%;
        order: -1;
    }
    
    .terminal-sidebar.collapsed {
        width: 100%;
        height: 48px;
    }
}

@media (max-width: 600px) {
    .terminal-container {
        padding: var(--spacing-md, 16px);
    }
    
    .terminal-header {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .terminal-info {
        order: 3;
        width: 100%;
        justify-content: center;
    }
    
    .terminal-ascii-art {
        font-size: 8px;
    }
}

/* ===== Special Effects ===== */
.terminal-glow-text {
    text-shadow: 
        0 0 5px currentColor,
        0 0 10px currentColor,
        0 0 20px currentColor;
}

.terminal-scanline {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        to bottom,
        transparent 50%,
        rgba(0, 0, 0, 0.1) 51%
    );
    background-size: 100% 4px;
    pointer-events: none;
    opacity: 0.3;
}

/* ===== Table Output ===== */
.terminal-table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
    font-size: 13px;
}

.terminal-table th,
.terminal-table td {
    padding: 6px 12px;
    text-align: left;
    border-bottom: 1px solid var(--terminal-border);
}

.terminal-table th {
    color: var(--terminal-cyan);
    background: var(--terminal-bg-secondary);
    font-weight: 600;
}

.terminal-table tr:hover td {
    background: var(--terminal-bg-secondary);
}

/* ===== Status Indicators ===== */
.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
}

.status-indicator::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.status-indicator.online::before {
    background: var(--terminal-green);
    box-shadow: 0 0 6px var(--terminal-green);
}

.status-indicator.offline::before {
    background: var(--terminal-red);
    box-shadow: 0 0 6px var(--terminal-red);
}

.status-indicator.warning::before {
    background: var(--terminal-yellow);
    box-shadow: 0 0 6px var(--terminal-yellow);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ===== Loading Spinner ===== */
.terminal-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--terminal-border);
    border-top-color: var(--terminal-green);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ===== Progress Bar ===== */
.terminal-progress {
    height: 4px;
    background: var(--terminal-bg-secondary);
    border-radius: 2px;
    overflow: hidden;
    margin: 8px 0;
}

.terminal-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--terminal-green), var(--terminal-cyan));
    border-radius: 2px;
    transition: width 0.3s ease;
}

/* ===== Syntax Highlighting ===== */
.syntax-keyword {
    color: var(--terminal-purple);
}

.syntax-string {
    color: var(--terminal-green);
}

.syntax-number {
    color: var(--terminal-orange);
}

.syntax-comment {
    color: var(--terminal-text-dim);
    font-style: italic;
}

.syntax-function {
    color: var(--terminal-blue);
}

.syntax-variable {
    color: var(--terminal-cyan);
}
