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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #232734;
  --border: #2e3347;
  --text: #e2e4ed;
  --text-muted: #8b8fa3;
  --primary: #6c8aff;
  --primary-hover: #8ba3ff;
  --success: #4ade80;
  --success-hover: #6ee7a0;
  --danger: #f87171;
  --danger-hover: #fca5a5;
  --warning: #fbbf24;
  --accent: #a78bfa;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--primary);
}

.badge {
  font-size: 0.6rem;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-left: 8px;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Buttons */
.btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  background: var(--border);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-sm {
  padding: 5px 12px;
  font-size: 0.8rem;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 700;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-success {
  background: var(--success);
  color: #111;
  border-color: var(--success);
}

.btn-success:hover:not(:disabled) {
  background: var(--success-hover);
  border-color: var(--success-hover);
}

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

.btn-danger:hover:not(:disabled) {
  background: var(--danger);
  color: #fff;
}

.btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.upload-btn {
  display: inline-flex;
  align-items: center;
  padding: 8px 16px;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s;
}

.upload-btn:hover {
  background: var(--primary-hover);
}

/* Timing badge */
.timing-badge {
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(167, 139, 250, 0.15);
  color: var(--accent);
  padding: 4px 12px;
  border-radius: 12px;
  border: 1px solid rgba(167, 139, 250, 0.3);
}

/* Drop Zone */
.drop-zone {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 40px;
  border: 2px dashed var(--border);
  border-radius: 16px;
  transition: all 0.2s;
  cursor: pointer;
}

.drop-zone.drag-over {
  border-color: var(--primary);
  background: rgba(108, 138, 255, 0.05);
}

.drop-zone-content {
  text-align: center;
  color: var(--text-muted);
}

.drop-zone-content svg {
  margin-bottom: 16px;
  opacity: 0.5;
}

.drop-zone-content p {
  font-size: 1.1rem;
  margin-bottom: 8px;
}

.drop-zone-hint {
  font-size: 0.85rem;
  opacity: 0.6;
}

/* Workspace */
.workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

.hidden {
  display: none !important;
}

/* Thumbnail Panel */
.thumbnail-panel {
  width: 160px;
  min-width: 80px;
  max-width: 400px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.thumbnail-header {
  padding: 10px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.thumbnail-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.thumbnail-item {
  position: relative;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 6px;
  overflow: hidden;
  transition: border-color 0.15s;
  flex-shrink: 0;
}

.thumbnail-item:hover {
  border-color: var(--border);
}

.thumbnail-item.active {
  border-color: var(--primary);
}

.thumbnail-item canvas {
  width: 100%;
  display: block;
}

.thumbnail-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.7);
  color: #fff;
  font-size: 0.7rem;
  text-align: center;
  padding: 2px;
}

.thumbnail-ocr-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--success);
  color: #111;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
}

.thumbnail-delete {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 0.65rem;
  font-weight: 700;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  line-height: 1;
}

.thumbnail-item:hover .thumbnail-delete {
  opacity: 1;
}

.thumbnail-item.dragging {
  opacity: 0.3;
}

.thumbnail-item.drag-over-top {
  border-top: 3px solid var(--primary);
}

.thumbnail-item.drag-over-bottom {
  border-bottom: 3px solid var(--primary);
}

/* Resize Handles */
.resize-handle {
  width: 5px;
  flex-shrink: 0;
  cursor: col-resize;
  background: var(--border);
  transition: background 0.15s;
  position: relative;
  z-index: 5;
}

.resize-handle:hover,
.resize-handle.active {
  background: var(--primary);
}

/* Viewer Panel */
.viewer-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.toolbar-spacer {
  flex: 1;
}

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

.toolbar-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 42px;
  text-align: center;
}

#pageIndicator {
  font-size: 0.85rem;
  color: var(--text-muted);
  min-width: 90px;
  text-align: center;
}

.viewer-container {
  flex: 1;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px;
  position: relative;
}

#pageCanvas {
  box-shadow: var(--shadow);
  border-radius: 4px;
  transition: width 0.15s;
}

#pageCanvas.clickable {
  cursor: pointer;
}

/* Text Panel */
.text-panel {
  width: 320px;
  min-width: 150px;
  max-width: 600px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.text-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.text-header-actions {
  display: flex;
  gap: 4px;
}

.ocr-textarea {
  flex: 1;
  padding: 14px;
  background: var(--surface-2);
  color: var(--text);
  border: none;
  resize: none;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  outline: none;
}

.ocr-textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

.ocr-textarea:disabled {
  opacity: 0.5;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 32px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  min-width: 380px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.modal-header h3 {
  font-size: 1.05rem;
  font-weight: 600;
}

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

.shortcuts-table td {
  padding: 6px 0;
  font-size: 0.85rem;
}

.shortcuts-table td:first-child {
  width: 180px;
  color: var(--text-muted);
}

kbd {
  display: inline-block;
  padding: 2px 7px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text);
  min-width: 22px;
  text-align: center;
}

/* Progress Overlay */
.progress-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.progress-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 40px;
  min-width: 360px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.progress-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.progress-bar-container {
  height: 8px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 12px;
}

.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  width: 0%;
  transition: width 0.3s;
}

.progress-status {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.progress-pages {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
}

/* Language select */
select.btn {
  appearance: auto;
  padding-right: 8px;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
