/* ============================================
   Fraktur Reader — Application Styles
   ============================================ */

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

:root {
  --bg: #1a1a1e;
  --bg-panel: #222226;
  --bg-surface: #2a2a2e;
  --bg-hover: #333338;
  --border: #3a3a40;
  --text: #e8e6e1;
  --text-dim: #8a887f;
  --text-muted: #5a5850;
  --accent: #c4453c;
  --accent-dim: rgba(196, 69, 60, 0.3);
  --green: #5a9a6a;
  --green-dim: rgba(90, 154, 106, 0.15);
  --font-serif: "Source Serif 4", Georgia, serif;
  --font-mono: "JetBrains Mono", monospace;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-serif);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

/* Scrollbars */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }


/* --- Flash Messages --- */
.flash-messages {
  position: fixed;
  top: 70px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 400px;
}

.flash-message {
  padding: 12px 16px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.4;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  opacity: 1;
  transition: opacity 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.flash-notice {
  background: var(--green-dim);
  border: 1px solid var(--green);
  color: var(--green);
}

.flash-alert {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--accent);
}

.flash-close {
  background: none;
  border: none;
  color: inherit;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.15s;
  padding: 0;
  margin-left: auto;
}

.flash-close:hover {
  opacity: 1;
}


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

.header-left {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-name {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

.btn-logout {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-logout:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.app-header h1 {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text);
}

.app-subtitle {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}


/* --- Three-Panel Layout --- */
.panels {
  display: flex;
  height: calc(100vh - 46px); /* subtract header */
  overflow: hidden;
}

.panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.panel-pdf { flex: 1.3; }

.panel-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-label-detail {
  font-family: var(--font-serif);
  font-size: 11px;
  font-style: italic;
  color: var(--text-dim);
  text-transform: none;
  letter-spacing: normal;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.divider {
  width: 1px;
  background: var(--border);
  flex-shrink: 0;
}


/* --- Upload Area --- */
.pdf-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

.upload-form {
  display: contents;
}

.upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 40px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  max-width: 280px;
  text-align: center;
}

.upload-area:hover,
.upload-area.drag-over {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.upload-icon { color: var(--text-muted); }
.upload-area:hover .upload-icon,
.upload-area.drag-over .upload-icon { color: var(--accent); }

.upload-text {
  font-family: var(--font-serif);
  font-size: 14px;
  color: var(--text-dim);
}

.upload-hint {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

/* --- Upload Progress --- */
.upload-area > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.upload-progress {
  width: 200px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.upload-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.2s ease;
}

.upload-progress-text {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 500;
  color: var(--text);
}


/* --- PDF Loading Overlay --- */
.pdf-loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bg-panel);
  z-index: 10;
}

.pdf-loading-spinner {
  width: 32px;
  height: 32px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.pdf-loading-text {
  font-family: var(--font-serif);
  font-size: 14px;
  color: var(--text-dim);
}

.pdf-loading-progress {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}


/* --- PDF Viewer --- */
.pdf-viewer {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* Thumbnail sidebar */
.thumb-sidebar {
  width: 72px;
  overflow-y: auto;
  padding: 8px;
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.thumb-item {
  background: none;
  border: 2px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  padding: 2px;
  position: relative;
  transition: border-color 0.15s;
}

.thumb-item img {
  display: block;
  width: 100%;
  border-radius: 2px;
}

.thumb-item.active { border-color: var(--accent); }
.thumb-item:hover:not(.active) { border-color: var(--text-muted); }

.thumb-num {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-muted);
  background: rgba(26, 26, 30, 0.85);
  padding: 1px 4px;
  border-radius: 2px;
}

/* Main canvas area */
.pdf-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pdf-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  flex-shrink: 0;
}

.toolbar-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 14px;
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toolbar-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

.toolbar-btn:disabled { opacity: 0.3; cursor: default; }

.upload-btn { padding: 5px 8px; position: relative; }
.upload-btn form { position: absolute; opacity: 0; width: 0; height: 0; overflow: hidden; }

.page-info,
.zoom-info {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  padding: 0 6px;
  min-width: 48px;
  text-align: center;
}

.zoom-btn { font-size: 16px; padding: 3px 8px; }

.toolbar-spacer {
  width: 1px;
  height: 16px;
  background: var(--border);
  margin: 0 6px;
}

.pdf-scroll {
  flex: 1;
  overflow: auto;
  background: var(--bg);
  display: flex;
  justify-content: center;
  padding: 16px;
}

.canvas-wrapper {
  position: relative;
  display: inline-block;
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.4);
}

.pdf-canvas { display: block; }

.overlay-canvas {
  position: absolute;
  top: 0;
  left: 0;
  /* width & height set explicitly by JS to match main canvas */
  cursor: crosshair;
}

.draw-hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  background: rgba(26, 26, 30, 0.9);
  padding: 4px 12px;
  border-radius: 4px;
  pointer-events: none;
  opacity: 0.7;
}


/* --- OCR Panel --- */
.ocr-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px;
}

.ocr-state-text {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  max-width: 200px;
  line-height: 1.6;
}

.ocr-error {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  text-align: center;
  max-width: 260px;
  line-height: 1.5;
}

.ocr-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.ocr-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  position: relative;
}

.ocr-text {
  font-family: var(--font-serif);
  font-size: 15px;
  line-height: 1.75;
  color: var(--text);
  white-space: pre-wrap;
}

.copy-btn {
  position: sticky;
  bottom: 0;
  float: right;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.copy-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* Correction status indicators */
.ocr-correction-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #f0f9ff;
  border-radius: 6px;
  margin-bottom: 12px;
  font-size: 13px;
  color: #0369a1;
}

.ocr-correction-warning {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #fef3c7;
  border-radius: 6px;
  margin-bottom: 12px;
  font-size: 13px;
  color: #92400e;
}

.ocr-text-dim {
  opacity: 0.6;
}

.ocr-spinner-small {
  width: 14px;
  height: 14px;
  border: 2px solid #bfdbfe;
  border-top-color: #0369a1;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}


/* --- Translation Panel --- */
.translation-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

.translation-state-text {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  max-width: 200px;
  line-height: 1.6;
}

.translation-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.translation-placeholder {
  text-align: center;
  max-width: 240px;
}

.placeholder-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--green);
  background: var(--green-dim);
  padding: 4px 12px;
  border-radius: 4px;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

.placeholder-text {
  font-family: var(--font-serif);
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
}


/* --- Language Selector --- */
.language-selector-wrapper {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  display: flex;
  align-items: center;
  gap: 12px;
}

.language-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.language-select {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  outline: none;
}

.language-select:hover {
  background: var(--bg-hover);
  border-color: var(--text-muted);
}

.language-select:focus {
  border-color: var(--accent);
}
