:root {
    --bg: #0a0e1a;
    --bg-elevated: #0f1424;
    --bg-panel: #141b2d;
    --panel: var(--bg-elevated);
    --text: #e8ecff;
    --muted: #a9b3da;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3b82f6;
    --error-bg: rgba(239, 68, 68, 0.12);
    --error-border: rgba(239, 68, 68, 0.45);
    --error-text: #ef4444;
}

/* Scrollbars - blueish dark theme */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(59, 130, 246, 0.45) var(--bg-elevated);
}
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: var(--bg-elevated); }
*::-webkit-scrollbar-thumb {
    background: rgba(59, 130, 246, 0.35);
    border-radius: 4px;
}
*::-webkit-scrollbar-thumb:hover { background: rgba(59, 130, 246, 0.55); }
*::-webkit-scrollbar-corner { background: var(--bg-elevated); }

/* Shared style for sequence explorer error messages (compact, smaller font) */
#seq-error-display,
.seq-error-message {
    font-size: 0.72rem;
    line-height: 1.35;
    padding: 0.4rem 0.6rem;
    margin-bottom: 0.6rem;
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    border-radius: 4px;
    color: var(--error-text);
    word-break: break-word;
}

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

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.4 system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
    overflow-y: auto;
}

body {
    padding: 0.5rem;
    min-height: 100vh;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: transparent;
    border-radius: 10px;
    border: 1px solid var(--border);
    overflow: visible;
}

.content {
    padding: 1rem;
}

.panel {
    background: transparent;
    padding: 1rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    margin-bottom: 1rem;
}

.panel h2, .section-title {
    font-size: 0.9rem;
    font-weight: 600;
    margin: 0 0 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--accent);
    display: flex;
    align-items: center;
}

#seq-explorer-section {
    border: none;
    border-radius: 0;
    background: transparent;
    padding: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.seq-explorer-controls {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    align-items: center;
    flex-wrap: wrap;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}

.seq-explorer-controls label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text);
}

.seq-explorer-controls input[type="checkbox"] {
    cursor: pointer;
    width: 1rem;
    height: 1rem;
}

.seq-explorer-panes {
    display: flex;
    gap: 0.5rem;
    min-height: 500px;
}

.seq-explorer-left-pane {
    width: 40%;
    display: flex;
    flex-direction: column;
}

.seq-explorer-right-pane {
    width: 60%;
    display: flex;
    flex-direction: column;
}

.seq-explorer-tree {
    overflow-y: auto;
    flex: 1;
    padding: 0.5rem 0;
    min-height: 400px;
}

#seq-params-section {
    border: none;
    border-radius: 0;
    background: transparent;
    padding: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.seq-source-group {
    margin-bottom: 0.75rem;
}

.seq-source-header {
    font-weight: 600;
    color: var(--accent);
    padding: 0.5rem;
    background: rgba(59, 130, 246, 0.1);
    border-radius: 6px;
    margin-bottom: 0.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
}

.seq-source-header:hover {
    background: rgba(59, 130, 246, 0.15);
}

.seq-source-header::before {
    content: '▶';
    margin-right: 0.5rem;
    transition: transform 0.2s;
    font-size: 0.7rem;
}

.seq-source-header.collapsed::before {
    transform: rotate(-90deg);
}

.seq-source-items {
    margin-left: 1rem;
    padding-left: 0.5rem;
    border-left: 2px solid var(--border);
}

.seq-source-items.collapsed {
    display: none;
}

.seq-function-item {
    padding: 0.4rem 0.5rem;
    margin: 0.25rem 0;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
    color: var(--text);
}

.seq-function-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.seq-function-item.selected {
    background: rgba(59, 130, 246, 0.2);
    border-left: 3px solid var(--accent);
}

.seq-function-name {
    font-weight: 500;
}

.seq-file-function-name {
    font-weight: 500;
    font-size: 0.875rem;
}

.seq-function-doc {
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 0.25rem;
    font-style: italic;
}

.status-message {
    padding: 0.75rem;
    background: rgba(59, 130, 246, 0.1);
    border-left: 4px solid var(--accent);
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.status-message.error {
    background: rgba(239, 68, 68, 0.1);
    border-left-color: #ef4444;
}

.status-message.success {
    background: rgba(34, 197, 94, 0.1);
    border-left-color: #22c55e;
}

.loading {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* Subtle loading animation */
.startup-loader {
    position: fixed;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}
.startup-loader.active {
    opacity: 1;
}
.startup-loader.hidden {
    opacity: 0;
    transition: opacity 0.5s ease;
}
.loader-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(59, 130, 246, 0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
.loader-text {
    color: var(--muted);
    font-size: 0.875rem;
    text-align: center;
}

/* Console and versions styling */
.console {
    padding: 0.75rem;
    background: #111827;
    color: #4ade80;
    font-family: monospace;
    font-size: 0.7rem;
    border-radius: 0.375rem;
    overflow-x: auto;
    white-space: pre-wrap;
    height: 10rem;
    overflow-y: auto;
    border: 1px solid #1f2937;
}
.console .timestamp { color: var(--muted); }
.console .error { color: #f87171; }
.console .warn { color: #fbbf24; }
.console .info { color: #4ade80; }
.versions {
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.04);
    border-top: 1px solid var(--border);
    font-size: 0.7rem;
    color: var(--muted);
}
.versions span {
    margin-right: 0.75rem;
}
.console-section {
    display: none;
}
.console-section.visible {
    display: block;
}

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

/* Parameter controls */
#seq-params-section h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.75rem;
    letter-spacing: 0.05em;
}

#seq-params-controls {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 1rem;
    min-height: 0;
}

#seq-params-controls table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
}

#seq-params-controls table td {
    padding: 0.05rem 0.25rem;
    vertical-align: middle;
    line-height: 1.2;
}

#seq-params-controls table td:first-child {
    font-size: 0.8rem;
    font-weight: bold;
    color: var(--muted);
    letter-spacing: 0.05em;
    width: 100px;
}

#seq-params-controls table td:nth-child(2) {
    width: auto;
    min-width: 100px;
}

#seq-params-controls table td:last-child {
    width: 60px;
    text-align: right;
}

#seq-params-controls input[type="text"],
#seq-params-controls input[type="number"] {
    width: 100%;
    min-width: 100px;
    padding: 0.1rem 0.3rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.8rem;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    line-height: 1.2;
    height: auto;
}

#seq-params-controls input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Upload button in params table - align with app button style */
.params-upload-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(59, 130, 246, 0.4);
    background: rgba(59, 130, 246, 0.3);
    color: var(--text);
    border-radius: 3px;
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    gap: 0.25rem;
}

.params-upload-btn:hover:not(:disabled) {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.params-upload-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.btn.primary {
    background: var(--accent);
    border-color: rgba(0, 0, 0, 0.15);
    color: white;
}

.btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.12);
}

.btn.primary:hover:not(:disabled) {
    background: #2563eb;
}

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

#seq-execute-btn {
    /* Kept for ID specificity if needed, but uses .btn classes now */
}

/* Code Editor Modal */
.seq-editor-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.seq-editor-container {
    background: var(--bg, #1e1e1e);
    border: 1px solid var(--border, #333);
    border-radius: 8px;
    padding: 0;
    max-width: 90vw;
    max-height: 90vh;
    width: 1000px;
    height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.seq-editor-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border, #333);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.seq-editor-header h2 {
    margin: 0;
    color: var(--accent, #4a9eff);
    font-size: 1.2rem;
}

.seq-editor-body {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.seq-editor-body .CodeMirror {
    height: 100%;
    font-size: 14px;
}

/* Plot output container */
.seq-plot-container {
    width: 100%;
    margin-bottom: 1rem;
    min-height: 400px;
    max-height: none;
    overflow: visible;
    border: none;
    border-radius: 0;
    background: var(--bg);
    padding: 0.5rem;
}

.mpl-figure-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
    min-height: 0;
    padding: 0.25rem;
}

.mpl-figure-container:empty {
    min-height: 0;
    padding: 0;
    border: none;
    background: transparent;
}

/* Style the figure containers generated by matplotlib */
.mpl-figure-container > div {
    border: 1px solid var(--border) !important;
    border-radius: 6px !important;
    padding: 0 !important;
    background: var(--bg-elevated, #0f1424) !important;
    box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.3) !important;
    position: relative !important;
    display: inline-block !important;
    width: fit-content !important;
    max-width: 100% !important;
    margin: 0 0 0.5rem 0 !important;
    overflow: hidden;
}

#seq-plot-output canvas {
    display: block;
    max-width: 100%;
    height: auto !important;
    border-radius: 0;
}

#seq-plot-output * {
    visibility: visible !important;
    pointer-events: auto !important;
}

/* Hide the figure titles and title bars */
#seq-plot-output .ui-dialog-titlebar {
    display: none !important;
}

/* Scale down the entire toolbar area and its contents */
#seq-plot-output .mpl-toolbar, 
#seq-plot-output div[id$="top"] {
    display: flex !important;
    flex-wrap: wrap;
    gap: 3px;
    margin-bottom: 0;
    background: var(--bg-elevated, #0f1424);
    padding: 3px;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    min-height: 24px;
}

#seq-plot-output .mpl-toolbar button,
#seq-plot-output div[id$="top"] button,
#seq-plot-output .mpl-widget {
    padding: 2px 6px;
    background: var(--accent);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    font-size: 10px;
    line-height: 1.2;
    color: var(--text);
    transition: all 0.2s ease;
    opacity: 1;
}

#seq-plot-output .mpl-toolbar button:hover,
#seq-plot-output div[id$="top"] button:hover,
#seq-plot-output .mpl-widget:hover {
    background: rgba(59, 130, 246, 0.2);
    border-color: var(--accent);
    color: white;
}

#seq-plot-output .mpl-toolbar button:active,
#seq-plot-output div[id$="top"] button:active,
#seq-plot-output .mpl-widget:active,
#seq-plot-output .mpl-toolbar button.mpl-active,
#seq-plot-output div[id$="top"] button.mpl-active,
#seq-plot-output .mpl-widget.mpl-active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Style select dropdowns if they appear in the toolbar */
#seq-plot-output .mpl-toolbar select,
#seq-plot-output div[id$="top"] select {
    font-size: 10px !important;
    padding: 0 3px !important;
    height: 20px !important;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
    border: 1px solid var(--border);
}

/* Handle any images/icons in the toolbar */
#seq-plot-output .mpl-toolbar img,
#seq-plot-output div[id$="top"] img {
    width: 15px !important;
    height: 15px !important;
}

/* Tighten up the coordinate display area */
#seq-plot-output div[id$="message"] {
    font-size: 10px !important;
    padding: 2px 6px !important;
    min-height: 1rem !important;
    background: rgba(255, 255, 255, 0.04);
    border-top: 1px solid var(--border);
    color: var(--text);
}

#seq-plot-output div[id$="top"] button:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* Popup plot container - same styling as regular plot output */
#seq-popup-plot-container * {
    visibility: visible !important;
    pointer-events: auto !important;
}

/* Hide the figure titles and title bars in popup */
#seq-popup-plot-container .ui-dialog-titlebar {
    display: none !important;
}

/* Scale down the entire toolbar area and its contents in popup */
#seq-popup-plot-container .mpl-toolbar, 
#seq-popup-plot-container div[id$="top"] {
    display: flex !important;
    flex-wrap: wrap;
    gap: 3px;
    margin-bottom: 0;
    background: var(--bg-elevated, #0f1424);
    padding: 3px;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    min-height: 24px;
}

#seq-popup-plot-container .mpl-toolbar button,
#seq-popup-plot-container div[id$="top"] button,
#seq-popup-plot-container .mpl-widget {
    padding: 2px 6px;
    background: var(--accent);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    font-size: 10px;
    line-height: 1.2;
    color: var(--text);
    transition: all 0.2s ease;
    opacity: 1;
}

#seq-popup-plot-container .mpl-toolbar button:hover,
#seq-popup-plot-container div[id$="top"] button:hover,
#seq-popup-plot-container .mpl-widget:hover {
    background: rgba(59, 130, 246, 0.2);
    border-color: var(--accent);
    color: white;
}

#seq-popup-plot-container .mpl-toolbar button:active,
#seq-popup-plot-container div[id$="top"] button:active,
#seq-popup-plot-container .mpl-widget:active,
#seq-popup-plot-container .mpl-toolbar button.mpl-active,
#seq-popup-plot-container div[id$="top"] button.mpl-active,
#seq-popup-plot-container .mpl-widget.mpl-active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Style select dropdowns if they appear in the toolbar in popup */
#seq-popup-plot-container .mpl-toolbar select,
#seq-popup-plot-container div[id$="top"] select {
    font-size: 10px !important;
    padding: 0 3px !important;
    height: 20px !important;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
    border: 1px solid var(--border);
}

/* Handle any images/icons in the toolbar in popup */
#seq-popup-plot-container .mpl-toolbar img,
#seq-popup-plot-container div[id$="top"] img {
    width: 15px !important;
    height: 15px !important;
}

/* Tighten up the coordinate display area in popup */
#seq-popup-plot-container div[id$="message"] {
    font-size: 10px !important;
    padding: 2px 6px !important;
    min-height: 1rem !important;
    background: rgba(255, 255, 255, 0.04);
    border-top: 1px solid var(--border);
    color: var(--text);
}

#seq-popup-plot-container div[id$="top"] button:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* Style figure containers in popup */
#seq-popup-plot-container .mpl-figure-container > div {
    border: 1px solid var(--border) !important;
    border-radius: 6px !important;
    padding: 0 !important;
    background: var(--bg-elevated, #0f1424) !important;
    box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.3) !important;
    position: relative !important;
    display: inline-block !important;
    width: fit-content !important;
    max-width: 100% !important;
    margin: 0 0 0.5rem 0 !important;
    overflow: hidden;
}

#seq-popup-plot-container canvas {
    display: block;
    max-width: 100%;
    height: auto !important;
    border-radius: 0;
}
