/* ================================
   在线翻译工具 - 自定义样式
   配色与 Leowh 主页统一
   ================================ */

:root {
  --bg: #FAFAF9;
  --bg-alt: #F5F5F4;
  --surface: #FFFFFF;
  --border: #E7E5E4;
  --border-strong: #D6D3D1;
  --text: #1E293B;
  --text-secondary: #52525B;
  --text-muted: #71717A;
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --primary-light: rgba(79, 70, 229, 0.08);
  --secondary: #F97316;
  --accent: #EC4899;
  --success: #059669;
  --danger: #EF4444;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', 'Noto Sans SC', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Toast ── */
.toast {
  position: fixed; top: 24px; right: 24px;
  z-index: 10000;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 20px;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1);
  font-size: 14px; font-weight: 500;
  color: #1E293B;
  transform: translateX(120%);
  transition: transform 0.35s cubic-bezier(0.4,0,0.2,1);
  pointer-events: none;
  max-width: 90vw;
}
.toast.show { transform: translateX(0); }
.toast-dot { width: 8px; height: 8px; background: #4F46E5; border-radius: 50%; flex-shrink: 0; }

/* ── Page ── */
.page { max-width: 1100px; margin: 0 auto; padding: 0 32px; }

/* ── Header scroll effect ── */
#header.scrolled {
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 2px 20px rgba(0,0,0,0.06);
}

/* ══════════════════════════════════════════
   Tab Bar
   ══════════════════════════════════════════ */
.tab-bar {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.tab {
  display: flex; align-items: center; gap: 6px;
  padding: 12px 20px;
  background: none; border: none;
  border-bottom: 2px solid transparent;
  font-family: inherit; font-size: 14px; font-weight: 500;
  color: var(--text-muted); cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text-secondary); }
.tab.active { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: tab-fade-in 0.25s ease-out; }

@keyframes tab-fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ══════════════════════════════════════════
   Language Bar
   ══════════════════════════════════════════ */
.lang-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0 20px;
}
.lang-select-group {
  flex: 1; position: relative;
}
.lang-select {
  width: 100%; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit; font-size: 14px; color: var(--text);
  cursor: pointer; outline: none;
  transition: border-color 0.2s ease;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
.lang-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1); }
.lang-detect-hint {
  position: absolute; bottom: -20px; left: 4px;
  font-size: 11px; color: var(--primary); font-weight: 500;
  white-space: nowrap;
}

.swap-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-alt); border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-secondary); cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}
.swap-btn:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); transform: rotate(180deg); }

/* ══════════════════════════════════════════
   Translate Grid
   ══════════════════════════════════════════ */
.translate-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

.translate-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}

.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-alt);
}

.panel-title {
  font-size: 14px; font-weight: 600;
  color: var(--text);
}

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

.translate-textarea {
  width: 100%; flex: 1; min-height: 260px;
  padding: 16px;
  background: var(--bg); border: none;
  font-family: inherit; font-size: 15px; line-height: 1.6;
  color: var(--text); resize: none;
  outline: none;
}
.translate-textarea::placeholder { color: var(--text-muted); }

.translate-output {
  flex: 1; min-height: 260px; max-height: 500px;
  padding: 16px;
  background: var(--bg);
  font-size: 15px; line-height: 1.6;
  color: var(--text);
  overflow-y: auto;
  white-space: pre-wrap; word-break: break-word;
  border-left: 3px solid transparent;
  transition: border-left-color 0.6s ease-out;
}
.translate-output.translated {
  border-left-color: var(--success);
}

.output-placeholder {
  color: var(--text-muted); font-size: 14px;
}

.panel-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-alt);
}

.result-actions {
  display: flex; gap: 4px; align-items: center;
}

.translate-status {
  font-size: 11px; color: var(--primary); font-weight: 500;
  white-space: nowrap;
  display: flex; align-items: center; gap: 4px;
}

.status-spinner {
  width: 12px; height: 12px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
  flex-shrink: 0;
}

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

.retry-btn {
  padding: 8px 18px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 100px;
  font-family: inherit; font-size: 13px; font-weight: 500;
  color: var(--primary); cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex; align-items: center; gap: 5px;
}
.retry-btn:hover { border-color: var(--primary); background: var(--primary-light); transform: translateY(-1px); box-shadow: 0 2px 8px rgba(79,70,229,0.12); }

/* ── Buttons ── */
.btn-convert {
  padding: 10px 20px;
  background: var(--primary); border: none;
  border-radius: var(--radius);
  font-family: inherit; font-size: 14px; font-weight: 600;
  color: white; cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.btn-convert:hover { background: var(--primary-hover); box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25); }
.btn-convert:active { transform: scale(0.98); }
.btn-convert:disabled {
  opacity: 0.5; cursor: not-allowed;
  box-shadow: none;
}
.btn-convert:disabled:hover { background: var(--primary); }

.btn-ghost {
  padding: 8px 14px;
  background: none; border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit; font-size: 13px; font-weight: 500;
  color: var(--text-secondary); cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn-ghost:hover { border-color: var(--text-muted); color: var(--text); }
.btn-sm { font-size: 12px; padding: 6px 12px; }

.btn-secondary {
  padding: 10px 20px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit; font-size: 14px; font-weight: 600;
  color: var(--primary); cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-secondary:hover { background: var(--primary-light); border-color: var(--primary); }

.btn-icon {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-muted); cursor: pointer;
  transition: all 0.15s ease;
}
.btn-icon:hover { background: var(--bg); border-color: var(--border); color: var(--text); }
.btn-icon.recording {
  background: rgba(239,68,68,0.1); border-color: #ef4444; color: #ef4444;
  animation: pulse-rec 1.5s ease-in-out infinite;
}

@keyframes pulse-rec {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.3); }
  50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}

/* ══════════════════════════════════════════
   Batch Progress Bar
   ══════════════════════════════════════════ */
.batch-progress {
  display: flex; align-items: center; gap: 10px;
  flex: 1;
}
.batch-progress.hidden { display: none; }

.progress-bar {
  flex: 1; height: 6px; background: var(--border);
  border-radius: 3px; overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  border-radius: 3px;
  transition: width 0.3s ease;
}
.progress-text {
  font-size: 12px; color: var(--text-muted); white-space: nowrap;
}

/* ══════════════════════════════════════════
   Translation History
   ══════════════════════════════════════════ */
.history-section {
  margin-top: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.history-toggle {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 14px 20px;
  background: none; border: none;
  font-family: inherit; font-size: 14px; font-weight: 600;
  color: var(--text); cursor: pointer;
  transition: background 0.15s ease;
  user-select: none;
}
.history-toggle:hover { background: var(--bg-alt); }
.history-count {
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  background: var(--bg-alt); padding: 2px 8px; border-radius: 100px;
}
.history-clear-btn {
  font-size: 12px; font-weight: 500; color: var(--text-muted);
  background: none; border: none; cursor: pointer;
  padding: 4px 10px; border-radius: 4px;
  transition: all 0.15s ease;
}
.history-clear-btn:hover { color: var(--danger); background: rgba(239,68,68,0.08); }
.toggle-arrow {
  width: 16px; height: 16px; color: var(--text-muted);
  transition: transform 0.2s ease;
}
.history-toggle.open .toggle-arrow { transform: rotate(180deg); }

.history-list { max-height: 320px; overflow-y: auto; }
.history-list.hidden { display: none; }

/* ── Guide Section ── */
.guide-section {
  margin-top: 16px;
  margin-bottom: 64px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.guide-toggle {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 14px 20px;
  background: none; border: none;
  cursor: pointer;
  transition: background 0.15s ease;
}
.guide-toggle:hover { background: var(--bg-alt); }
.guide-toggle.open .toggle-arrow { transform: rotate(180deg); }
.guide-list { padding: 0 20px 20px; }
.guide-list.hidden { display: none; }
.guide-item {
  padding: 16px 0;
  border-top: 1px solid var(--border);
}
.guide-item:first-child { border-top: 1px solid var(--border); }
.guide-item-title {
  font-size: 14px; font-weight: 600; color: var(--text);
  margin-bottom: 6px;
}
.guide-item-body {
  font-size: 13px; color: var(--text-secondary); line-height: 1.8;
}
.guide-item-body kbd {
  padding: 1px 6px;
  background: var(--bg-alt); border: 1px solid var(--border-strong);
  border-radius: 4px;
  font-family: 'SF Mono', 'Cascadia Code', monospace;
  font-size: 12px; color: var(--text-secondary);
}

.history-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  transition: background 0.15s ease;
}
.history-item:hover { background: var(--bg-alt); }
.history-item-main { flex: 1; min-width: 0; cursor: pointer; }
.history-item-source {
  font-size: 13px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 2px;
}
.history-item-result {
  font-size: 14px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-item-meta {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; color: var(--text-muted);
  margin-top: 4px;
}
.history-item-lang {
  padding: 1px 6px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 4px;
  font-size: 10px; font-weight: 600;
}
.history-item-delete {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none;
  color: var(--text-muted); cursor: pointer;
  border-radius: 6px; flex-shrink: 0;
  transition: all 0.15s ease;
}
.history-item-delete:hover { background: rgba(239,68,68,0.1); color: var(--danger); }

.history-empty {
  padding: 32px 20px; text-align: center;
  color: var(--text-muted); font-size: 14px;
}

/* ══════════════════════════════════════════
   Drop Zone
   ══════════════════════════════════════════ */
.drop-zone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: 20px;
}
.drop-zone:hover { border-color: var(--primary); background: var(--primary-light); }
.drop-zone.drag-over { border-color: var(--primary); background: var(--primary-light); }
.drop-zone-icon {
  color: var(--text-muted);
  margin-bottom: 12px;
}
.drop-zone-title {
  font-size: 15px; font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.drop-zone-hint {
  font-size: 13px; color: var(--text-muted);
}

/* ══════════════════════════════════════════
   Document Preview
   ══════════════════════════════════════════ */
.doc-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
  overflow: hidden;
}
.doc-preview.hidden { display: none; }

.doc-preview-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
}

.doc-preview-text {
  max-height: 200px; overflow-y: auto;
  padding: 16px; font-size: 14px; line-height: 1.7;
  color: var(--text); white-space: pre-wrap; word-break: break-word;
}

/* ══════════════════════════════════════════
   Document Result
   ══════════════════════════════════════════ */
.doc-result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 24px;
}
.doc-result.hidden { display: none; }

.doc-result-text {
  max-height: 400px; overflow-y: auto;
  padding: 16px; font-size: 15px; line-height: 1.7;
  color: var(--text); white-space: pre-wrap; word-break: break-word;
}

/* ══════════════════════════════════════════
   Image Workspace
   ══════════════════════════════════════════ */
.image-workspace {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}
.image-workspace.hidden { display: none; }

.image-preview-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.image-preview-wrap {
  padding: 16px;
  display: flex; align-items: center; justify-content: center;
  background: #f0f0f0;
  min-height: 300px;
}
.image-preview-img {
  max-width: 100%; max-height: 400px;
  object-fit: contain; border-radius: 4px;
}

.ocr-result-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}

.ocr-status {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-muted);
}
.ocr-status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-muted);
}
.ocr-status-dot.processing { background: var(--accent); animation: pulse 1.5s ease-in-out infinite; }
.ocr-status-dot.done { background: var(--success); }

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

.ocr-text {
  flex: 1; min-height: 160px; max-height: 300px;
  padding: 16px; font-size: 14px; line-height: 1.7;
  color: var(--text); overflow-y: auto;
  white-space: pre-wrap; word-break: break-word;
}

/* ══════════════════════════════════════════
   Image Result
   ══════════════════════════════════════════ */
.image-result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 24px;
}
.image-result.hidden { display: none; }

.image-result-text {
  max-height: 400px; overflow-y: auto;
  padding: 16px; font-size: 15px; line-height: 1.7;
  color: var(--text); white-space: pre-wrap; word-break: break-word;
}

/* ── Footer ── */
.footer {
  padding: 24px 0;
  border-top: 1px solid var(--border);
  text-align: center; font-size: 13px; color: var(--text-muted);
}
.footer-sep { margin: 0 8px; color: var(--border-strong); }

/* ── Custom scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #A5B4FC; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #4F46E5; }

::selection { background: rgba(79, 70, 229, 0.2); }

/* ══════════════════════════════════════════
   Responsive
   ══════════════════════════════════════════ */
@media (max-width: 768px) {
  .page { padding: 0 16px; }

  .translate-grid { grid-template-columns: 1fr; }
  .image-workspace { grid-template-columns: 1fr; }

  .lang-bar { flex-wrap: wrap; }
  .lang-select-group { flex: 1 1 40%; }
  .swap-btn { margin-top: 0; }

  .tab { font-size: 13px; padding: 10px 14px; }

  .translate-textarea { min-height: 140px; }
  .translate-output { min-height: 140px; max-height: 300px; }

  .drop-zone { padding: 32px 16px; }
}
/* ══════════════════════════════════════════
   Glossary Button (Tab Bar)
   ══════════════════════════════════════════ */
.tab-bar {
  justify-content: flex-start;
  position: relative;
}

.glossary-trigger {
  display: flex; align-items: center; gap: 6px;
  margin-left: auto;
  padding: 8px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit; font-size: 13px; font-weight: 500;
  color: var(--text-secondary); cursor: pointer;
  transition: all 0.2s ease;
}
.glossary-trigger:hover {
  background: var(--primary-light); border-color: var(--primary); color: var(--primary);
}

/* ══════════════════════════════════════════
   Glossary Modal
   ══════════════════════════════════════════ */
.glossary-modal {
  display: none;
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 2000;
  align-items: center; justify-content: center;
}
.glossary-modal.show { display: flex; }

.glossary-modal-content {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 90%; max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.glossary-list-items {
  display: flex; flex-direction: column; gap: 6px;
}

.glossary-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-alt);
  border-radius: var(--radius);
  font-size: 14px;
}

.glossary-item-text {
  color: var(--text);
  font-weight: 500;
}

.glossary-empty {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ══════════════════════════════════════════
   Image Language Bar
   ══════════════════════════════════════════ */
.image-lang-bar .lang-select {
  padding: 6px 30px 6px 10px;
  font-size: 13px;
}

.image-lang-bar .swap-btn {
  width: 32px; height: 32px;
}

@media (max-width: 768px) {
  .glossary-modal-content { width: 95%; padding: 16px; }
  .glossary-trigger span { display: none; }
  .image-lang-bar { flex-wrap: wrap; }
}

/* ══════════════════════════════════════════
   Glossary Hint Banner
   ══════════════════════════════════════════ */
.glossary-hint {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  margin-bottom: 16px;
  background: var(--primary-light);
  border: 1px solid rgba(79, 70, 229, 0.15);
  border-radius: var(--radius);
  font-size: 13px; color: var(--text-secondary);
  animation: tab-fade-in 0.3s ease-out;
}
.glossary-hint.hidden { display: none; }
.glossary-hint-link {
  background: none; border: none;
  font-family: inherit; font-size: 13px; font-weight: 600;
  color: var(--primary); cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px;
  padding: 0;
  transition: color 0.15s ease;
}
.glossary-hint-link:hover { color: var(--primary-hover); }
.glossary-hint-close {
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none;
  color: var(--text-muted); cursor: pointer;
  border-radius: 4px; flex-shrink: 0;
  transition: all 0.15s ease;
}
.glossary-hint-close:hover { background: rgba(0,0,0,0.06); color: var(--text); }

/* ══════════════════════════════════════════
   OCR Progress Bar
   ══════════════════════════════════════════ */
.ocr-progress-wrap { margin-top: 12px; }
.ocr-progress-wrap.hidden { display: none; }
.ocr-progress-bar {
  width: 100%; height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.ocr-progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 2px;
  transition: width 0.3s ease;
}
.ocr-progress-label {
  font-size: 12px; color: var(--text-muted);
  margin-top: 4px;
}
