/* ==========================================================================
   nav.css — Navigation System
   "Obsidian & Champagne" — myTradingMCP Luxury Edition

   Architecture:
     Global header  → pages globales + pages workspace
     Workspace bar  → pages workspace uniquement (portfolio / strategy / insights / orders)

   Variables de layout à mettre à jour dans tokens.css :
     --header-h            : 60px  (inchangé)
     --workspace-bar-h     : 46px  (nouvelle)
     --context-bar-h       : remplacé par --workspace-bar-h sur pages workspace
   ========================================================================== */

/* ==========================================================================
   1. VARIABLES SUPPLÉMENTAIRES
   ========================================================================== */

:root {
  --workspace-bar-h: 46px;
  --nav-sep-color: rgba(240, 237, 230, 0.09);
}

/* Sur pages workspace, la hauteur totale du chrome = header + workspace bar */
body.page-workspace {
  --context-bar-h: var(--workspace-bar-h);
}

/* ==========================================================================
   2. HEADER — Structure (complète layout.css)
   ========================================================================== */

/* Gold accent line preserved from layout.css — kept here for nav scope */
.site-header::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(201, 169, 110, 0.35), transparent);
  pointer-events: none;
}

/* ==========================================================================
   3. SITE NAV — Global navigation
   ========================================================================== */

.site-nav {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 0;
  min-width: 0;
}

/* ─── Global links group ─────────────────────────────────────────── */
.nav-global {
  display: flex;
  align-items: center;
  gap: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden; /* prevents overflow on small viewports */
}

/* Visual separator */
.nav-sep {
  width: 1px;
  height: 14px;
  background: var(--nav-sep-color);
  margin: 0 6px;
  flex-shrink: 0;
}

/* ─── Nav links ──────────────────────────────────────────────────── */
.nav-base {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.6rem;
  font-family: var(--font-sans);
  font-size: var(--text-xs, 0.6875rem);
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--color-text-muted);
  text-decoration: none;
  border-radius: var(--radius-sm, 4px);
  background: transparent;
  border: none;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--transition-base), background var(--transition-base);
  flex-shrink: 0;
}

.nav-base:hover {
  color: var(--color-text);
  background: rgba(255, 255, 255, 0.04);
}

/* Active state */
.nav-active {
  color: var(--color-text) !important;
}

/* System links — even more muted, smaller */
.nav-base--sys {
  font-size: 0.625rem;
  letter-spacing: 0.05em;
  color: var(--color-text-faint, rgba(240, 237, 230, 0.28));
  opacity: 0.8;
}

.nav-base--sys:hover {
  color: var(--color-text-muted);
  opacity: 1;
}

.nav-base--sys.nav-active {
  color: var(--color-text-muted) !important;
  opacity: 1;
}

/* ==========================================================================
   4. RIGHT CONTROLS
   ========================================================================== */

.nav-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  margin-left: auto;
  padding-left: 0.75rem;
}

/* ─── Workspace CTA (global pages only) ──────────────────────────── */
.nav-workspace-cta {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.75rem;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--color-accent, #C9A96E);
  text-decoration: none;
  border: 1px solid rgba(201, 169, 110, 0.25);
  border-radius: var(--radius-sm);
  background: rgba(201, 169, 110, 0.06);
  white-space: nowrap;
  transition:
    background var(--transition-base),
    border-color var(--transition-base),
    box-shadow var(--transition-base);
}

.nav-workspace-cta:hover {
  background: rgba(201, 169, 110, 0.12);
  border-color: rgba(201, 169, 110, 0.40);
  box-shadow: 0 0 0 3px rgba(201, 169, 110, 0.08);
}

.nav-workspace-cta svg {
  flex-shrink: 0;
  opacity: 0.8;
}

/* ─── Chat IA button ─────────────────────────────────────────────── */
.nav-chat-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.75rem;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--color-text-muted);
  background: transparent;
  border: 1px solid var(--color-border, rgba(240,237,230,0.08));
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition:
    background var(--transition-base),
    border-color var(--transition-base),
    color var(--transition-base);
}

.nav-chat-btn:hover {
  color: var(--color-text);
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--color-border-strong, rgba(240,237,230,0.18));
}

/* When chat is open, show active state */
.nav-chat-btn[aria-expanded="true"] {
  color: var(--color-accent);
  border-color: rgba(201, 169, 110, 0.35);
  background: rgba(201, 169, 110, 0.07);
}

/* ─── Status beacon ──────────────────────────────────────────────── */
.status {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.status-indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-faint);
  transition: background var(--transition-base), box-shadow var(--transition-base);
  flex-shrink: 0;
}

.status-indicator.up    { background: var(--color-success); box-shadow: 0 0 5px rgba(74, 222, 128, 0.5); }
.status-indicator.down  { background: var(--color-danger);  box-shadow: 0 0 5px rgba(248, 113, 113, 0.5); }
.status-indicator.unknown { background: var(--color-text-faint); }

/* ==========================================================================
   5. WORKSPACE BAR
   Replaces the former thin "context-bar" on portfolio / strategy / insights / orders
   ========================================================================== */

.workspace-bar {
  position: sticky;
  top: var(--header-h);
  z-index: 1100;
  height: var(--workspace-bar-h);
  background: rgba(14, 14, 18, 0.92);
  border-bottom: 1px solid var(--color-border-light);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  align-items: stretch;

  /* Gold left accent bar */
  position: sticky;
  box-shadow: inset 2px 0 0 rgba(201, 169, 110, 0.45);
}

.workspace-bar__inner {
  display: flex;
  align-items: stretch;
  gap: 0;
  height: 100%;
  width: min(var(--container-max), calc(100% - 2 * var(--container-gutter)));
  margin: 0 auto;
}

/* ─── Context selectors (injected by contextBar.js) ──────────────── */
.workspace-bar__context {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding-right: 1rem;
  flex-shrink: 0;
}

/* contextBar.js creates .ctx-group > .ctx-field > label + select */
.workspace-bar__context .ctx-group {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.workspace-bar__context .ctx-field {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.workspace-bar__context .ctx-label {
  font-family: var(--font-sans);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--color-text-faint);
  white-space: nowrap;
}

.workspace-bar__context .ctx-select,
.workspace-bar__context select {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.18rem 1.4rem 0.18rem 0.5rem;
  min-height: 26px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23786a52' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.4rem center;
  cursor: pointer;
  transition: border-color var(--transition-base), background var(--transition-base);
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.workspace-bar__context .ctx-select:focus,
.workspace-bar__context select:focus {
  outline: none;
  border-color: rgba(201, 169, 110, 0.40);
  box-shadow: 0 0 0 2px rgba(201, 169, 110, 0.10);
}

/* ─── Vertical separator ─────────────────────────────────────────── */
.workspace-bar__sep {
  width: 1px;
  background: var(--nav-sep-color);
  margin: 10px 0.85rem;
  flex-shrink: 0;
}

/* ─── Workspace tabs ─────────────────────────────────────────────── */
.workspace-bar__tabs {
  display: flex;
  align-items: stretch;
  gap: 0;
  height: 100%;
}

.workspace-tab {
  display: inline-flex;
  align-items: center;
  padding: 0 1rem;
  height: 100%;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.025em;
  color: var(--color-text-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color var(--transition-base), border-color var(--transition-base);
  position: relative;
}

.workspace-tab:hover {
  color: var(--color-text);
}

.workspace-tab--active {
  color: var(--color-accent, #C9A96E);
  border-bottom-color: var(--color-accent, #C9A96E);
}

/* Subtle hover indicator for inactive tabs */
.workspace-tab:not(.workspace-tab--active):hover::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0.5rem;
  right: 0.5rem;
  height: 1px;
  background: var(--color-border-strong);
}

/* ─── Workspace badge (far right) ────────────────────────────────── */
.workspace-badge {
  display: flex;
  align-items: center;
  margin-left: auto;
  padding-left: 1rem;
  font-family: var(--font-sans);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: rgba(201, 169, 110, 0.5);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ==========================================================================
   6. LAYOUT ADJUSTMENT — main content top padding
   ========================================================================== */

/* On workspace pages, the sticky workspace bar adds to the chrome height.
   layout.css uses calc(var(--header-h) + var(--context-bar-h) + space)
   which resolves correctly because we set --context-bar-h = --workspace-bar-h
   on body.page-workspace above. */

/* Additional visual: on workspace pages, reduce default top padding
   since the workspace bar already provides clear separation */
body.page-workspace #main-content {
  padding-top: calc(var(--header-h) + var(--workspace-bar-h) + var(--space-lg));
}

/* ==========================================================================
   7. RESPONSIVE
   ========================================================================== */

@media (max-width: 1100px) {
  /* Hide system links on medium viewports */
  .nav-base--sys { display: none; }
  .nav-sep:last-of-type { display: none; }
}

@media (max-width: 900px) {
  /* Workspace bar: hide badge, compress tabs */
  .workspace-badge { display: none; }
  .workspace-tab   { padding: 0 0.65rem; }

  /* Context selectors: shorten labels */
  .workspace-bar__context .ctx-label { display: none; }
  .workspace-bar__context .ctx-select,
  .workspace-bar__context select { max-width: 110px; }
}

@media (max-width: 720px) {
  /* Global nav: show only 3 most important items */
  .nav-base:not(:first-child):not(.nav-active) { display: none; }
  .nav-sep { display: none; }
  .nav-workspace-cta { display: none; }

  /* Workspace: stack context above tabs */
  .workspace-bar {
    height: auto;
    min-height: var(--workspace-bar-h);
  }

  .workspace-bar__inner {
    flex-wrap: wrap;
    padding: 0.3rem 0;
    height: auto;
  }

  .workspace-bar__context {
    width: 100%;
    padding: 0.3rem 0 0.25rem;
    border-bottom: 1px solid var(--color-border-light);
  }

  .workspace-bar__sep { display: none; }

  .workspace-bar__tabs {
    width: 100%;
    height: 36px;
  }

  .workspace-tab { font-size: 0.625rem; padding: 0 0.5rem; }
}

/* ==========================================================================
   8. PORTFOLIO PAGE — hide sim selector (kept from portfolio.css compat)
   ========================================================================== */

.page-portfolio .workspace-bar__context .ctx-field:nth-child(2) {
  display: none;
}

/* ==========================================================================
   9. HOVER STATE FOR NAV DURING WORKSPACE NAVIGATION
   On workspace pages, the global nav items feel slightly lighter —
   the workspace bar is the "active" navigation element.
   ========================================================================== */

body.page-workspace .nav-base:not(.nav-active) {
  opacity: 0.75;
}

body.page-workspace .nav-base:hover {
  opacity: 1;
}
