body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

#table-container {
    margin-top: 20px;
    overflow-x: auto;
    max-width: 100%;
}

#grid {
    table-layout: fixed; /* Фиксированная ширина колонок */
    width: 100%;
    max-width: 1200px; /* Максимальная ширина таблицы */
    margin: 0 auto; /* Центрирование */
    border-collapse: collapse;
}

td {
    border: 1px solid #000;
    width: 12.5%; /* 100% / 8 колонок */
    height: 100px;
    min-height: 100px;
    max-height: 100px;
    text-align: center;
    vertical-align: middle;
    overflow: hidden;
    position: relative;
    padding: 5px;
    box-sizing: border-box;
    background-size: calc(100% - 2px) calc(100% - 2px);
    background-position: center;
}

td p {
    margin: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    word-wrap: break-word;
    overflow: hidden;
    padding: 5px;
    box-sizing: border-box;
}

#grid td {
    position: relative;
    color: #6e510c;
    border: 1px solid #B78F39;
    overflow: hidden;
    padding: 5px;
    width: 12.5%;
    height: 100px !important; /* Важно! Фиксированная высота */
    min-height: 100px;
    max-height: 100px;
    min-width: 0; /* Предотвращение растяжения */
    max-width: 12.5%; /* Максимальная ширина */
}

#grid td .background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: contain; /* Ensure the image fits within the cell */
    background-repeat: no-repeat;
    background-position: center;
    z-index: 0;
    /* High-quality image rendering */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: high-quality;
    -ms-interpolation-mode: bicubic;
}

#grid td p {
    position: relative;
    z-index: 1; /* Ensure text appears above the background */
    margin: 0; /* Remove default margin */
    padding: 5px; /* Add padding to avoid text touching the cell edges */
    font-weight: bold;
    box-sizing: border-box;
    word-break: normal; /* Allow line breaks between words */
    overflow-wrap: break-word; /* Wrap long words to next line as whole word */
    word-wrap: break-word; /* Legacy support for word wrapping */
    hyphens: none; /* No hyphenation - don't split words with hyphens */
    white-space: normal; /* Allow normal text wrapping */
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 100%; /* Minimum height instead of fixed */
    width: 100%;
    max-width: 100%; /* Не позволять тексту растягивать ячейку */
    overflow: hidden; /* Скрыть переполнение */
    font-size: 12px; /* Default font size */
}

/* JPG Export Settings Styles */
#jpg-quality-value {
    min-width: 50px;
    text-align: center;
    font-size: 0.9em;
}

.form-control-range {
    flex: 1;
}

/* Tooltip for resolution info */
#jpg-resolution option {
    padding: 5px;
}
