/* ============================================================
   ConstruTrack — Estilos globales
   ============================================================ */

:root {
  --ct-sidebar-width: 240px;
  --ct-navbar-height: 56px;
  --ct-sidebar-bg: #1a2035;
  --ct-sidebar-text: rgba(255,255,255,.75);
  --ct-sidebar-active: rgba(255,255,255,.12);
  --ct-primary: #1565C0;
  --ct-accent: #FF6F00;
  --ct-radius: 12px;
}

/* ---- Reset / Base ---- */
*, *::before, *::after { box-sizing: border-box; }
body { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

/* ---- Navbar ---- */
.ct-navbar {
  background: var(--ct-sidebar-bg);
  height: var(--ct-navbar-height);
  position: sticky;
  top: 0;
  z-index: 1030;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}

/* ---- Sidebar ---- */
.ct-sidebar {
  width: var(--ct-sidebar-width);
  min-width: var(--ct-sidebar-width);
  background: var(--ct-sidebar-bg);
  display: flex;
  flex-direction: column;
  transition: width .25s ease, min-width .25s ease, transform .25s ease;
  overflow: hidden;
  position: sticky;
  top: var(--ct-navbar-height);
  height: calc(100vh - var(--ct-navbar-height));
  overflow-y: auto;
  /* Scroll suave en iOS */
  -webkit-overflow-scrolling: touch;
}

.ct-sidebar.collapsed {
  width: 0;
  min-width: 0;
}

.sidebar-inner { flex: 1; }

.ct-sidebar .nav-link {
  color: var(--ct-sidebar-text);
  border-radius: 8px;
  margin: 2px 12px;
  font-size: .875rem;
  white-space: nowrap;
  transition: background .15s, color .15s;
  /* Touch target mínimo 44px */
  min-height: 44px;
  display: flex;
  align-items: center;
}
.ct-sidebar .nav-link:hover,
.ct-sidebar .nav-link.active {
  background: var(--ct-sidebar-active);
  color: #fff;
}
.ct-sidebar .nav-link.active { font-weight: 600; }

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,.1);
  color: var(--ct-sidebar-text);
  font-size: .75rem;
}

/* ---- Overlay para sidebar en móvil ---- */
#sidebarOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1024;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
#sidebarOverlay.active { display: block; }

/* ---- Main ---- */
.ct-main {
  background: #f0f2f5;
  min-height: calc(100vh - var(--ct-navbar-height));
  overflow-x: hidden;
  /* Padding inferior para iOS safe area */
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

/* ---- Cards ---- */
.card {
  border: none;
  box-shadow: 0 1px 6px rgba(0,0,0,.08);
  border-radius: var(--ct-radius);
}
.card-header { border-radius: var(--ct-radius) var(--ct-radius) 0 0 !important; }

/* ---- KPI Cards ---- */
.kpi-card { border-radius: var(--ct-radius); overflow: hidden; }
.kpi-card .kpi-icon {
  width: 52px; height: 52px;
  border-radius: var(--ct-radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
}

/* ---- Progress bars ---- */
.progress { border-radius: 8px; }
.progress-bar { border-radius: 8px; }

/* ---- Tables ---- */
.table th {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: #6c757d;
  border-top: none;
}
.table td { vertical-align: middle; }

/* Todas las tablas con scroll horizontal en mobile */
.table-responsive { -webkit-overflow-scrolling: touch; }

/* ---- Badges ---- */
.badge { font-weight: 500; }

/* ---- Buttons touch targets ---- */
.btn { min-height: 38px; }
.btn-sm { min-height: 32px; }

/* ---- Forms ---- */
.form-control, .form-select {
  font-size: 16px; /* evita zoom automático en iOS */
  min-height: 44px;
  border-radius: 8px;
}
.form-control-sm, .form-select-sm {
  font-size: 14px;
  min-height: 36px;
}
/* No zoom en iOS para inputs de tipo especial */
input[type="date"],
input[type="number"],
input[type="email"],
input[type="text"],
input[type="password"],
select,
textarea {
  font-size: 16px !important;
}

/* ---- Stage timeline ---- */
.stage-item {
  border-left: 3px solid #dee2e6;
  padding-left: 1rem;
  margin-bottom: 1.25rem;
  position: relative;
}
.stage-item.completed   { border-left-color: #198754; }
.stage-item.in-progress { border-left-color: #0d6efd; }
.stage-item.blocked     { border-left-color: #dc3545; }
.stage-item::before {
  content: '';
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #dee2e6;
  position: absolute;
  left: -7px; top: 6px;
}
.stage-item.completed::before   { background: #198754; }
.stage-item.in-progress::before { background: #0d6efd; }
.stage-item.blocked::before     { background: #dc3545; }

/* ---- Gantt simple ---- */
.gantt-bar {
  height: 28px;
  border-radius: 6px;
  position: relative;
  overflow: hidden;
  background: #e9ecef;
  margin-bottom: 6px;
}
.gantt-fill {
  height: 100%;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--ct-primary), #1976D2);
  transition: width .5s ease;
  display: flex; align-items: center; padding-left: 8px;
  color: #fff; font-size: .75rem; font-weight: 600;
  min-width: 32px;
}

/* ---- Photo grid ---- */
.photo-thumb {
  width: 100%; height: 120px;
  object-fit: cover;
  border-radius: 8px;
  cursor: pointer;
  transition: transform .2s;
}
.photo-thumb:hover { transform: scale(1.04); }

/* ---- Alert states ---- */
.alert-project-late { border-left: 4px solid #dc3545; }
.alert-project-ok   { border-left: 4px solid #198754; }

/* ============================================================
   RESPONSIVE — Tablet (≤992px)
   ============================================================ */
@media (max-width: 992px) {
  .ct-main { padding: 1.25rem !important; }

  /* Sidebar fijo, empieza colapsado — se abre sobre el contenido */
  .ct-sidebar {
    position: fixed;
    z-index: 1025;
    top: var(--ct-navbar-height);
    left: 0;
    height: calc(100vh - var(--ct-navbar-height));
    transform: translateX(0);
  }
  .ct-sidebar.collapsed {
    transform: translateX(-100%);
    width: var(--ct-sidebar-width);
    min-width: var(--ct-sidebar-width);
  }

  /* El main ocupa todo el ancho */
  .ct-main { margin-left: 0 !important; }
}

/* ============================================================
   RESPONSIVE — Móvil (≤576px)
   ============================================================ */
@media (max-width: 576px) {
  .ct-main { padding: .75rem !important; }

  /* Cabeceras de página en columna */
  .d-flex.justify-content-between.mb-4 {
    flex-direction: column;
    align-items: flex-start !important;
    gap: .75rem;
  }

  /* Cards sin padding lateral excesivo */
  .card-body.p-4 { padding: 1rem !important; }
  .card-body.p-3 { padding: .75rem !important; }

  /* Botones de acción a ancho completo en formularios */
  .col-12.d-flex.gap-2.pt-2 .btn { flex: 1; }

  /* KPI cards: 2 columnas */
  .row.g-3 > .col-6.col-md-3,
  .row.g-3 > .col-6.col-md-2 {
    flex: 0 0 50%;
    max-width: 50%;
  }

  /* Tabla de etapas: columnas menos prioritarias ocultas */
  .table-mobile-hide { display: none !important; }

  /* Modales a pantalla completa en móvil */
  .modal-dialog:not(.modal-fullscreen-sm-down) {
    margin: .5rem;
    max-width: calc(100vw - 1rem);
  }

  /* Filtros en columna */
  form .row.g-2 > [class*="col-md"] {
    flex: 0 0 100%;
    max-width: 100%;
  }

  /* h4 más pequeño */
  h4.fw-bold { font-size: 1.1rem; }

  /* Badges de KPI más grandes */
  .fs-3.fw-bold { font-size: 1.4rem !important; }

  /* Botones de exportar en fila */
  .d-flex.gap-2 .btn-sm { padding: .3rem .6rem; font-size: .8rem; }
}

/* ---- Safe area iOS (notch/home bar) ---- */
@supports (padding: max(0px)) {
  .ct-navbar {
    padding-left: max(.75rem, env(safe-area-inset-left));
    padding-right: max(.75rem, env(safe-area-inset-right));
  }
  .ct-main {
    padding-left: max(.75rem, env(safe-area-inset-left));
    padding-right: max(.75rem, env(safe-area-inset-right));
  }
}

/* ---- Print (global) ---- */
@media print {
  .ct-sidebar, .ct-topbar, .no-print, #sidebarOverlay { display: none !important; }
  .ct-main { margin: 0 !important; padding: 0 !important; }
  .card { box-shadow: none !important; border: 1px solid #dee2e6 !important; }
}
