/* =====================================================
   EXCEL-LIKE TABLE
   ===================================================== */

#richTextEditor .excel-table-wrapper {
    /* -----------------------------------------------
       Table variables
       ----------------------------------------------- */
    --excel-column-width: 200px;
    --excel-row-height: 32px;
    --excel-header-height: 32px;
    --excel-row-header-width: 46px;

    width: 100%;
    max-width: 100%;

    overflow: auto;

    margin: 12px 0;

    background: #ffffff;

    border: 1px solid #cbd5e1;
    border-radius: 6px;

    box-shadow:
        0 1px 2px rgba(0, 0, 0, 0.04);

    /* Smooth scrolling */
    scroll-behavior: smooth;

    /* Better scrolling on mobile */
    -webkit-overflow-scrolling: touch;
}


/* =====================================================
   TABLE
   ===================================================== */

#richTextEditor table.excel-table {
    border-collapse: separate;
    border-spacing: 0;

    table-layout: fixed;

    min-width: max-content;

    background: #ffffff;

    margin: 0;

    /* Prevent browser from collapsing the table */
    width: max-content;
}


/* =====================================================
   CORNER
   Top-left blank cell
   ===================================================== */

#richTextEditor .excel-corner {
    position: sticky;

    top: 0;
    left: 0;

    z-index: 40;

    width: var(--excel-row-header-width);
    min-width: var(--excel-row-header-width);
    max-width: var(--excel-row-header-width);

    height: var(--excel-header-height);

    padding: 0;

    background: #e5e7eb;

    border-right: 1px solid #cbd5e1;
    border-bottom: 1px solid #cbd5e1;

    box-sizing: border-box;

    user-select: none;
}


/* =====================================================
   COLUMN HEADERS
   A B C D
   ===================================================== */

#richTextEditor .excel-column-header {
    position: sticky;

    top: 0;

    z-index: 30;

    width: var(--excel-column-width);
    min-width: var(--excel-column-width);

    height: var(--excel-header-height);

    padding: 0;

    background: #f3f4f6;

    border-right: 1px solid #cbd5e1;
    border-bottom: 1px solid #cbd5e1;

    box-sizing: border-box;

    text-align: center;
    vertical-align: middle;

    font-size: 12px;
    font-weight: 600;

    line-height: var(--excel-header-height);

    color: #374151;

    user-select: none;

    cursor: default;

    transition:
        background-color 120ms ease,
        color 120ms ease;
}


/* Column header hover */

#richTextEditor .excel-column-header:hover {
    background: #e5e7eb;
}


/* =====================================================
   ROW HEADERS
   1 2 3 4
   ===================================================== */

#richTextEditor .excel-row-header {
    position: sticky;

    left: 0;

    z-index: 20;

    width: var(--excel-row-header-width);
    min-width: var(--excel-row-header-width);
    max-width: var(--excel-row-header-width);

    height: var(--excel-row-height);

    padding: 0;

    background: #f3f4f6;

    border-right: 1px solid #cbd5e1;
    border-bottom: 1px solid #cbd5e1;

    box-sizing: border-box;

    text-align: center;
    vertical-align: middle;

    font-size: 12px;
    font-weight: 500;

    line-height: var(--excel-row-height);

    color: #4b5563;

    user-select: none;

    transition:
        background-color 120ms ease,
        color 120ms ease;
}


/* Row header hover */

#richTextEditor .excel-row-header:hover {
    background: #e5e7eb;
}


/* =====================================================
   CELLS
   ===================================================== */

#richTextEditor .excel-cell {
    width: var(--excel-column-width);
    min-width: var(--excel-column-width);

    height: var(--excel-row-height);

    padding: 5px 8px;

    background: #ffffff;

    border-right: 1px solid #d1d5db;
    border-bottom: 1px solid #d1d5db;

    box-sizing: border-box;

    vertical-align: middle;

    /* Text wrapping */
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;

    /* Editing */
    outline: none;

    user-select: text;

    font-size: 13px;
    line-height: 20px;

    color: #111827;

    transition:
        background-color 100ms ease;
}


/* =====================================================
   CELL HOVER
   ===================================================== */

#richTextEditor .excel-cell:hover {
    background: #f8fafc;
}


/* =====================================================
   CELL FOCUS
   ===================================================== */

#richTextEditor .excel-cell:focus {
    background: #ffffff;
}


/* =====================================================
   ACTIVE CELL
   ===================================================== */

#richTextEditor .excel-cell.excel-active-cell {
    position: relative;

    z-index: 10;

    background: #ffffff;

    box-shadow:
        inset 0 0 0 2px #2563eb;
}


/* =====================================================
   ACTIVE COLUMN / ROW HEADER
   ===================================================== */

#richTextEditor
.excel-column-header.excel-active-header,

#richTextEditor
.excel-row-header.excel-active-header {

    background: #dbeafe;

    color: #1d4ed8;

    font-weight: 700;
}


/* =====================================================
   SELECTED TABLE
   ===================================================== */

#richTextEditor
.excel-table-wrapper.excel-selected {

    box-shadow:
        0 0 0 2px #3b82f6,
        0 2px 6px rgba(0, 0, 0, 0.08);
}


/* =====================================================
   RESIZE CURSOR
   ===================================================== */

#richTextEditor .excel-column-header {
    cursor: default;
}


/* =====================================================
   TABLE SCROLLBAR
   ===================================================== */

#richTextEditor .excel-table-wrapper::-webkit-scrollbar {
    width: 9px;
    height: 9px;
}

#richTextEditor .excel-table-wrapper::-webkit-scrollbar-track {
    background: #f8fafc;
}

#richTextEditor .excel-table-wrapper::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 6px;
}

#richTextEditor .excel-table-wrapper::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}


/* =====================================================
   MOBILE
   ===================================================== */

@media (max-width: 640px) {

    #richTextEditor .excel-table-wrapper {
        --excel-column-width: 160px;
        --excel-row-header-width: 42px;
    }

    #richTextEditor .excel-cell {
        font-size: 12px;
        padding: 5px 7px;
    }

    #richTextEditor .excel-column-header,
    #richTextEditor .excel-row-header {
        font-size: 11px;
    }
}
