/* ==========================================================================
   استوديو المعلم الذكي
   ========================================================================== */

body.studio-body {
  min-height: 100vh;
  background:
    radial-gradient(900px 500px at 100% 0%, rgba(59, 108, 255, 0.09), transparent 60%),
    radial-gradient(800px 500px at 0% 100%, rgba(17, 181, 164, 0.1), transparent 60%),
    var(--bg);
}

/* ---------- الشريط العلوي ---------- */

.studio-top {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(5, 11, 31, 0.92);
  backdrop-filter: blur(14px);
  color: #fff;
}

.studio-top .bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  height: 70px;
  width: min(1500px, 100% - 32px);
  margin-inline: auto;
}

.studio-top .brand {
  font-size: 1.1rem;
}

.studio-top .brand-mark {
  width: 38px;
  height: 38px;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.stepper li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stepper button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 6px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: rgba(255, 255, 255, 0.55);
  font-weight: 700;
  transition:
    color 0.3s,
    background 0.3s;
}

.stepper button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
}

.stepper button:disabled {
  cursor: default;
}

.stepper .dot {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  font-size: 0.9rem;
  transition:
    background 0.4s var(--ease),
    border-color 0.4s,
    transform 0.4s var(--ease);
}

.stepper .dot svg {
  width: 16px;
  height: 16px;
  stroke-width: 3;
  display: none;
}

.stepper li.active button {
  color: #fff;
}

.stepper li.active .dot {
  border-color: transparent;
  background: var(--grad);
  transform: scale(1.1);
  box-shadow: 0 0 0 5px rgba(59, 108, 255, 0.25);
}

.stepper li.done button {
  color: rgba(255, 255, 255, 0.85);
}

.stepper li.done .dot {
  background: var(--teal);
  border-color: var(--teal);
}

.stepper li.done .dot span {
  display: none;
}

.stepper li.done .dot svg {
  display: block;
}

.stepper .sep {
  width: 34px;
  height: 2px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
  position: relative;
}

.stepper .sep::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--teal);
  transform: scaleX(0);
  transform-origin: right;
  transition: transform 0.6s var(--ease);
}

.stepper li.done .sep::after {
  transform: scaleX(1);
}

.top-actions {
  display: flex;
  gap: 10px;
}

.top-actions .btn-ghost {
  padding: 9px 16px;
  font-size: 0.92rem;
}

.count-pill {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--grad);
  font-size: 0.75rem;
}

/* ---------- التخطيط الرئيسي ---------- */

.studio {
  display: grid;
  grid-template-columns: clamp(340px, 30vw, 460px) minmax(0, 1fr);
  gap: 24px;
  width: min(1500px, 100% - 32px);
  margin: 24px auto;
  align-items: start;
}

.panel {
  position: sticky;
  top: 94px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 118px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 26px 26px 10px;
  scrollbar-width: thin;
}

.panel-foot {
  display: flex;
  gap: 10px;
  padding: 16px 26px 20px;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #fafbfe);
}

.panel-foot .btn {
  flex: 1;
}

.panel-foot .btn-back {
  flex: 0 0 auto;
}

.step {
  display: none;
}

.step.active {
  display: block;
  animation: stepIn 0.55s var(--ease) both;
}

.step.active.from-left {
  animation-name: stepInLeft;
}

@keyframes stepIn {
  from {
    opacity: 0;
    transform: translateX(-28px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes stepInLeft {
  from {
    opacity: 0;
    transform: translateX(28px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.step-head {
  margin-bottom: 22px;
}

.step-head .kicker {
  color: var(--blue);
  font-weight: 800;
  font-size: 0.85rem;
}

.step-head h2 {
  margin: 4px 0 4px;
  font-size: 1.55rem;
  font-weight: 900;
  line-height: 1.35;
}

.step-head p {
  margin: 0;
  color: var(--muted);
}

/* ---------- الحقول ---------- */

.field {
  margin-bottom: 18px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.field label,
.field .label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink-2);
}

.field .hint {
  font-weight: 500;
  color: var(--muted);
  font-size: 0.82rem;
}

.input,
.textarea,
.select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: #fbfcfe;
  outline: none;
  transition:
    border-color 0.25s,
    box-shadow 0.25s,
    background 0.25s;
}

.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--blue);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(59, 108, 255, 0.12);
}

.textarea {
  min-height: 92px;
  resize: vertical;
  line-height: 1.7;
}

.input-hero {
  position: relative;
}

.input-hero .icon {
  position: absolute;
  top: 50%;
  inset-inline-start: 16px;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  color: var(--blue);
  pointer-events: none;
}

.input-hero .input {
  padding: 16px 52px 16px 16px;
  font-size: 1.15rem;
  font-weight: 700;
  border-radius: 16px;
}

.field.invalid .input {
  border-color: var(--rose);
  animation: shake 0.45s;
}

@keyframes shake {
  20%,
  60% {
    transform: translateX(-6px);
  }
  40%,
  80% {
    transform: translateX(6px);
  }
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.suggestion {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink-2);
  transition:
    transform 0.3s var(--ease),
    border-color 0.3s,
    color 0.3s,
    background 0.3s;
  animation: popIn 0.5s var(--ease) both;
}

.suggestion:hover {
  transform: translateY(-2px);
  border-color: var(--blue);
  color: var(--blue);
}

.suggestion.on {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.7);
  }
}

/* أزرار مقسّمة واختيارات متعددة */

.segmented,
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.segmented button,
.chips button {
  position: relative;
  padding: 9px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: #fff;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--ink-2);
  transition:
    all 0.3s var(--ease);
}

.segmented button:hover,
.chips button:hover {
  border-color: rgba(59, 108, 255, 0.5);
}

.segmented button.on {
  color: #fff;
  border-color: transparent;
  background: var(--grad);
  box-shadow: 0 8px 18px -8px rgba(59, 108, 255, 0.7);
}

.chips button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chips button .icon {
  width: 16px;
  height: 16px;
  stroke-width: 3;
  display: none;
}

.chips button.on {
  color: var(--blue);
  border-color: var(--blue);
  background: rgba(59, 108, 255, 0.08);
}

.chips button.on .icon {
  display: block;
  animation: popIn 0.35s var(--ease);
}

/* شريط التمرير */

.range-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
}

.range-wrap output {
  min-width: 48px;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(59, 108, 255, 0.1);
  color: var(--blue);
  font-weight: 800;
  text-align: center;
}

input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 8px;
  border-radius: 8px;
  background: linear-gradient(to left, var(--blue) var(--p, 50%), var(--line) var(--p, 50%));
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid var(--blue);
  box-shadow: 0 4px 10px rgba(59, 108, 255, 0.4);
  cursor: grab;
  transition: transform 0.2s;
}

input[type="range"]::-webkit-slider-thumb:active {
  transform: scale(1.2);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid var(--blue);
}

/* مفتاح التشغيل */

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-weight: 700;
  color: var(--ink-2);
  padding-top: 10px;
}

.toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle .track {
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--line);
  transition: background 0.3s;
  flex-shrink: 0;
}

.toggle .track::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: transform 0.35s var(--ease);
}

.toggle input:checked + .track {
  background: var(--teal);
}

.toggle input:checked + .track::after {
  transform: translateX(-20px);
}

.toggle input:focus-visible + .track {
  box-shadow: 0 0 0 4px rgba(59, 108, 255, 0.2);
}

/* قسم قابل للطي */

.collapse {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fafbfe;
  margin-bottom: 18px;
  overflow: hidden;
}

.collapse summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  cursor: pointer;
  font-weight: 800;
  list-style: none;
}

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

.collapse summary .icon {
  color: var(--teal-600);
}

.collapse summary .chev {
  margin-inline-start: auto;
  transition: transform 0.3s var(--ease);
  transform: rotate(-90deg);
}

.collapse[open] summary .chev {
  transform: rotate(90deg);
}

.collapse .collapse-body {
  padding: 4px 16px 6px;
  animation: stepIn 0.4s var(--ease);
}

.logo-pick {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-preview {
  width: 54px;
  height: 54px;
  border-radius: 12px;
  border: 1.5px dashed var(--line);
  display: grid;
  place-items: center;
  background: #fff;
  overflow: hidden;
  color: var(--muted);
}

.logo-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* ---------- بطاقات اختيار الخدمة ---------- */

.service-tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.tile {
  --c1: #11b5a4;
  --c2: #3b6cff;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 18px 16px;
  border-radius: 18px;
  border: 1.5px solid var(--line);
  background: #fff;
  text-align: right;
  transition:
    transform 0.4s var(--ease),
    border-color 0.3s,
    box-shadow 0.4s var(--ease);
  overflow: hidden;
  isolation: isolate;
  animation: popIn 0.5s var(--ease) both;
}

.tile:hover {
  transform: translateY(-4px);
  border-color: color-mix(in srgb, var(--c2) 40%, transparent);
  box-shadow: var(--shadow);
}

.tile .t-icon {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--c1), var(--c2));
  transition: transform 0.5s var(--ease);
}

.tile .t-icon svg {
  width: 24px;
  height: 24px;
}

.tile:hover .t-icon {
  transform: rotate(-10deg) scale(1.08);
}

.tile strong {
  font-size: 1.05rem;
  font-weight: 800;
}

.tile small {
  color: var(--muted);
  line-height: 1.55;
  font-size: 0.83rem;
}

.tile .t-check {
  position: absolute;
  top: 12px;
  inset-inline-end: 12px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--c2);
  color: #fff;
  transform: scale(0);
  transition: transform 0.4s var(--ease);
}

.tile .t-check svg {
  width: 14px;
  height: 14px;
  stroke-width: 3;
}

.tile::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(135deg, color-mix(in srgb, var(--c1) 10%, transparent), color-mix(in srgb, var(--c2) 14%, transparent));
  opacity: 0;
  transition: opacity 0.4s;
}

.tile.on {
  border-color: var(--c2);
  box-shadow: 0 14px 30px -14px color-mix(in srgb, var(--c2) 70%, transparent);
}

.tile.on::before {
  opacity: 1;
}

.tile.on .t-check {
  transform: scale(1);
}

/* ملخص الاختيار */

.summary-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.summary-chips span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: #f1f4fa;
  font-weight: 700;
  font-size: 0.86rem;
  color: var(--ink-2);
}

.summary-chips .icon {
  width: 16px;
  height: 16px;
  color: var(--blue);
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 26px 0 16px;
  color: var(--muted);
  font-weight: 800;
  font-size: 0.88rem;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

/* منطقة رفع الملفات */

.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 20px;
  border: 2px dashed #cfd8ea;
  border-radius: 16px;
  background: #fafbfe;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition:
    border-color 0.3s,
    background 0.3s,
    transform 0.3s var(--ease);
}

.dropzone:hover,
.dropzone.drag {
  border-color: var(--blue);
  background: rgba(59, 108, 255, 0.05);
  transform: scale(1.01);
}

.dropzone .icon {
  width: 30px;
  height: 30px;
  color: var(--blue);
  transition: transform 0.4s var(--ease);
}

.dropzone:hover .icon {
  transform: translateY(-4px);
}

.dropzone strong {
  color: var(--ink);
}

.dropzone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: #f1f4fa;
  font-size: 0.88rem;
  font-weight: 600;
  animation: popIn 0.4s var(--ease);
}

.file-item .icon {
  color: var(--blue);
}

.file-item span {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  transition:
    background 0.25s,
    color 0.25s;
}

.icon-btn:hover {
  background: rgba(244, 63, 110, 0.1);
  color: var(--rose);
}

.notice {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  margin-bottom: 18px;
  background: #fff7e6;
  border: 1px solid #fde3a7;
  color: #8a5a00;
  font-size: 0.88rem;
  font-weight: 600;
}

.notice code {
  direction: ltr;
  display: inline-block;
  padding: 0 4px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.06);
}

/* ---------- منطقة العرض ---------- */

.stage {
  position: sticky;
  top: 94px;
  height: calc(100vh - 118px);
  border-radius: 24px;
  background:
    radial-gradient(circle at 1px 1px, rgba(11, 22, 48, 0.08) 1px, transparent 0) 0 0 / 22px 22px,
    #eef2f9;
  border: 1px solid var(--line);
  overflow: clip;
}

.stage-view {
  display: none;
}

.stage-view.active {
  display: flex;
  height: 100%;
  animation: fadeUp 0.6s var(--ease) both;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* حالة البداية */

.empty {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 40px 24px;
  text-align: center;
}

.empty-art {
  position: relative;
  width: 260px;
  height: 230px;
  margin-bottom: 26px;
}

.empty-art .sheet-a,
.empty-art .sheet-b {
  position: absolute;
  width: 150px;
  height: 196px;
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 18px 16px;
}

.empty-art .sheet-a {
  right: 20px;
  top: 6px;
  transform: rotate(8deg);
  animation: sheetFloat 6s ease-in-out infinite;
}

.empty-art .sheet-b {
  left: 22px;
  top: 22px;
  transform: rotate(-7deg);
  animation: sheetFloat 6s ease-in-out -3s infinite;
}

@keyframes sheetFloat {
  50% {
    translate: 0 -12px;
  }
}

.empty-art .ln {
  height: 8px;
  border-radius: 6px;
  background: #e9eef7;
  margin-bottom: 10px;
}

.empty-art .ln.s {
  width: 60%;
}

.empty-art .ln.g {
  background: var(--grad);
  opacity: 0.8;
  width: 75%;
}

.empty-art .spark {
  position: absolute;
  color: var(--amber);
  animation: twinkle 2.4s ease-in-out infinite;
}

.empty-art .spark svg {
  width: 28px;
  height: 28px;
}

.empty-art .spark.s1 {
  top: -6px;
  left: 40%;
}

.empty-art .spark.s2 {
  bottom: 10px;
  right: 0;
  animation-delay: -1.2s;
  color: var(--blue);
}

@keyframes twinkle {
  50% {
    transform: scale(0.6) rotate(20deg);
    opacity: 0.4;
  }
}

.empty h3 {
  margin: 0 0 8px;
  font-size: 1.5rem;
  font-weight: 900;
}

.empty p {
  margin: 0;
  max-width: 420px;
  color: var(--muted);
}

/* حالة التحميل */

.loading {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 40px 24px;
  text-align: center;
}

.orb {
  position: relative;
  width: 132px;
  height: 132px;
  margin-bottom: 28px;
}

.orb .ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: var(--blue);
  border-left-color: var(--teal);
  animation: spinSlow 1.6s linear infinite;
}

.orb .ring.r2 {
  inset: 14px;
  border-top-color: var(--violet);
  border-left-color: transparent;
  border-right-color: var(--blue);
  animation-duration: 2.4s;
  animation-direction: reverse;
}

.orb .ring.r3 {
  inset: 28px;
  border-top-color: var(--amber);
  border-left-color: transparent;
  animation-duration: 3.2s;
}

.orb .core {
  position: absolute;
  inset: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--grad);
  color: #fff;
  box-shadow: 0 0 40px rgba(59, 108, 255, 0.55);
  animation: corePulse 1.8s ease-in-out infinite;
}

.orb .core svg {
  width: 26px;
  height: 26px;
}

@keyframes corePulse {
  50% {
    transform: scale(1.12);
    box-shadow: 0 0 60px rgba(17, 181, 164, 0.6);
  }
}

.loading h3 {
  margin: 0 0 6px;
  font-size: 1.45rem;
  font-weight: 900;
}

.loading .stage-msg {
  margin: 0 0 22px;
  color: var(--muted);
  min-height: 1.7em;
  transition: opacity 0.3s;
}

.progress {
  position: relative;
  width: min(420px, 100%);
  height: 10px;
  border-radius: 10px;
  background: #dde4f1;
  overflow: hidden;
}

.progress span {
  position: absolute;
  inset-block: 0;
  right: 0;
  width: 0;
  border-radius: 10px;
  background: var(--grad);
  background-size: 200% 100%;
  animation: gradShift 2s linear infinite;
  transition: width 0.6s var(--ease);
}

.progress span::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent);
  animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
  from {
    transform: translateX(100%);
  }
  to {
    transform: translateX(-100%);
  }
}

.loading-meta {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
}

.load-steps {
  list-style: none;
  margin: 26px 0 0;
  padding: 0;
  display: grid;
  gap: 10px;
  text-align: right;
  width: min(360px, 100%);
}

.load-steps li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
  color: var(--muted);
  font-weight: 700;
  transition: all 0.4s var(--ease);
}

.load-steps .st {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.load-steps .st svg {
  width: 14px;
  height: 14px;
  stroke-width: 3;
  display: none;
}

.load-steps li.active {
  color: var(--ink);
  background: #fff;
  box-shadow: var(--shadow-sm);
  transform: scale(1.03);
}

.load-steps li.active .st {
  border-color: var(--blue);
  border-top-color: transparent;
  animation: spinSlow 0.9s linear infinite;
}

.load-steps li.done {
  color: var(--ink-2);
}

.load-steps li.done .st {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.load-steps li.done .st svg {
  display: block;
}

.tip {
  margin-top: 24px;
  max-width: 420px;
  font-size: 0.9rem;
  color: var(--muted);
  transition: opacity 0.4s;
}

.tip b {
  color: var(--blue);
}

/* حالة الخطأ */

.error-view {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 40px 24px;
  text-align: center;
}

.error-icon {
  width: 84px;
  height: 84px;
  border-radius: 26px;
  display: grid;
  place-items: center;
  background: rgba(244, 63, 110, 0.1);
  color: var(--rose);
  margin-bottom: 18px;
  animation: shake 0.6s;
}

.error-icon svg {
  width: 40px;
  height: 40px;
}

.error-view h3 {
  margin: 0 0 8px;
  font-size: 1.4rem;
  font-weight: 900;
}

.error-view p {
  max-width: 460px;
  color: var(--muted);
  margin: 0 0 22px;
}

/* النتيجة */

.result {
  flex-direction: column;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.toolbar .doc-name {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-inline-end: auto;
  min-width: 0;
}

.toolbar .doc-name .t-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  flex-shrink: 0;
}

.toolbar .doc-name strong {
  display: block;
  font-weight: 800;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toolbar .doc-name small {
  color: var(--muted);
  font-weight: 600;
}

.mode-switch {
  position: relative;
  display: inline-flex;
  padding: 4px;
  border-radius: 999px;
  background: #eef1f7;
}

.mode-switch button {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--muted);
  transition: color 0.3s;
}

.mode-switch button.on {
  color: #fff;
}

.mode-switch .pill {
  position: absolute;
  top: 4px;
  bottom: 4px;
  border-radius: 999px;
  background: var(--grad);
  transition:
    left 0.45s var(--ease),
    width 0.45s var(--ease);
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--ink-2);
  transition: all 0.3s var(--ease);
}

.tool-btn:hover {
  transform: translateY(-2px);
  border-color: var(--blue);
  color: var(--blue);
  box-shadow: var(--shadow-sm);
}

.tool-btn.on {
  background: #fff7e6;
  border-color: var(--amber);
  color: #8a5a00;
}

.tool-btn.primary {
  color: #fff;
  border-color: transparent;
  background: var(--grad);
}

.tool-btn.primary:hover {
  color: #fff;
  box-shadow: 0 10px 20px -10px rgba(59, 108, 255, 0.8);
}

.edit-hint {
  display: none;
  width: 100%;
  padding: 8px 12px;
  border-radius: 10px;
  background: #fff7e6;
  color: #8a5a00;
  font-weight: 600;
  font-size: 0.86rem;
}

.result.editing .edit-hint {
  display: block;
  animation: fadeUp 0.4s var(--ease);
}

.doc-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 30px 20px 50px;
}

.doc-wrap {
  width: 100%;
}

.doc-wrap .sheet {
  border-radius: 6px;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.06),
    0 22px 60px -18px rgba(11, 22, 48, 0.35);
}

/* الورقة مرنة على الشاشة فقط؛ الطباعة وWord يبقيان بمقاس A4 من doc.css.
   المحددات أعلى تخصيصًا لأن doc.css يُحمَّل بعد هذا الملف. */

@media screen {
  .doc-scroll {
    container: doc-view / inline-size;
  }

  .doc-wrap .doc .sheet {
    width: 100%;
    max-width: 210mm;
  }

  .doc-wrap .doc.landscape .sheet {
    width: 100%;
    max-width: 297mm;
  }
}

/* في المساحات الضيقة تُعاد صياغة المستند بدل تصغيره، ليبقى النص مقروءًا. */

@container doc-view (max-width: 820px) {
  .doc-wrap .doc .sheet,
  .doc-wrap .doc.landscape .sheet {
    padding-inline: 24px;
  }
}

@container doc-view (max-width: 640px) {
  .doc-wrap .doc {
    font-size: 11.5pt;
    overflow-wrap: anywhere;
  }

  .doc-wrap .doc .sheet,
  .doc-wrap .doc.landscape .sheet {
    min-height: 0;
    padding: 18px 16px 22px;
  }

  .doc-wrap .doc .doc-title h1 {
    padding: 4px 14px;
    font-size: 15pt;
  }

  .doc-wrap .doc .doc-title .sub {
    font-size: 11.5pt;
  }

  /* الترويسة والتذييل عموديًا */

  .doc-wrap .doc :is(.doc-head, .doc-foot),
  .doc-wrap .doc :is(.doc-head, .doc-foot) tbody {
    display: block;
  }

  .doc-wrap .doc .doc-head tr {
    display: flex;
    flex-direction: column;
  }

  .doc-wrap .doc .doc-head td {
    width: auto;
    text-align: center;
  }

  .doc-wrap .doc .doc-head .h-center {
    order: -1;
  }

  .doc-wrap .doc .doc-head .h-left span {
    text-align: center;
  }

  .doc-wrap .doc .doc-foot tr,
  .doc-wrap .doc .doc-foot td {
    display: block;
    width: auto;
    text-align: right;
  }

  .doc-wrap .doc .doc-foot td:empty {
    display: none;
  }

  /* جدول البيانات: كل تسمية بجوار قيمتها */

  .doc-wrap .doc .info,
  .doc-wrap .doc .info tbody {
    display: block;
  }

  .doc-wrap .doc .info tr {
    display: grid;
    grid-template-columns: minmax(120px, 36%) minmax(0, 1fr);
  }

  .doc-wrap .doc .info td {
    display: block;
    width: auto !important;
    height: auto;
    min-height: 34px;
  }

  .doc-wrap .doc .info .lbl {
    white-space: normal;
  }

  /* الأسئلة */

  .doc-wrap .doc :is(.mcq, .terms, .bank),
  .doc-wrap .doc :is(.mcq, .terms, .bank) tbody,
  .doc-wrap .doc .mcq .mcq-q,
  .doc-wrap .doc .mcq .mcq-q td {
    display: block;
  }

  .doc-wrap .doc .mcq .opt,
  .doc-wrap .doc .terms tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .doc-wrap .doc .mcq .opt td,
  .doc-wrap .doc .terms td {
    display: block;
    width: auto;
  }

  .doc-wrap .doc .terms td:empty {
    display: none;
  }

  .doc-wrap .doc .bank tr {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 6px;
  }

  .doc-wrap .doc .bank td {
    display: block;
    flex: 1 1 auto;
  }

  .doc-wrap .doc .match .mid {
    width: 52px;
    padding-inline: 2px;
  }

  /* جداول الخطط والتوزيع: كل صف بطاقة، وتسمية العمود من data-label */

  .doc-wrap .doc :is(.plan, .dist),
  .doc-wrap .doc :is(.plan, .dist) tbody,
  .doc-wrap .doc :is(.plan, .dist) tr,
  .doc-wrap .doc :is(.plan, .dist) td {
    display: block;
    width: auto;
  }

  .doc-wrap .doc :is(.plan, .dist) tr:has(th) {
    display: none;
  }

  .doc-wrap .doc :is(.plan, .dist) tr {
    margin-bottom: 12px;
    border: 1.2px solid #111827;
    border-radius: 8px;
    overflow: hidden;
  }

  .doc-wrap .doc :is(.plan, .dist) td {
    border: 0;
    border-top: 1px solid #e4e9f2;
    padding: 7px 12px;
    font-size: 10.5pt;
    text-align: right;
  }

  .doc-wrap .doc :is(.plan, .dist) td:first-child {
    border-top: 0;
  }

  .doc-wrap .doc :is(.plan, .dist) td[data-label]::before {
    content: attr(data-label);
    display: block;
    color: #6b7a99;
    font-size: 0.86em;
    font-weight: 800;
  }

  .doc-wrap .doc:not([contenteditable="true"]) .plan td:empty {
    display: none;
  }

  .doc-wrap .doc .plan .day {
    width: auto;
    font-size: 11.5pt;
    text-align: right;
  }

  .doc-wrap .doc .plan td.day::before {
    content: none;
  }

  .doc-wrap .doc .plan .term-name {
    text-align: center;
  }

  .doc-wrap .doc .dist td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .doc-wrap .doc .dist td::before {
    font-size: 1em;
  }
}

.doc-wrap .doc.reveal-doc .sheet > * {
  animation: docIn 0.7s var(--ease) both;
}

@keyframes docIn {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
}

.doc[contenteditable="true"] {
  outline: none;
}

.doc[contenteditable="true"] .sheet {
  box-shadow:
    0 0 0 3px rgba(245, 181, 68, 0.6),
    0 22px 60px -18px rgba(11, 22, 48, 0.35);
}

.doc[contenteditable="true"] :is(td, p, li, h1, div):hover {
  outline: 1px dashed rgba(245, 181, 68, 0.9);
  outline-offset: 1px;
}

/* ---------- درج المستندات ---------- */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(5, 11, 31, 0.45);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s;
}

.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 61;
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  background: #fff;
  box-shadow: var(--shadow-lg);
  transform: translateX(-104%);
  transition: transform 0.5s var(--ease);
}

.drawer.open {
  transform: none;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 22px;
  border-bottom: 1px solid var(--line);
}

.drawer-head h3 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 900;
}

.drawer-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: grid;
  align-content: start;
  gap: 10px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fff;
  text-align: right;
  transition: all 0.3s var(--ease);
  animation: fadeUp 0.5s var(--ease) both;
}

.history-item:hover {
  border-color: var(--blue);
  transform: translateX(-4px);
  box-shadow: var(--shadow-sm);
}

.history-item .t-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  flex-shrink: 0;
}

.history-item .meta {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.history-item strong {
  display: block;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item small {
  color: var(--muted);
}

.drawer-empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 10px;
}

/* ---------- إشعارات ---------- */

.toasts {
  position: fixed;
  bottom: 24px;
  inset-inline: 16px;
  z-index: 80;
  display: grid;
  justify-items: center;
  gap: 10px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--navy-800);
  color: #fff;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.5s var(--ease) both;
}

.toast .icon {
  color: var(--teal);
}

.toast.out {
  animation: toastOut 0.4s var(--ease) forwards;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
}

@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateY(10px) scale(0.95);
  }
}

#confetti {
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  width: 100%;
  height: 100%;
}

/* ---------- الاستجابة ---------- */

@media (max-width: 1100px) {
  .studio {
    grid-template-columns: minmax(0, 1fr);
  }

  .panel {
    position: relative;
    top: 0;
    max-height: none;
  }

  .stage {
    position: relative;
    top: 0;
    height: auto;
  }

  .stage-view.active {
    height: auto;
    min-height: 560px;
  }

  .doc-scroll {
    overflow-x: auto;
    overflow-y: visible;
  }

  /* الصفحة هي التي تتمرر هنا، فيجب أن يقف الشريط تحت الترويسة العلوية */
  .toolbar {
    top: 70px;
  }
}

@media (max-width: 760px) {
  .studio-top .bar {
    gap: 8px;
  }

  .stepper {
    gap: 2px;
  }

  .stepper li {
    gap: 2px;
  }

  .stepper button {
    padding: 4px;
  }

  .stepper .lbl {
    display: none;
  }

  .stepper .sep {
    width: 12px;
  }

  .top-actions .btn-ghost {
    padding: 8px 10px;
    gap: 6px;
  }

  /* ثلاثة صفوف ثابتة تأكل مساحة القراءة على الجوال */
  .toolbar {
    position: static;
    padding: 10px 12px;
  }

  .toolbar .doc-name {
    flex: 1 0 100%;
  }

  .doc-scroll {
    padding: 14px 10px 28px;
  }

  .studio-top .brand > span:last-child {
    display: none;
  }

  .top-actions .btn-ghost .lbl {
    display: none;
  }

  .panel-body {
    padding: 20px 18px 6px;
  }

  .panel-foot {
    padding: 14px 18px 18px;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .service-tiles {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .tile small {
    display: none;
  }

  .toolbar .tool-btn .lbl {
    display: none;
  }
}

/* ---------- الطباعة: إظهار المستند فقط ---------- */

@media print {
  body.studio-body {
    background: #fff !important;
  }

  body.studio-body > *:not(.studio),
  .panel,
  .toolbar,
  .stage-view:not(.result) {
    display: none !important;
  }

  .studio {
    display: block;
    width: auto;
    margin: 0;
  }

  .stage {
    border: 0;
    background: #fff !important;
    min-height: 0;
    border-radius: 0;
    overflow: visible;
  }

  .result,
  .doc-scroll {
    display: block !important;
    padding: 0 !important;
    min-height: 0 !important;
    overflow: visible !important;
    animation: none !important;
  }

  .doc-wrap {
    width: auto !important;
  }

  .doc-wrap .doc.reveal-doc .sheet > * {
    animation: none !important;
  }
}
