/* ==========================================================================
   Table block
   An editable data table: adjustable rows, columns, and per-column widths.
   ========================================================================== */

.table-block {
    width: 100%;
}

/* Horizontal scroll so wide tables never blow out the page on small screens. */
.table-block-scroll {
    width: 100%;
    overflow-x: auto;
}

.table-block-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    color: var(--text-primary);
    background: var(--surface-bg);
    border-radius: var(--radius-md, 8px);
    overflow: hidden;
}

/* "Fit content" width. */
.table-block-table.table-block-auto {
    width: auto;
    table-layout: auto;
}

.table-block-table th,
.table-block-table td {
    padding: 0.7rem 0.9rem;
    text-align: left;
    vertical-align: top;
    word-break: break-word;
}

.table-block-table thead th,
.table-block-table th[scope="col"] {
    background: color-mix(in srgb, var(--accent-gold) 16%, var(--surface-bg));
    color: var(--heading-color);
    font-weight: 700;
}

.table-block-table th[scope="row"] {
    background: color-mix(in srgb, var(--accent-gold) 8%, var(--surface-bg));
    color: var(--heading-color);
    font-weight: 600;
}

/* Striped body rows. */
.table-block-table.is-striped tbody tr:nth-child(even) td,
.table-block-table.is-striped tbody tr:nth-child(even) th[scope="row"] {
    background: color-mix(in srgb, var(--text-primary) 5%, var(--surface-bg));
}

/* Cell borders. */
.table-block-table.is-bordered,
.table-block-table.is-bordered th,
.table-block-table.is-bordered td {
    border: 1px solid var(--border-color);
}

/* Compact padding. */
.table-block-table.is-compact th,
.table-block-table.is-compact td {
    padding: 0.4rem 0.55rem;
}

/* --------------------------------------------------------------------------
   Studio editor
   -------------------------------------------------------------------------- */

.table-block-editor {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.table-block-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.table-block-toolbar-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.table-block-grid {
    display: grid;
    gap: 4px;
    align-items: stretch;
    overflow-x: auto;
    padding-bottom: 0.25rem;
}

/* Leading gutter above the row-delete column. */
.table-block-gutter {
    grid-column: 1;
}

.table-block-colctl {
    display: flex;
    align-items: center;
    gap: 4px;
}

.table-block-width {
    min-width: 0;
    flex: 1 1 auto;
    font-size: 0.75rem;
    text-align: center;
}

.table-block-colremove,
.table-block-rowremove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    line-height: 1;
    font-size: 1rem;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: var(--surface-bg);
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.table-block-rowremove {
    grid-column: 1;
    align-self: center;
    justify-self: center;
}

.table-block-colremove:hover:not(:disabled),
.table-block-rowremove:hover:not(:disabled) {
    background: color-mix(in srgb, var(--accent-rust, #c0563b) 18%, var(--surface-bg));
    color: var(--heading-color);
}

.table-block-colremove:disabled,
.table-block-rowremove:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* Each editor cell wraps an EditableRichText (Quill mounts on click). */
.table-block-cell {
    width: 100%;
    min-height: 2.6rem;
    padding: 0.25rem 0.4rem;
    background: var(--surface-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.table-block-cell:focus-within {
    border-color: var(--accent-gold);
    box-shadow: var(--focus-ring);
}

.table-block-cell.is-header {
    background: color-mix(in srgb, var(--accent-gold) 12%, var(--surface-bg));
}

.table-block-cell.is-header .table-block-cell-content {
    font-weight: 700;
    color: var(--heading-color);
}

/* Tight cell typography: drop the default block margins on the first/last child. */
.table-block-cell-content > :first-child {
    margin-top: 0;
}

.table-block-cell-content > :last-child {
    margin-bottom: 0;
}

.table-block-cell-content p {
    margin-bottom: 0.4rem;
}
