:root {
  --bg: #1e2126;
  --panel: #262a31;
  --panel-border: #383d46;
  --text: #e6e8eb;
  --text-dim: #9aa1ac;
  --accent: #5b9cf6;
  --accent-hover: #7bb0f8;
  --danger: #e15c5c;
  --stage-bg: #4a4e57;
  --box-fill: rgba(90, 90, 90, 0.45);
  --box-border: #cfcfcf;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
}

.app {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}
.app[hidden] { display: none; }

/* ---------- Auth gate ---------- */

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--text);
}
.auth-gate[hidden] { display: none; }

.auth-gate .auth-state {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
  padding: 24px;
  max-width: 360px;
}
.auth-gate[data-state="initializing"] .auth-state--initializing,
.auth-gate[data-state="redirecting"] .auth-state--redirecting,
.auth-gate[data-state="error"] .auth-state--error {
  display: flex;
}

.auth-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--panel-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: auth-spin 0.8s linear infinite;
}
@keyframes auth-spin {
  to { transform: rotate(360deg); }
}

.auth-error-message {
  color: #ffb3b3;
  font-size: 13px;
  margin: 0;
}

/* ---------- Sidebar ---------- */

.sidebar {
  width: 390px;
  min-width: 390px;
  background: var(--panel);
  border-right: 1px solid var(--panel-border);
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

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

.brand-icon {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  border-radius: 8px;
}

.brand-text {
  min-width: 0;
}

.brand h1 {
  font-size: 18px;
  margin: 0 0 6px;
}

.tagline {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.4;
}

.panel {
  border-top: 1px solid var(--panel-border);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.panel[hidden] { display: none; }

.panel h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
}

.step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  color: #0d1117;
  font-size: 11px;
  font-weight: 700;
}

.dropzone {
  border: 2px dashed var(--panel-border);
  border-radius: var(--radius);
  padding: 20px 12px;
  text-align: center;
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(91, 156, 246, 0.08);
}

.dropzone p { margin: 0 0 10px; font-size: 13px; }

.file-name {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-dim);
  word-break: break-all;
}

textarea#termsInput {
  width: 100%;
  resize: vertical;
  background: var(--bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
}

textarea#termsInput:focus, select:focus, .dropzone:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.option-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.select-row {
  justify-content: space-between;
  font-size: 13px;
}

select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 5px 8px;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-dim);
  cursor: pointer;
}

button {
  font-family: inherit;
  cursor: pointer;
  border-radius: 6px;
  border: none;
  padding: 9px 14px;
  font-size: 13px;
}

.primary-btn {
  background: var(--accent);
  color: #0d1117;
  font-weight: 600;
}
.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.secondary-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--panel-border);
}
.secondary-btn:hover { border-color: var(--accent); color: var(--accent); }

.icon-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--panel-border);
  padding: 5px 10px;
  text-decoration: none;
  white-space: nowrap;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
}
.hint.warning { color: #e0b35c; }

kbd {
  background: var(--bg);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
}

/* ---------- Viewer ---------- */

.viewer {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 15px;
}
.empty-state[hidden] { display: none; }

.viewer-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
}
.viewer-toolbar[hidden] { display: none; }

.viewer-toolbar .spacer { flex: 1; }

#pageIndicator, #zoomIndicator {
  font-size: 13px;
  color: var(--text-dim);
  min-width: 70px;
  text-align: center;
}

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

.page-stage {
  position: relative;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
  background: var(--stage-bg);
  height: fit-content;
}

.page-stage canvas {
  display: block;
}

/* Off-screen measuring layer used by app.js to locate search terms.
   Never shown on screen, but pdf.js positions its spans with left/top
   percentages that only take effect on absolutely positioned elements. */
.textLayer {
  position: absolute;
  overflow: clip;
  line-height: 1;
  transform-origin: 0 0;
}

.textLayer span, .textLayer br {
  position: absolute;
  white-space: pre;
  transform-origin: 0% 0%;
}

.box-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  cursor: crosshair;
}

.redaction-box {
  position: absolute;
  background: var(--box-fill);
  border: 1px dashed var(--box-border);
  box-sizing: border-box;
  cursor: move;
}

.redaction-box.selected {
  border: 1.5px solid var(--accent);
  background: rgba(91, 156, 246, 0.3);
}

.redaction-box .resize-handle {
  position: absolute;
  right: -5px;
  bottom: -5px;
  width: 12px;
  height: 12px;
  background: var(--accent);
  border-radius: 50%;
  cursor: nwse-resize;
  display: none;
}

.redaction-box.selected .resize-handle {
  display: block;
}

.redaction-box .delete-handle {
  position: absolute;
  top: -9px;
  right: -9px;
  width: 16px;
  height: 16px;
  background: var(--danger);
  color: white;
  border-radius: 50%;
  font-size: 11px;
  line-height: 16px;
  text-align: center;
  cursor: pointer;
  display: none;
  user-select: none;
}

.redaction-box.selected .delete-handle {
  display: block;
}

.redaction-box .apply-all-handle {
  position: absolute;
  top: -9px;
  left: -9px;
  width: 18px;
  height: 18px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  display: none;
  user-select: none;
}

.redaction-box.selected .apply-all-handle {
  display: block;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #2f3540;
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 4px 18px rgba(0,0,0,0.4);
  z-index: 100;
}

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