/* Extract Tables — review editor. Mirrors the redact editor shell (overlay,
   two-row toolbar, sidebar→drawer, stage) so it reads as the same product.
   Tokens only (light + dark via :root vars); reduced-motion respected. */

/* ---- overlay + editor frame ---- */
.extract-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 16, 0.88);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  animation: editorOverlayIn .26s ease;
}

.extract-overlay.closing {
  animation: editorOverlayOut .2s ease forwards;
  pointer-events: none;
}
.extract-overlay.closing .extract-editor {
  animation: editorBoxOut .2s ease forwards;
}

.extract-editor {
  background: var(--bg-elev);
  border: 0;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  box-shadow: none;
  animation: editorBoxIn .28s cubic-bezier(.2, .7, .3, 1);
}
@media (prefers-reduced-motion: reduce) {
  .extract-overlay, .extract-editor { animation: none; }
  .extract-overlay.closing, .extract-overlay.closing .extract-editor { animation: none; }
}

/* ---- toolbar ---- */
.extract-toolbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.extract-toolbar-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 14px;
  flex-wrap: wrap;
}
.extract-toolbar-info { display: flex; flex-direction: column; gap: 2px; }
.extract-toolbar-info strong { font-size: 14px; }
.extract-count { font-size: 12px; color: var(--text-soft); font-variant-numeric: tabular-nums; }
.extract-toolbar-main {
  display: flex;
  align-items: center;
  gap: 8px 12px;
  flex-wrap: wrap;
}
.extract-grid-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.extract-grid-actions .btn { padding: 4px 10px; }
.extract-danger { color: var(--danger); }
/* The "Edit table" overflow is mobile-only: on desktop the grid actions stay inline,
   so the trigger + menu are hidden (the @media block flips it on). */
.extract-more, .extract-more-menu { display: none; }

/* ---- "Export this table" split menu (meta row, every viewport) ---- */
.extract-toolbar-meta-right { display: flex; align-items: center; gap: 8px; }
.extract-export { position: relative; display: inline-flex; }
.extract-export-btn { display: inline-flex; align-items: center; gap: 6px; }
.extract-export-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 184px;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius, 12px);
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.22);
  z-index: 60;
  transform-origin: top right;
  animation: menuIn 0.15s cubic-bezier(0.2, 0.7, 0.3, 1);
}
.extract-export.open .extract-export-menu { display: flex; }
.extract-export-menu .btn { width: 100%; justify-content: flex-start; }
@media (prefers-reduced-motion: reduce) { .extract-export-menu { animation: none; } }

/* ---- body: sidebar + stage ---- */
.extract-body {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}
.extract-sidebar {
  width: 248px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px;
  background: var(--bg);
}
.extract-sidebar-head { font-size: 13px; font-weight: 600; margin-bottom: 10px; color: var(--text); }
.extract-sidebar-empty { font-size: 12px; color: var(--text-soft); line-height: 1.5; }

.extract-table-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease, opacity .15s;
}
.extract-table-row:hover { border-color: var(--border-strong); }
.extract-table-row.active { border-color: var(--primary); background: var(--primary-soft); }
.extract-table-row.excluded { opacity: 0.55; }
.extract-table-row-main { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.extract-table-row-title { font-size: 13px; font-weight: 600; color: var(--text); }
.extract-table-row-dims { font-size: 11.5px; color: var(--text-soft); font-variant-numeric: tabular-nums; }
.extract-flag { color: var(--danger); font-weight: 600; }
.extract-table-row-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  color: var(--primary); flex-shrink: 0;
}
.extract-table-row.excluded .extract-table-row-toggle { color: var(--text-soft); }

/* ---- stage: source pane + grid pane, SIDE BY SIDE (three-pane: list | source | grid).
   The source page and the editable grid are independent scroll columns, so the grid —
   the deliverable — is reachable without scrolling past the page preview. ---- */
.extract-page-pane {
  flex: 0 0 clamp(300px, 32%, 420px);
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
}
.extract-pane-head {
  flex: 0 0 auto;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-mute);
}
.extract-page-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.extract-grid-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg-soft); }
.extract-grid-scroll { flex: 1; min-height: 0; overflow: auto; }

.extract-preview { display: flex; flex-direction: column; gap: 6px; }
.extract-preview-frame {
  position: relative;
  display: inline-block;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  background: #fff;
}
.extract-preview-canvas { display: block; }
.extract-preview-box {
  position: absolute;
  /* Fixed brand teal (not a theme token): this overlays the always-white PDF
     canvas, so a token that flips in dark mode would render wrong over white. */
  border: 2px solid #0e7490;
  background: rgba(14, 116, 144, 0.16);
  border-radius: 2px;
  pointer-events: none;
}
.extract-preview-cap { font-size: 11.5px; color: var(--text-soft); }

.extract-conf-note {
  font-size: 12.5px;
  color: var(--text);
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  max-width: 640px;
}

.extract-grid-wrap { padding: 18px; display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
table.extract-grid {
  border-collapse: collapse;
  font-size: 13px;
  background: var(--bg-elev);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
table.extract-grid td, table.extract-grid th {
  border: 1px solid var(--border);
  padding: 6px 10px;
  min-width: 64px;
  max-width: 320px;
  text-align: left;
  vertical-align: top;
  color: var(--text);
  outline: none;
  white-space: pre-wrap;
  word-break: break-word;
}
table.extract-grid th { background: var(--bg-soft); font-weight: 600; }
table.extract-grid tr.extract-grid-header th { background: var(--primary-soft); color: var(--text); }
table.extract-grid td:focus, table.extract-grid th:focus {
  box-shadow: inset 0 0 0 2px var(--primary);
  border-color: var(--primary);
}

/* ---- mobile drawer (≤720px): sidebar slides over the stage ---- */
.extract-drawer-toggle { display: none; align-items: center; gap: 6px; }
.extract-drawer-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--primary); color: #fff; border-radius: 9px;
  font-size: 11px; font-weight: 600;
}
.extract-drawer-scrim { display: none; }

@media (max-width: 720px) {
  .extract-overlay { padding: 0; }
  .extract-editor { height: 100vh; height: 100dvh; max-width: 100vw; border-radius: 0; border: none; }
  /* Top padding clears the iPhone notch / Dynamic Island when the page goes
     edge-to-edge (viewport-fit=cover); a no-op otherwise. */
  .extract-toolbar { padding-top: calc(10px + env(safe-area-inset-top)); }
  .extract-drawer-toggle { display: inline-flex; }
  .extract-sidebar {
    position: absolute;
    top: 0; bottom: 0; left: 0;
    width: min(82%, 320px);
    transform: translateX(-100%);
    transition: transform 0.22s cubic-bezier(0.2, 0.7, 0.2, 1);
    z-index: 6;
    box-shadow: var(--shadow-lg);
  }
  .extract-editor.drawer-open .extract-sidebar { transform: none; }
  .extract-drawer-scrim {
    display: block; position: absolute; inset: 0;
    background: rgba(8, 10, 16, 0.45); opacity: 0;
    pointer-events: none; transition: opacity 0.2s ease; z-index: 5;
  }
  .extract-editor.drawer-open .extract-drawer-scrim { opacity: 1; pointer-events: auto; }
  /* Side-by-side collapses to a stack on phones: the source page sits above the
     grid (each its own scroll), and the table list returns to the off-canvas
     drawer — the desktop scroll problem doesn't exist on a touch-scroll phone. */
  .extract-body { flex-direction: column; }
  .extract-page-pane { flex: 0 0 42%; border-right: none; border-bottom: 1px solid var(--border); }
  .extract-grid-pane { flex: 1 1 auto; }
  .extract-page-scroll, .extract-grid-wrap { padding: 12px; }
  .extract-grid-actions .btn { padding: 4px 8px; font-size: 12px; }
  /* Shorten the export label to just "Export" so the meta row stays tidy. */
  .extract-export-scope { display: none; }

  /* Two-row toolbar (the Organize pattern): meta row (title + Done) above a tools
     row holding the Tables drawer toggle + a "⋯ Edit table" overflow pinned right.
     The 6 grid-edit actions move into the dropdown (syncToolbar) instead of wrapping
     across two rows. Touch targets ≥44px. */
  .extract-toolbar-main { flex-wrap: nowrap; }
  .extract-drawer-toggle, .extract-more-btn { min-height: 44px; }
  .extract-more { display: inline-flex; position: relative; margin-left: auto; }
  .extract-more-btn { display: inline-flex; }
  .extract-more-menu {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 200px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius, 12px);
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.22);
    padding: 6px;
    z-index: 60;
    transform-origin: top right;
    animation: menuIn 0.15s cubic-bezier(0.2, 0.7, 0.3, 1);
  }
  .extract-more.open .extract-more-menu { display: block; }
  /* The grid-action group, relocated into the menu, becomes a vertical list of
     full-width rows. */
  .extract-more-menu .extract-grid-actions { flex-direction: column; align-items: stretch; gap: 2px; flex-wrap: nowrap; }
  .extract-more-menu .extract-grid-actions .btn { width: 100%; justify-content: flex-start; padding: 9px 10px; min-height: 44px; font-size: 14px; }

  @media (prefers-reduced-motion: reduce) {
    .extract-sidebar, .extract-drawer-scrim { transition: none; }
    .extract-more-menu { animation: none; }
  }
}
