/* ============================================
   SIDEBAR NAVIGATION + LAYOUT SHELL
   ============================================ */

/* Layout Shell */
.layout-shell {
  display: flex;
  align-items: flex-start;
  min-height: 100vh;
  background: var(--bg-page);
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Sidebar */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: #fff;
  border-right: 2px solid var(--border-card);
  display: flex;
  flex-direction: column;
  height: 100vh;
  /* Use the dynamic viewport on mobile browsers so the bottom of the nav
     (Communication group, Account section, sidebar footer) doesn't render
     behind the URL bar / bottom system UI. Falls back to 100vh above. */
  height: 100dvh;
  position: sticky;
  top: 0;
  z-index: 50;
  scrollbar-width: thin;
  scrollbar-color: var(--border-card) transparent;
}

.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 2px solid var(--border-card);
}

.sidebar-brand-name {
  font-size: 20px;
  font-weight: 800;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0;
}

.sidebar-brand-role {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  margin-top: 6px;
}

.sidebar-brand-role-admin {
  background: var(--color-coral-orange);
  color: #fff;
}

.sidebar-brand-role-teacher {
  background: var(--color-sky-blue);
  color: #fff;
}

.sidebar-brand-role-parent {
  background: var(--color-soft-purple);
  color: #fff;
}

.sidebar-search {
  padding: 8px 12px;
}

.sidebar-search input {
  width: 100%;
  padding: 8px 12px;
  border: 2px solid #FFE4E1;
  border-radius: 50px;
  font-size: 13px;
  font-family: 'Nunito', sans-serif;
  background: #FFF5EE;
  color: #1F2937;
  outline: none;
  box-sizing: border-box;
}

.sidebar-search input:focus {
  border-color: #FF6B6B;
  background: #fff;
}

.sidebar-search input::placeholder {
  color: #9CA3AF;
}

/* Sidebar Navigation */
.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  text-decoration: none;
  color: var(--text-body);
  font-weight: 600;
  font-size: 14px;
  transition: all 0.15s ease;
  border-left: 3px solid transparent;
}

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

.sidebar-item:focus-visible {
  outline: 2px solid var(--color-coral-orange);
  outline-offset: -2px;
  background: var(--bg-soft);
}

.sidebar-item:active {
  transform: scale(0.98);
}

.sidebar-item-active {
  background: linear-gradient(90deg, rgba(255, 217, 61, 0.15) 0%, rgba(255, 107, 107, 0.08) 100%);
  color: var(--text-dark);
  font-weight: 800;
  border-left-color: var(--color-coral-orange);
}

.sidebar-item-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

/* Sidebar Groups */
.sidebar-group {
  margin-bottom: 4px;
}

.sidebar-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  cursor: pointer;
  user-select: none;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  transition: color 0.15s ease;
}

.sidebar-group-header:hover {
  color: var(--text-dark);
}

.sidebar-group-arrow {
  font-size: 10px;
  transition: transform 0.2s ease;
}

.sidebar-group-collapsed .sidebar-group-arrow {
  transform: rotate(-90deg);
}

.sidebar-group-collapsed .sidebar-group-items {
  display: none;
}

.sidebar-group-items {
  display: block;
}

/* Sidebar Divider */
.sidebar-divider {
  height: 1px;
  background: var(--border-card);
  margin: 8px 16px;
}

/* Sidebar User / Footer */
.sidebar-user {
  padding: 16px 20px;
  border-top: 2px solid var(--border-card);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-user-avatar {
  width: 36px;
  height: 36px;
  background: var(--gradient-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dark);
  font-weight: 800;
  font-size: 14px;
  flex-shrink: 0;
}

.sidebar-user-info {
  flex: 1;
  min-width: 0;
}

.sidebar-user-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-email {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-logout-btn {
  padding: 6px 14px;
  border-radius: var(--radius-button);
  background: #fff;
  border: 2px solid var(--border-card);
  color: var(--text-body);
  font-weight: 700;
  cursor: pointer;
  font-size: 12px;
  font-family: 'Nunito', sans-serif;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.sidebar-logout-btn:hover {
  border-color: var(--color-coral-orange);
  color: var(--color-coral-orange);
}

/* Main Content Area */
.main-content {
  flex: 1;
  min-width: 0;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

.main-header {
  background: var(--gradient-primary);
  padding: 20px 16px;
}

.main-header-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.main-header h1 {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-dark);
  margin: 0;
}

.main-header p {
  color: var(--text-body);
  margin: 4px 0 0;
  font-size: 14px;
}

.main-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

@media (max-width: 600px) {
  .main-header-inner {
    flex-direction: column;
    align-items: flex-start;
  }
  .main-header-actions {
    width: 100%;
  }
}

.main-body {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px;
  width: 100%;
  box-sizing: border-box;
}

/* Sidebar Toggle — floating bottom-right on mobile */
.sidebar-toggle {
  display: none;
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  right: calc(16px + env(safe-area-inset-right, 0px));
  z-index: 60;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--gradient-primary);
  border: none;
  color: var(--text-dark);
  font-size: 22px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(255, 107, 107, 0.35);
  font-family: 'Nunito', sans-serif;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

/* Sidebar Overlay (Mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 49;
}

/* Responsive: Mobile */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: -260px;
    width: 260px;
    min-width: 260px;
    transition: left 0.3s ease;
    box-shadow: none;
    z-index: 51;
  }

  .sidebar-toggle {
    display: flex;
  }

  .layout-shell.sidebar-open .sidebar {
    left: 0;
    box-shadow: 8px 0 30px rgba(0, 0, 0, 0.15);
  }

  .layout-shell.sidebar-open .sidebar-overlay {
    display: block;
  }

  .main-body {
    padding: 16px 12px;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .sidebar-item,
  .sidebar-group-arrow,
  .sidebar-toggle,
  .sidebar-logout-btn {
    transition: none;
  }
}

/* Scrollbar styling for sidebar */
.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}

.sidebar-nav::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--border-card);
  border-radius: 2px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
  background: var(--color-coral-orange);
}
