/* Next School Operations Platform - Main CSS */
/* Mobile-first responsive design */

/* CSS Custom Properties for theming */
:root {
  --primary-50: #eff6ff;
  --primary-100: #dbeafe;
  --primary-200: #bfdbfe;
  --primary-300: #93c5fd;
  --primary-400: #60a5fa;
  --primary-500: #3b82f6;
  --primary-600: #2563eb;
  --primary-700: #1d4ed8;
  --primary-800: #1e40af;
  --primary-900: #1e3a8a;
  
  /* Safe area insets for devices with notches */
  --safe-area-inset-top: env(safe-area-inset-top);
  --safe-area-inset-right: env(safe-area-inset-right);
  --safe-area-inset-bottom: env(safe-area-inset-bottom);
  --safe-area-inset-left: env(safe-area-inset-left);
}

/* Base styles */
html {
  font-size: 16px; /* Minimum 16px to prevent zoom on iOS */
}

body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Touch targets - minimum 44x44px for mobile */
.touch-target {
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Enhanced focus states for accessibility */
.focus-ring:focus {
  outline: 2px solid var(--primary-500);
  outline-offset: 2px;
}

/* Custom scrollbar for webkit browsers */
.custom-scrollbar::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.custom-scrollbar::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* HTMX loading states */
.htmx-request .htmx-indicator {
  display: block;
}

.htmx-request.htmx-indicator {
  display: block;
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255, 255, 255, .3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Mobile-specific styles */
@media (max-width: 768px) {
  /* Improve tap targets on mobile */
  button, .btn, input[type="submit"], a.touch-target {
    min-height: 48px;
    padding: 12px 16px;
  }
  
  /* Larger form inputs on mobile */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="tel"],
  input[type="number"],
  input[type="date"],
  textarea,
  select {
    font-size: 16px; /* Prevents zoom on iOS */
    min-height: 48px;
    padding: 12px 16px;
  }
  
  /* Full-width modals on mobile */
  .modal-mobile-full {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100vh;
    margin: 0;
    border-radius: 0;
  }
  
  /* Bottom navigation safe area */
  .bottom-nav {
    padding-bottom: calc(var(--safe-area-inset-bottom) + 1rem);
  }
  
  /* Hide desktop-only elements */
  .desktop-only {
    display: none !important;
  }
}

/* Desktop-specific styles */
@media (min-width: 1024px) {
  /* Hide mobile-only elements */
  .mobile-only {
    display: none !important;
  }
  
  /* Enhanced hover states on desktop */
  button:hover,
  .btn:hover,
  a.hover-lift:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.2s ease;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #1f2937;
    --bg-secondary: #374151;
    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --border-color: #4b5563;
  }
  
  .dark-mode-support {
    background-color: var(--bg-primary);
    color: var(--text-primary);
  }
}

/* Animation classes */
.fade-in {
  opacity: 0;
  animation: fadeIn 0.3s ease-in-out forwards;
}

.slide-up {
  transform: translateY(20px);
  opacity: 0;
  animation: slideUp 0.3s ease-out forwards;
}

.slide-down {
  transform: translateY(-20px);
  opacity: 0;
  animation: slideDown 0.3s ease-out forwards;
}

@keyframes fadeIn {
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes slideDown {
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Card component styles */
.card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  transition: all 0.2s ease;
}

.card:hover {
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.card-interactive {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.card-interactive:active {
  transform: scale(0.98);
}

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

.form-label {
  display: block;
  font-weight: 500;
  color: #374151;
  margin-bottom: 0.5rem;
  font-size: 14px;
}

.form-input {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 12px 16px;
  font-size: 16px;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
  background-color: white;
}

/* Input with left icon */
.form-input.pl-10 {
  padding-left: 2.5rem; /* 40px */
}

/* Input with right icon */
.form-input.pr-10 {
  padding-right: 2.5rem; /* 40px */
}

/* Input with both left and right icons */
.form-input.pl-10.pr-10 {
  padding-left: 2.5rem;
  padding-right: 2.5rem;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-input.error {
  border-color: #ef4444;
}

.form-input.error:focus {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.form-error {
  color: #ef4444;
  font-size: 14px;
  margin-top: 0.25rem;
}

/* Button styles */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.2s ease;
  cursor: pointer;
  border: none;
  font-size: 14px;
  line-height: 1.5;
  min-height: 44px;
  padding: 10px 16px;
  -webkit-tap-highlight-color: transparent;
}

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

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

.btn-primary:hover:not(:disabled) {
  background-color: var(--primary-700);
}

.btn-primary:active:not(:disabled) {
  background-color: var(--primary-800);
}

.btn-secondary {
  background-color: white;
  color: #374151;
  border: 1px solid #d1d5db;
}

.btn-secondary:hover:not(:disabled) {
  background-color: #f9fafb;
  border-color: #9ca3af;
}

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

.btn-outline:hover:not(:disabled) {
  background-color: var(--primary-50);
}

.btn-ghost {
  background-color: transparent;
  color: #6b7280;
}

.btn-ghost:hover:not(:disabled) {
  background-color: #f3f4f6;
  color: #374151;
}

/* Utility classes */
.text-truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .card {
    border: 1px solid #000;
  }
  
  .btn {
    border: 1px solid currentColor;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Print styles */
@media print {
  .no-print {
    display: none !important;
  }
  
  body {
    font-size: 12pt;
    line-height: 1.5;
  }
  
  .card {
    box-shadow: none;
    border: 1px solid #ccc;
  }
}

/* Custom components */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-success {
  background-color: #dcfce7;
  color: #166534;
}

.badge-warning {
  background-color: #fef3c7;
  color: #92400e;
}

.badge-error {
  background-color: #fee2e2;
  color: #991b1b;
}

.badge-info {
  background-color: #dbeafe;
  color: #1e40af;
}

/* Loading states */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
}

@keyframes loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* Search and filter components */
.search-container {
  position: relative;
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1px solid #d1d5db;
  border-top: none;
  border-radius: 0 0 6px 6px;
  max-height: 300px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.search-result-item {
  padding: 12px 16px;
  border-bottom: 1px solid #f3f4f6;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.search-result-item:hover {
  background-color: #f9fafb;
}

.search-result-item:last-child {
  border-bottom: none;
}

/* Navigation enhancements */
.nav-link {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  color: #6b7280;
  text-decoration: none;
  border-radius: 6px;
  transition: all 0.15s ease;
  font-weight: 500;
  min-height: 44px;
}

.nav-link:hover {
  background-color: #f3f4f6;
  color: #374151;
}

.nav-link.active {
  background-color: var(--primary-50);
  color: var(--primary-700);
}

.nav-link svg {
  width: 20px;
  height: 20px;
  margin-right: 12px;
  flex-shrink: 0;
}

/* Override nav-link SVG margin when sidebar is collapsed */
.nav-link.sidebar-icon-centered svg {
  margin-right: 0 !important;
  margin-left: 0 !important;
}

/* Mobile navigation specific */
@media (max-width: 768px) {
  .mobile-nav-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    color: #6b7280;
    text-decoration: none;
    transition: color 0.15s ease;
    min-height: 60px;
    font-size: 12px;
    font-weight: 500;
  }
  
  .mobile-nav-link.active {
    color: var(--primary-600);
  }
  
  .mobile-nav-link svg {
    width: 24px;
    height: 24px;
    margin-bottom: 4px;
  }
}

/* Responsive tables */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
  .table-mobile-cards .table-row {
    display: block;
    background: white;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  }
  
  .table-mobile-cards .table-cell {
    display: block;
    padding: 4px 0;
    border: none;
  }
  
  .table-mobile-cards .table-cell::before {
    content: attr(data-label) ': ';
    font-weight: 600;
    color: #374151;
  }
}

/* Form validation styles */
.field-error {
  border-color: #ef4444 !important;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1) !important;
}

.field-success {
  border-color: #10b981 !important;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1) !important;
}

/* Accessibility improvements */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.focus-visible:focus-visible {
  outline: 2px solid var(--primary-500);
  outline-offset: 2px;
}

/* Custom utilities for the school platform */
.grade-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-weight: 600;
  font-size: 14px;
}

.grade-a { background-color: #dcfce7; color: #166534; }
.grade-b { background-color: #d1fae5; color: #065f46; }
.grade-c { background-color: #fef3c7; color: #92400e; }
.grade-d { background-color: #fed7aa; color: #9a3412; }
.grade-f { background-color: #fee2e2; color: #991b1b; }

.attendance-status {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.attendance-present { background-color: #dcfce7; color: #166534; }
.attendance-absent { background-color: #fee2e2; color: #991b1b; }
.attendance-late { background-color: #fef3c7; color: #92400e; }
.attendance-excused { background-color: #e0e7ff; color: #3730a3; }

/* Collapsible Sidebar Styles */
.sidebar-collapsed {
  width: 4rem !important; /* 64px */
}

.sidebar-expanded {
  width: 16rem !important; /* 256px */
}

/* Sidebar transition smoothing */
.sidebar-transition {
  transition: width 0.3s ease-in-out;
}

/* When sidebar is collapsed, center icons and hide text */
.sidebar-collapsed .nav-link {
  justify-content: center !important;
  padding-left: 12px !important;
  padding-right: 12px !important;
}

.sidebar-collapsed .nav-link svg {
  margin-right: 0 !important;
  margin-left: 0 !important;
}

/* Tooltip styles for collapsed sidebar */
.tooltip {
  position: relative;
}

.tooltip:hover::after {
  content: attr(title);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background-color: #374151;
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  white-space: nowrap;
  z-index: 1000;
  opacity: 0;
  animation: tooltipFadeIn 0.2s ease-in-out forwards;
}

.tooltip:hover::before {
  content: '';
  position: absolute;
  left: calc(100% + 4px);
  top: 50%;
  transform: translateY(-50%);
  border: 6px solid transparent;
  border-right-color: #374151;
  z-index: 1000;
  opacity: 0;
  animation: tooltipFadeIn 0.2s ease-in-out forwards;
}

@keyframes tooltipFadeIn {
  from {
    opacity: 0;
    transform: translateY(-50%) translateX(-5px);
  }
  to {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
  }
}

/* Only show tooltips on desktop when sidebar is collapsed */
@media (min-width: 1024px) {
  .sidebar-collapsed .nav-link[title]:hover::after,
  .sidebar-collapsed .nav-link[title]:hover::before {
    display: block;
  }
}

/* Hide tooltips on mobile */
@media (max-width: 1023px) {
  .tooltip:hover::after,
  .tooltip:hover::before {
    display: none !important;
  }
}