:root {
  --bg-color-light: #f5f7fa;
  --text-color-light: #333;
  --card-bg-light: #fff;
  --accent-color-light: #1e88e5;
  --accent-dark-light: #1565c0;
  --shadow-light: 0 4px 8px rgba(0, 0, 0, 0.1);
  --modal-bg-light: rgba(0, 0, 0, 0.5);
  --modal-content-bg-light: #fff;
  --section-header-color: #555;
  --link-border-light: #ddd;
}

body.dark-mode {
  --bg-color-light: #121212;
  --text-color-light: #e0e0e0;
  --card-bg-light: #1e1e1e;
  --accent-color-light: #64b5f6;
  --accent-dark-light: #42a5f5;
  --shadow-light: 0 4px 8px rgba(0, 0, 0, 0.3);
  --modal-bg-light: rgba(255, 255, 255, 0.2);
  --modal-content-bg-light: #1e1e1e;
  --section-header-color: #ccc;
  --link-border-light: #444;
}

body {
  font-family: 'Nunito', sans-serif;
  margin: 0;
  padding: 0;
  background-color: var(--bg-color-light);
  color: var(--text-color-light);
  transition: background-color 0.3s, color 0.3s;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  align-items: center;
}

/* This class prevents background scrolling when a modal is open */
.modal-open {
  overflow: hidden;
}

/* Pre-login Loading State */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--bg-color-light);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  transition: opacity 0.5s ease-in-out;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  border: 8px solid var(--text-color-light);
  border-top: 8px solid var(--accent-color-light);
  border-radius: 50%;
  width: 60px;
  height: 60px;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

#main-content {
  flex-grow: 1;
  padding: 20px;
  width: 100%;
  margin-left: 0;
  max-width: 800px;
}

/* --- Content Sections --- */
.content-section {
  display: none;
  animation: fadeIn 0.5s ease-in-out;
}

.content-section.active {
  display: block;
}

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

/* --- Home Card Styling --- */
h1 {
  font-size: 2.5rem;
  color: var(--accent-color-light);
  margin-bottom: 10px;
}

.home-card {
  text-align: center;
  padding: 40px;
  max-width: 600px;
  margin: 0 auto;
  background-color: var(--card-bg-light);
  border-radius: 12px;
  box-shadow: var(--shadow-light);
}

.home-card p {
  font-size: 1.2rem;
  margin-bottom: 20px;
}

/* --- Password Gating Styles --- */
.password-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

#username-input,
#password-input {
  padding: 15px;
  font-size: 1rem;
  border-radius: 8px;
  border: 1px solid #ccc;
  width: 250px;
  transition: border-color 0.2s;
  background-color: var(--card-bg-light);
  color: var(--text-color-light);
}

#username-input:focus,
#password-input:focus {
  outline: none;
  border-color: var(--accent-color-light);
}

.home-button {
  display: inline-block;
  padding: 15px 30px;
  font-size: 1.1rem;
  font-weight: 700;
  text-decoration: none;
  background-color: var(--accent-color-light);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.2s;
}

.home-button:hover {
  background-color: var(--accent-dark-light);
  transform: translateY(-2px);
}

.error-message {
  color: #e53935;
  font-weight: bold;
  font-size: 1rem;
  margin-top: 10px;
  min-height: 20px;
}

/* Error Message Shake Animation */
.error-message.shake {
  animation: shake 0.5s ease-in-out;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20%,
  60% {
    transform: translateX(-5px);
  }
  40%,
  80% {
    transform: translateX(5px);
  }
}

.login-instructions {
  background-color: #f0f4f7;
  border-radius: 8px;
  padding: 20px;
  margin-top: 30px;
  text-align: left;
  border: 1px solid #e0e6eb;
  color: #555;
  font-size: 0.95rem;
}

body.dark-mode .login-instructions {
  background-color: #2a2a2a;
  border-color: #3b3b3b;
  color: #ddd;
}

.login-instructions p {
  margin-bottom: 10px;
  font-weight: bold;
  font-size: 1rem;
}

.login-instructions ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.login-instructions li {
  margin-bottom: 5px;
  line-height: 1.4;
}

/* --- Menu Section Styling --- */
.user-profile-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 500;
  display: none;
  flex-direction: column;
  align-items: flex-end;
}

body.has-header .user-profile-container {
  display: block;
}

.profile-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.profile-pic {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  transition: transform 0.2s ease;
  border: 2px solid var(--accent-color-light);
}

.profile-trigger:hover .profile-pic {
  transform: scale(1.1);
}

.dropdown-chevron {
  color: var(--text-color-light);
  font-size: 1rem;
  transition: transform 0.3s ease;
}

.dropdown-chevron.rotated {
  transform: rotate(180deg);
}

.logout-menu {
  position: absolute;
  top: 50px;
  right: 0;
  background-color: var(--card-bg-light);
  border-radius: 8px;
  box-shadow: var(--shadow-light);
  width: 180px;
  padding: 10px;
  z-index: 10;
  visibility: hidden;
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.3s, visibility 0.3s, transform 0.3s;
}

.logout-menu.visible {
  visibility: visible;
  opacity: 1;
  transform: translateY(0);
}

.user-info-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 10px;
  padding: 5px 10px;
  border-bottom: 1px solid var(--link-border-light);
}

#user-display-name {
  font-weight: bold;
}

#user-grade-level {
  font-size: 0.8rem;
  color: #888;
  margin-top: 2px;
}

.dropdown-options {
  list-style: none;
  padding: 0;
  margin: 0;
}

.dropdown-options li {
  margin-bottom: 5px;
}

.dropdown-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  text-decoration: none;
  color: var(--text-color-light);
  border-radius: 6px;
  transition: background-color 0.2s;
}

.dropdown-link:hover {
  background-color: var(--bg-color-light);
}

body.dark-mode .dropdown-link:hover {
  background-color: #333;
}

#menu-welcome-title {
  font-size: 1.8rem;
  text-align: center;
  margin: 0 0 20px 0;
  color: var(--accent-color-light);
  width: 100%;
}

/* --- Menu Links Styling --- */
.menu-links-card {
  padding: 20px;
}

.menu-links-card h3 {
  color: var(--section-header-color);
  margin: 0 0 15px 0;
  font-size: 1.2rem;
  font-weight: 700;
  padding-bottom: 5px;
  border-bottom: 2px solid #ddd;
}

body.dark-mode .menu-links-card h3 {
  border-bottom-color: #444;
}

.menu-links-card ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  transition: grid-template-columns 0.3s;
}

.menu-link {
  background-color: var(--card-bg-light);
  border: 1px solid var(--link-border-light);
  border-radius: 8px;
  transition: background-color 0.2s, transform 0.2s;
  height: 100px;
  display: flex;
}

.menu-link > a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
  text-decoration: none;
  font-weight: bold;
  color: inherit;
  text-align: center;
}

.menu-link:hover {
  background-color: var(--accent-color-light);
  border-color: var(--accent-color-light);
  transform: translateY(-2px);
}

.menu-link:hover > a {
  color: white;
}

body.dark-mode .menu-link {
  background-color: #333;
  border-color: #444;
}

body.dark-mode .menu-link:hover {
  background-color: var(--accent-color-light);
  border-color: var(--accent-color-light);
}

body.dark-mode .menu-link:hover > a {
  color: white;
}

/* List view for links */
.menu-links-card.list-view ul {
  display: flex;
  flex-direction: column;
}

.menu-links-card.list-view .menu-link {
  height: auto;
  border: none;
  background-color: transparent;
  border-bottom: 1px solid var(--link-border-light);
  border-radius: 0;
  padding: 0;
}

.menu-links-card.list-view .menu-link:hover {
  background-color: transparent;
  transform: none;
}

.menu-links-card.list-view .menu-link:hover > a {
  color: var(--accent-color-light);
}

body.dark-mode .menu-links-card.list-view .menu-link:hover {
  background-color: transparent;
}

.menu-links-card.list-view .menu-link > a {
  flex-direction: row;
  justify-content: flex-start;
  height: auto;
  padding: 12px 20px;
  line-height: 1;
}

.link-favicon {
  width: 40px;
  height: 40px;
  margin-bottom: 8px;
}

.menu-links-card.list-view .link-favicon {
  margin-bottom: 0;
  margin-right: 15px;
  transition: opacity 0.2s;
}

.menu-links-card.list-view .menu-link:hover .link-favicon {
  opacity: 0.7;
}

/* This rule adds spacing between the link sections */
.links-section {
  margin-bottom: 20px;
}

body.dark-mode #username-input,
body.dark-mode #password-input {
  border: 1px solid #444;
}

/* --- Redesigned Settings Modal Styles --- */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: var(--modal-bg-light);
  justify-content: center;
  align-items: center;
}

.modal.show {
  display: flex;
}

.modal-content {
  background-color: var(--modal-content-bg-light);
  padding: 20px;
  border-radius: 12px;
  box-shadow: var(--shadow-light);
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--link-border-light);
  padding-bottom: 10px;
  margin-bottom: 20px;
}

.modal-header h3 {
  margin: 0;
  color: var(--text-color-light);
}

.close-button {
  color: #aaa;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  transition: color 0.2s;
}

.close-button:hover,
.close-button:focus {
  color: var(--text-color-light);
  text-decoration: none;
  cursor: pointer;
}

.modal-body {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 20px;
}

.settings-section {
  background-color: var(--bg-color-light);
  padding: 20px;
  border-radius: 8px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
}

body.dark-mode .settings-section {
  background-color: #2a2a2a;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
}

.settings-section h4 {
  margin: 0 0 15px 0;
  font-size: 1.1rem;
  color: var(--text-color-light);
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--link-border-light);
  padding-bottom: 10px;
}

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
}

/* Reusable buttons */
.action-button, .toggle-button {
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: bold;
  cursor: pointer;
  border: 1px solid var(--link-border-light);
  border-radius: 6px;
  transition: background-color 0.2s, color 0.2s;
  background-color: var(--card-bg-light);
  color: var(--text-color-light);
}

.action-button.active {
    background-color: var(--accent-color-light);
    color: white;
    border-color: var(--accent-color-light);
}

.action-button:not(.active):hover {
  background-color: var(--accent-color-light);
  color: white;
  border-color: var(--accent-color-light);
}

/* Style for disabled button (Light Mode) */
.action-button.disabled {
    background-color: #e0e0e0;
    color: #a0a0a0;
    border-color: #e0e0e0;
    cursor: not-allowed;
    pointer-events: none;
}

body.dark-mode .action-button, body.dark-mode .toggle-button {
  background-color: #333;
}

body.dark-mode .action-button:not(.active):hover {
  background-color: var(--accent-color-light);
  color: white;
}

body.dark-mode .action-button.active {
    background-color: var(--accent-color-light);
    color: white;
}

/* Style for disabled button (Dark Mode) */
body.dark-mode .action-button.disabled {
    background-color: #444;
    color: #666;
    border-color: #444;
    cursor: not-allowed;
    pointer-events: none;
}

/* Toggle Switch Styling for Grid/List */
.toggle-switch {
  display: flex;
  border: 1px solid var(--link-border-light);
  border-radius: 6px;
  overflow: hidden;
}

.toggle-switch .toggle-button {
  border: none;
  background-color: transparent;
  color: var(--text-color-light);
}

.toggle-switch .toggle-button.active {
  background-color: var(--accent-color-light);
  color: white;
  border-color: var(--accent-color-light);
}

/* Button Group Styling for Sorting */
.button-group {
    display: flex;
}

.button-group .action-button {
    padding: 8px 12px;
    border-radius: 0;
}

.button-group .action-button:first-child {
    border-top-left-radius: 6px;
    border-bottom-left-radius: 6px;
}

.button-group .action-button:last-child {
    border-top-right-radius: 6px;
    border-bottom-right-radius: 6px;
}

/* New drag-and-drop styles */
.menu-link.sortable-ghost {
  opacity: 0.4;
  background-color: var(--accent-color-light);
  color: white;
}

.menu-link.sortable-chosen > a {
  cursor: grabbing;
}

/* --- Responsive Layout Fix for Overlapping Header --- */
@media (max-width: 500px) {
  #main-content {
    padding-top: 80px; /* Add space to prevent overlap from fixed header */
  }

  .user-profile-container {
    top: 10px;
    right: 10px;
  }
  
  .profile-trigger {
    background-color: var(--card-bg-light);
    border-radius: 20px;
    padding: 5px 10px;
    box-shadow: var(--shadow-light);
  }

  #menu-welcome-title {
    font-size: 1.5rem;
    margin-bottom: 10px;
    text-align: left;
  }
}

/* --- GLASS THEME STYLES (New) --- */

body.glass-on .home-button,
body.glass-on .action-button,
body.glass-on .toggle-button,
body.glass-on .menu-link {
  position: relative;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 8px 32px rgba(31, 38, 135, 0.2),
    inset 0 4px 20px rgba(255, 255, 255, 0.3);
  transition: all 0.3s ease;
}

body.glass-on.dark-mode .home-button,
body.glass-on.dark-mode .action-button,
body.glass-on.dark-mode .toggle-button,
body.glass-on.dark-mode .menu-link {
  background: rgba(30, 30, 30, 0.15);
  border-color: rgba(60, 60, 60, 0.8);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5),
    inset 0 4px 20px rgba(255, 255, 255, 0.1);
}

/* Adding the subtle highlight effect to the glass elements */
body.glass-on .home-button::after,
body.glass-on .action-button::after,
body.glass-on .toggle-button::after,
body.glass-on .menu-link::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.1);
  border-radius: inherit;
  backdrop-filter: blur(1px);
  box-shadow: inset -10px -8px 0px -11px rgba(255, 255, 255, 1),
    inset 0px -9px 0px -8px rgba(255, 255, 255, 1);
  opacity: 0.6;
  z-index: -1;
  filter: blur(1px) drop-shadow(10px 4px 6px black) brightness(115%);
}

body.glass-on.dark-mode .home-button::after,
body.glass-on.dark-mode .action-button::after,
body.glass-on.dark-mode .toggle-button::after,
body.glass-on.dark-mode .menu-link::after {
  background: rgba(255, 255, 255, 0.05);
  box-shadow: inset -10px -8px 0px -11px rgba(255, 255, 255, 0.5),
    inset 0px -9px 0px -8px rgba(255, 255, 255, 0.5);
  filter: blur(1px) drop-shadow(10px 4px 6px #000) brightness(115%);
}

/* --- New Profile Modal Styling --- */
.profile-info-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 20px;
}

.profile-pic-modal {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 4px solid var(--accent-color-light);
  margin-bottom: 10px;
}

#profile-modal-name {
  font-size: 1.5rem;
  margin: 0;
}

#profile-modal-grade {
  font-size: 1rem;
  color: #888;
  margin: 5px 0 0 0;
}

body.dark-mode #profile-modal-grade {
  color: #ccc;
}

.profile-action-buttons {
  display: flex;
  justify-content: center;
  gap: 10px;
}

/* Styling for the Google Workspace section title */
.links-section-title {
    margin: 20px 0 10px;
    font-size: 1.2rem;
    color: var(--text-color-light);
    border-bottom: 2px solid var(--link-border-light);
    padding-bottom: 5px;
}

/* Fix for dynamically added favicons */
.menu-links-card.list-view .link-favicon {
  margin-right: 15px; /* Adds space between the icon and the text */
}

.link-favicon {
  width: 24px;  /* Adjust the size of the icons */
  height: 24px;
  object-fit: contain; /* Prevents the icons from stretching */
  flex-shrink: 0; /* Ensures the icon doesn't shrink when text is long */
}

/* New styles for the homepage and navigation pages */
.school-selection-container {
    display: flex;
    flex-direction: column;
    align-items: center; /* This is the key change */
    gap: 20px;
    margin-top: 30px;
}

.school-button {
    width: 100%;
    max-width: 400px; /* Limits the button to a reasonable width on large screens */
}