/* ClassConnect - Unified Mobile-First CSS */

/* ===== CSS VARIABLES ===== */
:root {
  --primary: #4F46E5;
  --primary-dark: #4338CA;
  --secondary: #10B981;
  --danger: #EF4444;
  --warning: #F59E0B;
  --info: #3B82F6;
  --dark: #1F2937;
  --light: #F9FAFB;
  --gray: #6B7280;
  --border: #E5E7EB;
  --success: #10B981;
}

/* ===== RESET & BASE (Mobile First) ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--dark);
  background: var(--light);
  overflow-x: hidden;
}

/* ===== LAYOUT (Mobile First) ===== */
.container {
  width: 100%;
  padding: 0 1rem;
  margin: 0 auto;
}

.main-wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== HEADER (Mobile First) ===== */
.header {
  background: white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  position: sticky;
  top: 0;
  z-index: 100;
  width: 100%;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  max-width: 1400px;
  margin: 0 auto;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  white-space: nowrap;
}

/* ===== MOBILE NAVIGATION ===== */
.hamburger {
  display: flex;
  flex-direction: column;
  cursor: pointer;
  padding: 0.5rem;
  z-index: 1001;
  background: none;
  border: none;
}

.hamburger span {
  width: 25px;
  height: 3px;
  background: var(--dark);
  margin: 3px 0;
  transition: 0.3s;
  border-radius: 2px;
}

.hamburger.active span:nth-child(1) {
  transform: rotate(-45deg) translate(-5px, 6px);
}

.hamburger.active span:nth-child(2) {
  opacity: 0;
}

.hamburger.active span:nth-child(3) {
  transform: rotate(45deg) translate(-5px, -6px);
}

.nav {
  position: fixed;
  top: 0;
  right: -100%;
  height: 100vh;
  width: 280px;
  max-width: 85%;
  flex-direction: column;
  background: white;
  padding: 4rem 0 2rem 0;
  box-shadow: -5px 0 15px rgba(0,0,0,0.3);
  transition: right 0.3s ease;
  z-index: 999;
  overflow-y: auto;
  display: flex;
  gap: 0;
}

.nav.active {
  right: 0;
}

.nav.nav-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 998;
  pointer-events: none; /* Prevent it from blocking clicks when hidden */
}

.nav-overlay.active {
  display: block;
  pointer-events: auto; /* Only enable clicks when overlay is visible */
}

.nav {
  position: fixed;
  top: 0;
  right: -100%;
  height: 100vh;
  width: 280px;
  max-width: 85%;
  flex-direction: column;
  background: white;
  padding: 4rem 0 2rem 0;
  box-shadow: -5px 0 15px rgba(0,0,0,0.3);
  transition: right 0.3s ease;
  z-index: 9999; /* Increased to sit above overlay */
  overflow-y: auto;
  display: flex;
  gap: 0;
}

.nav-link {
  padding: 1rem 1.5rem;
  color: var(--dark);
  text-decoration: none;
  font-weight: 500;
  transition: all 0.3s;
  border-bottom: 1px solid var(--border);
  display: block;
}

.nav-link:hover,
.nav-link:active {
  background: var(--light);
  color: var(--primary);
}

/* ===== BUTTONS (Mobile First) ===== */
.btn {
  display: inline-block;
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: 0.5rem;
  font-size: 0.9375rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.3s;
  text-align: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  margin: 0.5rem 1rem;
  width: calc(100% - 2rem);
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover,
.btn-primary:active {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--secondary);
  color: white;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
}

.btn:active {
  transform: scale(0.98);
}

/* ===== FORMS (Mobile First) ===== */
.form-group {
  margin-bottom: 1rem;
  width: 100%;
}

.form-label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: var(--dark);
  font-size: 0.9375rem;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.875rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 16px; /* Prevents zoom on iOS */
  transition: border-color 0.3s;
  -webkit-appearance: none;
  appearance: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-textarea {
  resize: vertical;
  min-height: 120px;
  font-family: inherit;
}

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236B7280' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.5rem;
}

/* ===== CARDS (Mobile First) ===== */
.card {
  background: white;
  border-radius: 0.75rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  padding: 1rem;
  margin-bottom: 1rem;
  width: 100%;
}

.card-header {
  font-size: 1.125rem;
  font-weight: 700;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

/* ===== GRID (Mobile First) ===== */
.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

/* ===== ALERTS (Mobile First) ===== */
.alert {
  padding: 0.875rem 1rem;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.9375rem;
}

.alert-success {
  background: #D1FAE5;
  color: #065F46;
  border: 1px solid #10B981;
}

.alert-error {
  background: #FEE2E2;
  color: #991B1B;
  border: 1px solid #EF4444;
}

.alert-info {
  background: #DBEAFE;
  color: #1E40AF;
  border: 1px solid #3B82F6;
}

.alert-warning {
  background: #FEF3C7;
  color: #92400E;
  border: 1px solid #F59E0B;
}

/* ===== MODAL (Mobile First) ===== */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: white;
  border-radius: 0.75rem;
  padding: 1.5rem;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.75rem;
  cursor: pointer;
  color: var(--gray);
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== TABLES (Mobile First) ===== */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -1rem;
  padding: 0 1rem;
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 0.75rem;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  min-width: 600px;
}

.table th,
.table td {
  padding: 0.75rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

.table th {
  background: var(--light);
  font-weight: 600;
  color: var(--dark);
  white-space: nowrap;
}

.table tr:last-child td {
  border-bottom: none;
}

/* ===== BADGES (Mobile First) ===== */
.badge {
  display: inline-block;
  padding: 0.25rem 0.625rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-primary {
  background: var(--primary);
  color: white;
}

.badge-success {
  background: var(--secondary);
  color: white;
}

.badge-danger {
  background: var(--danger);
  color: white;
}

.badge-warning {
  background: var(--warning);
  color: white;
}

.badge-info {
  background: var(--info);
  color: white;
}

/* ===== ADMIN LAYOUT (Mobile First) ===== */
.admin-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.sidebar {
  width: 100%;
  background: var(--dark);
  color: white;
  padding: 1rem 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.sidebar-header {
  padding: 0 1rem;
  margin-bottom: 1rem;
}

.sidebar-header h2 {
  font-size: 1.25rem;
  margin-bottom: 0.25rem;
}

.sidebar-header p {
  font-size: 0.875rem;
  opacity: 0.7;
}

.sidebar-nav {
  display: flex;
  flex-direction: row;
  gap: 0.5rem;
  padding: 0 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.sidebar-link {
  padding: 0.625rem 1rem;
  color: white;
  text-decoration: none;
  transition: background 0.3s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
  border-radius: 0.5rem;
  font-size: 0.875rem;
}

.sidebar-link:hover,
.sidebar-link.active {
  background: rgba(255,255,255,0.15);
}

.main-content {
  flex: 1;
  background: var(--light);
  width: 100%;
}

.top-bar {
  background: white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ===== CHAT LAYOUT (Mobile First) ===== */
.chat-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  height: calc(100vh - 180px);
}

.chat-sidebar {
  display: none;
}

.chat-sidebar.active {
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  z-index: 1000;
  background: white;
}

#messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  -webkit-overflow-scrolling: touch;
}

/* ===== POPUPS (Mobile First) ===== */
.subscription-popup {
  position: fixed;
  bottom: 10px;
  left: 10px;
  right: 10px;
  background: white;
  border-radius: 0.75rem;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  padding: 1rem;
  z-index: 999;
  animation: slideIn 0.5s ease-out;
}

.subscription-popup.active {
  display: block;
}

.popup-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--gray);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== LOADING SPINNER ===== */
.spinner {
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin: 2rem auto;
}

/* ===== PWA INSTALL BUTTON ===== */
.pwa-install-button {
  position: fixed;
  bottom: 80px;
  right: 15px;
  z-index: 999;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  animation: slideIn 0.3s ease-out;
  font-size: 0.875rem;
  padding: 0.65rem 1.25rem;
}

/* ===== ANIMATIONS ===== */
@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes slideIn {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ===== UTILITIES ===== */
.hide-mobile {
  display: none;
}

.text-center {
  text-align: center;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

/* ===== TABLET (min-width: 640px) ===== */
@media (min-width: 640px) {
  .container {
    padding: 0 1.5rem;
  }
  
  .card {
    padding: 1.5rem;
  }
  
  .btn {
    width: auto;
    margin: 0;
  }
  
  .grid-sm-2 {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .table th,
  .table td {
    padding: 1rem 0.75rem;
  }
}

/* ===== DESKTOP (min-width: 768px) ===== */
@media (min-width: 768px) {
  .container {
    max-width: 1400px;
    padding: 0 2rem;
  }
  
  .hamburger {
    display: none;
  }
  
  .nav {
    position: static;
    height: auto;
    width: auto;
    max-width: none;
    flex-direction: row;
    background: transparent;
    padding: 0;
    box-shadow: none;
    overflow: visible;
    gap: 2rem;
  }
  
  .nav-link {
    padding: 0;
    border-bottom: none;
  }
  
  .btn {
    padding: 0.75rem 1.5rem;
  }
  
  .grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .hide-mobile {
    display: block;
  }
  
  .chat-layout {
    grid-template-columns: 250px 1fr;
    gap: 1.5rem;
  }
  
  .chat-sidebar {
    display: block;
    position: static;
    width: auto;
    height: auto;
  }
  
  .admin-wrapper {
    flex-direction: row;
  }
  
  .sidebar {
    width: 250px;
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    overflow-y: auto;
    padding: 2rem 0;
  }
  
  .sidebar-nav {
    flex-direction: column;
    overflow: visible;
    gap: 0;
    padding: 0;
  }
  
  .sidebar-link {
    padding: 0.75rem 1.5rem;
    border-radius: 0;
  }
  
  .main-content {
    margin-left: 250px;
  }
  
  .top-bar {
    flex-direction: row;
    padding: 1rem 2rem;
    justify-content: space-between;
    align-items: center;
  }
  
  .subscription-popup {
    bottom: 20px;
    left: auto;
    right: 20px;
    max-width: 350px;
  }
  
  .pwa-install-button {
    bottom: 20px;
    right: 20px;
  }
}

/* ===== LARGE DESKTOP (min-width: 1024px) ===== */
@media (min-width: 1024px) {
  .grid-lg-3 {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .grid-lg-4 {
    grid-template-columns: repeat(4, 1fr);
  }
}