/**
 * VIGURA - Global Responsive CSS Framework
 * Mobile-first, collision-free, production-ready
 */

/* =====================================================
   CSS VARIABLES
   ===================================================== */
:root {
  /* Breakpoints (for reference in JS) */
  --bp-xs: 320px;
  --bp-sm: 375px;
  --bp-md: 768px;
  --bp-lg: 1024px;
  --bp-xl: 1280px;
  --bp-2xl: 1536px;

  /* Spacing Scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Safe Areas (for notch devices) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  /* Header Height */
  --header-height: 56px;
  --header-height-lg: 64px;

  /* Touch Target Minimum */
  --touch-min: 44px;

  /* Z-Index Scale */
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-fixed: 300;
  --z-modal-backdrop: 400;
  --z-modal: 500;
  --z-tooltip: 600;
  --z-toast: 700;
}

/* =====================================================
   GLOBAL RESETS & FOUNDATIONS
   ===================================================== */

/* Prevent horizontal overflow */
html,
body {
  overflow-x: hidden;
  width: 100%;
}

/* Box sizing for all elements */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Safe area padding for body */
body {
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* Responsive images */
img,
video,
iframe,
embed,
object {
  max-width: 100%;
  height: auto;
}

/* Prevent text overflow */
h1,
h2,
h3,
h4,
h5,
h6,
p,
li,
td,
th,
label,
span,
a {
  overflow-wrap: break-word;
  word-wrap: break-word;
  word-break: break-word;
  hyphens: auto;
}

/* Long URLs and strings */
.break-all {
  word-break: break-all;
}

/* =====================================================
   TOUCH-FRIENDLY ELEMENTS
   ===================================================== */

/* Minimum touch target size */
button,
a.btn,
input[type="submit"],
input[type="button"],
.touch-target {
  min-height: var(--touch-min);
  min-width: var(--touch-min);
}

/* Larger tap areas on mobile */
@media (max-width: 768px) {

  input[type="checkbox"],
  input[type="radio"] {
    min-width: 20px;
    min-height: 20px;
  }

  select {
    min-height: var(--touch-min);
  }
}

/* =====================================================
   RESPONSIVE TABLES
   ===================================================== */

/* Table wrapper for horizontal scroll */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Prevent table from breaking layout */
table {
  width: 100%;
  min-width: 600px;
  /* Minimum width before scroll */
}

/* Stack table on very small screens */
@media (max-width: 640px) {
  .table-stack thead {
    display: none;
  }

  .table-stack tbody tr {
    display: block;
    margin-bottom: 1rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    padding: 0.5rem;
  }

  .table-stack tbody td {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem;
    border: none;
    border-bottom: 1px solid #f3f4f6;
  }

  .table-stack tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    margin-right: 1rem;
  }

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

/* =====================================================
   RESPONSIVE MODALS
   ===================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: var(--z-modal-backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-content {
  background: white;
  border-radius: 1rem;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  width: 100%;
}

@media (min-width: 768px) {
  .modal-content {
    max-width: 500px;
  }
}

@media (min-width: 1024px) {
  .modal-content.modal-lg {
    max-width: 800px;
  }

  .modal-content.modal-xl {
    max-width: 1140px;
  }
}

/* =====================================================
   RESPONSIVE GRID UTILITIES
   ===================================================== */

/* Auto-fit grid */
.grid-auto {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

/* Responsive columns */
.grid-cols-responsive {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .grid-cols-responsive {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .grid-cols-responsive {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1280px) {
  .grid-cols-responsive {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* =====================================================
   RESPONSIVE FORMS
   ===================================================== */

/* Form group stacking */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

/* Inline form on larger screens */
@media (min-width: 768px) {
  .form-inline {
    flex-direction: row;
    align-items: center;
  }

  .form-inline label {
    min-width: 150px;
  }
}

/* Full-width inputs on mobile */
@media (max-width: 640px) {

  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea {
    width: 100% !important;
  }

  .btn-group {
    flex-direction: column;
  }

  .btn-group>* {
    width: 100%;
  }
}

/* =====================================================
   RESPONSIVE NAVIGATION
   ===================================================== */

/* Fixed header spacing */
.has-fixed-header {
  padding-top: var(--header-height);
}

@media (min-width: 1024px) {
  .has-fixed-header {
    padding-top: var(--header-height-lg);
  }
}

/* Mobile menu overlay */
.mobile-menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: var(--z-modal-backdrop);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.mobile-menu-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* Mobile slide menu */
.mobile-menu-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(320px, 85vw);
  background: white;
  z-index: var(--z-modal);
  transform: translateX(100%);
  transition: transform 0.3s ease;
  overflow-y: auto;
}

.mobile-menu-panel.active {
  transform: translateX(0);
}

/* =====================================================
   RESPONSIVE SIDEBAR (ADMIN)
   ===================================================== */

.admin-layout {
  display: flex;
  min-height: 100vh;
}

.admin-sidebar {
  width: 256px;
  flex-shrink: 0;
  background: #0d1b12;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: var(--z-fixed);
  transform: translateX(-100%);
  transition: transform 0.3s ease;
}

.admin-sidebar.open {
  transform: translateX(0);
}

.admin-content {
  flex: 1;
  min-width: 0;
  padding: 1rem;
}

@media (min-width: 1024px) {
  .admin-sidebar {
    transform: translateX(0);
  }

  .admin-content {
    margin-left: 256px;
  }
}

/* =====================================================
   DROPDOWN POSITIONING
   ===================================================== */

.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  min-width: 200px;
  max-width: min(300px, 90vw);
  background: white;
  border-radius: 0.5rem;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  z-index: var(--z-dropdown);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s ease;
}

.dropdown:hover .dropdown-menu,
.dropdown.active .dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Prevent dropdown overflow on mobile */
@media (max-width: 640px) {
  .dropdown-menu {
    position: fixed;
    top: auto;
    right: 1rem;
    left: 1rem;
    bottom: 1rem;
    max-width: none;
  }
}

/* =====================================================
   FLUID TYPOGRAPHY
   ===================================================== */

html {
  font-size: clamp(14px, 2vw, 16px);
}

h1 {
  font-size: clamp(1.75rem, 5vw, 3rem);
  line-height: 1.2;
}

h2 {
  font-size: clamp(1.5rem, 4vw, 2.25rem);
  line-height: 1.25;
}

h3 {
  font-size: clamp(1.25rem, 3vw, 1.75rem);
  line-height: 1.3;
}

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

/* Hide on mobile */
@media (max-width: 767px) {
  .hide-mobile {
    display: none !important;
  }
}

/* Hide on desktop */
@media (min-width: 768px) {
  .hide-desktop {
    display: none !important;
  }
}

/* Show only on mobile */
@media (min-width: 768px) {
  .show-mobile-only {
    display: none !important;
  }
}

/* Container with max width */
.container-safe {
  width: 100%;
  max-width: 1280px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 1rem;
  padding-right: 1rem;
}

@media (min-width: 640px) {
  .container-safe {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }
}

@media (min-width: 1024px) {
  .container-safe {
    padding-left: 2rem;
    padding-right: 2rem;
  }
}

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

/* Line clamp */
.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.line-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* =====================================================
   ACCESSIBILITY
   ===================================================== */

/* Focus ring */
:focus-visible {
  outline: 2px solid #2bee6c;
  outline-offset: 2px;
}

/* Skip link */
.skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  background: #2bee6c;
  color: #0d1b12;
  padding: 0.5rem 1rem;
  z-index: 9999;
}

.skip-link:focus {
  top: 0;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}