/* ============================================================
   Log Dog AI — Source Panel (slide-in)
   Owned by: static/js/source-view-modal.js
   Replaces the legacy full-overlay source modal with a 380px
   right-anchored slide-in panel. All colors via design tokens
   defined in static/css/styles.css (:root).
   ============================================================ */

/* ── Panel container ── */
.src-panel {
  position: fixed;
  top: var(--hdr-h);
  right: 0;
  bottom: 0;
  width: 380px;
  background: var(--s1);
  border-left: 1px solid var(--bd);
  transform: translateX(100%);
  transition: transform .25s ease;
  z-index: 150;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.src-panel.open {
  transform: translateX(0);
}

/* Disable the slide-in transition while the user is dragging the resize handle
   so width updates feel direct. JS adds .src-panel.resizing during a drag. */
.src-panel.resizing {
  transition: none;
}

/* ── Left-edge resize handle ──
   12px-wide grab strip straddling the left edge of the panel (6px inside,
   6px outside). Wide enough to grab without pixel-precise aim. The handle
   element is still a descendant of .src-panel, so click-outside detection
   (closest('#src-panel')) correctly ignores clicks on it. */
.src-panel-resize-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -6px;
  width: 12px;
  cursor: col-resize;
  z-index: 5;
  background: transparent;
  transition: background .15s;
}

/* Render a subtle visible accent only on the leftmost 3px so the body of the
   panel stays clean. Use ::after so we get a thin indicator without making
   the whole 12px grab strip look like a fat bar. */
.src-panel-resize-handle::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 4.5px;
  width: 3px;
  background: transparent;
  transition: background .15s;
}

.src-panel-resize-handle:hover::after,
.src-panel.resizing .src-panel-resize-handle::after {
  background: var(--ac);
  opacity: .35;
}

/* ── Header ── */
.src-panel-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .625rem 1rem;
  border-bottom: 1px solid var(--bd);
  background: var(--s2);
  flex-shrink: 0;
  gap: .5rem;
}

.src-panel-title {
  font-size: .85rem;
  font-weight: 600;
  color: var(--tx);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.src-panel-hdr-right {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-shrink: 0;
}

.src-panel-close {
  color: var(--txm);
  background: transparent;
  border: none;
  padding: .25rem .4rem;
  border-radius: 3px;
  transition: all .15s;
  font-size: 1rem;
  cursor: pointer;
  line-height: 1;
}

.src-panel-close:hover {
  color: var(--tx);
  background: var(--s3);
}

/* ── Zoom controls ── */
.src-panel-zoom {
  display: flex;
  align-items: center;
  gap: .375rem;
}

.src-zoom-btn {
  font-size: .75rem;
  color: var(--txm);
  padding: .2rem .45rem;
  background: var(--s1);
  border: 1px solid var(--bd);
  border-radius: 3px;
  transition: all .15s;
  cursor: pointer;
  line-height: 1;
}

.src-zoom-btn:hover {
  color: var(--tx);
  border-color: var(--txm);
}

.src-zoom-btn.src-zoom-fit {
  padding: .2rem .35rem;
}

/* ── Magnifier toggle ──
   Checkbox styled as a small icon button, sits alongside the zoom controls.
   When checked, JS attaches mousemove handler to the image viewport and
   displays a magnified lens that follows the cursor (see .src-magnifier-lens
   below). Matches the pattern already used by Components.initSourceMagnifier. */
.src-magnify-toggle {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  padding: .2rem .35rem;
  border: 1px solid var(--bd);
  border-radius: 3px;
  background: var(--s1);
  color: var(--txm);
  transition: all .15s;
  line-height: 1;
  user-select: none;
}

.src-magnify-toggle:hover {
  color: var(--tx);
  border-color: var(--txm);
}

.src-magnify-toggle input[type="checkbox"] {
  /* Hide the native checkbox; the label state is reflected via [data-on]. */
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.src-magnify-toggle[data-on="true"] {
  color: var(--ac);
  border-color: var(--ac);
  background: var(--ac2);
}

.src-magnify-toggle svg {
  display: block;
  width: 14px;
  height: 14px;
}

/* ── Magnifier lens ──
   Square-ish lens that follows the mouse pointer when the magnifier is on.
   The viewport sets the lens's backgroundImage at startup; positioning is
   driven by JS on mousemove. Bordered + lightly shadowed to read as a window. */
.src-magnifier-lens {
  position: absolute;
  display: none;
  width: 220px;
  height: 160px;
  border: 1px solid var(--ac);
  border-radius: var(--rs);
  background-repeat: no-repeat;
  box-shadow: 0 4px 16px rgba(15, 22, 41, .25);
  pointer-events: none;
  z-index: 7;
  background-color: var(--s1);
}

.src-image-viewport.magnify-on { cursor: crosshair; }
.src-image-viewport.magnify-on .src-page-image { cursor: crosshair; }

.src-zoom-level {
  font-family: var(--fm);
  font-size: .65rem;
  color: var(--txm);
  min-width: 2.5rem;
  text-align: center;
}

/* ── Multi-page nav ── */
.src-page-nav {
  display: flex;
  align-items: center;
  gap: .375rem;
  padding: .375rem .625rem;
  background: var(--s2);
  border-bottom: 1px solid var(--bd2);
  flex-shrink: 0;
}

.src-nav-btn {
  font-size: .7rem;
  color: var(--txm);
  background: var(--s1);
  border: 1px solid var(--bd);
  border-radius: 3px;
  padding: .15rem .4rem;
  cursor: pointer;
  transition: all .15s;
  line-height: 1;
}

.src-nav-btn:hover:not(:disabled) {
  color: var(--tx);
  border-color: var(--txm);
}

.src-nav-btn:disabled {
  opacity: .35;
  cursor: not-allowed;
}

.src-page-thumbs {
  display: flex;
  gap: .25rem;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: thin;
}

.src-page-thumb {
  font-family: var(--fm);
  font-size: .6rem;
  color: var(--txm);
  background: var(--s1);
  border: 1px solid var(--bd);
  border-radius: 3px;
  padding: .15rem .4rem;
  cursor: pointer;
  transition: all .15s;
  flex-shrink: 0;
  line-height: 1;
}

.src-page-thumb:hover {
  color: var(--tx);
  border-color: var(--txm);
}

.src-page-thumb.active {
  color: var(--ac);
  background: var(--ac2);
  border-color: var(--ac);
}

.src-page-indicator {
  font-family: var(--fm);
  font-size: .6rem;
  color: var(--txd);
  margin-left: auto;
  flex-shrink: 0;
}

/* ── Image area ── */
.src-panel-img-wrap {
  background: var(--s2);
  border-bottom: 1px solid var(--bd);
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Default height; JS overrides via inline style and persists via localStorage.
     min/max keep extreme drags reasonable. */
  height: 40vh;
  min-height: 160px;
  max-height: 80vh;
}

/* Bottom-edge resize handle on the image wrapper. 12px-tall grab strip
   straddling the divider line — 6px above the wrap's bottom (over the image)
   and 6px below (into the body section). Wide grab target, thin visible
   stripe via ::after. */
.src-img-resize-handle {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -6px;
  height: 12px;
  cursor: row-resize;
  z-index: 6;
  background: transparent;
  transition: background .15s;
}

.src-img-resize-handle::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 4.5px;
  height: 3px;
  background: transparent;
  transition: background .15s;
}

.src-img-resize-handle:hover::after,
.src-panel-img-wrap.resizing .src-img-resize-handle::after {
  background: var(--ac);
  opacity: .35;
}

.src-panel-img-wrap.resizing {
  /* No transition while dragging — direct response. */
  transition: none;
}

.src-image-viewport {
  width: 100%;
  height: 100%;
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.src-page-image {
  max-width: 100%;
  max-height: 100%;
  display: block;
  opacity: 0;
  transition: opacity .2s ease;
  cursor: default;
  user-select: none;
  -webkit-user-drag: none;
}

.src-page-image.loaded {
  opacity: 1;
}

.src-page-image.zoomed {
  cursor: grab;
}

.src-img-placeholder {
  width: 100%;
  min-height: 220px;
  background: repeating-linear-gradient(
    45deg,
    var(--s2) 0,
    var(--s2) 1px,
    var(--s3) 1px,
    var(--s3) 8px
  );
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--fm);
  font-size: .72rem;
  color: var(--txd);
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 1rem;
  text-align: center;
}

/* ── Body (scrollable sections) ── */
.src-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.src-section {
  margin-bottom: 1.25rem;
}

.src-section:last-child {
  margin-bottom: 0;
}

.src-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--fm);
  font-size: .63rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--txm);
  margin-bottom: .625rem;
  padding-bottom: .375rem;
  border-bottom: 1px solid var(--bd2);
}

/* Key-value pair rows */
.src-kv {
  display: flex;
  gap: .5rem;
  margin-bottom: .425rem;
  font-size: .8rem;
}

.src-k {
  color: var(--txm);
  flex-shrink: 0;
  min-width: 80px;
}

.src-v {
  color: var(--tx);
  word-break: break-word;
}

.src-v.desc {
  color: var(--txm);
  font-size: .78rem;
  line-height: 1.5;
}

.src-v.src-uid,
.src-uid {
  font-family: var(--fm);
  font-size: .63rem;
  color: var(--txd);
  word-break: break-all;
}

/* Raw OCR text box */
.raw-txt-box {
  background: var(--s2);
  border: 1px solid var(--bd);
  border-radius: var(--rs);
  padding: .75rem;
  font-family: var(--fm);
  font-size: .65rem;
  color: var(--txm);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 240px;
  overflow-y: auto;
}

.raw-txt-box.empty {
  font-family: var(--f, inherit);
  font-style: italic;
}

/* Categorized + ref containers (use .src-kv child rows) */
.src-categorized,
.src-ref {
  display: flex;
  flex-direction: column;
}

.src-empty {
  font-size: .78rem;
  color: var(--txd);
  font-style: italic;
}

/* Copy button (Raw section header action) */
.src-copy-btn {
  font-family: var(--f, inherit);
  font-size: .65rem;
  color: var(--txm);
  background: var(--s1);
  border: 1px solid var(--bd);
  border-radius: 3px;
  padding: .15rem .45rem;
  cursor: pointer;
  transition: all .15s;
  text-transform: none;
  letter-spacing: 0;
}

.src-copy-btn:hover {
  color: var(--tx);
  border-color: var(--txm);
}

.src-copy-btn.copied {
  color: var(--ac);
  border-color: var(--ac);
  background: var(--ac2);
}
