/* ============================================
   Course Tree / PDF Manager Styling
   ============================================ */

/* Main wrapper */
.ct-pdfui-wrap {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: #333;
  background: #f9f9f9;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Header section */
.ct-pdfui-head {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.ct-pdfui-head label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
}

.ct-pdfui-head label input[type="checkbox"] {
  cursor: pointer;
  width: 18px;
  height: 18px;
}

.ct-pdfui-head > div {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.ct-pdfui-head strong {
  font-weight: 600;
  white-space: nowrap;
}

/* Levels list */
.ct-levels {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ct-levels li {
  background: rgba(255, 255, 255, 0.2);
  padding: 6px 12px;
  border-radius: 4px;
  cursor: move;
  transition: all 0.2s ease;
  font-size: 13px;
  font-weight: 500;
  user-select: none;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.ct-levels li:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}

/* Control section */
.ct-pdfui-controls {
  background: white;
  padding: 15px 20px;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.ct-pdfui-controls strong {
  font-weight: 600;
  white-space: nowrap;
}

.ct-pdfui-controls input[type="text"] {
  flex: 1;
  min-width: 200px;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  transition: border-color 0.2s ease;
}

.ct-pdfui-controls input[type="text"]:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Alert messages */
.ct-alert {
  padding: 12px 16px;
  margin: 0;
  border-radius: 0;
  border-left: 4px solid #667eea;
  background: #f0f4ff;
  color: #333;
  font-size: 14px;
}

.ct-alert--info {
  border-left-color: #667eea;
  background: #f0f4ff;
}

.ct-alert--ok {
  border-left-color: #4caf50;
  background: #f1f8f4;
  color: #2e7d32;
}

.ct-alert--error {
  border-left-color: #f44336;
  background: #fef5f5;
  color: #c62828;
}

/* Main tree container */
.ct-tree {
  padding: 20px;
  background: white;
  max-height: 600px;
  overflow-y: auto;
}

/* ---- Compatibility layer for course-tree.js structure ---- */
#ct-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 15px;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
}

#ct-actions input[type="search"] {
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
}

#ct-order-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 15px;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
}

#ct-order {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ct-order-block {
  background: #e8eaf6;
  color: #444;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: move;
  border: 1px solid #d0d2e6;
  user-select: none;
}

/* Folder/file aliases */
.folder {
  margin: 10px 0;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #e8e8e8;
  background: white;
  transition: all 0.2s ease;
}

.folder:hover {
  border-color: #667eea;
  box-shadow: 0 2px 6px rgba(102, 126, 234, 0.1);
}

.folder-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 15px;
  background: linear-gradient(to right, #f8f9fa, #ffffff);
  border-bottom: 1px solid #e8e8e8;
  cursor: pointer;
}

.folder-toggle {
  background: none;
  border: 1px solid #667eea;
  padding: 4px 8px;
  cursor: pointer;
  color: #667eea;
  font-size: 14px;
  font-weight: bold;
  width: 28px;
  height: 28px;
  border-radius: 4px;
}

.folder-name {
  font-weight: 600;
  color: #333;
  flex: 1;
}

.folder-count {
  background: #e8eaf6;
  color: #667eea;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.folder-select,
.folder-deselect {
  background: white;
  color: #667eea;
  border: 1px solid #667eea;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

.folder-body {
  padding: 10px 0;
  background: #fafafa;
}

.file {
  padding: 8px 15px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid #f0f0f0;
}

.file:last-child {
  border-bottom: none;
}

.file input[type="checkbox"] {
  cursor: pointer;
  width: 18px;
  height: 18px;
  accent-color: #667eea;
}

.file label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  cursor: pointer;
}

.ct-tree::-webkit-scrollbar {
  width: 8px;
}

.ct-tree::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.ct-tree::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 4px;
}

.ct-tree::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* Folder styling */
.ct-folder {
  margin: 10px 0;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #e8e8e8;
  background: white;
  transition: all 0.2s ease;
}

.ct-folder:hover {
  border-color: #667eea;
  box-shadow: 0 2px 6px rgba(102, 126, 234, 0.1);
}

/* Folder row (header) */
.ct-folder__row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 15px;
  background: linear-gradient(to right, #f8f9fa, #ffffff);
  border-bottom: 1px solid #e8e8e8;
  cursor: pointer;
  transition: background 0.2s ease;
}

.ct-folder__row:hover {
  background: linear-gradient(to right, #f0f4ff, #f8f9fa);
}

/* Toggle button */
.ct-folder__toggle {
  background: none;
  border: none;
  padding: 4px 8px;
  cursor: pointer;
  color: #667eea;
  font-size: 14px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.ct-folder__toggle:hover {
  background: rgba(102, 126, 234, 0.1);
  border-radius: 4px;
}

/* Folder title */
.ct-folder__title {
  font-weight: 600;
  color: #333;
  flex: 1;
  font-size: 15px;
}

/* File count badge */
.ct-folder__badge {
  background: #e8eaf6;
  color: #667eea;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Folder tools (buttons) */
.ct-folder__tools {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* Indentation for nested items */
.ct-indent {
  margin-left: 20px;
}

/* File list */
.ct-filelist {
  list-style: none;
  padding: 10px 0;
  margin: 0;
  background: #fafafa;
}

.ct-filelist li {
  padding: 8px 15px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid #f0f0f0;
  transition: background 0.2s ease;
}

.ct-filelist li:hover {
  background: #f0f4ff;
}

.ct-filelist li:last-child {
  border-bottom: none;
}

.ct-filelist input[type="checkbox"] {
  cursor: pointer;
  width: 18px;
  height: 18px;
  accent-color: #667eea;
  flex-shrink: 0;
}

.ct-filelist label {
  cursor: pointer;
  flex: 1;
  font-size: 14px;
  color: #555;
  margin: 0;
}

/* Sublist (nested files) */
.ct-sublist {
  list-style: none;
  padding: 0;
  margin: 0;
}

.ct-sublist li {
  padding: 6px 15px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid #f0f0f0;
  background: white;
}

.ct-sublist li:last-child {
  border-bottom: none;
}

/* Buttons */
.ct-btn {
  background: white;
  color: #667eea;
  border: 1px solid #667eea;
  padding: 8px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.ct-btn:hover {
  background: #667eea;
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(102, 126, 234, 0.3);
}

.ct-btn:active {
  transform: translateY(0);
}

.ct-btn--primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
}

.ct-btn--primary:hover {
  background: linear-gradient(135deg, #5568d3 0%, #6a3f91 100%);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

/* Result section */
.ct-result {
  background: #f1f8f4;
  padding: 15px 20px;
  border-top: 1px solid #c8e6c9;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.ct-result a {
  color: #2e7d32;
  text-decoration: none;
  font-weight: 600;
  transition: color 0.2s ease;
}

.ct-result a:hover {
  color: #1b5e20;
  text-decoration: underline;
}

/* Responsive design */
@media (max-width: 768px) {
  .ct-pdfui-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 15px;
  }

  .ct-pdfui-head > div {
    width: 100%;
    flex-direction: column;
  }

  .ct-levels {
    width: 100%;
  }

  .ct-pdfui-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .ct-pdfui-controls input[type="text"] {
    width: 100%;
    min-width: unset;
  }

  .ct-folder__row {
    flex-wrap: wrap;
  }

  .ct-folder__tools {
    width: 100%;
    margin-top: 10px;
  }

  .ct-tree {
    max-height: 400px;
  }

  .ct-indent {
    margin-left: 10px;
  }
}

@media (max-width: 480px) {
  .ct-pdfui-wrap {
    border-radius: 0;
  }

  .ct-pdfui-head {
    padding: 15px;
  }

  .ct-pdfui-controls {
    padding: 12px 15px;
  }

  .ct-tree {
    padding: 15px;
    max-height: 300px;
  }

  .ct-folder__row {
    padding: 10px 12px;
  }

  .ct-filelist li {
    padding: 6px 12px;
  }

  .ct-btn {
    padding: 6px 12px;
    font-size: 12px;
  }

  .ct-folder__badge {
    font-size: 11px;
    padding: 3px 8px;
  }
}

/* Animation for folder toggle */
@keyframes slideDown {
  from {
    opacity: 0;
    max-height: 0;
  }
  to {
    opacity: 1;
    max-height: 1000px;
  }
}

.ct-folder__content {
  animation: slideDown 0.3s ease;
}

/* Loading spinner */
.ct-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(102, 126, 234, 0.3);
  border-top-color: #667eea;
  border-radius: 50%;
  animation: ct-spin 0.6s linear infinite;
  margin-right: 6px;
  vertical-align: middle;
}

@keyframes ct-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Disabled button state */
button:disabled,
.ct-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

/* Print styles */
@media print {
  .ct-pdfui-head,
  .ct-pdfui-controls,
  .ct-folder__tools,
  .ct-btn {
    display: none;
  }

  .ct-tree {
    max-height: none;
    overflow: visible;
  }
}
