/* --- หน้าต่างขายของ NPC (แนวตั้ง: กระเป๋าเรา / ช่อง NPC) --- */
.npc-sell-root {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
        max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.18s ease;
}

.npc-sell-root.open {
    pointer-events: auto;
    opacity: 1;
}

.npc-sell-backdrop {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 50% 40%, rgba(20, 28, 36, 0.72) 0%, rgba(0, 0, 0, 0.78) 70%);
}

.npc-sell-sheet {
    position: relative;
    width: min(96vw, 440px);
    max-height: min(88vh, 640px);
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    border-radius: 10px;
    background: linear-gradient(180deg, #3a2e24 0%, #1e1612 38%, #120e0a 100%);
    box-shadow:
        0 0 0 1px rgba(255, 213, 79, 0.12),
        0 12px 40px rgba(0, 0, 0, 0.55),
        inset 0 1px 0 rgba(141, 110, 99, 0.25);
}

/* --- หัวต่าง --- */
.npc-sell-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px 10px;
    flex-shrink: 0;
    border-bottom: 2px solid rgba(0, 0, 0, 0.35);
    background: linear-gradient(180deg, rgba(74, 52, 36, 0.55) 0%, rgba(30, 22, 16, 0.2) 100%);
}

.npc-sell-head-text {
    flex: 1;
    min-width: 0;
}

.npc-sell-title {
    margin: 0;
    font-size: var(--text-lg);
    font-weight: bold;
    color: var(--px-gold);
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.6);
    line-height: 1.3;
}

.npc-sell-subtitle {
    margin: 4px 0 0;
    font-size: var(--text-xs);
    color: #a89a8c;
    line-height: 1.35;
}

.npc-sell-close-btn {
    flex-shrink: 0;
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    padding: 0;
    font-size: var(--text-md);
    line-height: 1;
}

/* --- สองซีกเลื่อนได้ --- */
.npc-sell-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 8px 10px 6px;
}

.npc-sell-pane {
    flex: 1 1 0;
    min-height: 120px;
    max-height: 42vh;
    display: flex;
    flex-direction: column;
    gap: 6px;
    border-radius: 8px;
    padding: 6px 6px 4px;
    background: rgba(0, 0, 0, 0.28);
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.35);
}

.npc-sell-pane--player {
    border: 1px solid rgba(66, 165, 245, 0.22);
}

.npc-sell-pane--npc {
    border: 1px solid rgba(255, 213, 79, 0.2);
}

.npc-sell-pane-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    padding: 0 2px;
}

.npc-sell-pane-badge {
    font-size: var(--text-xs);
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border: 1px solid rgba(0, 0, 0, 0.4);
}

.npc-sell-pane-badge--you {
    color: #90caf9;
    background: rgba(25, 118, 210, 0.25);
    border-color: rgba(66, 165, 245, 0.35);
}

.npc-sell-pane-badge--npc {
    color: #ffe082;
    background: rgba(201, 162, 39, 0.22);
    border-color: rgba(255, 213, 79, 0.35);
}

.npc-sell-pane-title {
    flex: 1;
    min-width: 0;
    font-size: var(--text-sm);
    font-weight: bold;
    color: #efebe9;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.npc-sell-pane-gold,
.npc-sell-pane-count {
    font-size: var(--text-xs);
    font-weight: bold;
    font-variant-numeric: tabular-nums;
    color: #ffe082;
    text-shadow: 0 0 6px var(--px-glow-gold);
    flex-shrink: 0;
}

.npc-sell-pane-count {
    color: #bcaaa4;
    text-shadow: none;
}

.npc-sell-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 4px 2px 6px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.18);
}

/* scrollbar ธีมเกม — ดู .game-scroll ใน base.css */

.npc-sell-divider {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
}

.npc-sell-divider-line {
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(141, 110, 99, 0.5), transparent);
}

.npc-sell-divider-arrow {
    font-size: 10px;
    color: var(--px-gold-dim);
    opacity: 0.85;
    text-shadow: 0 0 6px var(--px-glow-gold);
}

/* --- กริดช่อง --- */
.npc-sell-grid {
    display: grid;
    gap: 5px;
    justify-content: center;
    padding: 2px;
}

.npc-sell-grid--bag {
    grid-template-columns: repeat(9, minmax(38px, 44px));
}

.npc-sell-grid--npc {
    grid-template-columns: repeat(5, minmax(38px, 44px));
}

.npc-sell-slot {
    width: 100%;
    aspect-ratio: 1;
    padding: 3px;
    position: relative;
    border: 2px solid #3e2723;
    border-radius: 4px;
    background: linear-gradient(145deg, rgba(62, 48, 38, 0.9) 0%, rgba(24, 18, 14, 0.95) 100%);
    box-shadow:
        inset 0 1px 0 rgba(141, 110, 99, 0.2),
        inset 0 -2px 4px rgba(0, 0, 0, 0.35);
    cursor: pointer;
    transition: border-color 0.1s, transform 0.06s, box-shadow 0.1s;
}

.npc-sell-slot:not(.empty):not(.locked):not(.unsellable):hover,
.npc-sell-slot:not(.empty):not(.locked):active {
    border-color: var(--px-gold-dim);
    box-shadow:
        inset 0 1px 0 rgba(255, 213, 79, 0.25),
        0 0 10px rgba(255, 213, 79, 0.15);
}

.npc-sell-slot.empty {
    opacity: 0.5;
    cursor: default;
}

.npc-sell-slot.empty::after {
    content: '';
    position: absolute;
    inset: 18%;
    border: 1px dashed rgba(141, 110, 99, 0.35);
    border-radius: 2px;
    pointer-events: none;
}

.npc-sell-slot.unsellable {
    opacity: 0.38;
    cursor: not-allowed;
    filter: grayscale(0.6);
}

.npc-sell-slot.locked {
    opacity: 0.22;
    cursor: default;
}

.npc-sell-slot.locked::after {
    content: '🔒';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    opacity: 0.7;
}

.npc-sell-slot.in-queue {
    box-shadow:
        inset 0 0 0 2px rgba(255, 213, 79, 0.45),
        0 0 8px rgba(255, 213, 79, 0.2);
}

.npc-sell-slot--npc:not(.empty) {
    border-color: rgba(255, 213, 79, 0.45);
    background: linear-gradient(145deg, rgba(78, 58, 32, 0.95) 0%, rgba(32, 24, 14, 0.98) 100%);
}

.npc-sell-slot img {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    object-fit: contain;
    pointer-events: none;
}

.npc-sell-qty {
    position: absolute;
    right: 3px;
    bottom: 2px;
    font-size: 10px;
    font-weight: bold;
    line-height: 1;
    color: #fff;
    text-shadow:
        0 0 2px #000,
        1px 1px 0 #000;
    pointer-events: none;
}

.npc-sell-price {
    position: absolute;
    left: 2px;
    top: 2px;
    max-width: calc(100% - 4px);
    padding: 0 2px;
    border-radius: 2px;
    font-size: 8px;
    font-weight: bold;
    line-height: 1.2;
    color: #ffe082;
    background: rgba(0, 0, 0, 0.72);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}

/* --- ท้ายต่าง --- */
.npc-sell-footer {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 14px 12px;
    border-top: 2px solid rgba(0, 0, 0, 0.4);
    background: linear-gradient(0deg, rgba(0, 0, 0, 0.35) 0%, rgba(46, 36, 28, 0.15) 100%);
}

.npc-sell-footer-summary {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.npc-sell-total-label {
    font-size: var(--text-xs);
    color: #a89a8c;
}

.npc-sell-total {
    font-size: var(--text-lg);
    font-weight: bold;
    color: var(--px-gold);
    font-variant-numeric: tabular-nums;
    text-shadow: 0 0 10px var(--px-glow-gold);
}

.npc-sell-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.npc-sell-actions .pixel-btn {
    min-height: var(--touch-min);
    padding: 8px 14px;
    font-size: var(--text-sm);
}

.npc-sell-actions .pixel-btn.primary {
    min-width: 7.5em;
}

@media (max-width: 380px) {
    .npc-sell-grid--bag {
        grid-template-columns: repeat(6, minmax(36px, 42px));
    }

    .npc-sell-grid--npc {
        grid-template-columns: repeat(4, minmax(36px, 42px));
    }
}

.damage-number--label {
    color: #aed581;
    font-size: 10px;
}
