/**
 * Topic Modeling Studio - Styles
 * Uses CSS variables from ../shared/css/demo-styles.css for theming
 */

/* Demo-specific variables that don't conflict with theming */
:root {
    --topic-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --topic-shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
    --topic-transition: all 0.3s ease;
}

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

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px;
}

/* Hero Header - matches ELIZA demo styling */
.hero-header {
    padding: 3rem 0 2rem;
    margin-bottom: 30px;
    text-align: center;
    background: linear-gradient(180deg, var(--surface-color) 0%, var(--bg-color) 100%);
}

.hero-title {
    font-size: clamp(2rem, 4vw, 3rem);
    font-weight: 800;
    margin-bottom: 1rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hero-subtitle {
    font-size: clamp(1rem, 2vw, 1.25rem);
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto;
}

/* Main Layout */
.main-layout {
    display: grid;
    grid-template-columns: 350px 1fr;
    min-height: calc(100vh - 300px);
    gap: 0;
    background: var(--surface-color);
    border-radius: 12px;
    box-shadow: var(--topic-shadow-lg);
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    background: var(--bg-secondary);
    padding: 20px;
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    max-height: calc(100vh - 200px);
}

.control-panel {
    background: var(--surface-color);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--topic-shadow);
    border: 1px solid var(--border-color);
}

.control-panel h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.3em;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 8px;
}

.control-panel h4 {
    color: var(--secondary-color);
    margin: 15px 0 10px 0;
    font-size: 1.1em;
}

.control-section {
    margin-bottom: 20px;
}

.control-section label {
    display: block;
    margin: 10px 0 5px 0;
    font-weight: 600;
    color: var(--text-secondary);
}

.control-section select,
.control-section textarea {
    width: 100%;
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.3s;
    background: var(--surface-color);
    color: var(--text-primary);
}

.control-section select:focus,
.control-section textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.control-section textarea {
    resize: vertical;
    font-family: monospace;
}

.control-section input[type="range"] {
    width: calc(100% - 50px);
    margin-right: 10px;
}

.control-section span {
    display: inline-block;
    min-width: 40px;
    text-align: right;
    font-weight: 600;
    color: var(--primary-color);
}

.checkbox-group {
    margin-top: 10px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    margin: 8px 0;
    font-weight: 400;
    cursor: pointer;
    color: var(--text-primary);
}

.checkbox-group input[type="checkbox"] {
    margin-right: 8px;
    cursor: pointer;
}

.btn {
    width: 100%;
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--topic-transition);
    margin-top: 10px;
}

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

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: var(--surface-hover);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--surface-color);
    border-color: var(--primary-color);
}

.status-text {
    margin-top: 10px;
    padding: 8px;
    border-radius: 6px;
    background: rgba(16, 185, 129, 0.1);
    color: var(--success-color);
    font-size: 13px;
    text-align: center;
}

.info-panel {
    background: var(--surface-color);
    border-radius: 12px;
    padding: 20px;
    border-left: 4px solid var(--warning-color);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--warning-color);
}

.info-panel h4 {
    color: var(--warning-color);
    margin-bottom: 10px;
}

.info-panel p {
    margin-bottom: 10px;
    line-height: 1.6;
    color: var(--text-secondary);
}

.info-panel ul {
    list-style: none;
    padding-left: 0;
}

.info-panel li {
    margin: 8px 0;
    padding-left: 20px;
    position: relative;
    color: var(--text-secondary);
}

.info-panel li:before {
    content: '\25B8';
    position: absolute;
    left: 0;
    color: var(--warning-color);
}

.info-panel li strong {
    color: var(--text-primary);
}

/* Main Content */
.main-content {
    padding: 30px;
    overflow-y: auto;
    max-height: calc(100vh - 200px);
    background: var(--surface-color);
}

.view-container {
    animation: fadeIn 0.3s;
}

.view-container h2 {
    color: var(--primary-color);
    margin-bottom: 20px;
    font-size: 2em;
}

.view-container .subtitle {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.hidden {
    display: none !important;
}

/* Loading */
.loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--surface-color);
    padding: 40px;
    border-radius: 16px;
    box-shadow: var(--shadow-xl);
    text-align: center;
    z-index: 1000;
    border: 1px solid var(--border-color);
}

.loading p {
    color: var(--text-primary);
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

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

/* Topics Grid */
.topics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.topic-card {
    background: var(--surface-color);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    transition: var(--topic-transition);
    cursor: pointer;
}

.topic-card:hover {
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
    transform: translateY(-4px);
}

.topic-card h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.3em;
}

.topic-card .word-list {
    list-style: none;
}

.topic-card .word-item {
    display: flex;
    justify-content: space-between;
    margin: 8px 0;
    padding: 6px;
    background: var(--bg-secondary);
    border-radius: 6px;
}

.topic-card .word {
    font-weight: 600;
    color: var(--text-primary);
}

.topic-card .weight {
    color: var(--primary-color);
    font-size: 0.9em;
}

.topic-card .doc-count {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.9em;
}

/* Word Clouds */
.wordclouds-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    gap: 30px;
    margin-top: 20px;
}

.wordcloud-container {
    background: var(--surface-color);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
}

.wordcloud-container h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
    text-align: center;
}

.wordcloud-canvas {
    width: 100%;
    height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Document Distributions */
.distribution-controls {
    margin-bottom: 20px;
}

.distribution-controls label {
    font-weight: 600;
    margin-right: 10px;
    color: var(--text-primary);
}

.distribution-controls select {
    padding: 8px 12px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    background: var(--surface-color);
    color: var(--text-primary);
}

.plot-container {
    background: var(--surface-color);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    margin-top: 20px;
    min-height: 400px;
}

.doc-preview {
    margin-top: 20px;
    padding: 20px;
    background: var(--bg-secondary);
    border-radius: 12px;
    border-left: 4px solid var(--primary-color);
}

.doc-preview h4 {
    color: var(--primary-color);
    margin-bottom: 10px;
}

.doc-preview p {
    line-height: 1.8;
    color: var(--text-primary);
}

/* Inter-topic Distance */
.topic-details {
    margin-top: 30px;
    padding: 20px;
    background: var(--bg-secondary);
    border-radius: 12px;
}

.topic-details-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.topic-details h3 {
    color: var(--primary-color);
    margin-bottom: 0;
}

.close-btn {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: var(--topic-transition);
}

.close-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

/* Statistics Panel */
.stats-panel {
    background: var(--surface-color);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    margin-top: 30px;
}

.stats-panel h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.5em;
}

#stats-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.stat-item {
    padding: 15px;
    background: var(--bg-secondary);
    border-radius: 8px;
    text-align: center;
}

.stat-label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.9em;
    margin-bottom: 5px;
}

.stat-value {
    display: block;
    color: var(--primary-color);
    font-size: 1.8em;
    font-weight: 700;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Responsive */
@media (max-width: 1024px) {
    .main-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        max-height: none;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .topics-grid,
    .wordclouds-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .hero-title {
        font-size: 1.8rem;
    }

    .hero-subtitle {
        font-size: 0.9em;
    }

    .main-content {
        padding: 15px;
    }

    #stats-content {
        grid-template-columns: 1fr;
    }
}

/* Topic Documents Modal */
.topic-docs-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.topic-docs-modal.hidden {
    display: none;
}

.topic-docs-content {
    background: var(--surface-color);
    border-radius: 16px;
    width: 100%;
    max-width: 1200px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-color);
}

.topic-docs-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.topic-docs-header h3 {
    margin: 0;
    color: var(--primary-color);
}

.topic-docs-body {
    display: grid;
    grid-template-columns: 350px 1fr;
    flex: 1;
    overflow: hidden;
}

.topic-docs-list {
    overflow-y: auto;
    border-right: 1px solid var(--border-color);
    max-height: calc(90vh - 80px);
}

.topic-doc-item {
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: var(--topic-transition);
}

.topic-doc-item:hover {
    background: var(--surface-hover);
}

.topic-doc-item.selected {
    background: var(--bg-secondary);
    border-left: 3px solid var(--primary-color);
}

.topic-doc-item-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topic-doc-item-preview {
    font-size: 0.85em;
    color: var(--text-secondary);
    line-height: 1.4;
}

.topic-doc-item-score {
    margin-top: 8px;
}

.score-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8em;
    font-weight: 600;
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

.score-badge.dominant {
    background: var(--primary-color);
    color: white;
}

.topic-doc-detail {
    padding: 20px;
    overflow-y: auto;
    max-height: calc(90vh - 80px);
}

.topic-doc-detail h4 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.2em;
}

.topic-doc-detail .placeholder-text {
    color: var(--text-secondary);
    text-align: center;
    padding: 40px;
}

.doc-distribution-bars {
    margin-bottom: 20px;
    padding: 15px;
    background: var(--bg-secondary);
    border-radius: 8px;
}

.dist-bar-row {
    display: flex;
    align-items: center;
    margin: 8px 0;
    gap: 10px;
}

.dist-bar-row.focus {
    font-weight: 600;
}

.dist-bar-label {
    width: 70px;
    font-size: 0.85em;
    color: var(--text-secondary);
}

.dist-bar-track {
    flex: 1;
    height: 12px;
    background: var(--border-color);
    border-radius: 6px;
    overflow: hidden;
}

.dist-bar-fill {
    height: 100%;
    border-radius: 6px;
    transition: width 0.3s ease;
}

.dist-bar-value {
    width: 50px;
    text-align: right;
    font-size: 0.85em;
    color: var(--text-primary);
}

.doc-tagged-text {
    line-height: 1.8;
    color: var(--text-primary);
    padding: 15px;
    background: var(--bg-secondary);
    border-radius: 8px;
    max-height: 400px;
    overflow-y: auto;
}

.tagged-word {
    padding: 2px 0;
    border-radius: 2px;
    cursor: help;
}

.tagged-word.focus {
    font-weight: 600;
}

/* New Text Analysis Section */
.analyze-section {
    margin-top: 20px;
    padding: 20px;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.analyze-section h4 {
    color: var(--secondary-color);
    margin-bottom: 15px;
}

.analyze-section textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    background: var(--surface-color);
    color: var(--text-primary);
    resize: vertical;
    min-height: 80px;
}

.analyze-section textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.analyze-section .btn {
    margin-top: 10px;
}

.analyze-results {
    margin-top: 15px;
    padding: 15px;
    background: var(--surface-color);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.analyze-results h5 {
    color: var(--primary-color);
    margin-bottom: 10px;
}

.example-select-group {
    margin-bottom: 10px;
}

.example-select-group label {
    display: block;
    margin-bottom: 5px;
    color: var(--text-secondary);
    font-size: 0.9em;
}

.example-select-group select {
    width: 100%;
    padding: 8px 12px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--surface-color);
    color: var(--text-primary);
}

@media (max-width: 900px) {
    .topic-docs-body {
        grid-template-columns: 1fr;
    }
    
    .topic-docs-list {
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    
    .topic-doc-detail {
        max-height: calc(90vh - 280px);
    }
}

/* How It Works - LDA Explanation */
.lda-explanation {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.lda-explanation h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.3em;
}

.graphical-model-section {
    background: var(--bg-secondary);
    padding: 25px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.plate-diagram {
    display: flex;
    align-items: flex-start;
    gap: 40px;
    padding: 20px;
    justify-content: center;
}

.plate {
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    position: relative;
}

.outer-plate {
    background: rgba(99, 102, 241, 0.05);
    border-color: var(--primary-color);
}

.inner-plate {
    background: rgba(168, 85, 247, 0.05);
    border-color: var(--secondary-color);
    margin-top: 15px;
}

.plate-label {
    position: absolute;
    bottom: -10px;
    right: 10px;
    background: var(--surface-color);
    padding: 2px 8px;
    font-size: 0.85em;
    color: var(--text-secondary);
    font-style: italic;
}

.plate-label-small {
    font-size: 0.8em;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 5px;
}

.plate-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.node {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--surface-color);
    transition: var(--topic-transition);
}

.node:hover {
    transform: scale(1.1);
    box-shadow: var(--topic-shadow-lg);
}

.node.observed {
    background: var(--text-secondary);
    border-color: var(--text-secondary);
}

.node.observed .node-symbol,
.node.observed .node-label {
    color: var(--surface-color);
}

.node-symbol {
    font-size: 1.3em;
    font-weight: 700;
    color: var(--primary-color);
}

.node-label {
    font-size: 0.65em;
    color: var(--text-secondary);
    margin-top: 2px;
}

.theta-node {
    border-color: #22c55e;
}

.theta-node .node-symbol {
    color: #22c55e;
}

.z-node {
    border-color: var(--secondary-color);
}

.z-node .node-symbol {
    color: var(--secondary-color);
}

.phi-node {
    border-color: #f59e0b;
}

.phi-node .node-symbol {
    color: #f59e0b;
}

.arrow-down {
    width: 2px;
    height: 20px;
    background: var(--border-color);
    position: relative;
}

.arrow-down::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: -4px;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 8px solid var(--border-color);
}

.arrow-right {
    width: 30px;
    height: 2px;
    background: var(--border-color);
    position: relative;
}

.arrow-right::after {
    content: '';
    position: absolute;
    right: 0;
    top: -4px;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-left: 8px solid var(--border-color);
}

.hyperparams {
    display: flex;
    flex-direction: column;
    gap: 40px;
    padding-top: 30px;
}

.hyperparam {
    display: flex;
    align-items: center;
    gap: 15px;
}

.hyperparam .node-symbol {
    font-size: 1.5em;
    font-weight: 700;
    color: var(--warning-color);
}

.alpha-param {
    margin-top: 20px;
}

.beta-param {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 15px;
}

.lda-concepts .concept-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
}

.lda-concepts .concept-card {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    transition: var(--topic-transition);
}

.lda-concepts .concept-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--topic-shadow-lg);
    border-color: var(--primary-color);
}

.lda-concepts .concept-card h4 {
    color: var(--primary-color);
    margin-bottom: 10px;
    font-size: 1.1em;
}

.lda-concepts .concept-card p {
    color: var(--text-secondary);
    font-size: 0.9em;
    line-height: 1.6;
}

.lda-process {
    background: var(--bg-secondary);
    padding: 25px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.process-steps {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.process-step {
    display: flex;
    gap: 15px;
    align-items: flex-start;
    padding: 15px;
    background: var(--surface-color);
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
}

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

.step-content h4 {
    color: var(--text-primary);
    margin-bottom: 5px;
    font-size: 1em;
}

.step-content p {
    color: var(--text-secondary);
    font-size: 0.9em;
    margin: 5px 0;
    font-family: 'Monaco', 'Menlo', monospace;
}

.lda-inference {
    background: var(--bg-secondary);
    padding: 25px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.inference-intro {
    color: var(--text-secondary);
    margin-bottom: 15px;
    line-height: 1.6;
}

.lda-inference .formula-box {
    background: var(--surface-color);
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
}

.lda-inference .formula-box p {
    margin: 0 0 10px 0;
    color: var(--text-primary);
}

.lda-inference .formula-box p:first-child {
    font-weight: 600;
}

.lda-inference .formula {
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 1em;
    color: var(--primary-color);
    background: var(--bg-secondary);
    padding: 12px 20px;
    border-radius: 6px;
    text-align: center;
    margin: 10px 0;
    border: 1px solid var(--border-color);
    overflow-x: auto;
}

.lda-inference .formula-desc {
    font-size: 0.9em;
    color: var(--text-secondary);
    margin-top: 10px;
}

@media (max-width: 768px) {
    .plate-diagram {
        flex-direction: column;
        align-items: center;
    }
    
    .hyperparams {
        flex-direction: row;
        gap: 20px;
        padding-top: 20px;
    }
}
