/* HellenScribe — dark theme */

:root {
  --bg:        #0f172a;
  --surface:   #1e293b;
  --surface2:  #2d3f55;
  --border:    #334155;
  --text:      #e2e8f0;
  --muted:     #94a3b8;
  --accent:    #3b82f6;
  --green:     #22c55e;
  --amber:     #f59e0b;
  --red:       #ef4444;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
}

/* ------------------------------------------------------------------ */
/* Shared utilities                                                     */
/* ------------------------------------------------------------------ */
.muted  { color: var(--muted); }
.small  { font-size: 12px; }
.spacer { flex: 1; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

kbd {
  display: inline-block;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 11px;
  font-family: monospace;
}

button { cursor: pointer; font-family: inherit; }

.btn-primary {
  display: inline-block;
  padding: 9px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
}
.btn-primary:hover { opacity: 0.85; }

.btn-sm {
  display: inline-block;
  padding: 4px 10px;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 12px;
  text-decoration: none;
}
.btn-sm:hover { background: var(--border); text-decoration: none; }
.btn-green { background: rgba(34,197,94,0.15); color: var(--green); border-color: var(--green); }
.btn-green:hover { background: rgba(34,197,94,0.25); }
.btn-red   { background: rgba(239,68,68,0.12); color: var(--red); border-color: var(--red); }
.btn-red:hover { background: rgba(239,68,68,0.22); }

.progress-wrap {
  display: inline-block;
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
  vertical-align: middle;
}
.progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 3px;
  transition: width 0.3s ease;
}

/* ------------------------------------------------------------------ */
/* Index page                                                          */
/* ------------------------------------------------------------------ */
header {
  padding: 20px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
header h1 { font-size: 22px; }
header p   { color: var(--muted); font-size: 12px; margin-top: 2px; }

.index-main {
  max-width: 860px;
  margin: 0 auto;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 24px;
}
.card h2 { font-size: 14px; font-weight: 600; margin-bottom: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.upload-form .form-row { margin-bottom: 12px; }
.upload-form label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.upload-form input[type="text"],
.upload-form input[type="file"] {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
}
.upload-form input:focus { outline: none; border-color: var(--accent); }

.doc-table { width: 100%; border-collapse: collapse; }
.doc-table th, .doc-table td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); }
.doc-table th { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.doc-table tr:last-child td { border-bottom: none; }
.doc-table .progress-wrap { width: 70px; margin-right: 6px; vertical-align: middle; }

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

.doc-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.doc-list-header h2 { margin-bottom: 0; }
.doc-list-actions { display: flex; gap: 6px; align-items: center; }

/* Folders */
.folder-group {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
  overflow: hidden;
}
.folder-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  background: var(--surface2);
  transition: background 0.15s;
}
.folder-header:hover { background: var(--border); }
.folder-icon {
  font-size: 10px;
  color: var(--muted);
  flex-shrink: 0;
  width: 14px;
  transition: transform 0.15s;
}
.folder-name { font-weight: 600; font-size: 13px; }
.folder-children { padding: 0 8px 8px; }

.doc-table-nested { font-size: 12px; }
.doc-table-nested td { padding: 5px 8px; }

/* Upload progress */
.upload-progress-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.hints-card .hints-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px 16px;
  font-size: 12px;
  color: var(--muted);
}

.empty-state { text-align: center; color: var(--muted); padding: 40px; }

.import-notice {
  background: rgba(34,197,94,0.12);
  border: 1px solid var(--green);
  border-radius: 6px;
  padding: 12px 16px;
  color: var(--green);
  font-size: 13px;
}

.field-hint {
  margin-top: 5px;
  font-size: 11px;
  color: var(--muted);
}

/* ------------------------------------------------------------------ */
/* Kraken segmentation overlay                                          */
/* ------------------------------------------------------------------ */
.seg-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(3px);
}

.seg-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px 36px;
  min-width: 340px;
  max-width: 480px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.seg-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
  letter-spacing: 0.02em;
}

.seg-msg {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 18px;
  min-height: 38px;
  line-height: 1.5;
  transition: color 0.3s;
}

.seg-bar-wrap {
  width: 100%;
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.seg-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--green));
  border-radius: 4px;
  transition: width 0.5s ease;
}

.seg-pct {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ */
/* Transcription layout                                                 */
/* ------------------------------------------------------------------ */
.transcribe-body {
  height: 100vh;
  overflow: hidden;
}

.transcribe-layout {
  display: flex;
  height: 100vh;
}

/* --- Left panel --- */
.panel-left {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-width: 0;
}

.panel-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 42px;
}
.doc-title { font-weight: 600; font-size: 13px; }

.save-indicator {
  margin-left: auto;
  font-size: 12px;
  color: var(--green);
  opacity: 0;
  transition: opacity 0.4s ease;
}
.save-indicator.visible { opacity: 1; }

.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;
}
.progress-inline {
  display: flex;
  align-items: center;
  gap: 6px;
}

.img-container {
  flex: 1;
  overflow: auto;
  position: relative;
  background: #050a14;
  cursor: default;
}

#page-img {
  display: block;
  max-width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}

#overlay {
  position: absolute;
  top: 0;
  left: 0;
  cursor: crosshair;
}

/* --- Right panel --- */
.panel-right {
  width: 480px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow: hidden;
}

.crop-zone {
  min-height: 60px;
  height: 200px;
  background: #050a14;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  position: relative;
}
.panel-resize-handle {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 6px;
  cursor: ns-resize;
  background: transparent;
  z-index: 11;
}
.panel-resize-handle:hover,
.panel-resize-handle.dragging {
  background: var(--accent, #4af);
  opacity: 0.5;
}
.crop-magnifier {
  position: absolute;
  width: 500px;
  height: 140px;
  border-radius: 6px;
  border: 2px solid rgba(255,255,255,0.6);
  box-shadow: 0 0 8px rgba(0,0,0,0.5);
  pointer-events: none;
  background-repeat: no-repeat;
  z-index: 10;
}
.crop-placeholder { color: var(--muted); font-size: 12px; padding: 12px; text-align: center; }
.line-crop-img {
  max-width: calc(100% - 8px);
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  padding: 4px;
}

.editor-area {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}
.editor-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.editor-actions { display: flex; gap: 4px; }

#line-text {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: "Georgia", "Times New Roman", "DejaVu Serif", serif;
  font-size: 22px;
  line-height: 1.5;
  resize: vertical;
}
#line-text:focus { outline: none; border-color: var(--amber); }

.input-hints {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}

.line-list-header {
  display: flex;
  justify-content: space-between;
  padding: 6px 12px 4px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.line-list {
  flex: 1;
  overflow-y: auto;
}

.line-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px 6px 4px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
  position: relative;
}
.line-item:hover { background: var(--surface2); }
.line-item.selected { background: rgba(245,158,11,0.12); }
.line-item.multi-sel { background: rgba(167,139,250,0.12); }
.line-item.multi-sel.selected { background: rgba(245,158,11,0.18); }

/* Drag handle */
.drag-handle {
  cursor: grab;
  color: var(--muted);
  font-size: 12px;
  opacity: 0.4;
  user-select: none;
  flex-shrink: 0;
  width: 14px;
  text-align: center;
}
.line-item:hover .drag-handle { opacity: 0.8; }
.line-item.multi-sel .drag-handle { opacity: 0.8; color: #a78bfa; }

/* Drag states */
.line-item.dragging {
  opacity: 0.35;
}

.line-item.drop-above::before,
.line-item.drop-below::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
  z-index: 10;
}
.line-item.drop-above::before { top: -2px; }
.line-item.drop-below::after  { bottom: -2px; }

.lnum {
  min-width: 22px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}
.line-item.done   .lnum { color: var(--green); }
.line-item.selected .lnum { color: var(--amber); }
.line-item.multi-sel .lnum { color: #a78bfa; }

.ltext {
  font-size: 14px;
  font-family: Georgia, serif;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.line-item.done .ltext    { color: var(--text); }
.line-item.selected .ltext { color: var(--text); }

/* ------------------------------------------------------------------ */
/* OCR reference panel                                                  */
/* ------------------------------------------------------------------ */
.ocr-panel {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  height: 200px;
  min-height: 48px;
  position: relative;
  overflow: hidden;
}

.ocr-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.ocr-panel-actions {
  display: flex;
  gap: 4px;
}

.ocr-text-content {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
  font-family: "Georgia", "Times New Roman", "DejaVu Serif", serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  user-select: text;
  background: var(--bg);
  margin: 0 8px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.ocr-line {
  display: block;
  padding: 1px 4px;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.1s;
  word-break: break-word;
}
.ocr-line:hover {
  background: rgba(59,130,246,0.15);
}
.ocr-line-selected {
  background: rgba(59,130,246,0.25);
  border-left: 3px solid var(--accent);
}
.ocr-line-used {
  color: var(--green);
  background: rgba(34,197,94,0.08);
}
.ocr-line-resume {
  outline: 2px solid var(--accent);
  background: rgba(99,102,241,0.15);
}

.ocr-panel.empty .ocr-text-content {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
}

.ocr-empty {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, sans-serif;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  padding: 8px;
}

/* ------------------------------------------------------------------ */
/* Region section                                                       */
/* ------------------------------------------------------------------ */
.region-section {
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.region-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.region-type-select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 10px;
  padding: 1px 4px;
  cursor: pointer;
  flex-shrink: 0;
  flex-shrink: 0;
  display: inline-block;
}

/* ------------------------------------------------------------------ */
/* Projects                                                             */
/* ------------------------------------------------------------------ */
.project-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 16px;
  margin-bottom: 8px;
  transition: background 0.15s;
}
.project-card:hover { background: var(--surface2); }

.project-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.project-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--accent);
  text-decoration: none;
}
.project-name:hover { text-decoration: underline; }
.project-stats {
  display: flex;
  align-items: center;
  gap: 6px;
}
.project-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
}
.project-description { margin-top: 4px; }
.project-meta { margin-top: 2px; }

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.filter-input {
  flex: 1;
  min-width: 150px;
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 12px;
}
.filter-input:focus { outline: none; border-color: var(--accent); }
.filter-select {
  padding: 6px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

/* Breadcrumb */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}
.breadcrumb a { color: var(--accent); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb-sep { color: var(--muted); }

/* ------------------------------------------------------------------ */
/* Toolbar extras                                                       */
/* ------------------------------------------------------------------ */
.toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

/* ------------------------------------------------------------------ */
/* Virtual Keyboard                                                     */
/* ------------------------------------------------------------------ */
.vkb-panel {
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: 6px;
  max-height: 260px;
  overflow-y: auto;
}
.vkb-group { margin-bottom: 6px; }
.vkb-group-label {
  display: block;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}
.vkb-keys { display: flex; flex-wrap: wrap; gap: 2px; }
.vkb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: "Noto Serif", Georgia, serif;
  font-size: 18px;
  cursor: pointer;
  color: var(--text);
  min-width: 30px;
  height: 30px;
  transition: background 0.1s, border-color 0.1s;
}
.vkb-btn:hover {
  background: var(--surface2);
  border-color: var(--accent);
}
.vkb-btn:active { background: var(--accent); color: #fff; }
#btn-vkb.active, #btn-scissor.active, #btn-diff.active { background: var(--accent); color: #fff; }

/* ------------------------------------------------------------------ */
/* Version Diff                                                         */
/* ------------------------------------------------------------------ */
.diff-panel {
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: 6px;
}
.diff-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}
.diff-content {
  font-family: "Noto Serif", Georgia, serif;
  font-size: 18px;
  line-height: 1.5;
  word-wrap: break-word;
}
.diff-equal { color: var(--text); }
.diff-del { background: rgba(239,68,68,0.25); text-decoration: line-through; color: var(--red); }
.diff-ins { background: rgba(34,197,94,0.25); color: var(--green); }

/* ------------------------------------------------------------------ */
/* Tags                                                                 */
/* ------------------------------------------------------------------ */
.tag-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 10px;
  color: #fff;
  font-weight: 500;
  vertical-align: middle;
  margin-left: 4px;
}
.tag-manager {
  display: flex;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.tag-manager-inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  min-width: 320px;
  max-width: 450px;
}
.tag-manager-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.tag-create-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 12px;
}
.tag-list { display: flex; flex-direction: column; gap: 4px; }
.tag-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}
.tag-popup {
  position: absolute;
  right: 0;
  top: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  z-index: 100;
  min-width: 160px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.tag-popup-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  cursor: pointer;
}
.tag-popup-item:hover { background: var(--surface2); border-radius: 4px; }

/* ------------------------------------------------------------------ */
/* Collection groups                                                    */
/* ------------------------------------------------------------------ */
.collection-group {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
  overflow: hidden;
}
.collection-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--surface2);
  cursor: pointer;
  font-weight: 500;
}
.collection-header:hover { background: var(--surface); }
.collection-icon { font-size: 10px; color: var(--muted); width: 14px; }
.collection-name { font-size: 14px; }
.collection-children {
  padding-left: 12px;
  border-top: 1px solid var(--border);
}
.collection-children .folder-group {
  border: none;
  border-bottom: 1px solid var(--border);
}
.collection-children .folder-group:last-child { border-bottom: none; }

/* ------------------------------------------------------------------ */
/* User menu                                                            */
/* ------------------------------------------------------------------ */
.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

/* ------------------------------------------------------------------ */
/* Full-text search results                                             */
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
/* Versions panel                                                       */
/* ------------------------------------------------------------------ */
.versions-panel {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 6px;
  background: var(--surface);
}

/* ------------------------------------------------------------------ */
/* Freehand polygon lens                                                */
/* ------------------------------------------------------------------ */
.freehand-lens {
  position: absolute;
  border: 2px solid var(--green);
  border-radius: 50%;
  pointer-events: none;
  z-index: 100;
  box-shadow: 0 0 12px rgba(34,197,94,0.4);
  overflow: hidden;
}

.search-results {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
  background: var(--surface);
}
