/* v3.0 - Minimal elegant design inspired by ChatGPT/Claude */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    background: #f9fafb;
    color: #1f2937;
    height: 90vh;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

/* Login Screen Styles */
.login-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #ffffff;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.login-card {
    background: #ffffff;
    border-radius: 12px;
    padding: 48px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border: 1px solid #e5e7eb;
    width: 90%;
    max-width: 420px;
    animation: slideIn 0.5s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

.login-header h2 {
    color: #111827;
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.login-header p {
    color: #6b7280;
    font-size: 0.875rem;
}

.login-card .form-group {
    margin-bottom: 20px;
}

.login-card .form-group label {
    display: block;
    color: #4a5568;
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.login-card .form-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.875rem;
    transition: all 0.2s;
    font-family: inherit;
    background: #ffffff;
}

.login-card .form-group input:focus {
    outline: none;
    border-color: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.login-button {
    width: 100%;
    padding: 10px;
    background: #10b981;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.login-button:hover {
    background: #059669;
}

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

.login-error {
    color: #991b1b;
    background: #fee2e2;
    border: 1px solid #ef4444;
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 15px;
    font-size: 0.875rem;
    display: none;
}

.login-error.show {
    display: block;
}

.login-footer {
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px solid #e5e7eb;
    text-align: center;
}

.login-footer p {
    color: #6b7280;
    font-size: 0.875rem;
    margin: 5px 0;
}

.container {
    height: 95vh;
    display: flex;
    flex-direction: column;
    padding: 0;
    margin: 0;
}

.main-content {
    display: grid;
    grid-template-columns: 280px 1fr 480px;
    gap: 0;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding: 0;
    max-width: 2060px;
    margin: 0 auto;
    width: 100%;
    height: 100vh;
    box-sizing: border-box;
}

/* Adjust grid when left sidebar is collapsed */
.main-content:has(.sidebar-card.collapsed) {
    grid-template-columns: 60px 1fr 480px;
}

/* Adjust grid when right sidebar is collapsed */
.main-content:has(.right-sidebar-card.collapsed) {
    grid-template-columns: 280px 1fr 60px;
}

/* Adjust grid when left sidebar is collapsed */
.main-content:has(.sidebar-card.collapsed):not(:has(.right-sidebar-card.collapsed)) {
    grid-template-columns: 60px 1fr 480px;
}

/* Adjust grid when both sidebars are collapsed */
.main-content:has(.sidebar-card.collapsed):has(.right-sidebar-card.collapsed) {
    grid-template-columns: 60px 1fr 60px;
}

.sidebar-card {
    width: 280px;
    transition: width 0.3s ease, opacity 0.3s ease;
    position: relative;
    overflow: hidden;
    height: 100%;
    min-height: 0; /* Allow flex shrinking */
    display: flex;
    flex-direction: column;
}

.right-sidebar-card {
    width: 480px;
    transition: width 0.3s ease, opacity 0.3s ease;
    position: relative;
    overflow: hidden;
    height: 100%;
    min-height: 0; /* Allow flex shrinking */
    display: flex;
    flex-direction: column;
    border-right: none;
    border-left: 1px solid #e5e7eb;
}

.sidebar-card.collapsed {
    width: 60px;
    background: #ffffff;
    border-left: 2px solid #d1d5db;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f3f4f6;
    position: relative;
    flex-shrink: 0;
}

.sidebar-header h3 {
    color: #6b7280;
    font-size: 0.75rem;
    font-weight: 500;
    margin: 0;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.toggle-btn {
    background: transparent;
    color: #374151;
    border: 1.5px solid #9ca3af;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 400;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    position: relative;
    padding: 0;
    line-height: 1;
    left: 0%;
}

.toggle-btn span {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    line-height: 0;
}

.toggle-icon {
    width: 12px;
    height: 12px;
    object-fit: contain;
    display: block;
    opacity: 50%;
}

.toggle-btn:hover {
    border-color: #374151;
    color: #111827;
    background: #f9fafb;
}

/* Right sidebar header layout */
.right-sidebar-header {
    flex-direction: row;
    justify-content: flex-start;
}

.right-sidebar-header .toggle-btn {
    position: relative;
    right: auto;
    left: 0;
    top: auto;
    transform: none;
    margin-right: 12px;
}

.right-sidebar-header .toggle-btn:hover {
    transform: scale(1.1);
}

.sidebar-card.collapsed .toggle-btn {
    position: absolute;
    left: 50%;
    right: auto;
    top: 30%;
    transform: translateX(-50%);
    z-index: 1000;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    background: white;
    border-color: #d1d5db;
}

.sidebar-card.collapsed .toggle-btn:hover {
    transform: translateX(-50%) scale(1.1);
}

.sidebar-content {
    transition: opacity 0.3s ease;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.sidebar-scrollable {
    overflow-y: scroll;
    flex: 1;
    min-height: 0;

    /* Firefox scrollbar */
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}

.sidebar-scrollable:hover {
    scrollbar-color: #9ca3af #f1f1f1;
}

/* Webkit browsers scrollbar */
.sidebar-scrollable::-webkit-scrollbar {
    width: 6px;
}

.sidebar-scrollable::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 3px;
}

.sidebar-scrollable::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 3px;
}

.sidebar-scrollable:hover::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.sidebar-scrollable:hover::-webkit-scrollbar-thumb {
    background: #9ca3af;
}

.sidebar-scrollable:hover::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}


.sidebar-card.collapsed .sidebar-content {
    display: none;
}

/* Hide header content but keep toggle button visible */
.sidebar-card.collapsed .sidebar-header {
    padding: 8px;
    min-height: auto;
    border-bottom: none;
}

.sidebar-card.collapsed .sidebar-header h3,
.sidebar-card.collapsed .sidebar-header .ai-status,
.sidebar-card.collapsed .sidebar-header img:not(.toggle-icon),
.sidebar-card.collapsed .sidebar-header > span:not(:has(.toggle-icon)) {
    display: none;
}

.sidebar-card.collapsed .sidebar-header > div:first-child {
    justify-content: center;
}

.sidebar-card.collapsed .sidebar-header > div:first-child > div:first-child {
    display: none;
}

.right-sidebar-card.collapsed {
    width: 60px;
    background: #ffffff;
    border-left: 2px solid #d1d5db;
}

.right-sidebar-card.collapsed .toggle-btn {
    position: absolute;
    left: 50%;
    right: auto;
    top: 30%;
    transform: translate(-50%, -50%);
    margin-right: 0;
    z-index: 1000;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    background: white;
    border-color: #d1d5db;
}

.right-sidebar-card.collapsed .toggle-btn:hover {
    transform: translate(-50%, -50%) scale(1.1);
}

.right-sidebar-card.collapsed .sidebar-content {
    display: none;
}

/* Hide header content but keep toggle button visible */
.right-sidebar-card.collapsed .sidebar-header {
    padding: 8px;
    min-height: auto;
    border-bottom: none;
}

.right-sidebar-card.collapsed .sidebar-header h3 {
    display: none;
}

.card {
    background: #ffffff;
    border-radius: 0;
    padding: 16px;
    box-shadow: none;
    border: none;
    border-right: 1px solid #e5e7eb;
    height: 100%;
    min-height: 0; /* Allow flex shrinking */
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

.chat-section {
    height: 100%;
    min-height: 0; /* Allow flex shrinking */
    min-width: 480px;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    overflow: hidden; /* Prevent section from expanding */
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f3f4f6;
    flex-shrink: 0;
}

.chat-header h2 {
    color: #111827;
    font-weight: 500;
    font-size: 1rem;
    flex-grow: 1;
}

.ai-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    color: #6b7280;
}

.history-btn {
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
}

.history-btn:hover {
    background: #e5e7eb;
    border-color: #d1d5db;
    color: #374151;
}

.conversation-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: #f9fafb;
    border-radius: 8px;
    margin-bottom: 8px;
    border: 1px solid #e5e7eb;
}

.conversation-item:hover {
    background: #f3f4f6;
}

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

.conversation-preview {
    font-size: 0.85rem;
    color: #374151;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.conversation-summary {
    font-size: 0.8rem;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
    font-style: italic;
}

.conversation-meta {
    font-size: 0.75rem;
    color: #9ca3af;
}

.conversation-delete-btn {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 1rem;
    transition: background 0.2s;
}

.conversation-delete-btn:hover {
    background: #fee2e2;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: #374151;
    padding: 6px 12px;
    background: #f9fafb;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
}

.user-info-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.875rem;
    color: #374151;
    padding: 10px;
    margin-top: 10px;
    background: #f9fafb;
    border-radius: 6px;
    border: none;
    flex-shrink: 0;
    width: 96%;
    box-sizing: border-box;
}

.ai-performance-footer {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px 10px;
    margin-top: 8px;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;
    width: 100%;
    box-sizing: border-box;
}

.user-role-badge {
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.user-role-badge.admin {
    background: #f59e0b;
    color: white;
}

.user-role-badge.operator {
    background: #3b82f6;
    color: white;
}

.logout-btn {
    padding: 4px 10px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    transition: background 0.2s;
    margin-left: 4px;
}

.logout-btn:hover {
    background: #dc2626;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #10b981;
    animation: pulse 2s infinite;
}

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

.chat-messages {
    flex: 1;
    overflow-y: scroll;
    padding: 15px;
    border: none;
    border-radius: 0;
    margin-bottom: 20px;
    background: #ffffff;
    min-height: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 0.95rem;

    /* Firefox scrollbar */
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}

.chat-messages:hover {
    scrollbar-color: #9ca3af #f1f1f1;
}

/* Webkit browsers (Chrome, Safari, Edge) scrollbar */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 4px;
}

.chat-messages:hover::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-messages:hover::-webkit-scrollbar-thumb {
    background: #9ca3af;
}

.chat-messages:hover::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

.message {
    margin-bottom: 15px;
    padding: 12px 16px;
    border-radius: 8px;
    max-width: 85%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 0.95rem;
    line-height: 1.6;
}

/* Code blocks within messages should use monospace */
.message pre,
.message code {
    font-family: 'SF Mono', 'Consolas', 'Monaco', 'Courier New', monospace;
}

.message pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 0.85rem;
    line-height: 1.4;
}

.message code {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
}

.message.user {
    background: #f3f4f6;
    color: #1f2937;
    margin-left: auto;
    text-align: right;
    border: 1px solid #e5e7eb;
}

.message.ai {
    background: #f9fafb;
    color: #1f2937;
    overflow: hidden;
    border: 1px solid #e5e7eb;
}

.message.success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #10b981;
}

.message.error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #ef4444;
}

.message-time {
    font-size: 0.8rem;
    opacity: 0.7;
    margin-top: 5px;
}

.input-section {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
}

.query-input {
    flex-grow: 1;
    padding: 12px 16px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
    resize: none; /* Disable resize to prevent layout issues */
    min-height: 80px;
    max-height: 200px;
    height: 80px; /* Fixed height */
    line-height: 1.5;
    overflow-y: scroll;
}

.query-input::-webkit-scrollbar {
    width: 6px;
}

.query-input::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.query-input::-webkit-scrollbar-thumb {
    background: #9ca3af;
    border-radius: 3px;
}

.query-input::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

.query-input:focus {
    border-color: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.send-button {
    padding: 12px 20px;
    background: #228479;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.2s;
    align-self: flex-end;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-button:hover {
    background: #1a6961;
}

.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #9ca3af;
}

.system-status {
    margin-bottom: 20px;
}

/* Bioreactor Real-Time Data */
.bioreactor-data {
    background: #f3f4f6;
    border-radius: 8px;
    padding: 0px;
    margin-bottom: 20px;
    color: #111827;
    border: 1px solid #e5e7eb;
}

.bioreactor-data h3 {
    margin: 0 0 12px 0;
    font-size: 1rem;
    font-weight: 600;
    color: #111827;
}

/* Bioreactor data section with horizontal scroll */
.bioreactor-data {
    overflow-x: auto;
    margin-bottom: 10px;
    max-width: 100%; /* Prevent overflow beyond sidebar */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

.bioreactor-data::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

.bioreactor-data:hover {
    scrollbar-width: thin; /* Firefox */
    -ms-overflow-style: auto; /* IE and Edge */
}

.bioreactor-data:hover::-webkit-scrollbar {
    display: block; /* Chrome, Safari, Opera */
    height: 8px;
}

.bioreactor-data:hover::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.bioreactor-data:hover::-webkit-scrollbar-thumb {
    background: #9ca3af;
    border-radius: 4px;
}

.bioreactor-data:hover::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

.realtime-data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    table-layout: fixed; /* Fixed layout for consistent column widths */
    margin-bottom: 5px;
}

.realtime-data-table th,
.realtime-data-table td {
    padding: 8px 12px;
    text-align: center;
    border: 1px solid #e5e7eb;
    max-width: 0; /* Force truncation with table-layout: fixed */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.realtime-data-table th {
    background: #f3f4f6;
    font-weight: 600;
    color: #374151;
}

/* Removed first-child styling since Type column was removed */
/* .realtime-data-table td:first-child {
    font-weight: 600;
    background: rgba(0, 0, 0, 0.15);
    position: sticky;
    left: 0;
    z-index: 1;
} */

.realtime-data-table tbody tr:nth-child(odd) {
    background: #f9fafb;
}

.data-update-time {
    text-align: right;
    font-size: 0.75rem;
    color: #6b7280;
    vertical-align: middle;
    font-style: italic;
    margin-right: 8px;
}

/* Carousel Indicators */
.carousel-indicators {
    display: flex;
    gap: 8px;
    align-items: center;
    vertical-align: middle;
    margin-left: 8px;   
}

.carousel-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #d1d5db;
    cursor: pointer;
    transition: all 0.2s ease;
}

.carousel-indicator.active {
    background: #6b7280;
    width: 10px;
    height: 10px;
}

.carousel-indicator:hover {
    background: #9ca3af;
}

/* System Status Mini at bottom */
.system-status-mini {
    background: #f9fafb;
    border-radius: 8px;
    padding: 12px 15px;
    margin-top: 20px;
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    border: 1px solid #e5e7eb;
}

.status-mini-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
}

.status-mini-label {
    color: #718096;
    font-weight: 500;
}

.status-mini-value {
    color: #2D3748;
    font-weight: 600;
}

.status-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 20px;
}

.status-item {
    background: #f9fafb;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
    border-left: 3px solid #10b981;
}

.status-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: #2d3748;
}

.status-label {
    font-size: 0.9rem;
    color: #718096;
    margin-top: 5px;
}

.quick-actions {
    margin-top: 0;
}

.quick-actions h3 {
    margin-bottom: 8px;
    color: #6b7280;
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.recent-queries {
    margin-top: 10px;
    margin-bottom: 10px;
}

.recent-queries h3 {
    margin-bottom: 12px;
    color: #111827;
    font-size: 1rem;
    font-weight: 600;
}

.recent-query-btn {
    background: #f9fafb !important;
    border-color: #d1d5db !important;
    font-style: italic;
}

.recent-query-btn:hover {
    background: #f3f4f6 !important;
    border-color: #10b981 !important;
}

.horizontal-buttons {
    display: flex;
    gap: 10px;
}

.action-buttons {
    display: grid;
    gap: 4px;
}

.action-button {
    padding: 8px 12px;
    border: none;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
    font-size: 0.8rem;
    color: #374151;
}

.action-button:hover {
    background: #f3f4f6;
}

.emergency-button {
    background: #ef4444;
    color: white;
    border: none;
    font-weight: 500;
    margin-top: 4px;
}

.emergency-button:hover {
    background: #dc2626;
}

.analytics-panel {
    margin-top: 16px;
}

.analytics-panel h3 {
    margin-bottom: 8px;
    color: #6b7280;
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.analytics-chart {
    background: #f9fafb;
    padding: 15px;
    border-radius: 8px;
    margin-top: 10px;
    text-align: center;
    color: #6b7280;
    font-style: italic;
    border: 1px solid #e5e7eb;
}

.control-loops {
    background: transparent;
    padding: 0;
    border-radius: 0;
    margin-top: 10px;
    border: none;
}

.loop-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background: #f9fafb;
    border-radius: 6px;
    margin-bottom: 6px;
    max-height: 200px;
    overflow: hidden;
}

.loop-description {
    font-size: 0.85rem;
    color: #718096;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    max-height: 3.9em; /* ~3 lines at 1.3 line-height */
    line-height: 1.3;
}

.loop-item:last-child {
    margin-bottom: 0;
}

.loading {
    display: none;
    text-align: center;
    color: #6b7280;
    font-style: italic;
    flex-shrink: 0;
    margin-top: 10px;
}

.loading.show {
    display: block;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.modal[style*="display: block"] {
    display: flex !important;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: white;
    border-radius: 12px;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
    background-color: white;
    border-radius: 12px 12px 0 0;
}

.modal-header h2 {
    color: #111827;
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
}

.close {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s;
}

.close:hover {
    color: #000;
}

.reactor-context-bar {
    background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 100%);
    border-bottom: 1px solid #d1fae5;
    padding: 8px 25px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.875rem;
}

.reactor-context-bar .reactor-name {
    font-weight: 600;
    color: #065f46;
}

.reactor-context-bar .reactor-id {
    color: #6b7280;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    font-size: 0.8rem;
    background: rgba(255,255,255,0.6);
    padding: 2px 8px;
    border-radius: 4px;
}

.reactor-context-bar:empty {
    display: none;
}

.modal-body {
    padding: 25px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

/* Scrollbar styles for modal body */
.modal-body {
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}

.modal-body:hover {
    scrollbar-color: #9ca3af #f1f1f1;
}

.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 4px;
}

.modal-body:hover::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.modal-body:hover::-webkit-scrollbar-thumb {
    background: #9ca3af;
}

.modal-body:hover::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

.rules-section {
    margin-bottom: 20px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 16px;
}

.rules-section h3 {
    color: #374151;
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 12px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    color: #4a5568;
    font-weight: 500;
    margin-bottom: 5px;
}

.form-input {
    width: 100%;
    padding: 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.form-textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
    min-height: 80px;
    resize: vertical;
    transition: border-color 0.2s;
}

.form-textarea:focus {
    outline: none;
    border-color: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.rules-list {
    max-height: 400px;
    overflow-y: auto;
}

.rules-list {
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}

.rules-list:hover {
    scrollbar-color: #9ca3af #f1f1f1;
}

.rules-list::-webkit-scrollbar {
    width: 8px;
}

.rules-list::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 4px;
}

.rules-list::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 4px;
}

.rules-list:hover::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.rules-list:hover::-webkit-scrollbar-thumb {
    background: #9ca3af;
}

.rule-item {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
}

.rule-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-size: 0.95rem;
}

.rule-priority {
    background: #6b7280;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
}

.rule-body {
    color: #2d3748;
    margin-bottom: 10px;
    line-height: 1.5;
}

.rule-params {
    color: #718096;
    font-size: 0.9rem;
    margin-bottom: 10px;
}

.rule-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #e2e8f0;
}

.rule-stats {
    color: #718096;
    font-size: 0.85rem;
}

.rule-btn {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
    margin-left: 8px;
}

.rule-btn.enabled {
    background: #48bb78;
    color: white;
}

.rule-btn.disabled {
    background: #cbd5e0;
    color: #4a5568;
}

.rule-btn.delete {
    background: #f56565;
    color: white;
}

.rule-btn:hover {
    opacity: 0.9;
}

.edit-button {
    padding: 5px 10px;
    border: 1px solid #d1d5db;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    color: #374151;
    transition: all 0.2s;
}

.edit-button:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

/* Consistent modal action buttons */
.modal-action-btn {
    padding: 6px 12px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.2s;
    white-space: nowrap;
}

.modal-action-btn:hover {
    opacity: 0.85;
    transform: translateY(-1px);
}

.modal-action-btn:active {
    transform: translateY(0);
}

.delete-button {
    padding: 5px 10px;
    border: 1px solid #d1d5db;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    color: #374151;
    transition: all 0.2s;
}

.delete-button:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.status-badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
    margin-left: 8px;
    display: inline-block;
}

@media (max-width: 768px) {
    body {
        height: 100vh;
    }

    .container {
        padding: 5px;
        height: 100vh;
    }

    .main-content {
        display: flex;
        flex-direction: column;
        gap: 10px;
        padding: 10px;
        height: 100%;
    }

    /* Sidebars at top when collapsed on mobile */
    .sidebar-card {
        order: 1;
        width: 100%;
        height: auto;
        max-height: none;
        flex-shrink: 0;
        margin-bottom: 0;
    }

    .right-sidebar-card {
        order: 2;
        width: 100%;
        height: auto;
        max-height: none;
        flex-shrink: 0;
        margin-bottom: 0;
    }

    .sidebar-card.collapsed {
        margin-bottom: 5px;
    }

    .right-sidebar-card.collapsed {
        margin-bottom: 10px;
    }

    /* Chat section stays at bottom on mobile */
    .chat-section {
        order: 3;
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    /* Collapsed state on mobile */
    .sidebar-card.collapsed, .right-sidebar-card.collapsed {
        width: 100%;
        height: 50px;
        min-height: 50px;
        max-height: 50px;
        overflow: hidden;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        display: flex;
        align-items: center;
        padding: 0 !important;
        cursor: pointer;
        transition: background-color 0.2s ease, border-color 0.2s ease;
        background-color: #ffffff;
    }

    .sidebar-card.collapsed:active,
    .right-sidebar-card.collapsed:active {
        background-color: #f9fafb;
        border-color: #228479;
    }

    .sidebar-card.collapsed .sidebar-header,
    .right-sidebar-card.collapsed .sidebar-header {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0 15px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        border-bottom: none;
        position: relative;
        pointer-events: none;
    }

    .sidebar-card.collapsed .toggle-btn,
    .right-sidebar-card.collapsed .toggle-btn {
        pointer-events: auto;
    }

    .sidebar-card.collapsed .sidebar-content,
    .right-sidebar-card.collapsed .sidebar-content {
        display: none;
    }

    /* Expanded state on mobile - overlay style */
    .sidebar-card:not(.collapsed), .right-sidebar-card:not(.collapsed) {
        position: fixed;
        top: 10px;
        left: 10px;
        right: 10px;
        bottom: 10px;
        width: calc(100% - 20px);
        height: auto;
        max-height: calc(100vh - 20px);
        z-index: 1001;
        box-shadow: 0 4px 20px rgba(0,0,0,0.3);
        border: 2px solid #228479;
        animation: slideInMobile 0.3s ease-out;
    }

    @keyframes slideInMobile {
        from {
            opacity: 0;
            transform: translateY(-20px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    /* Toggle button positioning on mobile */
    .sidebar-card.collapsed .toggle-btn,
    .right-sidebar-card.collapsed .toggle-btn {
        position: relative;
        right: auto;
        left: auto;
        top: auto;
        transform: none;
        margin: 0;
        box-shadow: none;
        flex-shrink: 0;
    }

    /* Left sidebar in collapsed mobile mode */
    .sidebar-card.collapsed .sidebar-header {
        flex-direction: row !important;
        align-items: center !important;
        gap: 10px;
        padding: 8px 12px;
    }

    .sidebar-card.collapsed .sidebar-header > div:first-child {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .sidebar-card.collapsed .ai-status {
        display: none;
    }

    .sidebar-card.collapsed h3 {
        font-size: 0.85rem !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .sidebar-card.collapsed .toggle-btn {
        position: relative !important;
        left: auto !important;
        top: auto !important;
        transform: none !important;
        flex-shrink: 0;
    }

    /* Right sidebar button on right side when collapsed */
    .right-sidebar-card.collapsed .sidebar-header {
        flex-direction: row;
        justify-content: space-between;
        gap: 10px;
    }

    .right-sidebar-card.collapsed h3 {
        order: 1;
        max-width: calc(100% - 50px);
    }

    .right-sidebar-card.collapsed .toggle-btn {
        order: 2;
        margin-right: 0;
    }

    /* Toggle buttons in expanded state on mobile */
    .sidebar-card:not(.collapsed) .toggle-btn {
        position: absolute;
        right: 15px;
        top: 15px;
        transform: none;
        margin: 0;
    }

    .right-sidebar-card:not(.collapsed) .toggle-btn {
        position: absolute;
        right: 15px;
        top: 15px;
        left: auto;
        margin: 0;
        transform: none;
    }

    /* Header adjustments on mobile */
    .sidebar-header {
        min-height: 50px;
        display: flex;
        align-items: center;
        padding: 0 15px;
        position: relative;
    }

    .sidebar-card.collapsed .sidebar-header h3,
    .right-sidebar-card.collapsed .sidebar-header h3 {
        opacity: 1;
        font-size: 0.95rem;
        font-weight: 600;
        margin: 0;
        padding: 0 10px 0 0;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        flex: 1;
        color: #111827;
    }

    .right-sidebar-card.collapsed .sidebar-header h3 {
        padding: 0 10px 0 0;
    }

    /* Expanded state headers */
    .sidebar-card:not(.collapsed) .sidebar-header,
    .right-sidebar-card:not(.collapsed) .sidebar-header {
        padding: 15px 50px 15px 15px;
        flex-direction: row;
        justify-content: flex-start;
    }

    .sidebar-card:not(.collapsed) .sidebar-header h3,
    .right-sidebar-card:not(.collapsed) .sidebar-header h3 {
        opacity: 1;
    }

    /* Sidebar content scrolling on mobile */
    .sidebar-card:not(.collapsed) .sidebar-content,
    .right-sidebar-card:not(.collapsed) .sidebar-content {
        overflow-y: auto;
        max-height: calc(100vh - 90px);
    }

    /* Chat input adjustments */
    .query-input {
        min-height: 60px;
        height: 60px;
        font-size: 0.9rem;
    }

    .send-button {
        min-height: 60px;
        padding: 10px 15px;
        font-size: 0.85rem;
    }

    .modal-content {
        width: 95%;
        max-height: 95vh;
    }

    /* Adjust chat messages for mobile */
    .message {
        max-width: 95%;
        font-size: 0.9rem;
    }

    .chat-header h2 {
        font-size: 1rem;
    }

    /* Make action buttons more touch-friendly */
    .action-button {
        padding: 12px 14px;
        font-size: 0.9rem;
    }

    /* Mobile alert positioning */
    .alert-container {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }

    .alert-popup {
        min-width: auto;
        width: 100%;
    }
}

/* Mobile sidebar backdrop */
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-backdrop.active {
    display: block;
    opacity: 1;
}

/* Alert and Alarm Popup Styles */
.alert-container {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 400px;
    pointer-events: none;
}

.alert-popup {
    pointer-events: auto;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    overflow: hidden;
    min-width: 350px;
    max-width: 400px;
    border: 2px solid;
    backdrop-filter: blur(10px);
}

.alert-popup.alert-yellow {
    background: rgba(255, 243, 205, 0.98);
    border-color: #f59e0b;
    color: #1f2937;
}

.alert-popup.alert-red {
    background: rgba(220, 38, 38, 0.95);
    border-color: #fbbf24;
    color: #fef3c7;
}

.alert-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    gap: 10px;
    font-weight: 600;
    border-bottom: 1px solid;
}

.alert-popup.alert-yellow .alert-header {
    background: rgba(245, 158, 11, 0.2);
    border-bottom-color: #f59e0b;
}

.alert-popup.alert-red .alert-header {
    background: rgba(185, 28, 28, 0.3);
    border-bottom-color: #fbbf24;
}

.alert-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.alert-type {
    flex: 1;
    font-size: 16px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.alert-close {
    background: none;
    border: none;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.alert-popup.alert-yellow .alert-close {
    color: #92400e;
}

.alert-popup.alert-yellow .alert-close:hover {
    background: rgba(245, 158, 11, 0.3);
}

.alert-popup.alert-red .alert-close {
    color: #fef3c7;
}

.alert-popup.alert-red .alert-close:hover {
    background: rgba(185, 28, 28, 0.4);
}

.alert-body {
    padding: 16px;
}

.alert-message {
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 8px;
    font-weight: 500;
}

.alert-popup.alert-yellow .alert-message {
    color: #1f2937;
}

.alert-popup.alert-red .alert-message {
    color: #fef3c7;
    font-weight: 600;
}

.alert-time {
    font-size: 12px;
    opacity: 0.8;
    font-style: italic;
}

.alert-popup.alert-yellow .alert-time {
    color: #78716c;
}

.alert-popup.alert-red .alert-time {
    color: #fde68a;
}

@keyframes slideInRight {
    from {
        transform: translateX(450px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(450px);
        opacity: 0;
    }
}

/* Tab Buttons */
.tab-button {
    background: none;
    border: none;
    padding: 10px 16px;
    font-size: 0.9rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    color: #6b7280;
    font-weight: 400;
}

.tab-button:hover {
    color: #374151;
    background: #f9fafb;
}

.tab-button.active {
    color: #111827;
    border-bottom-color: #374151;
    font-weight: 500;
}

.alert-tab-panel {
    animation: fadeIn 0.3s ease-in;
}

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

/* ==================== Reactor Info & Parameter Manager Styles ==================== */

.form-section {
    background: white;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
    padding: 16px;
    margin-bottom: 16px;
}

.form-section h3 {
    margin: 0 0 12px 0;
    font-size: 1rem;
    font-weight: 500;
    color: #374151;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

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

.form-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 5px;
}

.form-group input,
.form-group textarea {
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.875rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 60px;
}

.button-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.btn-primary,
.btn-secondary,
.btn-danger {
    padding: 8px 16px;
    border: 1px solid #d1d5db;
    background: white;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 400;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary:hover,
.btn-secondary:hover,
.btn-danger:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.btn-primary:active,
.btn-secondary:active,
.btn-danger:active {
    background: #e5e7eb;
}

.btn-sm {
    padding: 4px 10px;
    border: 1px solid #d1d5db;
    background: white;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 400;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-sm:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.btn-sm:active {
    background: #e5e7eb;
}

.parameter-card {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 10px;
}

.parameter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e5e7eb;
}

.parameter-header strong {
    font-size: 1rem;
    color: #1f2937;
}

.parameter-details {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 0.875rem;
    color: #6b7280;
    margin-bottom: 10px;
}

.parameter-details strong {
    color: #374151;
}

.status-message {
    display: none;
    padding: 12px;
    border-radius: 6px;
    margin-top: 15px;
    font-size: 0.875rem;
    font-weight: 500;
}

/* Header Icon Buttons (Chat/Trends/History) */
.header-icon-btn {
    background: transparent;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 6px;
    cursor: pointer;
    color: #6b7280;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
}

.header-icon-btn:hover {
    background: #f3f4f6;
    color: #374151;
    border-color: #d1d5db;
}

.header-icon-btn.active {
    background: #228479;
    color: white;
    border-color: #228479;
}

.header-icon-btn.active:hover {
    background: #1a6b62;
    border-color: #1a6b62;
}

/* Time Range Buttons for Trends */
.time-range-btn {
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    padding: 6px 0;
    min-width: 42px;
    font-size: 0.75rem;
    cursor: pointer;
    color: #6b7280;
    border-radius: 4px;
    transition: all 0.15s ease;
    text-align: center;
}

.time-range-btn:hover {
    background: #e5e7eb;
}

.time-range-btn.active {
    background: #228479;
    color: white;
    font-weight: 600;
    border-color: #228479;
}

/* Y-Axis Legend Items (editable) */
.y-axis-legend-item {
    padding: 2px 6px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.y-axis-legend-item:hover {
    background-color: #e5e7eb;
}

.y-axis-legend-item .y-min,
.y-axis-legend-item .y-max {
    font-weight: 600;
    text-decoration: underline;
    text-decoration-style: dotted;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr;
    }

    .form-group[style*="grid-column: span 2"] {
        grid-column: span 1 !important;
    }

    .button-group {
        flex-direction: column;
    }

    .button-group button {
        width: 100%;
    }
}

/* Loading Spinner */
.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #e5e7eb;
    border-top-color: #10b981;
    border-radius: 50%;
    animation: spinner-spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}

.loading-spinner-lg {
    width: 24px;
    height: 24px;
    border-width: 3px;
}

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

/* Data Logger Button Styles */
.logger-btn:hover:not(:disabled) {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.logger-btn:active:not(:disabled) {
    background: #e5e7eb;
}

/* Parameter Selector Toggle Button */
#paramSelectorToggle:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

#paramSelectorToggle:active {
    background: #e5e7eb;
}

/* uPlot chart container needs position relative for legend positioning */
#trendChartContainer {
    position: relative;
    overflow: visible;
}

/* uPlot legend - show crosshair values inline at top of chart */
#trendChartContainer .u-legend.u-inline.u-live {
    position: absolute;
    top: 5px !important;
    left: 50%;
    transform: translateX(-50%);
    bottom: auto !important;
    z-index: 10;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 4px;
    padding: 4px 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    font-size: 0.75rem;
    white-space: nowrap;
    max-width: 95%;
    overflow-x: auto;
}

#trendChartContainer .u-legend {
    max-height: none;
    overflow-y: visible;
}

/* Style legend series markers */
#trendChartContainer .u-legend .u-series {
    display: inline-block;
    margin: 0 6px;
}

#trendChartContainer .u-legend .u-marker {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 3px;
}

#trendChartContainer .u-legend .u-value {
    font-weight: 500;
}

/* ========================================
   Portrait Mode (Mobile) - Floating Toggle Buttons
   ======================================== */
@media (max-width: 768px) and (orientation: portrait) {
    /* Hide the collapsed sidebar banners in portrait mode */
    .sidebar-card.collapsed,
    .right-sidebar-card.collapsed {
        display: none !important;
    }

    /* Show the floating toggle buttons container */
    .portrait-toggle-buttons {
        display: flex !important;
    }

    /* Chat section takes full height when sidebars collapsed */
    .chat-section {
        order: 1 !important;
        flex: 1;
        position: relative;
    }
}

/* Portrait mode floating toggle buttons */
.portrait-toggle-buttons {
    display: none;
    position: absolute;
    top: 50px; /* Below chat-header */
    left: 8px;
    right: 8px;
    z-index: 100;
    justify-content: space-between;
    pointer-events: none;
}

.portrait-toggle-btn {
    pointer-events: auto;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid rgba(34, 132, 121, 0.5);
    background: rgba(255, 255, 255, 0.7);
    color: #228479;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.portrait-toggle-btn:hover {
    background: rgba(34, 132, 121, 0.8);
    border-color: #228479;
}

.portrait-toggle-btn:hover img {
    filter: brightness(0) invert(1);
}

.portrait-toggle-btn:active {
    transform: scale(0.9);
    background: rgba(34, 132, 121, 0.9);
}

.portrait-toggle-btn img {
    width: 14px;
    height: 14px;
    opacity: 0.7;
}

/* When sidebar is expanded in portrait, hide the corresponding floating button */
@media (max-width: 768px) and (orientation: portrait) {
    .portrait-toggle-btn-left.hidden,
    .portrait-toggle-btn-right.hidden {
        opacity: 0;
        pointer-events: none;
    }
}

/* Markdown content styles for chat messages */
.markdown-content {
    line-height: 1.6;
}

.markdown-content p {
    margin: 0 0 0.75em 0;
}

.markdown-content p:last-child {
    margin-bottom: 0;
}

.markdown-content code {
    background: rgba(0, 0, 0, 0.06);
    padding: 0.15em 0.4em;
    border-radius: 4px;
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
}

.markdown-content pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 12px 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.75em 0;
}

.markdown-content pre code {
    background: none;
    padding: 0;
    font-size: 0.85em;
    color: inherit;
}

.markdown-content ul,
.markdown-content ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.markdown-content li {
    margin: 0.25em 0;
}

.markdown-content blockquote {
    border-left: 3px solid #228479;
    margin: 0.75em 0;
    padding-left: 1em;
    color: #4b5563;
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4 {
    margin: 1em 0 0.5em 0;
    font-weight: 600;
    line-height: 1.3;
}

.markdown-content h1:first-child,
.markdown-content h2:first-child,
.markdown-content h3:first-child {
    margin-top: 0;
}

.markdown-content table {
    border-collapse: collapse;
    margin: 0.75em 0;
    width: 100%;
}

.markdown-content th,
.markdown-content td {
    border: 1px solid #e5e7eb;
    padding: 8px 12px;
    text-align: left;
}

.markdown-content th {
    background: #f9fafb;
    font-weight: 600;
}

.markdown-content a {
    color: #228479;
    text-decoration: none;
}

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

/* KaTeX math styles */
.markdown-content .katex-display {
    margin: 0.75em 0;
    overflow-x: auto;
    overflow-y: hidden;
}

.markdown-content .katex {
    font-size: 1.1em;
}
