/* ==========================================================================
   Helix Platform — Frontend Styles
   Multi-feature RAG platform with dark sidebar + clean chat area
   ========================================================================== */

/* --- Reset & Tokens --- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Helix brand — from CNXN Helix style guide */
  --color-helix-orange: #E85D26;
  --color-helix-blue: #5B9BD5;
  --color-primary: #E85D26;
  --color-primary-light: #F07040;
  --color-primary-dark: #C94D1E;
  --color-accent: #5B9BD5;
  --color-accent-light: #7AB3E0;

  /* Safety palette */
  --color-danger: #dc2626;
  --color-warning: #E85D26;
  --color-success: #2EAD4B;

  /* Neutrals */
  --color-bg: #f5f7fa;
  --color-surface: #ffffff;
  --color-surface-raised: #eef2f7;
  --color-border: #d6dde6;
  --color-border-light: #eef2f7;
  --color-text: #1a2332;
  --color-text-secondary: #516175;
  --color-text-muted: #8896a7;

  /* Sidebar */
  --sidebar-bg: #0A1628;
  --sidebar-surface: #122340;
  --sidebar-text: #dce3ea;
  --sidebar-text-muted: #8896a7;
  --sidebar-border: #1A3050;
  --sidebar-width: 320px;

  /* Topbar */
  --topbar-height: 56px;
  --topbar-bg: #0A1628;

  /* Typography */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", "Consolas", monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-lg: 1.125rem;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 16px;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}


/* ==========================================================================
   TOP BAR — rebuilt header
   ========================================================================== */

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--topbar-height);
  background: var(--topbar-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-5) 0 var(--space-6);
  padding-right: max(var(--space-5), env(safe-area-inset-right));
  padding-left: max(var(--space-6), env(safe-area-inset-left));
  border-bottom: 1px solid rgba(255,255,255,0.08);
  max-width: 100vw;
  box-sizing: border-box;
}

/* --- Left: icons + title ------------------------------------------------ */

.topbar__left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar__shield-icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  color: var(--color-helix-orange);
}

.topbar__helix-icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
}

.topbar__title {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.topbar__name {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-header-text, #fff);
  letter-spacing: -0.01em;
  line-height: 1.15;
  white-space: nowrap;
}

.topbar__subtitle {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--sidebar-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  line-height: 1;
}

/* --- Right: token badge + divider + status ------------------------------ */

.topbar__right {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-shrink: 0;
}

/* Token badge */
.topbar__token-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  cursor: default;
  user-select: none;
}

.topbar__token-icon {
  flex-shrink: 0;
  width: 15px;
  height: 15px;
  color: var(--color-helix-orange);
}

.topbar__token-text {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--sidebar-text-muted);
  letter-spacing: 0.02em;
}

.topbar__token-value {
  font-size: var(--text-sm);
  font-weight: 700;
  color: #fff;
  font-family: var(--font-mono);
  min-width: 20px;
  text-align: right;
  transition: color 200ms ease, transform 200ms ease;
}

.topbar__token-value--pulse {
  animation: tokenPulse 350ms ease;
}

@keyframes tokenPulse {
  0%   { color: #fff; transform: scale(1); }
  40%  { color: var(--color-helix-orange); transform: scale(1.2); }
  100% { color: #fff; transform: scale(1); }
}

/* Vertical divider between tokens and status */
.topbar__divider {
  width: 1px;
  height: 20px;
  background: rgba(255,255,255,0.15);
}

/* Status indicator */
.topbar__status {
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar__status-dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-text-muted);
  transition: background var(--transition-base);
}

.topbar__status-dot--ok       { background: var(--color-success); }
.topbar__status-dot--degraded { background: var(--color-warning); }
.topbar__status-dot--error    { background: var(--color-danger); }

.topbar__status-text {
  font-size: var(--text-xs);
  color: var(--sidebar-text-muted);
  white-space: nowrap;
}


/* ==========================================================================
   APP LAYOUT
   ========================================================================== */

.app {
  display: flex;
  height: calc(100vh - var(--topbar-height));
  height: calc(100dvh - var(--topbar-height));
  margin-top: var(--topbar-height);
  overflow: hidden;
  max-width: 100vw;
}


/* ==========================================================================
   SIDEBAR
   ========================================================================== */

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: width var(--transition-base), min-width var(--transition-base), transform var(--transition-base);
}

/* Desktop collapse toggle */
.sidebar__collapse-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--sidebar-text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
  margin-left: auto;
}

.sidebar__collapse-btn:hover {
  background: var(--sidebar-surface);
  color: var(--sidebar-text);
}

.sidebar__collapse-btn svg {
  width: 16px;
  height: 16px;
  transition: transform var(--transition-base);
}

.sidebar__collapse-header {
  display: flex;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--sidebar-border);
}

/* Collapsed state (desktop) */
.sidebar--collapsed {
  width: 0;
  min-width: 0;
  overflow: hidden;
  border-right: none;
}

.sidebar--collapsed .sidebar__section,
.sidebar--collapsed .sidebar__footer,
.sidebar--collapsed .sidebar__collapse-header {
  opacity: 0;
  pointer-events: none;
}

.sidebar__section {
  padding: var(--space-5);
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar__heading {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sidebar-text-muted);
  margin-bottom: var(--space-3);
}

.sidebar__filters {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.filter-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--sidebar-text);
  font-size: var(--text-sm);
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.filter-btn:hover {
  background: var(--sidebar-surface);
}

.filter-btn--active {
  background: var(--color-primary);
  color: #fff;
}

.filter-btn--active:hover {
  background: var(--color-primary-light);
}

/* Quick prompt buttons */
.sidebar__prompts {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.prompt-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--sidebar-text);
  font-size: var(--text-sm);
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.prompt-btn:hover {
  background: var(--sidebar-surface);
  border-color: var(--color-primary-light);
  color: var(--color-primary-light);
}

/* Settings */
.sidebar__settings {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.setting {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  position: relative;
}

.setting__info-btn {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border: 1px solid var(--sidebar-border);
  border-radius: 50%;
  background: transparent;
  color: var(--sidebar-text-muted);
  font-size: 11px;
  font-weight: 700;
  font-style: italic;
  font-family: Georgia, serif;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  line-height: 1;
}

.setting__info-btn:hover,
.setting__info-btn--active {
  background: var(--color-helix-orange);
  border-color: var(--color-helix-orange);
  color: #fff;
}

.setting__popup {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 240px;
  padding: var(--space-3);
  background: #1a2332;
  color: #dce3ea;
  font-size: var(--text-xs);
  line-height: 1.5;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 150;
  border: 1px solid var(--sidebar-border);
  animation: fadeIn 150ms ease;
}

.setting__popup::before {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 12px;
  border: 5px solid transparent;
  border-bottom-color: #1a2332;
}

.setting__label {
  font-size: var(--text-sm);
  color: var(--sidebar-text-muted);
  min-width: 72px;
}

.setting__range {
  flex: 1;
  accent-color: var(--color-primary-light);
  cursor: pointer;
}

.setting__value {
  font-size: var(--text-sm);
  color: var(--sidebar-text);
  font-family: var(--font-mono);
  min-width: 30px;
  text-align: right;
}

.setting__select {
  flex: 1;
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-sm);
  background: var(--sidebar-surface);
  color: var(--sidebar-text);
  font-size: var(--text-sm);
  font-family: var(--font-sans);
  cursor: pointer;
}

.setting__checkbox {
  accent-color: var(--color-primary-light);
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.sidebar__footer {
  margin-top: auto;
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--sidebar-border);
}

.sidebar__stats {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--sidebar-text-muted);
}

.sidebar__stats strong {
  color: var(--sidebar-text);
}


/* ==========================================================================
   CHAT AREA
   ========================================================================== */

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  background: var(--color-bg);
  overflow: hidden;
}

/* Ensure messages area can scroll within its flex parent */
.chat__messages {
  min-height: 0;
}

.chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6) var(--space-8);
  scroll-behavior: smooth;
}

/* --- Messages --- */

.message {
  display: flex;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
  animation: fadeIn 300ms ease;
}

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

.message__avatar {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.message__avatar svg {
  width: 20px;
  height: 20px;
}

.message--system .message__avatar {
  background: var(--color-primary);
  color: #fff;
}

.message--user .message__avatar {
  background: var(--color-surface-raised);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.message--assistant .message__avatar {
  background: var(--color-primary);
  color: #fff;
}

.message__content {
  flex: 1;
  min-width: 0;
}

.message__header {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.message__name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
}

.message__time {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.message__body {
  font-size: var(--text-base);
  line-height: 1.4;
  color: var(--color-text);
}

.message__body p {
  margin: 0 0 0.75em 0;
}

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

.message__body ul,
.message__body ol {
  margin: 0 0 0.75em 0;
  padding-left: 1.1em;
  list-style-position: outside;
}

.message__body ul:last-child,
.message__body ol:last-child {
  margin-bottom: 0;
}

/* Nested lists get additional indent */
.message__body li ul,
.message__body li ol {
  padding-left: 1.5em;
  margin-top: 0.25em;
  margin-bottom: 0;
}

.message__body li {
  margin: 0 0 0.25em 0;
  padding: 0;
  padding-left: 0.2em;
  line-height: 1.4;
}

.message__body li:last-child {
  margin-bottom: 0;
}

.message__body ul + p,
.message__body ol + p,
.message__body pre + p,
.message__body h2 + p,
.message__body h3 + p,
.message__body h4 + p {
  margin-top: 0.75em;
}

.message__body > p:last-child:not(:first-child) {
  margin-top: 1em;
}

.message__body li > p {
  margin: 0;
}

.message__body h1,
.message__body h2,
.message__body h3,
.message__body h4 {
  margin: 1.25em 0 0.4em 0;
  line-height: 1.2;
}

.message__body > h1:first-child,
.message__body > h2:first-child,
.message__body > h3:first-child,
.message__body > h4:first-child {
  margin-top: 0;
}

.message__body strong {
  font-weight: 600;
}

.message__body code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--color-surface-raised);
  padding: 0.15em 0.4em;
  border-radius: 3px;
}

.message__body pre {
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  overflow-x: auto;
  margin: 0.35em 0;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.5;
}

.message--user .message__body {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5);
}

/* Typing indicator */
.typing-indicator {
  display: inline-flex;
  gap: 4px;
  padding: var(--space-2) 0;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-primary-light);
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* --- Source Cards --- */

.sources {
  margin-top: var(--space-4);
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-4);
}

.sources__toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-3);
  cursor: pointer;
  user-select: none;
}

.sources__toggle:hover {
  color: var(--color-text-secondary);
}

.sources__toggle-icon {
  width: 14px;
  height: 14px;
  transition: transform var(--transition-fast);
  transform: rotate(-90deg);
}

.sources__toggle--open .sources__toggle-icon {
  transform: rotate(0deg);
}

.sources__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-3);
  transition: max-height 300ms ease, opacity 200ms ease;
  overflow: hidden;
}

.sources__grid--collapsed {
  max-height: 0;
  opacity: 0;
  margin: 0;
}

.source-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

.source-card__section {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: var(--space-1);
}

.source-card__title {
  font-size: var(--text-sm);
  color: var(--color-text);
  font-weight: 500;
  margin-bottom: var(--space-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-card__score {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.source-card__url {
  display: block;
  font-size: var(--text-xs);
  color: var(--color-primary);
  text-decoration: none;
  margin-top: var(--space-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-card__url:hover {
  text-decoration: underline;
  color: var(--color-primary-light);
}

.source-card__bar {
  height: 3px;
  background: var(--color-border);
  border-radius: 2px;
  margin-top: var(--space-2);
  overflow: hidden;
}

.source-card__fill {
  height: 100%;
  border-radius: 2px;
  background: var(--color-primary-light);
  transition: width var(--transition-base);
}

/* --- Performance Metrics --- */

.metrics {
  display: flex;
  gap: var(--space-4);
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border-light);
}

.metric {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.metric strong {
  color: var(--color-text-secondary);
  font-weight: 600;
}

/* --- Action Buttons (post-response quick actions) --- */

.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.message-actions__btn {
  padding: var(--space-2) var(--space-4);
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.message-actions__btn:hover {
  background: var(--color-primary-dark);
}

.message-actions__btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--color-text-muted);
}

.action-prompt {
  margin-top: var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.action-prompt__input {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  width: 200px;
  outline: none;
  transition: border-color var(--transition-fast);
}

.action-prompt__input:focus {
  border-color: var(--color-primary);
}

.action-prompt__submit {
  padding: var(--space-2) var(--space-3);
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.action-prompt__submit:hover {
  background: var(--color-primary-dark);
}

.action-prompt__prefix {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
  white-space: nowrap;
  line-height: 1;
}

.action-prompt__input--phone {
  width: 170px;
}


/* ==========================================================================
   CHAT INPUT AREA
   ========================================================================== */

.chat__input-area {
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  padding: var(--space-4) var(--space-8);
  padding-bottom: max(var(--space-4), env(safe-area-inset-bottom));
  flex-shrink: 0;
}

.chat__form {
  max-width: 900px;
  margin: 0 auto;
}

.chat__input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: var(--space-3);
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  transition: border-color var(--transition-fast);
}

.chat__input-wrapper:focus-within {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(91, 155, 213, 0.15);
}

.chat__input {
  flex: 1;
  border: none;
  outline: none;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--color-text);
  background: transparent;
  resize: none;
  line-height: 1.5;
  max-height: 150px;
  min-height: 24px;
}

.chat__input::placeholder {
  color: var(--color-text-muted);
}

.chat__send {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chat__send:hover:not(:disabled) {
  background: var(--color-primary-dark);
}

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

.chat__send svg {
  width: 18px;
  height: 18px;
}

.chat__meta {
  display: flex;
  justify-content: space-between;
  margin-top: var(--space-2);
  padding: 0 var(--space-1);
}

.chat__charcount {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.chat__section-label {
  font-size: var(--text-xs);
  color: var(--color-primary);
  font-weight: 500;
}


/* ==========================================================================
   SOURCE DETAIL MODAL
   ========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  animation: fadeIn 200ms ease;
}

.modal-overlay--visible {
  display: flex;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 640px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  animation: modalSlideUp 250ms ease;
}

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

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-border);
}

.modal__title {
  font-size: var(--text-lg);
  font-weight: 600;
}

.modal__close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
}

.modal__close:hover {
  background: var(--color-surface-raised);
  color: var(--color-text);
}

.modal__body {
  padding: var(--space-6);
  overflow-y: auto;
  font-size: var(--text-sm);
  line-height: 1.65;
  color: var(--color-text);
}

.modal__body .modal-field {
  margin-bottom: var(--space-4);
}

.modal__body .modal-field__label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-1);
}

.modal__body .modal-field__value {
  color: var(--color-text);
}

.modal__body .modal-field__value a {
  color: var(--color-primary);
  text-decoration: none;
}

.modal__body .modal-field__value a:hover {
  text-decoration: underline;
}

.modal__body .source-text {
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.6;
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
}


/* ==========================================================================
   SIDEBAR TOGGLE (desktop expand btn when collapsed + mobile hamburger)
   ========================================================================== */

.sidebar-toggle {
  position: fixed;
  bottom: var(--space-6);
  left: var(--space-4);
  z-index: 90;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition-fast);
}

.sidebar-toggle:hover {
  transform: scale(1.05);
}

.sidebar-toggle svg {
  width: 20px;
  height: 20px;
}

/* Desktop: show expand button when sidebar is collapsed */
.sidebar--collapsed ~ .main-content .sidebar-expand-btn {
  display: flex;
}

.sidebar-expand-btn {
  display: none;
  position: fixed;
  top: calc(var(--topbar-height) + var(--space-3));
  left: var(--space-3);
  z-index: 90;
  width: 36px;
  height: 36px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
}

.sidebar-expand-btn:hover {
  background: var(--color-surface-raised);
  color: var(--color-primary);
}

.sidebar-expand-btn svg {
  width: 18px;
  height: 18px;
}

/* Mobile menu button in topbar */
.topbar__menu-btn {
  display: none;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--sidebar-text-muted);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  margin-right: var(--space-2);
}

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

.topbar__menu-btn svg {
  width: 20px;
  height: 20px;
}

/* Mobile dropdown panel overlay */
.mobile-menu-overlay {
  display: none;
  position: fixed;
  inset: 0;
  top: var(--topbar-height);
  z-index: 85;
  background: rgba(0, 0, 0, 0.4);
}

.mobile-menu-overlay--visible {
  display: block;
}

/* Mobile dropdown panel */
.mobile-menu {
  display: none;
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  right: 0;
  z-index: 90;
  background: var(--sidebar-bg);
  border-bottom: 2px solid var(--color-primary);
  box-shadow: var(--shadow-lg);
  max-height: calc(100vh - var(--topbar-height) - 40px);
  overflow-y: auto;
  animation: mobileMenuSlide 200ms ease;
}

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

.mobile-menu--visible {
  display: block;
}

.mobile-menu__section {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--sidebar-border);
}

.mobile-menu__heading {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sidebar-text-muted);
  margin-bottom: var(--space-2);
}

.mobile-menu__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mobile-menu__btn {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--sidebar-text);
  font-size: var(--text-sm);
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.mobile-menu__btn:hover {
  background: var(--sidebar-surface);
}

.mobile-menu__btn--active {
  background: var(--color-primary);
  color: #fff;
}

.mobile-menu__btn--prompt {
  font-size: var(--text-xs);
  color: var(--sidebar-text-muted);
  border-left: 2px solid transparent;
}

.mobile-menu__btn--prompt:hover {
  border-left-color: var(--color-primary);
  color: var(--sidebar-text);
}

.mobile-menu__btn svg {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
}

.mobile-menu__stats {
  display: flex;
  gap: var(--space-4);
  font-size: var(--text-xs);
  color: var(--sidebar-text-muted);
  padding: var(--space-2) var(--space-3);
}

.mobile-menu__stats strong {
  color: var(--sidebar-text);
}


/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

@media (max-width: 900px) {
  /* Hide desktop sidebar on mobile — use dropdown menu instead */
  .sidebar {
    display: none !important;
  }

  .sidebar__collapse-btn,
  .sidebar-expand-btn {
    display: none !important;
  }

  /* Show mobile menu button in topbar */
  .topbar__menu-btn {
    display: flex;
  }

  /* Hide the old floating toggle */
  .sidebar-toggle {
    display: none !important;
  }

  .chat__messages {
    padding: var(--space-6) var(--space-4) var(--space-4);
  }

  .chat__input-area {
    padding: var(--space-3) var(--space-4);
    padding-bottom: max(var(--space-3), env(safe-area-inset-bottom));
  }

  .sources__grid {
    grid-template-columns: 1fr;
  }

  .metrics {
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  /* Prevent right-side truncation on mobile Safari */
  .main-content {
    max-width: 100vw;
    overflow-x: hidden;
  }

  .topbar {
    padding: 0 var(--space-3) 0 var(--space-3);
    padding-right: max(var(--space-3), env(safe-area-inset-right));
    padding-left: max(var(--space-3), env(safe-area-inset-left));
  }

  /* Ensure admin tables scroll horizontally on mobile */
  .admin-table-wrap {
    -webkit-overflow-scrolling: touch;
  }

  .admin-view__content,
  .pipeline-view__content {
    padding: var(--space-4);
  }

  .admin-panel {
    padding: var(--space-4);
  }

  .admin-panel__header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
  }

  .admin-panel__actions {
    width: 100%;
  }

  .admin-panel__actions .admin-form__btn {
    flex: 1;
  }
}

@media (max-width: 600px) {
  .topbar__subtitle {
    display: none;
  }

  /* Hide token badge and status to prevent overlap with feature name */
  .topbar__token-badge,
  .topbar__divider {
    display: none;
  }

  .topbar__status {
    display: none;
  }

  .topbar__name {
    font-size: var(--text-base);
  }

  .message {
    gap: var(--space-2);
  }

  .message__avatar {
    width: 28px;
    height: 28px;
  }

  .message__avatar svg {
    width: 16px;
    height: 16px;
  }

  /* Reduce spacing on the welcome message so the description is visible */
  .message--system {
    margin-bottom: var(--space-3);
  }

  .message--system .message__body {
    font-size: var(--text-sm);
  }

  /* Mobile menu stats are redundant when topbar items are hidden */
  .mobile-menu__stats {
    display: none;
  }
}


/* ==========================================================================
   SCROLLBAR
   ========================================================================== */

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-muted);
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--sidebar-border);
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--sidebar-text-muted);
}


/* ==========================================================================
   ERROR STATE
   ========================================================================== */

.message--error .message__body {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5);
  color: var(--color-danger);
}


/* ==========================================================================
   NAVIGATION BUTTONS (sidebar nav)
   ========================================================================== */

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--sidebar-text);
  font-size: var(--text-sm);
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.nav-btn:hover {
  background: var(--sidebar-surface);
}

.nav-btn--active {
  background: var(--color-primary);
  color: #fff;
}

.nav-btn--active:hover {
  background: var(--color-primary-light);
}

.nav-btn--subtle {
  color: var(--sidebar-text-muted);
  font-size: var(--text-xs);
}

.nav-btn--subtle:hover {
  color: var(--sidebar-text);
}

.nav-btn--back {
  color: var(--color-text-secondary);
  padding: var(--space-3);
}

.nav-btn--back:hover {
  color: var(--color-primary);
  background: var(--color-surface-raised);
}

.nav-btn__icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
}


/* ==========================================================================
   SIDEBAR — Additional Elements
   ========================================================================== */

.sidebar__info {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--sidebar-text-muted);
}

.sidebar__info strong {
  color: var(--sidebar-text);
}

/* Example Prompts heading row */
.sidebar__heading-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-1);
  cursor: pointer;
  margin-left: 0;
  margin-bottom: var(--space-2);
  width: 100%;
}

.sidebar__heading-row .sidebar__heading {
  margin-bottom: 0;
}

/* Small arrow toggle for Example Prompts */
.sidebar__prompts-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--sidebar-text-muted);
  cursor: pointer;
  padding: 2px;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), background var(--transition-fast);
}

.sidebar__prompts-toggle:hover {
  color: var(--sidebar-text);
  background: var(--sidebar-surface);
}

.sidebar__prompts-toggle-icon {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
  transition: transform var(--transition-fast);
}

.sidebar__prompts-toggle[aria-expanded="false"] .sidebar__prompts-toggle-icon {
  transform: rotate(-90deg);
}

/* Prompt list container */
.sidebar__prompts {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  overflow: hidden;
  max-height: 300px;
  transition: max-height var(--transition-base), opacity var(--transition-fast);
}

.sidebar__prompts--collapsed {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}

/* Individual prompt button */
.prompt-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.3rem var(--space-2);
  border: none;
  border-left: 2px solid var(--sidebar-border);
  border-radius: 0;
  background: transparent;
  color: var(--sidebar-text-muted);
  font-size: var(--text-xs);
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.prompt-btn:hover {
  background: var(--sidebar-surface);
  border-left-color: var(--color-primary);
  color: var(--sidebar-text);
}

.sidebar__admin {
  border-top: 1px solid var(--sidebar-border);
}

.sidebar__powered {
  font-size: 0.65rem;
  color: var(--sidebar-text-muted);
  line-height: 1.5;
  margin-top: var(--space-3);
  text-align: center;
}


/* ==========================================================================
   TOPBAR — User Dropdown
   ========================================================================== */

.topbar__user {
  position: relative;
}

.topbar__user-btn {
  width: 32px;
  height: 32px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 50%;
  background: rgba(255,255,255,0.07);
  color: var(--sidebar-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

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

.topbar__user-icon {
  width: 16px;
  height: 16px;
}

.topbar__user-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 180px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 110;
  overflow: hidden;
}

.topbar__user-dropdown--visible {
  display: block;
}

.topbar__user-info {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
}

.topbar__user-link {
  display: block;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: background var(--transition-fast);
}

.topbar__user-link:hover {
  background: var(--color-surface-raised);
  color: var(--color-danger);
}


/* ==========================================================================
   MAIN CONTENT CONTAINER
   ========================================================================== */

.main-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}


/* ==========================================================================
   ADMIN VIEW
   ========================================================================== */

.admin-view {
  flex: 1;
  overflow-y: auto;
  background: var(--color-bg);
}

.admin-view__content {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-8);
}

.pipeline-view {
  flex: 1;
  overflow-y: auto;
  background: var(--color-bg);
}

.pipeline-view__content {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-8);
}

/* Admin panel card */
.admin-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-6);
  margin-bottom: var(--space-6);
}

.admin-panel--footer {
  background: transparent;
  border: none;
  text-align: center;
  padding: var(--space-4);
}

.admin-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
}

.admin-panel__actions {
  display: flex;
  gap: var(--space-2);
}

.admin-panel__title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: var(--space-2);
}

.admin-panel__header .admin-panel__title {
  margin-bottom: 0;
}

.admin-panel__desc {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-5);
}

/* Admin form */
.admin-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.admin-form__field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.admin-form__field--check {
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
}

.admin-form__row {
  display: flex;
  gap: var(--space-4);
}

.admin-form__row .admin-form__field {
  flex: 1;
}

.admin-form__label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
}

.admin-form__input {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color var(--transition-fast);
  outline: none;
}

.admin-form__input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(91, 155, 213, 0.15);
}

select.admin-form__input {
  cursor: pointer;
  appearance: auto;
}

.admin-form__check {
  accent-color: var(--color-primary);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.admin-form__file {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.admin-form__btn {
  padding: var(--space-3) var(--space-5);
  border: none;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: #fff;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast);
  align-self: flex-start;
}

.admin-form__btn:hover {
  background: var(--color-primary-dark);
}

.admin-form__btn--sm {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
}

.admin-form__btn--accent {
  background: var(--color-accent);
}

.admin-form__btn--accent:hover {
  background: var(--color-accent-light);
}

.admin-form__error {
  display: none;
  background: rgba(220,38,38,0.1);
  border: 1px solid rgba(220,38,38,0.3);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  color: var(--color-danger);
  font-size: var(--text-sm);
}

.admin-actions {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.admin-actions__status {
  font-size: var(--text-sm);
  font-weight: 500;
}

.admin-actions__status--ok {
  color: var(--color-success);
}

.admin-actions__status--err {
  color: var(--color-danger);
}

.admin-loading {
  text-align: center;
  padding: var(--space-8);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.admin-error {
  text-align: center;
  padding: var(--space-8);
  color: var(--color-danger);
  font-size: var(--text-sm);
}


/* ==========================================================================
   ADMIN TABLE
   ========================================================================== */

.admin-table-wrap {
  overflow-x: auto;
  margin: 0 calc(-1 * var(--space-6));
  padding: 0 var(--space-6);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.admin-table th {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
}

.admin-table td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--color-border-light);
  color: var(--color-text);
  vertical-align: middle;
}

.admin-table tr:hover td {
  background: var(--color-surface-raised);
}

.td-truncate {
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.td-empty {
  text-align: center;
  color: var(--color-text-muted);
  padding: var(--space-6) !important;
}


/* ==========================================================================
   BADGES
   ========================================================================== */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

.badge--ok {
  background: rgba(46,173,75,0.12);
  color: var(--color-success);
}

.badge--off {
  background: rgba(136,150,167,0.12);
  color: var(--color-text-muted);
}

.badge--admin {
  background: rgba(232,93,38,0.12);
  color: var(--color-primary);
}

.badge--user {
  background: rgba(91,155,213,0.12);
  color: var(--color-accent);
}

.badge--type {
  background: rgba(91,155,213,0.1);
  color: var(--color-accent);
}

.badge--status-idle {
  background: rgba(136,150,167,0.12);
  color: var(--color-text-muted);
}

.badge--status-running {
  background: rgba(91,155,213,0.12);
  color: var(--color-accent);
}

.badge--status-completed {
  background: rgba(46,173,75,0.12);
  color: var(--color-success);
}

.badge--status-error {
  background: rgba(220,38,38,0.12);
  color: var(--color-danger);
}


/* ==========================================================================
   TABLE ACTION BUTTONS
   ========================================================================== */

.tbl-btn {
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: var(--text-xs);
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.tbl-btn--edit {
  color: var(--color-accent);
  border-color: rgba(91,155,213,0.3);
}

.tbl-btn--edit:hover {
  background: rgba(91,155,213,0.1);
  border-color: var(--color-accent);
}

.tbl-btn--del {
  color: var(--color-danger);
  border-color: rgba(220,38,38,0.3);
}

.tbl-btn--del:hover {
  background: rgba(220,38,38,0.1);
  border-color: var(--color-danger);
}


/* ==========================================================================
   POWERED-BY FOOTER TEXT
   ========================================================================== */

.powered-by-text {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: 1.5;
}


/* ==========================================================================
   PIPELINE STATUS BAR
   ========================================================================== */

.pipeline-status {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  margin: var(--space-3) 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}

.pipeline-status--idle { border-color: var(--color-border); }
.pipeline-status--starting,
.pipeline-status--running { border-color: rgba(91,155,213,0.4); background: rgba(91,155,213,0.05); }
.pipeline-status--completed { border-color: rgba(46,173,75,0.4); background: rgba(46,173,75,0.05); }
.pipeline-status--failed { border-color: rgba(220,38,38,0.4); background: rgba(220,38,38,0.05); }

.pipeline-status__icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.pipeline-status--idle .pipeline-status__icon { color: var(--color-text-muted); }
.pipeline-status--starting .pipeline-status__icon,
.pipeline-status--running .pipeline-status__icon { color: var(--color-accent); }
.pipeline-status--completed .pipeline-status__icon { color: var(--color-success); }
.pipeline-status--failed .pipeline-status__icon { color: var(--color-danger); }

.pipeline-status__info { flex: 1; min-width: 0; }

.pipeline-status__label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
}

.pipeline-status__detail {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pipeline-status__bar {
  width: 100%;
  height: 3px;
  background: rgba(91,155,213,0.15);
  border-radius: 2px;
  overflow: hidden;
  margin-top: var(--space-2);
}

.pipeline-status__progress {
  height: 100%;
  width: 30%;
  background: var(--color-accent);
  border-radius: 2px;
  animation: pipeline-progress 1.5s ease-in-out infinite;
}

.pipeline-status__progress--determinate {
  animation: none;
  transition: width 0.5s ease;
}

@keyframes pipeline-progress {
  0% { transform: translateX(-100%); width: 30%; }
  50% { width: 60%; }
  100% { transform: translateX(350%); width: 30%; }
}

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

.spin-icon {
  animation: spin-icon 1s linear infinite;
}

.pipeline-error-btn {
  flex-shrink: 0;
}


/* ==========================================================================
   PIPELINE ERROR LOG DIALOG
   ========================================================================== */

.modal--wide {
  max-width: 720px;
  width: 90vw;
}

.pipeline-error-log {
  max-height: 400px;
  overflow: auto;
  padding: var(--space-3);
  background: var(--sidebar-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: #fca5a5;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.5;
}

.pipeline-error-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
}


/* ==========================================================================
   Branding / Color Picker Styles
   ========================================================================== */

.admin-form__field--color {
  margin-bottom: 1.25rem;
}

.admin-form__color-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.admin-form__color-picker {
  width: 44px;
  height: 36px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 2px;
  cursor: pointer;
  background: transparent;
}

.admin-form__input--hex {
  width: 110px;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.admin-form__input--sm {
  padding: 0.4rem 0.6rem;
  font-size: var(--text-sm);
}

.admin-form__hint {
  display: block;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

.admin-form__preview {
  margin-bottom: 0.5rem;
}

.admin-form__btn--secondary {
  background: var(--color-surface-raised);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.admin-form__btn--secondary:hover {
  background: var(--color-border-light);
}


/* ==========================================================================
   Toggle Switch (for licensing)
   ========================================================================== */

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-switch__slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--color-border);
  transition: 200ms;
  border-radius: 24px;
}

.toggle-switch__slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 200ms;
  border-radius: 50%;
}

.toggle-switch input:checked + .toggle-switch__slider {
  background-color: var(--color-success);
}

.toggle-switch input:checked + .toggle-switch__slider::before {
  transform: translateX(20px);
}


/* ==========================================================================
   Monitoring Dashboard
   ========================================================================== */

.monitoring {
  padding: var(--space-4) var(--space-6);
  max-width: 1400px;
  margin: 0 auto;
}

.monitoring__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
  gap: var(--space-3);
}

.monitoring__title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-text);
}

/* Controls row (timezone + period selector) */
.monitoring__controls {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

/* Period Selector */
.monitoring__period-selector {
  display: flex;
  gap: 2px;
  background: var(--color-surface-raised);
  border-radius: 8px;
  padding: 3px;
  border: 1px solid var(--color-border-light);
}

.monitoring__period-btn {
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 500;
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.monitoring__period-btn:hover {
  background: var(--color-surface);
  color: var(--color-text);
}

.monitoring__period-btn--active {
  background: var(--color-primary);
  color: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.monitoring__period-btn--active:hover {
  background: var(--color-primary-dark);
  color: #fff;
}

/* Status Cards */
.monitoring__status-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.mon-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--color-surface);
  border-radius: 10px;
  border: 1px solid var(--color-border-light);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  transition: box-shadow 0.15s ease;
}

.mon-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.mon-card__icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.mon-card__icon svg {
  width: 22px;
  height: 22px;
}

.mon-card--gpu .mon-card__icon {
  background: rgba(232, 93, 38, 0.1);
  color: #E85D26;
}

.mon-card--gpu-mem .mon-card__icon {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

.mon-card--cpu .mon-card__icon {
  background: rgba(91, 155, 213, 0.1);
  color: #5B9BD5;
}

.mon-card--memory .mon-card__icon {
  background: rgba(139, 92, 246, 0.1);
  color: #8b5cf6;
}

.mon-card--requests .mon-card__icon {
  background: rgba(16, 185, 129, 0.1);
  color: #10b981;
}

.mon-card__content {
  min-width: 0;
}

.mon-card__label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.mon-card__value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.2;
}

.mon-card__sub {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  margin-top: 2px;
}

/* Sections */
.monitoring__section {
  margin-bottom: var(--space-6);
}

.monitoring__section-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 2px solid var(--color-border-light);
}

.monitoring__section-icon {
  width: 20px;
  height: 20px;
  color: var(--color-primary);
}

/* Chart Rows */
.monitoring__charts-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.monitoring__chart-container {
  background: var(--color-surface);
  border-radius: 10px;
  border: 1px solid var(--color-border-light);
  padding: var(--space-3) var(--space-4);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.monitoring__chart-header {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
}

.monitoring__chart-wrap {
  position: relative;
  height: 220px;
}

/* Cost Cards */
.monitoring__cost-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.mon-cost-card {
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border-radius: 10px;
  border: 1px solid var(--color-border-light);
  text-align: center;
}

.mon-cost-card__label {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.mon-cost-card__value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text);
}

.mon-cost-card__value--cost {
  color: var(--color-success);
}

/* Tables */
.monitoring__table-container {
  background: var(--color-surface);
  border-radius: 10px;
  border: 1px solid var(--color-border-light);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  overflow-x: auto;
}

.monitoring__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.monitoring__table th {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  font-weight: 600;
  color: var(--color-text-secondary);
  border-bottom: 2px solid var(--color-border-light);
  white-space: nowrap;
}

.monitoring__table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border-light);
  color: var(--color-text);
}

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

.monitoring__table-empty {
  text-align: center;
  color: var(--color-text-muted);
  padding: var(--space-4) !important;
  font-style: italic;
}

.monitoring__bar-cell {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.monitoring__bar {
  height: 6px;
  background: var(--color-primary);
  border-radius: 3px;
  min-width: 2px;
  transition: width 0.3s ease;
}

/* Insights */
.monitoring__insights {
  background: var(--color-surface);
  border-radius: 10px;
  border: 1px solid var(--color-border-light);
  padding: var(--space-3) var(--space-4);
}

.monitoring__insights-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-top: var(--space-2);
}

.monitoring__insights-empty {
  color: var(--color-text-muted);
  font-style: italic;
  text-align: center;
  padding: var(--space-3);
}

.monitoring__insight {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--color-surface-raised);
  border-radius: 8px;
  border-left: 3px solid var(--color-primary);
}

.monitoring__insight-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  color: var(--color-primary);
}

.monitoring__insight-icon svg {
  width: 100%;
  height: 100%;
}

.monitoring__insight-text {
  font-size: 0.875rem;
  color: var(--color-text-secondary);
  line-height: 1.5;
}

.monitoring__insight-text strong {
  color: var(--color-text);
}

/* Load Testing */
.monitoring__loadtest-form {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: flex-end;
  margin-bottom: var(--space-3);
}

.monitoring__loadtest-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.monitoring__loadtest-field label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.monitoring__loadtest-input {
  width: 100px;
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 0.875rem;
}

.monitoring__loadtest-field--toggle {
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
  padding-bottom: 4px;
}

.monitoring__loadtest-field--actions {
  flex-direction: row;
  gap: var(--space-2);
  padding-bottom: 0;
}

.monitoring__loadtest-info {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
}

.monitoring__loadtest-status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-2);
}

.monitoring__loadtest-status-label {
  font-weight: 600;
  font-size: 0.9rem;
}

.monitoring__loadtest-elapsed {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
}

.monitoring__loadtest-progress {
  height: 6px;
  background: var(--color-border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: var(--space-4);
}

.monitoring__loadtest-progress-bar {
  height: 100%;
  background: var(--color-primary, #E85D26);
  border-radius: 3px;
  transition: width 0.5s ease;
}

.monitoring__loadtest-results {
  margin-top: var(--space-4);
}

/* Responsive */
@media (max-width: 900px) {
  .monitoring {
    padding: var(--space-3);
  }

  .monitoring__header {
    flex-direction: column;
    align-items: stretch;
  }

  .monitoring__period-selector {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .monitoring__charts-row {
    grid-template-columns: 1fr;
  }

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

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

@media (max-width: 600px) {
  .monitoring__status-cards {
    grid-template-columns: 1fr;
  }

  .monitoring__cost-cards {
    grid-template-columns: 1fr;
  }
}

/* Per-GPU blocks */
.monitoring__gpu-block {
  margin-bottom: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-raised);
  border-radius: 10px;
  border: 1px solid var(--color-border-light);
}

.monitoring__gpu-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-3);
}

.monitoring__gpu-vendor {
  font-size: 0.7rem;
  font-weight: 500;
  padding: 2px 8px;
  background: var(--color-primary);
  color: #fff;
  border-radius: 4px;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* No-data overlay for empty charts */
.monitoring__no-data {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(245, 247, 250, 0.85);
  color: var(--color-text-muted);
  font-size: 0.85rem;
  font-style: italic;
  border-radius: 8px;
  z-index: 2;
  pointer-events: none;
}

/* ── 2FA Setup Steps ───────────────────────────────────────────────────── */

.tfa-steps {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tfa-step {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--color-text-muted, #94a3b8);
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm, 6px);
  background: rgba(255,255,255,0.03);
  border: 1px solid transparent;
}

.tfa-step--active {
  color: var(--color-helix-orange, #E85D26);
  background: rgba(232,93,38,0.08);
  border-color: rgba(232,93,38,0.3);
  font-weight: 600;
}

.tfa-step--done {
  color: #4ade80;
  background: rgba(74,222,128,0.08);
  border-color: rgba(74,222,128,0.2);
}

.tfa-step__num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  background: rgba(255,255,255,0.1);
}

.tfa-step--active .tfa-step__num {
  background: var(--color-helix-orange, #E85D26);
  color: #fff;
}

.tfa-step--done .tfa-step__num {
  background: #4ade80;
  color: #000;
}

/* ── Recovery Codes ────────────────────────────────────────────────────── */

.recovery-warning {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 1rem;
  background: rgba(250,204,21,0.08);
  border: 1px solid rgba(250,204,21,0.3);
  border-radius: var(--radius-sm, 6px);
  color: #fde68a;
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 1rem;
}

.recovery-codes-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.recovery-code {
  font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
  font-size: 1rem;
  letter-spacing: 0.1em;
  padding: 0.6rem 1rem;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm, 6px);
  color: #e2e8f0;
  text-align: center;
}

/* ── Setting field description text ────────────────────────────────────── */

.admin-form__desc {
  font-size: 0.8rem;
  color: var(--color-text-muted, #94a3b8);
  margin: 0.125rem 0 0.375rem 0;
  line-height: 1.4;
}
