/**
 * Course unit shared engine (v2) - canonical CSS.
 *
 * Base = unit-2 superset (see דוח_איחוד_מנוע.md section ג), plus the
 * non-conflicting additions the report lists: .video-duration / .tool-item
 * (unit 3) and .chip / .embedded-page / .bug-card (units 8-9).
 *
 * Every rule is prefixed with #interactive-unit-container.cpt-engine-v2 -
 * old-format units (which carry their own full embedded <style>) never have
 * the .cpt-engine-v2 marker class, so this file cannot affect them at all.
 *
 * Deliberately NOT here (stay per-unit, in each unit-N.html override block):
 *  - :root rules (the --primary-color leak of units 4-7 is fixed by design)
 *  - --primary-color / --secondary-color values
 *  - #content geometry variants, .styled-button variants, h4 rhythm,
 *    heading-rhythm rules of units 2-3, the visible progress-bar of 4-7,
 *    the global pre/h4::before of units 8-9, unit-7 gallery CSS.
 *
 * Per-unit override blocks are inline in the page content; they use
 * body-prefixed selectors so they win regardless of stylesheet order.
 */

#interactive-unit-container.cpt-engine-v2 {
  /* Defaults so the engine never breaks if a unit forgets to set its accent;
     per-unit inline `--primary-color` overrides these. */
  --primary-color: #2a8c8c;
  --secondary-color: #34495e;
  --nav-width: 300px;
  --header-height: 60px;
  --content-strip-rgb: 74, 144, 226;
  --primary-hover-1: #3a7bc8;
  --primary-hover-2: #229954;
  font-family: 'Rubik', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  display: flex;
  align-items: flex-start;
  direction: rtl;
  position: relative;
}

#interactive-unit-container.cpt-engine-v2 * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

#interactive-unit-container.cpt-engine-v2 #nav {
  width: var(--nav-width);
  flex: 0 0 var(--nav-width);
  align-self: flex-start;
  /* Native sticky - anchored below the admin bar + the sticky top nav.
     Falls back gracefully if the shell vars are absent (chrome=off). */
  position: sticky;
  top: calc(var(--stick-top, 0px) + var(--course-topnav-h, 60px) + 10px);
  max-height: calc(100vh - var(--stick-top, 0px) - var(--course-topnav-h, 60px) - 20px);
  overflow-y: auto;
  background: #fbfcfd;
  padding: 22px 18px;
  font-size: 1rem;
  border-left: 1px solid #e9edf1;
  z-index: 1001;
  order: 1;
}

#interactive-unit-container.cpt-engine-v2 .sidebar-title {
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .04em;
  margin: 4px 10px 14px;
  text-align: right;
  color: #8895a3;
  text-transform: none;
}

#interactive-unit-container.cpt-engine-v2 #content {
  flex: 1 1 auto;
  min-width: 0;
  margin-right: 0;
  padding: 40px 40px 40px 30px;
  margin-top: 0;
  max-width: none;
  order: 2;
  position: relative;
}

#interactive-unit-container.cpt-engine-v2 #content::before {
  content: "";
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(to bottom, rgba(var(--content-strip-rgb), 0.2), rgba(var(--content-strip-rgb), 0.1));
  opacity: 0;
  transition: opacity 0.3s;
}

#interactive-unit-container.cpt-engine-v2 #content.has-active::before {
  opacity: 1;
}

/* hidden by default; visible white bar of units 4-7 stays a per-unit override */
#interactive-unit-container.cpt-engine-v2 .progress-bar {
  display: none;
}

#interactive-unit-container.cpt-engine-v2 .progress-indicator {
  height: 10px;
  background: linear-gradient(to right, var(--primary-color), #27ae60);
  border-radius: 5px;
  transition: width 0.3s ease;
  width: 0;
}

#interactive-unit-container.cpt-engine-v2 .nav-item {
  margin: 2px 0;
  cursor: pointer;
}

#interactive-unit-container.cpt-engine-v2 .main-item,
#interactive-unit-container.cpt-engine-v2 .sub-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  border-right: 3px solid transparent;
  background: transparent;
  color: #3a4756;
  transition: background-color .18s ease, border-color .18s ease, color .18s ease;
}

#interactive-unit-container.cpt-engine-v2 .main-item {
  font-weight: 600;
}

#interactive-unit-container.cpt-engine-v2 .sub-item {
  margin: 1px 0;
  font-size: .95em;
  color: #5a6776;
}

#interactive-unit-container.cpt-engine-v2 .main-item:hover,
#interactive-unit-container.cpt-engine-v2 .sub-item:hover {
  background: #eef2f5;
  color: var(--secondary-color);
}

#interactive-unit-container.cpt-engine-v2 .completion-circle {
  width: 20px;
  height: 20px;
  border: 2px solid #cbd3db;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: all 0.25s ease;
  background: #fff;
  flex-shrink: 0;
}

/* Completed sections - only circle gets checkmark with colored background */
#interactive-unit-container.cpt-engine-v2 .nav-item.completed .completion-circle {
  background: var(--primary-color);
  border-color: var(--primary-color);
  border-width: 2px;
}

#interactive-unit-container.cpt-engine-v2 .nav-item.completed .completion-circle::after {
  content: "✓";
  color: white;
  font-weight: bold;
}

#interactive-unit-container.cpt-engine-v2 .main-item:hover .completion-circle,
#interactive-unit-container.cpt-engine-v2 .sub-item:hover .completion-circle {
  border-color: var(--primary-color);
}

#interactive-unit-container.cpt-engine-v2 .sub-items {
  margin-right: 34px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}

#interactive-unit-container.cpt-engine-v2 .sub-items.active {
  max-height: 500px;
}

#interactive-unit-container.cpt-engine-v2 .video-container {
  margin: 30px 0;
  background: #f8f9fa;
  padding: 20px;
  border-radius: 8px;
  max-width: 800px;
  position: relative;
}

#interactive-unit-container.cpt-engine-v2 .video-title {
  font-weight: bold;
  margin-bottom: 10px;
}

/* unit-3 addition */
#interactive-unit-container.cpt-engine-v2 .video-duration {
  color: #666;
  font-size: 0.9em;
  margin-bottom: 10px;
}

#interactive-unit-container.cpt-engine-v2 iframe {
  width: 100%;
  max-width: 800px;
  aspect-ratio: 16/9;
  border: none;
  border-radius: 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

#interactive-unit-container.cpt-engine-v2 .content-section {
  animation: fadeIn-scoped 0.5s ease-out;
  margin-bottom: 40px;
  line-height: 1.6;
}

/* Lists: the global `* { padding:0 }` reset strips marker indentation -
   restore a slight inward indent (RTL: padding on the right) */
#interactive-unit-container.cpt-engine-v2 .content-section ul,
#interactive-unit-container.cpt-engine-v2 .content-section ol {
  padding-right: 1.8em;
  margin: 12px 0;
  list-style-position: outside;
}

#interactive-unit-container.cpt-engine-v2 .content-section li {
  margin-bottom: 8px;
  line-height: 1.6;
}

#interactive-unit-container.cpt-engine-v2 .styled-button {
  display: inline-block;
  background: linear-gradient(45deg, var(--primary-color), #27ae60) !important;
  color: white !important;
  padding: 10px 20px;
  border-radius: 25px;
  text-decoration: none;
  font-weight: bold;
  margin: 10px 0;
  border: none;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: left;
  box-shadow: 0 2px 8px rgba(var(--content-strip-rgb), 0.3);
}

#interactive-unit-container.cpt-engine-v2 .styled-button:hover {
  opacity: 0.95;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(46, 204, 113, 0.4);
  background: linear-gradient(45deg, var(--primary-hover-1), var(--primary-hover-2)) !important;
}

#interactive-unit-container.cpt-engine-v2 .prompt-container {
  background-color: #f0ebf5;
  border-right: 4px solid var(--primary-color);
  border-radius: 4px;
  padding: 20px;
  margin: 20px 0;
  position: relative;
  font-family: 'Varela Round', 'Rubik', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-size: 1em;
  line-height: 1.6;
}

#interactive-unit-container.cpt-engine-v2 .prompt-container .copy-button {
  position: absolute;
  top: 10px;
  left: 10px;
  background-color: transparent;
  color: var(--primary-color);
  border: none;
  padding: 5px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 1.2em;
  opacity: 0.6;
  transition: opacity 0.3s, background-color 0.3s;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#interactive-unit-container.cpt-engine-v2 .prompt-container .copy-button:hover {
  opacity: 1;
  background-color: rgba(0, 0, 0, 0.08);
}

#interactive-unit-container.cpt-engine-v2 .prompt-container pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  margin: 0;
  padding-top: 20px;
}

#interactive-unit-container.cpt-engine-v2 .content-section hr {
  border: 0;
  height: 1px;
  background-image: linear-gradient(to right, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0));
  margin: 40px 0;
}

#interactive-unit-container.cpt-engine-v2 .content-section h4 {
  font-size: 1.4em;
  margin-top: 50px;
  margin-bottom: 15px;
  color: var(--secondary-color);
}

#interactive-unit-container.cpt-engine-v2 .button-wrapper {
  text-align: left;
}

/* Active section: soft accent tint + accent rail on the right (RTL start). */
#interactive-unit-container.cpt-engine-v2 .main-item.active,
#interactive-unit-container.cpt-engine-v2 .sub-item.active {
  background: color-mix(in srgb, var(--primary-color) 12%, #fff) !important;
  border: 1px solid transparent !important;
  border-right: 3px solid var(--primary-color) !important;
  color: var(--secondary-color) !important;
  position: relative;
  font-weight: 700;
  box-shadow: none !important;
  transform: none !important;
}

#interactive-unit-container.cpt-engine-v2 .main-item.active .completion-circle,
#interactive-unit-container.cpt-engine-v2 .sub-item.active .completion-circle {
  border-color: var(--primary-color) !important;
  background: #fff !important;
}

#interactive-unit-container.cpt-engine-v2 .illustration {
  width: 100%;
  max-width: 600px;
  margin: 30px auto;
  border-radius: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  display: block;
}

#interactive-unit-container.cpt-engine-v2 .full-width-image {
  width: 100%;
  max-width: 100%;
  margin: 30px 0;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#interactive-unit-container.cpt-engine-v2 table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
}

#interactive-unit-container.cpt-engine-v2 table th,
#interactive-unit-container.cpt-engine-v2 table td {
  padding: 12px;
  border: 1px solid #dee2e6;
  text-align: right;
}

#interactive-unit-container.cpt-engine-v2 table th {
  background-color: var(--primary-color);
  color: white;
  font-weight: bold;
}

#interactive-unit-container.cpt-engine-v2 table tr:nth-child(even) {
  background-color: #f8f9fa;
}

/* unit-3 addition */
#interactive-unit-container.cpt-engine-v2 .tool-item {
  margin-bottom: 30px;
  padding-bottom: 20px;
}

#interactive-unit-container.cpt-engine-v2 .tool-item:last-of-type {
  margin-bottom: 0;
  padding-bottom: 0;
}

/* units 8-9 additions */
#interactive-unit-container.cpt-engine-v2 .chip {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 20px;
  background: linear-gradient(135deg, #3498db, #8e44ad);
  color: white !important;
  font-weight: bold;
  text-decoration: none;
  margin: 5px;
  transition: transform 0.2s, box-shadow 0.2s;
}

#interactive-unit-container.cpt-engine-v2 .chip:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  background: linear-gradient(135deg, #2980b9, #7d3c98);
}

#interactive-unit-container.cpt-engine-v2 .embedded-page {
  width: 100%;
  height: 600px;
  border: 1px solid #ddd;
  border-radius: 8px;
  margin: 20px 0;
}

#interactive-unit-container.cpt-engine-v2 .bug-card {
  background: #fff8e1;
  border: 1px solid #ffecb3;
  border-left: 5px solid var(--primary-color);
  padding: 15px 20px;
  margin-bottom: 15px;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.07);
  font-size: 1.05em;
}

/* keyframes cannot be scope-prefixed; identical definition exists in the
   old-format units, so a duplicate is harmless */
@keyframes fadeIn-scoped {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 800px) {
  #interactive-unit-container.cpt-engine-v2 { display: block; }
  #interactive-unit-container.cpt-engine-v2 #content { display: none; }
  #interactive-unit-container.cpt-engine-v2 #nav { position: static; width: 100%; height: auto; padding: 10px; border-left: none; }
  #interactive-unit-container.cpt-engine-v2 .main-content { margin: 0; width: 100%; padding: 10px; }
  #interactive-unit-container.cpt-engine-v2 .progress-bar { right: 0; width: 100%; }
  #interactive-unit-container.cpt-engine-v2 .sub-items { margin-right: 0; }
  #interactive-unit-container.cpt-engine-v2 .sub-item { padding-right: 8px; padding-left: 8px; }

  #interactive-unit-container.cpt-engine-v2 .section-wrapper {
    padding: 15px;
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-in-out;
  }

  #interactive-unit-container.cpt-engine-v2 .section-wrapper.active {
    max-height: 5000px;
  }

  #interactive-unit-container.cpt-engine-v2 .sub-items.active {
    max-height: 5000px;
  }

  #interactive-unit-container.cpt-engine-v2 .content-section {
    animation: none;
  }
}
