/* ── Portal Header — shared by index.html and viewer.html ── */
/* To change header height: edit --header-height only.        */

:root {
  --header-height: 36px;
  --tab-bar-height: 33px; /* height of #ri-tab-bar — update if tab bar padding changes */
}

header {
  background: var(--header-bg);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  position: sticky;
  top: 0;
  z-index: 200;
  flex-shrink: 0;
}

.header-brand { display:flex; align-items:center; gap:8px; color:#fff; }

.monogram {
  width: 22px; height: 22px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Libre Baskerville', serif;
  font-size: 10px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}

.header-brand h1 { font-size:12px; font-weight:400; color:rgba(255,255,255,0.7); line-height:1; }
.header-brand h1 .brand-name  { font-family:'Libre Baskerville',serif; font-size:12px; color:rgba(255,255,255,0.85); font-weight:400; }
.header-brand h1 .brand-sep   { color:rgba(255,255,255,0.4); margin:0 5px; }
.header-brand h1 .brand-module{ color:#fff; font-weight:500; }
/* Parent module breadcrumb segment — span wrapping a clickable name +
   its own dropdown. Clicking the name opens the dropdown listing all
   top-level modules. Lighter color than the current module's title to
   signal "you can switch away from this hierarchy here". */
.header-brand h1 .parent-breadcrumb { display: inline-flex; align-items: center; }
.header-brand h1 .parent-breadcrumb .parent-switcher { position: relative; cursor: pointer; display: inline-flex; align-items: center; }
.header-brand h1 .parent-breadcrumb .parent-link { color: rgba(255,255,255,0.75); text-decoration: none; user-select: none; }
.header-brand h1 .parent-breadcrumb .parent-switcher:hover .parent-link { color: #fff; text-decoration: underline; text-underline-offset: 2px; }

.header-right { display:flex; align-items:center; gap:8px; }
.header-user  { display:none; }
.signout-btn  { display:none; }

/* ── User avatar + dropdown ── */
.user-avatar {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.35);
  color: #fff; font-size: 9px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; position: relative;
  font-family: 'DM Sans', sans-serif; letter-spacing: 0.02em;
}
.user-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px); right: 0;
  background: var(--white);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  z-index: 300; min-width: 180px; padding: 6px 0;
}
.user-dropdown.open { display: block; }
.user-dropdown-email {
  font-size: 11px; color: var(--text-muted);
  padding: 6px 14px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px;
}
.user-dropdown-signout {
  display: flex; align-items: center; gap: 8px;
  width: 100%; background: none; border: none;
  padding: 8px 14px; font-size: 13px; color: var(--text-mid);
  cursor: pointer; font-family: 'DM Sans', sans-serif; text-align: left;
}
.user-dropdown-signout:hover { background: var(--settings-hover); }

/* ── Settings gear ── */
.settings-wrap { position: relative; }
.gear-btn {
  background: var(--gear-hover);
  border: 1px solid var(--header-btn-border);
  color: var(--header-text);
  width: 22px; height: 22px;
  border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background .15s; flex-shrink: 0;
}
.gear-btn:hover { background: rgba(255,255,255,0.25); }
.gear-btn svg   { transition: transform .4s ease; }
.gear-btn:hover svg { transform: rotate(60deg); }

#settings-panel {
  display: none;
  position: absolute;
  top: calc(100% + 10px); right: 0;
  background: var(--settings-bg);
  border: 1.5px solid var(--settings-border);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  z-index: 400; min-width: 260px; overflow: hidden;
}
#settings-panel.open { display: block; }
.settings-section-label {
  font-size: 10px; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text-muted);
  padding: 14px 16px 8px;
}
.settings-divider { height: 1px; background: var(--settings-border); margin: 0 10px 8px; }

/* ── Theme picker (viewer only) ── */
.theme-grid { display:grid; grid-template-columns:1fr 1fr 1fr; gap:6px; padding:0 10px 14px; }
.theme-option {
  display:flex; align-items:center; gap:8px;
  padding:8px 10px; border-radius:8px; cursor:pointer;
  font-size:12.5px; font-weight:500; color:var(--text-mid);
  transition:background .1s; border:1.5px solid transparent;
}
.theme-option:hover { background: var(--settings-hover); }
.theme-option.active { border-color:var(--theme-check); background:var(--settings-hover); }
.theme-option.active::after { content:"✓"; margin-left:auto; color:var(--theme-check); font-size:12px; font-weight:700; }
.theme-swatch { width:22px; height:22px; border-radius:50%; flex-shrink:0; border:2px solid rgba(0,0,0,0.1); }

/* ── Module switcher dropdown ── */
.module-switcher { position: relative; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.module-switcher:hover .brand-module { opacity: 0.8; }
.module-caret { display: flex; align-items: center; opacity: 0.5; transition: opacity .15s; }
.module-switcher:hover .module-caret { opacity: 0.9; }
.module-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  background: var(--settings-bg);
  border: 1.5px solid var(--settings-border);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  z-index: 400;
  min-width: 200px;
  max-width: 280px;
  padding: 6px 0;
  /* No overflow:hidden — the sub-popout needs to extend beyond the
     main dropdown's bounds. Border-radius still clips inner items. */
}
.module-dropdown.open { display: block; }
/* Parent-breadcrumb dropdown: position-anchored to .parent-switcher so
   it appears directly under the parent module name. The .parent-switcher
   has position:relative, but we add this explicit rule so any cascading
   conflicts can't push the dropdown to the wrong ancestor. */
.parent-switcher .parent-module-dropdown {
  top: calc(100% + 6px);
  left: 0;
  margin-left: 0;
}
.module-dropdown-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  font-size: 12px; color: var(--text-mid);
  cursor: pointer; text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background .1s;
  position: relative;
}
.module-dropdown-item:hover { background: var(--settings-hover); }
.module-dropdown-item.active { color: var(--green); font-weight: 600; }
.module-dropdown-item svg { flex-shrink: 0; opacity: 0.6; }
.module-dropdown-divider { height: 1px; background: var(--settings-border); margin: 4px 0; }
/* Two-level expansion ── parent rows
   Parent rows use a div wrapper (not an anchor) so they can host both a
   clickable parent link AND a submenu without invalid <a>-in-<a> nesting. */
.module-dropdown-item.has-submenu {
  cursor: default;
  padding-right: 12px;
  /* Override the inherited overflow:hidden from .module-dropdown-item —
     it would otherwise clip the sub-popout to this row's box. */
  overflow: visible;
}
.module-submenu-parent-link {
  display: flex; align-items: center; gap: 10px;
  flex: 1; min-width: 0;
  color: inherit; text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.module-submenu-parent-link:hover { color: var(--text); }
.module-submenu-parent-link.active { color: var(--green); font-weight: 600; }
.module-dropdown-item.has-submenu .module-submenu-caret {
  margin-left: auto; color: var(--text-muted); font-size: 14px; line-height: 1; opacity: 0.6;
}
.module-dropdown-item.has-submenu:hover .module-submenu-caret { opacity: 1; }
/* Sub-popout — appears to the right of the parent row on hover/focus.
   Sized similarly to the main dropdown. The .has-submenu row is the
   anchor; .module-subdropdown is positioned relative to it. */
.module-subdropdown {
  display: none;
  position: absolute;
  left: 100%;
  top: -8px;
  margin-left: 2px;
  background: var(--settings-bg);
  border: 1.5px solid var(--settings-border);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  min-width: 200px;
  max-width: 280px;
  padding: 6px 0;
  z-index: 401;
}
.module-dropdown-item.has-submenu:hover .module-subdropdown,
.module-dropdown-item.has-submenu:focus-within .module-subdropdown {
  display: block;
}
.module-subdropdown-hdr {
  font-size: 9px; font-weight: 600; color: var(--text-muted);
  letter-spacing: 0.06em; text-transform: uppercase;
  padding: 4px 14px 6px;
  border-bottom: 0.5px solid var(--settings-border);
  margin-bottom: 4px;
}
/* Submenu items are slightly compact and dimmer to reinforce hierarchy */
.module-dropdown-item.module-submenu-item {
  font-size: 11px;
  padding: 7px 14px 7px 24px;
  color: var(--text-muted);
}
.module-dropdown-item.module-submenu-item:hover { color: var(--text); }
#ri-tab-bar   { top: var(--header-height) !important; }
.ri-ai-toggle { top: var(--header-height) !important; }
#ri-kpi-row   { top: calc(var(--header-height) + var(--tab-bar-height)) !important; }
