/* reports.css — Reports mode (Depth Calc + Tagger CSV) for the Field Describer.
   Ported from public/debug/index.html's report styles, retoned to the GRAIPH
   field design system (--graiph-* tokens, Nunito Sans, dark #00001E base,
   accent #33CC66). Scoped under #fdReportsContainer + the header controls. */

/* ── Mode container: full-bleed (overrides the centered default). The container
   itself does NOT scroll — its .rpt-body child does, so the section-detail dock
   can stay pinned at the bottom while the tab content scrolls above it. ── */
#fdReportsContainer.fd-mode-container {
  padding: 0;
  align-items: stretch;
  justify-content: stretch;
  flex-direction: column;
  display: flex;
  overflow: hidden;
}
#fdReportsContainer.fd-mode-container[hidden] {
  display: none;
}
/* Scrolling tab-content area (Depth Calc rows / Tagger tables). */
.rpt-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ── Header controls (tabs + settings gear), shown only in reports mode ── */
#fdReportsControls {
  display: none;
  align-items: center;
  gap: 4px;
}
body[data-fd-mode="reports"] #fdReportsControls {
  display: inline-flex;
}
/* Mirror the Geológico/Geotécnico segmented-pill style (.fd-kind-btn): solid
   green fill on the active tab, transparent outline otherwise. */
.rpt-tabbtn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 12px;
  appearance: none;
  border: 1px solid var(--graiph-border);
  border-radius: var(--graiph-radius-md);
  background: transparent;
  color: var(--graiph-text-primary);
  font: 600 13px/1 var(--graiph-font, "Nunito Sans", sans-serif);
  cursor: pointer;
}
.rpt-tabbtn:hover {
  border-color: var(--graiph-border-hover);
}
.rpt-tabbtn.active,
.rpt-tabbtn[aria-pressed="true"] {
  background: var(--graiph-accent);
  border-color: var(--graiph-accent);
  color: #00001E;
}

/* ── Reports second header (#fdReportsBar): refresh + visualization toggles
   (section-calculation settings come from the protocol, not the UI), mirroring
   the describer's second header. Shown only in reports mode. ── */
.fd-reports-bar {
  display: none;
  align-items: stretch;
  /* Wrap instead of horizontal-scroll: at narrow widths the Display group used
     to scroll off the right edge (overflow-x:auto) and get clipped, so its
     toggles couldn't be clicked. Wrapping drops the group to a second line when
     it can't fit; on wide screens everything stays on one row. `gap` doubles as
     the row-gap between wrapped lines. (Mirrors the A5 section-row wrap change.) */
  flex-wrap: wrap;
  gap: 7px;
  padding: 5px 10px;
  background: var(--graiph-bg-secondary);
  border-bottom: var(--graiph-border-default);
}
body[data-fd-mode="reports"] #fdReportsBar {
  display: flex;
}
.fd-reports-bar #fdReportsRefreshBtn {
  align-self: center;
  flex: 0 0 auto;
}
/* The bordered group panels make the inline separators redundant. */
.fd-reports-bar-sep {
  display: none;
}
/* Section / Display group = a subtle bordered panel with a leading header chip. */
.rpt-bar-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 3px 9px;
  background: var(--graiph-bg-tertiary);
  border: 1px solid var(--graiph-border);
  border-radius: var(--graiph-radius-md);
  white-space: nowrap;
  flex: 0 0 auto;
}
.rpt-bar-h {
  align-self: stretch;
  display: flex;
  align-items: center;
  padding-right: 8px;
  border-right: 1px solid var(--graiph-border);
  font: 800 9px/1 var(--graiph-font, "Nunito Sans", sans-serif);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--graiph-text-muted);
}
/* Toggles in the bar read as compact muted labels too. */
.fd-reports-bar .rpt-toggle {
  font-size: 10px;
  gap: 5px;
  color: var(--graiph-text-secondary);
}
.rpt-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--graiph-text-secondary);
  cursor: pointer;
}
.rpt-toggle input {
  accent-color: var(--graiph-accent);
}
.rpt-settings-divider {
  height: 1px;
  background: var(--graiph-border);
  margin: 2px 0;
}

/* ── Empty / loading states ── */
.rpt-empty,
.rpt-loading {
  margin: auto;
  text-align: center;
  color: var(--graiph-text-secondary);
  padding: 48px 24px;
}
.rpt-empty-msg {
  font-size: 15px;
  font-weight: 600;
  color: var(--graiph-text-primary);
}
.rpt-empty-hint,
.rpt-loading-label {
  font-size: 13px;
  margin-top: 8px;
  color: var(--graiph-text-muted);
}
.rpt-progress-bar {
  width: 240px;
  height: 4px;
  margin: 14px auto 0;
  background: var(--graiph-bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
}
.rpt-progress-fill {
  height: 100%;
  width: 0;
  background: var(--graiph-accent);
  transition: width 0.2s ease;
}
.rpt-spinner {
  width: 26px;
  height: 26px;
  margin: 0 auto 14px;
  border: 3px solid var(--graiph-border);
  border-top-color: var(--graiph-accent);
  border-radius: 50%;
  animation: rpt-spin 0.8s linear infinite;
}
@keyframes rpt-spin {
  to { transform: rotate(360deg); }
}

/* ── Tagger CSV tab ── */
.rpt-tagger {
  padding: 16px;
}
.rpt-subtabs {
  display: flex;
  gap: 2px;
  align-items: center;
  border-bottom: 1px solid var(--graiph-border);
  margin-bottom: 12px;
}
/* Copy / Download toolbar — pushed to the right end of the subtab row, same
   level as the tabs. */
.rpt-subtabs-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
  align-items: center;
}
.rpt-subtab {
  appearance: none;
  background: none;
  border: 1px solid transparent;
  border-bottom: none;
  padding: 6px 14px;
  font: 600 12px/1 var(--graiph-font, "Nunito Sans", sans-serif);
  color: var(--graiph-text-muted);
  cursor: pointer;
  border-radius: var(--graiph-radius-sm) var(--graiph-radius-sm) 0 0;
}
.rpt-subtab:hover {
  color: var(--graiph-text-primary);
  background: var(--graiph-bg-hover);
}
.rpt-subtab.active {
  color: var(--graiph-accent-text);
  background: var(--graiph-bg-tertiary);
  border-color: var(--graiph-border);
  margin-bottom: -1px;
}
.rpt-count {
  margin-left: 6px;
  padding: 0 5px;
  font-size: 9px;
  font-weight: 700;
  background: var(--graiph-bg-primary);
  border-radius: 8px;
  color: var(--graiph-text-muted);
}
.rpt-subpanel {
  display: none;
}
.rpt-subpanel.active {
  display: block;
}
.rpt-btn-xs {
  padding: 4px 9px !important;
  font-size: 11px !important;
}
.rpt-table-wrap {
  overflow: auto;
  max-height: 70vh;
  border: 1px solid var(--graiph-border);
  border-radius: var(--graiph-radius-sm);
}
.rpt-table {
  border-collapse: collapse;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11px;
  white-space: nowrap;
}
/* Left-justified tables (user request 2026-07-22): every cell and header
   shares one left edge. Group captions stay centered below. */
.rpt-table th,
.rpt-table td {
  padding: 3px 8px;
  border-bottom: 1px solid var(--graiph-border);
  text-align: left;
}
/* Frozen header + frozen first column (user request 2026-07-22): scrolling a
   wide CSV keeps the column headers AND the row identifier (Corrida / id / Core)
   in view. The grouped head is up to 3 rows tall (group captions + leaf
   headers); each row sticks below the previous via a fixed per-row height —
   single-line nowrap cells make the height deterministic. */
.rpt-table {
  --rpt-head-h: 24px;
}
.rpt-table th {
  position: sticky;
  top: 0;
  background: var(--graiph-bg-tertiary);
  color: var(--graiph-text-primary);
  z-index: 2;
  /* Headers carry a `title` glossary tooltip — cue the user it's hoverable. */
  cursor: help;
  text-decoration: underline dotted var(--graiph-border);
  text-underline-offset: 3px;
}
.rpt-table thead tr { height: var(--rpt-head-h); }
.rpt-table thead tr:nth-child(2) th { top: var(--rpt-head-h); }
.rpt-table thead tr:nth-child(3) th { top: calc(2 * var(--rpt-head-h)); }
/* Rowspan cells (ungrouped columns spanning the whole head) stick at the top. */
.rpt-table thead th[rowspan] { top: 0; }
/* First column: frozen against horizontal scroll. In multi-row heads the
   corner cell lives ONLY in the first tr (rowspan covers the rest), so no
   tr:nth-child rules are needed for later rows. Sticky cells need an opaque
   background; the row hover/selection tints are reapplied as a background-image
   layer so they still read over the opaque base. */
.rpt-table td:first-child,
.rpt-table thead tr:first-child th:first-child {
  position: sticky;
  left: 0;
  border-right: 1px solid var(--graiph-border);
}
.rpt-table td:first-child {
  background: var(--graiph-bg-primary);
  z-index: 1;
}
.rpt-table thead tr:first-child th:first-child {
  z-index: 3; /* corner: above both the sticky head row and the sticky column */
}
.rpt-table tbody tr:hover td:first-child {
  background-image: linear-gradient(var(--graiph-bg-hover), var(--graiph-bg-hover));
}
.rpt-table tbody tr.rpt-row.active td:first-child {
  background-image: linear-gradient(rgba(33, 150, 243, 0.18), rgba(33, 150, 243, 0.18));
}
/* Grouped-header caption spanning its run of leaf columns (e.g. "Minerales de
   Alteración"). Centered over its group; no glossary tooltip cue. */
.rpt-table th.rpt-th-group {
  text-align: center;
  cursor: default;
  text-decoration: none;
  border-left: 1px solid var(--graiph-border);
  border-right: 1px solid var(--graiph-border);
  font-weight: 700;
}
.rpt-table tbody tr:hover {
  background: var(--graiph-bg-hover);
}
.rpt-table tbody tr.rpt-row {
  cursor: pointer;
}
.rpt-table tbody tr.rpt-row.active {
  background: rgba(33, 150, 243, 0.18);
}

/* ── Depth Calc tab ── */
.rpt-depth {
  display: flex;
  gap: 16px;
  padding: 16px;
  align-items: flex-start;
}
.rpt-depth-main {
  flex: 1 1 0;
  min-width: 0;
}
.rpt-tray-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  padding: 4px;
  background: var(--graiph-bg-tertiary);
  border: 1px solid var(--graiph-border);
  border-radius: var(--graiph-radius-sm);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11px;
  align-items: stretch;
}
.rpt-img-container {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  border-radius: var(--graiph-radius-sm);
  position: relative;
}
/* Spin the refresh icon while a reload is in flight. */
#fdReportsRefreshBtn.rpt-refreshing i,
#fdReportsRefreshBtn.rpt-refreshing svg {
  animation: rpt-spin 0.8s linear infinite;
}
@keyframes rpt-spin {
  to { transform: rotate(360deg); }
}

/* Box drawn over the tray photo for the selected section. One per spanned
   gutter; left/top/width/height are set inline (px) from the gutter's
   bounding_rectangle + the bounding depth-blocks' center_position. */
.rpt-img-highlight {
  position: absolute;
  border: 2px solid #2196f3;
  background: rgba(33, 150, 243, 0.2);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  z-index: 6;
}
.rpt-img-container canvas.frac-overlay {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
}
.rpt-tray-meta {
  flex: 0 0 290px;
  min-width: 0;
  overflow: hidden;
}
.rpt-depth-main.cv-hidden .rpt-gstrips {
  display: none;
}
.rpt-depth-main.fr-hidden canvas.frac-overlay {
  display: none;
}
.rpt-depth-main.st-hidden .rpt-ststrips {
  display: none;
}
/* Estructuras-Mayores presence bands over the Visual-tab tray photo. The
   container ignores the pointer (like .rpt-gstrips) but each band is a
   click target → the record's range detail.

   Height is NOT set here: the bands' top/height percentages are normalized to
   the tray IMAGE, but .rpt-img-container is taller than the image (it also
   holds the depth caption). `inset: 0` stretched this box over image+caption,
   so every band drifted downward by ~16px worth of percent. paintSectionImage
   height-syncs it to img.offsetHeight once the lazy image decodes — exactly
   like .rpt-gstrips. */
.rpt-ststrips {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  pointer-events: none;
}
.rpt-st-band {
  position: absolute;
  pointer-events: auto;
  cursor: pointer;
  border-radius: 1px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45);
  opacity: 0.85;
}
.rpt-st-band:hover {
  opacity: 1;
}
.rpt-seg-clickable {
  cursor: pointer;
  border-radius: 2px;
}
.rpt-seg-clickable:hover {
  background: var(--graiph-bg-hover);
}
.rpt-seg-clickable.active {
  background: rgba(33, 150, 243, 0.18);
}

/* Chart side column (detail moved to the shared bottom dock → more room here) */
.rpt-depth-side {
  flex: 0 0 480px;
  width: 480px;
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.rpt-chart-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.rpt-chart-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--graiph-text-primary);
}
.rpt-chart-sub {
  font-size: 11px;
  color: var(--graiph-text-muted);
}
.rpt-chart-wrap {
  position: relative;
}
.rpt-chart-wrap canvas {
  width: 100%;
  border: 1px solid var(--graiph-border);
  border-radius: var(--graiph-radius-sm);
  background: var(--graiph-bg-primary);
}
.rpt-sel-marker {
  display: none;
  position: absolute;
  pointer-events: none;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid var(--graiph-accent);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--graiph-accent);
  z-index: 9;
}
.rpt-tooltip {
  display: none;
  position: absolute;
  pointer-events: none;
  /* Theme-aware surface — the hardcoded dark navy was wrong on the light theme. */
  background: var(--graiph-bg-secondary);
  border: 1px solid var(--graiph-border);
  border-radius: 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  padding: 6px 10px;
  font-size: 11px;
  color: var(--graiph-text-primary);
  white-space: nowrap;
  z-index: 10;
}

/* Section detail: full-width dock pinned at the bottom of the mode container,
   shared by both tabs (Depth Calc selection + Tagger CSV row click). */
.rpt-section-detail {
  flex: 0 0 auto;
  max-height: 42vh;
  overflow-y: auto;
  background: var(--graiph-bg-secondary);
  border-top: 2px solid var(--graiph-border);
}
.rpt-section-detail[hidden] {
  display: none;
}
.rpt-detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 12px;
  background: var(--graiph-bg-tertiary);
  border-bottom: 1px solid var(--graiph-border);
  position: sticky;
  top: 0;
  z-index: 1;
}
.rpt-detail-title {
  font-weight: 700;
  font-size: 12px;
  color: var(--graiph-alert-info);
}
.rpt-detail-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.rpt-detail-link {
  appearance: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  color: var(--graiph-text-secondary);
  background: var(--graiph-bg-secondary);
  border: 1px solid var(--graiph-border);
  border-radius: var(--graiph-radius-sm);
  padding: 3px 9px;
  text-decoration: none;
  white-space: nowrap;
}
.rpt-detail-link:hover {
  color: var(--graiph-accent-text);
  border-color: var(--graiph-accent);
}
.rpt-detail-close {
  cursor: pointer;
  color: var(--graiph-text-muted);
  background: none;
  border: none;
  font-size: 18px;
  line-height: 1;
}
.rpt-detail-close:hover {
  color: var(--graiph-alert-error);
}
/* Block layout (matches the debug interface): the section image strip on top,
   the metric KVs underneath it. */
.rpt-detail-body {
  padding: 8px 12px;
}
.rpt-detail-img {
  background: var(--graiph-bg-primary);
  border: 1px solid var(--graiph-border);
  border-radius: var(--graiph-radius-sm);
  overflow-x: auto;
  overflow-y: hidden;
  min-height: 114px;
  display: flex;
  align-items: flex-start;
}
.rpt-detail-img canvas {
  display: block;
}
.rpt-img-note {
  font-size: 11px;
  color: var(--graiph-text-muted);
  padding: 8px 10px;
}
.rpt-detail-data {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 18px;
  margin-top: 8px;
}
.rpt-kv {
  display: flex;
  gap: 5px;
  font-size: 12px;
}
.rpt-kv .k {
  color: var(--graiph-text-muted);
}
.rpt-kv .v {
  font-weight: 600;
  color: var(--graiph-text-primary);
}

/* Narrow tablets: stack the chart column under the rows. */
@media (max-width: 1100px) {
  .rpt-depth {
    flex-direction: column;
  }
  .rpt-depth-side {
    flex: 1 1 auto;
    width: 100%;
    position: static;
  }
}
