/* ==================== Reset & Variables ==================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-light: #fef2f2;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ==================== Layout ==================== */
.app {
  display: flex;
  min-height: 100vh;
}

/* ==================== Sidebar ==================== */
.sidebar {
  width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  border-bottom: 1px solid var(--border);
  color: var(--primary);
  font-size: 20px;
  font-weight: 700;
}

.nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 15px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  text-align: left;
  width: 100%;
}

.nav-item:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.8;
}

/* ==================== Main Content ==================== */
.main {
  flex: 1;
  margin-left: 260px;
  padding: 40px 48px;
  max-width: 960px;
}

/* ==================== Tool Panels ==================== */
.tool-panel {
  display: none;
}

.tool-panel.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

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

.tool-header {
  margin-bottom: 32px;
}

.tool-header h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.tool-header p {
  color: var(--text-secondary);
  font-size: 16px;
}

/* ==================== Upload Area ==================== */
.upload-area {
  margin-bottom: 24px;
}

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--surface);
}

.upload-zone:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.upload-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
}

.upload-zone svg {
  color: var(--text-muted);
  margin-bottom: 12px;
}

.upload-zone p {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.upload-zone span {
  font-size: 13px;
  color: var(--text-muted);
}

/* ==================== Selected File Display ==================== */
.selected-file {
  margin-top: 12px;
  padding: 12px 16px;
  background: var(--primary-light);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--primary);
  font-weight: 500;
}

.selected-file .remove-file {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
}

.selected-file .remove-file:hover {
  background: rgba(0,0,0,0.1);
}

/* ==================== File List (Merge) ==================== */
.file-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.file-item:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.file-item.dragging {
  opacity: 0.5;
  border-color: var(--primary);
}

.file-item .drag-handle {
  cursor: grab;
  color: var(--text-muted);
  padding: 4px;
}

.file-item .drag-handle:active {
  cursor: grabbing;
}

.file-item .file-icon {
  color: var(--primary);
  flex-shrink: 0;
}

.file-item .file-name {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-item .file-size {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.file-item .remove-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: all var(--transition);
}

.file-item .remove-btn:hover {
  color: var(--danger);
  background: var(--danger-light);
}

.file-item .order-badge {
  background: var(--primary-light);
  color: var(--primary);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

/* ==================== Buttons ==================== */
.btn-primary, .btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  margin-top: 16px;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: var(--shadow-md);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
  box-shadow: var(--shadow-md);
}

.btn-primary:disabled, .btn-danger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ==================== Option Cards ==================== */
.split-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.option-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
}

.option-card h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
}

.option-card p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.text-input {
  width: 100%;
  padding: 10px 14px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: all var(--transition);
  background: var(--bg);
  margin-bottom: 8px;
}

.text-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* ==================== Rotate Buttons ==================== */
.rotate-buttons {
  display: flex;
  gap: 12px;
}

.rotate-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: all var(--transition);
  flex: 1;
  color: var(--text-secondary);
}

.rotate-option:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.rotate-option.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.rotate-option span {
  font-size: 13px;
  font-weight: 500;
}

/* ==================== Progress Bar ==================== */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 16px;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  width: 0%;
  animation: indeterminate 1.5s ease-in-out infinite;
}

@keyframes indeterminate {
  0% { width: 0%; margin-left: 0; }
  50% { width: 60%; margin-left: 20%; }
  100% { width: 0%; margin-left: 100%; }
}

/* ==================== Status Text ==================== */
.status-text {
  margin-top: 12px;
  font-size: 14px;
  color: var(--text-secondary);
}

.status-text.success {
  color: #16a34a;
}

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

/* ==================== Info Result ==================== */
.info-result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.info-table {
  width: 100%;
  border-collapse: collapse;
}

.info-table th,
.info-table td {
  text-align: left;
  padding: 14px 20px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

.info-table th {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
  width: 160px;
}

.info-table td {
  color: var(--text);
}

.info-table tr:last-child td,
.info-table tr:last-child th {
  border-bottom: none;
}

/* ==================== Toast ==================== */
.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 14px 20px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  font-size: 14px;
  font-weight: 500;
  animation: slideIn 0.3s ease;
  border-left: 4px solid var(--primary);
  min-width: 280px;
  max-width: 420px;
}

.toast.success {
  border-left-color: #16a34a;
}

.toast.error {
  border-left-color: var(--danger);
}

.toast.info {
  border-left-color: #0ea5e9;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(100%); }
  to { opacity: 1; transform: translateX(0); }
}

/* ==================== PDF Editor ==================== */
.edit-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 50;
}

.btn-sm {
  padding: 8px 14px;
  font-size: 13px;
  margin-top: 0;
}

.toolbar-sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}

.zoom-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  min-width: 40px;
  text-align: center;
}

.toolbar-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
}

.edit-page-card {
  position: relative;
  margin-bottom: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  display: inline-block;
  overflow: hidden;
}

.edit-page-card canvas {
  display: block;
}

.annotations-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.annotation-item {
  position: absolute;
  pointer-events: auto;
  cursor: move;
  user-select: none;
  border: 2px solid transparent;
  border-radius: 4px;
  min-width: 20px;
  min-height: 20px;
}

.annotation-item:hover {
  border-color: rgba(79, 70, 229, 0.4);
}

.annotation-item.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.annotation-text {
  background: rgba(255, 255, 200, 0.9);
  padding: 6px 10px;
  font-size: 14px;
  color: #333;
  border-radius: 4px;
  white-space: pre-wrap;
  word-break: break-word;
  outline: none;
  min-width: 40px;
  min-height: 24px;
  display: flex;
  align-items: center;
}

.annotation-image {
  background: transparent;
}

.annotation-image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.annotation-resize-handle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: var(--primary);
  border: 1px solid white;
  border-radius: 50%;
  pointer-events: auto;
}

.resize-nw { top: -4px; left: -4px; cursor: nw-resize; }
.resize-ne { top: -4px; right: -4px; cursor: ne-resize; }
.resize-sw { bottom: -4px; left: -4px; cursor: sw-resize; }
.resize-se { bottom: -4px; right: -4px; cursor: se-resize; }

/* ==================== PDF Translator ==================== */
.translate-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 50;
}

.translate-mode-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.translate-mode-btn {
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 6px;
  transition: all var(--transition);
}

.translate-mode-btn.active {
  background: var(--primary);
  color: white;
}

.translate-mode-btn:hover:not(.active) {
  color: var(--primary);
}

.translate-lang {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}

.translate-lang select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  cursor: pointer;
}

.translate-lang select:focus {
  border-color: var(--primary);
}

/* Text layer for PDF selection */
.textLayer {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  opacity: 0.2;
  line-height: 1.0;
}

.textLayer ::selection {
  background: rgba(79, 70, 229, 0.3);
}

.textLayer span {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
}

.textLayer .highlighted {
  background-color: rgba(255, 220, 100, 0.4);
}

/* Translate page card wrapper */
.translate-page-card {
  position: relative;
  margin-bottom: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  display: inline-block;
  overflow: hidden;
}

.translate-page-card canvas {
  display: block;
}

/* Floating popup */
.translate-popup {
  position: fixed;
  z-index: 9999;
  width: 360px;
  max-height: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0,0,0,0.15);
  overflow: hidden;
  animation: fadeIn 0.15s ease;
}

.translate-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--primary-light);
  border-bottom: 1px solid var(--border);
}

.translate-popup-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
}

.translate-popup-close {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.translate-popup-close:hover {
  color: var(--text);
}

.translate-popup-original {
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  max-height: 100px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}

.translate-popup-divider {
  height: 1px;
  background: var(--border);
  margin: 0 14px;
}

.translate-popup-result {
  padding: 12px 14px;
  font-size: 14px;
  color: var(--text);
  max-height: 140px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
}

/* Full translation: two-column layout */
.translate-full-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
  max-height: calc(100vh - 200px);
}

.translate-pdf-col {
  overflow-y: auto;
  max-height: calc(100vh - 200px);
  padding-right: 8px;
}

.translate-pdf-col .translate-page-card {
  transform-origin: top left;
}

.translate-result-col {
  overflow-y: auto;
  max-height: calc(100vh - 200px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.translate-result-inner {
  padding: 4px 0;
}

.translate-result-page-label {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 700;
  color: white;
  background: var(--primary);
  position: sticky;
  top: 0;
  z-index: 2;
}

.translate-result-para {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.translate-result-para:last-child {
  border-bottom: none;
}

.translate-result-original {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 8px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 4px;
  border-left: 3px solid var(--border);
}

.translate-result-translated {
  font-size: 14px;
  color: var(--text);
  line-height: 1.7;
  padding: 8px 10px;
  background: rgba(79, 70, 229, 0.03);
  border-radius: 4px;
  border-left: 3px solid var(--primary);
}

.translate-result-original-label,
.translate-result-translated-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.translate-result-original-label { color: var(--text-muted); }
.translate-result-translated-label { color: var(--primary); }

#translate-progress-text {
  font-size: 13px;
  color: var(--text-muted);
}

/* Paragraph indicator line */
.translate-para-gap {
  height: 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

/* ==================== Responsive ==================== */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    position: relative;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 12px;
  }

  .logo { padding: 8px 12px; font-size: 16px; border: none; }
  .nav { flex-direction: row; flex-wrap: wrap; padding: 8px; }
  .nav-item { padding: 8px 12px; font-size: 13px; }
  .nav-item span { display: none; }
  .sidebar-footer { display: none; }
  .main { margin-left: 0; padding: 24px 16px; }
  .split-options { grid-template-columns: 1fr; }
  .rotate-buttons { flex-direction: column; }
}
