/* --- หน้าต่างซื้อของ NPC — ธีมเดียวกับคราฟ --- */
.npc-buy-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-buy-root.open {
    pointer-events: auto;
    opacity: 1;
}

.npc-buy-backdrop {
    position: absolute;
    inset: 0;
    z-index: 0;
    background: radial-gradient(ellipse at 50% 40%, rgba(20, 28, 36, 0.72) 0%, rgba(0, 0, 0, 0.78) 70%);
}

.npc-buy-sheet {
    position: relative;
    z-index: 1;
    width: min(96vw, 420px);
    max-height: min(88vh, 620px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 10px;
    padding: 0;
    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-buy-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px 10px;
    flex-shrink: 0;
    position: relative;
    z-index: 2;
    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-buy-head-text {
    flex: 1;
    min-width: 0;
}

.npc-buy-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-buy-subtitle {
    margin: 4px 0 0;
    font-size: var(--text-xs);
    color: #a89a8c;
    line-height: 1.35;
}

.npc-buy-gold {
    margin: 6px 0 0;
    font-size: var(--text-xs);
    font-weight: bold;
    font-variant-numeric: tabular-nums;
    color: #ffe082;
    text-shadow: 0 0 6px var(--px-glow-gold);
}

.npc-buy-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-buy-tabs-wrap {
    display: flex;
    align-items: stretch;
    flex-shrink: 0;
    position: relative;
    z-index: 2;
    gap: 0;
    border-bottom: 2px solid rgba(0, 0, 0, 0.35);
    background: linear-gradient(
        180deg,
        rgba(46, 36, 28, 0.55) 0%,
        rgba(30, 22, 16, 0.35) 100%
    );
}

.npc-buy-tabs-wrap[hidden] {
    display: none !important;
}

.npc-buy-tabs-arrow {
    flex: 0 0 auto;
    width: 28px;
    min-width: 28px;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 0;
    background: rgba(30, 22, 16, 0.75);
    color: #c9b8a8;
    font-family: inherit;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    touch-action: manipulation;
}

.npc-buy-tabs-arrow:hover,
.npc-buy-tabs-arrow:focus-visible {
    color: #fff8e1;
    background: rgba(74, 52, 36, 0.85);
}

.npc-buy-tabs-arrow[hidden] {
    display: none !important;
}

.npc-buy-tabs-arrow--left {
    border-right: 1px solid rgba(0, 0, 0, 0.35);
}

.npc-buy-tabs-arrow--right {
    border-left: 1px solid rgba(0, 0, 0, 0.35);
}

.npc-buy-tabs {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 4px;
    padding: 8px 10px;
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    scrollbar-width: thin;
    scrollbar-color: #8d6e63 rgba(0, 0, 0, 0.2);
}

.npc-buy-tabs::-webkit-scrollbar {
    height: 6px;
}

.npc-buy-tabs::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.npc-buy-tabs::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #8d6e63 0%, #5d4037 100%);
    border-radius: 3px;
}

.npc-buy-tabs[hidden] {
    display: none !important;
}

.npc-buy-tab {
    flex: 0 0 auto;
    margin: 0;
    padding: 6px 12px;
    border: 2px solid #5d4037;
    border-radius: 4px;
    background: rgba(46, 36, 28, 0.65);
    color: #b0a090;
    font-family: inherit;
    font-size: 12px;
    line-height: 1.2;
    cursor: pointer;
}

.npc-buy-tab:hover {
    color: #efe6d8;
    border-color: #8d6e63;
}

.npc-buy-tab.is-active {
    background: linear-gradient(180deg, #6d4c41 0%, #4e342e 100%);
    border-color: #ffd54f;
    color: #fff8e1;
}

.npc-buy-scroll {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 10px 12px 14px;
    position: relative;
    z-index: 1;
}

.npc-buy-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.npc-buy-empty {
    margin: 0;
    text-align: center;
    color: #a89a8c;
    font-size: var(--text-sm);
    padding: 24px 8px;
}

.npc-buy-card {
    display: flex;
    align-items: stretch;
    gap: 10px;
    padding: 10px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(141, 110, 99, 0.35);
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.25);
}

.npc-buy-card.disabled {
    opacity: 0.72;
}

.npc-buy-card-result {
    flex: 1;
    min-width: 0;
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.npc-buy-result-icon {
    position: relative;
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    padding: 4px;
    border-radius: 6px;
    background: linear-gradient(145deg, rgba(74, 52, 36, 0.95) 0%, rgba(24, 18, 14, 0.98) 100%);
    border: 2px solid rgba(141, 110, 99, 0.45);
    cursor: pointer;
    font-family: inherit;
}

.npc-buy-result-icon:hover {
    border-color: var(--px-gold-dim);
    box-shadow: 0 0 8px var(--px-glow-gold);
}

.npc-buy-result-icon img {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    object-fit: contain;
    pointer-events: none;
}

.npc-buy-card-info {
    flex: 1;
    min-width: 0;
}

.npc-buy-card-name {
    margin: 0 0 6px;
    font-size: var(--text-sm);
    font-weight: bold;
    color: #efebe9;
}

.npc-buy-card-price {
    margin: 0;
    font-size: var(--text-xs);
    font-weight: bold;
    color: #ffe082;
    text-shadow: 0 0 6px var(--px-glow-gold);
}

.npc-buy-btn {
    flex-shrink: 0;
    align-self: center;
    min-width: 4.5em;
    min-height: var(--touch-min);
    padding: 8px 12px;
    font-size: var(--text-sm);
}

.npc-buy-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.npc-buy-root > .item-detail-root {
    position: absolute;
    inset: 0;
    z-index: 20;
}

.npc-buy-root > .item-detail-root .item-detail-panel {
    max-height: min(85vh, 520px);
}

.npc-buy-item-preview {
    -webkit-tap-highlight-color: transparent;
}
