/* ============================================
   HELDA V1.0.0 — Global Styles
   ============================================ */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* --- Reset & Base --- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-body: #0A0A0C;
  --bg-card: #131316;
  --bg-card-dark: #18181C;
  --bg-input: #1A1A1E;
  --bg-hover: #1C1C20;
  --border: #28282D;
  --border-hover: #3A3A40;
  --text-primary: #F4F4F5;
  --text-secondary: #D4D4D8;
  --text-muted: #888890;
  --text-dim: #52525B;
  --accent: #F97316;
  --accent-to: #EAB308;
  --accent-gradient: linear-gradient(to right, var(--accent), var(--accent-to));
  --accent-10: rgba(249, 115, 22, 0.1);
  --accent-20: rgba(249, 115, 22, 0.2);
  --white: #FFFFFF;
  --black: #000000;
  --red-400: #f87171;
  --red-500: #ef4444;
  --amber-400: #fbbf24;
  --amber-500: #f59e0b;
  --emerald-400: #34d399;
  --emerald-500: #10b981;
  --radius-sm: 0.125rem;
  --radius-md: 0.25rem;
  --radius-lg: 0.25rem;
  --radius-xl: 0.375rem;
  --radius-2xl: 0.375rem;
  --radius-full: 0.25rem;
  --bg-pipeline: #0E0E11;
  --bg-pipeline-dot: var(--border);
}

:root.theme-light {
  --bg-body: #F4F4F5;
  --bg-card: #FFFFFF;
  --bg-card-dark: #F9FAFB;
  --bg-input: #FFFFFF;
  --bg-hover: #F3F4F6;
  --border: #E5E7EB;
  --border-hover: #D1D5DB;
  --text-primary: #18181B;
  --text-secondary: #3F3F46;
  --text-muted: #71717A;
  --text-dim: #A1A1AA;
  --white: #18181B;
  --black: #FFFFFF;
  --bg-pipeline: #F4F4F5;
  --bg-pipeline-dot: #E5E7EB;
}

html,
body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  overflow: hidden;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #3F3F46;
}

/* --- Layout --- */
.app-shell {
  display: flex;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

/* --- Sidebar --- */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  height: 100%;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 1rem 0.75rem;
  z-index: 10;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-xl);
  cursor: pointer;
  margin-bottom: 1rem;
  transition: background 0.2s;
}

.sidebar-brand:hover {
  background: var(--bg-hover);
}

.sidebar-brand-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sidebar-brand-logo {
  width: 28px;
  height: 28px;
  background: var(--white);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--black);
}

.sidebar-brand-name {
  color: var(--white);
  font-weight: 500;
}

.sidebar-section-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-dim);
  padding: 0 0.75rem;
  margin-bottom: 0.5rem;
  margin-top: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
}

/* --- Sidebar Item --- */
.sidebar-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  color: var(--text-muted);
}

.sidebar-item:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.sidebar-item.active {
  background: var(--bg-hover);
  color: var(--white);
}

.sidebar-item-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sidebar-item-label {
  font-size: 0.875rem;
  font-weight: 500;
}

.sidebar-item.highlight .sidebar-item-icon,
.sidebar-item.highlight .sidebar-item-label {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  color: var(--accent);
}

.sidebar-item.active.highlight .sidebar-item-label {
  color: var(--white);
}

.sidebar-item-shortcut {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-muted);
}

/* --- Main Content --- */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 2.5rem 2rem;
  position: relative;
}

/* --- View Header --- */
.view-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
  font-weight: 500;
}

.view-breadcrumb .accent {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  color: var(--accent);
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 2rem;
}

.view-title {
  font-size: 1.875rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
}

.view-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* --- Cards --- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  padding: 1.25rem;
  transition: border-color 0.2s;
}

.card:hover {
  border-color: var(--border-hover);
}

.card-dark {
  background: var(--bg-card-dark);
}

/* --- Metric Card --- */
.metric-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  cursor: help;
}

.metric-label {
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.metric-value {
  font-size: 2rem;
  font-weight: 600;
  color: var(--white);
  line-height: 1;
}

.metric-icon {
  width: 56px;
  height: 56px;
  background: var(--bg-card-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
}

/* --- Grid Layouts --- */
.grid-1 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
}

@media (max-width: 1024px) {
  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {

  .grid-3,
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1rem;
  border-radius: var(--radius-xl);
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, opacity 0.2s;
  font-family: inherit;
}

.btn-primary {
  background: var(--white);
  color: var(--black);
}

.btn-primary:hover {
  background: #E4E4E7;
}

.btn-secondary {
  background: var(--bg-hover);
  color: var(--white);
  border: 1px solid var(--border-hover);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-accent {
  background: var(--accent-gradient);
  color: var(--black);
  font-weight: 600;
  border: none;
}

.btn-accent:hover {
  filter: brightness(1.1);
}

.btn-success {
  background: rgba(16, 185, 129, 0.1);
  color: var(--emerald-400);
  border: 1px solid rgba(16, 185, 129, 0.2);
  cursor: default;
}

.btn-disabled {
  background: var(--border);
  color: var(--text-muted);
  pointer-events: none;
}

.btn-full {
  width: 100%;
}

/* --- Chart Container --- */
.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  padding: 1.5rem;
  height: 320px;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.chart-container h3 {
  color: var(--white);
  font-weight: 500;
  z-index: 10;
}

.chart-y-axis {
  position: absolute;
  inset: 0;
  padding: 4rem 1.5rem 2rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  z-index: 0;
  pointer-events: none;
}

.chart-y-label {
  display: flex;
  align-items: center;
  width: 100%;
}

.chart-y-label span {
  font-size: 0.75rem;
  color: var(--text-dim);
  width: 2rem;
}

.chart-y-label .line {
  flex: 1;
  border-top: 1px solid var(--border);
  margin-left: 0.5rem;
}

.chart-svg-area {
  position: absolute;
  inset: 0;
  padding: 4rem 1.5rem 3rem 3.5rem;
  z-index: 10;
  pointer-events: none;
  display: flex;
  align-items: flex-end;
}

/* --- AI Engine Redesign --- */
.ai-engine-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  margin: -2.5rem -2rem;
  /* Overrides .main-content padding */
  background: var(--bg-body);
}

.ai-top-bar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 1rem 2rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.ai-top-bar-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--white);
  font-weight: 500;
  font-size: 0.875rem;
}

.ai-top-bar-items {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.ai-top-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-body);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 0.375rem 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}

.ai-top-item:hover {
  background: var(--bg-hover);
  color: var(--white);
}

.ai-top-item.selected {
  background: rgba(249, 115, 22, 0.1);
  border-color: var(--accent);
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  color: var(--accent);
}

.ai-top-bar-dates {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: fadeIn 0.3s ease;
}

.ai-top-date {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  color: var(--white);
  color-scheme: dark;
  outline: none;
}

.ai-top-date:focus {
  border-color: var(--accent);
}

.ai-chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  max-width: 48rem;
  margin: 0 auto;
  width: 100%;
}

.ai-chat-intro {
  text-align: center;
  padding: 4rem 0 2rem;
}

.ai-intro-icon {
  width: 64px;
  height: 64px;
  border-radius: 4px;
  background: var(--bg-hover);
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.5rem;
}

.ai-chat-intro h2 {
  color: var(--white);
  font-size: 1.5rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.ai-chat-intro p {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.ai-msg-row {
  display: flex;
}

.ai-msg-row.user {
  justify-content: flex-end;
}

.ai-msg-row.ai,
.ai-msg-row.system {
  justify-content: flex-start;
}

.ai-msg-bubble {
  max-width: 85%;
  border-radius: var(--radius-2xl);
  padding: 1rem 1.25rem;
  font-size: 0.95rem;
  line-height: 1.6;
}

.ai-msg-bubble.user-bubble {
  background: var(--white);
  color: var(--black);
  border-top-right-radius: 4px;
}

.ai-msg-bubble.ai-bubble {
  background: transparent;
  color: var(--text-secondary);
}

.ai-msg-bubble.system-bubble {
  background: transparent;
  color: var(--text-dim);
  width: 100%;
  text-align: center;
  font-size: 0.75rem;
  font-family: monospace;
}

.ai-msg-icon {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  color: var(--accent);
  display: inline-block;
  margin-right: 0.75rem;
  vertical-align: top;
  margin-top: 0.25rem;
}

.ai-chat-input-area {
  padding: 1.5rem 2rem 2rem;
  max-width: 52rem;
  margin: 0 auto;
  width: 100%;
  background: transparent;
}

.ai-chat-input-area.border-none {
  border-top: none;
}

.ai-quick-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  justify-content: center;
}

.ai-quick-btn {
  font-size: 0.75rem;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s;
}

.ai-quick-btn:hover {
  color: var(--white);
  border-color: var(--border-hover);
}

.ai-input-wrap {
  position: relative;
}

.ai-input-wrap input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  padding: 1.25rem 4rem 1.25rem 1.5rem;
  color: var(--white);
  font-size: 1rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  transition: all 0.2s;
}

.ai-input-wrap input:focus {
  border-color: var(--accent-20);
  box-shadow: 0 4px 20px rgba(249, 115, 22, 0.1);
}

.ai-send-btn {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-lg);
  background: var(--white);
  color: var(--black);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.ai-send-btn:hover {
  background: #E4E4E7;
}

/* --- AI Top Bar Right / Model Badge --- */
.ai-top-bar {
  flex-wrap: wrap;
}

.ai-top-bar-right {
  margin-left: auto;
}

.ai-model-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-body);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 0.375rem 0.875rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}

.ai-model-badge:hover {
  border-color: var(--border-hover);
  color: var(--white);
}

.ai-model-label {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ai-conn-dot.connected {
  background: var(--emerald-400);
  box-shadow: 0 0 6px rgba(52, 211, 153, 0.5);
}

.ai-conn-dot.disconnected {
  background: var(--red-400);
  box-shadow: 0 0 6px rgba(248, 113, 113, 0.4);
}

.ai-conn-dot.unknown {
  background: var(--text-dim);
}

/* --- AI Stop / Clear Buttons --- */
.ai-stop-btn {
  background: var(--red-500) !important;
  color: #fff !important;
}

.ai-stop-btn:hover {
  background: var(--red-400) !important;
}

.ai-clear-btn {
  border-color: rgba(239, 68, 68, 0.25) !important;
  color: var(--red-400) !important;
}

.ai-clear-btn:hover {
  background: rgba(239, 68, 68, 0.1) !important;
  border-color: var(--red-400) !important;
}

/* --- AI Typing Dots --- */
.ai-typing-dots {
  display: inline-flex;
  gap: 4px;
  padding: 0 4px;
  vertical-align: middle;
}

.ai-typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  display: inline-block;
  animation: aiDotPulse 1.4s infinite ease-in-out both;
}

.ai-typing-dots span:nth-child(1) { animation-delay: 0s; }
.ai-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes aiDotPulse {
  0%, 80%, 100% { transform: scale(0.5); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

/* --- AI Settings Modal --- */
.ai-settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.ai-settings-modal {
  width: 580px;
  max-width: 95vw;
  max-height: 85vh;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
  animation: settingsSlideUp 0.3s ease;
}

@keyframes settingsSlideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.ai-settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.ai-settings-header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--white);
}

.ai-settings-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--white);
}

.ai-settings-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}

.ai-settings-close:hover {
  color: var(--white);
  background: var(--bg-hover);
}

.ai-settings-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}


.ai-settings-section-title {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 1rem;
}

.ai-settings-field {
  margin-bottom: 1rem;
}

.ai-settings-field:last-child {
  margin-bottom: 0;
}

.ai-settings-field label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.ai-settings-val {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.ai-settings-input,
.ai-settings-select,
.ai-settings-textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.625rem 0.875rem;
  color: var(--white);
  font-size: 0.875rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.ai-settings-input:focus,
.ai-settings-select:focus,
.ai-settings-textarea:focus {
  border-color: var(--accent);
}

.ai-settings-select {
  appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%2388889' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

.ai-settings-textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}

.ai-settings-input-row {
  display: flex;
  gap: 0.5rem;
}

.ai-settings-input-row .ai-settings-input,
.ai-settings-input-row .ai-settings-select {
  flex: 1;
}

.ai-settings-test-btn,
.ai-settings-refresh-btn {
  padding: 0.5rem 1rem;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  font-family: inherit;
}

.ai-settings-test-btn:hover,
.ai-settings-refresh-btn:hover {
  color: var(--white);
  border-color: var(--border-hover);
}

.ai-settings-test-btn.success {
  color: var(--emerald-400);
  border-color: rgba(16, 185, 129, 0.3);
}

.ai-settings-test-btn.failed {
  color: var(--red-400);
  border-color: rgba(239, 68, 68, 0.3);
}

.ai-settings-refresh-btn {
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
}

.ai-settings-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.ai-settings-range {
  width: 100%;
  accent-color: var(--accent);
  margin-top: 0.25rem;
}

.ai-settings-range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-top: 0.25rem;
}

/* Toggle switch */
.ai-settings-toggle-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-top: 0.25rem;
}

.ai-settings-toggle-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.ai-settings-toggle {
  width: 42px;
  height: 24px;
  border-radius: 12px;
  background: var(--border);
  border: none;
  padding: 2px;
  cursor: pointer;
  position: relative;
  transition: background 0.2s;
}

.ai-settings-toggle.active {
  background: var(--accent);
}

.ai-settings-toggle-knob {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--white);
  display: block;
  transition: transform 0.2s;
}

.ai-settings-toggle.active .ai-settings-toggle-knob {
  transform: translateX(18px);
}

.ai-settings-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1.25rem 1.5rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* AI message code blocks */
.ai-msg-bubble code {
  background: var(--bg-hover);
  padding: 0.15em 0.4em;
  border-radius: 3px;
  font-size: 0.85em;
  color: var(--accent);
}

/* --- Digital Twin --- */
.sim-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.sim-panel h3 {
  color: var(--white);
  font-weight: 500;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sim-panel h3 .icon-muted {
  color: var(--text-muted);
}

.sim-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.5rem;
}

@media (max-width: 768px) {
  .sim-grid {
    grid-template-columns: 1fr;
  }
}

.sim-field label {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.5rem;
}

.sim-field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.sim-field .range-val {
  text-align: right;
  font-size: 0.75rem;
  color: var(--white);
  margin-top: 0.25rem;
}

.sim-select,
.sim-date-display {
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--white);
  font-family: inherit;
  outline: none;
  width: 100%;
}

.sim-select {
  appearance: none;
  cursor: pointer;
}

.sim-date-display .icon-dim {
  color: var(--text-dim);
  margin-right: 0.5rem;
}

.sim-results {
  transition: opacity 0.5s, transform 0.5s;
}

.sim-results.hidden {
  opacity: 0.5;
  transform: translateY(1rem);
  pointer-events: none;
}

.sim-chart-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  padding: 1.5rem;
  height: 300px;
  position: relative;
  overflow: hidden;
}

.sim-chart-box h4 {
  color: var(--white);
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 1rem;
  position: relative;
  z-index: 10;
}

.sim-legend {
  position: absolute;
  bottom: 1rem;
  left: 1.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  gap: 1rem;
  z-index: 20;
}

.sim-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 0.25rem;
}

.sim-legend-dot.accent {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  color: var(--accent);
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sim-legend-dot.dim {
  background: var(--text-dim);
}

.sim-svg-wrap {
  position: absolute;
  inset: 0;
  padding-top: 4rem;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
  padding-bottom: 1.5rem;
  z-index: 10;
  display: flex;
  align-items: flex-end;
}

/* --- Stress Bars --- */
.stress-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  padding: 1.5rem;
  height: 300px;
  display: flex;
  flex-direction: column;
}

.stress-card h4 {
  color: var(--white);
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 1rem;
  display: flex;
  justify-content: space-between;
}

.stress-items {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  justify-content: center;
}

.stress-item-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  margin-bottom: 0.25rem;
}

.stress-item-header .name {
  color: var(--text-secondary);
}

.stress-item-header .status-red {
  color: var(--red-400);
}

.stress-item-header .status-amber {
  color: var(--amber-400);
}

.stress-item-header .status-green {
  color: var(--emerald-400);
}

.stress-bar-bg {
  width: 100%;
  background: var(--bg-input);
  height: 8px;
  border-radius: var(--radius-full);
  overflow: hidden;
}

.stress-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
}

.stress-bar-fill.red {
  background: var(--red-500);
}

.stress-bar-fill.amber {
  background: var(--amber-500);
}

.stress-bar-fill.green {
  background: var(--emerald-500);
}

/* --- Competitor Map --- */
.radar-container {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 500px;
}

.radar-bg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0.2;
}

.radar-circle {
  border: 1px solid var(--text-dim);
  border-radius: 50%;
  position: absolute;
}

.radar-circle-lg {
  width: 800px;
  height: 800px;
}

.radar-circle-md {
  width: 500px;
  height: 500px;
}

.radar-circle-sm {
  width: 200px;
  height: 200px;
}

.radar-line-h {
  width: 100%;
  height: 1px;
  background: var(--text-dim);
  position: absolute;
}

.radar-line-v {
  height: 100%;
  width: 1px;
  background: var(--text-dim);
  position: absolute;
}

.radar-center {
  position: absolute;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.radar-center-dot {
  width: 24px;
  height: 24px;
  background: var(--white);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
  z-index: 20;
}

.radar-center-label {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--white);
  background: var(--bg-body);
  padding: 0.125rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.radar-pin {
  position: absolute;
  z-index: 10;
  cursor: pointer;
}

.radar-pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
}

.radar-pin-dot:hover {
  background: var(--text-muted);
}

.radar-pin-dot.active {
  background: var(--accent-gradient);
  transform: scale(1.5);
  box-shadow: 0 0 15px rgba(249, 115, 22, 0.6);
}

.radar-info-card {
  position: absolute;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--bg-card-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  padding: 1.25rem;
  width: 320px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  z-index: 30;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(1rem);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.radar-info-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}

.radar-info-name {
  color: var(--white);
  font-weight: 500;
  font-size: 1.125rem;
}

.radar-info-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.radar-info-close {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.2s;
}

.radar-info-close:hover {
  color: var(--white);
}

.radar-info-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1rem 0;
}

.radar-stat-box {
  background: var(--bg-card);
  padding: 0.75rem;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
}

.radar-stat-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.radar-stat-value {
  color: var(--white);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.radar-stat-value.critical {
  color: var(--red-400);
}

/* --- Supplier Cards --- */
.supplier-card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.supplier-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.supplier-icon-box {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-xl);
  background: var(--bg-hover);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--white);
}

.supplier-status {
  font-size: 10px;
  font-family: monospace;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  border: 1px solid;
}

.supplier-status.on-time {
  background: rgba(16, 185, 129, 0.1);
  color: var(--emerald-400);
  border-color: rgba(16, 185, 129, 0.2);
}

.supplier-status.delayed {
  background: rgba(239, 68, 68, 0.1);
  color: var(--red-400);
  border-color: rgba(239, 68, 68, 0.2);
}

.supplier-status.pending {
  background: rgba(245, 158, 11, 0.1);
  color: var(--amber-400);
  border-color: rgba(245, 158, 11, 0.2);
}

.supplier-name {
  color: var(--white);
  font-weight: 500;
  font-size: 1.125rem;
  margin-bottom: 0.25rem;
}

.supplier-category {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.supplier-details {
  background: var(--bg-card-dark);
  border-radius: var(--radius-xl);
  padding: 0.75rem;
  border: 1px solid var(--border);
  font-size: 0.875rem;
}

.supplier-detail-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.supplier-detail-row:last-child {
  margin-bottom: 0;
}

.supplier-detail-row .label {
  color: var(--text-muted);
}

.supplier-detail-row .value {
  color: var(--white);
}

.supplier-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.supplier-actions .btn {
  flex: 1;
}

/* --- CRM Table --- */
.crm-search-box {
  position: relative;
}

.crm-search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
}

.crm-search-input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 0.5rem 1rem 0.5rem 2.25rem;
  font-size: 0.875rem;
  color: var(--white);
  outline: none;
  width: 16rem;
  font-family: inherit;
  transition: border-color 0.2s;
}

.crm-search-input:focus {
  border-color: var(--text-dim);
}

.crm-search-input::placeholder {
  color: var(--text-dim);
}

.crm-table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  overflow: hidden;
}

.crm-table {
  width: 100%;
  text-align: left;
  border-collapse: collapse;
}

.crm-table thead tr {
  border-bottom: 1px solid var(--border);
  background: var(--bg-card-dark);
}

.crm-table th {
  font-weight: 400;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 1rem 1.5rem;
}

.crm-table th.text-right {
  text-align: right;
}

.crm-table tbody {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.crm-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.crm-table tbody tr:hover {
  background: var(--bg-input);
}

.crm-table tbody tr:last-child {
  border-bottom: none;
}

.crm-table td {
  padding: 1rem 1.5rem;
}

.crm-table td.text-right {
  text-align: right;
}

.crm-name-cell {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 500;
  color: var(--white);
}

.crm-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.crm-segment {
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
}

.crm-segment.vip {
  background: rgba(245, 158, 11, 0.1);
  color: var(--amber-400);
}

.crm-segment.default {
  background: var(--bg-hover);
  color: var(--text-muted);
}

.crm-mono {
  font-family: monospace;
}

.crm-pref {
  color: var(--text-muted);
  font-size: 0.75rem;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crm-edit-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, color 0.2s;
}

tr:hover .crm-edit-btn {
  opacity: 1;
}

.crm-edit-btn:hover {
  color: var(--white);
}

/* --- Target / Action Cards --- */
.target-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.target-id {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.5rem;
  background: var(--bg-input);
  border-radius: 4px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  font-size: 10px;
  font-family: monospace;
  font-weight: 500;
  margin-bottom: 1rem;
}

.target-id .icon-accent {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  color: var(--accent);
}

.target-name {
  color: var(--white);
  font-weight: 500;
  margin-bottom: 0.375rem;
  line-height: 1.4;
}

.target-desc {
  color: var(--text-muted);
  font-size: 0.875rem;
  line-height: 1.6;
  margin-bottom: 1.5rem;
}

.target-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* --- Live Events Card --- */
.live-events-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

.live-events-header {
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.live-events-header .icon-accent {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  color: var(--accent);
}

.live-event-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}

.live-event-row:last-child {
  margin-bottom: 0;
}

.live-event-desc {
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 0.5rem;
}

.live-event-time {
  color: var(--text-dim);
  font-family: monospace;
  font-size: 10px;
  white-space: nowrap;
}

/* --- Spinner Animation --- */
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.animate-spin {
  animation: spin 1s linear infinite;
}

/* --- Section margin --- */
.mb-6 {
  margin-bottom: 1.5rem;
}

.pb-12 {
  padding-bottom: 3rem;
}

/* --- Utility --- */
.hidden {
  display: none !important;
}

.text-white {
  color: var(--white);
}

.text-amber-star {
  color: var(--amber-400);
}

/* --- Gradient Overrides --- */
.gradient-text,
.sidebar-item.active,
.accent,
.icon-accent,
.ai-top-item.selected,
.ai-intro-icon,
.ai-msg-icon,
.dt-metric-icon,
.aip-event-icon,
.metric-change.positive,
.tab-btn.active {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  color: transparent !important;
}

[style*="-webkit-text-fill-color: transparent"] svg,
.sidebar-item.active svg,
.accent svg,
.icon-accent svg,
.ai-top-item.selected svg,
.ai-intro-icon svg,
.ai-msg-icon svg,
.dt-metric-icon svg,
.aip-event-icon svg,
.metric-change.positive svg,
.tab-btn.active svg {
  stroke: url(#accentGradient) !important;
}

[style*="-webkit-text-fill-color: transparent"] svg[fill="currentColor"],
.sidebar-item.active svg[fill="currentColor"],
.accent svg[fill="currentColor"] {
  fill: url(#accentGradient) !important;
  stroke: none !important;
}

/* --- Data Pipelines --- */
.pipeline-board {
  height: 600px;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  position: relative;
  background: var(--bg-pipeline);
  background-image: radial-gradient(var(--bg-pipeline-dot) 1px, transparent 1px);
  background-size: 20px 20px;
}

.pipeline-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: rgba(19, 19, 22, 0.8);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.pipeline-tools {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tool-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  transition: all 0.2s;
}

.tool-btn:hover {
  background: var(--bg-hover);
  color: var(--white);
}

.tool-btn.active {
  background: var(--bg-card);
  border-color: var(--border);
  color: var(--white);
}

.pipeline-tools .divider {
  width: 1px;
  height: 16px;
  background: var(--border);
  margin: 0 0.25rem;
}

.pipeline-status {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-dot.healthy {
  background: var(--emerald-500);
  box-shadow: 0 0 8px var(--emerald-500);
}

.pipeline-canvas {
  flex: 1;
  position: relative;
  overflow: auto;
}

.pipeline-links {
  position: absolute;
  top: 0;
  left: 0;
  width: 2000px;
  height: 1000px;
  pointer-events: none;
}

.node-block {
  position: absolute;
  width: 230px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  z-index: 10;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
  cursor: grab;
}

.node-block:hover {
  border-color: var(--border-hover);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  transform: translateY(-2px);
}

.node-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--white);
  border-top-left-radius: var(--radius-xl);
  border-top-right-radius: var(--radius-xl);
}

.trigger-node .node-header {
  border-top: 3px solid var(--emerald-500);
}

.action-node .node-header {
  border-top: 3px solid var(--accent);
}

.ai-node .node-header {
  border-top: 3px solid #db2777;
  /* pink accent for AI */
}

.util-node .node-header {
  border-top: 3px solid var(--text-muted);
}

.node-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.node-body {
  padding: 1rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.node-tag {
  display: inline-block;
  margin-top: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: var(--bg-hover);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.port {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--bg-body);
  border: 2px solid var(--text-muted);
  border-radius: 50%;
  top: 50%;
  transform: translateY(-50%);
  cursor: crosshair;
  transition: border-color 0.2s;
}

.port:hover {
  border-color: var(--white);
  background: var(--border);
}

.port-in {
  left: -6px;
}

.port-out {
  right: -6px;
}

/* --- Shared Keyframes --- */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* --- Toast Notifications --- */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-hover);
  color: var(--white);
  padding: 1rem 1.5rem;
  border-radius: var(--radius-xl);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: toastSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  pointer-events: auto;
}

.toast.hiding {
  animation: toastSlideOut 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes toastSlideIn {
  from { opacity: 0; transform: translateX(50px) scale(0.95); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toastSlideOut {
  from { opacity: 1; transform: translateX(0) scale(1); }
  to { opacity: 0; transform: translateX(50px) scale(0.95); }
}