:root {
  --qm-sidebar: 260px;
  --qm-editor: 420px;
}

@media (max-width: 720px) {
  :root {
    --qm-sidebar: 200px;
  }
}

.qm-app {
  width: min(100% - var(--space-3) * 2, 1700px);
  margin: 0 auto;
  padding: var(--space-3) 0 var(--space-4);
  min-height: 100vh;
}

.qm-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
  padding: var(--space-2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}

.qm-brand {
  flex: 1 1 auto;
}

.qm-brand h1 {
  margin: 0 0 4px;
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  font-weight: 800;
  line-height: 1.1;
}

.qm-pack-controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  align-items: center;
  justify-content: flex-end;
}

.qm-pack-controls .qm-select {
  min-width: 220px;
}

.qm-layout {
  display: grid;
  grid-template-columns: var(--qm-sidebar) 1fr var(--qm-editor);
  gap: var(--space-2);
  align-items: start;
}

.qm-sidebar,
.qm-question-panel,
.qm-editor-panel {
  border-radius: var(--radius);
  padding: var(--space-2);
  border: 1px solid var(--border);
  background: var(--surface);
  min-height: 70vh;
}

.qm-sidebar-header,
.qm-panel-header,
.qm-editor-header,
.qm-media-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-1);
  margin-bottom: var(--space-2);
}

.qm-sidebar-header h2,
.qm-panel-header h2,
.qm-editor-header h2,
.qm-media-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.qm-panel-title {
  display: flex;
  gap: var(--space-1);
  align-items: center;
}

.qm-panel-title span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.qm-category-list {
  display: grid;
  gap: 8px;
}

.qm-category-item {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-hover);
  border: 1px solid var(--border);
  cursor: grab;
  transition: background 150ms, border-color 150ms;
}

.qm-category-item:hover {
  border-color: var(--text-muted);
}

.qm-category-item.is-active {
  border-color: var(--accent);
  background: rgba(245, 184, 60, 0.1);
}

.qm-category-item.dragging {
  opacity: 0.5;
}

.qm-category-icon {
  font-size: 1.2rem;
  width: 28px;
  text-align: center;
}

.qm-category-name {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.qm-category-count {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.qm-category-actions {
  display: flex;
  gap: 4px;
}

.qm-icon-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  display: grid;
  place-items: center;
  transition: background 150ms, border-color 150ms;
}

.qm-icon-btn:hover {
  background: var(--surface-hover);
  border-color: var(--text-muted);
}

.qm-filters {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr 1fr;
  gap: var(--space-1);
  margin-bottom: var(--space-2);
}

.qm-search,
.qm-select,
.qm-field {
  min-height: 40px;
  width: 100%;
  padding: 0 var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: var(--bg);
  font: inherit;
  font-size: 14px;
  outline: none;
}

.qm-search:focus,
.qm-select:focus,
.qm-field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(245, 184, 60, 0.2);
}

.qm-select {
  cursor: pointer;
}

.qm-question-list {
  display: grid;
  gap: 10px;
}

.qm-question-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--surface-hover);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 150ms, border-color 150ms;
}

.qm-question-card:hover {
  border-color: var(--text-muted);
}

.qm-question-card.is-active {
  border-color: var(--accent);
  background: rgba(245, 184, 60, 0.1);
}

.qm-question-card-main {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
  overflow: hidden;
}

.qm-point-value {
  min-width: 56px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: rgba(245, 184, 60, 0.12);
  border: 1px solid rgba(245, 184, 60, 0.25);
  color: var(--accent);
  font-weight: 800;
  text-align: center;
  font-size: 13px;
}

.qm-question-info {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.qm-question-info strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.qm-question-meta {
  color: var(--text-muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.qm-question-card-actions {
  display: flex;
  gap: 4px;
}

.qm-editor-empty {
  display: grid;
  min-height: 200px;
  place-items: center;
  color: var(--text-muted);
  text-align: center;
}

.qm-form {
  display: grid;
  gap: var(--space-2);
}

.qm-form label {
  display: grid;
  gap: 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.qm-form-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
}

.qm-field {
  min-height: 40px;
  text-transform: none;
  letter-spacing: normal;
  font-size: 14px;
  font-weight: 400;
}

textarea.qm-field {
  padding: 10px var(--space-2);
  resize: vertical;
}

.qm-media-section {
  margin-top: 8px;
  padding-top: var(--space-2);
  border-top: 1px solid var(--border);
}

.qm-media-header h3 {
  margin: 0;
  font-size: 16px;
}

.qm-hint {
  color: var(--text-muted);
  font-size: 12px;
}

.qm-drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 90px;
  padding: var(--space-2);
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-hover);
  transition: border-color 150ms, background 150ms;
}

.qm-drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(245, 184, 60, 0.08);
}

.qm-or {
  color: var(--text-muted);
  font-size: 13px;
}

.qm-links {
  display: grid;
  gap: 8px;
}

.qm-link-row {
  display: grid;
  grid-template-columns: 1fr 2fr auto;
  gap: 8px;
  align-items: center;
}

.qm-link-row input {
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.qm-link-row input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(245, 184, 60, 0.2);
  outline: none;
}

.qm-empty {
  color: var(--text-muted);
  text-align: center;
  padding: var(--space-3) 0;
  font-size: 14px;
}

/* Media Gallery overrides */
.qm-editor-panel .media-gallery {
  margin: var(--space-2) 0;
}

.qm-editor-panel .media-slide img,
.qm-editor-panel .media-slide video {
  max-height: 260px;
}

.qm-preview .media-youtube {
  margin: 0 auto;
  max-width: 640px;
}

.qm-preview-media {
  text-align: left;
}

/* Upload progress */
.upload-progress {
  margin: var(--space-2) 0;
}

.upload-progress .progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--surface-hover);
  border: 1px solid var(--border);
}

.upload-progress .progress-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--success));
  transition: width 220ms ease;
}

.progress-label {
  display: block;
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 12px;
}

/* Media item previews */
.media-item {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-hover);
  border: 1px solid var(--border);
}

.media-item .media-preview img,
.media-item .media-preview video {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
}

.media-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 6px;
  background: rgba(248, 113, 113, 0.9);
  color: white;
  cursor: pointer;
  font-weight: 800;
}

.media-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  font-size: 12px;
}

.media-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-size {
  color: var(--text-muted);
  white-space: nowrap;
}

.media-file-preview {
  display: grid;
  place-items: center;
  gap: 8px;
  padding: var(--space-2);
  min-height: 120px;
}

.file-icon {
  font-size: 2rem;
}

.qm-editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.qm-editor-actions .qm-select {
  min-width: 140px;
}

.qm-preview {
  display: grid;
  gap: var(--space-2);
  text-align: center;
}

.qm-preview .question-value {
  color: var(--accent);
  font-size: clamp(1.6rem, 3vw, 2.6rem);
}

.qm-preview .question-text {
  font-size: clamp(1.1rem, 2vw, 1.6rem);
}

.qm-preview .answer-box {
  text-align: left;
}

.qm-more-menu {
  position: relative;
}

.qm-more-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 100;
  display: none;
  min-width: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  overflow: hidden;
}

.qm-more-menu.is-open .qm-more-dropdown {
  display: grid;
}

.qm-more-dropdown button {
  padding: 10px 14px;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  font-family: inherit;
}

.qm-more-dropdown button:hover {
  background: var(--surface-hover);
}

.qm-more-dropdown button.danger {
  color: var(--danger);
}

.qm-editor-actions .btn[data-action="toggle-advanced"] {
  font-size: 12px;
}

.qm-form-row .qm-field:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 1300px) {
  .qm-layout {
    grid-template-columns: 220px 1fr;
  }

  .qm-editor-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 900px) {
  .qm-layout {
    grid-template-columns: 1fr;
  }

  .qm-sidebar {
    min-height: auto;
  }

  .qm-topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .qm-pack-controls {
    justify-content: flex-start;
  }

  .qm-filters {
    grid-template-columns: 1fr 1fr;
  }

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

@media (max-width: 560px) {
  .qm-filters {
    grid-template-columns: 1fr;
  }

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