/* ตั้งร้านค้าผู้เล่น — root เต็มจอ (layout-wide จัดกลางคอลัมน์เกม) · แผงจำกัดความกว้าง */
.pshop-root {
    position: fixed;
    inset: 0;
    z-index: 9400;
    display: none;
    align-items: center;
    justify-content: center;
    padding: max(8px, env(safe-area-inset-top, 0px))
        max(10px, env(safe-area-inset-right, 0px))
        max(8px, env(safe-area-inset-bottom, 0px))
        max(10px, env(safe-area-inset-left, 0px));
    box-sizing: border-box;
    overflow: hidden;
}

.pshop-root.open {
    display: flex;
}

.pshop-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.pshop-sheet {
    position: relative;
    z-index: 1;
    width: min(100%, 500px);
    min-width: 0;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    background: linear-gradient(165deg, #3a2c22 0%, #1a1410 55%, #120e0a 100%);
    border: 3px solid var(--px-border, #4a3424);
    box-shadow:
        inset 0 1px 0 var(--px-border-light, #8d6e63),
        0 6px 0 var(--px-shadow-deep, #080604);
    overflow: hidden;
    box-sizing: border-box;
}

/* กริดกระเป๋าใน modal — อย่าให้ minmax คงที่ดันกว้างเกินจอ */
.pshop-root .npc-sell-grid--bag {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
    justify-content: stretch;
}

.pshop-root .npc-sell-slot {
    min-width: 0;
    width: 100%;
}

.pshop-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 12px 8px;
    border-bottom: 2px solid rgba(74, 52, 36, 0.85);
    flex-shrink: 0;
}

.pshop-head-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.pshop-title {
    margin: 0;
    color: var(--px-gold, #ffd54f);
    font-size: var(--text-md);
}

.pshop-subtitle,
.pshop-muted {
    margin: 4px 0 0;
    color: #9a9080;
    font-size: var(--text-xs);
}

.pshop-body {
    flex: 1;
    min-height: 0;
    min-width: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.pshop-body > section {
    min-width: 0;
}

.pshop-section-label {
    margin: 0 0 6px;
    color: var(--px-gold-dim, #c9a227);
    font-size: var(--text-xs);
    font-weight: bold;
}

.pshop-name-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.pshop-name-row input {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border: 2px solid #5d4037;
    background: #ffffff;
    color: #1a1410;
    font: inherit;
}

.pshop-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.pshop-list-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 8px;
    align-items: center;
    padding: 8px;
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(93, 64, 55, 0.55);
}

.pshop-list-row--empty {
    grid-template-columns: 1fr;
    justify-items: center;
    color: #7a7268;
    min-height: 44px;
}

.pshop-list-item {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #e8e0d0;
    font-size: var(--text-sm);
    min-width: 0;
}

.pshop-list-item span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pshop-list-item img {
    image-rendering: pixelated;
    flex-shrink: 0;
}

.pshop-list-price {
    display: flex;
    align-items: center;
    gap: 4px;
    color: #a89888;
    font-size: var(--text-xs);
}

.pshop-list-price input {
    width: 72px;
    padding: 4px 6px;
    border: 2px solid #5d4037;
    background: #ffffff;
    color: #1a1410;
    font: inherit;
}

.pshop-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-top: 2px solid rgba(74, 52, 36, 0.85);
    flex-shrink: 0;
}

.pshop-footer-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.pshop-run-item,
.pshop-browse-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    padding: 10px;
    margin: 0 0 6px;
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(93, 64, 55, 0.55);
    color: #e8e0d0;
    text-align: left;
    font: inherit;
    cursor: pointer;
}

.pshop-run-item {
    cursor: default;
}

.pshop-run-item-main,
.pshop-browse-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pshop-browse-item-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.pshop-browse-item-text span {
    color: #9a9080;
    font-size: var(--text-xs);
}

.pshop-run-item-price {
    color: var(--px-gold, #ffd54f);
    font-size: var(--text-sm);
    white-space: nowrap;
}

.pshop-log-line {
    margin: 0 0 6px;
    padding: 6px 8px;
    background: rgba(0, 0, 0, 0.22);
    color: #cfc6b8;
    font-size: var(--text-xs);
}

.name-tag-shop {
    display: block;
    margin: 0 0 8px;
    padding: 2px 6px;
    border: 1px solid var(--px-gold-dim, #c9a227);
    background: rgba(40, 28, 12, 0.92);
    color: var(--px-gold, #ffd54f);
    font-size: 9px;
    font-weight: bold;
    letter-spacing: 0.02em;
    white-space: nowrap;
    max-width: 168px;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
}

.name-tag--shop-tap {
    z-index: 2;
}

/* จอแคบ / แนวตั้ง */
@media (max-width: 420px) {
    .pshop-list-row:not(.pshop-list-row--empty) {
        grid-template-columns: 1fr auto;
        grid-template-areas:
            'item remove'
            'price price';
    }

    .pshop-list-item {
        grid-area: item;
    }

    .pshop-list-price {
        grid-area: price;
    }

    .pshop-list-row [data-pshop-remove] {
        grid-area: remove;
    }
}

/* จอสั้น — บีบช่องว่างให้พอดี viewport */
@media (max-height: 720px) {
    .pshop-head {
        padding: 8px 10px 6px;
    }

    .pshop-body {
        padding: 8px 10px;
        gap: 8px;
    }

    .pshop-footer {
        padding: 8px 10px;
    }

    .pshop-list-row {
        padding: 6px;
        gap: 6px;
    }

    .pshop-list-row--empty {
        min-height: 36px;
    }

    .pshop-subtitle {
        display: none;
    }
}

@media (max-height: 560px) {
    .pshop-head {
        padding: 6px 8px;
    }

    .pshop-body {
        padding: 6px 8px;
        gap: 6px;
    }

    .pshop-section-label {
        margin-bottom: 4px;
    }

    .pshop-footer {
        padding: 6px 8px;
        flex-wrap: wrap;
    }
}
