/**
 * Optimized styles for Community Member Management System
 * Focus on preventing horizontal scroll and mobile optimization
 */

/* CSS Reset and Base Styles */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  line-height: 1.15;
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  overflow-x: hidden;
  max-width: 100vw;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Oxygen, Ubuntu, Cantarell, sans-serif;
  background-color: #f7fafc;
  color: #2d3748;
  line-height: 1.6;
  margin: 0;
  padding: 0;
  margin-top: 80px;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  max-width: 100vw;
  overflow-x: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Mobile adjustments */
@media (max-width: 768px) {
  body {
    margin-top: 70px;
    font-size: 16px; /* Prevent zoom on iOS */
  }
}

main {
  padding-top: 2rem !important;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

/* Container improvements to prevent overflow */
.container {
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
  padding-left: 1rem;
  padding-right: 1rem;
}

@media (min-width: 640px) {
  .container {
    max-width: 640px;
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }
}

@media (min-width: 768px) {
  .container {
    max-width: 768px;
    padding-left: 2rem;
    padding-right: 2rem;
  }
}

@media (min-width: 1024px) {
  .container {
    max-width: 1024px;
  }
}

@media (min-width: 1280px) {
  .container {
    max-width: 1280px;
  }
}

@media (min-width: 1536px) {
  .container {
    max-width: 1536px;
  }
}

/* Prevent horizontal scroll on all elements */
* {
  max-width: 100%;
}

img,
video,
iframe,
embed,
object {
  max-width: 100%;
  height: auto;
}

/* Enhanced focus styles for accessibility */
:focus {
  outline: 2px solid #4299e1;
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

:focus-visible {
  outline: 2px solid #4299e1;
  outline-offset: 2px;
}

/* Optimized scrollbar styles */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
  transition: background-color 0.3s ease;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Scrollbar for dark sections */
.dark-section::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
}

.dark-section::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
}

.dark-section::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.5);
}

/* Enhanced utility classes */
.max-h-80 {
  max-height: 20rem;
}

.min-h-40 {
  min-height: 10rem;
}

.max-w-full {
  max-width: 100%;
}

.w-full {
  width: 100%;
}

/* Responsive table improvements */
.table-fixed {
  table-layout: fixed;
  width: 100%;
}

.table-auto {
  table-layout: auto;
  width: 100%;
}

.responsive-table {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  max-width: 100%;
}

.responsive-table table {
  min-width: 100%;
  white-space: nowrap;
}

@media (max-width: 640px) {
  .responsive-table table {
    min-width: 600px;
    font-size: 0.875rem;
  }

  .responsive-table th,
  .responsive-table td {
    padding: 0.5rem;
  }
}

/* Enhanced badge styles */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  transition: all 0.3s ease;
}

.badge-primary {
  background-color: #dbeafe;
  color: #1e40af;
  border: 1px solid #3b82f6;
}

.badge-success {
  background-color: #dcfce7;
  color: #15803d;
  border: 1px solid #22c55e;
}

.badge-danger {
  background-color: #fef2f2;
  color: #dc2626;
  border: 1px solid #ef4444;
}

.badge-warning {
  background-color: #fefce8;
  color: #ca8a04;
  border: 1px solid #eab308;
}

.badge-info {
  background-color: #f0f9ff;
  color: #0284c7;
  border: 1px solid #0ea5e9;
}

/* Enhanced card hover effects */
.card-hover {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform, box-shadow;
}

.card-hover:hover {
  transform: translateY(-4px);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1),
    0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

@media (prefers-reduced-motion: reduce) {
  .card-hover {
    transition: none;
  }

  .card-hover:hover {
    transform: none;
  }
}

/* Enhanced form styles */
.form-input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  font-size: 1rem;
  transition: all 0.3s ease;
  background-color: #ffffff;
}

.form-input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
  outline: none;
}

.form-input:disabled {
  background-color: #f9fafb;
  color: #6b7280;
  cursor: not-allowed;
}

.input-error {
  border-color: #ef4444 !important;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1) !important;
}

.error-message {
  color: #dc2626;
  font-size: 0.875rem;
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.success-message {
  color: #059669;
  font-size: 0.875rem;
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

/* Button improvements */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 0.5rem;
  font-size: 1rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
}

.btn-primary {
  background-color: #3b82f6;
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background-color: #2563eb;
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: #6b7280;
  color: white;
}

.btn-secondary:hover:not(:disabled) {
  background-color: #4b5563;
  transform: translateY(-1px);
}

.btn-success {
  background-color: #10b981;
  color: white;
}

.btn-success:hover:not(:disabled) {
  background-color: #059669;
  transform: translateY(-1px);
}

.btn-danger {
  background-color: #ef4444;
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background-color: #dc2626;
  transform: translateY(-1px);
}

/* Loading spinner */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid #f3f4f6;
  border-top: 2px solid #3b82f6;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Enhanced animations */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.animate-fade-in {
  animation: fadeIn 0.5s ease-in-out;
}

.animate-fade-in-up {
  animation: fadeInUp 0.6s ease-out;
}

.animate-slide-down {
  animation: slideDown 0.3s ease-in-out;
}

.animate-pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Disable animations for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Mobile navigation optimizations */
.mobile-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 50;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.mobile-nav.open {
  opacity: 1;
  visibility: visible;
}

.mobile-nav-content {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(85vw, 400px);
  background-color: white;
  z-index: 51;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.mobile-nav.open .mobile-nav-content {
  transform: translateX(0);
}

/* Enhanced spacing utilities */
.space-y-1 > * + * {
  margin-top: 0.25rem;
}

.space-y-2 > * + * {
  margin-top: 0.5rem;
}

.space-y-3 > * + * {
  margin-top: 0.75rem;
}

.space-y-4 > * + * {
  margin-top: 1rem;
}

.space-y-6 > * + * {
  margin-top: 1.5rem;
}

.space-y-8 > * + * {
  margin-top: 2rem;
}

.space-x-1 > * + * {
  margin-left: 0.25rem;
}

.space-x-2 > * + * {
  margin-left: 0.5rem;
}

.space-x-3 > * + * {
  margin-left: 0.75rem;
}

.space-x-4 > * + * {
  margin-left: 1rem;
}

.space-x-6 > * + * {
  margin-left: 1.5rem;
}

.space-x-8 > * + * {
  margin-left: 2rem;
}

/* Text utilities */
.text-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.text-balance {
  text-wrap: balance;
}

.text-pretty {
  text-wrap: pretty;
}

/* Mobile-first responsive text sizes */
.text-responsive-xs {
  font-size: clamp(0.75rem, 2vw, 0.875rem);
}

.text-responsive-sm {
  font-size: clamp(0.875rem, 2.5vw, 1rem);
}

.text-responsive-base {
  font-size: clamp(1rem, 3vw, 1.125rem);
}

.text-responsive-lg {
  font-size: clamp(1.125rem, 3.5vw, 1.25rem);
}

.text-responsive-xl {
  font-size: clamp(1.25rem, 4vw, 1.5rem);
}

.text-responsive-2xl {
  font-size: clamp(1.5rem, 5vw, 2rem);
}

.text-responsive-3xl {
  font-size: clamp(1.875rem, 6vw, 2.5rem);
}

.text-responsive-4xl {
  font-size: clamp(2.25rem, 7vw, 3rem);
}

.text-responsive-5xl {
  font-size: clamp(2.5rem, 8vw, 4rem);
}

/* Safe area support for iOS devices */
@supports (padding: max(0px)) {
  .safe-area-inset {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }

  .safe-area-top {
    padding-top: max(1rem, env(safe-area-inset-top));
  }

  .safe-area-bottom {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
}

/* Print optimizations */
@media print {
  *,
  *::before,
  *::after {
    background: white !important;
    color: black !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  header,
  footer,
  nav,
  .no-print,
  .mobile-menu,
  .mobile-menu-overlay,
  .dropdown-menu {
    display: none !important;
  }

  body {
    font-size: 12pt;
    line-height: 1.5;
    margin: 0;
    padding: 0;
    background: white;
  }

  .container {
    max-width: 100% !important;
    width: 100% !important;
    padding: 0;
    margin: 0;
  }

  .print-only {
    display: block !important;
  }

  .page-break {
    page-break-before: always;
  }

  .avoid-break {
    page-break-inside: avoid;
  }

  a[href^="http"]:after {
    content: " (" attr(href) ")";
    font-size: 10pt;
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    page-break-after: avoid;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .btn {
    border: 2px solid currentColor;
  }

  .form-input {
    border-width: 2px;
  }

  .badge {
    border-width: 2px;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #1f2937;
    --bg-secondary: #374151;
    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --border-color: #4b5563;
  }

  body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
  }

  .form-input {
    background-color: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--text-primary);
  }

  .card-hover {
    background-color: var(--bg-secondary);
    border-color: var(--border-color);
  }
}

/* Performance optimizations */
.gpu-accelerated {
  transform: translateZ(0);
  backface-visibility: hidden;
  perspective: 1000px;
}

.will-change-transform {
  will-change: transform;
}

.will-change-opacity {
  will-change: opacity;
}

/* Image optimization */
.responsive-image {
  max-width: 100%;
  height: auto;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.responsive-image:hover {
  transform: scale(1.05);
}

/* Lazy loading support */
.lazy-image {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.lazy-image.loaded {
  opacity: 1;
}

/* Grid improvements */
.responsive-grid {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: 1fr;
  width: 100%;
}

@media (min-width: 640px) {
  .responsive-grid-sm-2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 768px) {
  .responsive-grid-md-2 {
    grid-template-columns: repeat(2, 1fr);
  }

  .responsive-grid-md-3 {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1024px) {
  .responsive-grid-lg-3 {
    grid-template-columns: repeat(3, 1fr);
  }

  .responsive-grid-lg-4 {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Flexbox utilities */
.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.flex-start {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
}

.flex-end {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
}

/* Aspect ratio utilities */
.aspect-square {
  aspect-ratio: 1 / 1;
}

.aspect-video {
  aspect-ratio: 16 / 9;
}

.aspect-photo {
  aspect-ratio: 4 / 3;
}

/* Border radius utilities */
.rounded-xs {
  border-radius: 0.125rem;
}

.rounded-sm {
  border-radius: 0.25rem;
}

.rounded-md {
  border-radius: 0.375rem;
}

.rounded-lg {
  border-radius: 0.5rem;
}

.rounded-xl {
  border-radius: 0.75rem;
}

.rounded-2xl {
  border-radius: 1rem;
}

.rounded-3xl {
  border-radius: 1.5rem;
}

/* Shadow utilities */
.shadow-xs {
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.shadow-sm {
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}

.shadow-md {
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
    0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.shadow-lg {
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1),
    0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.shadow-xl {
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1),
    0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.shadow-2xl {
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

/* Focus within styles for enhanced UX */
.focus-within-ring:focus-within {
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
  border-color: #3b82f6;
}

/* Backdrop blur utilities */
.backdrop-blur-none {
  backdrop-filter: blur(0);
}

.backdrop-blur-sm {
  backdrop-filter: blur(4px);
}

.backdrop-blur {
  backdrop-filter: blur(8px);
}

.backdrop-blur-md {
  backdrop-filter: blur(12px);
}

.backdrop-blur-lg {
  backdrop-filter: blur(16px);
}

.backdrop-blur-xl {
  backdrop-filter: blur(24px);
}

.backdrop-blur-2xl {
  backdrop-filter: blur(40px);
}

.backdrop-blur-3xl {
  backdrop-filter: blur(64px);
}

/* Support for older browsers */
@supports not (backdrop-filter: blur(1px)) {
  .backdrop-blur-sm {
    background-color: rgba(255, 255, 255, 0.8);
  }

  .backdrop-blur {
    background-color: rgba(255, 255, 255, 0.7);
  }

  .backdrop-blur-md {
    background-color: rgba(255, 255, 255, 0.6);
  }

  .backdrop-blur-lg {
    background-color: rgba(255, 255, 255, 0.5);
  }
}

/* Touch optimization for mobile */
@media (hover: none) and (pointer: coarse) {
  .btn {
    min-height: 44px;
    min-width: 44px;
  }

  .form-input {
    min-height: 44px;
  }

  .social-link {
    min-height: 44px;
    min-width: 44px;
  }
}

/* Final overflow prevention */
html,
body,
#root,
#app {
  max-width: 100vw;
  overflow-x: hidden;
}

/* Ensure all children respect the container */
* {
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}

/* Specific fixes for common overflow issues */
pre {
  white-space: pre-wrap;
  word-break: break-all;
}

code {
  word-break: break-all;
}

table {
  table-layout: fixed;
  width: 100%;
}

th,
td {
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Final mobile optimization */
@media (max-width: 767px) {
  * {
    max-width: 100vw !important;
  }

  .container {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    word-break: break-word;
    hyphens: auto;
  }
}
