:root {
  --primary: #2563eb;
  --primary-light: #dbeafe;
  --danger: #dc2626;
  --success: #059669;
  --bg: #f3f4f6;
  --card-bg: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --radius: 12px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #e0f2fe, #eef2ff 40%, #f9fafb);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 16px;
}

.container {
  width: 100%;
  max-width: 900px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-radius: 18px;
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.15);
  padding: 20px 16px 24px;
}

@media (min-width: 640px) {
  .container {
    padding: 24px 28px 30px;
  }
}

header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
  position: relative;
  padding-right: 240px;
}

header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

header h1 span.logo-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(135deg, #6366f1, #22c55e);
  box-shadow: 0 0 10px rgba(79, 70, 229, 0.6);
}

header p {
  font-size: 0.85rem;
  color: var(--muted);
}

.user-tools {
  position: absolute;
  right: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  max-width: 220px;
}

.user-profile {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 220px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: #e5e7eb;
  border: 1px solid rgba(148, 163, 184, 0.5);
  flex-shrink: 0;
}

#userNickname {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-history-btn {
  font-size: 0.76rem;
  padding: 6px 10px;
  min-height: 30px;
  box-shadow: none;
}

@media (max-width: 640px) {
  header {
    padding-right: 0;
  }

  .user-tools {
    position: static;
    align-self: flex-end;
    max-width: 100%;
  }

  .user-profile {
    max-width: 100%;
  }
}

.lang-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 4px;
}

.lang-switch select {
  border-radius: 999px;
  border: 1px solid rgba(209, 213, 219, 0.9);
  padding: 6px 10px;
  background: #fff;
  font-size: 0.8rem;
  color: var(--text);
}

.steps {
  display: grid;
  gap: 14px;
}

.steps > .card {
  min-width: 0;
}

@media (min-width: 768px) {
  .steps {
    grid-template-columns: 1.1fr 1.1fr;
  }

  .steps > .card.full-row {
    grid-column: 1 / -1;
  }
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px 14px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  border: 1px solid rgba(148, 163, 184, 0.25);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
}

.card-subtitle {
  font-size: 0.8rem;
  color: var(--muted);
}

.file-label {
  border-radius: 999px;
  border: 1px dashed rgba(148, 163, 184, 0.8);
  padding: 8px 12px;
  font-size: 0.85rem;
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  background: #f9fafb;
  transition: all 0.15s ease;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-label:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}

.file-label input {
  display: none;
}

.status {
  font-size: 0.8rem;
  color: var(--muted);
  min-height: 1.2em;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.status.success {
  color: var(--success);
}

.status.error {
  color: var(--danger);
}

.status.info {
  color: var(--primary);
}

.preview-wrapper {
  border-radius: 12px;
  background: #f9fafb;
  border: 1px solid rgba(209, 213, 219, 0.8);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preview-image {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: 8px;
  background: #e5e7eb;
}

audio {
  width: 100%;
  margin-top: 4px;
}

button {
  border: none;
  outline: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background-color 0.12s ease, color 0.12s ease;
}

button span.dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #bbf7d0;
}

button:disabled {
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

button:not(.btn-secondary):not(.btn-danger):disabled {
  background: #94a3b8;
  color: #e5e7eb;
}

button:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 30px rgba(37, 99, 235, 0.45);
}

.task-status-text {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.task-status-text strong {
  color: var(--primary);
}

.video-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

video {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(209, 213, 219, 0.9);
  background: #000;
  max-height: 360px;
}

.download-link {
  font-size: 0.85rem;
  color: var(--primary);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.download-link:hover {
  text-decoration: underline;
}

.helper-text {
  font-size: 0.75rem;
  color: var(--muted);
}

.field-label {
  font-size: 0.8rem;
  color: var(--text);
  font-weight: 600;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.overlay.hidden {
  display: none;
}

.overlay-content {
  background: #fff;
  border-radius: 16px;
  padding: 16px 20px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  max-width: 80%;
  text-align: center;
  font-size: 0.9rem;
}

.spinner {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 3px solid #e5e7eb;
  border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}

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

.overlay-text {
  color: var(--muted);
}

.footer-tip {
  margin-top: 12px;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: right;
}

.kb-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--muted);
  padding: 6px 2px;
}

.kb-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  background: #f9fafb;
  border: 1px solid rgba(209, 213, 219, 0.8);
  border-radius: 10px;
}

.kb-item-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kb-item span.name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kb-item span.meta {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  white-space: normal;
  word-break: break-word;
}

.kb-item-source {
  font-size: 0.7rem;
  color: #4b5563;
}

.kb-remove-btn {
  border: 1px solid rgba(209, 213, 219, 0.9);
  box-shadow: none;
  background: #fff;
  color: #6b7280;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  padding: 0;
  min-width: 28px;
  line-height: 1;
  font-size: 14px;
}

.kb-remove-btn:hover {
  background: #f3f4f6;
  box-shadow: none;
  transform: none;
}

.kb-existing-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(4px);
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.kb-existing-panel {
  width: 100%;
  max-width: 720px;
  max-height: 80vh;
  background: #fff;
  border-radius: 14px;
  border: 1px solid rgba(209, 213, 219, 0.9);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.28);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.kb-existing-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.kb-existing-title {
  font-size: 0.92rem;
  font-weight: 600;
}

.kb-modal-close {
  border: 1px solid rgba(209, 213, 219, 0.9);
  box-shadow: none;
  background: #fff;
  color: #6b7280;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  padding: 0;
  line-height: 1;
  font-size: 16px;
}

.kb-modal-close:hover {
  background: #f3f4f6;
  box-shadow: none;
  transform: none;
}

.kb-existing-list {
  border: 1px solid rgba(209, 213, 219, 0.9);
  border-radius: 10px;
  background: #f9fafb;
  overflow: auto;
  max-height: 48vh;
}

.image-existing-panel {
  max-width: 900px;
}

.video-history-panel {
  max-width: 980px;
}

.image-existing-list {
  border: 1px solid rgba(209, 213, 219, 0.9);
  border-radius: 10px;
  background: #f9fafb;
  overflow: auto;
  max-height: 52vh;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}

.image-existing-item {
  border: 1px solid rgba(209, 213, 219, 0.9);
  border-radius: 10px;
  background: #fff;
  padding: 6px;
  cursor: pointer;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.image-existing-item.selected {
  border-color: rgba(37, 99, 235, 0.95);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2) inset;
}

.image-existing-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  object-fit: cover;
  background: #e5e7eb;
}

.image-existing-meta {
  font-size: 0.72rem;
  color: #6b7280;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.image-existing-name {
  font-size: 0.78rem;
  color: #111827;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.video-history-list {
  border: 1px solid rgba(209, 213, 219, 0.9);
  border-radius: 10px;
  background: #f9fafb;
  overflow: auto;
  max-height: 62vh;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.video-history-item {
  border: 1px solid rgba(209, 213, 219, 0.9);
  border-radius: 10px;
  background: #fff;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.video-history-player {
  width: 100%;
  border-radius: 10px;
  background: #000;
  border: 1px solid rgba(209, 213, 219, 0.9);
  max-height: none;
}

.video-history-meta {
  font-size: 0.78rem;
  color: #6b7280;
  word-break: break-word;
}

.video-history-download {
  align-self: flex-start;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 8px 14px;
  border: 1px solid rgba(209, 213, 219, 0.9);
  background: #f3f4f6;
  color: #374151;
  font-size: 0.84rem;
  font-weight: 600;
}

.video-history-download:hover {
  background: #e5e7eb;
}

.kb-existing-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 10px;
  border-bottom: 1px solid rgba(229, 231, 235, 0.9);
}

.kb-existing-item:last-child {
  border-bottom: none;
}

.kb-existing-item input {
  margin-top: 2px;
}

.kb-existing-item-info {
  min-width: 0;
}

.kb-existing-item-name {
  font-size: 0.85rem;
  color: #111827;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kb-existing-item-meta {
  font-size: 0.74rem;
  color: #6b7280;
  word-break: break-word;
}

.kb-existing-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-top: 2px;
}

.kb-existing-actions-left,
.kb-existing-actions-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.kb-existing-actions-right {
  margin-left: auto;
}

@media (max-width: 640px) {
  .kb-existing-actions {
    flex-wrap: wrap;
    gap: 12px;
  }

  .kb-existing-actions-right {
    margin-left: 0;
    width: 100%;
    justify-content: flex-end;
  }
}

.script-editor-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.script-editor-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.script-editor {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  border-radius: 12px;
  border: 1px solid rgba(209, 213, 219, 0.9);
  padding: 10px 12px;
  font-size: 0.9rem;
  line-height: 1.5;
  outline: none;
}

.script-editor:focus {
  border-color: rgba(37, 99, 235, 0.8);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.script-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 1px solid rgba(209, 213, 219, 0.9);
  background: white;
  cursor: pointer;
  color: #111827; /* 让 currentColor 有值 */
}

.icon-btn:hover {
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}

.icon-btn svg {
  fill: #111827 !important;
  stroke: none;
  display: block;        /* 避免被 inline baseline 搞怪 */
  width: 18px;
  height: 18px;
  overflow: visible;
}

.script-view {
  white-space: pre-wrap;   /* 保留换行 */
  word-break: break-word;
  border-radius: 12px;
  border: 1px solid rgba(209, 213, 219, 0.9);
  background: #f9fafb;
  padding: 12px;
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--text);
}

/* ✅ 统一隐藏类：永远优先 */
.hidden {
  display: none !important;
}

.script-edit-area {
  background: #fefce8;   /* 很浅的黄色 */
  padding: 10px;
  border-radius: 12px;
  flex-direction: column;
  align-items: stretch !important;
  gap: 10px;
}

.script-edit-actions {
  gap: 10px;
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
}

.btn-secondary {
  background: #f3f4f6;
  border: 1px solid rgba(209, 213, 219, 0.9);
  color: #374151;          /* ✅ 深灰字 */
}

.btn-secondary:hover {
  background: #e5e7eb;
}

.btn-secondary:disabled {
  background: #f3f4f6;
  border-color: rgba(209, 213, 219, 0.9);
  color: #9ca3af;
}

.btn-danger {
  background: #dc2626;
  border: 1px solid #b91c1c;
  color: #fff;
  box-shadow: none;
}

.btn-danger:hover {
  background: #b91c1c;
  box-shadow: none;
  transform: none;
}

.btn-danger:disabled {
  background: #fca5a5;
  border-color: #fecaca;
  color: #fff;
}

.subject-pick-box{
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.subject-pick-title{
  font-weight: 600;
  margin-bottom: 10px;
}

.subject-pick-list{
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 10px;
}

.subject-item{
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  background: rgba(255,255,255,0.03);
  transition: transform .12s ease, border-color .12s ease;
}

.subject-item:hover{
  transform: translateY(-1px);
  border-color: rgba(255,255,255,0.25);
}

.subject-item.selected{
  border-color: rgba(99, 102, 241, 0.9);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.25) inset;
}

.subject-item img{
  width: 100%;
  height: 160px;
  object-fit: contain;
  border-radius: 10px;
  background: rgba(0,0,0,0.25);
}

.subject-item .subject-caption{
  margin-top: 8px;
  font-size: 12px;
  opacity: 0.9;
  word-break: break-all;
}
