/* ─── Variables ─────────────────────────────────────────────────────────── */

:root {
    --r4m-bg:           #ffffff;
    --r4m-surface:      #f8fafc;
    --r4m-surface-2:    #f1f5f9;
    --r4m-border:       #e2e8f0;
    --r4m-border-hover: #cbd5e1;
    --r4m-text:         #1e293b;
    --r4m-text-muted:   #64748b;
    --r4m-blue:         #3b82f6;
    --r4m-blue-dark:    #2563eb;
    --r4m-green:        #10b981;
    --r4m-green-dark:   #059669;
    --r4m-purple:       #8b5cf6;
    --r4m-purple-dark:  #7c3aed;
    --r4m-red:          #ef4444;
    --r4m-red-dark:     #dc2626;
    --r4m-shadow-sm:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
    --r4m-shadow-md:    0 4px 12px rgba(0,0,0,.1),  0 2px 4px rgba(0,0,0,.06);
    --r4m-radius:       8px;
    --r4m-radius-sm:    5px;
    --r4m-transition:   .15s ease;
}

/* ─── Mixins (utility classes) ───────────────────────────────────────────── */

/* Shared focus ring */
.r4m-col-name-input:focus,
.r4m-col-select:focus,
.r4m-col-width-input:focus,
.r4m-table-min-width:focus,
.r4m-group-label:focus {
    outline: none;
    border-color: var(--r4m-blue);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

/* ─── Outer wrapper ──────────────────────────────────────────────────────── */

.r4m-table-builder {
    background: var(--r4m-bg);
    border: 1px solid var(--r4m-border);
    border-radius: var(--r4m-radius);
    box-shadow: var(--r4m-shadow-sm);
    overflow: hidden;
}

/* ─── Toolbar ────────────────────────────────────────────────────────────── */

.r4m-table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    background: var(--r4m-surface);
    border-bottom: 1px solid var(--r4m-border);
}

.r4m-toolbar-settings {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.r4m-toolbar-right {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.r4m-toolbar-sep {
    display: inline-block;
    width: 1px;
    height: 20px;
    background: var(--r4m-border);
    margin: 0 6px;
    flex-shrink: 0;
    align-self: center;
}

.r4m-toolbar-io {
    display: flex;
    gap: 4px;
    align-items: center;
}

/* ─── Toggle switches ────────────────────────────────────────────────────── */

.r4m-setting-toggle {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 10px;
    border-radius: var(--r4m-radius-sm);
    cursor: pointer;
    user-select: none;
    transition: background var(--r4m-transition);
}

.r4m-setting-toggle:hover { background: var(--r4m-surface-2); }

.r4m-setting-toggle input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

.r4m-toggle-track {
    position: relative;
    display: inline-block;
    width: 30px;
    height: 16px;
    border-radius: 8px;
    background: var(--r4m-border);
    flex-shrink: 0;
    transition: background var(--r4m-transition);
}

.r4m-setting-toggle input:checked ~ .r4m-toggle-track { background: var(--r4m-blue); }

.r4m-toggle-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
    transition: left var(--r4m-transition);
}

.r4m-setting-toggle input:checked ~ .r4m-toggle-track .r4m-toggle-knob { left: 16px; }

.r4m-setting-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--r4m-text);
    white-space: nowrap;
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */

.r4m-tbtn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: none;
    border-radius: var(--r4m-radius-sm);
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    transition: all var(--r4m-transition);
    white-space: nowrap;
    text-decoration: none;
    box-shadow: var(--r4m-shadow-sm);
}

.r4m-tbtn svg { width: 14px; height: 14px; flex-shrink: 0; }

.r4m-tbtn-blue   { background: var(--r4m-blue);   color: #fff; }
.r4m-tbtn-green  { background: var(--r4m-green);  color: #fff; }
.r4m-tbtn-purple { background: var(--r4m-purple); color: #fff; }

.r4m-tbtn-blue:hover,
.r4m-tbtn-green:hover,
.r4m-tbtn-purple:hover { color: #fff; transform: translateY(-1px); box-shadow: var(--r4m-shadow-md); }

.r4m-tbtn-blue:hover   { background: var(--r4m-blue-dark); }
.r4m-tbtn-green:hover  { background: var(--r4m-green-dark); }
.r4m-tbtn-purple:hover { background: var(--r4m-purple-dark); }

.r4m-tbtn-outline {
    background: var(--r4m-bg);
    color: var(--r4m-text-muted);
    border: 1px solid var(--r4m-border);
    box-shadow: none;
}

.r4m-tbtn-outline:hover {
    background: var(--r4m-surface);
    color: var(--r4m-text);
    border-color: var(--r4m-text-muted);
    transform: translateY(-1px);
    box-shadow: var(--r4m-shadow-sm);
}

.r4m-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 1px solid var(--r4m-border);
    border-radius: 4px;
    background: var(--r4m-bg);
    color: var(--r4m-text-muted);
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    transition: all var(--r4m-transition);
}

.r4m-icon-btn:hover         { border-color: var(--r4m-blue);  color: var(--r4m-blue);  background: rgba(59,130,246,.06); }
.r4m-icon-btn-danger:hover  { border-color: var(--r4m-red);   color: var(--r4m-red);   background: rgba(239,68,68,.06);  }
.r4m-icon-btn:disabled      { opacity: .3; cursor: not-allowed; pointer-events: none; }

/* ─── Min-width / Visible-rows controls ──────────────────────────────────── */

.r4m-minwidth-control {
    display: flex;
    align-items: center;
    gap: 8px;
}

.r4m-minwidth-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--r4m-text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.r4m-table-min-width,
.r4m-table-visible-rows {
    padding: 5px 9px;
    font-size: 12px;
    border: 1px solid var(--r4m-border);
    border-radius: var(--r4m-radius-sm);
    background: var(--r4m-bg);
    color: var(--r4m-text);
    transition: border-color var(--r4m-transition), box-shadow var(--r4m-transition);
}

.r4m-table-min-width      { width: 110px; }
.r4m-table-visible-rows   { margin-right: 10px; }

/* ─── Grid wrapper ───────────────────────────────────────────────────────── */

.r4m-table-wrapper {
    padding: 10px;
    overflow-x: auto;
}

/* Single CSS Grid — column widths set via CSS custom property from JS.
   No min-width: max-content here — that creates a feedback loop with
   minmax(_, 1fr) when cell content has block children (e.g. <p>), causing
   columns to balloon to thousands of px. Horizontal scrolling is handled
   by .r4m-table-wrapper { overflow-x: auto }. */
.r4m-builder-grid {
    display: grid;
    grid-template-columns: var(--r4m-grid-tmpl, 84px 10px auto);
    background: var(--r4m-bg);
}

/* display:contents rows — children become direct grid items */
.r4m-grid-row { display: contents; }

/* Hidden rows */
.r4m-data-row.r4m-hidden,
.r4m-insert-row-spacer.r4m-hidden { display: none; }

/* ─── Column header cells ────────────────────────────────────────────────── */

.r4m-row-controls-header {
    background: rgba(0,0,0,.03);
    border-bottom: 2px solid var(--r4m-border);
}

.r4m-column-header {
    padding: 22px 12px 10px;
    background: rgba(0,0,0,.03);
    border-bottom: 2px solid var(--r4m-border);
    border-right: 1px solid var(--r4m-border);
}

.r4m-column-header .r4m-col-name-input { height: 20px; }

.r4m-col-topbar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.r4m-col-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--r4m-blue);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    flex-shrink: 0;
}

.r4m-col-topbar-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

.r4m-col-meta {
    display: flex;
    gap: 6px;
    flex: 1;
    min-width: 0;
    position: relative;
}

.r4m-col-meta-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.r4m-meta-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--r4m-text-muted);
    position: absolute;
    top: -15px;
}

.r4m-col-select,
.r4m-col-width-input {
    width: 100%;
    box-sizing: border-box;
    padding: 4px 6px;
    font-size: 11px;
    border: 1px solid var(--r4m-border);
    border-radius: 4px;
    background: var(--r4m-bg);
    color: var(--r4m-text);
    transition: border-color var(--r4m-transition);
}

.r4m-col-name-input {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 9px;
    font-size: 12px;
    font-weight: 600;
    color: var(--r4m-text);
    border: 1px solid var(--r4m-border);
    border-radius: var(--r4m-radius-sm);
    background: var(--r4m-bg);
    transition: border-color var(--r4m-transition), box-shadow var(--r4m-transition);
    margin-bottom: 0;
}

/* ─── Insert column spacers ──────────────────────────────────────────────── */

.r4m-insert-column-spacer {
    background: var(--r4m-surface-2);
    border-bottom: 2px solid var(--r4m-border);
    position: relative;
    transition: background var(--r4m-transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.r4m-insert-column-spacer:hover { background: rgba(59,130,246,.08); }

.r4m-insert-column-before,
.r4m-insert-column-after {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 22px;
    height: 22px;
    padding: 0;
    background: var(--r4m-blue);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    z-index: 20;
    box-shadow: var(--r4m-shadow-md);
    transition: background var(--r4m-transition);
    align-items: center;
    justify-content: center;
}

.r4m-insert-column-spacer:hover .r4m-insert-column-before,
.r4m-insert-column-spacer:hover .r4m-insert-column-after { display: flex; }

.r4m-insert-column-before:hover,
.r4m-insert-column-after:hover { background: var(--r4m-blue-dark); }

/* ─── Row controls column ────────────────────────────────────────────────── */

.r4m-row-controls {
    padding: 6px 4px;
    background: var(--r4m-surface);
    border-right: 1px solid var(--r4m-border);
    border-bottom: 1px solid var(--r4m-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    white-space: nowrap;
    transition: background var(--r4m-transition), border-color var(--r4m-transition);
}

.r4m-grid-row:hover > .r4m-row-controls {
    background: rgba(59,130,246,.04);
    border-right-color: rgba(59,130,246,.35);
}

.r4m-group-row:hover > .r4m-row-controls {
    background: rgba(139,92,246,.07);
    border-right-color: rgba(139,92,246,.35);
}

.r4m-row-controls-sep {
    display: block;
    width: 18px;
    height: 1px;
    background: var(--r4m-border);
    flex-shrink: 0;
    margin: 1px 0;
}

/* ─── Cell spacers ───────────────────────────────────────────────────────── */

.r4m-cell-spacer {
    background: var(--r4m-surface);
    border-left: 1px solid var(--r4m-border);
    border-right: 1px solid var(--r4m-border);
    border-bottom: 1px solid var(--r4m-border);
}

/* ─── Data cells ─────────────────────────────────────────────────────────── */

.r4m-data-cell {
    background: var(--r4m-bg);
    border-bottom: 1px solid var(--r4m-border);
    border-right: 1px solid var(--r4m-border);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.r4m-cell-textarea {
    display: block;
    width: 100%;
    box-sizing: border-box;
    font-size: 13px;
    border: none;
    resize: none;
    background: var(--r4m-bg);
}

/* Lightweight preview shown when TinyMCE is not active in this cell.
   Clicking activates the editor and replaces this preview in place. */
.r4m-cell-preview {
    display: block;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    min-height: 38px;
    padding: 8px 10px;
    box-sizing: border-box;
    font-size: 13px;
    line-height: 1.4;
    background: var(--r4m-bg);
    cursor: text;
    overflow: hidden;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.r4m-cell-preview:empty::before {
    content: '';
    display: inline-block;
}

.r4m-cell-preview:hover {
    background: var(--r4m-surface-2, #f8fafc);
}

.r4m-cell-preview p { margin: 0 0 4px; }
.r4m-cell-preview p:last-child { margin-bottom: 0; }
.r4m-cell-preview ul,
.r4m-cell-preview ol { margin: 0 0 4px; padding-left: 20px; }

.r4m-data-cell .wp-editor-wrap     { margin: 0; border: none; }
.r4m-data-cell .wp-editor-container { border: none; border-radius: 0; }
.r4m-data-cell .mce-edit-area,
.r4m-data-cell .mce-edit-area iframe { border: none !important; }

.r4m-data-cell .mce-toolbar-grp {
    background: var(--r4m-surface-2) !important;
    border-bottom: 1px solid var(--r4m-border) !important;
    border-top: none !important;
    border-radius: 0 !important;
}

.r4m-data-cell .mce-container-body .mce-toolbar { padding: 2px 4px !important; }
.r4m-data-cell .mce-btn button { padding: 3px 5px !important; font-size: 12px !important; }

/* ─── Insert row spacers ─────────────────────────────────────────────────── */

.r4m-insert-row-spacer {
    grid-column: 1 / -1;
    background: var(--r4m-surface);
    height: 10px;
    position: relative;
    transition: background var(--r4m-transition);
}

.r4m-insert-row-hint {
    position: relative;
    height: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.r4m-insert-row-line {
    position: absolute;
    inset: 50% 0;
    height: 2px;
    background: transparent;
    transition: background var(--r4m-transition);
    border-radius: 1px;
}

.r4m-insert-row-buttons {
    display: none;
    position: relative;
    z-index: 10;
    gap: 4px;
    align-items: center;
}

.r4m-insert-row-spacer:hover { background: rgba(59,130,246,.04); }
.r4m-insert-row-spacer:hover .r4m-insert-row-line { background: var(--r4m-blue); }
.r4m-insert-row-spacer:hover .r4m-insert-row-buttons { display: flex; }

.r4m-insert-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-size: 10px;
    font-weight: 700;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    transition: all var(--r4m-transition);
    line-height: 1.6;
    box-shadow: var(--r4m-shadow-sm);
    white-space: nowrap;
}

.r4m-insert-pill-data   { background: var(--r4m-green);  color: #fff; }
.r4m-insert-pill-group  { background: var(--r4m-purple); color: #fff; }

.r4m-insert-pill-data:hover  { background: var(--r4m-green-dark);  transform: scale(1.05); }
.r4m-insert-pill-group:hover { background: var(--r4m-purple-dark); transform: scale(1.05); }

/* ─── Empty states ───────────────────────────────────────────────────────── */

.r4m-empty-full {
    grid-column: 1 / -1;
    padding: 48px 24px;
    text-align: center;
}

.r4m-empty-no-columns {
    grid-column: unset;
    width: 100%;
    box-sizing: border-box;
}

.r4m-empty-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: var(--r4m-text-muted);
}

.r4m-empty-content p { margin: 0; font-size: 13px; }

.r4m-empty-actions { display: flex; gap: 8px; }

/* ─── Group rows ─────────────────────────────────────────────────────────── */

.r4m-group-row > .r4m-row-controls,
.r4m-group-row > .r4m-group-cell { background: rgba(0,0,0,.03); }

.r4m-group-cell {
    padding: 8px 12px;
    border-bottom: 1px solid var(--r4m-border);
    display: flex;
    align-items: center;
}

.r4m-group-inner {
    display: flex;
    align-items: center;
    gap: 8px;
}

.r4m-group-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    padding: 0;
    border: 1px solid var(--r4m-border);
    border-radius: 4px;
    background: var(--r4m-bg);
    color: var(--r4m-text-muted);
    cursor: pointer;
    transition: all var(--r4m-transition);
}

.r4m-group-toggle:hover {
    border-color: var(--r4m-purple);
    color: var(--r4m-purple);
    background: rgba(139,92,246,.07);
}

.r4m-group-label {
    flex: 1;
    min-width: 0;
    padding: 6px 10px;
    font-size: 13px;
    font-weight: 700;
    color: var(--r4m-text);
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    transition: border-color var(--r4m-transition), background var(--r4m-transition);
}

.r4m-group-label:hover {
    background: var(--r4m-bg);
    border-color: var(--r4m-border);
}

.r4m-default-collapsed-toggle {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 600;
    color: var(--r4m-text-muted);
    border: 1px solid var(--r4m-border);
    border-radius: 4px;
    background: var(--r4m-bg);
    cursor: pointer;
    transition: all var(--r4m-transition);
    white-space: nowrap;
}

.r4m-default-collapsed-toggle:hover {
    border-color: var(--r4m-purple);
    color: var(--r4m-purple);
    background: rgba(139,92,246,.05);
}

.r4m-default-collapsed-toggle.r4m-dc-active {
    border-color: var(--r4m-purple);
    background: rgba(139,92,246,.1);
    color: var(--r4m-purple);
}

.r4m-dc-label { pointer-events: none; }

/* ─── Data rows ──────────────────────────────────────────────────────────── */

.r4m-data-row.r4m-row-odd  > * { background: #FAFAFA; transition: filter var(--r4m-transition); }
.r4m-data-row.r4m-row-even > * { background: #FFFFFF; transition: filter var(--r4m-transition); }
.r4m-data-row.r4m-row-colored > * { background: var(--r4m-row-color) !important; }
.r4m-data-row:hover > * { filter: brightness(0.96); }

/* ─── Row color swatches ─────────────────────────────────────────────────── */

.r4m-row-color-swatches {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 2px 0 0;
}

.r4m-row-color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 2px;
    border: 1.5px solid transparent;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
    transition: border-color var(--r4m-transition), transform var(--r4m-transition);
}

.r4m-row-color-swatch:hover {
    border-color: var(--r4m-text) !important;
    transform: scale(1.25);
    z-index: 1;
    position: relative;
}

.r4m-row-color-swatch.r4m-swatch-active {
    border-color: var(--r4m-text) !important;
    transform: scale(1.15);
}

.r4m-row-color-swatch-reset {
    background: repeating-linear-gradient(45deg, #e2e8f0 0px, #e2e8f0 3px, #fff 3px, #fff 6px);
    border-color: var(--r4m-border) !important;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Frontend table — CSS Grid layout
   ═══════════════════════════════════════════════════════════════════════════ */

.r4m-data-table-container { margin: 20px 0; }

/* ─── Search bar ─────────────────────────────────────────────────────────── */

.r4m-data-table-search-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.r4m-data-table-search-icon {
    position: absolute;
    left: 14px;
    color: #999;
    pointer-events: none;
    flex-shrink: 0;
}

.r4m-data-table-search {
    width: 100%;
    padding: 12px 16px 12px 42px;
    font-size: 14px;
    border: 1px solid #e0e0e0;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    box-sizing: border-box;
    background: #fff;
    outline: none;
    color: #333;
    font-family: inherit;
}

.r4m-data-table-search::placeholder { color: #999; }

/* ─── Scroll wrapper ─────────────────────────────────────────────────────── */

.r4m-table-scroll-wrapper {
    overflow-x: auto;
    overscroll-behavior-x: none;
    border-left: 1px solid #e0e0e0;
    border-right: 1px solid #e0e0e0;
}

/* ─── Grid container ─────────────────────────────────────────────────────── */

.r4m-data-table {
    display: grid;
    min-width: 100%;
    background: #fff;
    font-family: "Open Sans", -apple-system, BlinkMacSystemFont, "Segoe UI",
                 Roboto, Oxygen-Sans, Ubuntu, Cantarell, sans-serif;
    font-feature-settings: 'liga' off, 'clig' off;
}

.r4m-data-table-row { display: contents; }
.r4m-data-table-row-hidden { display: none !important; }
.r4m-data-table-group-search-hidden { display: none !important; }

/* ─── Header cells ───────────────────────────────────────────────────────── */

.r4m-data-table-th {
    background: #f5f5f5;
    padding: 17px 12px;
    font-size: 14px;
    font-weight: 600;
    border-top: 1px solid #e0e0e0;
    line-height: 18px;
    text-align: left;
    color: rgba(0,0,0,.87);
    border-right: 1px solid #e0e0e0;
    border-bottom: 1px solid #c8c8c8;
    min-width: 0;
    word-wrap: break-word;
}

/* ─── Data cells ─────────────────────────────────────────────────────────── */

.r4m-data-table-td {
    padding: 12px;
    font-size: 14px;
    font-weight: 400;
    line-height: 20px;
    color: rgba(0,0,0,.70);
    border-right: 1px solid #e0e0e0;
    border-bottom: 1px solid #e0e0e0;
    background: var(--r4m-row-bg, #fff);
    min-width: 0;
    word-wrap: break-word;
}

.r4m-data-table-data-row > .r4m-data-table-td:first-child {
    font-weight: 500;
    color: rgba(0,0,0,.87);
}

.r4m-data-table-td p:first-child { margin-top: 0; }
.r4m-data-table-td p:last-child  { margin-bottom: 0; }

/* ─── Cell icons (check / cross) ─────────────────────────────────────────── */

.r4m-data-table-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    line-height: 1;
}

/* Center icon-only cells both vertically and horizontally */
.r4m-data-table-td:has(> .r4m-data-table-icon),
.r4m-data-table-td:has(> p:only-child > .r4m-data-table-icon:only-child) {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.r4m-data-table-td:has(> p:only-child > .r4m-data-table-icon:only-child) > p {
    line-height: 0;
}

.r4m-tinymce-btn-check button { color: #43a047 !important; font-weight: bold; }
.r4m-tinymce-btn-cross button { color: #e53935 !important; font-weight: bold; }

/* ─── Group headers ──────────────────────────────────────────────────────── */

.r4m-data-table-group-header {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 24px 9px 12px;
    background: #f5f5f5;
    border-right: 1px solid #e0e0e0;
    border-bottom: 1px solid #e0e0e0;
    font-size: 14px;
    font-weight: 600;
    line-height: 18px;
    color: rgba(0,0,0,.87);
    cursor: pointer;
    user-select: none;
}

.r4m-group-label-text {
    display: inline-block;
    position: sticky;
    left: 12px;
}

.r4m-data-table-group-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 3px;
    cursor: pointer;
    flex-shrink: 0;
    font-size: 16px;
    line-height: 1;
    color: #555;
    position: sticky;
    right: 24px;
    transition: background .15s, border-color .15s;
}

/* ─── Sticky header ──────────────────────────────────────────────────────── */

.r4m-data-table.sticky-header .r4m-data-table-th {
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 1px solid #e0e0e0;
}

.r4m-data-table.sticky-header .r4m-data-table-group-header {
    position: sticky;
    top: var(--r4m-thead-h, 45px);
    z-index: 4;
}

.r4m-data-table:not(.sticky-header) .r4m-data-table-group-header {
    position: sticky;
    top: 0;
    z-index: 4;
}

/* ─── Sticky first column ────────────────────────────────────────────────── */

.r4m-data-table.sticky-first-column .r4m-data-table-header-row > .r4m-data-table-th:first-child {
    position: sticky;
    left: 0;
    z-index: 15;
    border-right: 1px solid #e0e0e0;
}

.r4m-data-table.sticky-first-column .r4m-data-table-data-row > .r4m-data-table-td:first-child {
    position: sticky;
    left: 0;
    z-index: 5;
    box-shadow: inset -2px 0 0 #e0e0e0;
    border-right: 0;
    background: linear-gradient(var(--r4m-row-bg, transparent), var(--r4m-row-bg, transparent)), #fff;
}

/* ─── Fixed sticky header clone ──────────────────────────────────────────── */

.r4m-th-clone-wrap {
    display: none;
    position: fixed;
    z-index: 200;
    overflow: hidden;
    pointer-events: none;
    border-left: 1px solid #e0e0e0;
    border-right: 1px solid #e0e0e0;
}

.r4m-th-clone-inner {
    display: grid;
}

.r4m-th-clone-wrap.sticky-first-column .r4m-th-clone-inner > .r4m-data-table-th:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
}

/* ─── Fixed sticky group header clone ────────────────────────────────────── */

.r4m-group-clone {
    display: none;
    position: fixed;
    z-index: 198;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 24px 9px 12px;
    background: #f5f5f5;
    border-left: 1px solid #e0e0e0;
    border-right: 1px solid #e0e0e0;
    border-bottom: 1px solid #e0e0e0;
    box-shadow: 0 2px 4px rgba(0,0,0,.1);
    font-size: 14px;
    font-weight: 600;
    line-height: 18px;
    color: rgba(0,0,0,.87);
    cursor: pointer;
    user-select: none;
    box-sizing: border-box;
}

.r4m-group-clone .r4m-group-label-text,
.r4m-group-clone .r4m-data-table-group-toggle {
    position: static;
}

/* ─── Fixed sticky search clone ──────────────────────────────────────────── */

.r4m-search-clone {
    position: fixed;
    z-index: 199;
    background-color: #fff;
}

.r4m-search-clone .r4m-data-table-search {
    border-bottom: 1px solid #e0e0e0;
}

.r4m-search-clone .r4m-data-table-search-icon {
    top: 50%;
    transform: translateY(-50%);
}

/* ─── Expand full table button ───────────────────────────────────────────── */

.r4m-expand-table-btn-row {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 60px;
    padding: 12px;
    border-left: 1px solid rgba(0,0,0,.06);
    border-right: 1px solid rgba(0,0,0,.06);
    border-bottom: 1px solid rgba(0,0,0,.06);
    border-radius: 0 0 8px 8px;
}

.r4m-expand-table-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    padding: 0 12px;
    border: 1px solid rgba(0,0,0,.12);
    border-radius: 4px;
    background: rgba(255,255,255,.70);
    color: rgba(0,0,0,.70);
    font-family: "Open Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    font-weight: 600;
    line-height: 18px;
    cursor: pointer;
    box-sizing: border-box;
    transition: background .15s;
}

.r4m-expand-table-btn:hover { background: rgba(0,0,0,.04); }