﻿/* ===== Layout ===== */

/* Keep this if you still use the 2-col layout somewhere */
.builder {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 16px;
    align-items: start;
}

.builder-3col {
    display: grid;
    grid-template-columns: 280px 1fr 320px;
    gap: 16px;
    align-items: start;
}

/* ===== Palette ===== */

.palette {
    border: 1px solid #ddd;
    border-radius: 10px;
    padding: 12px;
    background: #fff;
    max-height: calc(100vh - 55px - 4px - 40px - 140px);
    overflow-y: auto;
    scrollbar-gutter: stable;
}

.palette-title {
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 0.95rem;
}

.palette-item {
    display: grid;
    grid-template-columns: 18px 1fr;
    gap: 8px;
    align-items: center;
    padding: 6px 8px;
    border-radius: 8px;
    border: 1px solid #eee;
    background: #fafafa;
    cursor: grab;
    user-select: none;
    margin-bottom: 6px;
}

    .palette-item:active {
        cursor: grabbing;
    }

.palette-icon {
    width: 18px;
    height: 18px;
}

/* ===== Diagram ===== */

.diagram {
    border: 1px solid #ddd;
    border-radius: 10px;
    padding: 12px;
    background: #fff;
}

.diagram-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 10px;
}

.diagram-scroll {
    overflow-x: auto; /* enables scroll instead of squish */
}

/* ===== Table sizing (min-width fix) ===== */

:root {
    --tier-col: 110px;
    --actions-col: 120px;
    --tile: 100px; /* matches .cell-item.tile width */
    --drop-padding: 20px; /* dropzone padding left+right (10 + 10) */
    --pv-min: calc(var(--tile) + var(--drop-padding)); /* 1 tile fits */
}

/* Table is as wide as its container, BUT will not shrink below required width */
.tier-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    /* THIS is what actually enforces min widths under table-layout: fixed */
    min-width: calc(var(--tier-col) + var(--actions-col) + (2 * var(--pv-min)));
}

    .tier-table th,
    .tier-table td {
        border: 1px solid #eee;
        padding: 10px;
        vertical-align: top;
    }

.tier-col {
    width: var(--tier-col);
    white-space: nowrap;
}

.actions-col {
    width: var(--actions-col);
}

/* Physical + Virtual: stable width split */
.tier-table th:nth-child(2),
.tier-table td:nth-child(2),
.tier-table th:nth-child(3),
.tier-table td:nth-child(3) {
    width: calc((100% - var(--tier-col) - var(--actions-col)) / 2);
}

/* ===== Drop area ===== */

.dropcell {
    padding: 0;
    vertical-align: top;
}

.dropzone {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-content: flex-start;
    width: 100%;
    min-height: 128px;
    padding: 10px;
    box-sizing: border-box;
}

.drop-here {
    opacity: 0.6;
    font-style: italic;
    pointer-events: none;
}

/* ===== Tiles ===== */

.cell-item {
    cursor: grab;
    user-select: none;
}

    .cell-item:active {
        cursor: grabbing;
    }

    .cell-item.tile {
        position: relative;
        width: var(--tile);
        height: var(--tile);
        padding: 10px;
        border: 1px solid #eee;
        border-radius: 12px;
        background: #fff;
        display: grid;
        grid-template-rows: 1fr auto;
        justify-items: center;
        align-items: center;
    }

.tile-icon {
    width: 64px;
    height: 64px;
}

.cell-text {
    width: 100%;
    text-align: center;
    font-size: 0.9rem;
    line-height: 1.1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

/* Remove button on tile */
.cell-item.tile .x {
    position: absolute;
    top: 4px;
    right: 6px;
    border: none;
    background: transparent;
    font-size: 18px;
    cursor: pointer;
    opacity: 0.6;
}

    .cell-item.tile .x:hover {
        opacity: 1;
    }

/* Selected state */
.cell-item.selected {
    border-color: #999;
    box-shadow: 0 0 0 2px rgba(0,0,0,0.08);
}

/* ===== Buttons & hint ===== */

.btn {
    border: 1px solid #ddd;
    background: #f6f6f6;
    padding: 6px 10px;
    border-radius: 8px;
    cursor: pointer;
}

.btn-danger {
    border-color: #f2b8b5;
    background: #fdeeee;
}

.hint {
    margin-top: 10px;
    opacity: 0.7;
    font-size: 0.95rem;
}

/* ===== Properties panel ===== */

.properties {
    border: 1px solid #ddd;
    border-radius: 10px;
    padding: 12px;
    background: #fff;
    position: sticky;
    top: 12px;
}

.properties-title {
    font-weight: 600;
    margin-bottom: 10px;
}

.properties-empty {
    opacity: 0.7;
}

.properties-grid {
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 10px 12px;
    align-items: center;
}

    .properties-grid .label {
        opacity: 0.7;
        font-size: 0.95rem;
    }

    .properties-grid .value {
        display: flex;
        gap: 8px;
        align-items: center;
    }

.prop-icon {
    width: 18px;
    height: 18px;
}

.text {
    width: 100%;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid #ddd;
}
