/* Intelligent Grid — override the --ig-* variables to theme it */
.ig {
    --ig-font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --ig-bg: #ffffff;
    --ig-fg: #1f2933;
    --ig-muted: #616e7c;
    --ig-border: #d9e0e8;
    --ig-header-bg: #f3f6f9;
    --ig-row-alt: #fafbfc;
    --ig-hover: #eef4fb;
    --ig-selected: #dcebff;
    --ig-active: #1a73e8;
    --ig-range-bg: rgba(26, 115, 232, .12);
    --ig-find-bg: #fff3b0;
    --ig-databar: rgba(26, 115, 232, .28);
    --ig-comment: #d93025;
    --ig-cf-good: #1e8e3e;
    --ig-cf-mid: #e37400;
    --ig-cf-bad: #d93025;
    --ig-accent: #1a73e8;
    --ig-accent-fg: #ffffff;
    --ig-danger: #c62828;
    --ig-error-bg: #fdecea;
    --ig-formula: #0b7a3e;
    --ig-negative: #c62828;
    --ig-inserted: #2e7d32;
    --ig-updated: #ed8b00;
    --ig-changed-bg: rgba(237, 139, 0, .12);
    --ig-radius: 6px;
    --ig-row-height: 34px;
    --ig-shadow: 0 8px 24px rgba(15, 23, 42, .16);

    position: relative;
    font: 14px/1.4 var(--ig-font);
    color: var(--ig-fg);
    background: var(--ig-bg);
    border: 1px solid var(--ig-border);
    border-radius: var(--ig-radius);
    min-width: 0;
}
/* the element the grid is mounted in: inside a flex or grid layout it must not grow with the
   table (the table scrolls instead). Low specificity, so your own CSS still wins. */
.ig-host { min-width: 0; }
/* hidden parts (panels, bars, spacer rows) stay hidden whatever their display rule */
.ig [hidden] { display: none !important; }

@media (prefers-color-scheme: dark) {
    .ig:not(.ig-light) {
        --ig-bg: #161b22;
        --ig-fg: #e6edf3;
        --ig-muted: #8b98a5;
        --ig-border: #30363d;
        --ig-header-bg: #1f262e;
        --ig-row-alt: #1a2028;
        --ig-hover: #222c38;
        --ig-selected: #1d3557;
        --ig-active: #58a6ff;
        --ig-range-bg: rgba(88, 166, 255, .18);
        --ig-find-bg: #5c4b00;
        --ig-databar: rgba(88, 166, 255, .35);
        --ig-comment: #ff7b72;
        --ig-cf-good: #57c26a;
        --ig-cf-mid: #f0b72f;
        --ig-cf-bad: #ff7b72;
        --ig-accent: #2f81f7;
        --ig-error-bg: #3b1d1d;
        --ig-formula: #56d364;
        --ig-negative: #ff7b72;
        --ig-inserted: #56d364;
        --ig-updated: #f0b72f;
        --ig-changed-bg: rgba(240, 183, 47, .14);
        --ig-shadow: 0 8px 24px rgba(0, 0, 0, .5);
    }
}

.ig *, .ig *::before, .ig *::after { box-sizing: border-box; }

.ig-navbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px;
    padding: 8px;
    border-bottom: 1px solid var(--ig-border);
}
.ig-navbar-group { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.ig-title { margin-right: 6px; }

.ig-input, .ig-btn, .ig-editor {
    font: inherit;
    color: inherit;
    background: var(--ig-bg);
    border: 1px solid var(--ig-border);
    border-radius: 4px;
    padding: 4px 8px;
    min-height: 30px;
}
.ig-search { width: 220px; max-width: 100%; }
.ig-btn { cursor: pointer; }
.ig-btn:hover:not(:disabled) { background: var(--ig-hover); }
.ig-btn:disabled { opacity: .5; cursor: default; }
.ig-btn-primary { background: var(--ig-accent); border-color: var(--ig-accent); color: var(--ig-accent-fg); }
.ig-btn-primary:hover:not(:disabled) { background: var(--ig-accent); filter: brightness(1.08); }
.ig-btn-danger { color: var(--ig-danger); }
.ig-btn-danger-solid { background: var(--ig-danger); border-color: var(--ig-danger); color: #fff; }
.ig-btn-danger-solid:hover:not(:disabled) { background: var(--ig-danger); filter: brightness(1.08); }
.ig-btn-link { border: 0; background: none; color: var(--ig-accent); }
.ig :focus-visible { outline: 2px solid var(--ig-accent); outline-offset: 1px; }

.ig-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 4px 2px 10px;
    border-radius: 999px;
    background: var(--ig-selected);
    font-size: 12px;
    max-width: 280px;
}
.ig-chip > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ig-chip-remove { border: 0; background: none; color: inherit; cursor: pointer; font-size: 14px; line-height: 1; padding: 0 4px; }

.ig-query-btn.ig-active { border-color: var(--ig-accent); color: var(--ig-accent); }
.ig-chip-query { max-width: 520px; }

/* find / replace / go to bar */
.ig-find { display: grid; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--ig-border); background: var(--ig-header-bg); }
.ig-find-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.ig-find-input { flex: 1 1 180px; min-width: 0; }
.ig-find-input.ig-invalid { border-color: var(--ig-danger); }
.ig-find-option { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; white-space: nowrap; }
.ig-find-count { font-size: 12px; color: var(--ig-muted); min-width: 64px; }
.ig-find-close { margin-left: auto; }
/* above the zebra, hover and selected row colors */
.ig-table td.ig-cell.ig-find-match { background-color: var(--ig-find-bg); }

.ig-qb {
    display: grid;
    gap: 10px;
    padding: 10px;
    border-bottom: 1px solid var(--ig-border);
    background: var(--ig-header-bg);
}
.ig-qb-group {
    display: grid;
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--ig-border);
    border-left: 3px solid var(--ig-accent);
    border-radius: var(--ig-radius);
    background: var(--ig-bg);
}
.ig-qb-group[data-join="or"] { border-left-color: var(--ig-updated, #ed8b00); }
.ig-qb-group.ig-qb-negated { border-left-style: dashed; }
.ig-qb-group-header { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ig-qb-spacer { flex: 1; }
.ig-qb-joins { display: inline-flex; border: 1px solid var(--ig-border); border-radius: 4px; overflow: hidden; }
.ig-qb-join { font: inherit; font-size: 12px; font-weight: 600; padding: 3px 10px; border: 0; background: var(--ig-bg); color: var(--ig-muted); cursor: pointer; }
.ig-qb-join + .ig-qb-join { border-left: 1px solid var(--ig-border); }
.ig-qb-join.ig-active { background: var(--ig-accent); color: var(--ig-accent-fg); }
.ig-qb-not { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; }
.ig-qb-children { display: grid; gap: 6px; padding-left: 8px; }
.ig-qb-rule { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.ig-qb-rule > select:first-child { min-width: 140px; }
.ig-qb-rule.ig-qb-incomplete .ig-input:last-of-type { border-style: dashed; }
.ig-qb-range { display: inline-flex; align-items: center; gap: 4px; }
.ig-qb-values { min-width: 180px; }
.ig-qb-remove { border: 0; background: none; color: var(--ig-muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 2px 6px; border-radius: 4px; }
.ig-qb-remove:hover { color: var(--ig-danger); background: var(--ig-hover); }
.ig-qb-empty { margin: 0; color: var(--ig-muted); font-size: 13px; }
.ig-qb-details summary { cursor: pointer; font-size: 13px; color: var(--ig-muted); }
.ig-qb-json { margin: 6px 0; padding: 8px; max-height: 220px; overflow: auto; background: var(--ig-bg); border: 1px solid var(--ig-border); border-radius: 4px; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre; }
.ig-qb-json-actions { display: flex; justify-content: flex-end; }
.ig-qb-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.ig-qb-preview { font-size: 13px; color: var(--ig-muted); }
.ig-qb-actions { display: flex; gap: 6px; }

.ig-scroll { overflow: auto; position: relative; outline: none; }

.ig-table { border-collapse: separate; border-spacing: 0; width: 100%; table-layout: fixed; }
.ig-table th, .ig-table td {
    height: var(--ig-row-height);
    padding: 0 10px;
    border-bottom: 1px solid var(--ig-border);
    border-right: 1px solid var(--ig-border);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ig-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--ig-header-bg);
    font-weight: 600;
    user-select: none;
    text-align: left;
}
.ig-table tfoot td {
    position: sticky;
    bottom: 0;
    z-index: 1;
    background: var(--ig-header-bg);
    font-weight: 600;
    border-top: 2px solid var(--ig-border);
}
.ig-th.ig-sortable { cursor: pointer; }
.ig-th-inner { display: flex; align-items: center; gap: 4px; }
.ig-th-title { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.ig-align-right .ig-th-inner { flex-direction: row-reverse; }
.ig-align-right .ig-th-title { text-align: right; }
.ig-sort-indicator { font-size: 10px; color: var(--ig-accent); }
.ig-sort-indicator sup { font-size: 9px; margin-left: 1px; }
.ig-filter-btn {
    border: 0;
    background: none;
    color: var(--ig-muted);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 12px;
}
.ig-filter-btn:hover { background: var(--ig-hover); }
.ig-filter-btn.ig-active { color: var(--ig-accent); }
.ig-resize { position: absolute; top: 0; right: -3px; width: 7px; height: 100%; cursor: col-resize; z-index: 3; }
.ig-select-col { width: 40px; }
.ig-select-cell { text-align: center; padding: 0 !important; }

.ig-row.ig-row-alt td { background-color: var(--ig-row-alt); }
.ig-row td { background-color: var(--ig-bg); }
.ig-row:hover td { background-color: var(--ig-hover); }
.ig-spacer td { padding: 0 !important; border: 0 !important; height: 0; }
.ig-spacer-cell { padding: 0 !important; }
.ig-table .ig-pinned { position: sticky; z-index: 1; }
.ig-table thead .ig-pinned, .ig-table tfoot .ig-pinned { z-index: 3; }
.ig-table th.ig-pinned { background: var(--ig-header-bg); }
.ig-table tfoot td.ig-pinned { background: var(--ig-header-bg); }
.ig-table .ig-select-cell.ig-pinned-left { left: 0; }
.ig-pinned-left-edge { box-shadow: inset -1px 0 0 var(--ig-border), 4px 0 6px -4px rgba(15, 23, 42, .25); }
.ig-pinned-right-edge { box-shadow: inset 1px 0 0 var(--ig-border), -4px 0 6px -4px rgba(15, 23, 42, .25); }
.ig-cell.ig-wrap { white-space: normal; overflow-wrap: anywhere; height: auto; padding-top: 6px; padding-bottom: 6px; }
.ig-row.ig-selected td { background-color: var(--ig-selected); }
.ig-align-right { text-align: right; }
.ig-align-center { text-align: center; }
.ig-cell.ig-active { box-shadow: inset 0 0 0 2px var(--ig-active); }
/* cell comments: a corner mark, a tooltip on hover, an editor on Shift+F2 */
.ig-cell.ig-has-comment::before { content: ""; position: absolute; top: 0; right: 0; border-style: solid; border-width: 0 7px 7px 0; border-color: transparent var(--ig-comment) transparent transparent; pointer-events: none; }
.ig-comment-tip { position: absolute; z-index: 30; max-width: 220px; padding: 6px 8px; border: 1px solid var(--ig-border); border-radius: 4px; background: var(--ig-bg); color: var(--ig-fg); box-shadow: 0 4px 12px rgba(15, 23, 42, .18); font-size: 12px; white-space: pre-wrap; pointer-events: none; }
.ig-comment-editor { display: grid; gap: 6px; width: 240px; padding: 8px; }
.ig-comment-input { width: 100%; resize: vertical; font: inherit; }
.ig-comment-actions { display: flex; justify-content: flex-end; gap: 6px; }

/* sparklines */
.ig-sparkline-cell { padding-top: 2px; padding-bottom: 2px; color: var(--ig-accent); line-height: 0; }
.ig-sparkline { display: block; max-width: 100%; overflow: visible; }

/* group rows */
.ig-group-row td { background: var(--ig-header-bg); font-weight: 600; cursor: pointer; border-bottom: 1px solid var(--ig-border); }
/* the label may run over the empty cells next to it (the first column is often narrow) */
.ig-group-row td.ig-group-label { white-space: nowrap; overflow: visible; z-index: 3; }
.ig-group-label .ig-group-title, .ig-group-label .ig-group-count { background: var(--ig-header-bg); }
.ig-group-toggle { border: 0; background: none; color: inherit; font: inherit; width: 18px; padding: 0; cursor: pointer; }
.ig-group-count { color: var(--ig-muted); font-weight: 400; }
.ig-group-level-1 td.ig-group-label { font-weight: 500; }

/* range selection: tinted cells, a border around the block, and the fill handle on its corner */
/* body cells only: footer and header cells are sticky */
.ig-table tbody .ig-cell:not(.ig-pinned) { position: relative; }
.ig-cell { background-image: var(--ig-range-layer, none), var(--ig-changed-layer, none), var(--ig-bar-layer, none); }
.ig-cell.ig-in-range { --ig-range-layer: linear-gradient(var(--ig-range-bg), var(--ig-range-bg)); }
.ig-cell.ig-in-range::after { content: ""; position: absolute; inset: 0; pointer-events: none; border: 0 solid var(--ig-active); }
.ig-cell.ig-range-top::after { border-top-width: 2px; }
.ig-cell.ig-range-bottom::after { border-bottom-width: 2px; }
.ig-cell.ig-range-left::after { border-left-width: 2px; }
.ig-cell.ig-range-right::after { border-right-width: 2px; }
.ig-cell.ig-in-range.ig-active { --ig-range-layer: none; box-shadow: none; }
.ig-fill-handle { position: absolute; right: -1px; bottom: -1px; width: 7px; height: 7px; background: var(--ig-active); border: 1px solid var(--ig-bg); cursor: crosshair; z-index: 1; }
.ig-cell.ig-fill-target { --ig-range-layer: linear-gradient(var(--ig-range-bg), var(--ig-range-bg)); outline: 1px dashed var(--ig-active); outline-offset: -2px; }
.ig-dragging, .ig-dragging * { user-select: none; cursor: cell; }
.ig-cell.ig-formula { color: var(--ig-formula); }
.ig-cell.ig-negative { color: var(--ig-negative); }
.ig-cell.ig-error { background-color: var(--ig-error-bg) !important; color: var(--ig-danger); }
.ig-cell.ig-invalid { box-shadow: inset 0 0 0 2px var(--ig-danger); }
.ig-cell.ig-editing { padding: 0; overflow: visible; }
.ig-row-inserted > td:first-child { box-shadow: inset 3px 0 0 var(--ig-inserted); }
.ig-row-updated > td:first-child { box-shadow: inset 3px 0 0 var(--ig-updated); }
.ig-cell.ig-cell-changed { --ig-changed-layer: linear-gradient(var(--ig-changed-bg), var(--ig-changed-bg)); }
/* conditional format presets: data bars draw under the text, icons sit before it */
.ig-cell.ig-databar { --ig-bar-layer: linear-gradient(to right, var(--ig-bar-color, var(--ig-databar)) var(--ig-bar, 0%), transparent var(--ig-bar, 0%)); }
.ig-cell.ig-databar-only { color: transparent; }
.ig-cf-icon { display: inline-block; width: 1.2em; margin-right: 4px; text-align: center; font-style: normal; }
.ig-align-right .ig-cf-icon { float: left; }
.ig-cf-icon-good { color: var(--ig-cf-good); }
.ig-cf-icon-mid { color: var(--ig-cf-mid); }
.ig-cf-icon-bad { color: var(--ig-cf-bad); }
.ig-changes-badge { font-size: 12px; font-weight: 600; color: var(--ig-updated); padding: 0 4px; }
.ig-editor { width: 100%; height: 100%; min-height: var(--ig-row-height); border-radius: 0; border-color: var(--ig-active); }
.ig-editor-textarea { position: relative; z-index: 4; min-height: 80px; resize: vertical; }
.ig-editor-checkbox { width: auto; min-height: 0; }

.ig-message, .ig-loading { padding: 24px; text-align: center; color: var(--ig-muted); }
.ig-sentinel { height: 1px; }
.ig-status { padding: 6px 10px; font-size: 12px; color: var(--ig-muted); border-top: 1px solid var(--ig-border); }

.ig-popover {
    position: absolute;
    z-index: 10;
    min-width: 240px;
    max-width: min(320px, calc(100vw - 32px));
    padding: 8px;
    background: var(--ig-bg);
    border: 1px solid var(--ig-border);
    border-radius: var(--ig-radius);
    box-shadow: var(--ig-shadow);
}
.ig-menu-section { display: flex; flex-direction: column; gap: 6px; padding: 6px 0; border-bottom: 1px solid var(--ig-border); }
.ig-menu-section:last-of-type { border-bottom: 0; }
.ig-menu-item { text-align: left; border: 0; background: none; color: inherit; padding: 6px; border-radius: 4px; cursor: pointer; font: inherit; }
.ig-menu-item:hover { background: var(--ig-hover); }
.ig-condition { display: flex; flex-direction: column; gap: 4px; }
.ig-join { display: flex; gap: 12px; font-size: 13px; }
.ig-values { max-height: 200px; overflow: auto; border: 1px solid var(--ig-border); border-radius: 4px; padding: 4px; }
.ig-value { display: flex; align-items: center; gap: 6px; padding: 2px 4px; cursor: pointer; }
.ig-value span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ig-value small { color: var(--ig-muted); }
.ig-menu-actions { display: flex; justify-content: flex-end; gap: 6px; padding-top: 8px; }

.ig-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(15, 23, 42, .45);
    animation: ig-fade .12s ease-out;
}
.ig-modal {
    width: min(420px, 100%);
    padding: 20px;
    background: var(--ig-bg);
    color: var(--ig-fg);
    border: 1px solid var(--ig-border);
    border-radius: calc(var(--ig-radius) + 4px);
    box-shadow: var(--ig-shadow);
    animation: ig-pop .14s ease-out;
}
.ig-modal-title { margin: 0 0 8px; font-size: 17px; }
.ig-modal-message { margin: 0 0 20px; color: var(--ig-muted); }
.ig-modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
@keyframes ig-fade { from { opacity: 0; } }
@keyframes ig-pop { from { opacity: 0; transform: translateY(6px) scale(.98); } }
@media (prefers-reduced-motion: reduce) {
    .ig-modal-backdrop, .ig-modal { animation: none; }
}

@media (max-width: 600px) {
    .ig-navbar { flex-direction: column; }
    .ig-search { width: 100%; }
}
