/* ============================================================================
   topic_detail.css
   Page-specific styles for Connect the Dots Topic Detail Page
   ============================================================================ */

:root {
  --navy:              oklch(0.33 0.09 264);
  --navy-hover:        oklch(0.28 0.08 264);
  --color-blue:        #2F5FEE;
  --color-blue-dark:   #1E46C4;
  --color-blue-light:  #EAF0FF;
  --color-ink:         #1B2237;
  --color-ink-soft:    #5B6478;
  --color-body-bg:     #FFFFFF;
  --color-panel:       #EFF4FC;
  --color-border:      #E4E9F2;
  --color-gray-soft:   #EEF1F6;
  --color-green:       #17A673;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --radius-pill: 999px;

  --shadow-card: 0 2px 6px rgba(20, 30, 60, .04);

  --font-display: var(--smw-font-stack);
  --font-body: var(--smw-font-stack);
}

body, button, input, select, textarea {
  font-family: var(--smw-font-stack);
  -webkit-font-smoothing: antialiased;
}

/* Breadcrumbs */
.cdt-breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--color-ink-soft);
  margin: 0 0 16px 0;
  padding: 0;
  box-sizing: border-box;
}

.cdt-breadcrumb a {
  display: inline-flex;
  align-items: center;
  color: var(--color-blue);
  font-weight: 600;
  text-decoration: none;
  transition: color 0.15s ease;
}

.cdt-breadcrumb a:hover {
  text-decoration: underline;
  color: var(--color-blue-dark);
}

.cdt-breadcrumb svg {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

.cdt-breadcrumb span:not(.sep) {
  color: var(--color-ink);
  font-weight: 600;
}

/* Inside the shared Kids Zone Topics bar (.kzd-bar, kidszone_topic_dropdown.css).
   That file styles `nav.breadcrumb`, but this page's breadcrumb is `.cdt-breadcrumb`,
   so the same rules are repeated here:
   - margin-bottom 0: the bar already owns the 16px gap below the row. Left in place,
     it made the breadcrumb box taller than its text and the centred row pushed
     the text ~8px above the dropdown.
   - flex 1 1 12rem + min-width 0: a long breadcrumb shrinks/wraps instead of
     forcing the dropdown onto a second row. */
.kzd-bar > .cdt-breadcrumb {
  margin-bottom: 0;
  flex: 1 1 12rem;
  min-width: 0;
}

.kzd-bar > .cdt-breadcrumb span:not(.sep) {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* Phones: the Kids Zone bar stacks into a column (kidszone_topic_dropdown.css, <=679px).
   In a column the flex-basis above would become a height, so reset it. */
@media (max-width: 679px) {
  .kzd-bar > .cdt-breadcrumb {
    flex: 0 0 auto;
    max-width: 100%;
  }
}

/* ============================================================
   HERO HEADER PANEL
   ============================================================ */
.cdt-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  margin-top: 0;
  margin-bottom: 1.5rem;
  padding: 1.375rem 1.75rem;
  background: oklch(0.95 0.03 264);
  border: 2px solid oklch(0.75 0.12 264);
  border-radius: 1rem;
  box-shadow: 0 1px 2px oklch(0.2 0.035 274 / .03), 0 6px 18px oklch(0.54 0.22 266 / .05);
  box-sizing: border-box;
}

.cdt-hero-text {
  width: 100%;
  display: flex;
  flex-direction: column;
}

.cdt-hero-text h1 {
  text-align: center;
  margin: 0 0 0.5rem 0;
  font-family: var(--smw-font-stack);
  font-size: 1.875rem; /* 30px */
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: #0e2770;
}

.cdt-hero-text p {
  margin: 0 0 1.25rem 0;
  width: 100%;
  text-align: left;
  font-family: var(--smw-font-stack);
  font-size: 0.9375rem; /* 15px */
  line-height: 1.5;
  color: #0b205f;
  font-weight: 500;
}

/* ============================================================
   STAT BADGES (Hero Pills)
   ============================================================ */
.cdt-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

.cdt-stat-card {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #ffffff;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 8px 16px;
  box-shadow: 0 1px 2px rgba(20, 30, 60, .04);
}

.cdt-stat-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  color: var(--color-blue);
  flex-shrink: 0;
}

.cdt-stat-icon svg {
  width: 18px;
  height: 18px;
}

.cdt-stat-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--color-ink);
}

/* ============================================================
   FILTER / SORT BAR
   ============================================================ */
.cdt-ws-filterbar {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin: 18px 0 16px;
}

.cdt-ws-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 130px;
  flex: 0 1 160px;
}

/* Theme dropdown (first field in the filter bar): size it to its longest
   option instead of the fixed 160px basis, so long names such as
   "Electronics & Equipments" are never clipped. width: max-content lets the
   native <select> report the width of its widest option (plus the existing
   padding, which already leaves a few px before the arrow). It does not
   shrink, and max-width: 100% keeps it inside the bar on very small screens.
   The Sort By field is unaffected. */
.cdt-ws-filterbar > .cdt-ws-field:first-child {
  flex: 0 0 auto;
  width: max-content;
  max-width: 100%;
}

/* +4px right padding (30px instead of 26px) = the small safety margin beyond
   the longest option's text width; the arrow icon position is unchanged. */
.cdt-ws-filterbar > .cdt-ws-field:first-child .cdt-ws-select {
  padding-right: 30px;
}

.cdt-ws-field label {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--color-ink-soft);
}

.cdt-ws-select {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--color-ink);
  border: 1px solid #64748B;
  border-radius: 6px;
  background: #fff;
  padding: 7px 26px 7px 10px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M6 9l6 6 6-6' stroke='%231E293B' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  cursor: pointer;
}

/* Plain classic select: the open list (and its blue highlight) is the
   browser's native popup. Focus only changes the border colour. */
.cdt-ws-select:focus,
.cdt-ws-select:focus-visible {
  outline: none;
  border-color: var(--color-blue);
}

.cdt-ws-select option {
  background: #fff;
  color: var(--color-ink);
}

.cdt-ws-field-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.cdt-ws-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 700;
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  border: 1px solid var(--color-border);
  background: #fff;
  color: var(--color-ink);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
  white-space: nowrap;
}

.cdt-ws-btn:hover { border-color: var(--color-blue); color: var(--color-blue); }

/* ============================================================
   WORKSHEET GRID & CARDS
   ============================================================ */
.cdt-ws-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 28px;
}

.cdt-ws-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: 14px;
  min-width: 0;
  box-sizing: border-box;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.cdt-ws-card:hover {
  border-color: var(--color-blue);
  box-shadow: 0 4px 12px rgba(20, 30, 60, 0.08);
}

.cdt-ws-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #ffffff;
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  box-sizing: border-box;
}

/* Image Loading Shimmer Effect */
.cdt-ws-thumb.is-loading {
  background: linear-gradient(90deg, #f0f4f8 25%, #e1e7f0 50%, #f0f4f8 75%);
  background-size: 200% 100%;
  animation: cdt-shimmer 1.5s infinite linear;
}

@keyframes cdt-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.cdt-ws-thumb.is-loading img {
  opacity: 0;
}

.cdt-ws-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  transition: opacity 0.3s ease;
  opacity: 1;
}

.cdt-ws-body {
  width: 100%;
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cdt-ws-card > .cdt-ws-body:first-child {
  padding-top: 0;
  order: -1;
}

.cdt-ws-title {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  color: var(--color-ink);
}

.cdt-ws-actions {
  width: 100%;
  display: flex;
  flex-direction: row;
  gap: 8px;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.cdt-ws-body .cdt-ws-download {
  flex: 1 1 0;
  min-width: 0;
  height: 38px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 12px;
  background: var(--color-blue);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  border: 1px solid var(--color-blue);
  cursor: pointer;
  transition: background 0.15s ease;
  box-sizing: border-box;
  text-decoration: none; /* Download is a real <a> link */
}

.cdt-ws-body .cdt-ws-download:visited,
.cdt-ws-body .cdt-ws-download:hover,
.cdt-ws-body .cdt-ws-download:focus {
  color: #fff;
}

.cdt-ws-body .cdt-ws-download:hover {
  background: var(--color-blue-dark);
}

.cdt-ws-body .cdt-ws-view {
  flex: 1 1 0;
  min-width: 0;
  height: 38px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 12px;
  background: #fff;
  color: var(--color-blue);
  font-size: 13px;
  font-weight: 700;
  border: 1px solid var(--color-border);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.cdt-ws-body .cdt-ws-view { text-decoration: none; }
.cdt-ws-body .cdt-ws-view:visited { color: var(--color-blue); }
.cdt-ws-body .cdt-ws-view:hover {
  background: var(--color-blue-light);
  border-color: var(--color-blue);
}

.cdt-ws-download-icon,
.cdt-ws-download-spinner {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.cdt-ws-download-spinner[hidden] { display: none !important; }

/* ============================================================
   FEATURE STRIP
   ============================================================ */
.cdt-features {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin: 16px 0 10px;
}

.cdt-feature {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 16px;
  background: var(--color-panel);
  border-radius: var(--radius-md);
  min-width: 0;
}

.cdt-feature-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  flex: none;
  background: #fff;
}

.cdt-feature-icon svg {
  width: 22px;
  height: 22px;
}

.cdt-feature-icon--blue { color: var(--color-blue); }

.cdt-feature-text h3 {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--color-ink);
  margin: 0 0 3px;
}

.cdt-feature-text p {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--color-ink-soft);
}

.cdt-ws-empty {
  grid-column: 1/-1;
  text-align: center;
  padding: 48px 20px;
  color: var(--color-ink-soft);
  font-size: 14px;
}

/* ============================================================
   VIEW PORTAL LIGHTBOX (MATCHED TO TRACING NUMBERS REFERENCE)
   ============================================================ */
.cdt-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: rgba(27, 34, 55, .45);
  padding: 1rem;
}

.cdt-lightbox[hidden] { display: none; }

.cdt-lb-panel {
  position: relative;
  width: min(800px, calc(100vw - 2rem));
  max-height: calc(100svh - 24px);
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 0px;
  box-shadow: 0 24px 60px -12px rgba(20, 30, 60, .35);
  overflow: hidden;
}

.cdt-lb-topbar {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: .5rem 3.5rem;
  background: linear-gradient(180deg, var(--navy), var(--navy-hover));
  color: #fff;
  position: relative;
}

.cdt-lb-panel-topic {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
}

/* Top-Right Close "X" Button */
.cdt-lb-close {
  position: absolute;
  right: 1.25rem;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  height: 38px;
  width: 38px;
  border: 1px solid rgba(0,0,0,.2);
  border-radius: 999px;
  background: rgba(255,255,255,.18);
  color: #fff;
  cursor: pointer;
  transition: background-color .15s ease, transform .15s ease;
}

.cdt-lb-close:hover {
  background:#ffffff;
  color: #0e2770;
}

.cdt-lb-close:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.8);
  outline-offset: 2px;
}

.cdt-lb-close .ico {
  width: 1.125rem;
  height: 1.125rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.25;
}

.cdt-lb-stage {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  padding: 1rem 1rem .75rem;
  min-height: min(460px, 64svh);
}

.cdt-lb-figure {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
}

.cdt-lb-img {
  max-width: 100%;
  max-height: calc(58vh + 24px);
  object-fit: contain;
  border-radius: .375rem;
  box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 10px 24px -8px rgba(0,0,0,.18);
}

.cdt-lb-nav-group {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: .375rem;
}

.cdt-lb-nav-label {
  font-size: .8125rem;
  font-weight: 700;
  color: rgb(36, 74, 143);
  white-space: nowrap;
  user-select: none;
  min-width: 4.375rem;
}

.cdt-lb-nav-label--prev { text-align: right; }
.cdt-lb-nav-label--next { text-align: left; }

.cdt-lb-nav {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: linear-gradient(180deg, var(--navy), var(--navy-hover));
  color: white;
  cursor: pointer;
  transition: background-color .15s ease, opacity .15s ease;
}

.cdt-lb-nav:hover {
  background: var(--color-blue-dark);
}

.cdt-lb-nav:focus-visible {
  outline: 2px solid var(--color-blue);
  outline-offset: 2px;
}

.cdt-lb-nav:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.cdt-lb-nav .ico {
  width: 1.125rem;
  height: 1.125rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.25;
}

.cdt-lb-panel-foot {
  display: flex;
  justify-content: center;
  gap: .875rem;
  padding: .5rem 1.25rem .75rem;
}

.cdt-lb-panel-foot .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 1.25rem;
  height: 40px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}

/* Modal Download is a real <a> link; keep it looking like the button. */
.cdt-lb-panel-foot a.btn {
  text-decoration: none;
}

.cdt-lb-panel-foot a.btn-primary,
.cdt-lb-panel-foot a.btn-primary:visited {
  color: #ffffff;
}

.cdt-lb-panel-foot .btn[hidden] {
  display: none;
}

.cdt-lb-panel-foot .btn .ico {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
}

/* Download & Close Hover Effects */
.cdt-lb-panel-foot .btn-primary {
  background: linear-gradient(180deg, var(--navy), var(--navy-hover));
  color: #ffffff;
}

.cdt-lb-panel-foot .btn-primary:hover {
  background: var(--color-blue-dark);
}

.cdt-lb-panel-foot .btn-secondary {
  background: linear-gradient(180deg, var(--navy), var(--navy-hover));
  border-color: var(--color-border);
  color: #ffffff;
  min-width: 7rem;
  justify-content: center;
}

.cdt-lb-panel-foot .btn-secondary:hover {
  background: #2F5FEE;
}

/* ============================================================
   RESPONSIVE LAYOUT
   ============================================================ */
@media (max-width: 1100px) {
  .cdt-features { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 992px) {
  .cdt-ws-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
  }
}

@media (max-width: 768px) {
  .cdt-hero {
    margin-bottom: 1rem;
    padding: 1rem;
  }
  .cdt-hero-text h1 {
    font-size: 1.5rem;
    text-align: left;
  }
  .cdt-hero-text p {
    font-size: 0.875rem;
  }
  .cdt-ws-grid { gap: 14px; }
  .cdt-features { grid-template-columns: 1fr; gap: 12px; }

  /* Viewer Portal Mobile Adaptations */
  .cdt-lb-nav-label { display: none; }
  .cdt-lb-panel { width: calc(100vw - 1.5rem); }
  .cdt-lb-topbar { padding: 0.5rem 3rem; }
  .cdt-lb-stage { min-height: min(320px, 55svh); padding: 0.5rem 0.75rem 0.25rem; }
  .cdt-lb-img { max-height: calc(48vh + 20px); }
  .cdt-lb-nav { width: 36px; height: 36px; }
  .cdt-lb-nav .ico { width: 1rem; height: 1rem; }
}

@media (max-width: 576px) {
  .cdt-ws-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  /* Viewer Portal Small Mobile Adaptations */
  .cdt-lb-panel-topic { font-size: 0.95rem; }
  .cdt-lb-stage { gap: 0.4rem; }
  .cdt-lb-panel-foot { gap: 0.5rem; }
  .cdt-lb-panel-foot .btn { padding: 0 0.9rem; font-size: 12.5px; min-width: 6.5rem; }
}