/**
 * Phase 1: Core App Structure — Mobile-first
 */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  overflow: hidden;
}
body {
  height: 100%;
  overflow: hidden;
}

.app-root {
  font-family: var(--app-font);
  background: var(--app-bg);
  color: var(--app-text);
  height: 100%;
  min-height: 100dvh;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-top: var(--app-safe-top);
  padding-bottom: var(--app-safe-bottom);
  overflow: hidden;
  background-image: var(--app-gradient-mesh);
  background-attachment: fixed;
}

.main-app {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
}

.app-header {
  flex-shrink: 0;
  height: var(--app-header-height);
  min-height: 48px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--app-border-soft);
  box-shadow: var(--app-shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  transition: background var(--app-duration) var(--app-ease), box-shadow var(--app-duration) var(--app-ease);
}
.app-dark .app-header {
  background: rgba(24, 24, 27, 0.9);
  border-bottom-color: var(--app-border);
}
.app-header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--app-text);
  font-weight: 800;
  font-size: 1.125rem;
  letter-spacing: -0.02em;
  transition: transform var(--app-duration-fast) var(--app-ease), color var(--app-duration-fast) var(--app-ease);
}
.app-header-logo:hover {
  color: var(--app-primary);
  transform: scale(1.02);
}
.app-header-logo img {
  width: 34px;
  height: 34px;
  object-fit: contain;
  border-radius: var(--app-radius-md);
}
.app-header-logo-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  line-height: 1.15;
  gap: 0;
}
/* Prepriga logo text — elegant gradient with shimmer */
.app-header-logo .logo-text-3d {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #4f46e5 100%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: prepriga-shimmer 3s ease-in-out infinite;
}
@keyframes prepriga-shimmer {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
.app-header-logo:hover .logo-text-3d {
  filter: brightness(1.15) drop-shadow(0 2px 8px rgba(79, 70, 229, 0.35));
}
.app-header-logo .logo-text-3d .b3d {
  display: inline;
  -webkit-text-fill-color: transparent;
}
/* Tagline below Prepriga — small */
.app-header-tagline {
  font-size: 0.55rem;
  font-weight: 600;
  color: var(--app-text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-top: 1px;
}
@media (max-width: 360px) {
  .app-header-tagline { display: none; }
}
.app-header-badge-wrap {
  flex: 1;
  display: flex;
  justify-content: center;
  position: relative;
}
.app-header-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--app-primary);
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  padding: 8px 14px;
  border-radius: var(--app-radius-full);
  border: 1px solid rgba(99, 102, 241, 0.35);
  background: var(--app-primary-soft);
  font-family: inherit;
  letter-spacing: 0.02em;
  transition: background var(--app-duration-fast) var(--app-ease), color var(--app-duration-fast) var(--app-ease), border-color var(--app-duration-fast) var(--app-ease), box-shadow var(--app-duration-fast) var(--app-ease);
  box-shadow: 0 1px 3px rgba(99, 102, 241, 0.12);
}
.app-header-badge:hover {
  color: var(--app-primary-hover);
  background: rgba(99, 102, 241, 0.2);
  border-color: rgba(99, 102, 241, 0.5);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.2);
}
.app-header-badge:focus {
  outline: none;
}
.app-header-badge:focus-visible {
  box-shadow: 0 0 0 2px var(--app-surface), 0 0 0 4px var(--app-primary);
}
.app-header-role-hint {
  display: none;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--app-text-muted);
  background: var(--app-bg-elevated);
  padding: 4px 8px;
  border-radius: var(--app-radius-sm);
  margin-left: 6px;
}
.app-header-user-block {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.app-header-user-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--app-text);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Role-coloured highlight: same name, different colour by role (users learn over time) */
.app-header-user-block[data-role="student"] .app-header-user-name { color: var(--role-student); }
.app-header-user-block[data-role="school"] .app-header-user-name { color: var(--role-school); }
.app-header-user-block[data-role="mentor"] .app-header-user-name { color: var(--role-mentor); }
.app-header-user-block[data-role="parent"] .app-header-user-name { color: var(--role-parent); }
.app-header-logout {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--app-primary);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: var(--app-radius-full);
  border: 1px solid rgba(99, 102, 241, 0.35);
  background: var(--app-primary-soft);
  transition: background var(--app-duration-fast) var(--app-ease), color var(--app-duration-fast) var(--app-ease);
}
.app-header-logout:hover {
  background: rgba(99, 102, 241, 0.2);
  color: var(--app-primary-hover);
}
.role-dropdown {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 4px;
  min-width: 160px;
  padding: 6px;
  background: var(--app-surface);
  border-radius: var(--app-radius-md);
  box-shadow: var(--app-shadow-lg);
  border: 1px solid var(--app-border);
  z-index: 200;
  display: none;
}
.role-dropdown.open {
  display: block;
}
.role-dropdown-btn {
  display: block;
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--app-text);
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--app-duration-fast) var(--app-ease);
}
.role-dropdown-btn:hover {
  background: var(--app-primary-soft);
  color: var(--app-primary);
}
.role-dropdown-btn.active {
  background: var(--app-primary-soft);
  color: var(--app-primary);
}
.app-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.app-header-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: var(--app-radius-full);
  color: var(--app-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--app-duration-fast) var(--app-ease), color var(--app-duration-fast) var(--app-ease), transform var(--app-duration-fast) var(--app-ease);
}
.app-header-btn:hover {
  background: var(--app-primary-soft);
  color: var(--app-primary);
  transform: scale(1.06);
}
.app-header-btn:active {
  transform: scale(0.96);
}
.app-header-btn svg {
  width: 22px;
  height: 22px;
}

.app-main {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}
.app-main-inner {
  min-height: min-content;
  padding-bottom: 32px;
}

/* Pull-to-refresh: behaviour only, no visible text */
.app-ptr {
  height: 0;
  padding: 0;
  overflow: hidden;
  visibility: hidden;
  font-size: 0;
  pointer-events: none;
}

.app-tabbar {
  flex-shrink: 0;
  height: var(--app-tabbar-height);
  min-height: 56px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--app-border-soft);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 8px 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  position: sticky;
  bottom: 0;
  z-index: 100;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.04);
}
.app-dark .app-tabbar {
  background: rgba(24, 24, 27, 0.92);
  border-top-color: var(--app-border);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.2);
}
.app-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 8px;
  border: none;
  background: transparent;
  color: var(--app-text-muted);
  font-size: 0.625rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color var(--app-duration) var(--app-ease), transform var(--app-duration-fast) var(--app-ease);
  position: relative;
}
.app-tab:hover,
.app-tab:focus {
  color: var(--app-primary);
}
.app-tab:active {
  transform: scale(0.95);
}
.app-tab.active {
  color: var(--app-primary);
}
.app-tab.active .app-tab-icon {
  color: var(--app-primary);
}
.app-tab-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: color var(--app-duration) var(--app-ease), transform var(--app-duration-fast) var(--app-ease);
}
.app-tab:hover .app-tab-icon {
  transform: translateY(-1px);
}
.app-tab-icon svg {
  width: 24px;
  height: 24px;
}
.app-tab-badge {
  position: absolute;
  top: -2px;
  right: -4px;
  min-width: 14px;
  height: 14px;
  padding: 0 4px;
  background: var(--app-primary);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  border-radius: var(--app-radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-panel {
  display: none;
  animation: app-fadeIn 0.25s ease;
}
.app-panel.active {
  display: block;
}
@keyframes app-fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Tablet & desktop: header full width, left sidebar nav, main content scrollable */
@media (min-width: 768px) {
  .main-app {
    display: grid;
    grid-template-rows: auto 1fr;
    grid-template-columns: 80px 1fr;
    grid-template-areas:
      "header header"
      "tabbar main";
    min-height: 0;
    height: 100%;
    overflow: hidden;
  }
  .app-header {
    grid-area: header;
    padding: 0 20px;
  }
  .app-header-badge {
    max-width: 200px;
    font-size: 0.875rem;
  }
  .app-tabbar {
    grid-area: tabbar;
    width: auto;
    height: auto;
    min-height: 0;
    flex-direction: column;
    justify-content: flex-start;
    gap: 6px;
    padding: 20px 0;
    border-top: none;
    border-right: 1px solid var(--app-border-soft);
    border-left: none;
    position: relative;
    bottom: auto;
    top: auto;
    align-self: stretch;
    flex-shrink: 0;
  }
  .app-tab {
    flex: none;
    width: 100%;
    padding: 14px 8px;
    min-height: 52px;
  }
  .app-tab span:last-child {
    display: none;
  }
  .app-main {
    grid-area: main;
    flex: 1;
    min-width: 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }
}

@media (min-width: 1024px) {
  .main-app {
    grid-template-columns: 96px 1fr;
  }
  .app-tabbar {
    padding: 24px 0;
  }
  .app-tab span:last-child {
    display: block;
    font-size: 0.6875rem;
    margin-top: 4px;
  }
}
