* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.playground-header {
    background: #1a1a1a;
    color: white;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #333;
    flex-shrink: 0; /* Prevent header from shrinking */
}

.playground-header h1 {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.header-brand {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

.header-brand h1 {
    display: inline;
}

.home-link {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    margin-right: 8px;
    color: #ccc;
    border-radius: 6px;
    transition: color 0.2s, background 0.2s;
    text-decoration: none;
}

.home-link:hover {
    color: #FF6B35;
    background: rgba(255, 107, 53, 0.15);
}

.home-link svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.example-selector, .format-selector {
    padding: 6px 12px;
    border: 1px solid #444;
    background: #2a2a2a;
    color: white;
    border-radius: 4px;
    font-size: 14px;
}

.format-selector {
    padding: 1px 6px;
    border: 1px solid #ccc;
    background: #f0f0f0;
    color: #555;
    border-radius: 3px;
    font-size: 10px;
    margin-right: 6px;
    height: 18px;
    line-height: 14px;
}

.btn {
    padding: 6px 16px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    font-weight: 500;
}

.btn-primary {
    background: #FF6B35;
    color: white;
}

.btn-primary:hover {
    background: #E55A2B;
}

.btn-secondary {
    background: #444;
    color: white;
}

.btn-secondary:hover {
    background: #555;
}

.btn-docs {
    background: transparent;
    color: #ccc;
    border: 1px solid #555;
    text-decoration: none;
    white-space: nowrap;
}

.btn-docs:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border-color: #777;
}

/* AI Sidebar Styles */
.ai-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 400px;
    height: 100vh;
    background: #fff;
    border-right: 1px solid #ddd;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
}

.ai-sidebar.open {
    transform: translateX(0);
}

.ai-sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f8f8;
}

.ai-sidebar-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.ai-sidebar-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s, color 0.2s;
}

.ai-sidebar-close:hover {
    background: #e0e0e0;
    color: #333;
}

.ai-sidebar-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ai-sidebar-controls {
    padding: 12px 16px;
    border-bottom: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-database-selector {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    background: white;
    color: #333;
}

.ai-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.ai-btn-primary {
    background: #FF6B35;
    color: white;
}

.ai-btn-primary:hover {
    background: #E55A2B;
}

.ai-btn-secondary {
    background: #f0f0f0;
    color: #333;
    border: 1px solid #ddd;
}

.ai-btn-secondary:hover {
    background: #e0e0e0;
}

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

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-message {
    padding: 12px;
    border-radius: 8px;
    max-width: 85%;
    word-wrap: break-word;
}

.ai-message.user {
    background: #e3f2fd;
    color: #1976d2;
    align-self: flex-end;
    margin-left: auto;
}

.ai-message.assistant {
    background: #f5f5f5;
    color: #333;
    align-self: flex-start;
}

.ai-message pre {
    background: rgba(0, 0, 0, 0.05);
    padding: 8px;
    border-radius: 4px;
    overflow-x: auto;
    margin: 8px 0 0 0;
    font-size: 12px;
}

.ai-message code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 12px;
}

/* Markdown styles for AI messages */
.ai-message h1,
.ai-message h2,
.ai-message h3,
.ai-message h4,
.ai-message h5,
.ai-message h6 {
    margin: 16px 0 8px 0;
    font-weight: 600;
    line-height: 1.4;
}

.ai-message h1 {
    font-size: 1.5em;
    border-bottom: 2px solid rgba(0, 0, 0, 0.1);
    padding-bottom: 4px;
}

.ai-message h2 {
    font-size: 1.3em;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    padding-bottom: 4px;
}

.ai-message h3 {
    font-size: 1.1em;
}

.ai-message p {
    margin: 8px 0;
    line-height: 1.6;
}

.ai-message ul,
.ai-message ol {
    margin: 8px 0;
    padding-left: 24px;
}

.ai-message li {
    margin: 4px 0;
    line-height: 1.5;
}

.ai-message strong {
    font-weight: 600;
}

.ai-message em {
    font-style: italic;
}

.ai-message blockquote {
    border-left: 3px solid rgba(0, 0, 0, 0.2);
    padding-left: 12px;
    margin: 8px 0;
    color: rgba(0, 0, 0, 0.7);
}

.ai-message hr {
    border: none;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    margin: 16px 0;
}

.ai-message table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
    font-size: 0.9em;
}

.ai-message table th,
.ai-message table td {
    border: 1px solid rgba(0, 0, 0, 0.1);
    padding: 6px 8px;
    text-align: left;
}

.ai-message table th {
    background: rgba(0, 0, 0, 0.05);
    font-weight: 600;
}

/* Thinking/Status indicators */
.ai-thinking-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(33, 150, 243, 0.1);
    border-radius: 4px;
    margin-bottom: 8px;
    font-size: 0.9em;
    color: #2196f3;
}

.ai-thinking-indicator {
    animation: pulse 1.5s ease-in-out infinite;
    color: #2196f3;
}

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

.ai-thinking-text {
    font-weight: 500;
}

.ai-message-content {
    min-height: 20px;
}

/* Research query display */
.ai-research-query {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 12px;
    margin: 8px 0;
    font-size: 0.9em;
}

.ai-research-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    font-weight: 600;
    color: #495057;
}

.ai-research-icon {
    font-size: 1.2em;
}

.ai-research-title {
    flex: 1;
}

.ai-research-label {
    font-weight: 600;
    color: #6c757d;
    font-size: 0.85em;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ai-research-query-sql {
    margin: 12px 0;
    padding: 8px;
    background: #fff;
    border: 1px solid #e9ecef;
    border-radius: 4px;
}

.ai-research-query-sql pre {
    margin: 0;
    padding: 0;
    background: transparent;
    font-size: 0.85em;
    overflow-x: auto;
}

.ai-research-query-sql code {
    background: transparent;
    padding: 0;
    color: #212529;
}

.ai-research-result {
    margin-top: 12px;
}

.ai-research-summary {
    padding: 8px 12px;
    background: #e7f3ff;
    border-left: 3px solid #2196f3;
    border-radius: 4px;
    margin-bottom: 12px;
    color: #1976d2;
    font-size: 0.9em;
}

.ai-research-summary strong {
    color: #1565c0;
}

.ai-research-summary code {
    background: rgba(255, 255, 255, 0.7);
    padding: 2px 4px;
    border-radius: 2px;
    font-size: 0.9em;
}

.ai-research-data {
    margin-top: 12px;
}

.ai-research-table {
    overflow-x: auto;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    background: #fff;
}

.ai-research-table table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    font-size: 0.85em;
}

.ai-research-table thead {
    background: #f8f9fa;
}

.ai-research-table th {
    padding: 8px 12px;
    text-align: left;
    font-weight: 600;
    color: #495057;
    border-bottom: 2px solid #dee2e6;
}

.ai-research-table td {
    padding: 6px 12px;
    border-bottom: 1px solid #e9ecef;
    color: #212529;
}

.ai-research-table tbody tr:hover {
    background: #f8f9fa;
}

.ai-research-table tbody tr:last-child td {
    border-bottom: none;
}

.ai-research-table td em {
    color: #6c757d;
    font-style: italic;
}

.ai-research-error {
    padding: 8px 12px;
    background: #fff3cd;
    border-left: 3px solid #ffc107;
    border-radius: 4px;
    color: #856404;
    margin-top: 12px;
    font-size: 0.9em;
}

.ai-research-error strong {
    color: #856404;
}

.ai-chat-input-container {
    padding: 16px;
    border-top: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-chat-input {
    width: 100%;
    min-height: 80px;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
}

.ai-chat-input:focus {
    outline: none;
    border-color: #FF6B35;
}

.ai-sidebar-toggle {
    position: fixed;
    left: 20px;
    bottom: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #FF6B35;
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    transition: background 0.2s, transform 0.2s;
}

.ai-sidebar-toggle:hover {
    background: #E55A2B;
    transform: scale(1.05);
}

.ai-sidebar-toggle.hidden {
    display: none;
}

/* Adjust playground container when sidebar is open */
.playground-container.with-sidebar {
    margin-left: 400px;
}

/* Chart chat button styles */
.dataface-chart {
    position: relative;
}

.dataface-chart-chat-btn {
    position: absolute;
    top: 8px;
    right: 50px;
    background: rgba(255, 107, 53, 0.9);
    color: white;
    border: none;
    border-radius: 4px;
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.dataface-chart:hover .dataface-chart-chat-btn {
    opacity: 1;
}

.dataface-chart-chat-btn:hover {
    background: rgba(255, 107, 53, 1);
    transform: scale(1.1);
}

.playground-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    transition: margin-left 0.3s ease;
}

.editor-pane, .preview-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #ddd;
    min-height: 0; /* Allow flex items to shrink below content size */
    overflow: hidden; /* Contain overflow */
}

.preview-pane {
    border-right: none;
    background: #f5f5f5;
}

.editor-header, .preview-header {
    padding: 8px 16px;
    background: #f8f8f8;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    font-weight: 600;
    color: #666;
    flex-shrink: 0; /* Prevent header from shrinking */
}

.header-actions-right {
    display: flex;
    gap: 8px;
    align-items: center;
}

.grid-toggle-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: #666;
    cursor: pointer;
    user-select: none;
    padding: 2px 6px;
    border-radius: 3px;
    transition: background 0.2s;
}

.grid-toggle-label:hover {
    background: #f0f0f0;
}

.grid-toggle-label input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
    width: 14px;
    height: 14px;
}

.btn-small {
    padding: 4px 12px;
    font-size: 12px;
}

.preview-header {
    background: #fff;
}

.status-indicator {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 3px;
    background: #e0e0e0;
    color: #666;
    height: 18px;
    line-height: 16px;
}

.status-indicator.status-rendered {
    background: #4caf50;
    color: white;
}

.status-indicator.status-error {
    background: #f44336;
    color: white;
}

.status-indicator.status-rendering {
    background: #ff9800;
    color: white;
}

.status-indicator.status-waiting {
    background: #e0e0e0;
    color: #666;
}

.status-indicator.status-connected {
    background: #2196f3;
    color: white;
}

.status-indicator.status-disconnected {
    background: #999;
    color: white;
}

#yaml-editor {
    flex: 1;
    overflow: auto;
}

.CodeMirror {
    height: 100%;
    font-size: 14px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
}

/* Ensure CodeMirror text is not clipped */
.CodeMirror-lines {
    padding: 8px 0;
}

.CodeMirror pre.CodeMirror-line,
.CodeMirror pre.CodeMirror-line-like {
    padding: 0 8px 0 12px;
}

/* Ensure gutter doesn't overlap code */
.CodeMirror-gutters {
    border-right: 1px solid #e0e0e0;
    background-color: #f8f8f8;
    min-width: 50px;
}

/* Prevent horizontal scroll clipping */
.CodeMirror-scroll {
    overflow-x: auto !important;
}

#preview-content {
    flex: 1;
    padding: 20px;
    min-height: 0; /* Allow flex item to shrink */
    overflow-y: auto; /* Enable vertical scrolling */
    overflow-x: hidden; /* Hide horizontal overflow - content will scale instead */
}

/* HTML iframe mode - iframe fills container, content inside has min-width */
#preview-content.html-mode {
    padding: 20px;
    height: auto;
}

#preview-content.html-mode iframe {
    width: 100%;
    border: none;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    display: block;
    /* Height will be set dynamically by JavaScript */
}

/* Wrapper for scalable content */
.preview-content-wrapper {
    width: 100%; /* fit-content; */
    max-width: 100%;
    transform-origin: top left;
    transition: transform 0.2s ease;
}

.preview-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #999;
    font-size: 14px;
}

.error-container {
    background: #ffebee;
    border: 1px solid #ef5350;
    border-radius: 4px;
    padding: 16px;
    color: #c62828;
}

.error-container ul {
    margin-top: 8px;
    margin-left: 20px;
}

.error-container li {
    margin: 4px 0;
}

/* Board/Dashboard title and description */
.board-title {
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #e0e0e0;
}

.board-title h1 {
    font-size: 32px;
    font-weight: 600;
    color: #1a1a1a;
    margin: 0;
}

.board-description {
    margin-bottom: 30px;
    color: #666;
}

.board-description p {
    font-size: 16px;
    line-height: 1.6;
    margin: 0;
}

.chart {
    background: white;
    padding: 20px;
    margin-bottom: 20px;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    /* Default aspect ratio for all charts (16:9) */
    aspect-ratio: 16 / 9;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
}

.chart h3 {
    margin-bottom: 15px;
    font-size: 18px;
    font-weight: 600;
    color: #333;
    flex-shrink: 0;
}

/* Chart content area - takes remaining space */
.chart-content {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

/* Make SVG charts responsive within their containers */
.chart svg {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    display: block;
}

/* Vega chart container */
.chart .vega-chart-container {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Charts with explicit height override */
.chart[data-height] {
    aspect-ratio: unset;
    height: var(--chart-height);
}

/* Charts with explicit width override */
.chart[data-width] {
    width: var(--chart-width);
}

.chart .error {
    color: #d32f2f;
    padding: 10px;
    background: #ffebee;
    border-radius: 4px;
}

/* Standalone error divs (not in error-container) */
.error {
    background: #ffebee;
    border: 1px solid #ef5350;
    border-radius: 4px;
    padding: 12px 16px;
    color: #c62828;
    margin: 10px 0;
    font-size: 14px;
    line-height: 1.5;
}

.content-section {
    background: white;
    padding: 20px;
    margin-bottom: 20px;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.content-section h2 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 20px;
    font-weight: 600;
    color: #333;
}

.content-section h1 {
    font-size: 24px;
    margin-top: 0;
    margin-bottom: 15px;
    color: #333;
}

.content-section h3 {
    font-size: 18px;
    margin-top: 15px;
    margin-bottom: 10px;
    color: #555;
}

.content-section p {
    margin: 10px 0;
    line-height: 1.6;
    color: #666;
}

.content-section table {
    border-collapse: collapse;
    width: 100%;
    margin: 15px 0;
    border: 1px solid #ddd;
}

.content-section table th {
    background: #f5f5f5;
    padding: 12px;
    text-align: left;
    font-weight: 600;
    border: 1px solid #ddd;
}

.content-section table td {
    padding: 10px 12px;
    border: 1px solid #ddd;
}

.content-section table tr:nth-child(even) {
    background: #fafafa;
}

.content-section code {
    background: #f4f4f4;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
}

.content-section pre {
    background: #f4f4f4;
    padding: 15px;
    border-radius: 5px;
    overflow-x: auto;
    margin: 15px 0;
}

.content-section pre code {
    background: none;
    padding: 0;
}

.content-section blockquote {
    border-left: 4px solid #ddd;
    padding-left: 20px;
    margin: 15px 0;
    color: #666;
    font-style: italic;
}

.content-section ul, .content-section ol {
    margin: 15px 0;
    padding-left: 30px;
}

.content-section li {
    margin: 5px 0;
    line-height: 1.6;
}

.content-section img {
    max-width: 100%;
    height: auto;
    margin: 15px 0;
    border-radius: 5px;
}

.content-section hr {
    border: none;
    border-top: 2px solid #e0e0e0;
    margin: 20px 0;
}

.content-section a {
    color: #2196f3;
    text-decoration: none;
}

.content-section a:hover {
    text-decoration: underline;
}

.section-title {
    margin: 20px 0 10px 0;
}

.section-title h2 {
    font-size: 22px;
    font-weight: 600;
    color: #333;
    margin: 0;
}

.section {
    margin-bottom: 30px;
}

.section h2 {
    font-size: 20px;
    font-weight: 600;
    color: #333;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #e0e0e0;
}

/* Cols layout - horizontal flex container */
/* For cols: widest chart sets height, others match */
.cols-layout {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    width: 100%;
    align-items: stretch; /* Same height for all items in row */
}

.cols-item {
    flex: 1;
    min-width: 0; /* Prevent flex items from overflowing */
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

/* Ensure charts inside cols-item fill the width and maintain aspect ratio */
.cols-item > .chart {
    width: 100%;
    flex: 1;
    margin-bottom: 0; /* Remove margin when in cols */
}

/* For rows layout: width is fixed, height flexes */
/* Rows are naturally vertical stack, so width is full container width */
.rows-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
}

.rows-layout .chart {
    width: 100%;
    /* Height determined by aspect ratio and width */
}

/* Grid layout - CSS grid container */
.grid-layout {
    display: grid;
    margin-bottom: 20px;
    width: 100%;
}

.grid-item {
    min-width: 0; /* Prevent grid items from overflowing */
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

/* Ensure charts inside grid-item fill the width */
.grid-item > .chart {
    width: 100%;
    flex: 1;
    margin-bottom: 0; /* Remove margin when in grid */
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #333;
    color: white;
    padding: 12px 20px;
    border-radius: 4px;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
    z-index: 1000;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

@media (max-width: 768px) {
    .playground-container {
        flex-direction: column;
    }

    .editor-pane, .preview-pane {
        border-right: none;
        border-bottom: 1px solid #ddd;
    }
}
