/* Editor Document Layout */
.editor-document {
  max-width: 800px;
}

/* Editor Block */
.editor-block {
  padding: 1rem;
  margin-bottom: 1rem;
  border: 1px solid var(--tblr-border-color);
  border-radius: var(--tblr-border-radius);
  background: var(--tblr-bg-surface);
}

.editor-block-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--tblr-body-color);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--tblr-border-color);
}

/* Block Type Variants */
.editor-block--metadata {
  background: var(--tblr-bg-surface-secondary, #f8fafc);
}

.editor-block--signature {
  border-style: dashed;
}

/* Metadata Grid */
.editor-metadata-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

/* Rich Text Content */
.editor-block-content {
  line-height: 1.6;
}

.editor-block-content p {
  margin-bottom: 0.5rem;
}

.editor-block-content p:last-child {
  margin-bottom: 0;
}

/* Signature Cell */
.signature-cell {
  min-width: 120px;
  height: 40px;
  border-bottom: 1px solid var(--tblr-border-color);
}

/* Save Indicator */
.editor-save-indicator {
  font-size: 0.75rem;
  padding: 0.125rem 0.5rem;
  border-radius: var(--tblr-border-radius);
  transition: all 0.2s ease;
}

.editor-save-indicator--saving {
  color: var(--tblr-blue);
}

.editor-save-indicator--saved {
  color: var(--tblr-green);
}

.editor-save-indicator--error {
  color: var(--tblr-red);
}

/* AI Generating Overlay */
.editor-block--ai-generating {
  position: relative;
  pointer-events: none;
  user-select: none;
}

.ai-generating-overlay {
  position: relative;
  padding: 0.5rem 0;
}

.ai-generating-shimmer {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.ai-shimmer-line {
  height: 0.75rem;
  border-radius: 0.25rem;
  background: linear-gradient(
    90deg,
    rgba(2, 108, 255, 0.06) 0%,
    rgba(2, 108, 255, 0.12) 40%,
    rgba(2, 108, 255, 0.06) 80%
  );
  background-size: 200% 100%;
  animation: shimmer 1.8s ease-in-out infinite;
}

.ai-shimmer-line--long { width: 95%; }
.ai-shimmer-line--medium { width: 72%; animation-delay: 0.15s; }
.ai-shimmer-line--short { width: 48%; animation-delay: 0.3s; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.ai-generating-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  margin-top: 0.875rem;
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--tblr-primary);
  background: rgba(2, 108, 255, 0.06);
  border-radius: 1rem;
  animation: pulse-opacity 2.4s ease-in-out infinite;
}

@keyframes pulse-opacity {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Table Textarea */
.table textarea.form-control {
  resize: vertical;
  min-height: 2.5rem;
}

/* Lexxy Editor Styling */
lexxy-editor {
  display: block;
  min-height: 120px;
}

/* Override Tabler resets that conflict with Lexxy's :where() selectors (specificity 0) */
lexxy-editor button,
lexxy-editor summary {
  line-height: normal;
}

lexxy-editor .lexxy-editor__toolbar-button {
  display: grid;
  place-items: center;
}

lexxy-editor svg {
  vertical-align: baseline;
}

lexxy-editor [contenteditable] {
  padding: 0.5rem;
  border: 1px solid var(--tblr-border-color);
  border-radius: var(--tblr-border-radius);
  min-height: 120px;
  outline: none;
}

lexxy-editor [contenteditable]:focus {
  border-color: var(--tblr-primary);
  box-shadow: 0 0 0 0.25rem rgba(2, 108, 255, 0.15);
}

/* Block Builder: hide Bootstrap validation icon on textareas */
.block-builder-ai-fields textarea.is-invalid {
  background-image: none;
  padding-right: 0.75rem;
}

/* Block Builder (Admin Template Editor) */
.block-builder-card {
  transition: box-shadow 0.15s ease;
}

.block-builder-card:hover {
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.block-builder-ghost {
  opacity: 0.4;
  box-shadow: 0 0 0 2px var(--tblr-primary);
  border-radius: var(--tblr-border-radius);
}

.block-builder-drag-handle {
  cursor: grab;
  color: var(--tblr-secondary);
  display: flex;
  align-items: center;
}

.block-builder-drag-handle:active {
  cursor: grabbing;
}

.block-builder-field-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.block-builder-json-preview {
  max-height: 400px;
  overflow-y: auto;
  font-size: 0.8125rem;
}

.block-builder-card .card-header input.form-control {
  background: transparent;
}

.block-builder-card .card-header input.form-control:focus {
  background: var(--tblr-bg-surface);
}

/* Agent Workspace - Ghost Value Blocks */
.agent-workspace-blocks {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.agent-block {
  position: relative;
  border: 1px solid var(--tblr-border-color);
  border-radius: var(--tblr-border-radius);
  padding: 1rem;
  background: var(--tblr-bg-surface);
}

/* Pencil icon overlaid on the header's top-right. Lives inside the
   editable turbo-frame so it vanishes when the frame swaps to edit
   mode — prevents a stale "Edit" button from re-fetching the form
   over an in-progress edit. */
.agent-block-edit-icon {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: var(--tblr-border-radius);
  color: var(--tblr-secondary);
  opacity: 0.6;
  transition: opacity 0.15s, background-color 0.15s, color 0.15s;
}

.agent-block-edit-icon:hover {
  opacity: 1;
  color: var(--tblr-primary);
  background-color: var(--tblr-bg-surface-secondary);
}

/* Disabled state: pencil stays visible but unclickable while pending
   AI suggestions remain. Tooltip on hover explains why. */
.agent-block-edit-icon--disabled {
  cursor: not-allowed;
  opacity: 0.3;
}

.agent-block-edit-icon--disabled:hover {
  opacity: 0.45;
  color: var(--tblr-secondary);
  background-color: transparent;
}

/* Inline row-edit textareas: chrome-free so the editing surface reads
   like the table cell it sits in, not a stack of input boxes. The
   tallest textarea in the row drives row height via field-sizing
   (content-based growth); shorter siblings stretch to match via
   height: 100%, so every cell's editing surface fills its td. The td
   uses height: 1px so its computed height matches the intrinsic
   content height — the height: 100% cascade then gives each textarea
   the actual row height to fill. */
.editor-table-row--editing td {
  height: 1px;
  vertical-align: top;
  padding: 0.25rem 0.5rem;
}

/* The drag + actions cells host icons, not textareas — keep them
   vertically centred even when the row grows tall because of a
   multi-line textarea elsewhere in the row. */
.editor-table-row--editing td.editor-table-row-drag,
.editor-table-row--editing td.editor-table-row-actions {
  vertical-align: middle;
}

/* Tint the data cells of an in-progress row so the chrome-free
   textareas read as editable inputs and the driver sees at a glance
   which row is being worked on. The drag + action cells stay
   transparent so the floating-icon look is preserved. */
.editor-table-row--editing td {
  background-color: var(--tblr-bg-surface-secondary);
}

.editor-table-row-textarea {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  resize: none;
  outline: none;
  overflow: hidden;
  field-sizing: content;
}

.editor-table-row-textarea:focus {
  outline: 0;
  background: var(--tblr-bg-surface-secondary);
}

/* Ghost-icon affordances for the inline row form. Neutral by default;
   confirm tints green and cancel tints red on hover so the action
   semantics still read at a glance without dominating the row. */
.agent-row-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--tblr-secondary);
  opacity: 0.6;
  border-radius: var(--tblr-border-radius);
  transition: opacity 0.15s, background-color 0.15s, color 0.15s;
}

.agent-row-icon-button:hover,
.agent-row-icon-button:focus-visible {
  opacity: 1;
  background-color: var(--tblr-bg-surface-secondary);
  outline: 0;
}

.agent-row-icon-button--confirm:hover,
.agent-row-icon-button--confirm:focus-visible {
  color: var(--tblr-success);
}

.agent-row-icon-button--cancel:hover,
.agent-row-icon-button--cancel:focus-visible {
  color: var(--tblr-danger);
}

/* In edit mode the confirm / cancel icons drop the muted ghost look so
   the driver sees the call to action — colour the icon itself but keep
   it borderless / chromeless. Background still arrives on hover for the
   tactile cue. */
.editor-table-row--editing .agent-row-icon-button--confirm {
  color: var(--tblr-success);
  opacity: 1;
}

.editor-table-row--editing .agent-row-icon-button--cancel {
  color: var(--tblr-danger);
  opacity: 1;
}

/* The drag handle and the per-row actions (pencil + trash) all sit
   in the same visual family: small icons floating to the left of
   the table grid. Suppressing borders + background on these cells
   keeps the icons looking like canvas affordances rather than yet
   more bordered cells. */
.editor-table-row-drag,
.editor-table-row-actions,
.editor-table-edit thead th.editor-table-drag-header,
.editor-table-edit thead th.editor-table-actions-header {
  text-align: center;
  vertical-align: middle;
  padding: 0;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}

.editor-table-row-drag,
.editor-table-edit thead th.editor-table-drag-header {
  width: 1.75rem;
}

.agent-row-drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  color: var(--tblr-secondary);
  opacity: 0.4;
  cursor: grab;
  transition: opacity 0.15s, color 0.15s;
}

.agent-row-drag-handle:hover {
  opacity: 1;
  color: var(--tblr-primary);
}

.agent-row-drag-handle:active {
  cursor: grabbing;
}

/* Form-row placeholder cell — matches the drag-handle column width
   so the per-cell columns stay aligned with the read-mode rows.
   No grip icon: a row in edit mode can't be reordered. */
.editor-table-row-drag--disabled {
  background: transparent;
}

/* SortableJS placeholder while a row is in flight. */
.agent-row-sortable-ghost {
  opacity: 0.4;
  background: var(--tblr-bg-surface-secondary);
}

/* Trim the Lexxy toolbar inside the agent-workspace edit form. Lexxy
   builds its toolbar from a hardcoded defaultTemplate and exposes no
   config API to disable individual buttons, so we hide the items we
   don't support in this regulated context: highlight (color), link,
   quote, heading, code, divider, table, file upload. The remaining
   set (bold, italic, strikethrough, lists, undo/redo) covers what
   users actually need for prose blocks. */
.agent-block-edit-form lexxy-toolbar > [name="quote"],
.agent-block-edit-form lexxy-toolbar > [name="heading"],
.agent-block-edit-form lexxy-toolbar > [name="code"],
.agent-block-edit-form lexxy-toolbar > [name="divider"],
.agent-block-edit-form lexxy-toolbar > [name="table"],
.agent-block-edit-form lexxy-toolbar > [name="upload"],
.agent-block-edit-form lexxy-toolbar > details:has(> summary[name="highlight"]),
.agent-block-edit-form lexxy-toolbar > details:has(> summary[name="link"]) {
  display: none !important;
}

.agent-block--pending {
  border-color: var(--tblr-yellow);
  box-shadow: 0 0 0 1px var(--tblr-yellow-lt);
}

/* Block header: label + badges on the left, accept/reject (and later
   edit/iterate) on the right — Tabler card-actions pattern. Wraps on
   narrow widths so a long label or many badges don't push the actions
   off-screen. The header replaces the earlier left-rail layout: blocks
   now use their full content width, which matters most for prose
   blocks (rich_text, metadata) where a fixed rail was just dead space.
   Tables keep the sticky leading column for per-row accept/reject —
   that's a different concern and lives in the table component. */
.agent-block-header {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.agent-block-label {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-width: 0;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--tblr-secondary);
}

.agent-block-label-text {
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Block reference number — `#N`, monospace, subtle. Always visible
   so collaborators can refer to specific blocks ("look at #3") without
   needing the labels to be unique. Explicitly opts out of the label's
   uppercase / letter-spaced treatment. */
.agent-block-number {
  font-family: var(--tblr-font-monospace);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--tblr-secondary);
  opacity: 0.75;
  text-transform: none;
  letter-spacing: 0;
}

/* Block footer: dedicated action area at the bottom of the block. The
   border-top makes it read as a distinct affordance row instead of an
   appendage to the content. The flex-wrap layout will accommodate
   future Edit / Iterate buttons next to Accept / Reject and an
   inline iteration-prompt textarea below them, without the layout
   collapsing on narrow widths. */
.agent-block-footer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--tblr-border-color);
}

.agent-block-footer-hint {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.agent-block-footer-actions {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  margin-left: auto;
}

.agent-block-ghost {
  border-left: 3px solid var(--tblr-yellow);
  padding: 0.5rem 0.75rem;
  background: var(--tblr-yellow-lt);
  color: var(--tblr-body-color);
  border-radius: 0 var(--tblr-border-radius) var(--tblr-border-radius) 0;
  opacity: 0.85;
}

/* Row-level ghost: pending TableRow records (agent proposed them but
   the driver hasn't accepted yet). Styled so they read as "not real
   yet" without being hidden — the driver needs to decide. */
.editor-table-row--pending {
  background: var(--tblr-yellow-lt);
  color: var(--tblr-secondary);
  font-style: italic;
}

.editor-table-row--pending td {
  border-left: 2px solid var(--tblr-yellow);
}

/* Leading action column: stays pinned to the left edge of the
   `.table-responsive` scroll container so accept/reject (or trash)
   stay reachable even when the table scrolls horizontally. The
   sticky cell needs a *solid* background — Tabler's `--tblr-*-lt`
   tokens are RGBA with low alpha, so applying them directly let the
   data cells bleed through as the table scrolled underneath. We
   stack a solid surface base + the lt tint as a gradient layer so
   the cell stays visually opaque while still matching the row's
   pending/proposed colour. The drop-shadow on the right edge gives
   a soft seam that makes the sticky/scrollable boundary obvious. */
.editor-table-row-actions,
.editor-table-actions-header {
  position: sticky;
  left: 0;
  z-index: 2;
  background-color: var(--tblr-bg-surface);
  white-space: nowrap;
  box-shadow: 4px 0 4px -2px rgba(0, 0, 0, 0.08);
}

/* The thead cell of the action column inherits the theme's
   `.table thead th` rule (uppercase blue label on a tinted background),
   which makes the empty action cell read as a "real" data column and
   misleads the eye. Match the rule's specificity (`.table thead th.X`)
   to override: keep the solid sticky background, drop the heavy header
   underline in favour of the body-cell border colour, and mute the
   inherited header text styling so the cell visually merges with the
   body of the action column. */
.table thead th.editor-table-actions-header {
  background-color: var(--tblr-bg-surface);
  border-bottom: 1px solid var(--traqx-blue-50);
  color: transparent;
}

.editor-table-row--pending .editor-table-row-actions {
  background-color: var(--tblr-bg-surface);
  background-image: linear-gradient(var(--tblr-yellow-lt), var(--tblr-yellow-lt));
}

.editor-table-row-pending-badge {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.65rem;
}

/* Discard proposal: strikethrough so the driver sees "this is the
   row that will disappear if accepted" without the row vanishing
   from the ghost view. The action cell is explicitly excluded —
   otherwise the line bleeds across the empty space between accept
   and reject and reads as a misplaced separator dash. */
.editor-table-row--discard-proposed td {
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.editor-table-row--discard-proposed td.editor-table-row-actions {
  text-decoration: none;
}

/* Reference pills: one pill per target row inside a row_reference
   cell. Pending pills (from LinkTableRows proposals) use the same
   yellow accent as pending rows. */
.editor-reference-pill {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: var(--tblr-border-radius);
  background: var(--tblr-secondary-lt);
  font-family: var(--tblr-font-monospace);
  font-size: 0.8em;
}

.editor-reference-pill--pending {
  background: var(--tblr-yellow-lt);
  border: 1px dashed var(--tblr-yellow);
  color: var(--tblr-secondary);
}

/* Actionable pending pill: layout becomes a horizontal flex so the
   label sits next to the accept/reject icons. The icons are tiny
   unobtrusive glyphs; hover reveals their affordance without
   cluttering a normally-static doc view. */
.editor-reference-pill--actionable {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.05rem 0.2rem 0.05rem 0.4rem;
}

.editor-reference-pill-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.1rem;
  margin-left: 0.1rem;
}

.editor-reference-pill-action {
  padding: 0.05rem 0.25rem !important;
  line-height: 1;
  min-height: 0 !important;
}

.agent-block-ghost-body {
  font-style: italic;
  color: var(--tblr-secondary);
}

.agent-block-audit-id {
  font-family: var(--tblr-font-monospace);
  font-size: 0.7rem;
  letter-spacing: 0.02em;
}

.agent-block-ghost-table {
  background: transparent;
}

.agent-block-ghost-table td,
.agent-block-ghost-table th {
  border-color: rgba(0, 0, 0, 0.05);
}

.agent-block-ghost-row {
  background: transparent;
  font-style: normal;
  color: var(--tblr-body-color);
}

.agent-block-ghost-row--unchanged {
  color: var(--tblr-secondary);
  opacity: 0.75;
}

.agent-block-ghost-row--added {
  background: #d1f4d9;
  color: #0a3d17;
}

.agent-block-ghost-row--added ins {
  text-decoration: none;
  background: transparent;
}

.agent-block-ghost-row--removed {
  background: #fbd5d5;
  color: #7a1515;
}

.agent-block-ghost-row--removed del {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  color: #7a1515;
}

.agent-block-ghost-row--modified {
  background: #fff4d6;
  color: #5a4200;
}

.agent-block-ghost-cell-old {
  display: block;
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  color: #7a1515;
  background: #fbd5d5;
  padding: 0 0.25rem;
  border-radius: 3px;
  font-size: 0.9em;
  margin-bottom: 0.15rem;
}

.agent-block-ghost-cell-new {
  display: block;
  text-decoration: none;
  color: #0a3d17;
  background: #d1f4d9;
  padding: 0 0.25rem;
  border-radius: 3px;
  font-weight: 600;
}

.agent-block-ghost-metadata dt {
  font-weight: 500;
}

.agent-block-citations > summary {
  cursor: pointer;
  list-style: none;
}

.agent-block-citations > summary::-webkit-details-marker {
  display: none;
}

.agent-block-citation-list {
  padding-left: 1rem;
}

/* Sources block — sits below the footer (Accept/Reject) so the
   audit-grade "where did this come from?" panel is right next to the
   decision the driver is about to make. Collapsed by default; the
   summary row is a slim secondary-tone label that hints at the count
   without competing visually with the action buttons above. */
.agent-block-sources {
  margin-top: 0.5rem;
}

.agent-block-sources-summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.5rem;
  border-radius: var(--tblr-border-radius);
  background: transparent;
  transition: background-color 0.15s ease;
}

.agent-block-sources-summary:hover {
  background: var(--traqx-blue-50);
}

.agent-block-sources-summary::-webkit-details-marker {
  display: none;
}

.agent-block-sources-list {
  padding-left: 1.25rem;
  list-style: disc;
}

.agent-block-sources-list li + li {
  margin-top: 0.25rem;
}

.agent-workspace-readonly-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  margin-bottom: 1rem;
  background: var(--tblr-yellow-lt);
  border: 1px solid var(--tblr-yellow);
  border-radius: var(--tblr-border-radius);
  color: var(--tblr-body-color);
  font-size: 0.875rem;
}

/* Version Picker (Document Header) */
.editor-version-picker .dropdown-menu {
  min-width: 18rem;
  max-height: min(28rem, calc(100vh - 12rem));
  overflow-y: auto;
}

.editor-version-picker .dropdown-item.active .badge,
.editor-version-picker .dropdown-item:active .badge {
  background-color: rgba(255, 255, 255, 0.25) !important;
  color: #fff;
}

.editor-version-picker .dropdown-item.active .text-secondary,
.editor-version-picker .dropdown-item:active .text-secondary {
  color: rgba(255, 255, 255, 0.8) !important;
}

/* US-116 — Integrity trust badge (sealed documents).
   Small round icon next to the version picker in the agent workspace,
   lazy-loaded with a live verify!: green = verified, red = tamper.
   Opens the integrity modal on click. */
.editor-integrity-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 999px;
  background: var(--tblr-green-lt);
  color: var(--tblr-green);
  line-height: 1;
  text-decoration: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.editor-integrity-badge:hover,
.editor-integrity-badge:focus {
  background: var(--tblr-green);
  color: #fff;
}

.editor-integrity-badge--tamper {
  background: var(--tblr-red-lt);
  color: var(--tblr-red);
}

.editor-integrity-badge--tamper:hover,
.editor-integrity-badge--tamper:focus {
  background: var(--tblr-red);
  color: #fff;
}
