/* ===========================================================
   Sidebar — Upranke v2
   Self-contained: relies only on tokens already defined in
   index.html :root (--bg, --surface, --accent, --text-*, etc.)
   Loaded after the inline <style> block so it overrides
   legacy .sb-sec / .sb-lbl / .ni rules in index.html.
   =========================================================== */

/* Local sidebar-scoped tokens (additive only — won't clobber globals) */
.sidebar {
  --sb-bg-deep: #070A14;
  --sb-section-color: var(--accent);

  width: var(--sw, 240px);
  background: linear-gradient(180deg, var(--bg) 0%, var(--sb-bg-deep) 100%);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
  overflow-y: auto;
  position: relative;
}

.sidebar::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 200px;
  background: radial-gradient(ellipse at top, var(--accent-glow) 0%, transparent 70%);
  opacity: 0.4;
  pointer-events: none;
  z-index: 0;
}

.sidebar > * {
  position: relative;
  z-index: 1;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 2px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: rgba(139, 92, 246, 0.5); }

/* ── Logo block ───────────────────────────────────────────── */
.sidebar__logo {
  padding: 22px 18px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.sidebar__logo-img {
  height: 44px;
  max-width: 200px;
  width: auto;
  object-fit: contain;
}

.sidebar__logo-fallback {
  font-family: var(--fh);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
}

/* ── Selectors (Client / Brand) ───────────────────────────── */
.sidebar__selectors {
  padding: 16px 14px 8px;
  display: grid;
  gap: 12px;
}

.selector-group { display: flex; flex-direction: column; }

.selector-label {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-d);
  margin-bottom: 5px;
  padding: 0 4px;
}

.sidebar .selector {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--text);
  font-family: var(--fb);
  font-size: 12px;
  font-weight: 500;
  width: 100%;
  cursor: pointer;
  appearance: none;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

.sidebar .selector:hover,
.sidebar .selector:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ── Nav sections ─────────────────────────────────────────── */
.sidebar__nav {
  padding: 6px 0;
  flex: 1;
}

.sidebar .sb-section {
  padding: 4px 0;
}

.sidebar .sb-section__label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--fh);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-d);
  padding: 14px 18px 6px;
}

.sidebar .sb-section__label::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--sb-section-color);
  box-shadow: 0 0 8px var(--sb-section-color);
}

.sidebar .sb-section--main             { --sb-section-color: var(--accent); }
.sidebar .sb-section--clients          { --sb-section-color: var(--cyan); }
.sidebar .sb-section--analysis         { --sb-section-color: var(--green); }
.sidebar .sb-section--intelligence     { --sb-section-color: var(--pink); }
.sidebar .sb-section--tools            { --sb-section-color: var(--amber); }
.sidebar .sb-section--brand-clients    { --sb-section-color: var(--cyan); }
.sidebar .sb-section--brand-intelligence { --sb-section-color: var(--pink); }

/* Conditional sections: hidden until JS toggles them when a Client / D2C
   Brand is selected. Always-on sections (MAIN, CLIENTS, INTELLIGENCE,
   AI TOOLS) carry no modifier and stay visible. */
.sidebar .sb-section.sidebar-brand   { display: none; }
.sidebar .sb-section.sidebar-generic { display: none; }

/* ── Nav items ────────────────────────────────────────────── */
.sidebar .ni {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 18px;
  margin: 1px 10px 1px 0;
  border-radius: 0 8px 8px 0;
  border-left: 3px solid transparent;
  color: var(--text-m);
  cursor: pointer;
  user-select: none;
  font-family: var(--fb);
  font-size: 13px;
  font-weight: 400;
  background: transparent;
  transition: background 0.18s, color 0.18s, transform 0.18s, border-left-color 0.18s;
}

.sidebar .ni:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  transform: translateX(2px);
  border-left-color: var(--sb-section-color);
}

.sidebar .ni.active,
.sidebar .ni--active {
  color: var(--text);
  font-weight: 500;
  border-left-color: var(--sb-section-color);
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--sb-section-color) 14%, transparent),
    transparent
  );
  box-shadow: inset 8px 0 24px -16px var(--sb-section-color);
}

/* Fallback for browsers without color-mix support */
@supports not (background: color-mix(in srgb, red, blue)) {
  .sidebar .sb-section--main .ni.active,
  .sidebar .sb-section--main .ni--active            { background: linear-gradient(90deg, var(--accent-dim), transparent); }
  .sidebar .sb-section--clients .ni.active,
  .sidebar .sb-section--clients .ni--active         { background: linear-gradient(90deg, var(--cyan-dim), transparent); }
  .sidebar .sb-section--analysis .ni.active,
  .sidebar .sb-section--analysis .ni--active        { background: linear-gradient(90deg, var(--green-dim), transparent); }
  .sidebar .sb-section--intelligence .ni.active,
  .sidebar .sb-section--intelligence .ni--active    { background: linear-gradient(90deg, var(--pink-dim), transparent); }
  .sidebar .sb-section--tools .ni.active,
  .sidebar .sb-section--tools .ni--active           { background: linear-gradient(90deg, var(--amber-dim), transparent); }
}

.sidebar .ni-ic {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: currentColor;
  opacity: 0.7;
  transition: opacity 0.18s;
}

.sidebar .ni:hover .ni-ic,
.sidebar .ni.active .ni-ic,
.sidebar .ni--active .ni-ic { opacity: 1; }

.sidebar .ni__label { flex: 1; }

/* Badge replaces the legacy .nb / .nb-b / .nb-a / .nb-g */
.sidebar .ni__badge {
  margin-left: auto;
  padding: 2px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: var(--fm);
  font-size: 10px;
  font-weight: 600;
  color: var(--text-m);
  line-height: 1.4;
}

.sidebar .ni__badge--accent { background: var(--accent-dim); color: var(--accent2); border-color: transparent; }
.sidebar .ni__badge--green  { background: var(--green-dim);  color: var(--green);   border-color: transparent; }
.sidebar .ni__badge--amber  { background: var(--amber-dim);  color: var(--amber);   border-color: transparent; }
.sidebar .ni__badge--cyan   { background: var(--cyan-dim);   color: var(--cyan);    border-color: transparent; }

.sidebar .ni__badge--new {
  background: var(--green-dim);
  color: var(--green);
  border-color: transparent;
  font-size: 9px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 2px 6px;
}

.sidebar .ni.active .ni__badge,
.sidebar .ni--active .ni__badge {
  background: color-mix(in srgb, var(--sb-section-color) 22%, transparent);
  color: var(--text);
  border-color: transparent;
}

/* ── Profile (replaces legacy .sb-foot / .u-row) ──────────── */
.sb-profile {
  margin-top: auto;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 11px;
  cursor: pointer;
  background: transparent;
  transition: background 0.18s;
}

.sb-profile:hover { background: var(--surface); }

.sb-profile__avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--fh);
  font-weight: 700;
  font-size: 12px;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px var(--bg), 0 0 12px var(--accent-glow);
}

.sb-profile__info { flex: 1; min-width: 0; overflow: hidden; }

.sb-profile__name {
  font-family: var(--fh);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb-profile__status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-d);
}

.sb-profile__logout-icon {
  width: 14px;
  height: 14px;
  color: var(--text-d);
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.18s;
}

.sb-profile:hover .sb-profile__logout-icon { opacity: 1; color: var(--text-m); }

/* ── Status dot (live API health) ─────────────────────────── */
.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  animation: sb-pulse 2s ease-in-out infinite;
  flex-shrink: 0;
}

.status-dot--amber { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.status-dot--red   { background: var(--red);   box-shadow: 0 0 8px var(--red);   }

@keyframes sb-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.55; transform: scale(0.8); }
}

/* Role-gated nav items — hidden when the active user is not an admin.
   Toggled by public/js/sidebar.js#applyRoleVisibility(). */
.sidebar .ni--admin-hidden { display: none; }
