/* CSS Variables */
:root {
  --primary-color: #2563eb;
  --primary-dark: #1e40af;
  --secondary-color: #64748b;
  --success-color: #059669;
  --warning-color: #d97706;
  --error-color: #dc2626;
  --background: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

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

/* Event Status Banner */
.status-banner {
  padding: 15px 20px;
  margin: 0;
  text-align: center;
  font-size: 14px;
  animation: slideDown 0.3s ease-out;
}

.status-banner-closed {
  background-color: #ff6b6b;
  color: white;
}

.status-banner-live {
  background-color: #51cf66;
  color: white;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Top Banner */
.top-banner {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.site-logo {
  width: 42px;
  height: 42px;
  object-fit: contain;
  border-radius: 8px;
  background: white;
  border: 1px solid var(--border);
  padding: 2px;
  display: none;
}

.site-name {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--primary-color);
  line-height: 1.2;
}

.page-title {
  font-size: 0.875rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.top-banner .user-info {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}

.top-banner .event-info {
  font-weight: 500;
  color: var(--text-light);
}

.branding-preview {
  border: 1px dashed var(--border);
  border-radius: 0.75rem;
  padding: 1.5rem;
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 130px;
  text-align: center;
}

.branding-preview img {
  max-height: 110px;
  max-width: 260px;
  object-fit: contain;
  display: none;
}

/* Buttons */
.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

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

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

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

.btn-success:hover {
  opacity: 0.9;
}

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

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

.btn-info {
  background-color: #0ea5e9;
  color: white;
}

.btn-info:hover {
  background-color: #0284c7;
}

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

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

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Forms */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--text);
}

.form-control {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 0.875rem;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-actions {
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.card-header {
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

/* Card header buttons - smaller on mobile */
@media (max-width: 768px) {
  .card-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.75rem;
  }

  .card-header .btn {
    width: 100%;
    font-size: 0.875rem;
    padding: 0.5rem 0.75rem;
    min-height: 40px; /* Slightly smaller than default for header buttons */
  }
  
  /* Ensure h2 doesn't take full width */
  .card-header h2 {
    width: 100%;
  }
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
}

/* Tables */
.table {
  width: 100%;
  border-collapse: collapse;
}

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

.table th {
  background-color: var(--background);
  font-weight: 600;
  color: var(--text);
}

/* Table Wrapper for Responsive Tables */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

/* Mobile Card View for Tables */
.table-mobile-card {
  display: none; /* Hidden on desktop */
}

.table-mobile-card .card-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.table-mobile-card .card-row-header {
  font-weight: 600;
  color: var(--primary-color);
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.table-mobile-card .card-row-item {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--background);
}

.table-mobile-card .card-row-item:last-child {
  border-bottom: none;
}

.table-mobile-card .card-row-label {
  font-weight: 500;
  color: var(--text-light);
  margin-right: 1rem;
  min-width: 100px;
}

.table-mobile-card .card-row-value {
  flex: 1;
  text-align: right;
  word-break: break-word;
}

.table-mobile-card .card-row-actions {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.table th.filterable {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding: 8px;
}

.table th.filterable:hover {
  background-color: #f1f5f9;
}

.table th.filterable.filter-active::after {
  content: " 🔍";
  font-size: 12px;
  margin-left: 4px;
}

.filter-input {
  width: 100%;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  margin-top: 4px;
  box-sizing: border-box;
}

.filter-row {
  display: table-row;
}

.filter-cell {
  display: table-cell;
  padding: 4px 8px 8px 8px;
}

.table tr:hover {
  background-color: var(--background);
}

/* Data table styling - for dynamically generated tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

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

.data-table th {
  background-color: var(--background);
  font-weight: 600;
  color: var(--text);
}

.data-table tr:hover {
  background-color: var(--background);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.5rem;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1rem;
}

.tab {
  padding: 0.75rem 1.5rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-weight: 500;
  color: var(--text-light);
  transition: all 0.2s;
}

.tab.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
}

/* Grid */
.grid {
  display: grid;
  gap: 1rem;
}

.grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

/* Utilities */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

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

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

.d-flex {
  display: flex;
}

.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.gap-3 { gap: 1.5rem; }

.justify-between {
  justify-content: space-between;
}

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

/* Badges */
.badge {
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-weight: 500;
}

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

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

/* Button sizes */
.btn-sm {
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.5);
  justify-content: center;
  align-items: center;
}

.modal-content {
  background-color: var(--surface);
  margin: 2rem auto;
  padding: 2rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

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

.modal-header h2 {
  margin: 0;
  color: var(--primary-color);
}

.modal-header button {
  font-size: 2rem;
  line-height: 1;
  background: transparent;
  border: none;
  color: var(--text-light);
  cursor: pointer;
}

.modal-header button:hover {
  color: var(--text);
}

/* Notifications */
.notification {
  position: fixed;
  top: 1rem;
  right: 1rem;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  transform: translateX(400px);
  transition: transform 0.3s;
}

.notification.show {
  transform: translateX(0);
}

.notification-success {
  border-left: 4px solid var(--success-color);
}

.notification-error {
  border-left: 4px solid var(--error-color);
}

.notification-info {
  border-left: 4px solid var(--primary-color);
}

/* Loading Spinner */
.loader {
  border: 4px solid var(--border);
  border-top: 4px solid var(--primary-color);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin: 2rem auto;
}

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

/* ========================================
   RESPONSIVE DESIGN - MOBILE FIRST
   ======================================== */

/* Enhanced Breakpoints:
   - Mobile: 320px - 480px
   - Tablet: 481px - 768px
   - Desktop: 769px+
*/

/* ========================================
   TABLET & MOBILE (768px and below)
   ======================================== */
@media (max-width: 768px) {
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }

  .top-banner {
    flex-direction: column;
    align-items: flex-start;
    padding: 0.75rem;
  }

  .site-name {
    font-size: 1.125rem;
    margin-bottom: 0.5rem;
  }

  .top-banner .user-info {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .top-banner .event-info {
    font-size: 0.875rem;
  }

  .btn {
    min-height: 44px; /* Touch target size */
    padding: 0.625rem 1rem;
  }

  /* Card header buttons can be slightly smaller */
  .card-header .btn {
    min-height: 40px;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
  }

  .tabs {
    flex-wrap: wrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    scrollbar-width: thin;
  }

  .tab {
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    scroll-snap-align: start;
    white-space: nowrap;
    min-width: fit-content;
  }

  .container {
    padding: 0.75rem;
  }

  .card {
    padding: 1.25rem;
  }

  /* Forms */
  .form-control {
    font-size: 16px; /* Prevents zoom on iOS */
    min-height: 44px;
    padding: 0.625rem;
  }

  .form-actions {
    flex-direction: column-reverse;
    gap: 0.75rem;
  }

  .form-actions .btn {
    width: 100%;
  }

  /* Class filters */
  .class-filters {
    flex-direction: column;
    gap: 0.75rem;
  }

  .class-filters select,
  .class-filters input {
    width: 100%;
  }
}

/* ========================================
   SMALL MOBILE (480px and below)
   ======================================== */
@media (max-width: 480px) {
  .container {
    padding: 0.5rem;
  }

  .card {
    padding: 1rem;
    margin-bottom: 0.75rem;
  }

  .top-banner {
    padding: 0.5rem;
  }

  .site-name {
    font-size: 1rem;
  }

  .top-banner .user-info {
    flex-direction: column;
    align-items: stretch;
  }

  .top-banner .user-info > div {
    width: 100%;
    flex-direction: column;
    gap: 0.5rem;
  }

  .btn {
    width: 100%;
    font-size: 0.875rem;
  }

  .tabs {
    gap: 0.25rem;
  }

  .tab {
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
  }

  .modal-content {
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: 0;
    max-height: 100vh;
    padding: 1rem;
  }

  .modal-header {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
  }

  .modal-header h2 {
    font-size: 1.125rem;
  }

  .notification {
    right: 0.5rem;
    left: 0.5rem;
    top: 0.5rem;
    width: auto;
  }
}

/* ========================================
   EXTRA SMALL MOBILE (320px and below)
   ======================================== */
@media (max-width: 320px) {
  .container {
    padding: 0.375rem;
  }

  .card {
    padding: 0.75rem;
  }

  .site-name {
    font-size: 0.9375rem;
  }

  .tab {
    padding: 0.5rem;
    font-size: 0.75rem;
  }
}

/* Student Dashboard Specific */
.dashboard-split {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.class-filters {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.class-filters select,
.class-filters input {
  flex: 1;
}

.timeslot-grid {
  display: grid;
  gap: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: 1rem;
}

.timeslot-row {
  display: grid;
  grid-template-columns: 150px repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.5rem;
}

.timeslot-cell {
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  text-align: center;
  font-size: 0.875rem;
}

.timeslot-cell.open {
  background-color: #f0fdf4;
  color: var(--success-color);
  cursor: pointer;
}

.timeslot-cell.conflict {
  background-color: #fef2f2;
  color: var(--error-color);
}

.timeslot-cell.enrolled {
  background-color: #dbeafe;
  color: var(--primary-color);
}

/* Timeslot Grid Mobile Optimization */
@media (max-width: 768px) {
  .timeslot-grid {
    padding: 0.75rem;
  }

  .timeslot-row {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .timeslot-cell {
    padding: 0.75rem;
    text-align: left;
  }

  /* Convert timeslot grid to vertical list on mobile */
  .timeslot-grid .timeslot-row {
    display: flex;
    flex-direction: column;
  }

  .timeslot-cell {
    width: 100%;
  }
}

@media (max-width: 1024px) {
  .dashboard-split {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}

/* Login Page */
.login-container {
  max-width: 400px;
  margin: 4rem auto;
  background: var(--surface);
  padding: 2rem;
  border-radius: 0.5rem;
  box-shadow: var(--shadow-lg);
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-header h1 {
  color: var(--primary-color);
  margin-bottom: 0.5rem;
}

.login-header p {
  color: var(--text-light);
}

.login-form {
  margin-top: 2rem;
}

.form-actions {
  margin-top: 1.5rem;
}

.error-message {
  background-color: #fef2f2;
  color: var(--error-color);
  padding: 0.75rem;
  border-radius: 0.375rem;
  margin-bottom: 1rem;
}

/* Bulk Add Grid */
.bulk-add-grid {
  overflow-x: auto;
}

.bulk-add-grid table {
  min-width: 800px;
}

.bulk-add-grid input,
.bulk-add-grid select {
  width: 100%;
  border: 1px solid var(--border);
  padding: 0.375rem;
  border-radius: 0.25rem;
}

/* ========================================
   MOBILE RESPONSIVE TABLE PATTERNS
   ======================================== */

/* Show mobile cards, hide table on small screens */
@media (max-width: 768px) {
  .table-responsive table {
    display: none;
  }

  .table-responsive .table-mobile-card {
    display: block;
  }

  /* Keep horizontal scroll for tables that need it (like bulk-add) */
  .table-scroll {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table-scroll table {
    display: table;
    min-width: 600px;
  }

  .table-scroll .table-mobile-card {
    display: none;
  }
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

/* Mobile Visibility */
.mobile-only {
  display: none;
}

.desktop-only {
  display: block;
}

@media (max-width: 768px) {
  .mobile-only {
    display: block;
  }

  .desktop-only {
    display: none;
  }
}

/* Touch-friendly targets */
@media (max-width: 768px) {
  a,
  button,
  input[type="button"],
  input[type="submit"],
  input[type="checkbox"],
  input[type="radio"],
  select {
    min-height: 44px;
    min-width: 44px;
  }

  input[type="checkbox"],
  input[type="radio"] {
    min-width: auto;
    width: 20px;
    height: 20px;
    margin-right: 0.5rem;
  }

  label {
    display: flex;
    align-items: center;
    min-height: 44px;
  }
}

/* Text sizing for mobile */
@media (max-width: 480px) {
  body {
    font-size: 15px;
  }

  h1 {
    font-size: 1.5rem;
  }

  h2 {
    font-size: 1.25rem;
  }

  h3 {
    font-size: 1.125rem;
  }

  .card-title {
    font-size: 1rem;
  }
}

/* Login page mobile optimization */
@media (max-width: 480px) {
  .login-container {
    margin: 2rem auto;
    padding: 1.5rem;
    border-radius: 0.375rem;
  }

  .login-header h1 {
    font-size: 1.5rem;
  }
}

/* Notification mobile positioning */
@media (max-width: 480px) {
  .notification {
    left: 0.5rem;
    right: 0.5rem;
    max-width: calc(100% - 1rem);
  }
}

/* View Only Badge */
.view-only-badge {
  display: inline-block;
  padding: 4px 12px;
  margin-left: 8px;
  background-color: #f59e0b;
  color: white;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Disabled state for view-only users */
.view-only-disabled {
  opacity: 0.5;
  cursor: not-allowed !important;
  pointer-events: none;
}

.view-only-disabled input,
.view-only-disabled select,
.view-only-disabled textarea,
.view-only-disabled button {
  opacity: 0.5;
  cursor: not-allowed !important;
  pointer-events: none;
}

