/* Permit field alignment tool */

.page-calibrate {
  min-height: 100vh;
  background: #1a2332;
  color: #e8ecf1;
  font-family: "DM Sans", system-ui, sans-serif;
}

.calibrate-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  padding: 0.85rem 1.25rem;
  background: #0c2340;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  position: sticky;
  top: 0;
  z-index: 100;
}

.calibrate-header h1 {
  margin: 0;
  font-family: "Barlow Condensed", sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.calibrate-header__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.calibrate-header a {
  color: #9ec5f7;
  text-decoration: none;
  font-size: 0.875rem;
}

.calibrate-header a:hover {
  text-decoration: underline;
}

.calibrate-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  min-height: calc(100vh - 56px);
}

@media (max-width: 960px) {
  .calibrate-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }
}

.calibrate-workspace {
  overflow: auto;
  padding: 1rem;
  background: #2a3548;
}

.calibrate-stage-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100%;
}

.calibrate-stage {
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.45);
  line-height: 0;
  user-select: none;
  touch-action: none;
}

.calibrate-stage__img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}

.calibrate-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.field-box {
  position: absolute;
  pointer-events: auto;
  box-sizing: border-box;
  border: 2px solid rgba(66, 153, 225, 0.85);
  background: rgba(66, 153, 225, 0.18);
  cursor: move;
  min-width: 4px;
  min-height: 4px;
}

.field-box--checkbox {
  border-color: rgba(72, 187, 120, 0.9);
  background: rgba(72, 187, 120, 0.22);
  overflow: visible;
}

/* Larger invisible grab target — true PDF size stays on the bordered box */
.field-box--checkbox .field-box__drag-pad {
  position: absolute;
  left: 50%;
  top: 50%;
  width: max(28px, 140%);
  height: max(28px, 140%);
  transform: translate(-50%, -50%);
  cursor: move;
  z-index: 1;
}

.field-box--checkbox.is-locked .field-box__resize {
  display: none;
}

.calibrate-filter-row {
  margin-bottom: 0.35rem;
}

.calibrate-filter-label {
  font-size: 0.8rem;
  color: #a0aec0;
}

.field-box.is-selected {
  border-color: #f6ad55;
  background: rgba(246, 173, 85, 0.28);
  z-index: 20;
  box-shadow: 0 0 0 1px #f6ad55;
}

.field-box.is-dimmed {
  opacity: 0.28;
}

.field-box--text .field-box__baseline {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: #fc8181;
  pointer-events: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.field-box--text.is-selected .field-box__baseline {
  background: #e53e3e;
  height: 3px;
}

.field-box__label {
  position: absolute;
  left: 0;
  top: -1.1em;
  font-size: 9px;
  line-height: 1.2;
  color: #fff;
  background: rgba(12, 35, 64, 0.88);
  padding: 1px 4px;
  border-radius: 2px;
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
}

.field-box:hover .field-box__label,
.field-box.is-selected .field-box__label,
.calibrate-overlay--show-labels .field-box__label {
  opacity: 1;
}

.field-box__resize {
  position: absolute;
  right: -5px;
  bottom: -5px;
  width: 10px;
  height: 10px;
  background: #f6ad55;
  border: 1px solid #fff;
  border-radius: 2px;
  cursor: nwse-resize;
  opacity: 0;
}

.field-box.is-selected .field-box__resize,
.field-box:hover .field-box__resize {
  opacity: 1;
}

.calibrate-sidebar {
  background: #0f1824;
  border-left: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 56px);
  overflow: hidden;
}

@media (max-width: 960px) {
  .calibrate-sidebar {
    max-height: none;
    border-left: none;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
  }
}

.calibrate-sidebar__section {
  padding: 1rem 1.1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.calibrate-sidebar__section h2 {
  margin: 0 0 0.65rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8b9cb3;
}

.calibrate-sidebar__hint {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  line-height: 1.45;
  color: #8b9cb3;
}

.calibrate-sidebar__hint code {
  font-size: 0.75rem;
  background: rgba(255, 255, 255, 0.06);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

.calibrate-coords {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.calibrate-coords label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.72rem;
  color: #8b9cb3;
}

.calibrate-coords input {
  width: 100%;
  padding: 0.35rem 0.45rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  background: #1a2332;
  color: #e8ecf1;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.calibrate-coords input:focus {
  outline: 2px solid #4299e1;
  border-color: transparent;
}

.calibrate-field-list-wrap {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 200px;
}

.calibrate-field-list-wrap .calibrate-sidebar__section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 0.5rem;
}

.calibrate-search {
  width: 100%;
  padding: 0.45rem 0.6rem;
  margin-bottom: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  background: #1a2332;
  color: #e8ecf1;
  font-size: 0.875rem;
}

.calibrate-field-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.calibrate-field-list li button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.35rem 0.5rem;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: #c5d0de;
  font-size: 0.78rem;
  font-family: ui-monospace, monospace;
  cursor: pointer;
}

.calibrate-field-list li button:hover {
  background: rgba(255, 255, 255, 0.06);
}

.calibrate-field-list li button.is-active {
  background: rgba(246, 173, 85, 0.2);
  color: #fbd38d;
}

.calibrate-field-list li button.kind-checkbox::before {
  content: "☐ ";
  color: #68d391;
}

.calibrate-field-list li button.kind-text::before {
  content: "T ";
  color: #63b3ed;
  font-weight: 700;
}

.calibrate-toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.calibrate-toolbar-row label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: #a0aec0;
  cursor: pointer;
}

.calibrate-btn {
  padding: 0.4rem 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 5px;
  background: #2d3748;
  color: #e8ecf1;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
}

.calibrate-btn:hover {
  background: #3d4a5c;
}

.calibrate-btn--primary {
  background: #bf0a30;
  border-color: #9a0826;
}

.calibrate-btn--primary:hover {
  background: #d4143a;
}

.calibrate-btn.is-active {
  background: #2b6cb0;
  border-color: #2c5282;
}

.calibrate-status {
  font-size: 0.8rem;
  color: #68d391;
  min-height: 1.2em;
}

.calibrate-status.is-error {
  color: #fc8181;
}

.calibrate-zoom {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: #a0aec0;
}

.calibrate-zoom input[type="range"] {
  width: 100px;
}

.calibrate-selected-name {
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  color: #fbd38d;
  margin-bottom: 0.5rem;
  word-break: break-all;
}

.calibrate-selected-name em {
  font-style: normal;
  color: #8b9cb3;
  font-size: 0.75rem;
}
