/* Blog IQ — Shared Layout Shell */
/* Light theme — Mixpanel-inspired premium SaaS */
/* Used by all authenticated pages (sidebar + main + optional context panel) */

/* ────────────────────────────────────────────
   App Shell
   ──────────────────────────────────────────── */
.app-shell {
  display: flex;
  height: 100vh;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
}

/* Demo-mode banner injected by state.js when /auth/me returns demo:true.
   Fixed at top so it survives scroll; body gets padding-top via
   .has-demo-banner so the app-shell (height: 100vh) doesn't clip. */
.demo-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 34px;
  background: linear-gradient(90deg, #7B46F6 0%, #9C6FFF 100%);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  z-index: 500;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}
body.has-demo-banner { padding-top: 34px; }
body.has-demo-banner .app-shell { height: calc(100vh - 34px); }

/* ────────────────────────────────────────────
   Sidebar
   ──────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  max-width: var(--sidebar-width);
  background: var(--bg-card);
  border-right: 1px solid var(--border-lighter);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Logo */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 24px;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}
a.sidebar-logo:hover .sidebar-logo-text { opacity: 0.8; }

.sidebar-logo-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent-gradient-start), var(--accent-gradient-end));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-primary);
}

.sidebar-logo-icon svg {
  width: 18px;
  height: 18px;
  color: white;
}

.sidebar-logo-text {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

/* Nav section */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  color: var(--text-muted);
  padding: 20px 12px 8px;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-short);
  text-decoration: none;
  position: relative;
}

.sidebar-nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  text-decoration: none;
}

.sidebar-nav-item.active {
  background: var(--accent-muted);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.sidebar-nav-item svg,
.sidebar-nav-item .nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--text-muted);
  transition: color var(--transition-short);
}

.sidebar-nav-item:hover svg,
.sidebar-nav-item:hover .nav-icon {
  color: var(--text-primary);
}

.sidebar-nav-item.active svg,
.sidebar-nav-item.active .nav-icon {
  color: var(--accent);
}

.sidebar-nav-item .nav-badge {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent-muted);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Separator */
.sidebar-separator {
  height: 1px;
  background: var(--border-lighter);
  margin: 8px 8px;
}

/* Brand switcher (bottom) */
.sidebar-bottom {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border-lighter);
}

.sidebar-logout {
  display: block;
  padding: 8px 12px;
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius);
  transition: all var(--transition-short);
}
.sidebar-logout:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
  text-decoration: none;
}

.brand-switcher {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-short);
}
.brand-switcher:hover {
  background: var(--bg-hover);
}

.brand-switcher-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  background: var(--accent-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
  overflow: hidden;
}
.brand-switcher-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-switcher-info {
  flex: 1;
  min-width: 0;
}
.brand-switcher-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-switcher-domain {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-switcher-chevron {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Brand switcher dropdown */
.brand-dropdown {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 12px;
  right: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-lighter);
  border-radius: var(--radius-md);
  padding: 0;
  display: none;
  flex-direction: column;
  z-index: 200;
  box-shadow: var(--shadow-lg);
  max-height: 340px;
  overflow: hidden;
}
.brand-dropdown.visible,
.brand-dropdown.open { display: flex; }

.brand-dropdown-search {
  padding: 8px;
  border-bottom: 1px solid var(--border-lighter);
  background: var(--bg-card);
  flex-shrink: 0;
}
.brand-dropdown-search input {
  width: 100%;
  box-sizing: border-box;
  padding: 7px 10px;
  border: 1px solid var(--border-lighter);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  font-size: 13px;
  color: var(--text-primary);
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition-short);
}
.brand-dropdown-search input:focus {
  border-color: var(--accent);
  background: var(--bg-card);
}
.brand-dropdown-search input::placeholder {
  color: var(--text-muted);
}
.brand-dropdown-list {
  padding: 6px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.brand-dropdown-empty {
  padding: 16px 10px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

.brand-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition-short);
  font-size: 13px;
  color: var(--text-secondary);
}
.brand-dropdown-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.brand-dropdown-item.active {
  background: var(--accent-muted);
  color: var(--accent);
}

.brand-dropdown-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  background: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
}
.brand-dropdown-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-dropdown-domain {
  font-size: 11px;
  color: var(--text-muted);
}
.brand-dropdown-check {
  margin-left: auto;
  color: var(--accent);
  opacity: 0;
  flex-shrink: 0;
}
.brand-dropdown-item.active .brand-dropdown-check { opacity: 1; }

/* ────────────────────────────────────────────
   Main Content Area
   ──────────────────────────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--bg);
}

.main-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ────────────────────────────────────────────
   Page Header
   ──────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px;
  border-bottom: 1px solid var(--border-lighter);
  background: var(--bg-card);
  flex-shrink: 0;
}

.page-header-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}
.page-header-left .page-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-header-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.page-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Breadcrumbs */
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}
.breadcrumbs a {
  color: var(--text-muted);
  transition: color var(--transition-short);
}
.breadcrumbs a:hover {
  color: var(--text-primary);
  text-decoration: none;
}
.breadcrumbs .sep {
  font-size: 10px;
  opacity: 0.5;
}
.breadcrumbs .current {
  color: var(--text-primary);
  font-weight: 500;
}

/* ────────────────────────────────────────────
   Page Body
   ──────────────────────────────────────────── */
.page-body {
  padding: 28px 32px;
  max-width: 1400px;
}

/* ────────────────────────────────────────────
   Context Panel (Chat / Inspector)
   ──────────────────────────────────────────── */
.context-panel {
  width: var(--context-panel-width);
  min-width: var(--context-panel-width);
  max-width: var(--context-panel-width);
  background: var(--bg-card);
  border-left: 1px solid var(--border-lighter);
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.04);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.2s ease, min-width 0.2s ease, opacity 0.15s ease;
}
.context-panel.collapsed {
  width: 0;
  min-width: 0;
  max-width: 0;
  opacity: 0;
  border-left: none;
  pointer-events: none;
}

.context-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-lighter);
  flex-shrink: 0;
}
.context-panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.context-panel-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius);
  transition: all var(--transition-short);
}
.context-panel-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.context-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}
.context-panel-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-lighter);
  flex-shrink: 0;
}

/* ────────────────────────────────────────────
   Toolbar (filter/action bar below page header)
   ──────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 32px;
  border-bottom: 1px solid var(--border-lighter);
  flex-shrink: 0;
  background: var(--bg-card);
}
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}
.toolbar-separator {
  width: 1px;
  height: 20px;
  background: var(--border-lighter);
  margin: 0 6px;
}
.toolbar-spacer {
  flex: 1;
}

/* ────────────────────────────────────────────
   Empty states
   ──────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 32px;
  text-align: center;
}
.empty-state-icon {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  color: var(--text-muted);
  opacity: 0.4;
}
.empty-state-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}
.empty-state-description {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 360px;
  line-height: 1.5;
}
.empty-state .btn-primary,
.empty-state .btn-ghost {
  margin-top: 24px;
}

/* ────────────────────────────────────────────
   Loading overlay
   ──────────────────────────────────────────── */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(248, 248, 248, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.loading-spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--border-lighter);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ────────────────────────────────────────────
   User menu (sidebar bottom)
   ──────────────────────────────────────────── */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 0;
  margin-top: 8px;
}
.sidebar-user-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
  overflow: hidden;
}
.sidebar-user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
.sidebar-user-name {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

/* ────────────────────────────────────────────
   New Chat button (sidebar)
   ──────────────────────────────────────────── */
.btn-new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  background: var(--btn-primary);
  color: var(--text-white);
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--btn-primary-shadow);
  transition: all var(--transition-medium);
  margin-bottom: 20px;
  text-decoration: none;
}
.btn-new-chat:hover {
  background: linear-gradient(90deg, var(--accent-hover) 0%, #976AF0 100%);
  box-shadow: 0px 4px 8px rgba(123, 70, 246, 0.4);
  transform: translateY(-1px);
}
.btn-new-chat:active {
  transform: translateY(0);
}
.btn-new-chat svg {
  width: 16px;
  height: 16px;
}

/* ────────────────────────────────────────────
   Period selector pills
   ──────────────────────────────────────────── */
.period-pills {
  display: flex;
  gap: var(--space-xs);
}
.period-pill {
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-subtle);
  cursor: pointer;
  transition: all var(--transition-short);
  border: none;
  font-family: var(--font-body);
}
.period-pill:hover:not(.active) {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.period-pill.active {
  background: linear-gradient(90deg, var(--accent-gradient-start), var(--accent-gradient-end));
  color: var(--text-white);
  font-weight: 600;
  box-shadow: 0px 1px 3px rgba(123, 70, 246, 0.3);
}

/* ────────────────────────────────────────────
   Page fade-in animation
   ──────────────────────────────────────────── */
.page-body {
  animation: pageIn 0.3s ease both;
}
@keyframes pageIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ────────────────────────────────────────────
   Responsive
   ──────────────────────────────────────────── */
/* ────────────────────────────────────────────
   Sidebar Footer (app pages)
   ──────────────────────────────────────────── */
.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 8px 4px;
  font-size: 11px;
}
.sidebar-footer a {
  color: var(--text-dim);
  text-decoration: none;
  transition: color 0.15s;
}
.sidebar-footer a:hover {
  color: var(--text-secondary);
}
.sidebar-footer span {
  color: var(--text-dim);
  opacity: 0.4;
}

/* ────────────────────────────────────────────
   Public Footer (login / onboard pages)
   ──────────────────────────────────────────── */
.public-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  font-size: 12px;
  color: var(--text-dim);
}
.public-footer a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}
.public-footer a:hover {
  color: var(--text-primary);
}

/* ────────────────────────────────────────────
   Responsive
   ──────────────────────────────────────────── */
@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 199;
    display: none;
  }
  .sidebar-backdrop.visible {
    display: block;
  }
  .context-panel {
    display: none;
  }
}
