/* ── Shell ──────────────────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Top nav ────────────────────────────────────────────────────────── */
.nav {
  height: 64px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 32px;
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--glass-nav);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border-bottom: 1px solid var(--border-soft);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 20px;
  letter-spacing: -0.01em;
  color: var(--text);
  white-space: nowrap;
}
.nav-brand-logo { display: block; flex-shrink: 0; filter: drop-shadow(0 4px 8px rgba(124, 58, 237, 0.45)); }
.nav-brand-text { color: var(--text); }
.nav-brand-accent { background: linear-gradient(135deg, #C0A6FF 0%, #7C3AED 100%); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }

.nav-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.nav-tab {
  position: relative;
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  color: var(--subtext);
  background: none;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: color var(--transition), background var(--transition);
}
.nav-tab .tab-icon { opacity: 0.7; transition: opacity var(--transition); }
.nav-tab:hover { color: var(--text); }
.nav-tab:hover .tab-icon { opacity: 1; }
.nav-tab.active { color: var(--text); }
.nav-tab.active .tab-icon { opacity: 1; }
/* Underline ticker */
.nav-tab.active::after {
  content: '';
  position: absolute;
  left: 14px; right: 14px; bottom: -4px;
  height: 2px;
  background: var(--primary-soft);
  border-radius: 2px;
  box-shadow: 0 0 12px rgba(210, 187, 255, 0.55);
}

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

/* Profile chip on the far right */
.nav-profile {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px 12px 4px 4px;
  border-radius: var(--radius-pill);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.nav-profile:hover { background: var(--surface1); border-color: var(--border-soft); }
.nav-profile-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5254DF 0%, #7C3AED 100%);
  color: var(--primary-bright);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-ui);
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

/* Icon-only header buttons (theme, chat) */
.nav-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: transparent;
  border: 1px solid transparent;
  color: var(--subtext);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: color var(--transition), background var(--transition), border-color var(--transition);
}
.nav-icon-btn:hover { color: var(--text); background: var(--surface1); border-color: var(--border-soft); }
.nav-icon-btn.active { color: var(--text); background: var(--surface1); border-color: var(--border-soft); }
.nav-icon-btn .status-dot {
  position: absolute;
  top: 7px; right: 7px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--subtext0);
  box-shadow: 0 0 0 2px var(--base);
}

/* ── Dashboard shell: main + permanent right rail ───────────────────── */
.dashboard-shell {
  --rail-width: 320px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--rail-width);
  align-items: stretch;
  width: 100%;
  min-height: calc(100vh - 64px);
}
.dashboard-shell.rail-hidden { grid-template-columns: minmax(0, 1fr); }

.main {
  padding: 32px 32px 48px;
  min-width: 0;
  width: 100%;
}

.view { display: none; }
.view.active { display: block; }

/* Common section heading — used by Pipeline, Discover, Portals, Analytics */
.section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}
/* Pages that compose multiple sections in a flex column (Pipeline shell)
   handle vertical rhythm via container `gap` and don't need the bottom
   margin. Apply this modifier to opt out. */
.section-header.no-mb { margin-bottom: 0; }
.section-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 32px;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--text);
  margin: 0;
}
.section-sub {
  margin: 4px 0 0 0;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--subtext);
}
/* Right-side action / stat cluster. Same shape across all pages so
   buttons + stat pills line up consistently. */
.section-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Grid helpers (kept for legacy callers) */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 16px; }

/* ── Right rail (chat / terminal) ────────────────────────────────────── */
.terminal-drawer {
  position: sticky;
  top: 64px;
  align-self: start;
  height: calc(100vh - 64px);
  width: 100%;
  display: flex;
  flex-direction: column;
  background: var(--glass-rail);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-rail);
  z-index: 50;
}

/* Drag-to-resize grip — thin invisible strip on the left edge of the rail
   that turns purple on hover/drag. Touches the column edge so the user can
   widen / narrow the chat panel. */
.terminal-resize-handle {
  position: absolute;
  z-index: 51;
  top: 0; left: -3px; bottom: 0; width: 6px;
  background: transparent;
  cursor: ew-resize;
  transition: background 120ms ease;
}
.terminal-resize-handle:hover,
.terminal-resize-handle.dragging { background: var(--primary); opacity: 0.45; }

.terminal-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  gap: 12px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
  min-height: 73px;
}

.rail-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.rail-brand-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #8B5CF6 0%, #5254DF 100%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--primary-bright);
  flex-shrink: 0;
  box-shadow: 0 6px 18px rgba(124, 58, 237, 0.4);
}
.rail-brand-text { display: flex; flex-direction: column; min-width: 0; }
.rail-brand-name {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.05em;
  color: var(--text);
}
.rail-brand-model {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 10px;
  color: var(--subtext);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Agent switcher tucked into the rail header. The Figma pill called for
   a tiny static label, but a real <select> wins — users actually swap
   agents from here. Sized to feel like a small chip with a chevron. */
select.terminal-header-agent {
  background: var(--surface1);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 26px 4px 10px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%23CCC3D8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><path d='M2 2 L6 6 L10 2'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 10px;
  max-width: 170px;
  cursor: pointer;
  margin-top: 4px;
  transition: background var(--transition), border-color var(--transition);
}
select.terminal-header-agent:hover { background: var(--surface2); border-color: var(--border); }
select.terminal-header-agent option { background: var(--mantle); color: var(--text); }

.terminal-view-toggle {
  display: inline-flex;
  align-items: center;
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 4px;
  gap: 4px;
}
.terminal-view-btn {
  border: none;
  background: transparent;
  color: var(--subtext);
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  text-transform: uppercase;
}
.terminal-view-btn:hover { color: var(--text); }
.terminal-view-btn.active {
  background: var(--primary);
  color: var(--primary-bright);
  font-weight: 700;
}

.terminal-content {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

.chat-pane,
.terminal-body { flex: 1; min-height: 0; }
.chat-pane { display: none; height: 100%; min-width: 0; }
.terminal-body { overflow: hidden; padding: 4px; min-width: 0; }

/* Empty state used across views */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--subtext);
  font-size: 14px;
}
.empty-state h3 {
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 18px;
}
.empty-state p { font-size: 14px; }

/* ── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 1180px) {
  .dashboard-shell { grid-template-columns: minmax(0, 1fr); }
  .terminal-drawer {
    position: fixed;
    top: 64px;
    right: 0;
    bottom: 0;
    height: auto;
    transform: translateX(100%);
    transition: transform 220ms ease;
  }
  .terminal-drawer.is-open { transform: translateX(0); }
}

@media (max-width: 720px) {
  .nav { padding: 0 16px; gap: 16px; }
  .nav-tabs { gap: 0; }
  .nav-tab { padding: 8px 10px; }
  .main { padding: 20px 16px 32px; }
  .section-title { font-size: 24px; }
}
