/**
 * Layout Utilities Component - ELITE VERSION
 * Sistema de utilidades de layout modernas y escalables
 * Inspirado en Tailwind CSS, Chakra UI, Material Design
 * Integrado con design-system.css
 */

/* ===== IMPORTAR DESIGN SYSTEM ===== */
@import url("../design-system.css");

/* ===== VARIABLES ESPECÍFICAS ===== */
:root {
  /* Container system */
  --container-xs: 100%;
  --container-sm: 540px;
  --container-md: 720px;
  --container-lg: 960px;
  --container-xl: 1140px;
  --container-xxl: 1320px;

  /* Grid system */
  --grid-columns: 12;
  --grid-gutter: var(--space-6);
  --grid-margin: var(--space-4);

  /* Layout breakpoints */
  --breakpoint-xs: 0;
  --breakpoint-sm: 576px;
  --breakpoint-md: 768px;
  --breakpoint-lg: 992px;
  --breakpoint-xl: 1200px;
  --breakpoint-xxl: 1400px;
}

/* ===== CONTAINER SYSTEM ===== */
.container {
  width: 100%;
  max-width: var(--container-xl);
  margin-inline: auto;
  padding-inline: var(--space-4);
}

.container-sm {
  max-width: var(--container-sm);
}
.container-md {
  max-width: var(--container-md);
}
.container-lg {
  max-width: var(--container-lg);
}
.container-xl {
  max-width: var(--container-xl);
}
.container-xxl {
  max-width: var(--container-xxl);
}

.container-fluid {
  width: 100%;
  max-width: none;
  margin-inline: auto;
  padding-inline: var(--space-4);
}

/* ===== GRID SYSTEM MODERNO ===== */
.grid {
  display: grid;
  gap: var(--grid-gutter);
}

.grid-cols-1 {
  grid-template-columns: repeat(1, minmax(0, 1fr));
}
.grid-cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.grid-cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.grid-cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.grid-cols-5 {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}
.grid-cols-6 {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}
.grid-cols-12 {
  grid-template-columns: repeat(12, minmax(0, 1fr));
}

.grid-auto-fit {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.grid-auto-fill {
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

/* ===== FLEXBOX UTILITIES ===== */
.flex {
  display: flex;
}
.inline-flex {
  display: inline-flex;
}

.flex-row {
  flex-direction: row;
}
.flex-col {
  flex-direction: column;
}
.flex-row-reverse {
  flex-direction: row-reverse;
}
.flex-col-reverse {
  flex-direction: column-reverse;
}

.flex-wrap {
  flex-wrap: wrap;
}
.flex-nowrap {
  flex-wrap: nowrap;
}
.flex-wrap-reverse {
  flex-wrap: wrap-reverse;
}

.items-start {
  align-items: flex-start;
}
.items-center {
  align-items: center;
}
.items-end {
  align-items: flex-end;
}
.items-baseline {
  align-items: baseline;
}
.items-stretch {
  align-items: stretch;
}

.justify-start {
  justify-content: flex-start;
}
.justify-center {
  justify-content: center;
}
.justify-end {
  justify-content: flex-end;
}
.justify-between {
  justify-content: space-between;
}
.justify-around {
  justify-content: space-around;
}
.justify-evenly {
  justify-content: space-evenly;
}

.content-start {
  align-content: flex-start;
}
.content-center {
  align-content: center;
}
.content-end {
  align-content: flex-end;
}
.content-between {
  align-content: space-between;
}
.content-around {
  align-content: space-around;
}
.content-evenly {
  align-content: space-evenly;
}

.self-auto {
  align-self: auto;
}
.self-start {
  align-self: flex-start;
}
.self-center {
  align-self: center;
}
.self-end {
  align-self: flex-end;
}
.self-stretch {
  align-self: stretch;
}

.flex-1 {
  flex: 1 1 0%;
}
.flex-auto {
  flex: 1 1 auto;
}
.flex-initial {
  flex: 0 1 auto;
}
.flex-none {
  flex: none;
}

.grow {
  flex-grow: 1;
}
.grow-0 {
  flex-grow: 0;
}
.shrink {
  flex-shrink: 1;
}
.shrink-0 {
  flex-shrink: 0;
}

/* ===== SPACING UTILITIES ===== */
.gap-0 {
  gap: 0;
}
.gap-1 {
  gap: var(--space-1);
}
.gap-2 {
  gap: var(--space-2);
}
.gap-3 {
  gap: var(--space-3);
}
.gap-4 {
  gap: var(--space-4);
}
.gap-5 {
  gap: var(--space-5);
}
.gap-6 {
  gap: var(--space-6);
}
.gap-8 {
  gap: var(--space-8);
}
.gap-10 {
  gap: var(--space-10);
}
.gap-12 {
  gap: var(--space-12);
}
.gap-16 {
  gap: var(--space-16);
}
.gap-20 {
  gap: var(--space-20);
}
.gap-24 {
  gap: var(--space-24);
}
.gap-32 {
  gap: var(--space-32);
}

.gap-x-0 {
  column-gap: 0;
}
.gap-x-1 {
  column-gap: var(--space-1);
}
.gap-x-2 {
  column-gap: var(--space-2);
}
.gap-x-3 {
  column-gap: var(--space-3);
}
.gap-x-4 {
  column-gap: var(--space-4);
}
.gap-x-5 {
  column-gap: var(--space-5);
}
.gap-x-6 {
  column-gap: var(--space-6);
}
.gap-x-8 {
  column-gap: var(--space-8);
}

.gap-y-0 {
  row-gap: 0;
}
.gap-y-1 {
  row-gap: var(--space-1);
}
.gap-y-2 {
  row-gap: var(--space-2);
}
.gap-y-3 {
  row-gap: var(--space-3);
}
.gap-y-4 {
  row-gap: var(--space-4);
}
.gap-y-5 {
  row-gap: var(--space-5);
}
.gap-y-6 {
  row-gap: var(--space-6);
}
.gap-y-8 {
  row-gap: var(--space-8);
}

/* ===== POSITIONING UTILITIES ===== */
.static {
  position: static;
}
.fixed {
  position: fixed;
}
.absolute {
  position: absolute;
}
.relative {
  position: relative;
}
.sticky {
  position: sticky;
}

.inset-0 {
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}
.inset-auto {
  top: auto;
  right: auto;
  bottom: auto;
  left: auto;
}

.top-0 {
  top: 0;
}
.top-auto {
  top: auto;
}
.right-0 {
  right: 0;
}
.right-auto {
  right: auto;
}
.bottom-0 {
  bottom: 0;
}
.bottom-auto {
  bottom: auto;
}
.left-0 {
  left: 0;
}
.left-auto {
  left: auto;
}

/* ===== DISPLAY UTILITIES ===== */
.block {
  display: block;
}
.inline-block {
  display: inline-block;
}
.inline {
  display: inline;
}
.hidden {
  display: none;
}
.table {
  display: table;
}
.table-cell {
  display: table-cell;
}
.table-row {
  display: table-row;
}

/* ===== OVERFLOW UTILITIES ===== */
.overflow-auto {
  overflow: auto;
}
.overflow-hidden {
  overflow: hidden;
}
.overflow-visible {
  overflow: visible;
}
.overflow-scroll {
  overflow: scroll;
}

.overflow-x-auto {
  overflow-x: auto;
}
.overflow-x-hidden {
  overflow-x: hidden;
}
.overflow-x-visible {
  overflow-x: visible;
}
.overflow-x-scroll {
  overflow-x: scroll;
}

.overflow-y-auto {
  overflow-y: auto;
}
.overflow-y-hidden {
  overflow-y: hidden;
}
.overflow-y-visible {
  overflow-y: visible;
}
.overflow-y-scroll {
  overflow-y: scroll;
}

/* ===== FLOAT UTILITIES ===== */
.float-left {
  float: left;
}
.float-right {
  float: right;
}
.float-none {
  float: none;
}

.clear-left {
  clear: left;
}
.clear-right {
  clear: right;
}
.clear-both {
  clear: both;
}
.clear-none {
  clear: none;
}

/* ===== VISIBILITY UTILITIES ===== */
.visible {
  visibility: visible;
}
.invisible {
  visibility: hidden;
}

/* ⚠️  COMENTADO - INTERFERÍA CON BOOTSTRAP NAVBAR */
/*
.collapse {
  visibility: collapse;
}
*/

/* ===== Z-INDEX UTILITIES ===== */
.z-auto {
  z-index: auto;
}
.z-0 {
  z-index: 0;
}
.z-10 {
  z-index: 10;
}
.z-20 {
  z-index: 20;
}
.z-30 {
  z-index: 30;
}
.z-40 {
  z-index: 40;
}
.z-50 {
  z-index: 50;
}

/* ===== ASPECT RATIO UTILITIES ===== */
.aspect-auto {
  aspect-ratio: auto;
}
.aspect-square {
  aspect-ratio: 1 / 1;
}
.aspect-video {
  aspect-ratio: 16 / 9;
}
.aspect-photo {
  aspect-ratio: 4 / 3;
}
.aspect-portrait {
  aspect-ratio: 3 / 4;
}

/* ===== LAYOUT PATTERN UTILITIES ===== */
.center-content {
  display: flex;
  align-items: center;
  justify-content: center;
}

.center-x {
  display: flex;
  justify-content: center;
}

.center-y {
  display: flex;
  align-items: center;
}

.full-screen {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
}

.full-width {
  width: 100%;
}

.full-height {
  height: 100%;
}

.min-full-height {
  min-height: 100vh;
}

.max-content {
  width: max-content;
}

.min-content {
  width: min-content;
}

.fit-content {
  width: fit-content;
}

/* ===== CONTENT LAYOUT PATTERNS ===== */
.content-layout {
  display: grid;
  grid-template-columns: 1fr min(65ch, 100%) 1fr;
  gap: var(--space-4);
}

.content-layout > * {
  grid-column: 2;
}

.content-layout > .full-bleed {
  grid-column: 1 / -1;
}

.sidebar-layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: var(--space-6);
}

.header-main-footer {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--space-6);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  align-items: center;
}

.reel {
  display: flex;
  gap: var(--space-4);
  overflow-x: auto;
  scrollbar-width: thin;
}

.reel::-webkit-scrollbar {
  height: 8px;
}

.reel::-webkit-scrollbar-track {
  background: var(--color-surface-variant);
}

.reel::-webkit-scrollbar-thumb {
  background: var(--color-outline);
  border-radius: var(--radius-full);
}

.reel > * {
  flex: 0 0 auto;
}

/* ===== CONTAINER QUERIES AVANZADAS ===== */
@supports (container-type: inline-size) {
  .container-query {
    container-type: inline-size;
  }

  .card-container {
    container-type: inline-size;
    container-name: card;
  }

  @container card (min-width: 400px) {
    .card-adaptive {
      display: grid;
      grid-template-columns: auto 1fr;
      gap: var(--space-4);
    }
  }

  .section-container {
    container-type: inline-size;
    container-name: section;
  }

  @container section (min-width: 600px) {
    .section-adaptive {
      display: grid;
      grid-template-columns: 1fr 2fr;
      gap: var(--space-8);
    }
  }
}

/* ===== PROPIEDADES LÓGICAS MODERNAS ===== */
.margin-inline-auto {
  margin-inline: auto;
}

.padding-block-start {
  padding-block-start: var(--space-4);
}

.padding-block-end {
  padding-block-end: var(--space-4);
}

.padding-inline-start {
  padding-inline-start: var(--space-4);
}

.padding-inline-end {
  padding-inline-end: var(--space-4);
}

.border-inline-start {
  border-inline-start: 1px solid var(--color-outline);
}

.border-inline-end {
  border-inline-end: 1px solid var(--color-outline);
}

.border-block-start {
  border-block-start: 1px solid var(--color-outline);
}

.border-block-end {
  border-block-end: 1px solid var(--color-outline);
}

/* ===== VIEW TRANSITIONS ===== */
@supports (view-transition-name: none) {
  .view-transition {
    view-transition-name: var(--view-transition-name, auto);
  }

  .view-transition-root {
    view-transition-name: root;
  }

  .view-transition-card {
    view-transition-name: card;
  }

  .view-transition-hero {
    view-transition-name: hero;
  }
}

@supports (view-transition: same) {
  ::view-transition-group(*) {
    animation-duration: var(--duration-normal);
    animation-timing-function: var(--easing-standard);
  }

  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: var(--duration-slow);
  }

  ::view-transition-old(root) {
    animation-name: layoutFadeOut;
  }

  ::view-transition-new(root) {
    animation-name: layoutFadeIn;
  }

  @keyframes layoutFadeIn {
    from {
      opacity: 0;
      transform: translateY(var(--space-4));
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  @keyframes layoutFadeOut {
    from {
      opacity: 1;
      transform: translateY(0);
    }
    to {
      opacity: 0;
      transform: translateY(calc(var(--space-4) * -1));
    }
  }
}

/* ===== RESPONSIVE UTILITIES ===== */
@media (min-width: 576px) {
  .sm\:block {
    display: block;
  }
  .sm\:hidden {
    display: none;
  }
  .sm\:flex {
    display: flex;
  }
  .sm\:grid {
    display: grid;
  }
  .sm\:grid-cols-1 {
    grid-template-columns: repeat(1, minmax(0, 1fr));
  }
  .sm\:grid-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .sm\:grid-cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .sm\:flex-row {
    flex-direction: row;
  }
  .sm\:flex-col {
    flex-direction: column;
  }
  .sm\:justify-start {
    justify-content: flex-start;
  }
  .sm\:justify-center {
    justify-content: center;
  }
  .sm\:justify-end {
    justify-content: flex-end;
  }
  .sm\:items-start {
    align-items: flex-start;
  }
  .sm\:items-center {
    align-items: center;
  }
  .sm\:items-end {
    align-items: flex-end;
  }
}

@media (min-width: 768px) {
  .md\:block {
    display: block;
  }
  .md\:hidden {
    display: none;
  }
  .md\:flex {
    display: flex;
  }
  .md\:grid {
    display: grid;
  }
  .md\:grid-cols-1 {
    grid-template-columns: repeat(1, minmax(0, 1fr));
  }
  .md\:grid-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .md\:grid-cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .md\:grid-cols-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .md\:flex-row {
    flex-direction: row;
  }
  .md\:flex-col {
    flex-direction: column;
  }
  .md\:justify-start {
    justify-content: flex-start;
  }
  .md\:justify-center {
    justify-content: center;
  }
  .md\:justify-end {
    justify-content: flex-end;
  }
  .md\:items-start {
    align-items: flex-start;
  }
  .md\:items-center {
    align-items: center;
  }
  .md\:items-end {
    align-items: flex-end;
  }

  .sidebar-layout {
    grid-template-columns: 300px 1fr;
  }
}

@media (min-width: 992px) {
  .lg\:block {
    display: block;
  }
  .lg\:hidden {
    display: none;
  }
  .lg\:flex {
    display: flex;
  }
  .lg\:grid {
    display: grid;
  }
  .lg\:grid-cols-1 {
    grid-template-columns: repeat(1, minmax(0, 1fr));
  }
  .lg\:grid-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .lg\:grid-cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .lg\:grid-cols-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .lg\:grid-cols-5 {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
  .lg\:flex-row {
    flex-direction: row;
  }
  .lg\:flex-col {
    flex-direction: column;
  }
  .lg\:justify-start {
    justify-content: flex-start;
  }
  .lg\:justify-center {
    justify-content: center;
  }
  .lg\:justify-end {
    justify-content: flex-end;
  }
  .lg\:items-start {
    align-items: flex-start;
  }
  .lg\:items-center {
    align-items: center;
  }
  .lg\:items-end {
    align-items: flex-end;
  }

  .card-grid {
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  }
}

@media (min-width: 1200px) {
  .xl\:block {
    display: block;
  }
  .xl\:hidden {
    display: none;
  }
  .xl\:flex {
    display: flex;
  }
  .xl\:grid {
    display: grid;
  }
  .xl\:grid-cols-1 {
    grid-template-columns: repeat(1, minmax(0, 1fr));
  }
  .xl\:grid-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .xl\:grid-cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .xl\:grid-cols-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .xl\:grid-cols-5 {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
  .xl\:grid-cols-6 {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
  .xl\:flex-row {
    flex-direction: row;
  }
  .xl\:flex-col {
    flex-direction: column;
  }
  .xl\:justify-start {
    justify-content: flex-start;
  }
  .xl\:justify-center {
    justify-content: center;
  }
  .xl\:justify-end {
    justify-content: flex-end;
  }
  .xl\:items-start {
    align-items: flex-start;
  }
  .xl\:items-center {
    align-items: center;
  }
  .xl\:items-end {
    align-items: flex-end;
  }

  .card-grid {
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  }
}

/* ===== ACCESSIBILITY ===== */
@media (prefers-reduced-motion: reduce) {
  .reel {
    scroll-behavior: auto;
  }

  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none;
  }
}

@media (forced-colors: active) {
  .container,
  .card-container,
  .section-container {
    border: 1px solid;
  }

  .reel::-webkit-scrollbar-thumb {
    background: CanvasText;
  }
}

@media (pointer: coarse) {
  .reel {
    scrollbar-width: thick;
  }

  .reel::-webkit-scrollbar {
    height: 12px;
  }
}

/* ===== DARK MODE ===== */
[data-bs-theme="dark"] {
  /* Variables ya definidas en design-system.css */
}

/* ===== PRINT STYLES ===== */
@media print {
  .hidden-print {
    display: none;
  }
  .visible-print {
    display: block;
  }

  .container,
  .container-sm,
  .container-md,
  .container-lg,
  .container-xl,
  .container-xxl {
    max-width: none;
    padding: 0;
  }

  .grid,
  .flex,
  .card-grid {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .sidebar-layout {
    grid-template-columns: 1fr;
  }

  .reel {
    overflow-x: visible;
    flex-wrap: wrap;
  }

  .full-screen {
    position: static;
    width: auto;
    height: auto;
  }
}

/* ===== DEBUGGING ===== */
@media screen and (max-width: 0px) {
  .debug-layout-utilities::before {
    content: "📐 Layout ELITE";
    position: fixed;
    top: 200px;
    right: 10px;
    background: var(--color-secondary-500);
    color: var(--color-on-secondary);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
    z-index: var(--z-debug);
    opacity: 0.8;
  }
}
