/* AnnoLink v0.9 Phase2 pilot. Enabled only when URL contains ?v09=1.
 * This file does not modify PDF/XLSX/GLB viewers or annotation storage. */
body.v09-integration #v09-structure-pane[hidden],
body.v09-integration #v09-search-panel[hidden] { display: none !important; }

@media (min-width: 900px) {
  /* The original Editor owns --sidebar-width; do not shadow it on body. */
  body.v09-integration:not(.mobile-portrait) #v09-structure-pane {
    width: clamp(205px, 21vw, 350px); min-width: 155px; max-width: 48vw;
    display: flex; flex: 0 0 auto; flex-direction: column; min-height: 0;
    background: var(--surface); border-right: 1px solid var(--border);
    resize: horizontal; overflow: auto;
  }
  body.v09-integration:not(.mobile-portrait) #v09-structure-pane[hidden] { display: none !important; }
  body.v09-integration:not(.mobile-portrait) #desktop-sidebar { min-width: 270px; }
}

/* The pilot does not force a 3-pane layout onto phones or narrow windows. */
@media (max-width: 899px) {
  body.v09-integration #v09-structure-pane { display: none !important; }
}

body.v09-integration .v09-pane-head {
  padding: 11px 10px 8px; display: flex; justify-content: space-between;
  align-items: center; gap: 8px; border-bottom: 1px solid var(--border);
}
body.v09-integration .v09-pane-head button,
body.v09-integration #v09-sidebar-tabs button,
body.v09-integration #v09-clear-query,
body.v09-integration #v09-return-previous,
body.v09-integration #v09-more-results {
  font: inherit; padding: 6px 8px; color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  background: transparent; cursor: pointer;
}
body.v09-integration #v09-scope-label,
body.v09-integration .v09-pane-foot { font-size: 11px; padding: 8px; color: var(--text); opacity: .78; line-height: 1.45; }
body.v09-integration #v09-folder-tree { padding: 4px 7px; overflow: auto; flex: 1; min-height: 0; }
body.v09-integration #v09-folder-tree details { margin-left: 9px; }
body.v09-integration #v09-folder-tree summary { cursor: pointer; padding: 3px 2px; }
body.v09-integration .v09-folder-select,
body.v09-integration .v09-file-open {
  display: block; width: 100%; text-align: left; color: var(--text);
  border: 0; background: none; padding: 5px 8px; border-radius: 4px;
  overflow-wrap: anywhere; font: inherit; cursor: pointer;
}
body.v09-integration .v09-folder-select.active { color: var(--cyan); background: var(--cyan-dim); }
body.v09-integration .v09-file-open.current { color: var(--cyan); font-weight: 700; }
body.v09-integration .v09-folder-select:hover,
body.v09-integration .v09-file-open:hover { background: rgba(100, 150, 160, .2); }

body.v09-integration #v09-sidebar-tabs { display: flex; gap: 6px; padding: 9px 10px; border-bottom: 1px solid var(--border); }
body.v09-integration #v09-sidebar-tabs button { flex: 1; }
body.v09-integration #v09-sidebar-tabs button[aria-selected="true"] { border-color: var(--cyan); color: var(--cyan); background: var(--cyan-dim); }
body.v09-integration.v09-search-active #sb-main-scroll,
body.v09-integration.v09-search-active .sb-footer { display: none !important; }

/* The tag tab is for browsing tags, not creating annotations.
   Keep Save and New Annotation unchanged on the annotation tab. */
body.v09-integration.v09-tags-active .sb-footer .sb-make-btn { display: none !important; }
body.v09-integration #v09-search-panel {
  flex: 1; min-height: 0; overflow: auto; padding: 12px 10px;
  display: flex; flex-direction: column; gap: 10px; scrollbar-width: thin;
}
body.v09-integration #v09-search-form { display: flex; flex-direction: column; gap: 7px; }
body.v09-integration .v09-search-input-row { display: flex; gap: 6px; }
body.v09-integration #v09-search-query { width: 0; flex: 1; min-width: 0; padding: 8px; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; user-select: text; }
body.v09-integration #v09-execute-search { border: 1px solid var(--cyan); color: var(--cyan); background: var(--cyan-dim); padding: 9px; cursor: pointer; border-radius: 6px; font: inherit; }
/* The control itself reports busy state: no pane re-render or overlay iframe. */
body.v09-integration #v09-execute-search[aria-busy="true"] { cursor: progress; }
body.v09-integration #v09-execute-search[aria-busy="true"]::before {
  content: ""; display: inline-block; box-sizing: border-box;
  width: 13px; height: 13px; margin-right: 8px; vertical-align: -2px;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: v09-search-spin .75s linear infinite;
}
@keyframes v09-search-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  body.v09-integration #v09-execute-search[aria-busy="true"]::before { animation: none; }
}
body.v09-integration .v09-search-caveat { color: var(--text); opacity: .74; font-size: 11px; line-height: 1.45; border-left: 3px solid var(--amber); padding: 4px 8px; }
body.v09-integration #v09-search-status { font-size: 11px; line-height: 1.4; overflow-wrap: anywhere; }
body.v09-integration .v09-hit { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; padding: 8px; }
body.v09-integration .v09-hit-title { display: block; width: 100%; text-align: left; font: inherit; font-weight: bold; padding: 6px 4px; border: none; cursor: pointer; background: transparent; color: var(--cyan); overflow-wrap: anywhere; }
body.v09-integration .v09-hit-evidence { font-size: 11px; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.4; user-select: text; margin-top: 6px; }
body.v09-integration .v09-hit-origin { font-size: 10px; opacity: .75; }
/* Search scrolls independently; this dock must never scroll away. */
body.v09-integration #v09-explore-dock {display:none; flex:0 0 auto; padding:9px 10px; border-top:1px solid var(--border); background:var(--surface); box-shadow:0 -5px 12px rgba(0,0,0,.15); flex-direction:column; gap:6px;}
body.v09-integration.v09-search-active #v09-explore-dock {display:flex;}
body.v09-integration #v09-explore-viz {padding:7px;border:1px solid var(--border);background:transparent;color:var(--cyan);border-radius:6px;cursor:pointer;}
/* The human-confirmed save action uses wine-red; the Viz action stays cyan. */
body.v09-integration #v09-save-exploration {
  padding:10px;
  border-radius:6px;
  border:1px solid #a63c59;
  background:rgba(122,30,54,.42);
  color:#ffdde6;
  cursor:pointer;
  width:100%;
}
body.v09-integration #v09-save-exploration:hover:not(:disabled) {
  border-color:#cd5677;
  background:rgba(142,37,69,.58);
  color:#fff3f7;
}
body.v09-integration #v09-save-exploration:focus-visible {
  outline:2px solid #e7a3b8;
  outline-offset:2px;
}
body.v09-integration #v09-save-exploration:disabled {opacity:.7;cursor:not-allowed;}
/* Phase 4.1: one compact preview and ONE save action; no start/branch/undo buttons. */
body.v09-integration #v09-exploration {border-top:1px solid var(--border);padding-top:8px;display:flex;flex-direction:column;gap:5px;}
body.v09-integration #v09-explore-message {font-size:11px;color:var(--text);overflow-wrap:anywhere;}
body.v09-integration #v09-explore-route {font-size:11px;line-height:1.55;padding:7px;border:1px solid var(--border);border-radius:5px;overflow-wrap:anywhere;white-space:pre-wrap;}
body.v09-integration #v09-more-results[hidden], body.v09-integration #v09-return-previous[hidden] { display: none !important; }
/* Phase 3: provenance of original text vs unverified OCR */
body.v09-integration .v09-search-mode-label {display:flex;align-items:center;justify-content:space-between;gap:8px;font-size:12px;}
body.v09-integration #v09-search-mode {font:inherit;color:var(--text);background:var(--bg);border:1px solid var(--border);border-radius:5px;padding:4px 8px;}
body.v09-integration .v09-match-points {display:flex;gap:4px;flex-wrap:wrap;margin-top:5px;}
body.v09-integration .v09-match-points button {background:transparent;border:1px solid var(--border);color:var(--cyan);border-radius:4px;padding:4px;font:inherit;font-size:11px;cursor:pointer;}
body.v09-integration .v09-hit-origin[data-evidence-kind="ocr"] {color:var(--amber);opacity:1;}
body.v09-integration .v09-hit-evidence {max-height:210px;overflow:auto;}

/* OCR rectangle is a CHILD of the transformed image inner container.
   Thus zoom, pan, Fit and 1:1 all preserve its alignment automatically. */
#v09-image-ocr-highlight {
  position: absolute;
  box-sizing: border-box;
  border: 2px solid #ff8c00;
  background: rgba(255, 230, 80, .35);
  box-shadow: 0 0 0 1px rgba(255, 140, 0, .12);
  pointer-events: none;
  z-index: 4;
}

/* Phase 3.2: mark the chosen result without replacing the results DOM. */
body.v09-integration .v09-hit.selected {outline:2px solid #ff8c00;outline-offset:-2px;}
/* 2026-09-22: only the selected search result keeps an outer frame. */
body.v09-integration #v09-search-results .v09-hit {
  border-color: transparent !important;
}
body.v09-integration #v09-search-results .v09-hit:hover,
body.v09-integration #v09-search-results .v09-hit:focus-within {
  border-color: transparent !important;
}
body.v09-integration #v09-search-results .v09-hit.selected {
  outline: 2px solid #ff8c00;
  outline-offset: -2px;
  border-color: #ff8c00 !important;
  box-shadow: 0 0 0 1px rgba(255,140,0,.10), inset 0 0 0 1px rgba(255,255,255,.04);
}

/* v1.8.5: the source tree is a real resizable flex item; collapsed panes must
   release their width AND background rather than leaving a minimum-width strip. */
@media (min-width: 900px) {
  body.v09-integration:not(.mobile-portrait):not(.annolink-embedded-viewer):not(.annolink-left-hidden) #v09-structure-pane:not([hidden]) {
    width: var(--annolink-left-width, 335px) !important;
    flex: 0 0 var(--annolink-left-width, 335px) !important;
    min-width: 0 !important; max-width: none !important;
    resize: none !important; overflow: hidden !important; position: relative;
  }
  body.v09-integration.annolink-left-hidden:not(.mobile-portrait) #v09-structure-pane {
    width: 0 !important; flex: 0 0 0px !important;
    min-width: 0 !important; max-width: 0 !important; border: 0 !important;
    padding: 0 !important; margin: 0 !important; visibility: hidden !important;
    overflow: hidden !important;
  }
  body.v09-integration:not(.mobile-portrait) #canvas-wrapper { min-width: 0 !important; }
  body.v09-integration:not(.mobile-portrait).sidebar-hidden #desktop-sidebar {
    width: 0 !important; flex: 0 0 0px !important;
    min-width: 0 !important; max-width: 0 !important;
    margin: 0 !important; padding: 0 !important; border: 0 !important;
    overflow: hidden !important; visibility: hidden !important;
  }
  body.v09-integration:not(.mobile-portrait):not(.sidebar-hidden) #desktop-sidebar {
    min-width: 0 !important; max-width: none !important;
  }
  body.v09-integration #v09-tree-resizer {
    position: absolute; right: 0; top: 0; bottom: 0; width: 10px;
    cursor: col-resize; touch-action: none; z-index: 6;
  }
  body.v09-integration #v09-tree-resizer::before {
    content: ''; position: absolute; right: 0; top: 0; bottom: 0; width: 3px;
    background: transparent;
  }
  body.v09-integration #v09-tree-resizer:hover::before,
  body.v09-integration #v09-tree-resizer:focus-visible::before,
  body.v09-integration.annolink-left-resizing #v09-tree-resizer::before { background: var(--cyan,#00e5cc); }
  body.v09-integration #v09-tree-toggle {
    display: flex; position: absolute; z-index: 320;
    top: 50%; left: var(--annolink-left-width,335px);
    transform: translateY(-50%); align-items: center; justify-content: center;
    width: 18px; height: 54px; font: inherit; font-size: 12px;
    color: var(--cyan,#00e5cc); background: var(--surface,#323232);
    border: 1px solid var(--cyan,#00e5cc); border-left: 0; border-radius: 0 9px 9px 0;
    cursor: pointer; touch-action: manipulation;
  }
  body.v09-integration.annolink-left-hidden #v09-tree-toggle { left: 0; }
  body.v09-integration #v09-tree-toggle:focus-visible { outline: 2px solid var(--cyan,#00e5cc); outline-offset: 2px; }
  body.v09-integration.annolink-left-resizing,
  body.v09-integration.annolink-left-resizing * { cursor: col-resize !important; user-select: none !important; }
}
@media (max-width: 899px) {
  #v09-tree-toggle, #v09-tree-resizer { display: none !important; }
}
body.annolink-embedded-viewer #v09-tree-toggle,
body.annolink-embedded-viewer #v09-tree-resizer,
body.picker-mode #v09-tree-toggle, body.picker-mode #v09-tree-resizer { display: none !important; }

