/* styles.css — 现代化简洁美观 + 响应式布局 */
:root {
  --bg: #f7f8fa;
  --card: #ffffff;
  --muted: #6b7280;
  --text: #1a1f29;
  --primary: #2563eb;
  --primary-600: #1d4ed8;
  --border: #e5e7eb;
  --ok: #35c759;
  --danger: #ef4444;
  --panel: #ffffff;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  font-weight: 600;
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

input,
textarea,
select {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  font-size: 14px;
  font-family: inherit;
  transition: all 0.2s;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 16px;
  cursor: pointer;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 8px;
  cursor: pointer;
}

.icon-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.btn.primary:hover {
  background: var(--primary-600);
}

.btn.ghost {
  background: transparent;
}

.btn.small {
  padding: 6px 10px;
}

.layout {
  display: grid;
  /* 左侧占 1/3，右侧占 2/3，设置成两个1则是 */
  grid-template-columns: 1fr 2fr;
  gap: 18px;
  padding: 18px;
  grid-template-rows: 1fr;
  flex: 1;
}

.left-panel,
.right-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.controls {
  margin-bottom: 12px;
}

.lang-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.select-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lang-row .custom-select-trigger,
.lang-row .btn,
.lang-row .icon-btn {
  height: 40px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  font-size: 14px;
}

.lang-row .custom-select-container {
  min-width: 150px;
}

.lang-row #swap-lang {
  width: 40px;
  min-width: 40px;
  justify-content: center;
  padding: 0;
}

.lang-row #model-select-btn {
  padding: 0 16px;
}

.input-area textarea {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Microsoft YaHei", sans-serif;
}

.input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}

.stats {
  color: var(--muted);
  display: flex;
  gap: 6px;
  align-items: baseline;
}

.output-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  color: var(--muted);
}

.outputs-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  overflow: auto;
}

.output-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  min-height: 200px;
}

.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.output-body {
  flex: 1;
  white-space: pre-wrap;
}

.output-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.drag-handle {
  cursor: grab;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: grid;
  place-items: center;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: min(880px, 92vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
}

.modal-content.large {
  width: min(1000px, 94vw);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.modal-body {
  padding: 12px;
  overflow: auto;
}

.modal-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}

.tab {
  background: transparent;
  border: none;
  color: var(--text);
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.tab.active {
  border-bottom-color: var(--primary);
  color: var(--primary);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.form-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 12px;
}

.row {
  display: flex;
  gap: 8px;
}

.storage-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.app-footer {
  padding: 16px;
  text-align: center;
  color: var(--muted);
}

/* 响应式 */
@media (max-width: 1024px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

/* 小动画 */
.btn,
.icon-btn {
  transition: all .15s ease;
}

.output-card {
  transition: box-shadow .2s ease;
}

.output-card:hover {
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.1);
}

/* 模型选择摘要样式 */
#i18n-source-lang-label,
#i18n-target-lang-label,
#model-count-badge,
#model-order-summary {
  display: none !important;
}

/* 设置弹窗中的 API 配置左右布局 */
.settings-split {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 12px;
}

.api-sidebar {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
}

.api-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.api-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.api-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}

.api-item:hover {
  background: rgba(0, 0, 0, 0.03);
}

.api-item.active {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(79, 140, 255, 0.08);
}

.api-detail {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.api-detail .form-grid {
  grid-template-columns: 1fr;
}

@media (max-width: 860px) {
  .settings-split {
    grid-template-columns: 1fr;
  }
}

/* 主题配色 */
:root[data-theme="dark"] {
  --bg: linear-gradient(180deg, #0b0f14 0%, #0d1218 100%);
  --card: #121821;
  --muted: #8aa0b6;
  --text: #e9eef5;
  --primary: #4f8cff;
  --primary-600: #3b74e6;
  --border: #1e2733;
  --ok: #35c759;
  --danger: #ff4d4f;
  --panel: rgba(18, 24, 33, 0.7);
}

:root[data-theme="solar"] {
  --bg: #fff9eb;
  --card: #fff5d8;
  --muted: #8b7e67;
  --text: #3b3a2e;
  --primary: #ff9f1c;
  --primary-600: #e0890a;
  --border: #f3e2b8;
  --ok: #10b981;
  --danger: #ef4444;
  --panel: #fff6e1;
}

:root[data-theme="moss"] {
  --bg: #0f1f17;
  --card: #14261d;
  --muted: #8fb29c;
  --text: #e8f1e9;
  --primary: #34d399;
  --primary-600: #10b981;
  --border: #1b3a2c;
  --ok: #35c759;
  --danger: #ff4d4f;
  --panel: #153226;
}

:root[data-theme="mono"] {
  --bg: #f6f6f6;
  --card: #ffffff;
  --muted: #888888;
  --text: #121212;
  --primary: #121212;
  --primary-600: #222222;
  --border: #e0e0e0;
  --ok: #35c759;
  --danger: #ef4444;
  --panel: #ffffff;
}

/* 在模板列表中为当前激活的模板名称添加绿色圆点标注 */
#prompt-templates-list .api-item .name {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

#prompt-templates-list .api-item .name::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 2px solid var(--success, #22c55e);
  background: transparent;
  opacity: 0;
  transition: opacity .2s ease, background .2s ease;
}

#prompt-templates-list .api-item.active .name::before {
  opacity: 1;
  background: var(--success, #22c55e);
}

/* 隐藏“当前使用”文案占位（不再需要） */
#current-prompt-active {
  display: none;
}

/* 右侧详情区域的模板名称输入优化 */
#prompt-detail .form-item input#prompt-template-name {
  width: 100%;
}

.api-sidebar .api-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 45vh;
  overflow: auto;
  padding-right: 4px;
}

.api-sidebar .api-item {
  padding: 8px 10px;
  border: 1px solid var(--border, #ddd);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.api-sidebar .api-item.active {
  background: var(--primary-weak, #f0f6ff);
  border-color: var(--primary, #3b82f6);
}

.api-sidebar .api-item .name {
  font-weight: 600;
}

.api-sidebar .api-item .badge {
  font-size: 12px;
  color: var(--primary, #3b82f6);
}

.current-badge {
  color: var(--text-secondary, #666);
}

/* Prompt detail improvements */
#prompt-detail .form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

#prompt-detail .form-item textarea {
  width: 100%;
  box-sizing: border-box;
}

#prompt-detail .form-item .row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* Buttons */
.btn.small {
  padding: 6px 10px;
  font-size: 12px;
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--border, #ddd);
}

/* ===== Toast 提示样式 ===== */
#toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
  /* 不阻挡点击 */
}

.toast {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  border-radius: 12px;
  padding: 10px 14px;
  min-width: 240px;
  max-width: 60vw;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transform: translateY(12px);
  animation: toast-in .18s ease forwards;
}

.toast.success {
  border-color: var(--ok);
}

.toast.error {
  border-color: var(--danger);
}

.toast .icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
}

.toast.success .icon {
  background: var(--ok);
}

.toast.error .icon {
  background: var(--danger);
}

.toast .msg {
  font-size: 14px;
}

.toast.fade-out {
  animation: toast-out .18s ease forwards;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toast-out {
  from {
    opacity: 1;
    transform: translateY(0);
  }

  to {
    opacity: 0;
    transform: translateY(-6px);
  }
}

/* 暗色主题下阴影与边界适配 */
:root[data-theme="dark"] .toast {
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

.output-content {
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Microsoft YaHei", sans-serif;
}

/* ===== 模型列表弹窗美化与拖拽动画 ===== */
#model-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#model-list .list-header {
  font-weight: 600;
  color: var(--muted);
  padding: 6px 2px;
}

#selected-models-list,
#unselected-models-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 24px;
}

#selected-models-list.drag-active {
  outline: 2px dashed var(--primary);
  outline-offset: 4px;
  border-radius: 12px;
  padding: 4px;
}

#selected-models-list.dragging-context .row,
#selected-models-list.dragging-context .drag-placeholder {
  transition: none !important;
}

#selected-models-list .row,
#unselected-models-list .row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
  min-height: 40px;
}

#selected-models-list .row:hover,
#unselected-models-list .row:hover {
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
}

#selected-models-list .row.dragging {
  opacity: .9;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
  cursor: grabbing;
}

#selected-models-list .drag-handle {
  margin-left: auto;
  cursor: grab;
  color: var(--muted);
  font-weight: 700;
}

#selected-models-list .drag-handle:active {
  cursor: grabbing;
}

.drag-placeholder {
  background: linear-gradient(180deg, rgba(79, 140, 255, 0.08), rgba(79, 140, 255, 0.02));
  border: 1px dashed var(--primary);
  border-radius: 12px;
  margin: 4px 0;
  height: 40px;
  /* 与行高度一致，避免抖动 */
}

/* label 与 checkbox 对齐优化 */
#selected-models-list .row label,
#unselected-models-list .row label {
  flex: 1;
}

#selected-models-list .row input[type="checkbox"],
#unselected-models-list .row input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

/* 让列表项在占位插入和拖拽时有轻微位移动画以增强反馈 */
#selected-models-list .row:not(.dragging) {
  will-change: transform;
}


/* ===== SortableJS 拖拽动画样式 ===== */
.sortable-list {
  min-height: 60px;
}

/* 被选中准备拖动的元素 */
.sortable-chosen {
  cursor: grabbing !important;
  opacity: 1;
}

/* 拖动时的占位符（虚影） */
.sortable-ghost {
  opacity: 0.4 !important;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.1), rgba(79, 140, 255, 0.05)) !important;
  border: 2px dashed var(--primary) !important;
  transform: scale(0.98);
}

/* 正在拖动的元素 */
.sortable-drag {
  cursor: grabbing !important;
  transform: rotate(3deg) scale(1.05);
  box-shadow: 0 12px 32px rgba(37, 99, 235, 0.25) !important;
  opacity: 0.95;
  z-index: 9999;
}

/* 拖拽过程中的过渡动画 */
.sortable-list .row {
  transition: transform 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94),
    opacity 0.2s ease,
    box-shadow 0.2s ease;
}

/* 拖动手柄样式优化 */
.sortable-list .drag-handle {
  cursor: grab;
  user-select: none;
  transition: color 0.15s ease, transform 0.15s ease;
}

.sortable-list .drag-handle:hover {
  color: var(--primary);
  transform: scale(1.15);
}

.sortable-list .drag-handle:active {
  cursor: grabbing;
}

/* 拖拽时禁用选择 */
.sortable-list.sortable-active {
  user-select: none;
}

/* Custom Select Styles */
.custom-select-container {
  position: relative;
  display: inline-block;
  width: 100%;
}

.custom-select-trigger {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: all 0.2s;
  /* min-height removed */
}

.custom-select-trigger:after {
  content: '';
  width: 16px;
  height: 16px;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: center;
  margin-left: 8px;
}

.custom-select-options {
  position: fixed;
  top: 0;
  left: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
  margin-top: 0;
  z-index: 10005;
  max-height: 280px;
  overflow-y: auto;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1), transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.2s;
}

.custom-select-options.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.custom-option {
  padding: 10px 12px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  transition: background 0.1s;
}

.custom-option:hover {
  background: var(--bg);
  color: var(--primary);
}

.custom-option.selected {
  background: rgba(37, 99, 235, 0.08);
  font-weight: 500;
  color: var(--primary);
}

.custom-select-options::-webkit-scrollbar {
  width: 6px;
}

.custom-select-options::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

.custom-select-options::-webkit-scrollbar-track {
  background: transparent;
}