/* Base Styles - Shared across Desktop and Mobile */
* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    border: none;
    font-family: 'Noto Sans SC', sans-serif;
    scroll-behavior: smooth;
}

.outline-item {
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    margin-bottom: 0.25rem;
    cursor: pointer;
    transition: all 0.2s;
}

.outline-item:hover {
    background-color: #e2e8f0;
}

.outline-item.active {
    background-color: #dbeafe;
    color: #1e40af;
    font-weight: 500;
}

.outline-subitem {
    padding: 0.375rem 0.75rem 0.375rem 1.5rem;
    font-size: 0.875rem;
    border-radius: 0.375rem;
    margin-bottom: 0.125rem;
    cursor: pointer;
    transition: all 0.2s;
}

.outline-subitem:hover {
    background-color: #e2e8f0;
}

.outline-subitem.active {
    background-color: #dbeafe;
    color: #1e40af;
    font-weight: 500;
}

.section {
    scroll-margin-top: 2rem;
    position: relative;
}

/* Card Styles */
.card {
    background-color: white;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 1.5rem;
    overflow: hidden;
    position: relative;
    border: none;
}

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid #e2e8f0;
    position: relative;
}

.card-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: #1a202c;
    margin-bottom: 0.25rem;
}

.card-subtitle {
    font-size: 0.875rem;
    color: #64748b;
}

.card-content {
    padding: 1.5rem;
}

/* Analysis Text Styles */
.card-analysis-text {
    display: none;
    position: relative;
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 0.375rem;
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.75rem;
    transition: all 0.3s ease;
}

.card-analysis-text:not(:empty) {
    display: block;
}

.analysis-text-content {
    font-size: 0.875rem;
    line-height: 1.6;
    color: #475569;
    white-space: pre-wrap;
    word-wrap: break-word;
    transition: max-height 0.3s ease;
    overflow: hidden;
}

/* Collapsed state - show only last line with fade-out */
.card-analysis-text.collapsed .analysis-text-content {
    max-height: 1.6em;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.card-analysis-text.collapsed .analysis-text-content::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 1.6em;
    background: linear-gradient(to bottom, transparent 0%, #f8fafc 100%);
    pointer-events: none;
}

/* Expanded state - show up to 5 lines with scrollbar */
.card-analysis-text.expanded .analysis-text-content {
    max-height: 7em; /* ~5 lines with line-height 1.4 */
    overflow-y: auto;
    padding-right: 0.5rem;
}

/* Custom scrollbar for expanded text */
.card-analysis-text.expanded .analysis-text-content::-webkit-scrollbar {
    width: 6px;
}

.card-analysis-text.expanded .analysis-text-content::-webkit-scrollbar-track {
    background: #e2e8f0;
    border-radius: 3px;
}

.card-analysis-text.expanded .analysis-text-content::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 3px;
}

.card-analysis-text.expanded .analysis-text-content::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* Toggle button */
.analysis-text-toggle {
    position: absolute;
    top: 0.375rem;
    right: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    background-color: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.625rem;
    color: #64748b;
}

.analysis-text-toggle:hover {
    background-color: #f1f5f9;
    border-color: #94a3b8;
    color: #475569;
}

.analysis-text-toggle i {
    transition: transform 0.2s;
}

/* Tool Status Styles */
.card-tool-status,
.card-tool-status-mobile {
    font-size: 0.875rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    border-radius: 0.375rem;
    display: none;
    align-items: center;
    transition: all 0.3s ease;
    line-height: 1.4;
}

/* Show tool status when it has content */
.card-tool-status:not(:empty),
.card-tool-status-mobile:not(:empty) {
    display: flex;
}

/* Icon styling with animation for running state */
.card-tool-status .tool-status-icon,
.card-tool-status-mobile .tool-status-icon {
    display: inline-flex;
    margin-right: 0.25rem;
}

.card-tool-status.status-running .tool-status-icon,
.card-tool-status-mobile.status-running .tool-status-icon {
    animation: spin 1s linear infinite;
}

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

/* Error text styling */
.card-tool-status .tool-status-error,
.card-tool-status-mobile .tool-status-error {
    font-size: 0.8125rem;
    opacity: 0.8;
}

/* Status-specific color schemes */
.card-tool-status.status-running,
.card-tool-status-mobile.status-running {
    background-color: #e3f2fd;
    color: #1976d2;
    border-left: 3px solid #2196f3;
}

.card-tool-status.status-success,
.card-tool-status-mobile.status-success {
    background-color: #e8f5e9;
    color: #388e3c;
    border-left: 3px solid #4caf50;
}

.card-tool-status.status-fail,
.card-tool-status-mobile.status-fail {
    background-color: #ffebee;
    color: #d32f2f;
    border-left: 3px solid #f44336;
}

.card-tool-status.status-interrupted,
.card-tool-status-mobile.status-interrupted {
    background-color: #fff3e0;
    color: #f57c00;
    border-left: 3px solid #ff9800;
}

.card-conclusion {
    background-color: #f8fafc;
    padding: 1rem;
    border-radius: 0.375rem;
    margin-bottom: 1rem;
    border-left: 4px solid #3b82f6;
}

.card-conclusion strong {
    color: #5470c6;
    font-weight: 600;
}

.card-conclusion em {
    color: #666;
    font-style: normal;
    background: #e3f2fd;
    padding: 2px 6px;
    border-radius: 3px;
}

.card-conclusion code {
    background: #fff3cd;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: #856404;
}

.card-conclusion ul,
.card-conclusion ol {
    margin: 8px 0;
    padding-left: 20px;
}

.card-conclusion li {
    margin: 4px 0;
}

/* Visual gap element inserted when 3+ newlines are present in Markdown */
.card-conclusion .md-gap {
    height: 0.75rem;
}

/* Ensure two newlines (Markdown paragraphs) render with visible spacing */
.card-conclusion p {
    margin: 0.75rem 0;
}

.card-visualization {
    width: 100%;
}

/* 16:9 aspect-ratio for chart containers */
.card-visualization.chart-16x9 {
    aspect-ratio: 16 / 9;
}

.card-actions {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    gap: 0.5rem;
}

.card-action-btn {
    background-color: transparent;
    border: none;
    color: #64748b;
    cursor: pointer;
    font-size: 0.875rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    transition: all 0.2s;
}

.card-action-btn:hover {
    background-color: #f1f5f9;
    color: #1e40af;
}

/* Chat Panel - Base Styles */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #e2e8f0;
}

/* Chat header actions (Stop + Toggle) */
.chat-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.stop-chat-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    background-color: #ef4444; /* red-500 */
    color: #ffffff;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
}

.stop-chat-btn:hover {
    background-color: #dc2626; /* red-600 */
}

.stop-chat-btn:disabled {
    background-color: #cbd5e1; /* slate-300 */
    cursor: not-allowed;
}

.file-upload-area {
    padding: 1rem;
    border-bottom: 1px solid #e2e8f0;
}

.file-upload-container {
    display: flex;
    flex-direction: column;
}

.file-upload-label {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem;
    background-color: #f1f5f9;
    color: #334155;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
}

.file-upload-label:hover {
    background-color: #e2e8f0;
}

.file-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.5rem;
    padding: 0.5rem;
    background-color: #f8fafc;
    border-radius: 0.25rem;
    font-size: 0.875rem;
}

.remove-file {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.chat-message {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
}

.chat-message.user {
    align-items: flex-end;
}

.chat-message.ai {
    align-items: flex-start;
}

.chat-message-content {
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    max-width: 80%;
    word-break: break-word;
    white-space: pre-wrap;
}

.chat-message.user .chat-message-content {
    background-color: #3b82f6;
    color: white;
    border-top-right-radius: 0;
}

.chat-message.ai .chat-message-content {
    background-color: #f1f5f9;
    color: #334155;
    border-top-left-radius: 0;
}

.message-input-container {
    padding: 1rem;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 0.5rem;
}

.message-input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.375rem;
    resize: none;
    font-family: inherit;
    font-size: 0.875rem;
}

.message-input:focus {
    outline: none;
    border-color: #3b82f6;
}

.send-message-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    background-color: #3b82f6;
    color: white;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
}

.send-message-btn:hover {
    background-color: #2563eb;
}

.send-message-btn:disabled {
    background-color: #cbd5e1;
    cursor: not-allowed;
}

/* Loading Indicators */
.loading-spinner {
    display: inline-block;
    width: 1.5rem;
    height: 1.5rem;
    border: 2px solid rgba(59, 130, 246, 0.2);
    border-radius: 50%;
    border-top-color: #3b82f6;
    animation: spin 1s linear infinite;
}

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

.loading-dots {
    display: inline-flex;
    align-items: center;
}

.loading-dots span {
    width: 0.5rem;
    height: 0.5rem;
    margin: 0 0.1rem;
    background-color: #3b82f6;
    border-radius: 50%;
    animation: pulse 1.4s infinite ease-in-out;
}

.loading-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.loading-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

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

/* Utility Classes */
.hidden {
    display: none !important;
}

.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.text-sm {
    font-size: 0.875rem;
}

.text-gray-500 {
    color: #64748b;
}

.mt-2 {
    margin-top: 0.5rem;
}

/* Subtle Session ID Badge */
.session-badge {
    position: absolute;
    top: 0.5rem;
    left: 0.75rem;
    font-size: 0.75rem;
    color: #94a3b8; /* slate-400 */
    opacity: 0.65;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
    cursor: text;
    z-index: 50;
    pointer-events: auto;
    -webkit-touch-callout: default;
}

.session-badge:hover {
    opacity: 0.9;
}

/* Data Reference Tooltips */
.data-ref {
    cursor: pointer;
    position: relative;
    border-bottom: 1px dashed #5470c6;
    transition: all 0.2s ease;
}

.data-ref:hover {
    background: #e3f2fd;
    border-bottom-color: #1976d2;
}

.ref-tooltip {
    position: absolute;
    background: #fafafa;
    border: 2px solid #0055B8;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);
    z-index: 10000;
    font-size: 12px;
    min-width: 280px;
    max-width: 450px;
    display: none;
}

.ref-tooltip.show {
    display: block;
}

.ref-tooltip-title {
    font-weight: 600;
    color: #0055B8;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 2px solid #E0E6F1;
    font-size: 13px;
    position: relative;
}

.ref-tooltip-title::after {
    content: '';
    position: absolute;
    left: 0;
    bottom: -2px;
    width: 60%;
    height: 2px;
    background: linear-gradient(to right, #0055B8, #4A99DD, transparent);
}

.table-info-tooltip {
    position: absolute;
    background: #f5f5f5;
    color: #555;
    border: 1.5px solid #4A99DD;
    border-radius: 10px;
    padding: 12px 14px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1), 0 2px 6px rgba(0, 0, 0, 0.05);
    z-index: 10001;
    font-size: 11px;
    min-width: 180px;
    max-width: 320px;
    display: none;
    line-height: 1.6;
}

.table-info-tooltip.show {
    display: block;
}

#trajectory-content code {
    background: #e3f2fd;
    padding: 2px 5px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: #0055B8;
    font-weight: 500;
}

#trajectory-content a {
    color: #0055B8;
    text-decoration: underline;
    text-decoration-style: dotted;
    cursor: pointer;
    position: relative;
    user-select: none;
}

#trajectory-content a:hover {
    color: #003d82;
    background: #e3f2fd;
}

#trajectory-content p {
    margin: 6px 0;
}

#trajectory-content ol, #trajectory-content ul {
    margin: 6px 0;
    padding-left: 20px;
}

/* Mobile-friendly tooltip sizes */
@media (max-width: 768px) {
    .ref-tooltip {
        max-width: calc(100vw - 20px);
        min-width: 240px;
    }
    
    .table-info-tooltip {
        max-width: calc(100vw - 20px);
        min-width: 160px;
    }
}
