/* ========================================================================
LAYOUT
======================================================================== */
.app-main-broker {
  width: 100%;
  padding: var(--space-lg) 0;
}

/* فقط در وب: فاصله باکس کلی از دو طرف 40px */
/* @media (min-width: 900px) {
.app-main-broker { padding-left: 40px; padding-right: 40px; }
} */

.state-container {
  text-align: center;
  padding: var(--space-xl) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  align-items: center;
  justify-content: center;
}
.spinner {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 4px solid var(--border-light);
  border-top-color: var(--color-primary);
  animation: spin 1s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ========================================================================
COURSE CARD & HEADER
======================================================================== */
.course-card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  border: 1px solid var(--border-light);
  margin-bottom: var(--space-lg);
  box-shadow: var(--shadow-sm);
  display: grid;
  gap: var(--space-lg);
  grid-template-columns: 1fr;
  align-items: stretch;
  box-shadow: var(--shadow-md);
}
.course-header {
  border-bottom: 1px solid var(--border-light);
  padding-bottom: var(--space-xs);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  align-items: center;
}

@media (min-width: 900px) {
  .course-card {
    grid-template-columns: minmax(240px, 1fr) minmax(260px, 1fr) minmax(
        360px,
        1.3fr
      );
  }
  .course-header {
    grid-column: 1 / -1;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding-bottom: var(--space-sm);
  }
}
@media (max-width: 890px) {
  .course-card {
    display: flex;
    flex-direction: column;
    padding: var(--space-xs);
    gap: var(--space-xs);
    margin-bottom: 0.1rem;
  }
  .course-header {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding-bottom: var(--space-sm);
  }
  .course-meta {
    width: 100%;
  }
}

.instructor-profile {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  min-width: 0;
}

/* ========================================================================
AVATAR (PROFESSIONAL & REPLACEABLE)
======================================================================== */
.avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e2e8f0, #f8fafc);
  border: 1px solid var(--border-light);
  color: var(--color-text-secondary);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-weight: 800;
  font-size: var(--font-sm);
  position: relative;
  overflow: hidden;
}
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.avatar .avatar-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: var(--font-sm);
  color: #0f172a;
  background: linear-gradient(135deg, #e2e8f0, #f1f5f9);
}

.instructor-text {
  min-width: 0;
  flex: 1;
}
.instructor-main-title {
  font-size: clamp(14px, 4vw, 17px);
  font-weight: 800;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}
.instructor-subtitle {
  font-size: clamp(11px, 3.2vw, 14px);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

/* کارت‌های سرفصل (هم‌شکل و هم‌سایز) */
.topic-cards-broker {
  display: grid;
  gap: var(--space-sm);
  grid-template-columns: repeat(auto-fit, minmax(max-content, 50px));
  /* grid-template-columns: repeat(auto-fit, minmax(50px, 1fr)); */
  width: 100%;
}

/* فقط در وب: 6 باکس در یک ردیف */
@media (min-width: 900px) {
  .topic-cards-broker {
    grid-template-columns: repeat(max-content, max-content);
    justify-content: end;
  }
}
.buy-course {
  height: 30vh;
  background: var(--color-surface-muted);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px;
  height: 110px;
  width: 100px;
  transition: 0.2s;
  cursor: pointer;
  position: relative;

}

.topic-card-broker {
  height: 30vh;
  background: var(--color-surface-muted);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px;
  height: 110px;
  max-width: 100px;
  transition: 0.2s;
  cursor: pointer;
  position: relative;
}
.topic-card-broker:hover {
  background: var(--bg-surface);
  border-color: var(--border-light);
}
.topic-card-broker.active {
  border-color: var(--text-primary);
  background: var(--bg-surface);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.topic-avatar-broker {
  width: 44px;
  height: 44px;
  border-radius: 5px;
  overflow: hidden;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  display: grid;
  place-items: center;
  font-weight: 800;
  color: var(--text-primary);
  font-size: 12px;
  margin-bottom: 8px;
  object-fit: cover;
  object-position: center;
}
.topic-card-broker.active .topic-avatar-broker {
  background: var(--text-primary);
  color: #fff;
  border-color: var(--text-primary);
}
.topic-title {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}
.topic-card-broker.active .topic-title {
  color: var(--text-primary);
  font-weight: 700;
}
.contacts-form-group {
  height: max-content;
}
/* ========================================================================
COLUMN 1 – COURSE META (سایت و ارتباط)
======================================================================== */
.course-meta {
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  height: auto;
  min-height: 0;
  align-self: start;
  min-width: 0;
  overflow-y: auto;
  position: relative;

  /* بردار/مرزبندی برای مشخص‌تر شدن هویت */
  border: 1.5px solid var(--border-light);
}
.course-meta::-webkit-scrollbar {
  width: 6px;
}
.course-meta::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}

.meta-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.meta-row-broker {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 10px;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border-light);
}
.meta-row-broker:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
.meta-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--color-surface);
  border: 1px solid var(--border-light);
  display: grid;
  place-items: center;
  color: var(--color-primary);
}
.meta-icon svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.meta-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.meta-label {
  font-size: var(--font-sm);
  color: var(--text-secondary);
}
.meta-value {
  font-size: var(--font-sm);
  font-weight: 700;
  direction: ltr;
  text-align: left;
  word-break: break-all;
}
.meta-value.meta-link {
  color: #2563eb !important;
}
.meta-value.meta-copy {
  cursor: pointer;
  color: var(--text-primary);
}
.meta-value.meta-copy:hover {
  color: var(--color-primary-hover);
  text-decoration: underline;
}

.meta-empty {
  font-size: var(--font-sm);
  color: var(--text-secondary);
  padding: 10px;
  border: 1px dashed var(--border-light);
  border-radius: var(--radius-md);
}

/* ========================================================================
COLUMN 2 – EPISODES
======================================================================== */

/* اصلاح syllabus-wrapper برای تبدیل به Flexbox */
.syllabus-wrapper {
  max-height: 260px;
  height: 100%;
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border-glass);
  border-radius: var(--space-sm);
  padding: 0.75rem;
  display: flex; /* اضافه شد */
  flex-direction: column; /* اضافه شد */
  gap: 0.5rem; /* اضافه شد */
}
/* اصلاح syllabus-container جهت اسکرول درست درون flex-box */
.syllabus-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  padding: 4px;
  scroll-behavior: smooth;
  height: 100%;
  background-color: transparent;
  overflow-y: auto;
  scroll-behavior: smooth;
}

/* هدر جدید جهت نگهداری عنوان و دکمه ادمین */
.syllabus-header {
  /* background: var(--bg-surface); */
  padding: 8px var(--space-sm);
  border-radius: var(--radius-md);
  /* border: 1px solid var(--border-light); */
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  transition: 0.25s ease;
  opacity: 0.7;
  width: 100%;
  height: 54px;
  flex-shrink: 0;
}

.syllabus-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-base);
}

.btn-add-ep-admin:hover {
  opacity: 0.85;
}


.episode-card {
  background: var(--bg-surface);
  padding: 8px var(--space-sm);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  transition: 0.25s ease;
  opacity: 0.7;
  height: 54px;
  flex-shrink: 0;
}
.episode-card:hover {
  opacity: 1;
  background: var(--color-bg);
}
.episode-card.active {
  opacity: 1;
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
  transform: scale(1.01);
  background: var(--color-bg);
}

.ep-file-type {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--color-border);
  display: grid;
  place-items: center;
  font-weight: bold;
  color: #000;
  font-family: monospace;
  font-size: 11px;
  flex-shrink: 0;
}
.episode-card.active .ep-file-type {
  background: var(--color-primary);
  color: var(--text-base);
}
.ep-title {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ep-meta {
  font-size: 11px;
  color: var(--color-text-secondary);
}
.ep-text-content {
  min-width: 0;
  flex: 1;
}

/* ========================================================================
COLUMN 3 – VIDEO PLAYER (ADVANCED)
======================================================================== */
.player-wrapper-broker {
  background: var(--color-player-bg);
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
  aspect-ratio: 16/9;
  display: flex;
  width: 100%;
  flex-direction: column;
  box-shadow: var(--shadow-md);
  user-select: none;
  height: 100%;
  min-height: 0;
  touch-action: none;
  direction: ltr;
  min-width: 0;

  /* بردار/مرزبندی برای مشخص‌تر شدن هویت */
  border: 1.5px solid var(--border-light);
}
video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  z-index: 1;
  transition: opacity 0.3s;
  cursor: pointer;
}

.player-wrapper-broker:fullscreen,
.player-wrapper-broker:-webkit-full-screen {
  aspect-ratio: unset;
  width: 100vw;
  height: 100vh;
  border-radius: 0;
}
.player-wrapper-broker:fullscreen video,
.player-wrapper-broker:-webkit-full-screen video {
  object-fit: contain;
}

.brightness-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0);
  pointer-events: none;
  z-index: 2;
  transition: background 0.1s;
}

.gesture-indicator {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 8px 16px;
  border-radius: 30px;
  font-size: 13px;
  font-weight: bold;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 20;
  pointer-events: none;
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  gap: 8px;
}
.gesture-indicator svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.gesture-indicator.show {
  opacity: 1;
}

/* آیکون های راهنمای کناری */
.side-hint-icon {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  color: rgba(255, 255, 255, 0.7);
  width: 32px;
  height: 32px;
  display: none;
  place-items: center;
  z-index: 15;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.3s ease;
}
.side-hint-icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.side-hint-icon.left-hint {
  left: 1rem;
}
.side-hint-icon.right-hint {
  right: 1rem;
}

@media (pointer: coarse) {
  .side-hint-icon {
    display: grid;
  }
  .player-wrapper-broker.playing.idle .side-hint-icon {
    opacity: 0;
  }
  .player-wrapper-broker.paused .side-hint-icon {
    opacity: 0;
  }
}

.audio-equalizer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--color-player-bg);
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  z-index: 3;
  pointer-events: none;
}
.player-wrapper-broker.is-audio .audio-equalizer {
  display: flex;
}
.player-wrapper-broker.is-audio video {
  opacity: 0;
}
.eq-bar {
  width: 8px;
  height: 15px;
  background: var(--color-success);
  border-radius: 4px;
  animation: eqAnim 1s ease-in-out infinite;
}
.eq-bar:nth-child(2) {
  animation-delay: 0.2s;
}
.eq-bar:nth-child(3) {
  animation-delay: 0.4s;
}
.eq-bar:nth-child(4) {
  animation-delay: 0.1s;
}
.eq-bar:nth-child(5) {
  animation-delay: 0.3s;
}
@keyframes eqAnim {
  0%,
  100% {
    height: 15px;
  }
  50% {
    height: 60px;
  }
}
.player-wrapper-broker.paused .eq-bar {
  animation-play-state: paused;
}

.center-play {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 64px;
  height: 64px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: white;
  cursor: pointer;
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: all 0.3s ease;
  z-index: 10;
}
.player-wrapper-broker.playing .center-play {
  opacity: 0;
  transform: translate(-50%, -50%) scale(1.3);
  pointer-events: none;
}
.center-play svg {
  width: 32px;
  height: 32px;
  fill: white;
  stroke: none;
  margin-left: 4px;
}

.custom-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 2rem var(--space-md) var(--space-md);
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.85) 0%, transparent 100%);
  opacity: 1;
  transition: opacity 0.3s ease;
  z-index: 10;
}
.player-wrapper-broker.playing.idle .custom-controls {
  opacity: 0;
  pointer-events: none;
}

.progress-container {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 5px;
  margin-bottom: var(--space-sm);
  cursor: pointer;
  position: relative;
  transition: height 0.2s;
}
.progress-container:hover {
  height: 8px;
}
.progress-filled {
  width: 0%;
  height: 100%;
  background: var(--color-success);
  border-radius: 5px;
  pointer-events: none;
  position: relative;
}
.progress-filled::after {
  content: "";
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  background: white;
  border-radius: 50%;
  opacity: 0;
  transition: 0.2s;
}
.progress-container:hover .progress-filled::after {
  opacity: 1;
}

.controls-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: white;
}
.controls-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.ctrl-btn {
  padding: 4px;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: 0.2s;
}
.ctrl-btn:hover {
  color: var(--color-success);
}
.ctrl-btn svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ctrl-btn.filled svg {
  fill: currentColor;
  stroke: none;
}

.time-display {
  font-size: var(--font-xs);
  font-variant-numeric: tabular-nums;
  direction: ltr;
  margin-left: 0.5rem;
}

.volume-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.vol-slider {
  width: 0;
  opacity: 0;
  transition: all 0.3s;
  cursor: pointer;
  accent-color: var(--color-success);
  height: 4px;
}
.volume-group:hover .vol-slider {
  width: 60px;
  opacity: 1;
}

.speed-btn {
  font-size: var(--font-xs);
  font-weight: 700;
  background: rgba(255, 255, 255, 0.2);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

/* Modal Backdrop & Container */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-backdrop.active {
  opacity: 1;
  pointer-events: all;
}


.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.1rem 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-close {
  background: none;
  border: none;
  color: #aaa;
  cursor: pointer;
  width: 24px;
  height: 24px;
}

.modal-close svg {
  stroke: currentColor;
  stroke-width: 2;
}

.modal-body {
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.modal-footer {
  display: flex;
  background: var(--bg-surface);
  justify-content: flex-end;
  gap: 10px;
  margin-top: 10px;
}

.btn-cancel {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #ccc;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
}

.btn-submit {
  background: var(--color-primary);
  border: none;
  color: var(--text-base);
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
}

/* Topic buttons inside Course header */
.btn-add-topic {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: var(--border-glass);
  border: 2px dashed var(--border-light);
  color: var(--text-base);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
}

.btn-topic-container {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
}

.btn-delete-topic,
.btn-edit-topic {
  border: none;
  background: transparent;
  padding: 2px;
  margin-right: 6px;
  opacity: 0.7;
}

.btn-edit-topic:hover {
  opacity: 1;
}

.btn-delete-topic svg,
.btn-add-topic svg,
.btn-edit-topic svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
}

.btn-edit-course,
.btn-edit-episode,
.btn-delete-episode {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  margin-right: 6px;
  opacity: 0.7;
  transition: opacity 0.2s;
}
.btn-edit-course:hover,
.btn-edit-episode:hover,
.btn-delete-episode:hover {
  opacity: 1;
}
.btn-edit-course svg,
.btn-edit-episode svg,
.btn-delete-episode svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.buy:hover {
  cursor: pointer;
}

.buy.purchased {
  opacity: 0.7;
  cursor: not-allowed;
}
.buy.purchased .stat-value,
.buy.purchased .stat-label {
  color: #6c757d !important;
}

/* ========================================================================
MOBILE RESPONSIVE TWEAKS 
======================================================================== */
@media (max-width: 900px) {
  .syllabus-wrapper {
    height: 248px;
  }
}
@media (max-width: 768px) {
  .app-main-broker {
    padding: 1rem 0;
  }
  .topic-cards-broker {
    grid-template-columns: repeat(3, minmax(40px, 1fr));
  }
  .topic-card-broker {
    height: max-content;
    max-width: 100%;
  }
  .buy-course {
    height: 100%;
  }
  .episode-card {
    padding: 0.5rem;
  }
}
