/* ===== Variables ===== */
:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-card: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-light: rgba(59, 130, 246, 0.15);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border: #334155;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.2s ease;
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ===== Layout ===== */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
    width: 340px;
    min-width: 340px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border);
}

.sidebar-logo {
    max-width: 160px;
    height: auto;
}

.sidebar-header p {
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-top: 4px;
}

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

/* ===== Upload Zone ===== */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 32px 20px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    background: transparent;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-light);
}

.upload-zone .upload-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
    display: block;
}

.upload-zone h3 {
    font-size: 0.95rem;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.upload-zone p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.upload-zone input[type="file"] {
    display: none;
}

/* ===== File Info ===== */
.file-info {
    display: none;
    margin-top: 20px;
}

.file-info.visible {
    display: block;
}

.file-card {
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 12px;
}

.file-card .file-name {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 8px;
    word-break: break-all;
    display: flex;
    align-items: center;
    gap: 8px;
}

.file-card .file-meta {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.file-card .file-meta span {
    display: block;
    margin-top: 2px;
}

.badge {
    display: inline-block;
    background: var(--accent-light);
    color: var(--accent);
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
}

.badge-success {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

.btn-new-file {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition);
    margin-top: 8px;
}

.btn-new-file:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* ===== Columns list ===== */
.columns-section {
    margin-top: 16px;
}

.columns-section h4 {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.columns-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.col-tag {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    border: 1px solid var(--border);
}

/* ===== Column Selector ===== */
.column-selector {
    margin-top: 16px;
    padding: 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.column-selector label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
}

.column-selector select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
}

.column-selector select:hover {
    border-color: var(--accent);
}

.column-selector select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.column-selector select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 8px;
}

/* ===== Main Chat Area ===== */
.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.chat-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
}

/* ===== Messages ===== */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.message {
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    align-self: flex-end;
}

.message.assistant {
    align-self: flex-start;
}

.message-bubble {
    padding: 14px 18px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    line-height: 1.7;
}

.message.user .message-bubble {
    background: var(--accent);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.message-bubble p {
    margin-bottom: 8px;
}

.message-bubble p:last-child {
    margin-bottom: 0;
}

.message-bubble strong {
    color: var(--accent);
}

.message-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ===== Chart container ===== */
.message:has(.chart-container) {
    max-width: 95%;
    width: 95%;
}

.chart-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 12px;
    padding: 16px;
    overflow: hidden;
    position: relative;
}

.chart-container .plotly-chart {
    width: 100%;
    min-height: 520px;
}

.chart-fullscreen-btn {
    position: absolute;
    top: 16px;
    left: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    padding: 6px 10px;
    font-size: 0.75rem;
    cursor: pointer;
    z-index: 10;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    gap: 6px;
    opacity: 0.7;
}

.chart-fullscreen-btn:hover {
    opacity: 1;
}

.chart-fullscreen-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--accent);
}

/* ===== Modal para gráfico en pantalla completa ===== */
.chart-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.chart-modal.active {
    display: flex;
}

.chart-modal-content {
    width: 100%;
    height: 100%;
    max-width: 1800px;
    max-height: 1000px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 20px;
    position: relative;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.chart-modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 10px 16px;
    font-size: 1rem;
    cursor: pointer;
    z-index: 10;
    transition: all var(--transition);
}

.chart-modal-close:hover {
    background: var(--danger);
    border-color: var(--danger);
}

.chart-modal .plotly-chart {
    width: 100%;
    height: 100%;
}

/* ===== Code block ===== */
.code-toggle {
    margin-top: 10px;
}

.code-toggle-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 4px 0;
    transition: color var(--transition);
}

.code-toggle-btn:hover {
    color: var(--accent);
}

.code-block {
    display: none;
    background: #0d1117;
    border-radius: var(--radius-sm);
    padding: 14px;
    margin-top: 8px;
    overflow-x: auto;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.78rem;
    line-height: 1.6;
    color: #c9d1d9;
    border: 1px solid #21262d;
}

.code-block.visible {
    display: block;
}

/* ===== Welcome message ===== */
.welcome-message {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px;
}

.welcome-content .welcome-icon {
    font-size: 3.5rem;
    margin-bottom: 16px;
    display: block;
}

.welcome-logo {
    max-width: 220px;
    height: auto;
    margin-bottom: 16px;
}

.welcome-content h2 {
    font-size: 1.4rem;
    margin-bottom: 8px;
}

.welcome-content p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    max-width: 450px;
    margin: 0 auto;
}

.suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 24px;
}

.suggestion-chip {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.suggestion-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-light);
}

/* ===== Input Area ===== */
.input-area {
    padding: 20px 28px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

.input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.input-wrapper textarea {
    flex: 1;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: border-color var(--transition);
    min-height: 46px;
    max-height: 120px;
    line-height: 1.5;
}

.input-wrapper textarea:focus {
    border-color: var(--accent);
}

.input-wrapper textarea::placeholder {
    color: var(--text-muted);
}

.btn-send {
    width: 46px;
    height: 46px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--accent);
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.btn-send:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.btn-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* ===== Loading ===== */
.loading-dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    padding: 8px 0;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: bounce 1.4s ease-in-out infinite;
}

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

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

/* ===== Proposals Grid ===== */
.proposals-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px;
    margin-top: 14px;
    padding: 0 4px;
}

.proposal-card {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
    font-family: inherit;
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.4;
}

.proposal-card:hover {
    border-color: var(--accent);
    background: var(--accent-light);
    color: var(--text-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

.proposal-label {
    flex: 1;
    font-weight: 500;
}

/* ===== Streaming text ===== */
.streaming-text {
    white-space: pre-wrap;
}

.streaming-text::after {
    content: "▋";
    animation: blink 0.7s infinite;
    color: var(--accent);
}

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

/* ===== Error message ===== */
.error-text {
    color: var(--danger);
    font-size: 0.8rem;
    padding: 8px 12px;
    background: rgba(239, 68, 68, 0.1);
    border-radius: var(--radius-sm);
    margin-top: 8px;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar {
        display: none;
    }
}

/* ===== Upload progress ===== */
.upload-progress {
    display: none;
    margin-top: 16px;
}

.upload-progress.visible {
    display: block;
}

.progress-bar {
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    width: 0%;
    transition: width 0.3s ease;
    animation: indeterminate 1.5s ease-in-out infinite;
}

@keyframes indeterminate {
    0% { width: 0%; margin-left: 0%; }
    50% { width: 60%; margin-left: 20%; }
    100% { width: 0%; margin-left: 100%; }
}

.progress-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 6px;
    text-align: center;
}
