.purchase-kpis{
  display:grid;
  grid-template-columns:
    repeat(5,minmax(0,1fr));
  gap:14px;
  margin-bottom:20px;
}

.purchase-kpi{
  display:block;
  background:#fff;
  border:1px solid #e4e7ec;
  border-radius:12px;
  padding:16px;
  color:#344054;
}

.purchase-kpi span{
  display:block;
  color:#667085;
  font-weight:700;
  margin-bottom:6px;
}

.purchase-kpi strong{
  font-size:2rem;
  color:#101828;
}

.purchase-kpi-warning{
  border-color:#f5c26b;
}

.purchase-kpi-danger{
  border-color:#fda29b;
}

.purchase-kpi-success{
  border-color:#86d9a4;
}


.purchase-filter-grid{
  display:grid;
  grid-template-columns:
    minmax(260px,2fr)
    minmax(190px,1fr)
    auto;
  gap:12px;
  align-items:end;
}

.purchase-filter-actions{
  display:flex;
  gap:8px;
}


.purchase-table{
  min-width:900px;
}

.purchase-number{
  font-weight:800;
}


.purchase-status,
.purchase-health{
  display:inline-flex;
  align-items:center;
  border-radius:999px;
  padding:5px 9px;
  font-size:.8rem;
  font-weight:800;
  white-space:nowrap;
}

.purchase-status{
  background:#f2f4f7;
  color:#344054;
}

.purchase-status.status-delivered{
  background:#ecfdf3;
  color:#067647;
}

.purchase-status.status-incident{
  background:#fef3f2;
  color:#b42318;
}

.purchase-status.status-cancelled{
  background:#f2f4f7;
  color:#475467;
}

.purchase-status.status-confirmed{
  background:#eef4ff;
  color:#1849a9;
}

.purchase-status.status-preparing{
  background:#f4f3ff;
  color:#5925dc;
}

.purchase-status.status-in_transit{
  background:#eef2f6;
  color:#344054;
}

.purchase-health.health-overdue{
  background:#fef3f2;
  color:#b42318;
}

.purchase-health.health-upcoming{
  background:#fff4e5;
  color:#93370d;
}

.purchase-health.health-unscheduled{
  background:#f2f4f7;
  color:#475467;
}


.purchase-detail-grid{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:20px;
}

.purchase-linked-orders{
  display:grid;
  grid-template-columns:
    repeat(auto-fit,minmax(260px,1fr));
  gap:10px;
}

.purchase-linked-orders > a{
  display:flex;
  flex-direction:column;
  gap:4px;
  padding:13px;
  border:1px solid #e4e7ec;
  border-radius:9px;
  background:#fbfcfd;
}

.purchase-linked-orders small{
  white-space:pre-line;
}


.purchase-history{
  display:grid;
  gap:10px;
}

.purchase-history-item{
  border-left:3px solid #d0d5dd;
  padding:8px 12px;
}

.purchase-history-item > div{
  display:flex;
  justify-content:space-between;
  gap:15px;
}

.purchase-history-item p{
  margin:6px 0;
}


.purchase-money-row{
  display:grid;
  grid-template-columns:2fr 1fr;
  gap:16px;
  max-width:520px;
}


/* =======================================================
   GANTT
   ======================================================= */

.purchase-gantt-card{
  padding:0;
  overflow:hidden;
}

.purchase-gantt-toolbar{
  display:flex;
  align-items:end;
  gap:12px;
  flex-wrap:wrap;
  padding:16px 18px;
  border-bottom:1px solid #e4e7ec;
}

.purchase-gantt-toolbar > div:first-child{
  display:flex;
  flex-direction:column;
  gap:5px;
}

.purchase-gantt-toolbar select{
  min-width:120px;
}

.purchase-gantt-legend{
  display:flex;
  gap:12px;
  flex-wrap:wrap;
  margin-left:auto;
  font-size:.82rem;
}

.purchase-gantt-legend span::before{
  content:"";
  display:inline-block;
  width:10px;
  height:10px;
  border-radius:3px;
  margin-right:5px;
}

.legend-normal::before{
  background:#2563eb;
}

.legend-upcoming::before{
  background:#d97706;
}

.legend-overdue::before{
  background:#dc2626;
}

.legend-final::before{
  background:#16a34a;
}


.purchase-gantt-scroll{
  overflow-x:auto;
  overflow-y:hidden;
  width:100%;
  background:#fff;
}

.pg-row{
  display:grid;
  min-width:max-content;
  border-bottom:1px solid #eaecf0;
}

.pg-left{
  position:sticky;
  left:0;
  z-index:4;
  width:360px;
  min-width:360px;
  background:#fff;
  border-right:1px solid #d0d5dd;
  padding:9px 12px;
}

.pg-left strong{
  display:block;
  color:#101828;
}

.pg-left span,
.pg-left small{
  display:block;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.pg-left span{
  color:#475467;
  margin-top:2px;
}

.pg-left small{
  color:#667085;
  margin-top:2px;
}


.pg-header{
  background:#f8fafc;
  font-weight:700;
}

.pg-header .pg-left{
  background:#f8fafc;
  z-index:6;
}


.pg-track{
  position:relative;
  min-height:62px;
  background-color:#fff;
}

.pg-header-track{
  min-height:72px;
  background:#f8fafc;
}


.pg-month{
  position:absolute;
  top:0;
  height:34px;
  display:flex;
  align-items:center;
  justify-content:center;
  border-right:1px solid #d0d5dd;
  border-bottom:1px solid #d0d5dd;
  color:#344054;
  font-size:.83rem;
  font-weight:800;
  overflow:hidden;
}


.pg-day{
  position:absolute;
  top:34px;
  height:38px;
  display:flex;
  align-items:center;
  justify-content:center;
  border-right:1px solid #eaecf0;
  color:#667085;
  font-size:.72rem;
  overflow:hidden;
}

.pg-day.weekend{
  background:#f5f6f8;
}


.pg-bar{
  position:absolute;
  top:18px;
  height:26px;
  border-radius:6px;
  display:flex;
  align-items:center;
  padding:0 8px;
  font-size:.75rem;
  font-weight:800;
  color:#fff;
  text-decoration:none;
  overflow:hidden;
  white-space:nowrap;
  text-overflow:ellipsis;
  background:#2563eb;
}

.pg-bar.health-upcoming{
  background:#d97706;
}

.pg-bar.health-overdue{
  background:#dc2626;
}

.pg-bar.health-final{
  background:#16a34a;
}

.pg-bar.health-unscheduled{
  background:#667085;
}


.pg-today{
  position:absolute;
  top:0;
  bottom:0;
  width:2px;
  background:#ef4444;
  z-index:3;
  pointer-events:none;
}

.pg-today::before{
  content:"Hoy";
  position:absolute;
  top:2px;
  left:4px;
  color:#b42318;
  font-size:10px;
  font-weight:800;
}


.purchase-gantt-filter{
  display:grid;
  grid-template-columns:
    minmax(240px,2fr)
    minmax(180px,1fr)
    auto
    auto;
  gap:10px;
  align-items:end;
}


.purchase-unscheduled-grid{
  display:grid;
  grid-template-columns:
    repeat(auto-fit,minmax(230px,1fr));
  gap:10px;
}

.purchase-unscheduled-grid a{
  display:flex;
  flex-direction:column;
  gap:4px;
  border:1px solid #e4e7ec;
  border-radius:9px;
  padding:12px;
  background:#fbfcfd;
}


@media(max-width:1000px){
  .purchase-kpis{
    grid-template-columns:
      repeat(3,minmax(0,1fr));
  }

  .purchase-filter-grid,
  .purchase-gantt-filter{
    grid-template-columns:
      1fr 1fr;
  }
}


@media(max-width:700px){
  .purchase-kpis{
    grid-template-columns:
      1fr 1fr;
  }

  .purchase-detail-grid{
    grid-template-columns:1fr;
  }

  .purchase-filter-grid,
  .purchase-gantt-filter{
    grid-template-columns:1fr;
  }

  .purchase-filter-actions{
    flex-wrap:wrap;
  }

  .purchase-money-row{
    grid-template-columns:1fr;
  }

  .pg-left{
    width:270px;
    min-width:270px;
  }

  .purchase-gantt-legend{
    width:100%;
    margin-left:0;
  }
}

/* GANTT-V159-REV2-START */

.purchase-gantt-card{
  overflow:hidden;
}

.purchase-gantt-toolbar{
  display:flex;
  align-items:center;
  gap:9px;
  flex-wrap:wrap;
  padding:14px 18px;
}

.purchase-gantt-toolbar > div:first-child{
  margin-right:5px;
}

.purchase-gantt-nav{
  min-width:42px;
  font-size:18px;
  line-height:1;
}

.purchase-gantt-range{
  color:#667085;
  font-size:.82rem;
  font-weight:700;
  margin-left:5px;
  white-space:nowrap;
}

.purchase-gantt-legend{
  margin-left:auto;
}


.purchase-gantt-scroll{
  width:100%;
  overflow-x:auto;
  overflow-y:hidden;
  background:#fff;
  scroll-behavior:smooth;
}


.pg-row{
  display:grid;
  min-width:max-content;
  border-bottom:1px solid #e4e7ec;
}


.pg-left{
  position:sticky;
  left:0;
  z-index:10;
  width:390px;
  min-width:390px;
  min-height:76px;
  box-sizing:border-box;
  padding:10px 13px;
  background:#fff;
  border-right:1px solid #d0d5dd;
}


.pg-left-header{
  background:#f8fafc;
  display:flex;
  flex-direction:column;
  justify-content:center;
}

.pg-left-header strong{
  font-size:.92rem;
}

.pg-left-header small{
  margin-top:3px;
  color:#667085;
}


.pg-left-top{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
}

.pg-left-top strong{
  color:#101828;
  font-size:.94rem;
}

.pg-left-supplier{
  display:block;
  margin-top:4px;
  color:#344054;
  overflow:hidden;
  white-space:nowrap;
  text-overflow:ellipsis;
}

.pg-left > small{
  display:block;
  margin-top:4px;
  color:#667085;
  overflow:hidden;
  white-space:nowrap;
  text-overflow:ellipsis;
}


.pg-left-badge{
  display:inline-flex;
  align-items:center;
  padding:3px 7px;
  border-radius:999px;
  background:#eef2f6;
  color:#344054;
  font-size:.7rem;
  font-weight:800;
  white-space:nowrap;
}

.pg-left-badge.health-upcoming{
  background:#fff3e0;
  color:#9a3412;
}

.pg-left-badge.health-overdue{
  background:#feecec;
  color:#b42318;
}

.pg-left-badge.health-final{
  background:#eaf8ef;
  color:#067647;
}


.pg-header{
  background:#f8fafc;
}

.pg-track{
  position:relative;
  min-height:76px;
  overflow:hidden;
  background:#fff;
}

.pg-header-track{
  min-height:76px;
  background:#f8fafc;
}


.pg-month{
  position:absolute;
  top:0;
  height:36px;
  display:flex;
  align-items:center;
  justify-content:center;
  box-sizing:border-box;
  border-right:1px solid #cfd5df;
  border-bottom:1px solid #d0d5dd;
  background:#f8fafc;
  color:#24364b;
  font-size:.82rem;
  font-weight:800;
  overflow:hidden;
  white-space:nowrap;
}


.pg-tick{
  position:absolute;
  top:36px;
  height:40px;
  display:flex;
  align-items:center;
  justify-content:center;
  box-sizing:border-box;
  border-right:1px solid #e4e7ec;
  color:#667085;
  font-size:.7rem;
  overflow:hidden;
  white-space:nowrap;
}

.pg-tick-day{
  flex-direction:column;
  gap:1px;
}

.pg-tick-day strong{
  color:#344054;
  font-size:.78rem;
}

.pg-tick-day.weekend{
  background:#eef1f5;
}

.pg-tick-week{
  padding:0 5px;
  font-weight:700;
}


.pg-weekend-band{
  position:absolute;
  top:0;
  bottom:0;
  z-index:0;
  background:#f6f7f9;
  pointer-events:none;
}

.pg-week-line{
  position:absolute;
  top:0;
  bottom:0;
  z-index:1;
  width:1px;
  background:#d9dee7;
  pointer-events:none;
}


.pg-today{
  position:absolute;
  top:0;
  bottom:0;
  z-index:6;
  width:2px;
  background:#ef4444;
  pointer-events:none;
}

.pg-today::before{
  display:none;
}

.pg-today-header::before{
  content:"Hoy";
  display:block;
  position:absolute;
  top:2px;
  left:4px;
  color:#c81e1e;
  font-size:10px;
  font-weight:900;
}


.pg-bar{
  position:absolute;
  top:24px;
  z-index:4;
  height:28px;
  box-sizing:border-box;
  display:flex;
  align-items:center;
  padding:0 9px;
  border-radius:6px;
  color:#fff;
  font-size:.73rem;
  font-weight:800;
  text-decoration:none;
  overflow:hidden;
  white-space:nowrap;
  text-overflow:ellipsis;
  background:#2563eb;
  box-shadow:0 1px 2px rgba(16,24,40,.16);
}


/* Estado normal */
.pg-bar.status-pending{
  background:#64748b;
}

.pg-bar.status-ordered{
  background:#2563eb;
}

.pg-bar.status-confirmed{
  background:#1d4ed8;
}

.pg-bar.status-preparing{
  background:#7c3aed;
}

.pg-bar.status-in_transit{
  background:#0284c7;
}


/* Situaciones automáticas */
.pg-bar.health-upcoming{
  background:#e68a00;
}

.pg-bar.health-overdue{
  background:#dc2626;
}

.pg-bar.health-final{
  background:#16a34a;
}


/* ◆ Entrega prevista */
.pg-milestone{
  position:absolute;
  top:31px;
  z-index:7;
  width:13px;
  height:13px;
  margin-left:-6px;
  transform:rotate(45deg);
  border:2px solid #fff;
  background:#2563eb;
  box-shadow:0 0 0 1px rgba(16,24,40,.18);
}

.pg-milestone.health-upcoming{
  background:#e68a00;
}

.pg-milestone.health-overdue{
  background:#dc2626;
}

.pg-milestone.health-final{
  background:#16a34a;
}


/* ● Fecha confirmada por proveedor */
.pg-confirmed-marker{
  position:absolute;
  top:14px;
  z-index:8;
  width:10px;
  height:10px;
  margin-left:-5px;
  border-radius:50%;
  border:2px solid #fff;
  background:#111827;
  box-shadow:0 0 0 1px rgba(16,24,40,.25);
}


/* Fecha real */
.pg-actual-marker{
  position:absolute;
  top:15px;
  bottom:15px;
  z-index:7;
  width:3px;
  margin-left:-1px;
  border-radius:3px;
  background:#15803d;
}


@media (hover:hover) and (pointer:fine){
  .pg-bar:hover{
    filter:brightness(.94);
  }

  .pg-milestone:hover{
    filter:brightness(.92);
  }
}


@media(max-width:700px){
  .pg-left{
    width:290px;
    min-width:290px;
  }

  .purchase-gantt-range{
    width:100%;
    margin-left:0;
  }

  .purchase-gantt-legend{
    width:100%;
    margin-left:0;
  }
}

/* GANTT-V159-REV2-END */

/* GANTT-V159-REV3-START */

.legend-confirmed-date,
.legend-expected-date{
  color:#475467;
  font-weight:700;
}

.legend-confirmed-date{
  color:#111827;
}

.legend-expected-date{
  color:#475467;
}

/*
 * El timeline empieza mostrando su inicio real.
 * La columna izquierda permanece sticky.
 */
.purchase-gantt-scroll{
  scroll-padding-left:390px;
}


/*
 * Cabecera un poco más fuerte para separar
 * claramente meses y semanas/días.
 */
.pg-header-track{
  box-shadow:
    inset 0 -1px 0 #d0d5dd;
}

.pg-month{
  background:#f4f6f9;
}


/*
 * Línea Hoy ligeramente más visible,
 * sin tapar el contenido.
 */
.pg-today{
  background:#ef4444;
  opacity:.92;
}


/*
 * Los hitos deben destacar sobre la barra.
 */
.pg-milestone{
  box-shadow:
    0 0 0 1px rgba(16,24,40,.25),
    0 1px 3px rgba(16,24,40,.15);
}


/*
 * Confirmación proveedor:
 * círculo negro claramente visible.
 */
.pg-confirmed-marker{
  background:#111827;
  box-shadow:
    0 0 0 1px rgba(16,24,40,.30);
}


/*
 * Fila ligeramente resaltada al pasar el ratón.
 */
@media (hover:hover) and (pointer:fine){

  .pg-row:not(.pg-header):hover
  .pg-track{
    background-color:#fafbfc;
  }

  .pg-row:not(.pg-header):hover
  .pg-left{
    background-color:#fafbfc;
  }
}


@media(max-width:700px){
  .purchase-gantt-scroll{
    scroll-padding-left:290px;
  }
}

/* GANTT-V159-REV3-END */

/* GANTT-V159-REV6-START */

.rev6-planning-summary{
  padding:15px 18px;
  border-bottom:1px solid #e4e7ec;
  background:#fbfcfd;
}

.rev6-summary-top{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:14px;
  flex-wrap:wrap;
}

.rev6-summary-title{
  display:flex;
  flex-direction:column;
  gap:3px;
}

.rev6-summary-title strong{
  color:#101828;
  font-size:.96rem;
}

.rev6-summary-title span{
  color:#667085;
  font-size:.82rem;
}

.rev6-overdue-alert{
  padding:5px 9px;
  border-radius:999px;
  background:#feecec;
  color:#b42318;
  font-size:.77rem;
  font-weight:800;
}

.rev6-quick-filters{
  display:flex;
  gap:7px;
  margin-top:12px;
  overflow-x:auto;
}

.rev6-filter{
  border:1px solid #d0d5dd;
  border-radius:999px;
  background:#fff;
  color:#344054;
  padding:6px 10px;
  font:inherit;
  font-size:.76rem;
  font-weight:700;
  cursor:pointer;
  white-space:nowrap;
}

.rev6-filter strong{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width:20px;
  height:20px;
  margin-left:4px;
  padding:0 5px;
  border-radius:999px;
  background:#eef2f6;
  font-size:.70rem;
}

.rev6-filter.active{
  border-color:#2563eb;
  background:#2563eb;
  color:#fff;
}

.rev6-filter.active strong{
  background:rgba(255,255,255,.20);
  color:#fff;
}

.rev6-clickable-left{
  cursor:pointer;
}

.rev6-clickable-left:hover{
  background:#f4f7fb;
}

.rev6-unscheduled-card{
  position:relative;
}

.rev6-missing{
  margin-top:8px;
  color:#9a3412;
  font-size:.76rem;
}

.rev6-unscheduled-actions{
  display:flex;
  justify-content:flex-end;
  margin-top:10px;
}

.rev6-plan-button{
  text-decoration:none;
}

.pg-bar,
.pg-milestone{
  cursor:pointer;
}

/* GANTT-V159-REV6-END */


/* GANTT-V159-REV6-SERVER-CARDS-START */

.purchase-unscheduled-grid{
  align-items:stretch;
}

.purchase-unscheduled-item{
  display:flex;
  flex-direction:column;
  min-width:0;
  padding:14px;
  border:1px solid #d9dee7;
  border-radius:10px;
  background:#fff;
}

.purchase-unscheduled-item
.purchase-unscheduled-main{
  display:flex;
  flex-direction:column;
  gap:4px;
  padding:0;
  border:0;
  border-radius:0;
  background:transparent;
  text-decoration:none;
}

.purchase-unscheduled-main strong{
  color:#1769ff;
}

.purchase-unscheduled-main span{
  color:#1769ff;
}

.purchase-unscheduled-main small{
  color:#667085;
}

.purchase-unscheduled-missing{
  display:flex;
  flex-direction:column;
  gap:2px;
  margin-top:12px;
  padding-top:10px;
  border-top:1px solid #eef1f5;
  color:#9a3412;
  font-size:.78rem;
  line-height:1.35;
}

.purchase-unscheduled-missing strong{
  color:#9a3412;
}

.purchase-unscheduled-actions{
  display:flex;
  justify-content:flex-end;
  margin-top:auto;
  padding-top:14px;
}

.purchase-unscheduled-actions
.purchase-unscheduled-plan{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width:96px;
  color:#fff !important;
  text-decoration:none;
}

@media(max-width:700px){

  .purchase-unscheduled-actions{
    justify-content:stretch;
  }

  .purchase-unscheduled-plan{
    width:100%;
  }
}

/* GANTT-V159-REV6-SERVER-CARDS-END */

/* GANTT-V159-REV6-PLAN-BUTTON-FINAL */

.purchase-unscheduled-item
.purchase-unscheduled-actions
a.purchase-unscheduled-plan{
  display:inline-flex !important;
  align-items:center !important;
  justify-content:center !important;

  width:auto !important;
  min-width:105px !important;

  padding:8px 14px !important;

  border:1px solid #2563eb !important;
  border-radius:7px !important;

  background:#2563eb !important;
  color:#ffffff !important;

  font-weight:700 !important;
  text-decoration:none !important;

  opacity:1 !important;
  visibility:visible !important;

  cursor:pointer !important;
}

.purchase-unscheduled-item
.purchase-unscheduled-actions
a.purchase-unscheduled-plan:hover{
  background:#1d4ed8 !important;
  border-color:#1d4ed8 !important;
  color:#ffffff !important;
}

