/* ============== Dashboard Layout ============== */
.dashboard-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    height: calc(100vh - 60px);
}

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

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 2px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: calc(16px * var(--text-scale, 1));
}

.sidebar-actions {
    display: flex;
    gap: 4px;
}

/* ============== Compare Toggle ============== */
.compare-toggle {
    padding: 12px 16px;
    border-bottom: 2px solid var(--border-color);
}

.compare-btn {
    width: 100%;
    padding: 10px 16px;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

.compare-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

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

/* ============== File Tree ============== */
.file-tree {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.tree-item {
    margin-bottom: 2px;
}

.tree-folder {
    cursor: pointer;
}

.folder-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
}

.folder-header:hover {
    background: var(--bg-tertiary);
}

.folder-icon {
    font-size: calc(16px * var(--text-scale, 1));
    transition: transform 0.2s;
}

.folder-header.expanded .folder-icon {
    transform: rotate(90deg);
}

.folder-name {
    flex: 1;
    font-weight: 500;
}

.folder-count {
    font-size: calc(12px * var(--text-scale, 1));
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    padding: 2px 8px;
    border-radius: 10px;
}

.folder-children {
    margin-left: 20px;
    display: none;
}

.folder-header.expanded + .folder-children {
    display: block;
}

/* ============== Sidebar Footer (Add Button) ============== */
.sidebar-footer {
    padding: 12px;
    border-top: 2px solid var(--border-color);
}

.add-item-btn {
    width: 100%;
    padding: 12px;
    background: transparent;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

.add-item-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--bg-tertiary);
}

.add-item-btn span {
    font-size: calc(18px * var(--text-scale, 1));
    font-weight: 700;
}

/* ============== Add Item Modal ============== */
.add-item-options {
    display: grid;
    gap: 16px;
}

.option-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
}

.option-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.option-icon {
    font-size: calc(24px * var(--text-scale, 1));
}

.option-info h3 {
    margin: 0 0 4px 0;
    font-size: calc(16px * var(--text-scale, 1));
    color: var(--text-primary);
}

.option-info p {
    margin: 0;
    font-size: calc(13px * var(--text-scale, 1));
    color: var(--text-secondary);
}

/* ============== Chat Log Items ============== */
.chat-log-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s;
    border: 2px solid transparent;
}

.chat-log-item:hover {
    background: var(--bg-tertiary);
}

.chat-log-item.selected {
    background: rgba(74, 144, 226, 0.1);
    border-color: var(--primary);
}

.chat-log-item.loading-selection {
    background: transparent;
    border: 2px dotted var(--primary);
    opacity: 0.6;
}

.folder-header.loading-selection {
    background: transparent;
    border: 2px dotted var(--primary);
    opacity: 0.6;
}

.chat-log-item.dragging {
    opacity: 0.5;
}

.chat-log-icon {
    font-size: calc(18px * var(--text-scale, 1));
}

.chat-log-info {
    flex: 1;
    min-width: 0;
}

.chat-log-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-log-meta {
    font-size: calc(12px * var(--text-scale, 1));
    color: var(--text-secondary);
}

.chat-log-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.chat-log-status.pending {
    background: var(--text-muted);
}

.chat-log-status.queued {
    background: var(--info);
}

.chat-log-status.processing {
    background: var(--warning);
    animation: pulse 1s infinite;
}

.chat-log-status.completed {
    background: var(--success);
}

.chat-log-status.error {
    background: var(--danger);
}

.chat-log-status.incomplete {
    background: var(--text-secondary);
    border: 1px solid var(--border-color); /* Distinguish from pending */
}

/* Metadata-only indicator badge */
.metadata-badge {
    font-size: calc(9px * var(--text-scale, 1));
    padding: 1px 4px;
    background: var(--info);
    color: white;
    border-radius: 3px;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
    margin-left: 4px;
    vertical-align: middle;
}

.chat-log-item.metadata-only .chat-log-icon {
    opacity: 0.7;
}

.viz-meta .metadata-tag {
    font-size: calc(11px * var(--text-scale, 1));
    padding: 2px 6px;
    background: var(--info);
    color: white;
    border-radius: 4px;
    margin-left: 8px;
    font-weight: 500;
}

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

/* ============== Compare Setup Area (Main Content) ============== */
.compare-setup-area {
    padding: 32px;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.setup-header {
    text-align: center;
    margin-bottom: 32px;
}

.setup-header h2 {
    font-size: calc(24px * var(--text-scale, 1));
    margin-bottom: 8px;
    color: var(--text-primary);
}

.setup-header p {
    color: var(--text-secondary);
}

.compare-groups-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
    overflow-y: auto;
    padding: 4px; /* Space for shadows */
}

.compare-group-card {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    height: 300px;
    transition: all 0.2s;
    border-top: 4px solid var(--group-color);
}

.compare-group-card:hover {
    box-shadow: var(--shadow-md);
}

.group-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-primary);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.group-header h3 {
    font-size: calc(16px * var(--text-scale, 1));
    font-weight: 600;
}

.group-color-picker,
.group-color-hex {
    display: none;
}

.figure-mode .group-color-picker {
    display: block;
    -webkit-appearance: none;
    appearance: none;
    width: 28px;
    height: 28px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 0;
    background: none;
    flex-shrink: 0;
}

.figure-mode .group-color-hex {
    display: block;
    width: 72px;
    padding: 4px 6px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: calc(12px * var(--text-scale, 1));
    background: var(--bg-primary);
    color: var(--text-primary);
    flex-shrink: 0;
}

.figure-mode .group-color-hex.invalid {
    border-color: var(--danger);
}

.group-color-picker::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.group-color-picker::-webkit-color-swatch {
    border: none;
    border-radius: 2px;
}

.group-header .group-name {
    cursor: pointer;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.group-header .group-name:hover {
    background: var(--bg-secondary);
}

.group-header .group-name-input {
    font-size: calc(16px * var(--text-scale, 1));
    font-weight: 600;
    padding: 2px 6px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    width: 200px;
    outline: none;
}

.group-header .group-name-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.remove-group-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: calc(20px * var(--text-scale, 1));
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}

.remove-group-btn:hover {
    color: var(--danger);
}

.group-dropzone {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: var(--bg-tertiary);
    transition: background 0.2s;
}

.group-dropzone.drag-over {
    background: rgba(74, 144, 226, 0.1);
    box-shadow: inset 0 0 0 2px var(--primary);
}

.group-dropzone-placeholder {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    text-align: center;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
}

.setup-actions {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: auto;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

/* Sidebar Compare Mode State */
.sidebar.compare-mode .chat-log-item {
    cursor: grab;
    opacity: 0.9;
    border: 1px solid transparent;
}

.sidebar.compare-mode .chat-log-item:hover {
    background: var(--bg-primary);
    border-color: var(--border-color);
    transform: translateX(4px);
}

.sidebar.compare-mode .chat-log-item.selected {
    background: transparent;
    border-color: transparent;
}

.sidebar.compare-mode .folder-header {
    cursor: pointer; /* Folders still clickable to expand/drag */
}

/* Dragging visual feedback */
.chat-log-item.dragging {
    opacity: 0.5;
    background: var(--bg-tertiary);
}

/* Compare Toggle Button Active State */
.compare-btn.active {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
}

.compare-btn.active:hover {
    background: #c82333;
}

/* Group Items in Card */
.compare-group-item {
    background: var(--bg-primary);
    padding: 8px 12px;
    margin-bottom: 8px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
    font-size: calc(13px * var(--text-scale, 1));
}

.compare-group-item .remove-item {
    color: var(--text-secondary);
    cursor: pointer;
    font-size: calc(16px * var(--text-scale, 1));
    background: none;
    border: none;
    padding: 0 4px;
}

.compare-group-item .remove-item:hover {
    color: var(--danger);
}

/* ============== Main Content ============== */
.main-content {
    overflow-y: auto;
    background: var(--bg-primary);
}

/* ============== Empty State ============== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 48px;
    text-align: center;
}

.empty-icon {
    font-size: calc(64px * var(--text-scale, 1));
    margin-bottom: 16px;
}

.empty-state h2 {
    margin-bottom: 8px;
    color: var(--text-primary);
}

.empty-state p {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.empty-state .primary-btn {
    width: auto;
    padding: 12px 32px;
}

/* ============== Visualization Area ============== */
.visualization-area {
    padding: 24px;
}

.viz-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--border-color);
}

.viz-title h2 {
    font-size: calc(24px * var(--text-scale, 1));
    margin-bottom: 4px;
}

.viz-meta {
    color: var(--text-secondary);
    font-size: calc(13px * var(--text-scale, 1));
}

.viz-actions {
    display: flex;
    gap: 12px;
}

/* ============== Viz Sections ============== */
.viz-section {
    margin-bottom: 32px;
}

.viz-section h3 {
    font-size: calc(16px * var(--text-scale, 1));
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border-color);
}

.section-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}

.section-header h3 {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.value-selector {
    padding: 8px 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    min-width: 200px;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: calc(13px * var(--text-scale, 1));
    cursor: pointer;
}

.toggle-label input {
    width: 16px;
    height: 16px;
}

/* ============== Chart Containers ============== */
.viz-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.chart-container {
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0;
    height: 400px;
    overflow: hidden;
    width: 100%;
    max-width: 100%;
}

/* Plotly charts fill their container */
.chart-container .js-plotly-plot,
.chart-container .plotly {
    width: 100% !important;
    height: 100% !important;
}

.chart-container .main-svg {
    width: 100% !important;
    height: 100% !important;
}

.chart-container.time-series {
    height: 350px;
}

.violin-container {
    overflow-y: auto;
    max-height: 450px;
}

/* ============== Conversation Filters ============== */
.conversation-filters {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.filter-btn {
    padding: 8px 16px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: calc(13px * var(--text-scale, 1));
}

.filter-btn:hover {
    background: var(--bg-tertiary);
}

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

/* ============== Conversation List ============== */
.conversation-list {
    display: grid;
    gap: 12px;
}

.conversation-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s;
}

.conversation-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.conv-index {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    font-weight: 700;
    font-size: calc(13px * var(--text-scale, 1));
}

.conv-info {
    flex: 1;
}

.conv-date {
    font-weight: 600;
    margin-bottom: 2px;
}

.conv-preview {
    font-size: calc(13px * var(--text-scale, 1));
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 400px;
}

.conv-stats {
    display: flex;
    gap: 16px;
    text-align: center;
}

.conv-stat-value {
    font-size: calc(18px * var(--text-scale, 1));
    font-weight: 700;
    color: var(--primary);
}

.conv-stat-label {
    font-size: calc(11px * var(--text-scale, 1));
    color: var(--text-secondary);
    text-transform: uppercase;
}

/* ============== Comparison Area ============== */
.comparison-area {
    padding: 24px;
}

.comparison-charts {
    display: grid;
    gap: 24px;
}

/* ============== Admin Layout ============== */
.admin-layout {
    display: grid;
    grid-template-columns: 200px 1fr;
    height: calc(100vh - 60px);
}

.admin-nav {
    background: var(--bg-secondary);
    border-right: 3px solid var(--border-dark);
    padding: 16px 0;
}

.admin-tab {
    display: block;
    width: 100%;
    padding: 12px 24px;
    background: none;
    border: none;
    text-align: left;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.15s;
}

.admin-tab:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.admin-tab.active {
    background: var(--primary);
    color: white;
}

.admin-content {
    padding: 24px;
    overflow-y: auto;
}

.admin-tab-content {
    display: none;
}

.admin-tab-content.active {
    display: block;
}

.admin-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.admin-actions h2 {
    font-size: calc(24px * var(--text-scale, 1));
}

.action-group {
    display: flex;
    gap: 12px;
    align-items: center;
}

.action-group input[type="number"] {
    width: 80px;
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
}

.action-group input[type="text"] {
    width: 180px;
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
}

.create-user-result {
    margin: 16px 0;
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    border: 2px solid var(--accent-color);
}

.create-user-result p {
    margin: 0 0 8px 0;
    font-weight: 600;
}

.token-display {
    display: flex;
    align-items: center;
    gap: 8px;
}

.token-display code {
    flex: 1;
    padding: 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: calc(14px * var(--text-scale, 1));
    user-select: all;
}

/* ============== Admin Tables ============== */
.admin-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.admin-table th,
.admin-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.admin-table th {
    background: var(--bg-secondary);
    font-weight: 600;
    font-size: calc(13px * var(--text-scale, 1));
    text-transform: uppercase;
    color: var(--text-secondary);
}

.admin-table tr:last-child td {
    border-bottom: none;
}

.admin-table tr:hover td {
    background: var(--bg-secondary);
}

.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: calc(12px * var(--text-scale, 1));
    font-weight: 600;
}

.status-badge.active {
    background: #e6ffe6;
    color: var(--success);
}

.status-badge.used {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.status-badge.expired {
    background: #ffe6e6;
    color: var(--danger);
}

/* ============== Stats Grid ============== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
}

.stat-card {
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 24px;
    text-align: center;
}

.stat-card .stat-value {
    font-size: calc(36px * var(--text-scale, 1));
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 8px;
}

.stat-card .stat-label {
    font-size: calc(14px * var(--text-scale, 1));
    color: var(--text-secondary);
    text-transform: uppercase;
}

/* ============== Config Form ============== */
.config-form {
    max-width: 700px;
}

.config-section {
    margin-bottom: 32px;
    padding: 20px;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
}

.config-section h3 {
    margin: 0 0 16px 0;
    font-size: calc(16px * var(--text-scale, 1));
    color: var(--text-primary);
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.config-field {
    display: grid;
    grid-template-columns: 200px 1fr auto;
    gap: 12px;
    align-items: center;
    margin-bottom: 12px;
}

.config-field:last-child {
    margin-bottom: 0;
}

.config-field.checkbox-field {
    grid-template-columns: 1fr auto;
}

.config-field.checkbox-field label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    color: var(--text-primary);
}

.config-field.checkbox-field input {
    width: 18px;
    height: 18px;
    margin: 0;
}

.config-field label {
    font-weight: 500;
    color: var(--text-secondary);
}

.config-field input,
.config-field select {
    padding: 8px 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: calc(14px * var(--text-scale, 1));
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.config-field input:focus,
.config-field select:focus {
    outline: none;
    border-color: var(--primary);
}

.config-save-btn {
    padding: 8px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: calc(13px * var(--text-scale, 1));
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.config-save-btn:hover {
    background: var(--primary-dark);
}

.config-hint {
    grid-column: 2 / -1;
    font-size: calc(12px * var(--text-scale, 1));
    color: var(--text-muted);
    margin-top: -8px;
}

/* ============== Queue Progress ============== */
.queue-progress {
    display: flex;
    align-items: center;
    gap: 8px;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    min-width: 80px;
}

.progress-bar-fill {
    height: 100%;
    background: var(--primary);
    transition: width 0.3s ease;
}

.progress-text {
    font-size: calc(12px * var(--text-scale, 1));
    color: var(--text-secondary);
    white-space: nowrap;
}

.status-badge.queued {
    background: #e3f2fd;
    color: #1976d2;
}

.status-badge.processing {
    background: #fff3e0;
    color: #f57c00;
    animation: pulse 1.5s infinite;
}

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

.status-badge.completed {
    background: #e6ffe6;
    color: var(--success);
}

.status-badge.error {
    background: #ffe6e6;
    color: var(--danger);
}

.status-badge.cancelled {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

[data-theme="dark"] .status-badge.queued {
    background: rgba(25, 118, 210, 0.2);
    color: #64b5f6;
}

[data-theme="dark"] .status-badge.processing {
    background: rgba(245, 124, 0, 0.2);
    color: #ffb74d;
}

[data-theme="dark"] .config-section {
    background: var(--bg-secondary);
}

/* ============== Conversation Detail Modal ============== */
.conversation-detail {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 24px;
    height: 100%;
}

.conversation-messages {
    overflow-y: auto;
    padding-right: 16px;
}

.message-item {
    margin-bottom: 16px;
}

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

.message-author {
    font-weight: 600;
    color: var(--primary);
}

.message-author.target {
    color: var(--success);
}

.message-time {
    font-size: calc(12px * var(--text-scale, 1));
    color: var(--text-secondary);
}

.message-content {
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    line-height: 1.6;
}

.message-item.target .message-content {
    background: rgba(40, 167, 69, 0.1);
    border: 1px solid rgba(40, 167, 69, 0.2);
}

.conversation-values {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 16px;
    overflow-y: auto;
}

.conversation-values h3 {
    font-size: calc(14px * var(--text-scale, 1));
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border-color);
}

.value-item {
    margin-bottom: 16px;
}

.value-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.value-name {
    font-weight: 600;
    font-size: calc(13px * var(--text-scale, 1));
}

.value-rating {
    font-weight: 700;
    color: var(--primary);
}

.value-analysis {
    font-size: calc(12px * var(--text-scale, 1));
    color: var(--text-secondary);
    line-height: 1.5;
}

.evidence-strong {
    color: var(--info, #17a2b8);
    font-weight: 700;
}

.evidence-weak {
    color: var(--danger, #dc3545);
    font-weight: 700;
}

.variation-marker {
    font-weight: 700;
    font-size: calc(0.85em * var(--text-scale, 1));
    vertical-align: super;
}
.variation-marker.most-precise {
    color: #17a2b8;
}
.variation-marker.least-precise {
    color: #e67e22;
}

.violin-mean[data-tooltip] {
    cursor: help;
    border-bottom: 1px dotted var(--text-secondary);
}

.value-rating[data-tooltip] {
    cursor: help;
    border-bottom: 1px dotted var(--text-secondary);
}

/* Insightfulness banner */
.insight-banner {
    padding: 12px;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    border-left: 4px solid;
}
.insight-banner.high {
    background: rgba(40, 167, 69, 0.1);
    border-left-color: var(--success, #28a745);
}
.insight-banner.medium {
    background: rgba(255, 193, 7, 0.1);
    border-left-color: var(--warning, #ffc107);
}
.insight-banner.low {
    background: rgba(220, 53, 69, 0.1);
    border-left-color: var(--danger, #dc3545);
}
.insight-banner-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}
.insight-banner-label {
    font-weight: 700;
    font-size: calc(13px * var(--text-scale, 1));
}
.insight-banner-score {
    font-weight: 700;
    font-size: calc(14px * var(--text-scale, 1));
    color: var(--primary);
}
.insight-banner-reasoning {
    font-size: calc(12px * var(--text-scale, 1));
    color: var(--text-secondary);
    line-height: 1.5;
    font-style: italic;
}

/* ============== Admin User Detail Modal ============== */
.large-modal {
    width: 900px;
    max-width: 95vw;
}

.user-detail-body {
    max-height: 80vh;
    overflow-y: auto;
}

.loading-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.user-detail-content.hidden {
    display: none;
}

.user-detail-section {
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
}

.user-detail-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.user-detail-section h3 {
    font-size: calc(16px * var(--text-scale, 1));
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
}

/* User Overview Grid */
.user-overview-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.overview-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    text-align: center;
}

.overview-label {
    font-size: calc(11px * var(--text-scale, 1));
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 4px;
    letter-spacing: 0.5px;
}

.overview-value {
    font-size: calc(14px * var(--text-scale, 1));
    font-weight: 600;
    color: var(--text-primary);
}

/* PVQ Results Container */
.pvq-results-container,
.aggregate-results-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.ud-chart-container {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    min-height: 280px;
}

.ud-scores-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.ud-score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    text-align: center;
}

.ud-score-label {
    font-size: calc(10px * var(--text-scale, 1));
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
}

.ud-score-value {
    font-size: calc(16px * var(--text-scale, 1));
    font-weight: 700;
    color: var(--primary);
}

/* Compact Table for Chat Logs */
.compact-table {
    font-size: calc(13px * var(--text-scale, 1));
}

.compact-table th,
.compact-table td {
    padding: 8px 12px;
}

.empty-state.hidden {
    display: none;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
}

/* Invite History */
.invite-history-container {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 16px;
}

.invite-history-row {
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

.invite-history-row:last-child {
    border-bottom: none;
}

.invite-history-row strong {
    color: var(--text-primary);
    margin-right: 8px;
}

.invite-history-row span {
    color: var(--text-secondary);
}

/* Clickable username in admin table */
.user-link {
    color: var(--primary);
    cursor: pointer;
    text-decoration: none;
}

.user-link:hover {
    text-decoration: underline;
}

/* PVQ section hidden state */
#udPvqSection.hidden {
    display: none;
}

#udAggregateSection.hidden {
    display: none;
}

/* ============== Responsive ============== */
@media (max-width: 1200px) {
    .viz-grid {
        grid-template-columns: 1fr;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 900px) {
    .dashboard-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: none;
    }

    .admin-layout {
        grid-template-columns: 1fr;
    }

    .admin-nav {
        display: flex;
        overflow-x: auto;
        padding: 0;
    }

    .admin-tab {
        white-space: nowrap;
    }

    .conversation-detail {
        grid-template-columns: 1fr;
    }

    .user-overview-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .pvq-results-container,
    .aggregate-results-container {
        grid-template-columns: 1fr;
    }

    .ud-scores-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Admin chat log hover preview popover */
.admin-chatlog-preview {
    position: fixed;
    z-index: 10000;
    display: flex;
    gap: 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
    padding: 12px;
    pointer-events: none;
    animation: previewFadeIn 0.15s ease-out;
}

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

.admin-chatlog-preview .preview-chart {
    flex-shrink: 0;
}

.admin-chatlog-preview .preview-values-stats {
    overflow-y: auto;
    max-height: 300px;
}

.preview-values-stats-table {
    border-collapse: collapse;
    font-size: calc(11px * var(--text-scale, 1));
    white-space: nowrap;
}

.preview-values-stats-table th,
.preview-values-stats-table td {
    padding: 3px 8px;
    border-bottom: 1px solid var(--border-color);
    text-align: right;
}

.preview-values-stats-table th {
    text-align: right;
    font-weight: 600;
    color: var(--text-secondary);
    position: sticky;
    top: 0;
    background: var(--bg-primary);
}

.preview-values-stats-table td:first-child,
.preview-values-stats-table th:first-child {
    text-align: left;
}

.preview-values-stats-table tr:last-child td {
    border-bottom: none;
}
