/* ============================================================
   JD Timeline Widget — Frontend Styles
   File: widgets/jd-timeline/css/jd-timeline.css
   Version: 1.2.0
   ============================================================ */

/* ── Custom Properties & Reset ───────────────────────────── */

.jd-timeline-wrapper {
  --jd-tl-trans: 0.4s cubic-bezier(0.22, 1, 0.36, 1);
  position: relative;
  width: 100%;
  /* Max-width can be controlled by Elementor column width */
}

.jd-timeline-wrapper *,
.jd-timeline-wrapper *::before,
.jd-timeline-wrapper *::after {
  box-sizing: border-box;
}

/* ── Expand / Collapse Buttons ───────────────────────────── */

.jd-tl-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
  justify-content: flex-start; /* Controllable via Elementor */
}

.jd-tl-btn {
  border: 1px solid currentColor;
  border-radius: 20px;
  cursor: pointer;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  color: inherit;
  background: transparent;
  transition:
    background-color 0.2s linear,
    color 0.4s ease,
    border-color 0.4s;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}

.jd-tl-btn:hover,
.jd-tl-btn:focus-visible {
  /* Colors applied via Elementor selectors */
}

/* ── Timeline Track container ────────────────────────────── */

.jd-tl-track {
  margin: 0;
  padding: 0;
  width: 100%;
}

/* ── Individual Item ─────────────────────────────────────── */

.jd-tl-item {
  position: relative;
  padding-bottom: 32px; /* Controlled via spacing option */
}

.jd-tl-item:last-child {
  padding-bottom: 0;
}

/* Vertical connecting line */
.jd-tl-item:not(:last-child)::before {
  content: "";
  display: block;
  position: absolute;
  /* Top calculation relies on icon/dot sizes — usually ~20px down */
  top: 21px;
  /* Position matches center of dot */
  left: 50px;
  width: 2px;
  height: 100%;
  transform: translateX(-50%);
  /* Color controlled via Elementor */
  background-color: #3d4fd6;
}

/* ── Item Header ─────────────────────────────────────────── */

.jd-tl-header {
  display: flex;
  align-items: flex-start;
}

/* ── Arrow / Toggle Icon ─────────────────────────────────── */

.jd-tl-arrow {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background: transparent;
  position: relative;
  margin-right: 12px;
  padding: 0;
  color: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background-color 0.2s linear,
    color 0.4s ease,
    border-color 0.4s ease,
    box-shadow 0.4s ease;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
}

/* Arrow rotating SVG */
.jd-tl-arrow svg {
  display: block;
  pointer-events: none;
  transition: transform var(--jd-tl-trans);
  width: 20px;
  height: 20px;
  /* Usually points right when closed, down when open */
  transform: rotate(0deg);
  fill: currentColor;
}

.jd-tl-arrow[aria-expanded="true"] svg {
  /* Configurable via controls, usually +90deg */
  transform: rotate(90deg);
}

/* ── Connecting Dot ──────────────────────────────────────── */

.jd-tl-dot {
  flex-shrink: 0;
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: #3d4fd6; /* Default, overridden in PHP */
  margin-top: 10px; /* Align vertically with text */
  margin-right: 16px;
  /* Ensure dot centers horizontally with the line: 
       Left padding of header (0) + Width of arrow (32) + Gap (12) + (DotWidth/2) = LineLeft
       0 + 32 + 12 + 6 = 50px line offset. 
       Note: We will control exact vertical line alignment in PHP settings. */
}

/* ── Meta: Date + Title ──────────────────────────────────── */

.jd-tl-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.jd-tl-date {
  display: block;
  font-size: 14px;
  line-height: 1.5;
  color: #666;
  margin-bottom: 4px;
}

.jd-tl-title {
  font-size: 18px;
  line-height: 1.3;
  font-weight: 600;
  margin: 0;
  color: #111;
}

/* ── Collapsible Body (CSS Grid Animation) ───────────────── */

.jd-tl-body {
  border-radius: 6px;
  overflow: hidden;
  /* Left margin skips arrow (32) + arrow-gap (12) + dot (12) + dot-gap (16) = ~72px */
  margin-top: 12px;
  margin-left: 56px;

  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--jd-tl-trans);
}

.jd-tl-body--expanded {
  grid-template-rows: 1fr;
}

.jd-tl-content {
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  padding: 20px 24px;
  background-color: #f8f9fa; /* Overridden */
  color: #444; /* Overridden */
  transition:
    opacity 0.4s ease,
    visibility 0.4s;
  transition-delay:
    0s, 0.4s; /* Delay visibility hidden until opacity transition finishes */
  font-size: 15px;
  line-height: 1.6;
}

.jd-tl-body--expanded .jd-tl-content {
  opacity: 1;
  visibility: visible;
  transition-delay:
    0.1s, 0s; /* immediate visibility, slightly delayed opacity fade */
}

/* Rich Text formatting */
.jd-tl-content *:first-child {
  margin-top: 0;
}
.jd-tl-content *:last-child {
  margin-bottom: 0;
}
.jd-tl-content p {
  margin-bottom: 1em;
}
.jd-tl-content ul,
.jd-tl-content ol {
  padding-left: 20px;
}
.jd-tl-content li {
  margin-bottom: 0.5em;
}

/* ── RTL Support ─────────────────────────────────────────── */

[dir="rtl"] .jd-tl-arrow {
  margin-right: 0;
  margin-left: 12px;
}
[dir="rtl"] .jd-tl-arrow svg {
  transform: rotate(180deg);
}
[dir="rtl"] .jd-tl-arrow[aria-expanded="true"] svg {
  transform: rotate(90deg);
}
[dir="rtl"] .jd-tl-dot {
  margin-right: 0;
  margin-left: 16px;
}
[dir="rtl"] .jd-tl-item:not(:last-child)::before {
  /* Adjusted in PHP styling dynamically */
  transform: translateX(50%);
}
[dir="rtl"] .jd-tl-body {
  margin-left: 0;
  margin-right: 56px;
}

/* ── Responsive ──────────────────────────────────────────── */

@media only screen and (max-width: 767px) {
  .jd-tl-body {
    margin-left: 40px; /* Tighter on mobile */
  }
  .jd-tl-content {
    padding: 16px;
  }
}
