* {
  box-sizing: border-box;
}

@font-face {
  font-family: 'PdfEditor ABAT';
  src: url('../fonts/ABAT.ttf?v=6') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: block;
}

@font-face {
  font-family: 'DejaVu Sans';
  src: url('../fonts/ABAT.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: 'Segoe UI', Tahoma, sans-serif;
  background: #2b2b2b;
  color: #eee;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 8px 12px;
  background: #1e1e1e;
  border-bottom: 1px solid #444;
  flex-shrink: 0;
}

.group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.group.sep {
  padding-left: 10px;
  border-left: 1px solid #444;
}

button {
  background: #3a3a3a;
  color: #eee;
  border: 1px solid #555;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
}

button:hover:not(:disabled) {
  background: #4a4a4a;
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

button.tool.active {
  background: #2563eb;
  border-color: #3b82f6;
}

.label {
  font-size: 12px;
  color: #aaa;
  margin-right: 4px;
}

.toolbar-check {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #bbb;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.toolbar-check input {
  margin: 0;
  cursor: pointer;
}

#pageInfo,
#zoomLabel {
  min-width: 64px;
  text-align: center;
  font-size: 13px;
}

.hint {
  padding: 6px 14px;
  font-size: 12px;
  background: #252525;
  border-bottom: 1px solid #333;
  line-height: 1.45;
  flex-shrink: 0;
  max-height: 52px;
  overflow-y: auto;
}

.hint strong {
  margin-right: 6px;
}

.muted {
  color: #888;
  margin-left: 8px;
}

#workspace {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #525659;
}

.page-sidebar {
  flex: 0 0 148px;
  width: 148px;
  background: #1e1e1e;
  border-right: 1px solid #444;
  overflow-y: auto;
  overflow-x: hidden;
}

.page-sidebar.hidden {
  display: none;
}

.ocr-panel {
  flex: 0 0 38%;
  max-width: 480px;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  background: #141414;
  border-right: 2px solid #2563eb;
  min-height: 0;
}

.ocr-panel.hidden {
  display: none;
}

.ocr-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: #1e1e1e;
  border-bottom: 1px solid #333;
  font-size: 12px;
  color: #ccc;
}

.ocr-panel-head-btns {
  display: flex;
  gap: 4px;
}

.ocr-panel-head-btns button {
  padding: 4px 8px;
  font-size: 12px;
}

#ocrPanelText.abat-text {
  font-family: 'PdfEditor ABAT', sans-serif;
}

#ocrPanelText {
  flex: 1;
  min-height: 120px;
  margin: 0;
  padding: 12px;
  border: none;
  resize: none;
  background: #0d0d0d;
  color: #eee;
  font-size: 14px;
  line-height: 1.55;
  font-family: 'Segoe UI', 'Traditional Arabic', 'PdfEditor ABAT', sans-serif;
  outline: none;
}

.ocr-panel-hint {
  margin: 0;
  padding: 6px 10px;
  font-size: 11px;
  line-height: 1.4;
  color: #9ca3af;
  border-top: 1px solid #333;
  background: #161616;
}

.ocr-panel-foot {
  padding: 8px 10px;
  border-top: 1px solid #333;
  background: #1a1a1a;
}

.ocr-panel-foot button {
  width: 100%;
  font-size: 12px;
}

.page-thumbnails {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 8px;
}

.page-thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 6px;
  border: 2px solid transparent;
  border-radius: 6px;
  background: #2a2a2a;
  cursor: grab;
}

.page-thumb.dragging {
  opacity: 0.45;
  cursor: grabbing;
}

.page-thumb.drag-over {
  border-color: #3b82f6;
  background: #2a3348;
}

.page-thumb:hover:not(:disabled) {
  background: #333;
  border-color: #555;
}

.page-thumb.active {
  border-color: #2563eb;
  background: #2a3348;
}

.page-thumb.deleted {
  opacity: 0.55;
}

.page-thumb.deleted .page-thumb-label {
  text-decoration: line-through;
  color: #f87171;
}

.page-thumb-frame {
  width: 100%;
  background: #fff;
  border-radius: 2px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-thumb-frame img {
  display: block;
  width: 100%;
  height: auto;
}

.page-thumb-placeholder {
  color: #888;
  font-size: 16px;
  padding: 18px 0;
}

.page-thumb-label {
  font-size: 11px;
  color: #aaa;
}

.page-viewport {
  flex: 1;
  position: relative;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px;
  min-width: 0;
}

#emptyState {
  margin-top: 120px;
  text-align: center;
  color: #ccc;
  font-size: 18px;
  cursor: pointer;
  user-select: none;
}

#emptyState:hover {
  color: #fff;
}

#emptyState.dragover {
  color: #fff;
  outline: 2px dashed #3b82f6;
  padding: 40px;
  border-radius: 12px;
}

.hidden {
  display: none !important;
}

#pageWrap {
  position: relative;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.45);
  background: #fff;
}

#pdfCanvas,
#overlayCanvas {
  display: block;
}

#overlayCanvas {
  position: absolute;
  left: 0;
  top: 0;
  cursor: crosshair;
}

#overlayCanvas.tool-pan {
  cursor: grab;
}

#overlayCanvas.tool-pan.grabbing {
  cursor: grabbing;
}

#overlayCanvas.tool-select {
  cursor: crosshair;
}

#textEditorLayer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.toolbar-format select {
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 4px;
  border: 1px solid #555;
  background: #2a2a2a;
  color: #eee;
  max-width: 140px;
}

#toolbarFontSize {
  width: 54px;
}

#toolbarFontColor {
  width: 32px;
  height: 28px;
  padding: 2px;
  border: 1px solid #555;
  border-radius: 4px;
  background: #2a2a2a;
  cursor: pointer;
  vertical-align: middle;
}

#ocrLangSelect {
  max-width: 220px;
  font-size: 12px;
}

.text-box {
  position: absolute;
  pointer-events: auto;
  min-width: 80px;
  min-height: 32px;
  border: 2px solid #2563eb;
  background: transparent;
  box-shadow: none;
  border-radius: 2px;
  overflow: visible;
}

.text-box textarea {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 28px;
  border: none;
  resize: none;
  outline: none;
  padding: 6px 8px;
  color: #111;
  background: transparent;
  line-height: 1.3;
  box-sizing: border-box;
}

.text-box textarea.font-abat {
  font-family: 'PdfEditor ABAT', 'DejaVu Sans', sans-serif !important;
}

.text-resize-handle {
  position: absolute;
  right: -5px;
  bottom: -5px;
  width: 12px;
  height: 12px;
  background: #2563eb;
  border: 2px solid #fff;
  border-radius: 2px;
  cursor: se-resize;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.stamp-box {
  position: absolute;
  pointer-events: auto;
  border: 2px dashed #16a34a;
  background: transparent;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  cursor: move;
  overflow: hidden;
}

.stamp-preview {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;
}

.stamp-resize-handle {
  background: #16a34a;
}

#overlayCanvas.tool-text {
  cursor: text;
}

#status {
  height: 26px;
  line-height: 26px;
  padding: 0 12px;
  font-size: 12px;
  background: #1a1a1a;
  border-top: 1px solid #333;
  color: #aaa;
  flex-shrink: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.context-menu {
  position: fixed;
  z-index: 1000;
  min-width: 210px;
  padding: 4px 0;
  margin: 0;
  list-style: none;
  background: #2a2a2a;
  border: 1px solid #555;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.context-menu button {
  display: flex;
  width: 100%;
  justify-content: space-between;
  gap: 24px;
  border: none;
  border-radius: 0;
  background: transparent;
  padding: 8px 14px;
  text-align: left;
  font-size: 13px;
}

.context-menu button:hover:not(:disabled) {
  background: #3d3d3d;
}

.context-menu button:disabled {
  opacity: 0.35;
}

.context-menu button span {
  color: #888;
  font-size: 11px;
}

.context-menu hr {
  border: none;
  border-top: 1px solid #444;
  margin: 4px 0;
}

/* Virtual keyboard */
.vk-panel {
  --vk-scale: 1.15;
}

.vk-panel.vk-floating:not(.hidden) {
  position: fixed;
  z-index: 10050;
  width: 440px;
  height: 400px;
  min-width: 260px;
  min-height: 180px;
  max-width: 96vw;
  max-height: 88vh;
  margin: 0;
  padding: 0;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  border: 1px solid #64748b;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #f1f5f9;
  touch-action: none;
  color: #111;
}

.vk-panel.hidden {
  display: none;
}

.vk-panel.vk-floating .vk-head {
  cursor: grab;
  user-select: none;
  touch-action: none;
  padding: 6px 8px;
  background: linear-gradient(#e2e8f0, #cbd5e1);
  border-bottom: 1px solid #94a3b8;
  flex-shrink: 0;
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
}

.vk-panel.vk-floating .vk-head:active {
  cursor: grabbing;
}

.vk-head-tools {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  margin-left: auto;
}

.vk-head-btn {
  min-width: 28px;
  height: 28px;
  border: 1px solid #94a3b8;
  border-radius: 6px;
  background: #fff;
  color: #334155;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.vk-head-btn:hover {
  background: #f8fafc;
}

.vk-scale-label {
  font-size: 11px;
  color: #475569;
  min-width: 38px;
  text-align: center;
}

.vk-drag-hint {
  font-size: 14px;
  color: #64748b;
  padding: 0 2px;
}

.vk-close-btn {
  border: none;
  background: transparent;
  color: #475569;
  font-size: 22px;
  line-height: 1;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}

.vk-close-btn:hover {
  background: rgba(255, 255, 255, 0.6);
  color: #0f172a;
}

.vk-resize-handle {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
  touch-action: none;
  background: linear-gradient(135deg, transparent 50%, #64748b 50%, #64748b 58%, transparent 58%, transparent 68%, #64748b 68%, #64748b 76%, transparent 76%);
  opacity: 0.75;
  border-radius: 0 0 8px 0;
}

.vk-title {
  font-weight: 600;
  color: #1e293b;
  white-space: nowrap;
}

.vk-head select {
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 4px;
  border: 1px solid #94a3b8;
  background: #fff;
  color: #111;
}

.vk-keys {
  flex: 1 1 auto;
  min-height: 0;
  padding: 3px;
  overflow: hidden;
  direction: ltr;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
}

.vk-panel.vk-floating .vk-row {
  display: grid;
  grid-template-columns: repeat(var(--vk-cols, 10), minmax(0, 1fr));
  gap: 2px;
  width: 100%;
  margin-bottom: 0;
}

.vk-key-btn {
  min-width: 0;
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: #fff;
  padding: 1px 2px;
  cursor: pointer;
  text-align: center;
  font-family: inherit;
  color: inherit;
}

.vk-key-btn .vk-key-label {
  display: block;
  font-size: calc(9px * var(--vk-scale, 1));
  font-weight: 600;
  color: #111;
  line-height: 1.05;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.vk-key-btn.lang-abat .vk-key-label {
  font-size: calc(10px * var(--vk-scale, 1));
}

.vk-key-btn .vk-key-glyph {
  display: block;
  font-size: calc(22px * var(--vk-scale, 1));
  line-height: 1.05;
  margin-top: 0;
  color: #111;
}

.vk-key-btn.lang-abat .vk-key-glyph {
  font-family: 'PdfEditor ABAT', 'DejaVu Sans', sans-serif;
  color: #111;
}

.vk-key-btn.lang-abat .vk-key-label {
  color: #111;
}

.vk-key-btn.lang-arabic .vk-key-glyph {
  font-family: 'Traditional Arabic', 'Arabic Typesetting', 'Segoe UI', sans-serif;
}

.vk-key-btn.lang-russian,
.vk-key-btn.lang-english {
  background: #2d4a6f;
  border-color: #1e3a5f;
}

.vk-key-btn.lang-russian .vk-key-glyph,
.vk-key-btn.lang-english .vk-key-glyph {
  color: #fff;
}

.vk-key-btn.lang-russian .vk-key-label,
.vk-key-btn.lang-english .vk-key-label {
  color: #e2e8f0;
}

.vk-key-btn.vk-key-num {
  min-width: 0;
  width: 100%;
  max-width: none;
  height: auto;
  min-height: calc(36px * var(--vk-scale, 1));
  font-size: calc(16px * var(--vk-scale, 1));
  font-weight: 700;
  color: #fff;
}

.vk-key-btn.vk-key-punct {
  min-width: 0;
  width: 100%;
  max-width: none;
  height: auto;
  min-height: calc(36px * var(--vk-scale, 1));
  background: #374151 !important;
  border-color: #6b7280;
  font-size: calc(18px * var(--vk-scale, 1));
  font-weight: 700;
  color: #fff;
}

.vk-key-btn.vk-key-punct .vk-key-label {
  display: none;
}

.vk-controls {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 3px;
  padding: 3px 4px 4px;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
}

.vk-controls .vk-util {
  max-width: none;
  flex: 0 1 auto;
  min-width: 48px;
  font-size: 12px;
  font-family: 'Segoe UI', sans-serif;
  background: #fff;
  border: 1px solid #cbd5e1;
  color: #111;
}

.vk-controls .vk-space.wide {
  flex: 2;
  min-width: 80px;
  max-width: 200px;
}

.vk-controls .vk-clear {
  color: #b45309;
  border-color: #fbbf24;
  background: #fffbeb;
}

.vk-toggle-btn.header-vk-btn,
.header-vk-btn {
  font-size: 14px !important;
  font-weight: 600;
  padding: 8px 14px !important;
  min-height: 36px;
  white-space: nowrap;
}

.toolbar .vk-toggle-btn.header-vk-btn {
  background: #1e4620 !important;
  border-color: #4caf50 !important;
  color: #e8f5e9 !important;
}

.toolbar .vk-toggle-btn.header-vk-btn:hover {
  background: #2e7d32 !important;
}

.toolbar .vk-toggle-btn.header-vk-btn.active {
  background: #2563eb !important;
  border-color: #3b82f6 !important;
  color: #fff !important;
}

.vk-clear-btn {
  font-size: 13px !important;
  font-weight: 600;
  padding: 8px 12px !important;
  min-height: 36px;
  color: #b45309 !important;
  border-color: #fbbf24 !important;
  background: #fffbeb !important;
}

.vk-clear-btn:hover {
  background: #fef3c7 !important;
}

.vk-keys.vk-rtl {
  direction: rtl;
}

.vk-keys[data-layout='abat'] {
  font-family: 'Segoe UI', sans-serif;
}

.vk-row-abat {
  gap: 2px;
}

.vk-key-num {
  font-family: 'Segoe UI', sans-serif !important;
  font-size: 18px;
  font-weight: 700;
  min-width: 40px;
  width: 40px;
  max-width: 40px;
  height: 44px;
  flex-shrink: 0;
  align-self: flex-start;
  color: #fff;
}

.vk-key-num-left {
  background: #1a7a5c;
  border: 1px solid #2ecc96;
}

.vk-key-num-right {
  background: #9a6b2e;
  border: 1px solid #d4a24a;
}

.vk-row-extra .vk-key-num-left {
  background: #156b52;
}

.vk-row-extra .vk-key-num-right {
  background: #7d5828;
}

.vk-row-punct {
  margin-top: 2px;
  padding-top: 2px;
  border-top: 1px solid #e2e8f0;
}

.vk-key-punct {
  background: #374151 !important;
  border: 1px solid #6b7280;
  font-family: 'Segoe UI', sans-serif !important;
  font-size: 22px;
  font-weight: 700;
  min-width: 52px;
  height: 44px;
  color: #fff;
}

.vk-key-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 52px;
  flex-shrink: 0;
}

.vk-key-abat-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  max-width: 44px;
  background: #533483;
  flex-direction: column;
  justify-content: center;
  padding: 2px;
  margin: 0;
}

.vk-key-abat-glyph {
  font-family: 'PdfEditor ABAT', 'DejaVu Sans', sans-serif;
  font-size: 22px;
  line-height: 1;
  color: #fff;
}

.vk-key-abat-caption {
  display: block;
  width: 100%;
  margin-top: 4px;
  font-family: 'Segoe UI', sans-serif;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.15;
  color: #fff;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  word-break: break-word;
}

.vk-key-abat-subcaption {
  display: block;
  width: 100%;
  margin-top: 1px;
  font-family: 'Segoe UI', sans-serif;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.1;
  color: #ffd966;
  text-align: center;
}

.vk-row-extra .vk-key-abat-btn {
  background: #3d5a80;
}

.vk-row-extra .vk-key-cell {
  width: 56px;
}

.vk-keys[data-layout='russian'] .vk-key-main {
  font-size: 17px;
  font-weight: 600;
}

.vk-keys[data-layout='russian'] .vk-key {
  background: #2d4a6f;
  min-width: 36px;
  height: 42px;
}

.vk-extra-label {
  font-size: calc(10px * var(--vk-scale, 1));
  color: #111;
  padding: 2px 4px 0;
  font-weight: 700;
  text-align: center;
  flex-shrink: 0;
}

.vk-keys[data-layout='arabic'] {
  font-family: 'Traditional Arabic', 'Arabic Typesetting', 'Segoe UI', sans-serif;
  font-size: 18px;
}

.vk-row {
  display: grid;
  grid-template-columns: repeat(var(--vk-cols, 10), minmax(0, 1fr));
  gap: 2px;
  width: 100%;
  margin-bottom: 0;
}

.vk-key {
  position: relative;
  min-width: 34px;
  height: 38px;
  padding: 2px 4px;
  font-size: 15px;
  line-height: 1.1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  max-width: 52px;
}

.vk-key-main {
  pointer-events: none;
}

.vk-key-hint {
  pointer-events: none;
  font-size: 9px;
  color: #cbd5e1;
  font-family: 'Segoe UI', sans-serif;
  line-height: 1;
  margin-top: 1px;
  font-weight: 600;
}

.vk-row-util .vk-key {
  max-width: none;
  flex: 0 1 auto;
  min-width: 48px;
  font-size: 13px;
  font-family: 'Segoe UI', sans-serif;
}

.vk-space {
  flex: 3;
  max-width: 280px;
}

.vk-panel.vk-floating .vk-key-abat-glyph {
  font-size: calc(22px * var(--vk-scale, 1));
}

.vk-panel.vk-floating .vk-key-abat-caption,
.vk-panel.vk-floating .vk-key-abat-subcaption {
  font-size: calc(10px * var(--vk-scale, 1));
  color: #111;
  text-shadow: none;
}

.vk-panel.vk-floating .vk-extra-label {
  color: #111;
  font-weight: 700;
}

.vk-panel.vk-floating .vk-key-hint {
  color: #111;
}

.vk-shift.vk-shift-on,
.vk-key.vk-active {
  background: #2563eb;
  border-color: #3b82f6;
  color: #fff;
}

#btnVkToggle.active,
.vk-toggle-btn.active {
  background: #2563eb !important;
  border-color: #3b82f6 !important;
  color: #fff !important;
}
