/* ============ Grid view ============ */
.grid-view { flex: 1; min-height: 0; display: flex; flex-direction: column; background: #f7f8fa; }
.grid-scroll { flex: 1; overflow: auto; position: relative; background: #f7f8fa; outline: none; }
.grid-canvas { position: relative; min-width: 100%; width: max-content; padding-bottom: 80px; }

/* ---------- header ---------- */
.grid-header {
  display: flex; position: sticky; top: 0; z-index: 12;
  height: 32px; background: #fff;
}
.gh-left {
  position: sticky; left: 0; z-index: 13;
  display: flex; background: #f5f5f5;
  border-bottom: 1px solid var(--border);
}
.gh-rownum {
  width: 66px; flex: none; display: flex; align-items: center;
  padding-left: 14px; color: var(--text-quiet);
}
.gh-rownum input[type="checkbox"] { accent-color: var(--blue); width: 12px; height: 12px; cursor: pointer; }
.gh-field {
  flex: none; display: flex; align-items: center; gap: 6px;
  padding: 0 8px; background: #f5f5f5;
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  cursor: pointer; user-select: none; position: relative;
}
.gh-field:hover { background: #eeeeee; }
.gh-field .gh-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; font-size: 13px; }
.gh-field .gh-typeicon { color: var(--text-quiet); flex: none; }
.gh-field .gh-caret { display: none; color: var(--text-quiet); flex: none; }
.gh-field:hover .gh-caret { display: inline-flex; }
.gh-field.primary { border-right-color: transparent; }
.gh-field.dragging { opacity: 0.4; }
.gh-add {
  flex: none; width: 94px; display: flex; align-items: center; justify-content: center;
  background: #f5f5f5; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  color: var(--text-quiet); cursor: pointer;
}
.gh-add:hover { background: #eeeeee; color: var(--text); }
.gh-resize {
  position: absolute; right: -3px; top: 0; bottom: 0; width: 7px;
  cursor: col-resize; z-index: 5;
}
.gh-resize:hover::after, .gh-resize.resizing::after {
  content: ""; position: absolute; left: 2px; top: 0; bottom: 0; width: 3px; background: var(--blue-focus);
}
.col-resize-guide { position: absolute; top: 0; width: 3px; background: var(--blue-focus); opacity: 0.6; z-index: 40; pointer-events: none; }
.col-drop-indicator { position: absolute; top: 0; width: 3px; background: var(--blue-focus); z-index: 40; pointer-events: none; }

/* separator below the frozen column */
.frozen-divider { box-shadow: 2px 0 4px rgba(0,0,0,0.07); clip-path: inset(0 -8px 0 0); border-right: 1px solid var(--border-dark); }

/* ---------- rows ---------- */
.grid-row { display: flex; position: relative; }
.gr-left {
  position: sticky; left: 0; z-index: 8;
  display: flex; background: #fff;
}
.grid-row:hover .gr-left, .gr-left.hover { background: #f8f8f8; }
.gr-rownum {
  width: 66px; flex: none; display: flex; align-items: center;
  border-bottom: 1px solid var(--border);
  color: var(--text-quiet); font-size: 12px;
  position: relative;
}
.gr-rownum .rn-number { width: 100%; text-align: left; padding-left: 18px; }
.gr-rownum .rn-check { display: none; margin-left: 13px; }
.gr-rownum .rn-check input { accent-color: var(--blue); width: 12px; height: 12px; cursor: pointer; display: block; }
.rn-expand {
  display: none; position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px; border-radius: 4px;
  align-items: center; justify-content: center; color: var(--blue);
  background: #fff; box-shadow: 0 0 0 1px var(--border);
  z-index: 3;
}
.rn-expand:hover { background: #eaf2fe; }
.gr-rownum .rn-drag {
  display: none; position: absolute; left: 2px; top: 50%; transform: translateY(-50%);
  color: var(--text-faint); cursor: grab; padding: 2px 0;
}
.grid-row:hover .rn-number, .grid-row.checked .rn-number { display: none; }
.grid-row:hover .rn-check, .grid-row.checked .rn-check { display: block; }
.grid-row:hover .rn-expand { display: inline-flex; }
.grid-row:hover .rn-drag { display: block; }
.row-colorstrip { position: absolute; left: 0; top: 0; bottom: 1px; width: 5px; }
.grid-row.checked .gr-left, .grid-row.checked .cell { background-color: #f0f6ff; }

.cell {
  flex: none; display: flex; align-items: center;
  padding: 0 8px; background: #fff;
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  font-size: 13px; position: relative; overflow: hidden;
  cursor: default; user-select: none;
}
.grid-row:hover .cell { background-color: #f8f8f8; }
.cell.primary-cell { border-right-color: transparent; font-weight: 500; }
.cell .cell-content { width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell.align-right .cell-content { text-align: right; }
.cell .pill + .pill, .cell .link-pill + .link-pill { margin-left: 4px; }
.cell.wrap .cell-content { white-space: normal; align-self: flex-start; padding-top: 5px;
  display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.4; }

/* selection */
.cell.in-range { background-color: rgba(45,127,249,0.08) !important; }
.cell.rng-t { box-shadow: inset 0 1px 0 0 var(--blue-focus); }
.cell.rng-b { box-shadow: inset 0 -1px 0 0 var(--blue-focus); }
.cell.rng-l { box-shadow: inset 1px 0 0 0 var(--blue-focus); }
.cell.rng-r { box-shadow: inset -1px 0 0 0 var(--blue-focus); }
.cell.rng-t.rng-l { box-shadow: inset 1px 1px 0 0 var(--blue-focus); }
.cell.rng-t.rng-r { box-shadow: inset -1px 1px 0 0 var(--blue-focus); }
.cell.rng-b.rng-l { box-shadow: inset 1px -1px 0 0 var(--blue-focus); }
.cell.rng-b.rng-r { box-shadow: inset -1px -1px 0 0 var(--blue-focus); }
.cell.rng-t.rng-b.rng-l.rng-r { box-shadow: inset 0 0 0 1px var(--blue-focus); }
.cell.active {
  box-shadow: inset 0 0 0 2px var(--blue-focus) !important;
  border-radius: 2px; background: #fff !important; z-index: 2;
}
.cell.active .fill-handle {
  position: absolute; right: -1px; bottom: -1px; width: 7px; height: 7px;
  background: var(--blue-focus); border: 1px solid #fff; border-radius: 1px; cursor: crosshair;
}
.cell.search-hit { background-color: #ffe58f !important; }
.cell.search-hit-active { background-color: #ffc53d !important; }

/* inline editor */
.cell-editor {
  position: absolute; z-index: 50;
  background: #fff; box-shadow: 0 0 0 2px var(--blue-focus), 0 4px 12px rgba(0,0,0,0.18);
  border-radius: 3px; display: flex; align-items: stretch;
}
.cell-editor input, .cell-editor textarea {
  border: none; outline: none; width: 100%; padding: 0 8px;
  font-size: 13px; font-family: inherit; background: transparent;
}
.cell-editor textarea { padding: 6px 8px; resize: none; line-height: 1.45; }
.cell-editor.number-editor input { text-align: right; }
.longtext-editor-hint {
  position: absolute; bottom: 3px; right: 8px; font-size: 10px; color: var(--text-faint);
  pointer-events: none; background: rgba(255,255,255,0.85); padding: 1px 3px; border-radius: 2px;
}

/* ---------- add-row ---------- */
.grid-addrow { display: flex; cursor: pointer; }
.grid-addrow .gr-left { cursor: pointer; }
.grid-addrow .gr-rownum { color: var(--text-quiet); }
.grid-addrow .addrow-plus { margin-left: 14px; display: inline-flex; color: var(--text-quiet); }
.grid-addrow:hover .gr-left { background: #f2f2f2; }
.grid-addrow .addrow-rest { flex: none; border-bottom: 1px solid var(--border); background: #fff; }
.grid-addrow:hover .addrow-rest { background: #f2f2f2; }

/* ---------- group headers ---------- */
.group-header { display: flex; position: relative; }
.group-header .gh-band {
  position: sticky; left: 0; display: flex; align-items: center; gap: 8px;
  width: 100%; max-width: 100vw; padding: 0 12px 0 8px; overflow: hidden;
}
.group-header-inner {
  height: 48px; background: #f2f2f2;
  border-bottom: 1px solid var(--border);
  display: flex; width: 100%;
}
.group-collapse {
  width: 24px; height: 24px; border-radius: 4px; flex: none;
  display: inline-flex; align-items: center; justify-content: center; color: var(--text-quiet);
  transition: transform 0.12s ease;
}
.group-collapse:hover { background: var(--bg-hover); color: var(--text); }
.group-collapse.collapsed svg { transform: rotate(-90deg); }
.group-collapse svg { transition: transform 0.12s ease; }
.group-meta { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.group-meta .gm-label { font-size: 11px; color: var(--text-faint); line-height: 1.2; }
.group-meta .gm-value { display: flex; align-items: center; gap: 6px; min-height: 18px; }
.group-count { margin-left: auto; font-size: 11px; color: var(--text-faint); white-space: nowrap; padding-right: 8px; }
.group-agg { font-size: 11px; color: var(--text-faint); white-space: nowrap; }
.group-spacer-row { height: 12px; }

/* ---------- footer / summary bar ---------- */
.grid-footer-outer {
  flex: none; height: 34px; background: #fff;
  border-top: 1px solid var(--border);
  overflow: hidden;
}
.grid-footer-inner { display: flex; height: 100%; }
.gf-left {
  position: sticky; left: 0; z-index: 2; display: flex; align-items: center; flex: none;
  background: #fff; padding-left: 14px; gap: 4px;
}
.gf-count { font-size: 12px; color: var(--text-mid); white-space: nowrap; }
.gf-cell {
  flex: none; display: flex; align-items: center; justify-content: flex-end;
  padding: 0 8px; font-size: 11px; color: var(--text-quiet);
  background: #fff; white-space: nowrap; overflow: hidden;
}
.gf-cell .gf-label { font-size: 9px; letter-spacing: 0.4px; color: var(--text-faint); margin-right: 4px; }
.gf-cell:hover { background: var(--bg-hover-quiet); }

/* row drag */
.row-drop-indicator { position: absolute; left: 0; height: 3px; background: var(--blue-focus); z-index: 40; pointer-events: none; }
.grid-row.drag-source { opacity: 0.45; }

/* empty states */
.grid-empty {
  position: sticky; left: 0; padding: 60px 40px; text-align: center; color: var(--text-quiet);
  max-width: 100vw;
}
.grid-empty .ge-title { font-size: 15px; font-weight: 500; color: var(--text); margin-bottom: 6px; }
.grid-empty .ge-sub { font-size: 13px; margin-bottom: 14px; }
