/* ==========================================================================
   Telkini v144 — أقسام نصوص Lesen: الشريط، القسم المخصص، ومحرر المشرف
   ========================================================================== */
:root {
  --tks-t1: #f59e0b; --tks-t2: #0ea5e9; --tks-t3: #6366f1; --tks-s1: #8b5cf6; --tks-s2: #ec4899; --tks-custom: #10b981;
  --tks-blue-a: #7cb4ff; --tks-blue-b: #3b82f6;
  --tks-ink: #0f172a; --tks-muted: #64748b; --tks-line: #e2e8f0; --tks-soft: #f8fafc; --tks-card: #fff;
}
.dark { --tks-ink: #f1f5f9; --tks-muted: #94a3b8; --tks-line: #334155; --tks-soft: #0b1220; --tks-card: #0f172a; }

/* الأقسام المخفية عن الطالب */
.tk-sec-off, .ex-pill button.tk-sec-off, [data-ex-pill] button.tk-sec-off, .ex-header > [data-ex-pill] button.tk-sec-off { display: none !important; }

/* أزرار الأقسام المخصصة في الشريط العلوي (نفس شكل أزرار الأجزاء) */
.ex-pill .tk-sec-lbl { display: block; max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 767px) { .ex-pill .tk-sec-lbl { max-width: 100%; } }

/* زر «التالي» (يختفي فوراً مع الزر الأصلي حين تخفيه أدوات التعديل الموجودة) */
.tk-p-hide + .tk-sec-next, .tk-t1-hide + .tk-sec-next { display: none !important; }
.tk-sec-next { gap: .5rem; }
.tk-sec-next svg { flex-shrink: 0; }

/* زر المشرف «أقسام النص» */
.tk-sec-admin-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 9999px;
  border: 1px solid #bfdbfe; background: #eff6ff; color: #1d4ed8; font: 700 12px/1 'Cairo', 'Alexandria', sans-serif;
  cursor: pointer; white-space: nowrap; transition: background .2s, border-color .2s, transform .15s;
}
.tk-sec-admin-btn:hover { background: #dbeafe; border-color: #93c5fd; }
.tk-sec-admin-btn:active { transform: scale(.97); }
.dark .tk-sec-admin-btn { background: #172554; border-color: #1e3a8a; color: #93c5fd; }
@media (max-width: 767px) { .tk-sec-admin-btn span { display: none; } .tk-sec-admin-btn { width: 32px; padding: 0; justify-content: center; } }

/* البطاقات في قائمة Lesen */
.topic-card { position: relative; }
.tk-sec-chip {
  font: 700 10.5px/1 'Cairo', 'Inter', sans-serif; color: #64748b; background: #f1f5f9; border: 1px solid #e2e8f0;
  padding: 3px 7px; border-radius: 6px; white-space: nowrap;
}
.dark .tk-sec-chip { color: #94a3b8; background: #1e293b; border-color: #334155; }
.tk-sec-card-btn {
  position: absolute; bottom: 10px; right: 34px; width: 26px; height: 26px; border-radius: 8px; display: inline-flex;
  align-items: center; justify-content: center; color: #2563eb; background: #eff6ff; border: 1px solid #bfdbfe;
  opacity: 0; transform: translateY(2px); transition: opacity .2s, transform .2s, background .2s; cursor: pointer; z-index: 2;
}
.topic-card:hover .tk-sec-card-btn, .tk-sec-card-btn:focus-visible { opacity: 1; transform: none; }
@media (hover: none) { .tk-sec-card-btn { opacity: 1; transform: none; } }
.tk-sec-card-btn:hover { background: #dbeafe; }
.dark .tk-sec-card-btn { background: #172554; border-color: #1e3a8a; color: #93c5fd; }

/* ---------------- شاشة القسم المخصص ---------------- */
html.tk-sec-lock, html.tk-sec-lock-ed { overflow: hidden; }
.tk-sec-view {
  position: fixed; inset: 0; z-index: 60; display: none; flex-direction: column; background: #fafbfd; direction: ltr;
  opacity: 0; transition: opacity .2s ease;
}
.dark .tk-sec-view { background: #070b14; }
.tk-sec-view.is-open { display: flex; opacity: 1; animation: tkSecIn .28s cubic-bezier(.22,1,.36,1); }
@keyframes tkSecIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.tk-sec-vhead {
  position: relative; z-index: 2; background: rgba(255,255,255,.95); backdrop-filter: blur(10px); border-bottom: 1px solid rgba(226,232,240,.8);
  padding: 10px 16px; box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.dark .tk-sec-vhead { background: rgba(15,23,42,.9); border-color: #1e293b; }
.tk-sec-vhead-start { display: flex; align-items: center; gap: 12px; min-width: 0; }
.tk-sec-vhead-end { display: flex; align-items: center; gap: 8px; }
.tk-sec-vback {
  width: 36px; height: 36px; flex-shrink: 0; border-radius: 12px; border: 1px solid var(--tks-line); display: inline-flex;
  align-items: center; justify-content: center; color: var(--tks-muted); background: transparent; cursor: pointer;
}
.tk-sec-vback:hover { background: #f1f5f9; }
.dark .tk-sec-vback:hover { background: #1e293b; }
.tk-sec-vtitle { min-width: 0; text-align: left; }
.tk-sec-vtitle b { display: block; font: 900 14px/1.3 'Inter', 'Cairo', sans-serif; color: var(--tks-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tk-sec-vtitle small { display: block; font: 700 10px/1.4 'Inter', sans-serif; color: #94a3b8; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tk-sec-vbody { flex: 1; overflow-y: auto; padding: 32px 20px 120px; }
.tk-sec-vinner { max-width: 820px; margin: 0 auto; }
.tk-sec-vh1 { text-align: center; font: 700 clamp(28px, 5vw, 44px)/1.15 'Inter', 'Cairo', sans-serif; color: #1e293b; letter-spacing: -.02em; margin: 6px 0 0; }
.dark .tk-sec-vh1 { color: #fff; }
.tk-sec-vsub { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 12px 0 28px; }
.tk-sec-vsub span { width: 48px; height: 1px; background: var(--tks-line); }
.tk-sec-vsub p { margin: 0; font: 700 10px/1 'Inter', 'Cairo', sans-serif; color: #94a3b8; letter-spacing: .18em; text-transform: uppercase; }
.tk-sec-vtools { display: flex; justify-content: flex-end; gap: 8px; margin-bottom: 12px; }
.tk-sec-vtools:empty { display: none; }
.tk-sec-chipbtn {
  font: 700 12px/1 'Cairo', sans-serif; padding: 8px 14px; border-radius: 9999px; border: 1px solid var(--tks-line);
  background: var(--tks-card); color: var(--tks-muted); cursor: pointer; transition: all .2s;
}
.tk-sec-chipbtn.is-on, .tk-sec-chipbtn:hover { border-color: #93c5fd; color: #1d4ed8; background: #eff6ff; }
.dark .tk-sec-chipbtn.is-on, .dark .tk-sec-chipbtn:hover { background: #172554; color: #93c5fd; border-color: #1e3a8a; }
.tk-sec-vcard {
  background: var(--tks-card); border: 2px solid #e5e7eb; border-radius: 26px; padding: clamp(20px, 4vw, 32px);
  box-shadow: 0 10px 15px -3px rgba(0,0,0,.06), 0 4px 6px -4px rgba(0,0,0,.06);
}
.dark .tk-sec-vcard { border-color: #1f2937; }
.tk-sec-de p { font: 400 15px/1.85 'Inter', 'Open Sans', 'Cairo', sans-serif; color: #334155; margin: 0 0 1em; text-align: start; }
.dark .tk-sec-de p { color: #cbd5e1; }
.tk-sec-ar { margin-top: 18px; padding-top: 18px; border-top: 1px dashed var(--tks-line); }
.tk-sec-de + .tk-sec-ar { margin-top: 6px; }
.tk-sec-ar p { font: 500 14px/2 'Cairo', sans-serif; color: #475569; margin: 0 0 .8em; text-align: right; }
.dark .tk-sec-ar p { color: #94a3b8; }
.tk-sec-empty, .tk-sec-locked { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 24px 8px; color: var(--tks-muted); font-family: 'Cairo', sans-serif; }
.tk-sec-empty b, .tk-sec-locked b { color: var(--tks-ink); font-size: 15px; }
.tk-sec-empty p, .tk-sec-locked p { margin: 0 0 6px; font-size: 13px; }
.tk-sec-empty svg, .tk-sec-locked svg { width: 28px; height: 28px; color: #94a3b8; }
.tk-sec-locked svg { color: #f59e0b; }
.tk-sec-vfoot {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 3; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--tks-card); border-top: 1px solid var(--tks-line);
}
.tk-sec-vfoot-txt { font: 700 12px/1 'Inter', sans-serif; color: #94a3b8; }

/* ---------------- أزرار عامة ---------------- */
.tk-sec-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 20px; border-radius: 12px;
  font: 700 13.5px/1 'Cairo', 'Inter', sans-serif; cursor: pointer; border: 1px solid transparent; transition: transform .15s, box-shadow .2s, background .2s, opacity .2s;
}
.tk-sec-btn:active { transform: scale(.97); }
.tk-sec-btn[disabled] { opacity: .6; cursor: progress; }
.tk-sec-btn-primary {
  color: #fff; background: linear-gradient(90deg, var(--tks-blue-a), var(--tks-blue-b));
  box-shadow: 0 6px 16px -6px rgba(59,130,246,.65);
}
.tk-sec-btn-primary:hover { box-shadow: 0 8px 20px -6px rgba(59,130,246,.8); }
.tk-sec-btn-ghost { color: #475569; background: #fff; border-color: var(--tks-line); }
.tk-sec-btn-ghost:hover { background: #f8fafc; }
.dark .tk-sec-btn-ghost { color: #cbd5e1; background: #0f172a; }
.tk-sec-btn-danger { color: #fff; background: #ef4444; }
.tk-sec-btn-danger:hover { background: #dc2626; }

/* ---------------- محرر المشرف ---------------- */
.tk-sec-modal {
  position: fixed; inset: 0; z-index: 100000; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(15,23,42,.45); backdrop-filter: blur(4px); opacity: 0; transition: opacity .18s ease; font-family: 'Cairo', 'Alexandria', sans-serif;
}
.tk-sec-modal.is-open { opacity: 1; }
.tk-sec-ed {
  width: min(640px, 100%); max-height: min(88vh, 820px); display: flex; flex-direction: column; background: var(--tks-card);
  border-radius: 22px; border: 1px solid var(--tks-line); box-shadow: 0 25px 50px -12px rgba(0,0,0,.25); outline: none;
  transform: translateY(8px) scale(.985); transition: transform .22s cubic-bezier(.22,1,.36,1); overflow: hidden;
}
.tk-sec-modal.is-open .tk-sec-ed { transform: none; }
.tk-sec-ed-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; background: linear-gradient(180deg, #eff6ff, transparent); border-bottom: 1px solid var(--tks-line); }
.dark .tk-sec-ed-head { background: linear-gradient(180deg, #172554, transparent); }
.tk-sec-ed-ic { width: 38px; height: 38px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; color: #fff; background: linear-gradient(135deg, var(--tks-blue-a), var(--tks-blue-b)); flex-shrink: 0; }
.tk-sec-ed-ic svg { width: 18px; height: 18px; }
.tk-sec-ed-ht { flex: 1; min-width: 0; }
.tk-sec-ed-ht b { display: block; font-size: 16px; color: var(--tks-ink); }
.tk-sec-ed-ht small { display: block; font: 600 12px/1.4 'Inter', 'Cairo', sans-serif; color: var(--tks-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tk-sec-x { width: 36px; height: 36px; border-radius: 10px; border: 0; background: transparent; color: var(--tks-muted); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.tk-sec-x:hover { background: #f1f5f9; color: var(--tks-ink); }
.dark .tk-sec-x:hover { background: #1e293b; }

/* زر التبديل (نفس شكل «الأساسي / المعدل») */
.tk-sec-ed-mode { padding: 14px 18px 4px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.tk-sec-seg { display: inline-flex; padding: 4px; gap: 2px; border-radius: 16px; background: #fff; border: 1px solid #e5e7eb; box-shadow: 0 1px 3px rgba(0,0,0,.05); }
.dark .tk-sec-seg { background: #0b1220; border-color: #334155; }
.tk-sec-seg button {
  min-width: 112px; height: 38px; padding: 0 18px; border: 0; border-radius: 12px; background: transparent; color: #9ca3af;
  font: 700 13.5px/1 'Cairo', sans-serif; cursor: pointer; transition: color .2s, background .25s, box-shadow .25s;
}
.tk-sec-seg button:hover { color: #64748b; }
.tk-sec-seg button.is-on { color: #fff; background: linear-gradient(90deg, var(--tks-blue-a), var(--tks-blue-b)); box-shadow: 0 4px 12px -4px rgba(59,130,246,.6); }
.tk-sec-ed-hint { margin: 0; font-size: 12px; color: var(--tks-muted); text-align: center; }

.tk-sec-ed-body { flex: 1; overflow-y: auto; padding: 10px 18px 16px; overscroll-behavior: contain; }
.tk-sec-ed-empty { text-align: center; padding: 18px; color: var(--tks-muted); font-size: 13px; border: 1px dashed var(--tks-line); border-radius: 14px; margin: 8px 0; }
.tk-sec-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.tk-sec-row {
  --c: var(--tks-custom); position: relative; border: 1px solid var(--tks-line); border-radius: 14px; background: var(--tks-card);
  transition: transform .18s cubic-bezier(.22,1,.36,1), box-shadow .2s, border-color .2s;
}
.tk-sec-row::before { content: ''; position: absolute; inset-block: 10px; inset-inline-start: 0; width: 3px; border-radius: 3px; background: var(--c); }
.tk-sec-row:hover { border-color: color-mix(in srgb, var(--c) 40%, var(--tks-line)); }
.tk-sec-row.is-drag { z-index: 5; box-shadow: 0 12px 28px -8px rgba(15,23,42,.3); transition: box-shadow .2s; border-color: var(--c); }
.tk-sec-t-t1 { --c: var(--tks-t1); } .tk-sec-t-t2 { --c: var(--tks-t2); } .tk-sec-t-t3 { --c: var(--tks-t3); }
.tk-sec-t-s1 { --c: var(--tks-s1); } .tk-sec-t-s2 { --c: var(--tks-s2); } .tk-sec-t-custom { --c: var(--tks-custom); }
.tk-sec-row-main { display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 8px; }
.tk-sec-grip { color: #cbd5e1; cursor: grab; touch-action: none; display: inline-flex; padding: 4px 2px; border-radius: 6px; }
.tk-sec-grip:hover { color: #64748b; background: #f1f5f9; }
.dark .tk-sec-grip:hover { background: #1e293b; }
.tk-sec-row.is-drag .tk-sec-grip { cursor: grabbing; }
.tk-sec-num { width: 22px; height: 22px; flex-shrink: 0; border-radius: 9999px; display: inline-flex; align-items: center; justify-content: center; font: 800 11px/1 'Inter', sans-serif; color: var(--c); background: color-mix(in srgb, var(--c) 12%, transparent); }
.tk-sec-type { display: inline-flex; align-items: center; gap: 5px; flex-shrink: 0; font: 700 11px/1 'Inter', 'Cairo', sans-serif; color: var(--c); padding: 5px 8px; border-radius: 8px; background: color-mix(in srgb, var(--c) 10%, transparent); }
.tk-sec-type svg { width: 13px; height: 13px; }
.tk-sec-name, .tk-sec-prev-name {
  flex: 1; min-width: 0; height: 36px; padding: 0 10px; border-radius: 10px; border: 1px solid transparent; background: var(--tks-soft);
  font: 700 13.5px/1 'Inter', 'Cairo', sans-serif; color: var(--tks-ink); outline: none; transition: border-color .2s, box-shadow .2s, background .2s;
}
.tk-sec-prev-name { display: flex; align-items: center; background: transparent; color: var(--tks-muted); }
.tk-sec-name:hover { border-color: var(--tks-line); }
.tk-sec-name:focus { border-color: #93c5fd; background: var(--tks-card); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.tk-sec-acts { display: inline-flex; gap: 2px; flex-shrink: 0; }
.tk-sec-ib { width: 32px; height: 32px; border-radius: 9px; border: 0; background: transparent; color: #94a3b8; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; transition: background .15s, color .15s; }
.tk-sec-ib:hover:not([disabled]) { background: #f1f5f9; color: #334155; }
.dark .tk-sec-ib:hover:not([disabled]) { background: #1e293b; color: #e2e8f0; }
.tk-sec-ib[disabled] { opacity: .3; cursor: default; }
.tk-sec-ib.is-on { color: #2563eb; background: #eff6ff; }
.tk-sec-ib-del:hover:not([disabled]) { color: #dc2626 !important; background: #fef2f2 !important; }
.tk-sec-confirm { margin: 0 10px 10px; padding: 12px; border-radius: 12px; background: #fef2f2; border: 1px solid #fecaca; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; animation: tkSecIn .2s ease; }
.dark .tk-sec-confirm { background: #2a0f12; border-color: #7f1d1d; }
.tk-sec-confirm p { margin: 0; font-size: 12.5px; line-height: 1.7; color: #7f1d1d; flex: 1 1 260px; }
.dark .tk-sec-confirm p { color: #fecaca; }
.tk-sec-confirm div { display: flex; gap: 6px; }
.tk-sec-confirm .tk-sec-btn { height: 34px; padding: 0 14px; font-size: 12.5px; }
.tk-sec-custom-ed { padding: 0 12px 12px; display: grid; gap: 10px; }
.tk-sec-custom-ed label { display: grid; gap: 5px; font-size: 12px; font-weight: 700; color: var(--tks-muted); }
.tk-sec-custom-ed textarea {
  width: 100%; resize: vertical; min-height: 84px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--tks-line); background: var(--tks-soft);
  font: 400 13.5px/1.75 'Inter', 'Cairo', sans-serif; color: var(--tks-ink); outline: none; box-sizing: border-box;
}
.tk-sec-custom-ed textarea:focus { border-color: #93c5fd; background: var(--tks-card); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }

.tk-sec-add { position: relative; margin-top: 10px; }
.tk-sec-addbtn {
  width: 100%; height: 46px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 14px;
  border: 1.5px dashed #93c5fd; background: #f8fbff; color: #2563eb; font: 800 14px/1 'Cairo', sans-serif; cursor: pointer; transition: background .2s, border-color .2s;
}
.tk-sec-addbtn:hover { background: #eff6ff; border-color: #3b82f6; }
.dark .tk-sec-addbtn { background: #0b1530; border-color: #1e40af; color: #93c5fd; }
.tk-sec-menu {
  margin-top: 6px; padding: 6px; border-radius: 14px; background: var(--tks-card); border: 1px solid var(--tks-line);
  box-shadow: 0 12px 30px -10px rgba(15,23,42,.25); display: grid; grid-template-columns: 1fr 1fr; gap: 4px; animation: tkSecIn .18s ease;
}
@media (max-width: 520px) { .tk-sec-menu { grid-template-columns: 1fr; } }
.tk-sec-mi {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 10px; border: 0; background: transparent; text-align: start;
  font: 700 13px/1.2 'Inter', 'Cairo', sans-serif; color: var(--tks-ink); cursor: pointer; transition: background .15s;
}
.tk-sec-mi svg { color: var(--c); flex-shrink: 0; }
.tk-sec-mi:hover:not([disabled]) { background: color-mix(in srgb, var(--c) 10%, transparent); }
.tk-sec-mi[disabled] { opacity: .45; cursor: not-allowed; }
.tk-sec-mi em { margin-inline-start: auto; font: 600 10.5px/1.2 'Cairo', sans-serif; font-style: normal; color: var(--tks-muted); }
.tk-sec-t-custom.tk-sec-mi { grid-column: 1 / -1; border-top: 1px solid var(--tks-line); border-radius: 0 0 10px 10px; }
.tk-sec-ed-note { margin: 12px 2px 0; font-size: 11.5px; line-height: 1.7; color: var(--tks-muted); }
.tk-sec-list.is-preview .tk-sec-row { background: var(--tks-soft); }

.tk-sec-ed-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--tks-line); background: var(--tks-card); }
.tk-sec-ed-foot > div { display: flex; gap: 8px; }
.tk-sec-ed-status { font-size: 12px; font-weight: 700; color: #d97706; }

@media (max-width: 560px) {
  .tk-sec-modal { padding: 0; align-items: flex-end; }
  .tk-sec-ed { width: 100%; max-height: 92vh; border-radius: 22px 22px 0 0; }
  .tk-sec-row-main { flex-wrap: wrap; }
  .tk-sec-type span { display: none; }
  .tk-sec-name { flex-basis: calc(100% - 120px); }
  .tk-sec-acts { width: 100%; justify-content: flex-end; border-top: 1px solid var(--tks-line); padding-top: 6px; }
  .tk-sec-seg button { min-width: 0; padding: 0 14px; }
  .tk-sec-vbody { padding: 20px 14px 110px; }
}
@media (prefers-reduced-motion: reduce) {
  .tk-sec-view.is-open, .tk-sec-confirm, .tk-sec-menu { animation: none; }
  .tk-sec-row, .tk-sec-ed { transition: none; }
}
