/*
 * Mục lục bài viết — Easy Table of Contents.
 * CSS gốc của plugin đã tắt (setting exclude_css), nên file này dựng lại toàn bộ.
 * Token của site: đỏ #ec2028 (đúng màu link trong .mona-content), chữ #313131,
 * viền #e4e7e9, font Inter (var(--font-pri)). html { font-size: 10px } nên 1rem = 10px.
 */

#ez-toc-container.kkt-toc {
  --toc-accent: #ec2028;
  --toc-accent-dark: #b8161d;
  --toc-ink: #1a1a1a;
  --toc-muted: #313131;

  display: block;
  box-sizing: border-box;
  width: 100%;
  margin: 2.4rem 0 3.2rem;
  padding: 2rem 2.4rem;
  background: #fff;
  border: 0.1rem solid #e4e7e9;
  border-left: 0.4rem solid var(--toc-accent);
  border-radius: 0.8rem;
  box-shadow: 0 0.4rem 1.6rem 0 rgba(0, 0, 0, 0.07);
  font-family: var(--font-pri, "Inter", sans-serif);
}

/* ---------- Tiêu đề + nút thu gọn ---------- */

#ez-toc-container.kkt-toc .ez-toc-title-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.6rem;
  width: 100%;
  margin: 0 0 1.6rem;
  padding: 0 0 1.2rem;
}

#ez-toc-container.kkt-toc .ez-toc-title-container::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 0.1rem;
  background: linear-gradient(90deg, #ec2028 0%, rgba(236, 32, 40, 0) 100%);
}

#ez-toc-container.kkt-toc p.ez-toc-title {
  margin: 0;
  padding: 0;
  color: var(--toc-ink);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.35;
}

#ez-toc-container.kkt-toc .ez-toc-title-toggle {
  display: inline-flex;
  flex: 0 0 auto;
}

#ez-toc-container.kkt-toc a.ez-toc-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.2rem;
  height: 3.2rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(236, 32, 40, 0.08);
  text-decoration: none;
  transition: background-color 0.3s ease-in-out;
}

#ez-toc-container.kkt-toc a.ez-toc-toggle:hover,
#ez-toc-container.kkt-toc a.ez-toc-toggle:focus-visible {
  background: rgba(236, 32, 40, 0.18);
}

/* Icon mặc định của plugin gắn fill inline #999 — bỏ hẳn, tự vẽ mũi tên.
   Plugin cũng vẽ sẵn một khung vuông quanh icon, phải gỡ kẻo đè lên nút tròn. */
#ez-toc-container.kkt-toc .ez-toc-js-icon-con {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  height: auto;
  border: 0;
  border-radius: 0;
}

#ez-toc-container.kkt-toc .ez-toc-js-icon-con svg {
  display: none !important;
}

#ez-toc-container.kkt-toc a.ez-toc-toggle::after {
  content: "";
  width: 0.8rem;
  height: 0.8rem;
  margin-top: -0.3rem;
  border-right: 0.2rem solid var(--toc-accent);
  border-bottom: 0.2rem solid var(--toc-accent);
  transform: rotate(-135deg); /* đang mở → mũi tên hướng lên */
  transition: transform 0.3s ease-in-out;
}

#ez-toc-container.kkt-toc.kkt-toc--collapsed a.ez-toc-toggle::after {
  margin-top: -0.6rem;
  transform: rotate(45deg); /* đã thu gọn → hướng xuống */
}

/* ---------- Danh sách ---------- */

#ez-toc-container.kkt-toc nav {
  display: block;
}

#ez-toc-container.kkt-toc ul {
  display: block;
  margin: 0;
  padding: 0;
  list-style: none;
}

#ez-toc-container.kkt-toc li {
  margin: 0;
  padding: 0;
  list-style: none;
}

#ez-toc-container.kkt-toc li::before,
#ez-toc-container.kkt-toc li::marker {
  content: none;
}

#ez-toc-container.kkt-toc a.ez-toc-link {
  display: flex;
  align-items: baseline;
  gap: 0.8rem;
  padding: 0.6rem 0.8rem 0.6rem 1.2rem;
  border-left: 0.3rem solid transparent;
  border-radius: 0 0.4rem 0.4rem 0;
  color: var(--toc-muted);
  font-size: 1.6rem;
  font-weight: 400;
  line-height: 1.5;
  text-decoration: none;
  transition: color 0.3s ease-in-out, background-color 0.3s ease-in-out,
    border-color 0.3s ease-in-out;
}

#ez-toc-container.kkt-toc a.ez-toc-link::before {
  flex: 0 0 auto;
  color: var(--toc-accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

@media screen and (min-width: 1201px) {
  #ez-toc-container.kkt-toc a.ez-toc-link:hover {
    color: var(--toc-accent);
    background: rgba(236, 32, 40, 0.04);
    text-decoration: none;
  }
}

#ez-toc-container.kkt-toc a.ez-toc-link:focus-visible {
  outline: 0.2rem solid var(--toc-accent);
  outline-offset: 0.2rem;
}

#ez-toc-container.kkt-toc li.is-active > a.ez-toc-link {
  color: var(--toc-accent);
  font-weight: 600;
  border-left-color: var(--toc-accent);
  background: rgba(236, 32, 40, 0.06);
}

/* ---------- Đánh số phân cấp (tự làm, plugin không in CSS đếm nữa) ---------- */

#ez-toc-container.kkt-toc nav > ul {
  counter-reset: kkttoc-l1;
}

#ez-toc-container.kkt-toc nav > ul > li {
  counter-increment: kkttoc-l1;
  counter-reset: kkttoc-l2;
}

#ez-toc-container.kkt-toc nav > ul > li > a.ez-toc-link::before {
  content: counter(kkttoc-l1) ".";
  min-width: 2rem;
}

#ez-toc-container.kkt-toc nav > ul > li > ul {
  margin: 0.2rem 0 0.4rem;
  padding-left: 2rem;
}

#ez-toc-container.kkt-toc nav > ul > li > ul > li {
  counter-increment: kkttoc-l2;
}

#ez-toc-container.kkt-toc nav > ul > li > ul > li > a.ez-toc-link {
  font-size: 1.5rem;
}

#ez-toc-container.kkt-toc nav > ul > li > ul > li > a.ez-toc-link::before {
  content: counter(kkttoc-l1) "." counter(kkttoc-l2);
  min-width: 2.8rem;
  color: var(--toc-accent-dark);
  font-weight: 600;
}

/* ---------- Anchor: chừa chỗ cho thanh nav cố định (.header-nav.is-fixed cao 44px) ---------- */

.mona-content span.ez-toc-section {
  scroll-margin-top: 7rem;
}

/* ---------- Mobile ---------- */

@media screen and (max-width: 767px) {
  #ez-toc-container.kkt-toc {
    margin: 2rem 0 2.4rem;
    padding: 1.6rem;
  }

  #ez-toc-container.kkt-toc p.ez-toc-title {
    font-size: 1.8rem;
  }

  #ez-toc-container.kkt-toc nav {
    max-height: 32rem;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  #ez-toc-container.kkt-toc a.ez-toc-link {
    font-size: 1.5rem;
  }

  #ez-toc-container.kkt-toc nav > ul > li > ul > li > a.ez-toc-link {
    font-size: 1.4rem;
  }

  .mona-content span.ez-toc-section {
    scroll-margin-top: 6rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  #ez-toc-container.kkt-toc a.ez-toc-toggle::after,
  #ez-toc-container.kkt-toc a.ez-toc-link {
    transition: none;
  }
}
