/* ============================================================
   CDL Co-Pilot — App Shell v2
   ------------------------------------------------------------
   Every selector is scoped under body.shell-v2-active so this
   stylesheet is safe to load on any page. When the shell is
   not mounted, this file is a no-op.

   Existing tokens (--color-primary, --color-accent, etc.) come
   from style.css. We add v2-specific tokens here, prefixed with
   --shell-* to avoid name collisions with future page-level CSS.
   ============================================================ */

body.shell-v2-active {
  /* === v2 design tokens === */
  --shell-text: #0f1115;
  --shell-text-secondary: #4a4f5a;
  --shell-text-tertiary: #7c8290;
  --shell-bg: #fafafb;
  --shell-border: #e7e8ec;
  --shell-border-strong: #d6d8de;

  --shell-shadow-1: 0 1px 2px rgba(15,17,21,0.04), 0 1px 1px rgba(15,17,21,0.02);
  --shell-shadow-2: 0 2px 6px rgba(15,17,21,0.06), 0 1px 2px rgba(15,17,21,0.04);
  --shell-shadow-3: 0 8px 24px rgba(15,17,21,0.08), 0 2px 6px rgba(15,17,21,0.04);

  --shell-r-md: 10px;
  --shell-r-lg: 14px;
  --shell-r-pill: 999px;

  --shell-ease: cubic-bezier(0.2, 0, 0, 1);
  --shell-dur: 180ms;

  --shell-top-h: 56px;
  --shell-bottom-h: 64px;
  --shell-max-w: 1280px;

  --shell-good: #1b9b5e;
  --shell-warn: #c87a05;
  --shell-bad: #c7384a;

  /* Body now uses Inter (system fallback retained) */
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--shell-bg);
  color: var(--shell-text);
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.005em;
}

/* Reserve space for fixed/sticky chrome */
body.shell-v2-active.shell-has-bottom-nav { padding-bottom: var(--shell-bottom-h); }

/* Pages opt their legacy header out of the layout when shell is active */
body.shell-v2-active [data-legacy-header] { display: none !important; }

/* ============================================================
   TOP BAR
   ============================================================ */
.shell-v2-active .shell-top {
  position: sticky; top: 0; z-index: 100;
  height: var(--shell-top-h);
  background: rgba(255,255,255,0.85);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--shell-border);
}
.shell-v2-active .shell-top-inner {
  max-width: var(--shell-max-w); margin: 0 auto;
  height: 100%;
  padding: 0 24px;
  display: flex; align-items: center; gap: 24px;
}
.shell-v2-active .shell-logo {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 14px;
  letter-spacing: -0.02em;
  color: var(--shell-text);
  text-decoration: none;
}
.shell-v2-active .shell-logo .logo-mark {
  width: 26px; height: 26px;
  background: var(--color-primary);
  border-radius: 7px;
  display: grid; place-items: center;
  color: #fff; font-size: 12px; font-weight: 800;
}
.shell-v2-active .shell-nav { display: flex; gap: 2px; }
.shell-v2-active .shell-nav a {
  padding: 8px 12px;
  font-size: 13px; font-weight: 500;
  color: var(--shell-text-secondary);
  border-radius: var(--shell-r-md);
  text-decoration: none;
  transition: all var(--shell-dur) var(--shell-ease);
}
.shell-v2-active .shell-nav a:hover { color: var(--shell-text); background: var(--color-primary-light); }
.shell-v2-active .shell-nav a.active { color: var(--color-primary); background: var(--color-primary-light); font-weight: 600; }

/* Global search — sits in the pinned top bar, between nav and the right cluster */
.shell-v2-active .shell-search {
  flex: 1 1 auto; max-width: 380px; min-width: 140px;
  display: flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 11px;
  background: rgba(255,255,255,0.6);
  border: 1px solid var(--shell-border);
  border-radius: 9px;
  transition: border-color var(--shell-dur) var(--shell-ease), box-shadow var(--shell-dur) var(--shell-ease), background var(--shell-dur) var(--shell-ease);
}
.shell-v2-active .shell-search:focus-within {
  background: #fff; border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(50,39,108,0.10);
}
.shell-v2-active .shell-search-ic { font-size: 16px; color: var(--shell-text-secondary); line-height: 1; opacity: 0.7; }
.shell-v2-active .shell-search-input {
  flex: 1; min-width: 0; border: none; background: none; outline: none;
  font-size: 13.5px; color: var(--shell-text); font-family: inherit;
}
.shell-v2-active .shell-search-input::placeholder { color: var(--shell-text-secondary); opacity: 0.85; }
.shell-v2-active .shell-search-clear {
  border: none; background: none; cursor: pointer; font-size: 17px;
  color: var(--shell-text-secondary); line-height: 1; padding: 0 2px;
}
.shell-v2-active .shell-search-clear:hover { color: var(--shell-text); }

.shell-v2-active .shell-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }

.shell-v2-active .shell-context {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px 5px 8px;
  background: #fff;
  border: 1px solid var(--shell-border);
  border-radius: var(--shell-r-pill);
  font-size: 12px; color: var(--shell-text-secondary);
  cursor: pointer;
  transition: all var(--shell-dur) var(--shell-ease);
  max-width: 280px;
  font-family: inherit;
}
.shell-v2-active .shell-context:hover { border-color: var(--shell-border-strong); box-shadow: var(--shell-shadow-1); }
.shell-v2-active .shell-context .ctx-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--shell-good); flex-shrink: 0;
}
.shell-v2-active .shell-context .ctx-text {
  font-weight: 500; color: var(--shell-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.shell-v2-active .shell-context .ctx-chev { color: var(--shell-text-tertiary); font-size: 10px; }

.shell-v2-active .shell-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  color: #fff; font-size: 12px; font-weight: 700;
  display: grid; place-items: center;
  cursor: pointer;
  border: none;
  transition: transform var(--shell-dur) var(--shell-ease);
}
.shell-v2-active .shell-avatar:hover { transform: scale(1.05); }

.shell-v2-active .shell-btn {
  padding: 7px 13px;
  background: #fff;
  border: 1px solid var(--shell-border);
  border-radius: var(--shell-r-md);
  font-size: 13px; font-weight: 500; color: var(--shell-text);
  cursor: pointer;
  font-family: inherit;
  transition: all var(--shell-dur) var(--shell-ease);
  text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
}
.shell-v2-active .shell-btn:hover { border-color: var(--shell-border-strong); box-shadow: var(--shell-shadow-1); }
.shell-v2-active .shell-btn.primary { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.shell-v2-active .shell-btn.primary:hover { background: var(--color-primary-hover); box-shadow: var(--shell-shadow-2); }
.shell-v2-active .shell-btn.ghost { background: transparent; border-color: transparent; color: var(--shell-text-secondary); }
.shell-v2-active .shell-btn.ghost:hover { background: var(--color-primary-light); color: var(--color-primary); }

/* === Anonymous variant === */
.shell-v2-active .shell-top.anon .shell-nav,
.shell-v2-active .shell-top.anon .shell-context,
.shell-v2-active .shell-top.anon .shell-avatar { display: none; }

/* ============================================================
   BREADCRUMB
   ============================================================ */
.shell-v2-active .shell-bcrumb {
  max-width: var(--shell-max-w);
  margin: 0 auto;
  padding: 16px 24px 0;
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--shell-text-tertiary);
}
.shell-v2-active .shell-bcrumb a {
  color: var(--shell-text-tertiary);
  text-decoration: none;
  transition: color var(--shell-dur) var(--shell-ease);
}
.shell-v2-active .shell-bcrumb a:hover { color: var(--color-primary); }
.shell-v2-active .shell-bcrumb .sep { opacity: 0.5; }
.shell-v2-active .shell-bcrumb .current { color: var(--shell-text); font-weight: 500; }

/* ============================================================
   MOBILE BOTTOM NAV
   ============================================================ */
.shell-v2-active .shell-bottom {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--shell-bottom-h);
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--shell-border);
  display: none;
  grid-template-columns: repeat(4, 1fr);
  z-index: 99;
  padding-bottom: env(safe-area-inset-bottom);
}
.shell-v2-active .shell-bottom a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-size: 10px; font-weight: 600;
  color: var(--shell-text-tertiary);
  text-decoration: none;
  transition: color var(--shell-dur) var(--shell-ease);
}
.shell-v2-active .shell-bottom a.active { color: var(--color-primary); }
.shell-v2-active .shell-bottom a .ic { width: 22px; height: 22px; display: grid; place-items: center; font-size: 17px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  body.shell-v2-active { padding-bottom: var(--shell-bottom-h); }
  .shell-v2-active .shell-top-inner { padding: 0 16px; gap: 12px; }
  .shell-v2-active .shell-nav { display: none; }
  .shell-v2-active .shell-context { max-width: 180px; }
  .shell-v2-active .shell-context .ctx-chev { display: none; }
  .shell-v2-active .shell-bottom { display: grid; }
  .shell-v2-active .shell-bcrumb { padding: 12px 16px 0; }
}
