/*******************************************
 *  TIMELINE HISTORY – DESKTOP
 *  Giữ nguyên CSS desktop
 *******************************************/
.xc-history-timeline {
  --connector-length: 70px;
  max-width: 1200px;
  margin: 60px auto 80px;
  padding: 80px 0;
  display: flex;
  justify-content: space-between;
  box-sizing: border-box;
}

.timeline-item {
  position: relative;
  flex: 0 0 20%;
  text-align: center;
  font-size: 14px;
  line-height: 1.5;
  color: #333;
  box-sizing: border-box;
  z-index: 1;
}

/* màu từng mốc */
.timeline-item.is-green {
  --line-color: #a7d27b;
  --border-light: #c9e8a8;
  --border-dark:  #7ac043;
}
.timeline-item.is-blue {
  --line-color: #1967b2;
  --border-light: #8ab7e2;
  --border-dark:  #1967b2;
}

/* line ngang ghép lại thành 1 dải */
.timeline-item::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 12px;
  background: var(--line-color);
  transform: translateY(-50%);
  z-index: 0;
}
.timeline-item:first-child::before {
  border-top-left-radius: 999px;
  border-bottom-left-radius: 999px;
}
.timeline-item:last-child::before {
  border-top-right-radius: 999px;
  border-bottom-right-radius: 999px;
}

/* khối trên / dưới */
.timeline-top,
.timeline-bottom {
  height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  box-sizing: border-box;
}

/* 1,3,5: year trên – content dưới */
.timeline-item.is-circle-top .timeline-top {
  margin-bottom: 40px;
}
.timeline-item.is-circle-top .timeline-bottom {
  margin-top: 40px;
}

/* 2,4: content trên – year dưới */
.timeline-item.is-circle-bottom .timeline-top {
  margin-bottom: 40px;
}
.timeline-item.is-circle-bottom .timeline-bottom {
  margin-top: 40px;
}

/******** CIRCLE (nền trắng + viền 2 nửa màu) ********/
.timeline-circle {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  flex-direction: column;
  justify-content: center;
  font-weight: 700;
  line-height: 1.1;
  box-sizing: border-box;
  box-shadow: 0 0 10px rgba(0,0,0,0.06);
  z-index: 2;
}

/* viền chia 2 nửa màu */
.timeline-circle::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  padding: 8px;
  background: conic-gradient(
    var(--border-light) 0deg,
    var(--border-light) 180deg,
    var(--border-dark)  180deg,
    var(--border-dark)  360deg
  );
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  z-index: -1;
}

.timeline-circle span { 
  font-size: 22px; 
  display: block;
  line-height: 1.3;
  position: relative;
  padding: 4px 0;
}

/* Đường line ngăn cách khi có <br> - chỉ hiển thị khi có class has-br */
.timeline-circle span.has-br::after {
  content: "";
  display: block;
  width: 50%;
  height: 1px;
  background-color: currentColor;
  opacity: 0.4;
  margin: 4px auto 12px;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: calc(50% - 2px);
  pointer-events: none;
}

.timeline-circle strong { font-size: 30px; }

.timeline-item.is-green .timeline-circle { color: #2f6f16; }
.timeline-item.is-blue  .timeline-circle { color: #0f3c8d; }

/******** MIDDLE (DOT + CONNECTOR DỌC) ********/
.timeline-middle {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  transform: translateY(-50%);
  height: 0;
  z-index: 1;
}

.timeline-dot {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, -50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 6px solid #fff;
  background: #fff;
  box-sizing: border-box;
  box-shadow: 0 0 0 4px var(--line-color);
  z-index: 3;
}

/* connector dọc */
.timeline-middle::before {
  content: "";
  position: absolute;
  left: 50%;
  width: 4px;
  background: var(--line-color);
  transform: translateX(-50%);
  z-index: 2;
}

/* circle trên: line kéo lên từ dot tới year */
.timeline-item.is-circle-top .timeline-middle::before {
  top: 0;
  height: var(--connector-length);
  transform: translate(-50%, -100%);
}

/* circle dưới: line kéo xuống từ dot tới year */
.timeline-item.is-circle-bottom .timeline-middle::before {
  top: 0;
  height: var(--connector-length);
  transform: translateX(-50%);
}

/*******************************************
 *  MOBILE – Học từ timelineX
 *  YEAR | LINE | CONTENT (INLINE)
 *******************************************/
@media (max-width: 767px) {
  .xc-history-timeline {
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 20px 0;
    margin: 20px 0;
  }

  .xc-history-timeline > p {
    display: none !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .timeline-item {
    flex: none;
    width: 100%;
    display: flex;
    flex-direction: row;       /* YEAR | LINE | CONTENT */
    align-items: flex-start;   /* Học từ timelineX - căn trên để dot và line thẳng hàng */
    gap: 10px;
    text-align: left;
  }

  /* bỏ line ngang desktop */
  .timeline-item::before {
    display: none !important;
  }

  /* reset 3 khối để xếp theo row */
  .timeline-top,
  .timeline-middle,
  .timeline-bottom {
    position: static;
    height: auto;
    margin: 0;
    padding: 0;
    display: flex;
    box-sizing: border-box;
  }

  .timeline-top > p,
  .timeline-bottom > p {
    display: none !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* is-circle-top: year đang ở .timeline-top, content ở .timeline-bottom */
  .timeline-item.is-circle-top .timeline-top {
    order: 1;    /* YEAR (trái) */
    flex: 0 0 auto;
    justify-content: center;
  }
  .timeline-item.is-circle-top .timeline-middle {
    order: 2;    /* LINE (giữa) */
    flex: 0 0 auto;
  }
  .timeline-item.is-circle-top .timeline-bottom {
    order: 3;    /* CONTENT (phải) */
    flex: 1 1 auto;
    justify-content: flex-start;
    margin-top: 0 !important;
  }

  /* is-circle-bottom: year nằm ở .timeline-bottom, content ở .timeline-top */
  .timeline-item.is-circle-bottom .timeline-bottom {
    order: 1;    /* YEAR (trái) */
    flex: 0 0 auto;
    justify-content: center;
    margin-top: 0;
  }
  .timeline-item.is-circle-bottom .timeline-middle {
    order: 2;    /* LINE (giữa) */
    flex: 0 0 auto;
  }
  .timeline-item.is-circle-bottom .timeline-top {
    order: 3;    /* CONTENT (phải) */
    flex: 1 1 auto;
    justify-content: flex-start;
  }

  /* circle thu nhỏ trên mobile - học từ timelineX */
  .timeline-circle {
    width: 70px;
    height: 70px;
    padding: 8px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    gap: 2px;
    box-shadow: 0 0 6px rgba(0,0,0,0.08);
  }
  .timeline-circle span {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.1;
  }
  .timeline-circle strong {
    font-size: 18px;
    line-height: 1.1;
  }
  .timeline-circle br {
    display: none;
  }

  /* LINE giữa (dot + đoạn dọc) - Học từ timelineX */
  /* TimelineX dùng min-height: 2.6em cho marker và căn giữa dot */
  .timeline-middle {
    --timeline-dot-size: 14px;
    --timeline-dot-radius: calc(var(--timeline-dot-size) / 2);
    --circle-height: 70px; /* Chiều cao của circle */
    --marker-min-height: 2.6em; /* Học từ timelineX */
    transform: none;
    align-self: stretch;
    min-height: var(--marker-min-height); /* Học từ timelineX */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start; /* Học từ timelineX */
    position: relative;
    width: 24px; /* Fixed width */
    flex: 0 0 24px;
  }

  .timeline-dot {
    position: relative;
    z-index: 2;
    transform: none;
    width: var(--timeline-dot-size);
    height: var(--timeline-dot-size);
    border-width: 3px;
    box-shadow: 0 0 0 2px var(--line-color);
    margin: 0;
    flex-shrink: 0;
    flex-grow: 0;
    /* Học từ timelineX: căn giữa dot trong min-height */
    margin-top: calc((var(--marker-min-height) - var(--timeline-dot-size)) / 2);
    left: -5px; /* Dịch sang trái 5px trên mobile */
  }

  .timeline-middle::before {
    display: none !important;
  }

  /* Line dọc - Học từ timelineX: bắt đầu từ dưới dot */
  .timeline-middle::after {
    content: "";
    position: absolute;
    left: calc(50% - 5px); /* Dịch sang trái 5px để thẳng hàng với dot */
    width: 2px;
    background: var(--line-color);
    transform: translateX(-50%);
    /* Bắt đầu từ dưới dot - học từ timelineX */
    top: calc((var(--marker-min-height) - var(--timeline-dot-size)) / 2 + var(--timeline-dot-size));
    bottom: -24px; /* Tăng chiều dài để chạm dot tiếp theo */
    z-index: 1;
  }

  .timeline-item:last-child .timeline-middle::after {
    display: none;
  }

  /* content bên phải */
  .timeline-top,
  .timeline-bottom {
    text-align: left;
  }

  .timeline-item.is-circle-top .timeline-bottom,
  .timeline-item.is-circle-bottom .timeline-top {
    align-items: flex-start;
  }
}

