/* ==========================================================================
   KURO FANGS — ACADEMIA LAYOUT SYSTEM
   Dark Sidebar (#1E1E2D) with Radiant Vertical Light Indicator
   Clean Light Surface (#F5F8FA & #FFFFFF), Responsive Drawer, and Sticky Header
   ========================================================================== */

/* App Master Layout */
.app-layout {
  display: flex;
  min-height: 100vh;
  width: 100%;
  background-color: var(--bg-app);
}

/* ==========================================================================
   1. ACADEMIA DARK SIDEBAR (#1E1E2D)
   ========================================================================== */
.app-sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-sidebar);
  border-inline-end: 1px solid var(--sidebar-border);
  position: fixed;
  top: 0;
  bottom: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform var(--transition-smooth), background-color var(--transition-base);
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.12);
}

html[dir="ltr"] .app-sidebar {
  left: 0;
}
html[dir="rtl"] .app-sidebar {
  right: 0;
}

/* Sidebar Brand Header */
.sidebar-header {
  height: var(--header-height);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.sidebar-brand-emblem {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: var(--brand-burgundy-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  font-size: 1.3rem;
  box-shadow: 0 2px 10px rgba(190, 18, 60, 0.4);
  flex-shrink: 0;
}

.sidebar-brand-meta {
  display: flex;
  flex-direction: column;
}

.sidebar-brand-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: #FFFFFF;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.sidebar-brand-sub {
  font-size: 0.725rem;
  color: #F43F5E;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.sidebar-close-btn {
  display: none;
  background: transparent;
  border: none;
  color: var(--sidebar-text);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-xs);
  align-items: center;
  justify-content: center;
}
.sidebar-close-btn:hover {
  color: #FFFFFF;
  background: var(--bg-sidebar-hover);
}

/* Sidebar Nav */
.sidebar-nav {
  flex: 1;
  padding: 18px 14px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--sidebar-border) transparent;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sidebar-section-title {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--sidebar-text-muted);
  padding: 16px 12px 6px;
  text-transform: uppercase;
}

.sidebar-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: 0.865rem;
  font-weight: 500;
  text-decoration: none;
  transition: all var(--transition-fast);
  position: relative;
}

.sidebar-menu-icon-wrap {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--sidebar-text);
  transition: color var(--transition-fast);
}

.sidebar-menu-icon-wrap svg {
  width: 18px;
  height: 18px;
}

.sidebar-cat-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  display: block;
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.sidebar-menu-item:hover .sidebar-cat-icon,
.sidebar-menu-item.active .sidebar-cat-icon {
  border-color: #BE123C;
  transform: scale(1.15);
}

.sidebar-menu-text {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-menu-item:hover {
  background-color: var(--bg-sidebar-hover);
  color: var(--sidebar-text-active);
}

.sidebar-menu-item:hover .sidebar-menu-icon-wrap {
  color: #FFFFFF;
}

/* Active State with Vertical Light Line Indicator */
.sidebar-menu-item.active {
  background-color: var(--bg-sidebar-active);
  color: var(--sidebar-text-active);
  font-weight: 700;
}

.sidebar-menu-item.active .sidebar-menu-icon-wrap {
  color: #FDA4AF;
}

/* Vertical glowing light line on active menu item */
.sidebar-menu-item.active::before {
  content: '';
  position: absolute;
  top: 6px;
  bottom: 6px;
  width: 4px;
  background: var(--sidebar-indicator);
  box-shadow: var(--sidebar-indicator-glow);
}

html[dir="ltr"] .sidebar-menu-item.active::before {
  left: -14px;
  border-radius: 0 4px 4px 0;
}
html[dir="rtl"] .sidebar-menu-item.active::before {
  right: -14px;
  border-radius: 4px 0 0 4px;
}

/* Sidebar Footer (Profile Info) */
.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--sidebar-border);
  background-color: rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}

.sidebar-user-card {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: background-color var(--transition-fast);
}
.sidebar-user-card:hover {
  background-color: var(--bg-sidebar-hover);
}

/* Sidebar Mascot & Footer Mascot Avatar */
.sidebar-mascot,
.sidebar-footer img {
  max-width: 100%;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
}

.sidebar-user-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid rgba(244, 63, 94, 0.45);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}
.sidebar-user-card:hover .sidebar-user-avatar {
  transform: scale(1.08);
  border-color: #F43F5E;
}

.mascot-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Ensure no bleeding absolute or fixed watermark */
.sidebar-mascot-watermark {
  display: none !important;
}

/* ==========================================================================
   FIX MASCOT POSITION & OVERLAY BUGS (Strict In-Flow & Compact)
   ========================================================================== */
.hero-mascot,
.hero-mascot-card,
.hero-mascot-widget,
.hero-mascot-compact-card,
.mascot-widget,
.mascot-card {
  position: static !important;
  max-width: 180px !important;
  top: auto !important;
  left: auto !important;
  right: auto !important;
  bottom: auto !important;
  z-index: auto !important;
}

.sidebar-user-meta {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-user-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: #FFFFFF;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-sub {
  font-size: 0.725rem;
  color: var(--sidebar-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Mobile Sidebar Backdrop with Blur */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 180;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
}

.sidebar-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* ==========================================================================
   2. MAIN APPLICATION CONTENT WRAPPER
   ========================================================================== */
.app-main-wrapper {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin var(--transition-smooth);
}

html[dir="ltr"] .app-main-wrapper {
  margin-left: var(--sidebar-width);
}
html[dir="rtl"] .app-main-wrapper {
  margin-right: var(--sidebar-width);
}

/* ==========================================================================
   3. TOP HEADER
   ========================================================================== */
.site-header {
  position: sticky;
  top: 0;
  height: var(--header-height);
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  z-index: 100;
  transition: background-color var(--transition-base), border-color var(--transition-base);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  max-width: 500px;
}

.mobile-toggle-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  width: 38px;
  height: 38px;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.mobile-toggle-btn:hover {
  background-color: var(--bg-hover);
  color: var(--brand-burgundy);
}

/* Header Live Search */
.header-search-box {
  position: relative;
  width: 100%;
  max-width: 380px;
}

html[dir="ltr"] .header-search-box input {
  padding: 9px 16px 9px 38px;
}
html[dir="ltr"] .header-search-box .search-icon {
  left: 12px;
}

html[dir="rtl"] .header-search-box input {
  padding: 9px 38px 9px 16px;
}
html[dir="rtl"] .header-search-box .search-icon {
  right: 12px;
}

.header-search-box input {
  width: 100%;
  background-color: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  font-size: 0.85rem;
  color: var(--text-primary);
  outline: none;
  transition: all var(--transition-fast);
}

.header-search-box input:focus {
  background-color: var(--bg-surface);
  border-color: var(--brand-burgundy);
  box-shadow: 0 0 0 3px rgba(136, 19, 55, 0.1);
}

.header-search-box .search-icon {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

/* Header Actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-subtle);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.header-toggle-btn:hover {
  border-color: var(--brand-burgundy);
  color: var(--brand-burgundy);
  background-color: var(--brand-burgundy-light);
}

.header-toggle-btn svg {
  width: 16px;
  height: 16px;
}

/* Points Pill */
.points-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  background: var(--brand-burgundy-light);
  color: var(--brand-burgundy);
  font-size: 0.8rem;
  font-weight: 800;
  border: 1px solid var(--brand-burgundy-border);
  box-shadow: 0 2px 6px rgba(136, 19, 55, 0.08);
  text-decoration: none;
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.points-pill:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(136, 19, 55, 0.15);
}

.points-pill svg {
  width: 15px;
  height: 15px;
  fill: var(--brand-burgundy);
}

/* Header Mascot Avatar Button */
.header-mascot-avatar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid #0B3B36;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
  text-decoration: none;
  flex-shrink: 0;
  background: var(--bg-card);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] .header-mascot-avatar-btn {
  border-color: #BE123C;
}

.header-mascot-avatar-btn:hover {
  transform: scale(1.08);
  border-color: #BE123C;
  box-shadow: 0 0 12px rgba(190, 18, 60, 0.35);
}

.header-mascot-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.header-mascot-pulse {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #10B981;
  border: 1.5px solid #FFFFFF;
  box-shadow: 0 0 6px #10B981;
}

/* ==========================================================================
   4. MAIN CONTENT AREA (#app)
   ========================================================================== */
.main-content {
  flex: 1;
  padding: 32px 36px 64px;
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  animation: pageFadeIn 0.28s ease;
}

@keyframes pageFadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==========================================================================
   5. RESPONSIVE BREAKPOINTS (Tablet & Mobile)
   ========================================================================== */
@media (max-width: 992px) {
  .app-sidebar {
    width: 270px;
    transform: translateX(-100%);
  }

  html[dir="rtl"] .app-sidebar {
    transform: translateX(100%);
  }

  .app-sidebar.open {
    transform: translateX(0) !important;
  }

  .sidebar-close-btn {
    display: flex;
  }

  html[dir="ltr"] .app-main-wrapper,
  html[dir="rtl"] .app-main-wrapper {
    margin-left: 0;
    margin-right: 0;
  }

  .mobile-toggle-btn {
    display: flex;
  }

  .site-header {
    padding: 0 18px;
  }

  .main-content {
    padding: 20px 18px 48px;
  }
}

@media (max-width: 640px) {
  .header-search-box {
    max-width: 180px;
  }

  .header-actions {
    gap: 8px;
  }

  .points-pill {
    padding: 6px 10px;
    font-size: 0.75rem;
  }

  .header-toggle-btn {
    padding: 6px 10px;
  }
}

/* ==========================================================================
   6. STUDIO FULLSCREEN MODE (JNotes Standalone Viewport)
   ========================================================================== */
body.studio-fullscreen-active .app-sidebar,
body.studio-fullscreen-active .site-header,
body.studio-fullscreen-active .guest-encourage-banner,
body.studio-fullscreen-active .sidebar-backdrop {
  display: none !important;
}

body.studio-fullscreen-active,
body.studio-fullscreen-active .app-layout {
  overflow: hidden !important;
  height: 100vh !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
  background-color: #12131F !important;
}

body.studio-fullscreen-active .app-main-wrapper {
  margin: 0 !important;
  padding: 0 !important;
  max-width: 100vw !important;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
  overflow: hidden !important;
}

body.studio-fullscreen-active #app,
body.studio-fullscreen-active .main-content {
  margin: 0 !important;
  padding: 0 !important;
  max-width: 100vw !important;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
  overflow: hidden !important;
}
