/* =========================================================
   SHARED MOBILE COMPONENTS
   Used by course_learn.html, editor_course.html, editor_home.html,
   quiz_player.html. Generalized from the learn-shell mobile pattern
   that used to be duplicated (learn-mobile-header / learn-nav /
   learn-bottom-nav). Respects the existing token system, all 4 themes.
   ========================================================= */

/* ---- Generic mobile header bar ---- */
.app-mobile-header {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  height: 52px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: relative;
}
.app-mobile-header__btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text);
  font-size: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.app-mobile-header__btn:active { background: rgba(var(--primary-rgb), .12); }
.app-mobile-header__title {
  flex: 1;
  font-size: 13px;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.app-mobile-header__progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -2px;
  height: 2px;
  background: rgba(var(--primary-rgb), .15);
}
.app-mobile-header__progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width .3s ease;
}

/* ---- Generic off-canvas drawer + backdrop ---- */
.app-drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 398;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.app-drawer-backdrop.is-open { display: block; }

.app-drawer__close-btn {
  display: none;
  width: 100%;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 10px 4px 12px;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
}

@media (max-width: 767px) { /* --bp-md */
  .app-mobile-header { display: flex; }
  .app-drawer.is-drawer-mobile {
    position: fixed;
    top: 0;
    left: 0;
    width: min(300px, 85vw);
    height: 100dvh;
    z-index: 399;
    transform: translateX(-100%);
    transition: transform .3s cubic-bezier(.4,0,.2,1);
    will-change: transform;
    border-right: 1px solid var(--border);
    box-shadow: none;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-top: 8px;
  }
  .app-drawer.is-drawer-mobile.is-open {
    transform: translateX(0);
    box-shadow: 8px 0 40px rgba(0,0,0,.5);
  }
  .app-drawer.is-drawer-mobile .app-drawer__close-btn { display: flex; }
}

/* ---- Generic sticky bottom bar (learn nav + editor save/preview) ---- */
.sticky-bottom-bar {
  display: none;
}
@media (max-width: 767px) { /* --bp-md */
  .sticky-bottom-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--bg);
    border-top: 1px solid var(--border);
    padding: 10px 14px;
    padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
    align-items: center;
    gap: 10px;
    box-shadow: 0 -4px 20px rgba(0,0,0,.2);
  }
}

/* ---- Generic bottom-sheet modal (replaces centered modals on mobile) ---- */
.sheet-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0,0,0,.6);
}
.sheet-backdrop.is-open { display: block; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 501;
  background: var(--surf-1);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 40px rgba(0,0,0,.5);
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  transform: translateY(110%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
}
.sheet.is-open { transform: translateY(0); }
.sheet__handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: rgba(165,176,194,.3);
  margin: 10px auto 4px;
  flex-shrink: 0;
}
.sheet__header {
  padding: 6px 20px 12px;
  font-weight: 900;
  font-size: 16px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.sheet__body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}
.sheet__footer {
  padding: 12px 20px;
  padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surf-1);
}

/* On desktop, an element with .sheet still renders as a normal centered
   modal instead of a bottom sheet — callers add .sheet--desktop-modal */
@media (min-width: 768px) { /* --bp-md */
  .sheet.sheet--desktop-modal {
    left: 50%;
    right: auto;
    bottom: auto;
    top: 50%;
    transform: translate(-50%, -50%) scale(.96);
    width: 100%;
    max-width: 480px;
    border-radius: 20px;
    opacity: 0;
    pointer-events: none;
    transition: transform .2s ease, opacity .2s ease;
  }
  .sheet.sheet--desktop-modal.is-open {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    pointer-events: auto;
  }
  .sheet.sheet--desktop-modal .sheet__handle { display: none; }
}

/* ---- Confirm-sheet (replaces window.confirm()) ---- */
.confirm-sheet__backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 600;
  background: rgba(0,0,0,.6);
  align-items: center;
  justify-content: center;
}
.confirm-sheet__backdrop.is-open { display: flex; }
.confirm-sheet {
  background: var(--surf-1);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px;
  width: 100%;
  max-width: 360px;
  margin: 16px;
  box-shadow: 0 30px 70px rgba(0,0,0,.5);
}
.confirm-sheet__title {
  font-weight: 900;
  font-size: 15px;
  margin-bottom: 8px;
}
.confirm-sheet__message {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 20px;
}
.confirm-sheet__actions {
  display: flex;
  gap: 10px;
}
.confirm-sheet__actions .btn { flex: 1; min-height: 44px; }

/* ---- Reorder up/down arrow fallback (paired with makeReorderable()) ---- */
.reorder-arrows {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}
.reorder-arrow-btn {
  width: 22px;
  height: 20px;
  min-width: 44px;
  min-height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  border-radius: 4px;
  -webkit-tap-highlight-color: transparent;
}
.reorder-arrow-btn:hover:not(:disabled) { color: var(--text); background: rgba(var(--primary-rgb), .1); }
.reorder-arrow-btn:disabled { opacity: .25; cursor: default; }
