/*
 * kAInet Unified Shell — Creative Unification 2026-05-05 (CU-9).
 *
 * Shared chrome (header + left nav + active-brand / active-preset chips +
 * cross-engine hand-off CTAs) that turns the brand / kAIcreative /
 * kAIcontent / Library pages into a single product experience without
 * collapsing them into one mega-page.
 *
 * Loaded by every consenting template via a `<link>` to this file plus
 * the matching `kainet-unified-shell.js`. Templates declare opt-in by
 * adding `<div data-kainet-shell></div>` somewhere in their <body>.
 */

:root {
  --shell-bg:           #0b0d0f;
  --shell-fg:           #e7eaee;
  --shell-fg-dim:       #9ba3ab;
  --shell-border:       #1c2128;
  --shell-card:         #14181d;
  --shell-card-hover:   #1a2027;
  --shell-accent:       #f5a623; /* Von Restorff: only the active-brand chip uses this */
  --shell-accent-fg:    #1a1300;
  --shell-stale:        #d97706;
  --shell-stale-fg:     #fff7ed;
  --shell-radius:       10px;
  --shell-radius-sm:    6px;
  --shell-pad-x:        16px;
  --shell-pad-y:        10px;
  --shell-z-shell:      50;
  --shell-z-toast:      80;
}

/* Theme-aware chrome: on light pages (the app's canonical theme) the header
   should read as light to stay cohesive with the page, instead of a black bar
   floating over white content. Dark values above remain the fallback for
   pages that opt into dark via data-theme="dark". The Von Restorff accent
   (brand chip) is intentionally unchanged in both themes. */
html[data-theme="light"] {
  --shell-bg:           #ffffff;
  --shell-fg:           #161c26;
  --shell-fg-dim:       #6b7280;
  --shell-border:       #e5e7eb;
  --shell-card:         #f3f4f6;
  --shell-card-hover:   #e9ebef;
}

[data-kainet-shell-mounted] body {
  /* Reserve space for the fixed header so existing page content
     doesn't slip underneath. Only set after JS mount so JS-disabled
     fallbacks still show the original page intact. */
  padding-top: 56px;
}

.kainet-shell-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--shell-bg);
  color: var(--shell-fg);
  border-bottom: 1px solid var(--shell-border);
  display: flex;
  align-items: center;
  padding: 0 var(--shell-pad-x);
  gap: 12px;
  z-index: var(--shell-z-shell);
  font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 13px;
  letter-spacing: 0.01em;
}

.kainet-shell-brand {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.04em;
  color: var(--shell-fg);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.kainet-shell-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
}

.kainet-shell-nav a {
  display: inline-block;
  padding: 6px 12px;
  border-radius: var(--shell-radius-sm);
  color: var(--shell-fg-dim);
  text-decoration: none;
  transition: background 120ms ease, color 120ms ease;
}

.kainet-shell-nav a:hover {
  background: var(--shell-card-hover);
  color: var(--shell-fg);
}

.kainet-shell-nav a[aria-current="page"] {
  background: var(--shell-card);
  color: var(--shell-fg);
}

.kainet-shell-spacer {
  flex: 1 1 auto;
}

/* Discreet legal link — sits to the right of the active-brand chip on
   every shell page. Same compliance link surfaces from /legal and from
   the AI sub-processor change notification email. */
.kainet-shell-legal-link {
  font-size: 12px;
  color: var(--kainet-fg-muted, #6b7280);
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 6px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: background-color .12s ease, color .12s ease;
}
.kainet-shell-legal-link:hover {
  color: var(--kainet-fg, #111827);
  background-color: var(--kainet-row-stripe, #f3f4f6);
}

/* Active-brand chip — Von Restorff accent so the user always knows
   what brand they're operating in. Click switches to /brand. */
.kainet-shell-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--shell-card);
  color: var(--shell-fg);
  border: 1px solid var(--shell-border);
  border-radius: 999px;
  padding: 4px 12px 4px 4px;
  cursor: pointer;
  text-decoration: none;
  transition: background 120ms ease, border-color 120ms ease;
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
}

.kainet-shell-chip:hover {
  background: var(--shell-card-hover);
  border-color: #2a3038;
}

.kainet-shell-chip--brand {
  border-color: var(--shell-accent);
}

.kainet-shell-chip--brand:hover {
  border-color: var(--shell-accent);
  background: rgba(245, 166, 35, 0.10);
}

.kainet-shell-chip__avatar {
  width: 28px; height: 28px;
  border-radius: 999px;
  background: var(--shell-accent);
  color: var(--shell-accent-fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  flex: 0 0 auto;
}

.kainet-shell-chip__avatar img {
  width: 100%; height: 100%;
  border-radius: inherit;
  object-fit: cover;
}

.kainet-shell-chip__label {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

.kainet-shell-chip__sub {
  font-size: 11px;
  color: var(--shell-fg-dim);
  margin-left: 6px;
}

.kainet-shell-chip--stale {
  border-color: var(--shell-stale) !important;
  position: relative;
}

.kainet-shell-chip--stale::after {
  content: "•";
  color: var(--shell-stale);
  font-size: 18px;
  line-height: 1;
  margin-left: 4px;
}

/* Preset chip — secondary, no accent (only the brand chip carries the
   Von Restorff accent so the user's eye lands there first). */
.kainet-shell-chip--preset {
  background: transparent;
}

/* Stale banner — under header, full-width, dismissible. */
.kainet-shell-banner {
  position: fixed;
  top: 56px; left: 0; right: 0;
  background: var(--shell-stale);
  color: var(--shell-stale-fg);
  padding: 8px 16px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: var(--shell-z-shell);
  font-family: -apple-system, system-ui, sans-serif;
}

.kainet-shell-banner button {
  background: transparent;
  color: inherit;
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 3px 10px;
  cursor: pointer;
  font-size: 12px;
}

.kainet-shell-banner button:hover {
  background: rgba(255, 255, 255, 0.08);
}

.kainet-shell-banner__dismiss {
  margin-left: auto;
  border: none !important;
  font-size: 18px;
  line-height: 1;
}

[data-kainet-shell-mounted].kainet-shell-has-banner body {
  padding-top: 96px;
}

/* Hand-off CTA toolbar — dropped onto the bottom of the page when
   templates declare `<div data-kainet-handoff></div>`. */
.kainet-shell-handoff {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--shell-border);
  background: var(--shell-card);
  border-radius: var(--shell-radius);
  margin-top: 16px;
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 13px;
  color: var(--shell-fg);
}

.kainet-shell-handoff__label {
  color: var(--shell-fg-dim);
  font-weight: 500;
  margin-right: 8px;
}

.kainet-shell-handoff a {
  color: var(--shell-fg);
  text-decoration: none;
  background: var(--shell-bg);
  border: 1px solid var(--shell-border);
  border-radius: var(--shell-radius-sm);
  padding: 6px 12px;
  transition: border-color 120ms ease, background 120ms ease;
}

.kainet-shell-handoff a:hover {
  background: var(--shell-card-hover);
  border-color: #2a3038;
}

.kainet-shell-handoff a[aria-disabled="true"] {
  opacity: 0.5;
  pointer-events: none;
}

/* Brand switcher popover — promoted from kaicreative into the shared shell. */
button.kainet-shell-chip--brand { cursor: pointer; font: inherit; }
.kainet-shell-brand-wrap { position: relative; display: inline-flex; }
.kainet-shell-brand-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: 18rem;
  max-height: 22rem;
  overflow-y: auto;
  padding: 4px;
  background: var(--card, #fff);
  border: 1px solid var(--line, rgba(22, 28, 38, 0.1));
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(22, 28, 38, 0.18);
  z-index: 60;
}
.kainet-shell-brand-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.5rem 0.6rem;
  background: none;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
}
.kainet-shell-brand-row:hover { background: var(--surface, rgba(22, 28, 38, 0.04)); }
.kainet-shell-brand-row.is-active { background: var(--accent-soft, rgba(0, 107, 85, 0.08)); }
.kainet-shell-brand-row__logo {
  width: 2rem;
  height: 2rem;
  flex: 0 0 auto;
  border-radius: 8px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line, rgba(22, 28, 38, 0.1));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--text, #161c26);
}
.kainet-shell-brand-row__meta { min-width: 0; display: flex; flex-direction: column; }
.kainet-shell-brand-row__name {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text, #161c26);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kainet-shell-brand-row__sub {
  font-size: 0.65rem;
  color: var(--muted, #64748b);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kainet-shell-brand-pop__msg {
  padding: 1.25rem 0.75rem;
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted, #64748b);
}
.kainet-shell-brand-pop__link { color: var(--accent, #006b55); font-weight: 600; }

/* Account menu — global user + logout, replaces per-page sidebar user widgets. */
.kainet-shell-user-wrap { position: relative; display: inline-flex; }
.kainet-shell-chip--user { padding: 4px; }
.kainet-shell-user-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: 13rem;
  padding: 6px;
  background: var(--card, #fff);
  border: 1px solid var(--line, rgba(22, 28, 38, 0.1));
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(22, 28, 38, 0.18);
  z-index: 60;
}
.kainet-shell-user-pop__id {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0.5rem 0.6rem 0.6rem;
  border-bottom: 1px solid var(--line, rgba(22, 28, 38, 0.08));
  margin-bottom: 4px;
}
.kainet-shell-user-pop__name {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text, #161c26);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kainet-shell-user-pop__sub {
  font-size: 0.66rem;
  color: var(--muted, #64748b);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kainet-shell-user-pop__logout {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.6rem;
  border: 0;
  border-radius: 8px;
  background: none;
  cursor: pointer;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text, #161c26);
}
.kainet-shell-user-pop__logout:hover { background: var(--surface, rgba(22, 28, 38, 0.04)); }
