/* Biz1 / MastroCRM-inspired curriculum viewer — RTL Hebrew */

:root {
  --primary: #11263c;
  --primary-light: #1a3550;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-gold: #ffae09;
  --bg: #f0f2f6;
  --surface: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 4px 24px rgba(17, 38, 60, 0.08);
  --radius: 12px;
  --sidebar-w: 280px;
  --topbar-h: 64px;
  --font: "Heebo", "Segoe UI", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
}

.app { min-height: 100vh; }

/* Top bar */
.topbar {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 100;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow);
}

.menu-toggle {
  display: none;
  background: transparent;
  border: 1px solid rgba(255,255,255,.25);
  color: #fff;
  font-size: 1.25rem;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  text-decoration: none;
  color: inherit;
}

.brand:hover .brand-title { color: var(--accent-gold); }

.brand-mark {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent-gold), #f59e0b);
  color: var(--primary);
  font-weight: 700;
  font-size: 1.1rem;
  border-radius: 10px;
}

.brand-title { display: block; font-size: 1rem; line-height: 1.2; }
.brand-sub { font-size: .75rem; opacity: .75; }

.search-wrap {
  flex: 1;
  max-width: 520px;
  margin-right: auto;
  position: relative;
}

.search-input {
  width: 100%;
  padding: 10px 16px 10px 40px;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: .95rem;
  background: rgba(255,255,255,.12);
  color: #fff;
  outline: none;
  transition: background .2s;
}

.search-input::placeholder { color: rgba(255,255,255,.55); }
.search-input:focus { background: rgba(255,255,255,.2); }

.search-hint {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: .7rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255,255,255,.15);
  color: rgba(255,255,255,.7);
  font-family: inherit;
}

/* Layout */
.layout {
  display: flex;
  padding-top: var(--topbar-h);
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  top: var(--topbar-h);
  right: 0;
  width: var(--sidebar-w);
  height: calc(100vh - var(--topbar-h));
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  z-index: 50;
  display: flex;
  flex-direction: column;
}

.sidebar-nav { flex: 1; padding: 12px 0; }

.part-group { margin-bottom: 8px; }

.part-label {
  padding: 8px 20px 4px;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text);
  text-decoration: none;
  font-size: .9rem;
  border-right: 3px solid transparent;
  transition: background .15s, border-color .15s;
}

.nav-link:hover { background: var(--bg); }
.nav-link.active {
  background: #eff6ff;
  border-right-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.nav-num {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: 8px;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.nav-link.active .nav-num {
  background: var(--accent);
  color: #fff;
}

.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  font-size: .8rem;
}

.muted-link { color: var(--text-muted); text-decoration: none; }
.muted-link:hover { color: var(--accent); }

.main {
  flex: 1;
  margin-right: var(--sidebar-w);
  padding: 28px 32px 48px;
  max-width: 100%;
}

.view.hidden { display: none; }

/* Home */
.hero {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 40px 36px;
  margin-bottom: 28px;
  box-shadow: var(--shadow);
}

.hero h1 { margin: 0 0 8px; font-size: 1.75rem; font-weight: 700; }
.hero p { margin: 0; opacity: .85; max-width: 540px; }

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  text-align: center;
}

.stat-card strong {
  display: block;
  font-size: 1.75rem;
  color: var(--accent);
  line-height: 1.2;
}

.stat-card span { font-size: .85rem; color: var(--text-muted); }

.parts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.part-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  border: 1px solid transparent;
  transition: border-color .2s, transform .15s;
}

.part-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.part-card h3 { margin: 0 0 6px; font-size: 1rem; color: var(--primary); }
.part-card p { margin: 0; font-size: .85rem; color: var(--text-muted); }

/* Lesson */
.lesson-header {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px 32px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
  border-right: 4px solid var(--accent);
}

.lesson-badge {
  display: inline-block;
  font-size: .75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: #eff6ff;
  color: var(--accent);
  margin-bottom: 8px;
}

.lesson-header h1 { margin: 0 0 8px; font-size: 1.5rem; color: var(--primary); }
.lesson-meta { font-size: .85rem; color: var(--text-muted); }

.lesson-body {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px 36px;
  box-shadow: var(--shadow);
  margin-bottom: 28px;
}

.lesson-gallery {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px 28px;
  box-shadow: var(--shadow);
}

.lesson-gallery h2 {
  margin: 0 0 16px;
  font-size: 1.1rem;
  color: var(--primary);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.gallery-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow .2s;
}

.gallery-item:hover { box-shadow: var(--shadow); }

.gallery-item img {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  display: block;
  background: var(--bg);
}

.gallery-item figcaption {
  padding: 10px 12px;
  font-size: .75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.gallery-item[data-missing="1"] img { opacity: .4; }

/* Prose */
.prose h2.lesson-heading { display: none; }

.prose h2 {
  font-size: 1.25rem;
  color: var(--primary);
  margin: 1.8em 0 .6em;
  padding-bottom: .3em;
  border-bottom: 2px solid var(--border);
}

.prose h3 { font-size: 1.1rem; color: var(--primary-light); margin: 1.4em 0 .5em; }
.prose h4 { font-size: 1rem; margin: 1.2em 0 .4em; }

.prose p { margin: .75em 0; }
.prose ul, .prose ol { padding-right: 1.4em; margin: .75em 0; }
.prose li { margin: .35em 0; }

.prose blockquote {
  margin: 1em 0;
  padding: 12px 16px;
  border-right: 4px solid var(--accent-gold);
  background: #fffbeb;
  border-radius: 0 8px 8px 0;
  font-size: .95rem;
}

.prose hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}

.prose :not(pre) > code {
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: .88em;
  direction: ltr;
  unicode-bidi: embed;
  color: #0f172a;
  font-family: ui-monospace, Consolas, "Courier New", monospace;
}

.prose pre.code-block {
  background: #0f172a;
  color: #e2e8f0;
  padding: 16px 20px;
  border-radius: 10px;
  overflow-x: auto;
  direction: ltr;
  text-align: left;
  font-size: 0.8125rem;
  line-height: 1.55;
  font-family: ui-monospace, Consolas, "Courier New", monospace;
  border: 1px solid #334155;
  margin: 1em 0;
}

.prose pre.code-block code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
  font-family: inherit;
  color: inherit;
  white-space: pre;
  display: block;
  direction: ltr;
  text-align: left;
  unicode-bidi: plaintext;
}

.table-wrap {
  overflow-x: auto;
  margin: 1em 0;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}

.prose th, .prose td {
  padding: 10px 14px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}

.prose th {
  background: var(--bg);
  font-weight: 600;
  color: var(--primary);
}

.prose tr:last-child td { border-bottom: none; }

.prose code.img-ref {
  font-size: .82rem;
  color: var(--accent);
  background: #eff6ff;
}

.lesson-figure {
  margin: 1.5em 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.lesson-figure img {
  width: 100%;
  height: auto;
  display: block;
  cursor: zoom-in;
}

.lesson-figure figcaption {
  padding: 12px 16px;
  background: var(--bg);
  font-size: .85rem;
  color: var(--text-muted);
}

.img-nav {
  margin-top: 6px;
  font-size: .8rem;
  color: var(--accent);
}

.img-what {
  margin-top: 4px;
  font-size: .82rem;
  line-height: 1.5;
}

.gallery-item figcaption .img-nav,
.gallery-item figcaption .img-what {
  margin-top: 4px;
  font-weight: 400;
}

.lesson-figure[data-missing="1"]::after {
  content: "תמונה חסרה";
  display: block;
  padding: 8px;
  text-align: center;
  font-size: .8rem;
  color: #dc2626;
  background: #fef2f2;
}

/* Search results */
.search-view h2 { margin: 0 0 20px; color: var(--primary); }

.search-results { display: flex; flex-direction: column; gap: 12px; }

.search-hit {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  border: 1px solid transparent;
  transition: border-color .15s;
}

.search-hit:hover { border-color: var(--accent); }

.search-hit strong { color: var(--accent); }
.search-hit .snippet { font-size: .9rem; color: var(--text-muted); margin-top: 6px; }

.search-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(17, 38, 60, .92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.lightbox.hidden { display: none; }

.lightbox img {
  max-width: 100%;
  max-height: 90vh;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0,0,0,.4);
}

.lightbox-close {
  position: absolute;
  top: 20px;
  left: 20px;
  background: rgba(255,255,255,.15);
  border: none;
  color: #fff;
  font-size: 2rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  cursor: pointer;
  line-height: 1;
}

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 40;
}

.overlay.open { display: block; }

/* Responsive */
@media (max-width: 900px) {
  .menu-toggle { display: block; }

  .sidebar {
    transform: translateX(100%);
    transition: transform .25s ease;
  }

  .sidebar.open { transform: translateX(0); }

  .main { margin-right: 0; padding: 20px 16px 40px; }

  .lesson-body { padding: 20px 18px; }
  .hero { padding: 28px 22px; }
  .search-wrap { max-width: none; }
  .brand-sub { display: none; }
}

@media (max-width: 480px) {
  .topbar { padding: 0 12px; gap: 10px; }
  .search-hint { display: none; }
}

.hidden { display: none !important; }

mark {
  background: #fef08a;
  padding: 0 2px;
  border-radius: 2px;
}

.locale-switch {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.25);
  color: #fff;
  text-decoration: none;
  font-size: .85rem;
  white-space: nowrap;
}

.locale-switch:hover {
  background: rgba(255,255,255,.12);
  color: var(--accent-gold);
}

.locale-picker {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.locale-picker-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 40px 48px;
  box-shadow: var(--shadow);
  text-align: center;
  max-width: 420px;
}

.locale-picker-card h1 {
  margin: 0 0 8px;
  color: var(--primary);
}

.locale-picker-links {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 24px;
}

.locale-picker-links .btn {
  display: inline-block;
  padding: 12px 24px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
}

.locale-picker-links .btn:hover {
  background: var(--accent-hover);
}

html[dir="ltr"] {
  --font: "Inter", "Segoe UI", Arial, sans-serif;
}

html[dir="ltr"] .search-wrap {
  margin-right: 0;
  margin-left: auto;
}

html[dir="ltr"] .search-hint {
  left: auto;
  right: 12px;
}

html[dir="ltr"] .search-input {
  padding: 10px 40px 10px 16px;
}

html[dir="ltr"] .sidebar {
  right: auto;
  left: 0;
  border-left: none;
  border-right: 1px solid var(--border);
}

html[dir="ltr"] .main {
  margin-right: 0;
  margin-left: var(--sidebar-w);
}

html[dir="ltr"] .nav-link {
  border-right: none;
  border-left: 3px solid transparent;
}

html[dir="ltr"] .nav-link.active {
  border-left-color: var(--accent);
  border-right-color: transparent;
}

html[dir="rtl"]:not([lang="he"]) {
  --font: "Noto Sans Arabic", "Segoe UI", Arial, sans-serif;
}

.locale-switchers {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.locale-switchers .locale-switch {
  padding: 6px 12px;
  font-size: .8rem;
}

@media (max-width: 900px) {
  html[dir="ltr"] .sidebar {
    transform: translateX(-100%);
  }

  html[dir="ltr"] .sidebar.open {
    transform: translateX(0);
  }

  html[dir="ltr"] .main {
    margin-left: 0;
  }
}
