/* ====================================================================
   RESPONSIVE FIXES - Correcciones de Alineación y Centrado
   Optimizado para PC, Tablet (iPad, Android tablets) y Móvil
   ==================================================================== */

/* ============ GLOBAL FIXES ============ */
html {
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
}

body {
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
  margin: 0;
  padding: 0;
}

* {
  box-sizing: border-box;
}

/* Prevenir scroll horizontal en cualquier elemento */
.app-container,
.main-content,
.content-section,
.grow-dashboard,
.grow-dashboard .container {
  overflow-x: hidden !important;
  max-width: 100%;
}

/* ============ DASHBOARD ALIGNMENT FIXES ============ */

/* Asegurar que el container del dashboard esté centrado */
.grow-dashboard .container {
  margin-left: auto;
  margin-right: auto;
  padding-left: 22px;
  padding-right: 22px;
}

/* Fix para rows que se desplazan a la derecha */
.grow-dashboard .row,
.grow-dashboard .row-top,
.grow-dashboard .row-bot {
  width: 100%;
  max-width: 100%;
  margin-left: 0;
  margin-right: 0;
}

/* Asegurar que las áreas no se desborden */
.grow-dashboard .area {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow-x: hidden;
}

/* Cycle banner centrado */
.grow-dashboard .cycle-banner {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  margin-left: 0;
  margin-right: 0;
}

/* ============ TABLET OPTIMIZATIONS (768px - 1024px) ============ */
@media (min-width: 768px) and (max-width: 1024px) {
  /* Dashboard container */
  .grow-dashboard .container {
    padding-left: 18px;
    padding-right: 18px;
    max-width: 100%;
  }
  
  /* Rows en tablet */
  .grow-dashboard .row-top {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .grow-dashboard .row-bot {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
  }
  
  /* Cycle banner responsive */
  .grow-dashboard .cycle-banner {
    padding: 18px 20px;
  }
  
  /* Areas más compactas */
  .grow-dashboard .area {
    padding: 16px 18px;
  }
  
  /* Main content en dashboard */
  .main-content {
    padding: 1.25rem;
  }
  
  /* Content header ajustado */
  .content-header {
    padding: 0.875rem 0;
  }
  
  .content-title {
    font-size: 1.65rem;
  }
}

/* ============ MÓVIL OPTIMIZATIONS (hasta 767px) ============ */
@media (max-width: 767px) {
  /* Dashboard container móvil */
  .grow-dashboard .container {
    padding: 14px 12px;
    max-width: 100%;
  }
  
  /* Todas las rows en 1 columna */
  .grow-dashboard .row-top,
  .grow-dashboard .row-bot {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  
  /* Cycle banner móvil */
  .grow-dashboard .cycle-banner {
    padding: 16px;
    flex-direction: column;
    text-align: center;
    align-items: center;
  }
  
  .grow-dashboard .cycle-info {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  
  .grow-dashboard .cycle-primary,
  .grow-dashboard .cycle-secondary {
    justify-content: center;
  }
  
  /* Areas móvil */
  .grow-dashboard .area {
    padding: 14px 16px;
    margin-bottom: 14px;
  }
  
  /* Main content móvil */
  .main-content {
    padding: 1rem;
    width: 100%;
    margin-left: 0 !important;
  }
  
  /* Content header móvil */
  .content-header {
    padding: 0.75rem 0;
    flex-wrap: wrap;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  
  .content-title {
    font-size: 1.5rem;
    flex: 1 1 auto;
    order: 1;
  }
  
  .header-controls {
    flex: 0 0 auto;
    margin-left: auto; /* A LA DERECHA */
    order: 2;
    display: flex;
    gap: 0.5rem;
  }
  
  /* Canvas responsive */
  canvas {
    max-width: 100%;
    height: auto;
  }
}

/* ============ MÓVIL PEQUEÑO (hasta 480px) ============ */
@media (max-width: 480px) {
  /* Dashboard container extra compacto */
  .grow-dashboard .container {
    padding: 12px 10px;
  }
  
  /* Cycle banner extra compacto */
  .grow-dashboard .cycle-banner {
    padding: 14px;
    gap: 14px;
  }
  
  .grow-dashboard .cycle-icon {
    font-size: 26px;
  }
  
  .grow-dashboard .cycle-primary {
    font-size: 14px;
  }
  
  .grow-dashboard .cycle-number,
  .grow-dashboard .week-number {
    font-size: 16px;
  }
  
  .grow-dashboard .progress-circle {
    width: 60px;
    height: 60px;
  }
  
  /* Areas extra compactas */
  .grow-dashboard .area {
    padding: 12px 14px;
  }
  
  /* Main content extra compacto */
  .main-content {
    padding: 0.75rem;
  }
  
  .content-title {
    font-size: 1.35rem;
  }
}

/* ============ LANDSCAPE TABLET (orientación horizontal) ============ */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
  .grow-dashboard .container {
    padding: 20px 24px;
  }
  
  .grow-dashboard .cycle-banner {
    flex-direction: row;
    text-align: left;
  }
  
  .grow-dashboard .cycle-info {
    flex-direction: row;
    text-align: left;
  }
  
  .grow-dashboard .row-bot {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* ============ PORTRAIT TABLET (orientación vertical) ============ */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
  .grow-dashboard .row-bot {
    grid-template-columns: 1fr;
  }
  
  .grow-dashboard .cycle-banner {
    flex-direction: column;
    text-align: center;
  }
}

/* ============ SIDEBAR FIXES ============ */
@media (max-width: 767px) {
  /* Sidebar móvil */
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    z-index: 2000;
  }
  
  /* Main content sin margin cuando sidebar está oculto */
  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
  }
  
  /* Overlay para cerrar sidebar */
  .sidebar.expanded::before {
    content: none;
  }
}

/* ============ FORMS & INPUTS RESPONSIVE ============ */
@media (max-width: 767px) {
  .form-input,
  .form-control,
  input[type="text"],
  input[type="email"],
  input[type="password"],
  select,
  textarea {
    font-size: 16px !important; /* Previene zoom en iOS */
    padding: 0.75rem;
  }
  
  .btn,
  button {
    padding: 0.75rem 1.25rem;
    font-size: 0.95rem;
  }
}

/* ============ TABLES RESPONSIVE ============ */
@media (max-width: 767px) {
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  table {
    min-width: 600px;
  }
}

/* ============ MODALS RESPONSIVE ============ */
@media (max-width: 767px) {
  .modal {
    width: 95%;
    max-width: 95%;
    margin: 1rem auto;
    max-height: 90vh;
    overflow-y: auto;
  }
  
  .modal-body {
    padding: 1rem;
  }
}

/* ============ CARDS RESPONSIVE ============ */
@media (max-width: 767px) {
  .card {
    margin-bottom: 1rem;
    padding: 1rem;
  }
  
  .card-title {
    font-size: 1.1rem;
  }
}

/* ============ PREVENT HORIZONTAL SCROLL ============ */
.no-scroll-x {
  overflow-x: hidden !important;
  max-width: 100% !important;
}

/* Aplicar a elementos comunes */
.container,
.row,
.col,
.section,
[class*="col-"] {
  max-width: 100%;
  overflow-x: hidden;
}

/* ============ SAFE AREAS (iPhone notch, Android navigation) ============ */
@supports (padding: max(0px)) {
  body {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }
  
  .sidebar {
    padding-left: max(0px, env(safe-area-inset-left));
  }
}

/* ============ TOUCH TARGETS (Accesibilidad móvil) ============ */
@media (max-width: 767px) {
  button,
  a,
  .btn,
  .menu-item,
  .clickable {
    min-height: 44px; /* Tamaño mínimo recomendado por Apple */
    min-width: 44px;
  }
}

/* ============ TEXT READABILITY ============ */
@media (max-width: 767px) {
  body {
    font-size: 15px; /* Tamaño óptimo para móvil */
    line-height: 1.6;
  }
  
  h1 {
    font-size: 1.75rem;
  }
  
  h2 {
    font-size: 1.5rem;
  }
  
  h3 {
    font-size: 1.25rem;
  }
  
  h4 {
    font-size: 1.1rem;
  }
  
  p {
    margin-bottom: 1rem;
  }
}

/* ============ ANDROID SPECIFIC FIXES ============ */
@media (max-width: 767px) {
  /* Fix para teclado Android */
  html.keyboard-open {
    overflow: hidden;
  }
  
  html.keyboard-open body {
    position: fixed;
    width: 100%;
  }
}

/* ============ iOS SPECIFIC FIXES ============ */
@supports (-webkit-touch-callout: none) {
  /* Fix para Safari iOS */
  body {
    -webkit-overflow-scrolling: touch;
  }
  
  /* Fix para input zoom */
  input,
  select,
  textarea {
    font-size: 16px !important;
  }
}

/* ============ PRINT STYLES ============ */
@media print {
  .sidebar,
  .header-controls,
  .mobile-toggle,
  button,
  .btn {
    display: none !important;
  }
  
  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
  }
}
