/* ── BULK ENTRY / BULK EDIT ──
   Phase 12E: extracted verbatim from components.css lines 2580-3223 (no rule changes).
   Cascade order preserved exactly: stylesheet links in index.html load these files
   in the original source order. Contents: Phase 4 bulk entry panel, Phase 4.1 editable grid, Phase 4.2 bulk edit */

/* ── PHASE 4: BULK ENTRY PANEL ─────────────────────────────────────────────── */

.bulk-panel {
  display: none;
  flex-direction: column;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
  border-top: 2px solid var(--accent);
  overflow: hidden;
  padding: 0;
}

/* Scroll area below the sticky header (info bar + grid + raw section) */
.bulk-panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

.bulk-panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}

.bulk-panel-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
  flex: 1;
  min-width: 160px;
}

.bulk-panel-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.bulk-panel-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
}

.bulk-section-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
}

.bulk-textarea {
  width: 100%;
  min-height: 180px;
  max-height: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.82rem;
  padding: 12px;
  border-radius: 6px;
  resize: vertical;
  box-sizing: border-box;
  line-height: 1.5;
}
.bulk-textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.bulk-textarea::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

.bulk-status-line {
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  gap: 14px;
  align-items: center;
}
.bulk-valid-count {
  color: var(--green);
}
.bulk-invalid-count {
  color: var(--red);
}

.bulk-result-banner {
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}
.bulk-result-ok   { color: var(--green); }
.bulk-result-fail { color: var(--red); }

/* Preview table */
.bulk-preview-section {
  padding: 0 20px 20px;
}

.bulk-preview-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.bulk-preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  table-layout: auto;
}

.bulk-preview-table th {
  background: var(--surface2);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  text-align: left;
}

.bulk-preview-table td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  color: var(--text);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bulk-preview-table tbody tr:hover {
  background: var(--surface2);
}

.bulk-th-idx, .bulk-idx {
  width: 30px;
  text-align: center;
  color: var(--muted);
  font-size: 0.7rem;
}

.bulk-req-star {
  color: var(--red);
  margin-left: 2px;
}

.bulk-row-invalid {
  background: rgba(255, 61, 87, 0.05);
}
.bulk-row-invalid:hover {
  background: rgba(255, 61, 87, 0.09) !important;
}

.bulk-cell-error {
  background: rgba(255, 61, 87, 0.15) !important;
  color: var(--red) !important;
  border-bottom-color: rgba(255, 61, 87, 0.3) !important;
  cursor: help;
  position: relative;
}

.bulk-th-errors {
  min-width: 200px;
}
.bulk-errors-cell {
  white-space: normal !important;
  max-width: 240px;
  padding: 4px 8px !important;
}
.bulk-errors-cell span {
  display: block;
  color: var(--red);
  font-size: 0.72rem;
  line-height: 1.4;
}

/* Light-mode overrides */
.light-mode .bulk-panel {
  background: var(--bg);
}
.light-mode .bulk-panel-header {
  background: #fff;
}
.light-mode .bulk-textarea {
  background: #fff;
  color: var(--text);
}
.light-mode .bulk-preview-table th {
  background: #f1f5f9;
}
.light-mode .bulk-row-invalid {
  background: rgba(220, 38, 38, 0.05);
}
.light-mode .bulk-cell-error {
  background: rgba(220, 38, 38, 0.12) !important;
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .bulk-panel-header {
    padding: 10px 14px;
  }
  .bulk-panel-body {
    padding: 14px;
  }
  .bulk-preview-section {
    padding: 0 14px 14px;
  }
}

/* ── PHASE 4.1: EDITABLE GRID ──────────────────────────────────────────────── */

/* Info / status bar */
.bulk-info-bar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 20px 6px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.bulk-helper-text {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

/* Grid wrapper — scrollable both axes, flex:1 so it expands to fill scroll area */
.bulk-grid-wrapper {
  flex: 1;
  min-height: 0;
  overflow: auto;
  margin: 12px 20px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* Grid table */
.bg-table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
  font-size: 0.8rem;
}

/* Sticky header */
.bg-table thead tr {
  position: sticky;
  top: 0;
  z-index: 3;
}
.bg-table thead th {
  background: var(--surface2);
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 6px 8px;
  border: 1px solid var(--border);
  white-space: nowrap;
  text-align: left;
  user-select: none;
}
.bg-th-req {
  color: var(--accent) !important;
}
.bg-th-idx {
  width: 28px;
  min-width: 28px !important;
  text-align: center;
}

/* Body cells */
.bg-table tbody tr:nth-child(even) {
  background: rgba(255,255,255,0.02);
}
.bg-table tbody tr:hover {
  background: rgba(255,255,255,0.04);
}
.bg-td {
  padding: 0;
  border: 1px solid var(--border);
  height: 28px;
  vertical-align: middle;
  position: relative;
}
.bg-td-err {
  background: rgba(255, 61, 87, 0.18) !important;
}
/* Red corner marker so an invalid cell is identifiable at a glance even before the
   user hovers for the tooltip. Drawn as a triangle in the top-right; pointer-events
   off so it never blocks clicks/selection. Shared by Bulk Entry (.bg-td) and Bulk
   Edit (.be-td) — both cells are position:relative. */
.bg-td-err::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 0;
  height: 0;
  border-top: 7px solid var(--red);
  border-left: 7px solid transparent;
  pointer-events: none;
  z-index: 2;
}
.bg-row-bad .bg-idx {
  color: var(--red) !important;
  font-weight: 700;
}
.bg-idx {
  padding: 0 6px;
  text-align: center;
  font-size: 0.68rem;
  color: var(--muted);
  border: 1px solid var(--border);
  background: var(--surface2);
  white-space: nowrap;
  min-width: 28px;
  user-select: none;
}

/* Cell inputs */
.bg-inp {
  display: block;
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.8rem;
  padding: 3px 7px;
  box-sizing: border-box;
  outline: none;
  min-width: 0;
}
/* Phase 11D: orange focus accent applies in EDIT mode only. In selection mode the
   cell <input> is readonly (but still focusable), so it must not look editable. */
.bg-inp:not([readonly]):focus {
  background: rgba(245, 166, 35, 0.07);
  box-shadow: inset 0 0 0 2px var(--accent);
  position: relative;
  z-index: 1;
}
/* Selection mode (readonly input): hide the text caret + use a cell cursor so the
   cell reads as "selected", not "editing". */
.bg-inp[readonly] {
  cursor: cell;
  caret-color: transparent;
}
.bg-td-err .bg-inp {
  color: var(--red);
}
.bg-td-err .bg-inp:focus {
  background: rgba(255, 61, 87, 0.12);
  box-shadow: inset 0 0 0 2px var(--red);
}
.bg-td-sel {
  background: rgba(59, 130, 246, 0.28) !important;
}
.bg-td-sel .bg-inp {
  background: transparent !important;
}
.bg-td-sel .bg-inp:focus {
  box-shadow: inset 0 0 0 2px #3b82f6 !important;
  background: rgba(59, 130, 246, 0.14) !important;
  z-index: 2;
}
.bg-td-sel.bg-td-err .bg-inp {
  color: var(--red) !important;
}
/* Selection outer-edge borders — form an Excel-like rectangle around the range */
.bg-sel-top    { border-top:    2px solid #3b82f6 !important; }
.bg-sel-bottom { border-bottom: 2px solid #3b82f6 !important; }
.bg-sel-left   { border-left:   2px solid #3b82f6 !important; }
.bg-sel-right  { border-right:  2px solid #3b82f6 !important; }
.bg-col-sel {
  background: rgba(59, 130, 246, 0.35) !important;
  color: #93c5fd;
  font-weight: 700;
}
.bg-idx-err {
  color: var(--red) !important;
  font-weight: 700;
}

/* Phase 11D: active EDIT cell — amber/accent treatment, distinct from the blue
   selection. Overrides selection blue so the editing cell is unmistakable. */
.bg-td-edit {
  background: rgba(245, 166, 35, 0.16) !important;
  z-index: 3;
}
.bg-td-edit .bg-inp,
.bg-td-edit .bg-inp:focus {
  background: rgba(245, 166, 35, 0.10) !important;
  box-shadow: inset 0 0 0 2px var(--accent) !important;
  caret-color: var(--accent);
  cursor: text;
}

/* Raw paste fallback */
.bulk-raw-section {
  padding: 10px 20px 16px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}
.bulk-raw-toggle {
  font-size: 0.75rem;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.bulk-raw-toggle:hover {
  color: var(--text);
}
#bulk-raw-paste-area {
  margin-top: 10px;
}

/* Light-mode overrides for the grid */
.light-mode .bulk-info-bar {
  background: #f8fafc;
}
.light-mode .bg-table thead th {
  background: #f1f5f9;
}
.light-mode .bg-table tbody tr:nth-child(even) {
  background: rgba(0,0,0,0.02);
}
.light-mode .bg-table tbody tr:hover {
  background: rgba(0,0,0,0.03);
}
.light-mode .bg-idx {
  background: #f1f5f9;
}
.light-mode .bg-inp {
  color: var(--text);
}
.light-mode .bg-td-err {
  background: rgba(220, 38, 38, 0.10) !important;
}
.light-mode .bg-inp:not([readonly]):focus {
  background: rgba(245, 158, 11, 0.06);
}
.light-mode .bg-td-edit {
  background: rgba(245, 158, 11, 0.14) !important;
}
.light-mode .bg-td-edit .bg-inp,
.light-mode .bg-td-edit .bg-inp:focus {
  background: rgba(245, 158, 11, 0.10) !important;
  box-shadow: inset 0 0 0 2px #d97706 !important;
  caret-color: #d97706;
}
.light-mode .bg-td-sel {
  background: rgba(37, 99, 235, 0.20) !important;
}
.light-mode .bg-td-sel .bg-inp:focus {
  box-shadow: inset 0 0 0 2px #2563eb !important;
  background: rgba(37, 99, 235, 0.12) !important;
}
.light-mode .bg-sel-top    { border-top:    2px solid #2563eb !important; }
.light-mode .bg-sel-bottom { border-bottom: 2px solid #2563eb !important; }
.light-mode .bg-sel-left   { border-left:   2px solid #2563eb !important; }
.light-mode .bg-sel-right  { border-right:  2px solid #2563eb !important; }
.light-mode .bg-col-sel {
  background: rgba(37, 99, 235, 0.22) !important;
  color: #1d4ed8;
  font-weight: 700;
}

/* Mobile: allow horizontal scroll */
@media (max-width: 768px) {
  .bulk-grid-wrapper {
    margin: 8px 10px 8px;
  }
  .bulk-info-bar {
    padding: 8px 12px 6px;
  }
  .bulk-raw-section {
    padding: 8px 12px 12px;
  }
}

/* ── BULK EDIT (Phase 4.2) ───────────────────────────────────────────────────── */

/* Base cell — mirrors bg-td geometry */
.be-td {
  border: 1px solid rgba(255,255,255,0.04);
  padding: 0;
  vertical-align: top;
  position: relative;
}

/* Dirty (changed) cell — amber/yellow */
.be-td-dirty {
  background: rgba(245, 158, 11, 0.22) !important;
}
.be-td-dirty .bg-inp {
  background: transparent !important;
}

/* Dirty row index indicator */
.be-idx-dirty {
  color: #f59e0b !important;
  font-weight: 700;
}
.be-row-dirty {
  background: rgba(245, 158, 11, 0.05) !important;
}

/* Read-only cell */
.be-td-ro {
  background: rgba(100, 116, 139, 0.08) !important;
}
.be-td-ro .bg-inp {
  color: var(--muted) !important;
  cursor: default;
  background: transparent !important;
}

/* Read-only column header */
.be-th-ro {
  color: var(--muted);
  font-style: italic;
}

/* Selection — same blue as Bulk Entry */
.be-td-sel {
  background: rgba(59, 130, 246, 0.28) !important;
}
.be-td-sel .bg-inp {
  background: transparent !important;
}
.be-td-sel .bg-inp:focus {
  box-shadow: inset 0 0 0 2px #3b82f6 !important;
  background: rgba(59, 130, 246, 0.14) !important;
  z-index: 2;
}
/* Dirty + selected: blue wins, yellow shows through slightly */
.be-td-sel.be-td-dirty {
  background: rgba(59, 130, 246, 0.28) !important;
}
.be-td-sel.be-td-dirty .bg-inp {
  background: transparent !important;
}
/* Error text preserved when selected */
.be-td-sel.bg-td-err .bg-inp {
  color: var(--red) !important;
}

/* Selection outer-edge borders */
.be-sel-top    { border-top:    2px solid #3b82f6 !important; }
.be-sel-bottom { border-bottom: 2px solid #3b82f6 !important; }
.be-sel-left   { border-left:   2px solid #3b82f6 !important; }
.be-sel-right  { border-right:  2px solid #3b82f6 !important; }

/* Phase 11D: active EDIT cell — amber/accent, distinct from blue selection */
.be-td-edit {
  background: rgba(245, 166, 35, 0.16) !important;
  z-index: 3;
}
.be-td-edit .bg-inp,
.be-td-edit .bg-inp:focus {
  background: rgba(245, 166, 35, 0.10) !important;
  box-shadow: inset 0 0 0 2px var(--accent) !important;
  caret-color: var(--accent);
  cursor: text;
}

/* Column header selection */
.be-col-sel {
  background: rgba(59, 130, 246, 0.35) !important;
  color: #93c5fd;
  font-weight: 700;
}

/* Helper text with amber accent */
.be-helper-text { color: #f59e0b; font-weight: 500; }

/* Status bar stats */
.be-status-line { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: 0.78rem; }
.be-stat { color: var(--muted); }
.be-stat strong { color: var(--text); }
.be-stat-changed strong { color: #f59e0b; }
.be-stat-invalid strong { color: var(--red); }
.be-stat-valid   strong { color: var(--green); }

/* Light mode overrides */
.light-mode .be-td {
  border-color: rgba(0,0,0,0.07);
}
.light-mode .be-td-dirty {
  background: rgba(217, 119, 6, 0.14) !important;
}
.light-mode .be-idx-dirty { color: #d97706 !important; }
.light-mode .be-row-dirty { background: rgba(217, 119, 6, 0.05) !important; }
.light-mode .be-td-ro {
  background: rgba(100, 116, 139, 0.06) !important;
}
.light-mode .be-td-sel {
  background: rgba(37, 99, 235, 0.18) !important;
}
.light-mode .be-td-sel .bg-inp:focus {
  box-shadow: inset 0 0 0 2px #2563eb !important;
  background: rgba(37, 99, 235, 0.10) !important;
}
.light-mode .be-td-edit {
  background: rgba(217, 119, 6, 0.14) !important;
}
.light-mode .be-td-edit .bg-inp,
.light-mode .be-td-edit .bg-inp:focus {
  background: rgba(217, 119, 6, 0.10) !important;
  box-shadow: inset 0 0 0 2px #d97706 !important;
  caret-color: #d97706;
}
.light-mode .be-sel-top    { border-top:    2px solid #2563eb !important; }
.light-mode .be-sel-bottom { border-bottom: 2px solid #2563eb !important; }
.light-mode .be-sel-left   { border-left:   2px solid #2563eb !important; }
.light-mode .be-sel-right  { border-right:  2px solid #2563eb !important; }
.light-mode .be-col-sel {
  background: rgba(37, 99, 235, 0.20) !important;
  color: #1d4ed8;
  font-weight: 700;
}
.light-mode .be-helper-text { color: #d97706; }

/* ── PHASE 17F: ROW SELECTION + PENDING DELETE ───────────────────────────────── */

/* Row-number header cells are clickable (select the full row) */
td.bg-idx { cursor: pointer; }

/* Row-header-selected rows — same blue treatment as the cell selection */
tr.bg-row-sel td.bg-td,
tr.bg-row-sel td.be-td {
  background: rgba(59, 130, 246, 0.28) !important;
}
tr.bg-row-sel td.bg-td .bg-inp,
tr.bg-row-sel td.be-td .bg-inp {
  background: transparent !important;
}
.bg-idx-sel {
  background: rgba(59, 130, 246, 0.45) !important;
  color: #93c5fd !important;
  font-weight: 700;
}

/* Bulk Edit pending-delete rows — danger tint + strikethrough + DEL badge.
   Declared after the row-selection rules so the red marking wins if a
   pending-delete row is row-selected again (e.g. to copy it). */
tr.be-row-pd td.be-td {
  background: rgba(255, 61, 87, 0.16) !important;
}
tr.be-row-pd .bg-inp {
  text-decoration: line-through;
  color: var(--red) !important;
}
.be-idx-pd {
  background: var(--red) !important;
  color: #fff !important;
  font-weight: 700;
}
.be-idx-pd::after {
  content: "DEL";
  display: block;
  font-size: 0.55rem;
  letter-spacing: 0.08em;
  line-height: 1;
}

/* Status-line counters */
.be-stat-rowsel strong { color: #3b82f6; }
.be-stat-pd,
.be-stat-pd strong { color: var(--red); }

/* Light mode */
.light-mode tr.bg-row-sel td.bg-td,
.light-mode tr.bg-row-sel td.be-td {
  background: rgba(37, 99, 235, 0.18) !important;
}
.light-mode .bg-idx-sel {
  background: rgba(37, 99, 235, 0.30) !important;
  color: #1d4ed8 !important;
}
.light-mode tr.be-row-pd td.be-td {
  background: rgba(220, 38, 38, 0.10) !important;
}
