:root {
  --bg-main: #0b0f17;
  --bg-sidebar: #111726;
  --bg-card: #182234;
  --bg-bubble-user: #2563eb;
  --bg-bubble-assistant: #192438;
  --border-color: #24324a;
  --border-subtle: #1c273a;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-primary: #3b82f6;
  --accent-hover: #1d4ed8;
  --accent-green: #10b981;
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

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

body, html {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-primary);
  overflow: hidden;
}

/* App Layout */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

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

.logo-icon {
  font-size: 20px;
}

.logo-text {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.3px;
  color: #fff;
}

.btn-new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 9px 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-new-chat:hover {
  background: #1e2d45;
  border-color: var(--accent-primary);
}

.sidebar-section {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.section-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.company-dropdown {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  outline: none;
}

/* Staging Dashboards list */
.staging-section {
  flex: 1;
  overflow-y: auto;
  min-height: 120px;
  border-bottom: 1px solid var(--border-subtle);
}

.dashboards-list, .chat-history-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.saved-section {
  max-height: 160px;
  overflow-y: auto;
  border-bottom: 1px solid var(--border-subtle);
}

.dashboard-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: var(--radius-sm);
  padding: 2px 4px;
  transition: background 0.15s ease;
}

.dashboard-row:hover {
  background: var(--bg-card);
}

.dashboard-row.active {
  background: #1e2d45;
}

.dashboard-link {
  flex: 1;
  padding: 6px 4px;
  font-size: 12px;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dashboard-row:hover .dashboard-link {
  color: var(--text-primary);
}

.dash-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.dash-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dash-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.dash-btn.delete-btn:hover {
  color: var(--accent-red);
  background: rgba(239, 68, 68, 0.15);
}

.dash-btn.save-btn.saved {
  color: var(--accent-amber);
}

.sql-details {
  margin-top: 12px;
  background: #090d16;
  border: 1px solid #1e293b;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 12px;
}

.sql-summary {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sql-summary:hover {
  color: var(--accent-primary);
}

.sql-details[open] .sql-summary {
  margin-bottom: 8px;
  color: var(--accent-primary);
}

.btn-save-toggle {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-save-toggle:hover {
  background: #1e2d45;
  color: var(--accent-amber);
}

.btn-save-toggle.is-saved {
  background: rgba(245, 158, 11, 0.15);
  border-color: var(--accent-amber);
  color: var(--accent-amber);
}

.empty-state {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  padding: 6px 0;
}

.chats-section {
  flex: 1;
  overflow-y: auto;
  border-bottom: 1px solid var(--border-subtle);
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #0d121c;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-primary), #8b5cf6);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}

.user-details {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.user-company-badge {
  font-size: 11px;
  color: var(--accent-primary);
}

.btn-logout {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
}

.btn-logout:hover {
  color: var(--accent-red);
  background: rgba(239, 68, 68, 0.1);
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Top Nav */
.top-nav {
  height: 52px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-sidebar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.active-tenant-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
}

.tenant-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent-green);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.4);
}

.tenant-name {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Model Selector Button/Dropdown */
.model-selector-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  padding: 4px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.model-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.model-dropdown {
  background: transparent;
  color: #fff;
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
}

.model-dropdown option {
  background: var(--bg-sidebar);
  color: var(--text-primary);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.btn-secondary:hover {
  background: #1e2d45;
}

/* Workspace Split Container */
.workspace-split-container {
  flex: 1;
  display: flex;
  min-height: 0;
}

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Message Rows */
.message-row {
  display: flex;
  gap: 14px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}

.message-row.user-row {
  flex-direction: row-reverse;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.user-row .avatar {
  background: var(--bg-bubble-user);
  color: #fff;
}

.assistant-row .avatar {
  background: #1e293b;
  border: 1px solid var(--border-color);
  color: var(--accent-primary);
}

.bubble {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.6;
  position: relative;
}

.user-row .bubble {
  background: var(--bg-bubble-user);
  color: #fff;
  border-bottom-right-radius: 2px;
}

.assistant-row .bubble {
  background: var(--bg-bubble-assistant);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 2px;
}

.welcome-message .bubble {
  background: #111a2a;
  border-color: #233550;
  max-width: 100%;
}

.welcome-message h3 {
  margin-bottom: 6px;
  font-size: 16px;
  color: #fff;
}

.quick-prompts-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.quick-prompt-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.quick-prompt-btn:hover {
  background: #1e2d45;
  color: #fff;
  border-color: var(--accent-primary);
}

/* SQL Block Formatting */
pre {
  background: #090d16;
  border: 1px solid #1e293b;
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow-x: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  margin: 10px 0;
  color: #38bdf8;
}

code {
  font-family: 'JetBrains Mono', monospace;
}

/* Staging action card in message */
.staging-card-box {
  margin-top: 12px;
  padding: 12px 14px;
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.staging-card-box .title {
  font-weight: 600;
  font-size: 13px;
  color: #34d399;
}

.btn-view-staging {
  background: var(--accent-green);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.btn-view-staging:hover {
  background: #059669;
}

/* Chat Input Bar */
.chat-input-wrapper {
  padding: 12px 32px 20px 32px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}

.chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 8px 14px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}

.chat-form:focus-within {
  border-color: var(--accent-primary);
}

.chat-form textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
}

.btn-send {
  background: var(--accent-primary);
  color: #fff;
  border: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-send:hover {
  background: var(--accent-hover);
}

.chat-disclaimer {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Dashboard Panel (Split-View) */
.dashboard-panel {
  flex: 1.1;
  background: var(--bg-main);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.dashboard-panel-header {
  height: 52px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

.dashboard-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-badge {
  background: var(--accent-green);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
}

.dashboard-panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn, .icon-link-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover, .icon-link-btn:hover {
  background: var(--bg-card);
  color: #fff;
}

.dashboard-iframe-wrapper {
  flex: 1;
  width: 100%;
  height: 100%;
  background: #fff;
}

.dashboard-iframe-wrapper iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* Login Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.login-card {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

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

.brand-badge {
  display: inline-block;
  background: #1e293b;
  color: var(--accent-primary);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 12px;
  margin-bottom: 12px;
}

.login-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 6px;
}

.login-header p {
  font-size: 13px;
  color: var(--text-secondary);
}

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

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: #fff;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  outline: none;
}

.form-group input:focus {
  border-color: var(--accent-primary);
}

.login-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid var(--accent-red);
  color: var(--accent-red);
  font-size: 12px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
}

.login-btn {
  width: 100%;
  background: var(--accent-primary);
  color: #fff;
  border: none;
  padding: 11px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.login-btn:hover {
  background: var(--accent-hover);
}

.hidden {
  display: none !important;
}

/* Typing Indicator Animation */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 2px;
}

.typing-dot {
  width: 7px;
  height: 7px;
  background: var(--accent-primary);
  border-radius: 50%;
  animation: typingPulse 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0s; }

@keyframes typingPulse {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.35; }
  40% { transform: scale(1.15); opacity: 1; }
}

.typing-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-left: 8px;
  font-style: italic;
}

/* Message Actions & Copy */
.message-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.copy-msg-btn {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.copy-msg-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border-color: var(--accent-primary);
}

.copy-msg-btn.copied {
  color: var(--accent-green);
  border-color: var(--accent-green);
}

/* Enhanced SQL inspector badge */
.sql-header-badge {
  background: #1e293b;
  color: #38bdf8;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  margin-left: auto;
  border: 1px solid #334155;
}

.copy-sql-btn {
  background: #1e293b;
  border: 1px solid #334155;
  color: var(--text-secondary);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  margin-left: 8px;
}

.copy-sql-btn:hover {
  background: #334155;
  color: #fff;
}
