/* Classivo Coding — Reusable UI components */

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: var(--text-sm);
  border: 1px solid transparent;
  transition: background-color var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease), transform var(--duration-fast) var(--ease);
}

.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }

.btn--primary {
  background: var(--brand);
  color: var(--text-on-brand);
}
.btn--primary:hover { background: var(--brand-strong); }

.btn--secondary {
  background: var(--bg-surface-alt);
  color: var(--brand-strong);
  border-color: var(--border-subtle);
}
.btn--secondary:hover { background: var(--brand-soft); }

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn--ghost:hover { background: var(--bg-surface-alt); color: var(--text-primary); }

.btn--icon {
  padding: var(--space-2);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
}
.btn--icon:hover { background: var(--bg-surface-alt); color: var(--text-primary); }
/* Inline SVG icons without width/height attributes collapsed to 0×0, leaving
   an invisible button (e.g. the playgrounds' "back to course" arrow). */
.btn--icon > svg:not([width]) { display: block; width: 20px; height: 20px; }

.btn--sm { padding: var(--space-2) var(--space-3); font-size: var(--text-xs); }

.auth-actions { display: flex; align-items: center; gap: var(--space-2); }

/* ---------- Cards ---------- */

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration-base) var(--ease), box-shadow var(--duration-base) var(--ease), border-color var(--duration-base) var(--ease);
}

.card--interactive:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--brand-200);
}

.lang-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-6);
  height: 100%;
}

/* A glossy "app icon" chip: a diagonal gradient built from the course's
   own --icon-color (set inline per card), plus a soft light-sheen overlay
   layered on top via ::before to fake a glass/glossy highlight. */
.lang-card__icon {
  --icon-color: var(--brand-500);
  position: relative;
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  color: #fff;
  background: linear-gradient(
    155deg,
    color-mix(in srgb, var(--icon-color) 82%, white 18%) 0%,
    var(--icon-color) 48%,
    color-mix(in srgb, var(--icon-color) 74%, black 26%) 100%
  );
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), inset 0 -6px 10px -6px rgba(0, 0, 0, 0.35);
}

.lang-card__icon::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.6) 0%, rgba(255, 255, 255, 0.18) 32%, transparent 58%);
  pointer-events: none;
}

.lang-card__icon svg {
  position: relative;
  z-index: 1;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.15));
}

.lang-card__title {
  font-size: var(--text-xl);
}

.lang-card__desc {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
}

.lang-card__meta {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* Upcoming courses look quieter (faded icon, dashed border) while their text
   keeps full contrast; fading the whole card made the text unreadable. */
.lang-card--soon {
  border-style: dashed;
}
.lang-card--soon .lang-card__icon { opacity: 0.55; }

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 700;
  background: var(--bg-surface-alt);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.badge--brand { background: var(--brand-soft); color: var(--brand-strong); border-color: transparent; }
.badge.lesson-module { color: var(--brand); font-weight: 600; }   /* "Module 12 — …" in the lesson header */
.badge--success { background: rgba(31, 157, 107, 0.12); color: var(--success-text); border-color: transparent; }
.badge--warning { background: rgba(193, 125, 31, 0.12); color: var(--accent-warning); border-color: transparent; }

/* ---------- Breadcrumbs ---------- */

.breadcrumbs {
  list-style: none;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-5);
}

.breadcrumbs li { display: flex; align-items: center; gap: var(--space-2); }
.breadcrumbs li:not(:last-child)::after { content: "/"; color: var(--border-strong); }
.breadcrumbs a { color: var(--text-secondary); font-weight: 500; }
.breadcrumbs li:last-child { color: var(--text-primary); font-weight: 600; }

/* ---------- Code blocks ---------- */

.code-block {
  position: relative;
  background: var(--bg-code);
  border-radius: var(--radius-md);
  margin: var(--space-5) 0;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}

.code-block__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  row-gap: 4px;
  padding: var(--space-2) var(--space-4);
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.code-block__lang {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--slate-400);
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.code-block__actions { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }

.code-block__copy, .code-block__open-playground {
  font-size: var(--text-xs);
  color: var(--slate-300);
  padding: 4px var(--space-2);
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.code-block__copy:hover, .code-block__open-playground:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }

.code-block pre {
  margin: 0;
  padding: var(--space-4) var(--space-5);
  overflow-x: auto;
  direction: ltr;
  text-align: start;
}

.code-block code {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: var(--leading-relaxed);
  color: var(--text-code);
  white-space: pre;
}

/* Code syntax is always written left-to-right, regardless of page
   direction — force LTR here so Arabic pages don't mirror punctuation,
   digits, or bracket pairs inside code. */
code.inline-code, :not(pre) > code {
  direction: ltr;
  unicode-bidi: isolate;
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--bg-inline-code);
  color: var(--brand-strong);
  padding: 0.15em 0.4em;
  border-radius: 5px;
  /* A long path or identifier may break rather than push the page sideways
     on a phone; it only breaks when it can't fit on its own line. */
  overflow-wrap: anywhere;
}

/* In RTL text, an LTR code span split across two lines reads out of
   order ("git" at the end of one line, "reset --hard" on the next).
   Keep each span together; it still wraps if longer than a full line. */
[dir="rtl"] code.inline-code, [dir="rtl"] :not(pre) > code {
  display: inline-block;
  max-width: 100%;
  overflow-wrap: anywhere;
  vertical-align: baseline;
}

/* Minimal token colors for hand-highlighted markup (data-token spans) */
.tok-tag   { color: #7ec4f5; }
.tok-attr  { color: #f5c26e; }
.tok-str   { color: #9adb8d; }
.tok-comment { color: #7a8ba0; font-style: italic; }
.tok-kw    { color: #d09bf5; }
.tok-num   { color: #f5a56e; }
.tok-punct { color: #93a6b8; }

/* ---------- Tabs ---------- */

.tabs__list {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border-subtle);
  list-style: none;
  margin-bottom: var(--space-5);
}

.tabs__tab {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tabs__tab.is-active {
  color: var(--brand-strong);
  border-bottom-color: var(--brand);
}

/* ---------- Callouts ---------- */

.callout {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-alt);
  margin: var(--space-5) 0;
}

.callout__icon { flex-shrink: 0; font-size: var(--text-lg); }
/* Flex items don't shrink below their longest word unless told to. */
.callout__body { min-width: 0; }
.callout__body p { color: var(--text-secondary); font-size: var(--text-sm); line-height: var(--leading-relaxed); }
.callout__body strong { color: var(--text-primary); }

.callout--tip { border-inline-start: 3px solid var(--brand); }
.callout--warning { border-inline-start: 3px solid var(--accent-warning); background: rgba(193, 125, 31, 0.06); }
.callout--mistake { border-inline-start: 3px solid var(--accent-danger); background: rgba(209, 69, 61, 0.06); }
.callout--perf { border-inline-start: 3px solid var(--accent-success); background: rgba(31, 157, 107, 0.06); }

/* ---------- Search ---------- */

/* Icon-only by default — the "Search lessons…" label + kbd hint only
   reappear once the viewport is wide enough to spare the room, so the
   trigger doesn't crowd the nav on ordinary desktop widths. */
.search-trigger {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-sunken);
  color: var(--text-muted);
  font-size: var(--text-sm);
  flex-shrink: 0; /* stays a full icon button instead of a squeezed empty pill */
}

.search-trigger span { display: none; }

.search-trigger kbd {
  display: none;
  margin-inline-start: auto;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 1px 6px;
}

@media (min-width: 1300px) {
  .search-trigger {
    padding: var(--space-2) var(--space-3);
    min-width: 140px;
  }
  .search-trigger span { display: inline; }
  .search-trigger kbd { display: inline-block; }
}

.search-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: none;
  background: var(--bg-overlay);
  padding: 10vh var(--space-4) var(--space-4);
}

.search-modal.is-open { display: block; }

.search-modal__panel {
  max-width: 620px;
  margin-inline: auto;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}

.search-modal__input {
  width: 100%;
  padding: var(--space-5);
  font-size: var(--text-lg);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-subtle);
}

.search-modal__results {
  max-height: 50vh;
  overflow-y: auto;
  padding: var(--space-2);
}

.search-result {
  display: block;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
}

.search-result:hover, .search-result.is-selected {
  background: var(--bg-surface-alt);
  text-decoration: none;
}

.search-result__title { font-weight: 700; color: var(--text-primary); }
.search-result__path { font-size: var(--text-xs); color: var(--text-muted); }
.search-modal__empty { padding: var(--space-6); text-align: center; color: var(--text-muted); font-size: var(--text-sm); }

/* ---------- Language toggle ---------- */

.lang-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: 700;
}
.lang-toggle:hover { background: var(--bg-surface-alt); color: var(--text-primary); }
.lang-toggle svg { width: 16px; height: 16px; flex-shrink: 0; }
.lang-toggle__label { letter-spacing: 0.01em; }

@media (max-width: 560px) {
  .lang-toggle__label { display: none; }
  .lang-toggle { padding: 0; width: 40px; justify-content: center; }
}

/* ---------- Theme toggle ---------- */

.theme-toggle {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}
.theme-toggle:hover { background: var(--bg-surface-alt); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

/* ---------- Quiz ---------- */

.quiz {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  background: var(--bg-surface);
  margin: var(--space-5) 0;
}

.quiz__question {
  font-weight: 700;
  margin-bottom: var(--space-4);
}

.quiz__options {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.quiz__option {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--text-sm);
}

.quiz__option:hover { border-color: var(--brand-300); }
.quiz__option.is-correct { border-color: var(--accent-success); background: rgba(31, 157, 107, 0.08); }
.quiz__option.is-incorrect { border-color: var(--accent-danger); background: rgba(209, 69, 61, 0.08); }

.quiz__feedback {
  margin-top: var(--space-4);
  font-size: var(--text-sm);
  font-weight: 600;
  display: none;
}
.quiz__feedback.is-visible { display: block; }

/* ---------- Progress ---------- */

.progress-bar {
  width: 100%;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface-alt);
  overflow: hidden;
}

.progress-bar__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--brand-400), var(--brand-600));
  border-radius: inherit;
  transition: width var(--duration-slow) var(--ease);
}

/* ---------- Table of contents ---------- */

.toc {
  position: sticky;
  top: calc(var(--header-height) + var(--space-6));
}

.toc__title {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: var(--space-3);
}

.toc__links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  border-inline-start: 2px solid var(--border-subtle);
}

.toc__links a {
  display: block;
  padding: 2px 0 2px var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-inline-start: -2px;
  border-inline-start: 2px solid transparent;
}

.toc__links a:hover { color: var(--text-primary); text-decoration: none; }
.toc__links a.is-active { color: var(--brand-strong); border-inline-start-color: var(--brand); font-weight: 600; }

/* ---------- Course overview (optional `overview` on a curriculum tree) ---------- */

.course-overview { margin-bottom: var(--space-8); display: flex; flex-direction: column; gap: var(--space-5); }
.course-overview__facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--space-3); margin: 0; }
.course-overview__facts > div { padding: var(--space-3) var(--space-4); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); background: var(--bg-surface); }
.course-overview__facts dt { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-secondary); }
.course-overview__facts dd { margin: var(--space-1) 0 0; font-weight: 600; }
.course-overview__description { font-size: var(--text-lg); color: var(--text-secondary); max-width: 75ch; }
.course-overview__stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: var(--space-3); }
.course-overview__stat { display: flex; flex-direction: column; align-items: center; gap: var(--space-1); padding: var(--space-4) var(--space-2); border-radius: var(--radius-md); background: var(--bg-surface-alt); text-align: center; }
.course-overview__stat strong { font-size: var(--text-2xl); color: var(--brand-strong); }
.course-overview__stat span { font-size: var(--text-xs); color: var(--text-secondary); }
.course-overview__grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: var(--space-4); }
.course-overview__grid .card { padding: var(--space-5); }
.course-overview__grid h3, .course-overview__skills h3 { font-size: var(--text-base); margin: 0 0 var(--space-3); }
.course-overview__grid ul { margin: 0; padding-inline-start: var(--space-5); display: flex; flex-direction: column; gap: var(--space-2); font-size: var(--text-sm); }

.course-module__heading { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.course-module__heading > span:first-child { color: var(--brand); }
.course-module__heading .badge { font-size: var(--text-xs); font-family: var(--font-mono); }
.example-card.is-done { border-color: color-mix(in srgb, var(--accent-success) 45%, var(--border-subtle)); }
.example-card__done { color: var(--accent-success); font-weight: 700; margin-inline-start: var(--space-1); }

/* ---------- Answer block (typed answer, checked client-side) ---------- */

.answer-check { border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); padding: var(--space-5); background: var(--bg-surface); margin: var(--space-5) 0; }
.answer-check__question { font-weight: 700; margin-bottom: var(--space-3); }
.answer-check__row { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.answer-check__input {
  flex: 1 1 220px; min-width: 0; padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--bg-surface); color: var(--text-primary); font-size: var(--text-sm);
}
.answer-check__input:focus-visible { outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--border-focus) 25%, transparent); }
.answer-check.is-correct .answer-check__input { border-color: var(--accent-success); }
.answer-check.is-incorrect .answer-check__input { border-color: var(--accent-danger); }
.answer-check__status { margin-top: var(--space-3); font-size: var(--text-sm); font-weight: 600; }
.answer-check.is-correct .answer-check__status { color: var(--accent-success); }
.answer-check.is-incorrect .answer-check__status { color: var(--accent-danger); }
.answer-check__explanation { margin-top: var(--space-2); font-size: var(--text-sm); display: none; }
.answer-check.is-correct .answer-check__explanation, .answer-check.is-revealed .answer-check__explanation { display: block; }

/* ---------- Reveal block (model answers hidden until asked for) ---------- */

.reveal { border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); margin: var(--space-5) 0; background: var(--bg-surface); }
.reveal > summary { cursor: pointer; padding: var(--space-3) var(--space-5); font-weight: 600; color: var(--brand-strong); }
.reveal > summary:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; border-radius: var(--radius-lg); }
.reveal[open] > summary { border-bottom: 1px dashed var(--border-subtle); }
.reveal__body { padding: var(--space-2) var(--space-5) var(--space-4); }

/* ---------- Toast (assets/js/components/toast.js) ---------- */

.toast-region {
  position: fixed; inset-block-end: var(--space-5); inset-inline-end: var(--space-5);
  display: flex; flex-direction: column; gap: var(--space-2); z-index: 1000;
  max-width: min(420px, calc(100vw - 2 * var(--space-5))); pointer-events: none;
}
.toast {
  pointer-events: auto; padding: var(--space-3) var(--space-4); border-radius: var(--radius-md);
  background: var(--bg-surface); color: var(--text-primary); border: 1px solid var(--border-subtle);
  border-inline-start: 4px solid var(--brand); box-shadow: var(--shadow-md, 0 6px 24px rgba(0, 0, 0, 0.15));
  font-size: var(--text-sm); animation: toast-in var(--duration-fast, 150ms) var(--ease, ease-out);
}
.toast--success { border-inline-start-color: var(--accent-success); }
.toast--error { border-inline-start-color: var(--accent-danger); }
.toast.is-leaving { opacity: 0; transition: opacity var(--duration-fast, 150ms) var(--ease, ease-out); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* Server-rendered text in both languages (app/views/i18n.php bi()): show the one for the page. */
html[lang="ar"] .i18n-en,
html:not([lang="ar"]) .i18n-ar { display: none; }
