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

:root {
    --color-bg: #f5f7fa;
    --color-surface: #ffffff;
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-accent: #059669;
    --color-accent-hover: #047857;
    --color-danger: #dc2626;
    --color-warning: #d97706;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-border: #e2e8f0;
    --color-badge-pending: #94a3b8;
    --color-badge-running: #f59e0b;
    --color-badge-done: #22c55e;
    --color-badge-error: #ef4444;
    --color-badge-action: #8b5cf6;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
    --font-mono: 'Menlo', 'Monaco', 'Courier New', monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

body {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
}

#app {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px;
}

/* === Header === */
header {
    text-align: center;
    margin-bottom: 24px;
}

header h1 {
    font-size: 1.8rem;
    margin-bottom: 8px;
}

.disclaimer {
    background: #fef3c7;
    border: 1px solid #fbbf24;
    border-radius: var(--radius);
    padding: 10px 16px;
    font-size: 0.85rem;
    color: #92400e;
    display: inline-block;
}

/* === Navigation === */
#pipeline-nav {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    overflow: hidden;
}

#pipeline-nav ul {
    display: flex;
    list-style: none;
}

#pipeline-nav .nav-link {
    display: block;
    padding: 14px 24px;
    text-decoration: none;
    color: var(--color-text-muted);
    font-weight: 500;
    transition: all 0.2s;
    border-bottom: 3px solid transparent;
}

#pipeline-nav .nav-link:hover {
    color: var(--color-primary);
    background: #f1f5f9;
}

#pipeline-nav .nav-link.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

/* === Sections === */
.section {
    display: none;
}

.section.active {
    display: block;
}

.section h2 {
    font-size: 1.4rem;
    margin-bottom: 16px;
}

/* === Cards === */
.card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
}

.card.card-compact {
    padding: 16px 24px;
}

.card h3 {
    font-size: 1.15rem;
    margin-bottom: 12px;
    color: var(--color-text);
}

.help-text {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-bottom: 12px;
}

/* === Model Selection === */
.model-selection-row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.model-select-group {
    flex: 1;
    min-width: 200px;
}

.model-select-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

.model-select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    background: #f8fafc;
    color: var(--color-text);
    cursor: pointer;
    transition: border-color 0.2s;
}

.model-select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* === Textareas === */
textarea {
    width: 100%;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    padding: 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    resize: vertical;
    background: #f8fafc;
    color: var(--color-text);
    line-height: 1.5;
    transition: border-color 0.2s;
}

textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* === Buttons === */
.button-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

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

.btn-primary {
    background: var(--color-primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
}

.btn-secondary {
    background: #e2e8f0;
    color: var(--color-text);
}

.btn-secondary:hover:not(:disabled) {
    background: #cbd5e1;
}

.btn-run {
    background: var(--color-accent);
    color: white;
}

.btn-run:hover:not(:disabled) {
    background: var(--color-accent-hover);
}

.btn-view {
    background: #e0e7ff;
    color: #3730a3;
}

.btn-view:hover:not(:disabled) {
    background: #c7d2fe;
}

.btn-accent {
    background: #7c3aed;
    color: white;
}

.btn-accent:hover:not(:disabled) {
    background: #6d28d9;
}

.status-msg {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    font-style: italic;
}

.status-msg.success {
    color: var(--color-accent);
}

.status-msg.error {
    color: var(--color-danger);
}

/* === Pipeline Diagram === */
#pipeline-diagram {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    padding: 16px 0;
    flex-wrap: wrap;
    justify-content: center;
}

.pipeline-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: #f1f5f9;
    border-radius: var(--radius);
    min-width: 100px;
    text-align: center;
    transition: all 0.2s;
}

.pipeline-stage.active {
    background: #dbeafe;
    border: 2px solid var(--color-primary);
}

.pipeline-stage.done {
    background: #dcfce7;
    border: 2px solid var(--color-badge-done);
}

.stage-icon {
    font-size: 1.5rem;
}

.stage-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text);
}

.stage-status {
    font-size: 0.65rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pipeline-arrow {
    font-size: 1.2rem;
    color: var(--color-text-muted);
    font-weight: bold;
}

/* === Steps === */
.step-group {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.step {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px;
    transition: border-color 0.2s;
}

.step:hover {
    border-color: #94a3b8;
}

.step-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.step-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: var(--color-primary);
    color: white;
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}

.step-title {
    font-weight: 600;
    font-size: 1rem;
    flex: 1;
}

.step-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--color-badge-pending);
    color: white;
}

.step-badge.running {
    background: var(--color-badge-running);
    animation: pulse 1.5s infinite;
}

.step-badge.done {
    background: var(--color-badge-done);
}

.step-badge.error {
    background: var(--color-badge-error);
}

.step-badge.action {
    background: var(--color-badge-action);
}

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

.step-desc {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-bottom: 8px;
}

/* === Session Link Containers === */
.session-link-container {
    display: none;
    margin-top: 8px;
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 0.82rem;
}

.session-monitor-link {
    background: #fef3c7;
    border: 1px solid #fbbf24;
    border-radius: var(--radius);
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.session-completed-link {
    background: #dcfce7;
    border: 1px solid #86efac;
    border-radius: var(--radius);
    padding: 8px 12px;
}

.session-error-link {
    background: #fef2f2;
    border: 1px solid #fca5a5;
    border-radius: var(--radius);
    padding: 8px 12px;
}

.monitor-link {
    color: var(--color-primary);
    text-decoration: underline;
    font-weight: 500;
}

.monitor-link:hover {
    color: var(--color-primary-hover);
}

.monitor-pulse {
    color: var(--color-badge-running);
    animation: pulse 1.5s infinite;
    font-size: 1.1em;
}

/* === Viewers === */
.viewer {
    margin-top: 12px;
    max-height: 500px;
    overflow-y: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px;
    background: #f8fafc;
    display: none;
    font-size: 0.9rem;
    line-height: 1.7;
}

.viewer.visible {
    display: block;
}

.viewer h1, .viewer h2, .viewer h3, .viewer h4 {
    margin-top: 1em;
    margin-bottom: 0.5em;
}

.viewer h1 {
    font-size: 1.4rem;
}

.viewer h2 {
    font-size: 1.2rem;
}

.viewer h3 {
    font-size: 1.05rem;
}

.viewer ul, .viewer ol {
    padding-left: 24px;
    margin-bottom: 0.5em;
}

.viewer li {
    margin-bottom: 4px;
}

.viewer p {
    margin-bottom: 0.75em;
}

.viewer code {
    background: #e2e8f0;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
}

.viewer pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 12px;
    border-radius: var(--radius);
    overflow-x: auto;
    margin-bottom: 1em;
}

.viewer pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.viewer blockquote {
    border-left: 4px solid var(--color-primary);
    padding-left: 16px;
    margin: 0.75em 0;
    color: var(--color-text-muted);
}

.viewer strong {
    color: var(--color-text);
}

/* === Results Tabs === */
.results-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 0;
    flex-wrap: wrap;
}

.results-tab {
    padding: 10px 20px;
    border: none;
    background: #e2e8f0;
    color: var(--color-text-muted);
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    border-radius: var(--radius) var(--radius) 0 0;
    transition: all 0.2s;
}

.results-tab:hover {
    background: #cbd5e1;
}

.results-tab.active {
    background: var(--color-surface);
    color: var(--color-primary);
    box-shadow: var(--shadow);
}

.results-content {
    background: var(--color-surface);
    border-radius: 0 var(--radius) var(--radius) var(--radius);
    box-shadow: var(--shadow);
}

.tab-panel {
    display: none;
    padding: 4px;
}

.tab-panel.active {
    display: block;
}

.tab-panel .card {
    box-shadow: none;
    margin-bottom: 0;
}

.result-viewer {
    min-height: 200px;
    max-height: 700px;
    overflow-y: auto;
    padding: 16px;
    line-height: 1.7;
    font-size: 0.9rem;
}

.result-viewer h1, .result-viewer h2, .result-viewer h3, .result-viewer h4 {
    margin-top: 1em;
    margin-bottom: 0.5em;
}

.result-viewer h1 {
    font-size: 1.4rem;
}

.result-viewer h2 {
    font-size: 1.2rem;
}

.result-viewer h3 {
    font-size: 1.05rem;
}

.result-viewer ul, .result-viewer ol {
    padding-left: 24px;
    margin-bottom: 0.5em;
}

.result-viewer li {
    margin-bottom: 4px;
}

.result-viewer p {
    margin-bottom: 0.75em;
}

.result-viewer blockquote {
    border-left: 4px solid var(--color-primary);
    padding-left: 16px;
    margin: 0.75em 0;
    color: var(--color-text-muted);
}

.placeholder {
    color: var(--color-text-muted);
    font-style: italic;
    text-align: center;
    padding: 40px 20px;
}

/* === Settings === */
.settings-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group label {
    font-weight: 600;
    font-size: 0.9rem;
}

.form-group .help-text {
    margin-bottom: 4px;
}

.settings-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.info-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.info-label {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    min-width: 100px;
}

.info-value {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    background: #f1f5f9;
    padding: 4px 8px;
    border-radius: 4px;
    word-break: break-all;
}

/* === Log Output === */
.log-output {
    margin-top: 12px;
    max-height: 400px;
    overflow-y: auto;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    background: #1e293b;
    color: #94a3b8;
    border-radius: var(--radius);
    padding: 12px;
    display: none;
}

.log-output.visible {
    display: block;
}

.log-output .log-entry {
    margin-bottom: 4px;
    line-height: 1.5;
}

.log-output .log-info {
    color: #60a5fa;
}

.log-output .log-success {
    color: #4ade80;
}

.log-output .log-error {
    color: #f87171;
}

.log-output .log-warn {
    color: #fbbf24;
}

.log-output a.monitor-link {
    color: #93c5fd;
    text-decoration: underline;
}

.log-output a.monitor-link:hover {
    color: #bfdbfe;
}

/* === Loading Overlay === */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    gap: 16px;
}

#loading-overlay.hidden {
    display: none;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-text {
    color: white;
    font-size: 1rem;
    font-weight: 500;
    text-align: center;
    line-height: 1.6;
}

.loading-text a {
    color: #93c5fd;
    text-decoration: underline;
}

.loading-text a:hover {
    color: #bfdbfe;
}

/* === Responsive === */
@media (max-width: 768px) {
    #app {
        padding: 12px;
    }

    header h1 {
        font-size: 1.3rem;
    }

    #pipeline-nav ul {
        flex-direction: column;
    }

    #pipeline-nav .nav-link {
        border-bottom: none;
        border-left: 3px solid transparent;
    }

    #pipeline-nav .nav-link.active {
        border-left-color: var(--color-primary);
        border-bottom-color: transparent;
    }

    #pipeline-diagram {
        flex-direction: column;
    }

    .pipeline-arrow {
        transform: rotate(90deg);
    }

    .button-row {
        flex-direction: column;
        align-items: stretch;
    }

    .results-tabs {
        flex-direction: column;
    }

    .results-tab {
        border-radius: var(--radius);
    }

    .model-selection-row {
        flex-direction: column;
    }
}