/* ============================================================
   Courseware Panel — split-view sidebar + mobile bottom drawer
   Digital Scriptorum theme (inherits all tokens from reader.css)
   ============================================================ */

/* ----- Panel base (desktop: fixed right, width via CSS var, default 360px) ----- */
:root { --cw-panel-w: 360px; }

.cw-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--cw-panel-w, 360px);
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 600;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform cubic-bezier(0.4, 0, 0.2, 1) 0.3s;
  box-shadow: -4px 0 24px -8px var(--shadow);
}

.cw-panel.open {
  transform: translateX(0);
}

.cw-panel.closed {
  transform: translateX(100%);
}

/* Disable handle pointer when closed — prevents stray drag events */
.cw-panel.closed .cw-panel-resize-handle {
  pointer-events: none;
}

/* Disable transition during resize for smooth drag */
.cw-panel.resizing {
  transition: none !important;
}

/* ----- Resize handle (gripper on left edge) ----- */
.cw-panel-resize-handle {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: col-resize;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

.cw-panel-resize-handle::before {
  content: '';
  width: 3px;
  height: 40px;
  background: var(--rule);
  border-radius: 2px;
  transition: background 0.15s, height 0.15s;
}

.cw-panel-resize-handle:hover::before,
.cw-panel-resize-handle.active::before {
  background: var(--accent);
  height: 64px;
}

.cw-panel-resize-handle:hover,
.cw-panel-resize-handle.active {
  background: transparent;
}

/* ----- Panel header ----- */
.cw-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.cw-panel-header h3 {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.02em;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.cw-panel-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}

.cw-panel-close:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* ----- Panel content (scrollable) ----- */
.cw-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  font-size: var(--reading-font, 19px);
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}

.cw-panel-content::-webkit-scrollbar {
  width: 7px;
}

.cw-panel-content::-webkit-scrollbar-thumb {
  background: var(--rule);
  border-radius: 4px;
}

.cw-panel-content::-webkit-scrollbar-track {
  background: transparent;
}

/* ----- Panel sections ----- */
.cw-panel-section {
  margin-bottom: 28px;
}

.cw-panel-section:last-child {
  margin-bottom: 0;
}

.cw-panel-section-title {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* ----- Question items ----- */
.cw-question-item {
  margin-bottom: 20px;
}

.cw-question-item:last-child {
  margin-bottom: 0;
}

.cw-question-text {
  font-family: var(--font-body);
  font-size: 0.85em;
  font-weight: 400;
  color: var(--text);
  line-height: 1.65;
  margin-bottom: 10px;
}

.cw-answer-textarea {
  width: 100%;
  min-height: 80px;
  padding: 10px 14px;
  font-family: var(--font-body);
  font-size: 0.85em;
  line-height: 1.6;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: vertical;
  transition: border-color 0.15s;
}

.cw-answer-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.cw-answer-textarea::placeholder {
  color: var(--faint);
}

/* ----- Key term display ----- */
.cw-keyterm {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 10px;
}

.cw-keyterm:last-child {
  margin-bottom: 0;
}

.cw-keyterm dt {
  font-family: var(--font-ui);
  font-size: 0.8em;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
}

.cw-keyterm dd {
  font-family: var(--font-body);
  font-size: 0.82em;
  color: var(--muted);
  line-height: 1.6;
  margin: 0;
}

/* ----- Scripture quote ----- */
.cw-scripture {
  background: var(--quote-bg);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  padding: 14px 18px;
  font-family: var(--font-body);
  font-size: 0.85em;
  font-style: italic;
  color: var(--muted);
  line-height: 1.7;
  margin-bottom: 10px;
}

.cw-scripture:last-child {
  margin-bottom: 0;
}

/* ----- Loading skeleton ----- */
.cw-loading {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 0;
}

.cw-loading-line {
  height: 14px;
  background: var(--surface-2);
  border-radius: 4px;
  animation: cw-pulse 1.5s ease-in-out infinite;
}

.cw-loading-line:nth-child(2) {
  width: 85%;
}

.cw-loading-line:nth-child(3) {
  width: 70%;
}

.cw-loading-line:nth-child(4) {
  width: 90%;
}

.cw-loading-line:nth-child(5) {
  width: 60%;
}

@keyframes cw-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ----- Error state ----- */
.cw-error {
  text-align: center;
  padding: 32px 16px;
}

.cw-error p {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
  line-height: 1.5;
}

.cw-error button {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 20px;
  padding: 8px 20px;
  cursor: pointer;
  transition: background 0.15s;
}

.cw-error button:hover {
  background: var(--accent-ink);
}

/* ----- Empty state ----- */
.cw-empty {
  text-align: center;
  padding: 40px 16px;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
}

/* ----- Outline inside panel (本章导航) ----- */
.cw-outline-section {
  margin-bottom: 28px;
}

.cw-outline-section .cw-panel-section-title {
  margin-bottom: 10px;
}

.cw-outline-link {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.75em;
  line-height: 1.5;
  color: var(--faint);
  text-decoration: none;
  padding: 4px 0 4px 12px;
  border-left: 2px solid var(--border);
  transition: color 0.15s, border-color 0.15s;
}

.cw-outline-link:hover {
  color: var(--text);
  border-left-color: var(--accent);
}

.cw-outline-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

/* ----- Back-to-top button inside panel ----- */
.cw-panel-totop {
  display: block;
  width: 100%;
  padding: 10px 0;
  font-family: var(--font-ui);
  font-size: 0.8em;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: none;
  border-top: 1px solid var(--border);
  cursor: pointer;
  text-align: center;
  transition: color 0.15s;
  margin-top: 12px;
}

.cw-panel-totop:hover {
  color: var(--accent);
}

/* ----- Mobile overlay backdrop ----- */
.cw-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--shadow);
  z-index: 550;
  pointer-events: auto;
}

.cw-overlay.hidden {
  display: none;
}

/* Sidebar collapse when panel opens */
.sidebar.collapsed {
  transform: translateX(-100%);
}

/* Make room for the panel — shift content left by panel width */
.layout.cw-active {
  margin-left: 0;
  margin-right: var(--cw-panel-w, 360px);
}

/* Hide the original outline when panel is open (it's now inside the panel) */
.outline.hidden-by-cw {
  display: none !important;
}

/* ============================================================
   Mobile (<768px): panel becomes bottom drawer
   ============================================================ */
@media (max-width: 767px) {
  .cw-panel {
    width: 100%;
    height: 50vh;
    height: 50vh;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 14px 14px 0 0;
    transform: translateY(100%);
    box-shadow: 0 -4px 24px -8px var(--shadow);
  }

  .cw-panel.open {
    transform: translateY(0);
  }

  .cw-panel.closed {
    transform: translateY(100%);
  }

  .cw-panel-content {
    max-height: calc(50vh - 60px);
  }

  .cw-overlay {
    display: block;
  }

  .cw-overlay.hidden {
    display: none;
  }

  /* Mobile: no resize handle, no layout shift */
  .cw-panel-resize-handle { display: none; }
  .layout.cw-active { margin-right: 0; }
}
