/* ============================================
   עיצוב משופר לקטעים מתקפלים וכרטיסיות הסבר
   ============================================ */

/* === משתנים גלובליים === */
:root {
  --details-border: #e1e4e8;
  --details-bg: #ffffff;
  --details-hover: #f6f8fa;
  --summary-color: #24292e;
  --summary-bg: linear-gradient(to right, #f8f9fa, transparent);
  --summary-arrow-color: #586069;
  --animation-speed: 0.3s;
  --header-anchor-color: #6c757d;
  --header-anchor-hover: #0366d6;
  --tooltip-bg: rgba(0, 0, 0, 0.8);
  --tooltip-text: white;
}

/* === Dark themes override === */
:root[data-theme="dark"],
:root[data-theme="dim"],
:root[data-theme="nebula"] {
  --details-border: #30363d;
  --details-bg: #0d1117;
  --details-hover: #161b22;
  --summary-color: #c9d1d9;
  --summary-bg: linear-gradient(to right, rgba(22, 27, 34, 0.8), transparent);
  --summary-arrow-color: #8b949e;
  --header-anchor-color: #8b949e;
  --header-anchor-hover: #58a6ff;
  --tooltip-bg: rgba(255, 255, 255, 0.9);
  --tooltip-text: #000;
}

/* === Ocean theme override === */
:root[data-theme="ocean"] {
  --details-border: rgba(49, 130, 206, 0.35);
  --details-bg: rgba(26, 54, 93, 0.85);
  --details-hover: rgba(42, 67, 101, 0.9);
  --summary-color: #ffffff;
  --summary-bg: linear-gradient(to right, rgba(49, 130, 206, 0.15), transparent);
  --summary-arrow-color: rgba(255, 255, 255, 0.65);
  --header-anchor-color: rgba(255, 255, 255, 0.65);
  --header-anchor-hover: #63b3ed;
  --tooltip-bg: rgba(26, 54, 93, 0.95);
  --tooltip-text: #ffffff;
}

/* === Forest theme override === */
:root[data-theme="forest"] {
  --details-border: rgba(72, 187, 120, 0.35);
  --details-bg: rgba(20, 83, 45, 0.85);
  --details-hover: rgba(22, 101, 52, 0.9);
  --summary-color: #ffffff;
  --summary-bg: linear-gradient(to right, rgba(72, 187, 120, 0.15), transparent);
  --summary-arrow-color: rgba(255, 255, 255, 0.65);
  --header-anchor-color: rgba(255, 255, 255, 0.65);
  --header-anchor-hover: #68d391;
  --tooltip-bg: rgba(20, 83, 45, 0.95);
  --tooltip-text: #ffffff;
}

/* === Rose Pine Dawn theme override === */
:root[data-theme="rose-pine-dawn"] {
  --details-border: #dfdad9;
  --details-bg: #faf4ed;
  --details-hover: #f2e9e1;
  --summary-color: #575279;
  --summary-bg: linear-gradient(to right, rgba(242, 233, 225, 0.8), transparent);
  --summary-arrow-color: #9893a5;
  --header-anchor-color: #9893a5;
  --header-anchor-hover: #907aa9;
  --tooltip-bg: rgba(87, 82, 121, 0.9);
  --tooltip-text: #faf4ed;
}

/* === High Contrast theme override === */
:root[data-theme="high-contrast"] {
  --details-border: #ffffff;
  --details-bg: #000000;
  --details-hover: #1a1a1a;
  --summary-color: #ffffff;
  --summary-bg: linear-gradient(to right, rgba(255, 255, 255, 0.1), transparent);
  --summary-arrow-color: #ffffff;
  --header-anchor-color: #ffffff;
  --header-anchor-hover: #ffff00;
  --tooltip-bg: #ffffff;
  --tooltip-text: #000000;
}

/* === Classic theme override === */
:root[data-theme="classic"] {
  --details-border: #e1e4e8;
  --details-bg: #ffffff;
  --details-hover: #f6f8fa;
  --summary-color: #24292e;
  --summary-bg: linear-gradient(to right, #f8f9fa, transparent);
  --summary-arrow-color: #586069;
  --header-anchor-color: #6c757d;
  --header-anchor-hover: #0366d6;
  --tooltip-bg: rgba(0, 0, 0, 0.8);
  --tooltip-text: white;
}

/* === Custom theme override - uses CSS variables from the custom theme === */
:root[data-theme="custom"],
:root[data-theme^="shared:"] {
  --details-border: var(--glass-border, #30363d);
  --details-bg: var(--bg-secondary, #0d1117);
  --details-hover: var(--bg-tertiary, #161b22);
  --summary-color: var(--text-primary, #c9d1d9);
  --summary-bg: linear-gradient(to right, color-mix(in srgb, var(--bg-tertiary, #161b22) 80%, transparent), transparent);
  --summary-arrow-color: var(--text-muted, #8b949e);
  --header-anchor-color: var(--text-muted, #8b949e);
  --header-anchor-hover: var(--primary, #58a6ff);
  --tooltip-bg: var(--bg-tertiary, rgba(255, 255, 255, 0.9));
  --tooltip-text: var(--text-primary, #000);
  /* mark/highlight styling - amber yellow at 30% opacity */
  --mark-bg: rgba(255, 191, 0, 0.3);
  --mark-text: var(--text-primary, #FFFFFF);
  --mark-border: #FFBF00;
}

/* === קטעים מתקפלים === */
.markdown-details {
  margin: 1rem 0;
  border: 1px solid var(--details-border);
  border-radius: 8px;
  background: var(--details-bg);
  overflow: hidden;
  transition: box-shadow var(--animation-speed) ease;
}

.markdown-details[open] {
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.08);
}

.markdown-summary {
  padding: 0.75rem 1rem;
  background: var(--summary-bg);
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  color: var(--summary-color);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: background-color var(--animation-speed) ease;
  position: relative;
}

.markdown-summary:hover {
  background: var(--details-hover);
}

.markdown-summary::before {
  content: '▶';
  display: inline-block;
  margin-left: 0.5rem;
  font-size: 0.8em;
  transition: transform var(--animation-speed) ease;
  color: var(--summary-arrow-color);
}

.markdown-details[open] .markdown-summary::before {
  transform: rotate(90deg);
}

.markdown-summary::-webkit-details-marker { display: none; }

.details-content {
  padding: 1rem;
  border-top: 1px solid var(--details-border);
  animation: slideDown var(--animation-speed) ease-out;
}

/* === כרטיסיות הסבר === */
.admonition {
  margin: 0 0 1rem 0;
  border-radius: 0.5rem;
  padding: 1rem;
  border-right: 4px solid;
}

.admonition-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}

.admonition-title svg {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

.admonition-content {
  font-size: 0.875rem;
}

.admonition-content > *:first-child { margin-top: 0; }
.admonition-content > *:last-child { margin-bottom: 0; }
.admonition-content > p { margin-bottom: 0.25rem; }
.admonition-content > p:last-child { margin-bottom: 0; }

/* סוגים – כחול */
.admonition-note,
.admonition-info,
.admonition-example,
.admonition-todo { border-color: #3b82f6; background: rgba(59, 130, 246, 0.1); }
.admonition-note .admonition-title,
.admonition-info .admonition-title,
.admonition-example .admonition-title,
.admonition-todo .admonition-title { color: #3b82f6; }

/* סוגים – ירוק */
.admonition-tip,
.admonition-success { border-color: #22c55e; background: rgba(34, 197, 94, 0.1); }
.admonition-tip .admonition-title,
.admonition-success .admonition-title { color: #22c55e; }

/* סוגים – סגול */
.admonition-important,
.admonition-question { border-color: #a855f7; background: rgba(168, 85, 247, 0.1); }
.admonition-important .admonition-title,
.admonition-question .admonition-title { color: #a855f7; }

/* סוגים – צהוב */
.admonition-warning,
.admonition-experimental { border-color: #eab308; background: rgba(234, 179, 8, 0.1); }
.admonition-warning .admonition-title,
.admonition-experimental .admonition-title { color: #eab308; }

/* סוגים – אדום */
.admonition-danger { border-color: #ef4444; background: rgba(239, 68, 68, 0.1); }
.admonition-danger .admonition-title { color: #ef4444; }

/* סוגים – אפור */
.admonition-quote,
.admonition-deprecated,
.admonition-abstract { border-color: #6b7280; background: rgba(107, 114, 128, 0.1); }
.admonition-quote .admonition-title,
.admonition-deprecated .admonition-title,
.admonition-abstract .admonition-title { color: #6b7280; }

/* === אנימציות === */
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === RTL === */
[dir="rtl"] .markdown-summary::before { margin-left: 0; margin-right: 0.5rem; transform: scaleX(-1); }
[dir="rtl"] .markdown-details[open] .markdown-summary::before { transform: scaleX(-1) rotate(90deg); }

/* === מובייל === */
@media (max-width: 768px) {
  .markdown-details, .admonition { margin: 0.75rem -0.5rem; border-radius: 0; }
  .admonition { padding: 0.75rem; }
  .details-content { padding: 0.75rem; }
}

/* === מצב כהה מוגדר כעת ב-data-theme למעלה === */

/* === Admonition overrides removed – transparent backgrounds work across all themes === */

/* === Header anchors & copy buttons accessibility additions === */
/* קישור עוגן (סמל בלבד) שמתווסף אחרי הכותרת; לא מסתיר טקסט הכותרת */
.header-anchor {
  margin-left: 0.5em;
  opacity: 0;
  color: var(--header-anchor-color);
  text-decoration: none;
  font-size: 0.9em;
  transition: opacity 0.2s ease, color 0.2s ease;
  vertical-align: middle;
}
.header-anchor:focus {
  opacity: 1;
  outline: 2px solid var(--header-anchor-hover);
  outline-offset: 2px;
  border-radius: 3px;
}
h1:hover .header-anchor,
h2:hover .header-anchor,
h3:hover .header-anchor,
h4:hover .header-anchor,
h5:hover .header-anchor,
h6:hover .header-anchor { opacity: 1; }
.header-anchor:hover { color: var(--header-anchor-hover); transform: scale(1.05); }

.permalink-tooltip {
  background: var(--tooltip-bg);
  color: var(--tooltip-text);
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 1000;
}

/* Visually hidden but accessible to screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Contrast/reduced motion adjustments */
/* Dark mode colors now handled via data-theme above */
@media (prefers-contrast: high) {
  .header-anchor:focus { outline-width: 3px; }
}
@media (prefers-reduced-motion: reduce) {
  .header-anchor, .permalink-tooltip { transition: none; }
}

/* Mobile/touch devices: אין hover, לכן האייקון תמיד גלוי ומגדילים hit-area */
@media (hover: none) {
  .header-anchor { opacity: 1; padding: 0.25em; display: inline-flex; align-items: center; }
}
@media (pointer: coarse) {
  .header-anchor { opacity: 1; padding: 0.25em; display: inline-flex; align-items: center; }
}

/* === Mark/Highlight styling (==טקסט מודגש==) === */
mark {
  background-color: rgba(255, 191, 0, 0.3);
  color: #FFFFFF;
  border-radius: 2px;
  padding: 0 4px;
  border-bottom: 1.5px solid #FFBF00;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

/* Light themes - darker text for readability on light backgrounds */
:root[data-theme="classic"] mark,
:root[data-theme="rose-pine-dawn"] mark {
  color: #1a1a1a;
}

/* Custom/Shared themes */
:root[data-theme="custom"] mark,
:root[data-theme^="shared:"] mark {
  background-color: color-mix(in srgb, #FFBF00 30%, transparent);
  color: var(--text-primary, #FFFFFF);
  border-bottom-color: #FFBF00;
}

/* High contrast */
:root[data-theme="high-contrast"] mark {
  background-color: rgba(255, 191, 0, 0.45);
  color: #FFFFFF;
  border-bottom: 2px solid #FFBF00;
  font-weight: bold;
}

/* === Admonition Custom/Shared overrides removed – transparent backgrounds work across all themes === */
