/* --- Main Layout --- */
body {
    background-color: #e2e8f0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    margin: 0;
    padding: 0;
}

/* Global typography improvements */
h1, h2, h3, h4, h5, h6 {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    font-weight: 600;
}

label, button, input, textarea, select {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
}

.chat-page-container {
    display: flex;
    height: calc(100vh - 40px);
    max-width: 1600px;
    margin: 20px auto;
    background-color: #1a2a40;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    min-height: 600px;
}

.panel-header {
    padding: 15px;
    border-bottom: 1px solid #4a5568;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.panel-toggle-btn {
    background: transparent;
    border: none;
    color: #a0b3c6;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: color 0.2s ease, background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.panel-toggle-btn:hover {
    color: #f97316;
    background-color: rgba(249, 115, 22, 0.1);
}

.panel-toggle-btn i {
    transition: transform 0.3s ease;
}

.connections-panel.collapsed .panel-toggle-btn i {
    transform: rotate(180deg);
}

.results-panel.collapsed .panel-toggle-btn i {
    transform: rotate(180deg);
}

.panel-header h3 {
    margin: 0;
    color: #f97316;
    font-size: 1.1em;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    font-weight: 600;
}

/* --- Connections Panel (Left) --- */
.connections-panel {
    flex: 0 0 260px;
    background-color: #2d3748;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #4a5568;
    transition: flex-basis 0.3s ease, min-width 0.3s ease;
    overflow: hidden;
    min-width: 260px;
}

.connections-panel.collapsed {
    flex: 0 0 50px;
    min-width: 50px;
}

.connections-panel.collapsed .connections-list,
.connections-panel.collapsed .add-connection-btn {
    display: none;
}

.connections-panel.collapsed .panel-header h3 {
    display: none;
}

.connections-list {
    list-style: none;
    padding: 0;
    margin: 0;
    overflow-y: auto;
    flex-grow: 1;
}

.connection-item {
    display: flex;
    align-items: flex-start;
    padding: 12px 15px;
    border-bottom: 1px solid #4a5568;
    cursor: pointer;
    transition: background-color 0.2s ease;
    min-height: 44px;
}

.connection-item:hover {
    background-color: #4a5568;
}

.connection-item input[type="checkbox"] {
    margin-right: 10px;
    cursor: pointer;
    margin-top: 2px;
    flex-shrink: 0;
}

.connection-item label {
    flex-grow: 1;
    display: flex;
    align-items: flex-start;
    cursor: pointer;
    min-width: 0;
    overflow: hidden;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 8px;
    background-color: #a0b3c6;
    flex-shrink: 0;
    margin-top: 6px;
}

.status-dot.active { background-color: #28a745; }
.status-dot.error { background-color: #ef4444; }

.connection-name {
    color: #e2e8f0;
    font-size: 0.95em;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    font-weight: 500;
    word-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
    line-height: 1.4;
    flex: 1;
    min-width: 0;
}

.settings-btn {
    background: none;
    border: none;
    color: #a0b3c6;
    cursor: pointer;
    padding: 5px;
    margin-left: 10px;
    flex-shrink: 0;
    align-self: flex-start;
    margin-top: -2px;
}

.settings-btn:hover { color: #e2e8f0; }

.add-connection-btn {
    display: block;
    width: calc(100% - 30px);
    margin: 15px;
    padding: 10px;
    background-color: #f97316;
    color: #0a192f;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    text-align: center;
}

.add-connection-btn i { margin-right: 5px; }

/* --- Chat Panel (Center) --- */
.chat-panel {
    flex-grow: 1;
    background-color: #1a2a40;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    min-width: 300px;
}

.connections-panel.collapsed ~ .chat-panel {
    margin-left: 0;
}

.chat-panel ~ .results-panel.collapsed {
    margin-right: 0;
}

.connections-panel.collapsed ~ .chat-panel {
    flex-grow: 1;
    max-width: none;
}

.results-panel.collapsed ~ .chat-panel {
    flex-grow: 1;
    max-width: none;
}

.connections-panel.collapsed ~ .chat-panel .chat-history {
    max-width: none;
}

.results-panel.collapsed ~ .chat-panel .chat-history {
    max-width: none;
}

.connections-panel.collapsed ~ .chat-panel ~ .results-panel.collapsed {
    margin-left: 0;
}

.connections-panel.collapsed ~ .chat-panel:has(~ .results-panel.collapsed) {
    flex-grow: 1;
    max-width: none;
    margin-left: 0;
    margin-right: 0;
}

@media (max-width: 1300px) {
    .connections-panel:not(.user-expanded) {
        flex: 0 0 50px;
    }
    .connections-panel:not(.user-expanded) .connections-list,
    .connections-panel:not(.user-expanded) .add-connection-btn,
    .connections-panel:not(.user-expanded) .panel-header h3 {
        display: none;
    }
}

@media (max-width: 1100px) {
    .results-panel:not(.user-expanded) {
        flex: 0 0 50px;
    }
    .results-panel:not(.user-expanded) .results-content,
    .results-panel:not(.user-expanded) .performance-panel,
    .results-panel:not(.user-expanded) .results-placeholder,
    .results-panel:not(.user-expanded) .panel-header h3 {
        display: none;
    }
}

.chat-history {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-width: 700px;
    transition: all 0.3s ease;
    min-height: 200px;
    max-height: calc(100vh - 300px);
}

.chat-history.collapsed {
    flex-grow: 0;
    min-height: 60px;
    max-height: 60px;
    overflow: hidden;
    padding: 10px 20px;
}

.chat-history.expanded {
    flex-grow: 1;
    min-height: 400px;
    max-height: calc(100vh - 200px);
}

.chat-panel .panel-toggle-btn.collapsed i {
    transform: rotate(180deg);
}

.chat-message {
    max-width: 75%;
    padding: 10px 15px;
    border-radius: 15px;
    font-size: 1.2em;
    line-height: 2;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    opacity: 0;
    transform: translateY(20px);
    animation: chatFadeIn 0.4s cubic-bezier(.4,0,.2,1) forwards;
}

@keyframes chatFadeIn {
    to {
        opacity: 1;
        transform: none;
    }
}

.chat-message.user {
    background-color: #8b5cf6;
    color: #fff;
    border-bottom-left-radius: 0;
    align-self: flex-start;
}

.chat-message.ai {
    background-color: #f97316;
    color: #0a192f;
    border-bottom-right-radius: 0;
    align-self: flex-end;
}

.chat-message p { margin: 0; }
.chat-message strong { font-weight: bold; }

/* Markdown styling for AI messages */
.chat-message.ai h1, .chat-message.ai h2, .chat-message.ai h3, 
.chat-message.ai h4, .chat-message.ai h5, .chat-message.ai h6 {
    margin: 0.5em 0 0.3em 0;
    font-weight: bold;
    color: inherit;
}

.chat-message.ai h1 { font-size: 1.2em; }
.chat-message.ai h2 { font-size: 1.1em; }
.chat-message.ai h3 { font-size: 1.05em; }
.chat-message.ai h4, .chat-message.ai h5, .chat-message.ai h6 { font-size: 1em; }

.chat-message.ai ul, .chat-message.ai ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.chat-message.ai li {
    margin: 0.2em 0;
}

.chat-message.ai code {
    background-color: rgba(0, 0, 0, 0.1);
    padding: 0.1em 0.3em;
    border-radius: 3px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', 'Source Code Pro', 'Menlo', 'Consolas', monospace;
    font-size: 0.9em;
    word-break: break-all;
}

.chat-message.ai pre {
    background-color: rgba(0, 0, 0, 0.1);
    padding: 0.8em;
    border-radius: 5px;
    overflow-x: auto;
    margin: 0.5em 0;
}

.chat-message.ai pre code {
    background: none;
    padding: 0;
}

.chat-message.ai blockquote {
    border-left: 3px solid rgba(0, 0, 0, 0.2);
    margin: 0.5em 0;
    padding-left: 1em;
    font-style: italic;
}

.chat-message.ai table {
    border-collapse: collapse;
    margin: 0.5em 0;
    width: 100%;
}

.chat-message.ai th, .chat-message.ai td {
    border: 1px solid rgba(0, 0, 0, 0.2);
    padding: 0.3em 0.6em;
    text-align: left;
}

.chat-message.ai th {
    background-color: rgba(0, 0, 0, 0.1);
    font-weight: bold;
}

.chat-message.loading p {
    display: flex; 
    gap: 4px;
}

.dot {
    width: 8px; 
    height: 8px; 
    border-radius: 50%; 
    background: #222; 
    animation: bounce 1s infinite alternate;
}

body.light-mode .dot {
    background:#f97316;
}

.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce { 
    to { 
        transform: translateY(-8px); 
        opacity: 0.5; 
    } 
}

.chat-message.ai.streaming::after {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #222;
    margin-left: 4px;
    animation: blink 1s infinite;
}

body.light-mode .chat-message.ai.streaming::after {
    background: #f97316;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.query-suggestions {
    padding: 5px 15px;
    border-top: 1px solid #4a5568;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.query-suggestions button {
    background-color: #2d3748;
    color: #a0b3c6;
    border: 1px solid #4a5568;
    padding: 5px 10px;
    font-size: 0.8em;
    border-radius: 15px;
    cursor: pointer;
}

.query-suggestions button:hover { 
    background-color: #4a5568; 
    color: #e2e8f0;
}

.chat-input-area {
    display: flex;
    padding: 15px;
    border-top: 1px solid #4a5568;
    background-color: #2d3748;
}

.chat-input-area textarea {
    flex-grow: 1;
    background: none;
    border: none;
    color: #e2e8f0;
    resize: none;
    height: 40px;
    max-height: 100px;
    padding: 10px;
    font-size: 1em;
    outline: none;
}

.chat-input-area textarea::placeholder { 
    color: #a0b3c6; 
}

#send-chat-btn {
    background: none;
    border: none;
    color: #f97316;
    font-size: 1.5em;
    padding: 5px 10px;
    cursor: pointer;
    margin-left: 10px;
}

#send-chat-btn:hover { 
    color: #ea580c; 
}

/* --- Results Panel (Right) --- */
.results-panel {
    flex: 0 0 450px;
    background-color: #2d3748;
    display: flex;
    flex-direction: column;
    border-left: 1px solid #4a5568;
    transition: flex-basis 0.3s ease, min-width 0.3s ease;
    overflow: hidden;
    min-width: 400px;
    max-width: 600px;
}

.results-panel.collapsed {
    flex: 0 0 50px;
    min-width: 50px;
}

.results-panel.collapsed .results-content,
.results-panel.collapsed .performance-panel,
.results-panel.collapsed .results-placeholder {
    display: none;
}

.results-panel.collapsed .panel-header h3 {
    display: none;
}

.close-results-btn {
    background: none; 
    border: none; 
    color: #a0b3c6; 
    cursor: pointer; 
    padding: 5px;
}

.close-results-btn:hover { 
    color: #e2e8f0; 
}

.results-content {
    flex-grow: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    color:#d8d8d8;
}

.result-section h4 {
    color: #d8d8d8;
    font-size: 0.9em;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.result-section p { 
    font-size: 0.9em; 
    margin: 0 0 5px 0; 
}

.result-section pre {
    background-color: #1a2a40;
    color:#d8dadd;
    padding: 10px;
    border-radius: 4px;
    overflow-x: auto;
    font-size: 0.85em;
    max-height: 150px;
}

.result-section code { 
    color: #e2e8f0; 
}

.result-section.collapsible h4 { 
    cursor: pointer;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    font-weight: 600;
    user-select: none;
    transition: color 0.2s;
}

.result-section.collapsible h4:hover {
    color: #f97316;
}

.result-section.collapsible h4 i { 
    margin-left: 5px; 
    transition: transform 0.2s ease; 
}

.result-section.collapsible.collapsed pre { 
    display: none; 
}

.result-section.collapsible.collapsed h4 i { 
    transform: rotate(-90deg); 
}

.table-container {
    max-height: 350px;
    overflow: auto;
    border: 1px solid #4a5568;
    border-radius: 6px;
    color: #e2e8f0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    background-color: #1a2a40;
}

.table-container table { 
    width: 100%; 
    border-collapse: collapse; 
}

.table-container th, .table-container td { 
    padding: 8px; 
    border: 1px solid #4a5568; 
    text-align: left; 
    font-size: 0.85em; 
}

.table-container th { 
    background-color: #4a5568;
    cursor: pointer;
    user-select: none;
}

.table-container th.sorted-asc::after { content: " ▲"; }
.table-container th.sorted-desc::after { content: " ▼"; }

.chart-container {
    position: relative;
    height: 300px;
    min-height: 250px;
    width: 100%;
    background-color: #1a2a40;
    border-radius: 6px;
    border: 1px solid #4a5568;
    overflow: hidden;
}

#d3-chart-container {
    width: 100%;
    height: 100%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

#d3-chart-container svg {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
}

.d3-tooltip {
    position: absolute;
    text-align: center;
    padding: 8px;
    font-size: 12px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    border-radius: 4px;
    pointer-events: none;
    z-index: 1000;
}

.bar:hover {
    fill: orange;
}

.axis text {
    font-size: 12px;
}

.axis path,
.axis line {
    fill: none;
    stroke: #000;
    shape-rendering: crispEdges;
}

#expand-chart-btn {
    position: absolute; 
    top: 10px; 
    right: 10px;
    background: #2d3748; 
    color: #f97316; 
    border: none; 
    border-radius: 4px; 
    cursor: pointer;
    z-index: 2;
    padding: 8px;
    transition: background-color 0.2s ease;
}

#expand-chart-btn:hover {
    background: #4a5568;
    color: #ea580c;
}

.result-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
    padding-top: 15px;
    border-top: 1px solid #4a5568;
}

.result-actions button {
    background-color: #4a5568;
    color: #e2e8f0;
    padding: 8px 12px;
    font-size: 0.9em;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.result-actions button:hover { 
    background-color: #5a6578; 
}

.result-actions button i { 
    margin-right: 5px; 
}

.results-placeholder {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #a0b3c6;
    text-align: center;
    padding: 20px;
}

.results-panel:has(.results-content:not(:empty)) .results-placeholder {
    display: none;
}

.results-panel:has(#connection-status:not(.hidden)) .results-placeholder {
     display: none;
}

/* --- Performance Panel --- */
.toggle-performance-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: calc(100% - 30px);
    margin: 15px 15px 5px 15px;
    padding: 8px 15px;
    background-color: #4a5568;
    color: #e2e8f0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background-color 0.3s ease;
}

.toggle-performance-btn:hover {
    background-color: #5a6578;
}

.toggle-performance-btn span {
    flex-grow: 1;
    text-align: center;
}

.toggle-performance-btn i {
    transition: transform 0.3s ease;
}

.toggle-performance-btn.expanded i {
    transform: rotate(180deg);
}

.performance-panel {
    background-color: #2d3748;
    border-top: 2px solid #4a5568;
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.5s ease-out, padding 0.5s ease-out;
    padding: 0 15px;
    flex-shrink: 0;
}

.performance-panel.expanded {
    max-height: 500px;
    padding: 15px 15px;
}

.performance-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #4a5568;
    gap: 15px;
}

.integration-info {
    display: flex;
    flex-direction: column;
    font-size: 0.9em;
}

#perf-integration-name {
    font-weight: bold;
    color: #e2e8f0;
    font-size: 1.1em;
    margin-bottom: 3px;
}

#perf-next-runtime {
    color: #a0b3c6;
}

.status-badge {
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.8em;
    font-weight: bold;
    text-transform: uppercase;
}

.status-badge.active { background-color: #16a34a; color: #fff; }
.status-badge.paused { background-color: #d97706; color: #fff; }
.status-badge.error { background-color: #dc2626; color: #fff; }

.integration-controls button {
    background: none;
    border: 1px solid #4a5568;
    color: #a0b3c6;
    padding: 5px 8px;
    border-radius: 4px;
    cursor: pointer;
    margin-left: 5px;
}

.integration-controls button:hover {
    background-color: #4a5568;
    color: #e2e8f0;
}

.integration-controls button i { 
    font-size: 0.9em; 
}

.performance-chart-area h4 {
    color: #a0b3c6;
    font-size: 0.9em;
    margin-bottom: 8px;
    text-transform: uppercase;
}

.performance-chart-container {
    height: 200px;
    position: relative;
}

.settings-usage-area {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #4a5568;
}

.settings-section, .usage-section {
    flex: 1;
}

.settings-section h4, .usage-section h4 {
    color: #a0b3c6;
    font-size: 0.9em;
    margin-top: 0;
    margin-bottom: 10px;
    text-transform: uppercase;
}

.settings-section button {
    display: block;
    width: 100%;
    margin-bottom: 8px;
    background-color: #4a5568;
    color: #e2e8f0;
    padding: 8px 12px;
    font-size: 0.9em;
    border: none;
    border-radius: 4px;
    text-align: left;
    cursor: pointer;
}

.settings-section button:hover { 
    background-color: #5a6578; 
}

.usage-section p {
    font-size: 0.9em;
    color: #a0b3c6;
    margin: 0;
}

.usage-section p span {
    font-weight: bold;
    font-size: 1.2em;
    color: #e2e8f0;
}

/* --- Utility --- */
.hidden { 
    display: none !important; 
}

/* --- Toast --- */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: #f97316;
    color: #fff;
    padding: 16px 32px;
    border-radius: 8px;
    font-size: 1.1em;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s;
    z-index: 9999;
}

.toast.show {
    opacity: 1;
    pointer-events: auto;
}

/* --- Button Effects --- */
.button-group button:active,
.result-actions button:active,
.add-connection-btn:active {
    transform: scale(0.97);
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

input:focus, textarea:focus, select:focus {
    outline: 2px solid #f97316;
    outline-offset: 2px;
}

/* --- Light Mode --- */
body.light-mode {
    background: #7c94a4;
    color: #222;
}

body.light-mode .chat-page-container,
body.light-mode .results-panel,
body.light-mode .chat-input-area,
body.light-mode .chat-input textarea,
body.light-mode .results-section,
body.light-mode .connections-panel {
    background: #d2dfe8;
    color: #222;
}

body.light-mode .chat-message.ai {
    color: white;
    background: #222;
}

body.light-mode .chat-panel{
    background: #fff;
    color: #222;
}

body.light-mode .connection-name {
    color: #222;
}

body.light-mode .results-content,
body.light-mode .results-section,
body.light-mode .results-section h4,
body.light-mode .results-panel{
    color:#222;
}

body.light-mode .table-container{
    color:#222;
}

/* --- Modal Base Styles --- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background-color: #2d3748;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    animation: modalSlideIn 0.3s ease-out;
    position: relative;
    margin: 20px;
}

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

.connection-settings-content {
    max-width: 600px;
    width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px 16px;
    border-bottom: 1px solid #4a5568;
}

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

.close-modal-btn {
    background: transparent;
    border: none;
    color: #a0b3c6;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    font-size: 1.1rem;
    transition: all 0.2s ease;
}

.close-modal-btn:hover {
    background-color: #4a5568;
    color: #e2e8f0;
}

.modal-body {
    padding: 24px;
}

/* --- Modal Tabs --- */
.modal-tabs {
    display: flex;
    border-bottom: 1px solid #4a5568;
    margin-bottom: 24px;
}

.tab-btn {
    background: transparent;
    border: none;
    color: #a0b3c6;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
}

.tab-btn.active {
    color: #e2e8f0;
    border-bottom-color: #3b82f6;
}

.tab-btn:hover {
    color: #e2e8f0;
}

.tab-btn:disabled {
    color: #4a5568;
    cursor: not-allowed;
}

.tab-content {
    display: none;
}

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

/* --- Form Styles --- */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    color: #e2e8f0;
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    background-color: #2d3748;
    border: 1px solid #4a5568;
    border-radius: 6px;
    color: #e2e8f0;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

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

.form-group input:disabled,
.form-group select:disabled {
    background-color: #1a202c;
    color: #a0b3c6;
    cursor: not-allowed;
}

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

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 32px;
    padding-top: 20px;
    border-top: 1px solid #4a5568;
}

.btn {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background-color: #3b82f6;
    color: white;
}

.btn-primary:hover {
    background-color: #2563eb;
}

.btn-secondary {
    background-color: #4a5568;
    color: #e2e8f0;
}

.btn-secondary:hover {
    background-color: #5a6578;
}

.connection-field-group {
    background-color: #1a202c;
    padding: 16px;
    border-radius: 6px;
    margin-bottom: 20px;
    border: 1px solid #4a5568;
}

.connection-field-group h4 {
    margin: 0 0 16px 0;
    color: #e2e8f0;
    font-size: 1rem;
    font-weight: 600;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

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

/* --- Schema Analysis Styles --- */
.schema-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    text-align: center;
}

.loading-animation {
    margin-bottom: 16px;
}

.loading-animation svg {
    animation: spin 2s linear infinite;
}

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

.schema-results {
    padding: 20px 0;
}

.schema-summary {
    margin-bottom: 20px;
}

.schema-summary h4 {
    color: #e2e8f0;
    margin-bottom: 8px;
}

.schema-summary p {
    color: #a0b3c6;
    margin: 0;
}

.schema-tables {
    margin-bottom: 20px;
}

.schema-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.schema-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    text-align: center;
}

.error-icon {
    font-size: 2rem;
    color: #ef4444;
    margin-bottom: 16px;
}

.schema-error p {
    color: #a0b3c6;
    margin-bottom: 20px;
}

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

.empty-state h4 {
    color: #e2e8f0;
    margin: 16px 0 8px 0;
}

.empty-state p {
    margin-bottom: 24px;
}

/* --- Theme Toggle --- */
#theme-toggle {
    background: transparent;
    border: none;
    color: #a0b3c6;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: color 0.2s ease, background-color 0.2s ease;
}

#theme-toggle:hover {
    color: #f97316;
    background-color: rgba(249, 115, 22, 0.1);
}

/* --- Account Button --- */
#account-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background-color: #4a5568;
    color: #e2e8f0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s ease;
}

#account-btn:hover {
    background-color: #5a6578;
}

#sign-in-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background-color: #3b82f6;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s ease;
}

#sign-in-btn:hover {
    background-color: #2563eb;
}

/* --- Responsive Design --- */
@media (max-width: 1400px) {
    .chat-page-container {
        max-width: 100vw;
        margin: 10px;
        height: calc(100vh - 20px);
    }
    .results-panel {
        flex: 0 0 400px;
        min-width: 350px;
    }
    .connections-panel {
        flex: 0 0 240px;
        min-width: 240px;
    }
}

@media (max-width: 1200px) {
    .chat-page-container {
        margin: 5px;
        height: calc(100vh - 10px);
    }
    .results-panel {
        flex: 0 0 350px;
        min-width: 320px;
    }
    .connections-panel {
        flex: 0 0 220px;
        min-width: 220px;
    }
    .chart-container {
        height: 250px;
        min-height: 200px;
    }
    .table-container {
        max-height: 300px;
    }
}

@media (max-width: 1000px) {
    .chat-page-container {
        flex-direction: column;
        max-width: 100vw;
        height: auto;
        min-height: 100vh;
    }
    .connections-panel {
        flex: 0 0 200px;
        max-width: 100vw;
        border-right: none;
        border-bottom: 1px solid #4a5568;
        min-width: 0;
        order: 1;
    }
    .results-panel {
        flex: 0 0 400px;
        max-width: 100vw;
        border-left: none;
        border-top: 1px solid #4a5568;
        min-width: 0;
        order: 3;
    }
    .chat-panel {
        min-width: 0;
        flex: 1;
        order: 2;
    }
}

@media (max-width: 768px) {
    .chat-page-container {
        margin: 0;
        border-radius: 0;
        height: 100vh;
    }
    .connections-panel {
        flex: 0 0 150px;
    }
    .results-panel {
        flex: 0 0 350px;
    }
    .chart-container {
        height: 200px;
        min-height: 180px;
    }
    .table-container {
        max-height: 250px;
        font-size: 0.85em;
    }
    .result-section {
        padding: 10px;
    }
    .results-content {
        padding: 10px;
    }
    .field-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .connection-settings-content {
        width: 95vw;
        margin: 20px auto;
    }
    .form-actions {
        flex-direction: column;
    }
    .btn {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 600px) {
    .connections-panel {
        flex: 0 0 120px;
    }
    .results-panel {
        flex: 0 0 300px;
    }
    .panel-header {
        padding: 10px;
    }
    .panel-header h3 {
        font-size: 1em;
    }
    .chart-container {
        height: 180px;
        min-height: 150px;
    }
    .table-container {
        max-height: 200px;
        font-size: 0.8em;
    }
    .table-container th, .table-container td {
        padding: 6px;
    }
}

/* --- Light Mode Modal Support --- */
body.light-mode .modal-header {
    border-bottom: 1px solid #e2e8f0;
}

body.light-mode .modal-header h3,
body.light-mode .form-group label {
    color: #1a202c;
}

body.light-mode .close-modal-btn {
    color: #4a5568;
}

body.light-mode .close-modal-btn:hover {
    background-color: #e2e8f0;
    color: #1a202c;
}

body.light-mode .form-group input,
body.light-mode .form-group textarea,
body.light-mode .form-group select {
    background-color: white;
    border: 1px solid #d1d5db;
    color: #1a202c;
}

body.light-mode .form-group input:disabled,
body.light-mode .form-group select:disabled {
    background-color: #f3f4f6;
    color: #6b7280;
}

body.light-mode .connection-field-group {
    background-color: #f9fafb;
    border: 1px solid #e5e7eb;
}

body.light-mode .connection-field-group h4 {
    color: #1a202c;
}

body.light-mode .form-actions {
    border-top: 1px solid #e2e8f0;
}

body.light-mode .modal-content {
    background-color: white;
}

/* --- CSS Variables for Theme Support --- */
:root {
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #0b1220;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --muted-text: #a0b3c6;
  --border: #1f2937;
  --accent: #22d3ee;
  --accent-strong: #06b6d4;
  --danger: #ef4444;
  --success: #22c55e;
  --shadow: rgba(0, 0, 0, 0.3);
}

body[data-theme="light"] {
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-2: #f1f5f9;
  --text: #0f172a;
  --muted: #475569;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --shadow: rgba(0,0,0,0.08);
}

/* --- Enhanced Collapsible SQL Section --- */
#generated-sql h4 { 
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
    gap: 8px; 
    cursor: pointer;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    font-weight: 600;
}

#generated-sql h4 .icon-btn {
  border: none; 
  background: transparent; 
  color: var(--muted); 
  cursor: pointer;
  padding: 4px 6px; 
  border-radius: 6px; 
  transition: background 140ms ease, color 140ms ease, transform 80ms ease;
}

#generated-sql h4 .icon-btn:hover, 
#generated-sql h4 .icon-btn:focus {
  color: var(--text); 
  background: var(--border); 
  outline: 2px solid transparent;
}

#generated-sql h4 .icon-btn:active { 
    transform: scale(0.96); 
}

#generated-sql pre {
  background: #0b1020;
  color: #e6edf3;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  overflow: auto;
  font-size: 0.9rem;
  line-height: 1.5;
}

body[data-theme="light"] #generated-sql pre {
  background: #f6f8fa;
  color: #111827;
}

.result-section.collapsible pre {
  transition: max-height 200ms ease;
}

.result-section.collapsible.collapsed pre {
  max-height: 0; 
  padding-top: 0; 
  padding-bottom: 0; 
  border-width: 0; 
  overflow: hidden;
}

/* --- Enhanced Button Focus --- */
button, .icon-btn {
  transition: background 150ms ease, color 150ms ease, box-shadow 150ms ease, transform 80ms ease;
}

button:focus-visible, .icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Enhanced Toast --- */
.toast {
  background: rgba(17, 24, 39, 0.98);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: 0 8px 18px var(--shadow);
}

body[data-theme="light"] .toast { 
    background: rgba(255, 255, 255, 0.98); 
    color: #111827; 
}

/* --- Accent Elements --- */
a, .accent { 
    color: var(--accent); 
}

a:hover, .accent:hover { 
    color: var(--accent-strong); 
}

/* --- Chart and Table Enhancements --- */
.chart-container, .table-container { 
    border-radius: 8px; 
}

/* --- Login Modal Specific --- */
#login-modal .modal-content {
  max-width: 480px;
}